from __future__ import annotations import json import subprocess import sys import unittest from pathlib import Path from tools.build_api_registry import build as build_api_registry from tools.build_architecture_inventory import build as build_architecture_inventory ROOT = Path(__file__).resolve().parents[1] class MaintenanceToolTests(unittest.TestCase): def test_generated_candidate_registries_are_current(self) -> None: expected_api = json.loads( (ROOT / "config" / "api.config.json").read_text(encoding="utf-8") ) expected_architecture = json.loads( (ROOT / "config" / "architecture-inventory.json").read_text( encoding="utf-8" ) ) self.assertEqual(expected_api, build_api_registry()) self.assertEqual(expected_architecture, build_architecture_inventory()) def test_baseline_verifier_uses_the_candidate_frontend(self) -> None: source = (ROOT / "tools" / "verify_baseline.py").read_text(encoding="utf-8") self.assertIn('FRONTEND_ROOT = ROOT / "frontend"', source) self.assertIn('FRONTEND_ROOT.rglob("*.js")', source) self.assertIn("start_e2e_server()", source) self.assertIn("stop_e2e_server(server)", source) self.assertNotIn('"static/app.js"', source) def test_every_tool_has_a_non_mutating_help_path(self) -> None: for path in sorted((ROOT / "tools").glob("*.py")): if path.name.startswith("_"): continue with self.subTest(tool=path.name): result = subprocess.run( [sys.executable, str(path), "--help"], cwd=ROOT, capture_output=True, text=True, timeout=15, check=False, ) self.assertEqual(result.returncode, 0, result.stderr) def test_migration_only_tools_are_explicitly_classified(self) -> None: readme = (ROOT / "tools" / "README.md").read_text(encoding="utf-8") for name in ( "build_preservation_manifest.py", "move_class_methods.py", "split_frontend_runtime.py", ): self.assertIn(name, readme) manifest = (ROOT / "tools" / "build_preservation_manifest.py").read_text( encoding="utf-8" ) self.assertNotIn('TARGET = ROOT / "app"', manifest) self.assertIn('required=True', manifest) if __name__ == "__main__": unittest.main()