video-shuoshan/repair_test_bug_67_66.py
2026-03-17 10:38:35 +08:00

128 lines
4.6 KiB
Python

"""
Verification script for Bug #67 (DockerBuildError) and Bug #66 (CrashLoopBackOff).
Bug #67: AdminLayout.tsx (and 3 other files) imported '../assets/logo_32.png'
which didn't exist, causing Vite build failure.
Fix: Created the missing logo_32.png asset file.
Bug #66: GenerationRecord model's index lacked an explicit name, causing
Django to detect a model-migration mismatch on every container start.
Fix: Added name='generation__user_id_371350_idx' to the index, plus
created migration 0004 for MODEL_CHOICES display name change.
"""
import os
import sys
import subprocess
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
BACKEND_DIR = os.path.join(PROJECT_ROOT, 'backend')
WEB_DIR = os.path.join(PROJECT_ROOT, 'web')
def test_bug_67_logo_asset_exists():
"""Bug #67: Verify logo_32.png asset file exists."""
logo_path = os.path.join(WEB_DIR, 'src', 'assets', 'logo_32.png')
assert os.path.isfile(logo_path), f"Missing file: {logo_path}"
assert os.path.getsize(logo_path) > 0, f"File is empty: {logo_path}"
# Verify it's a valid PNG (magic bytes)
with open(logo_path, 'rb') as f:
header = f.read(8)
assert header[:4] == b'\x89PNG', f"Not a valid PNG file: {logo_path}"
print("PASS: logo_32.png exists and is a valid PNG")
def test_bug_67_no_missing_imports():
"""Bug #67: Verify all files importing logo_32.png can resolve the asset."""
files_using_logo = [
'src/pages/AdminLayout.tsx',
'src/pages/TeamAdminLayout.tsx',
'src/components/Sidebar.tsx',
'src/components/LoginModal.tsx',
]
logo_path = os.path.join(WEB_DIR, 'src', 'assets', 'logo_32.png')
for f in files_using_logo:
full_path = os.path.join(WEB_DIR, f)
if not os.path.isfile(full_path):
print(f"SKIP: {f} does not exist")
continue
with open(full_path, 'r') as fh:
content = fh.read()
if 'logo_32.png' in content:
assert os.path.isfile(logo_path), \
f"{f} imports logo_32.png but asset doesn't exist"
print(f"PASS: {f} imports logo_32.png and asset exists")
else:
print(f"INFO: {f} no longer imports logo_32.png")
def test_bug_66_no_pending_migrations():
"""Bug #66: Verify Django detects no pending migration changes."""
result = subprocess.run(
[sys.executable, 'manage.py', 'makemigrations', '--check'],
capture_output=True, text=True, cwd=BACKEND_DIR
)
assert result.returncode == 0, \
f"Pending migrations detected:\nstdout: {result.stdout}\nstderr: {result.stderr}"
print("PASS: No pending migrations detected")
def test_bug_66_index_has_name():
"""Bug #66: Verify GenerationRecord index has explicit name."""
models_path = os.path.join(BACKEND_DIR, 'apps', 'generation', 'models.py')
with open(models_path, 'r') as f:
content = f.read()
assert "name='generation__user_id_371350_idx'" in content, \
"Index name not found in models.py"
print("PASS: GenerationRecord index has explicit name")
def test_bug_66_django_check():
"""Bug #66: Verify Django system check passes."""
result = subprocess.run(
[sys.executable, 'manage.py', 'check'],
capture_output=True, text=True, cwd=BACKEND_DIR
)
assert result.returncode == 0, \
f"Django check failed:\nstdout: {result.stdout}\nstderr: {result.stderr}"
print("PASS: Django system check passed")
def test_bug_66_migration_file_exists():
"""Bug #66: Verify migration 0004 exists for MODEL_CHOICES change."""
migration_path = os.path.join(
BACKEND_DIR, 'apps', 'generation', 'migrations',
'0004_alter_generationrecord_model.py'
)
assert os.path.isfile(migration_path), \
f"Migration 0004 not found: {migration_path}"
print("PASS: Migration 0004 exists")
if __name__ == '__main__':
tests = [
test_bug_67_logo_asset_exists,
test_bug_67_no_missing_imports,
test_bug_66_no_pending_migrations,
test_bug_66_index_has_name,
test_bug_66_django_check,
test_bug_66_migration_file_exists,
]
failed = 0
for test in tests:
try:
test()
except AssertionError as e:
print(f"FAIL: {test.__name__}: {e}")
failed += 1
except Exception as e:
print(f"ERROR: {test.__name__}: {e}")
failed += 1
print(f"\n{'='*40}")
print(f"Results: {len(tests) - failed}/{len(tests)} passed")
if failed:
sys.exit(1)
else:
print("All verification tests passed!")