Files
bakery-ia/verify_changes.py
2026-01-16 15:19:34 +01:00

149 lines
4.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Verification script to check that the user endpoint changes are syntactically correct.
"""
import os
import re
import sys
from pathlib import Path
def check_file_syntax(file_path: str) -> bool:
"""Check if a file has valid syntax (Python or TypeScript)"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Skip syntax check for TypeScript files
if file_path.endswith('.ts') or file_path.endswith('.tsx'):
print(f"✅ TypeScript file syntax check skipped for {file_path}")
return True
# Basic syntax check for Python files
compile(content, file_path, 'exec')
return True
except SyntaxError as e:
print(f"❌ Syntax error in {file_path}: {e}")
return False
except Exception as e:
print(f"❌ Error reading {file_path}: {e}")
return False
def check_auth_me_removed(file_path: str) -> bool:
"""Check that /auth/me endpoint has been removed"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Look for the /auth/me endpoint definition
if '@router.get("/me"' in content or 'def get_current_user(' in content:
print(f"❌ /auth/me endpoint still exists in {file_path}")
return False
return True
except Exception as e:
print(f"❌ Error checking {file_path}: {e}")
return False
def check_user_service_updated(file_path: str) -> bool:
"""Check that UserService has been updated to use user ID"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Check for the new implementation
if 'useAuthStore.getState()' in content and 'userId = authStore.user?.id' in content:
print(f"✅ UserService correctly updated in {file_path}")
return True
else:
print(f"❌ UserService not properly updated in {file_path}")
return False
except Exception as e:
print(f"❌ Error checking {file_path}: {e}")
return False
def check_api_client_updated(file_path: str) -> bool:
"""Check that API client has been updated"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Check that /auth/me is no longer in noTenantEndpoints (but allow /auth/me/onboarding)
lines = content.split('\n')
found_auth_me_alone = False
for line in lines:
# Look for /auth/me but not /auth/me/onboarding
if line.strip() == "'/auth/me'," or line.strip().endswith("/auth/me',"):
found_auth_me_alone = True
break
if found_auth_me_alone:
print(f"❌ /auth/me still in noTenantEndpoints in {file_path}")
return False
else:
print(f"✅ API client correctly updated in {file_path}")
return True
except Exception as e:
print(f"❌ Error checking {file_path}: {e}")
return False
def main():
"""Main verification function"""
print("🔍 Verifying user endpoint changes...")
print("=" * 60)
# Files to check
files_to_check = [
{
'path': '/Users/urtzialfaro/Documents/bakery-ia/services/auth/app/api/auth_operations.py',
'checks': [check_file_syntax, check_auth_me_removed]
},
{
'path': '/Users/urtzialfaro/Documents/bakery-ia/frontend/src/api/services/user.ts',
'checks': [check_file_syntax, check_user_service_updated]
},
{
'path': '/Users/urtzialfaro/Documents/bakery-ia/frontend/src/api/client/apiClient.ts',
'checks': [check_file_syntax, check_api_client_updated]
}
]
all_passed = True
for file_info in files_to_check:
file_path = file_info['path']
checks = file_info['checks']
print(f"\n📁 Checking {file_path}...")
for check in checks:
if not check(file_path):
all_passed = False
print("\n" + "=" * 60)
if all_passed:
print("🎉 All verification checks passed!")
print("\n✅ Changes summary:")
print(" • Removed /auth/me endpoint from auth service")
print(" • Updated UserService to use /users/{user_id}")
print(" • Updated API client to remove /auth/me from noTenantEndpoints")
print(" • All files have valid syntax")
else:
print("❌ Some verification checks failed!")
print("\nPlease review the errors above and fix them.")
print("=" * 60)
return all_passed
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)