from __future__ import annotations import argparse import importlib.util import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] CHECKER_PATH = REPO_ROOT / "scripts" / "check-dev-dashboard-ssot.py" def _load_checker(): spec = importlib.util.spec_from_file_location("check_dev_dashboard_ssot", CHECKER_PATH) if spec is None or spec.loader is None: raise RuntimeError(f"Cannot load {CHECKER_PATH}") module = importlib.util.module_from_spec(spec) sys.modules[spec.name] = module spec.loader.exec_module(module) return module checker = _load_checker() def _default_args() -> argparse.Namespace: return argparse.Namespace( dashboard=REPO_ROOT / "docs" / "dev_dashboard.html", source_gaps=REPO_ROOT / "docs" / "guides" / "source-docs-and-gaps.md", backlog=REPO_ROOT / "docs" / "ops" / "backlog-2026-06-26.md", testing=REPO_ROOT / "docs" / "guides" / "testing.md", local_development=REPO_ROOT / "docs" / "guides" / "local-development.md", todo=REPO_ROOT / "docs" / "TODO.md", ) class DevDashboardSsotTests(unittest.TestCase): def test_playwright_inventory_parser_requires_exact_summary(self) -> None: inventory = checker._parse_playwright_inventory( "Listing tests:\n [desktop] example\nTotal: 594 tests in 42 files\n" ) self.assertEqual(594, inventory.tests) self.assertEqual(42, inventory.files) with self.assertRaisesRegex(ValueError, "summary"): checker._parse_playwright_inventory("594 tests") def test_current_dashboard_matches_ssot_contract(self) -> None: report = checker.run_checks(_default_args()) failed = [check for check in report["checks"] if not check["passed"]] self.assertEqual([], failed) self.assertTrue(report["passed"]) self.assertEqual(checker.EXPECTED_STATUS_COUNTS, report["status_counts"]) def test_structure_parser_counts_nested_owner_columns(self) -> None: parser = checker._dashboard_structure( """
readiness-checked metadata
")) self.assertTrue( checker._has_check_status_markup('CHECK') ) def test_repeated_runs_are_stateless(self) -> None: reports = [checker.run_checks(_default_args()) for _ in range(3)] self.assertTrue(all(report["passed"] for report in reports)) self.assertEqual( [reports[0]["status_counts"], reports[1]["status_counts"], reports[2]["status_counts"]], [dict(checker.EXPECTED_STATUS_COUNTS) for _ in range(3)], ) if __name__ == "__main__": unittest.main()