"""Static regression checks for the A11OY experience/data-contract first wave.""" from __future__ import annotations import json from pathlib import Path import unittest ROOT = Path(__file__).resolve().parents[2] class ExperienceContractTests(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.matrix = json.loads((ROOT / "tools/readiness-harness/tabs.json").read_text(encoding="utf-8")) cls.landing = (ROOT / "a11oy_landing.html").read_text(encoding="utf-8") cls.console = (ROOT / "pages/console.html").read_text(encoding="utf-8") cls.server = (ROOT / "serve.py").read_text(encoding="utf-8") cls.dockerfile = (ROOT / "Dockerfile").read_text(encoding="utf-8") def test_matrix_is_publicly_shipped(self) -> None: self.assertIn( "COPY tools/readiness-harness/tabs.json ./tools/readiness-harness/tabs.json", self.dockerfile, ) self.assertEqual(self.matrix["version"], "1.1") self.assertEqual(set(self.matrix["stateVocabulary"]), { "LIVE", "MEASURED", "MODELED", "SNAPSHOT", "SAMPLE", "CACHED", "UNAVAILABLE", }) def test_endpoint_methods_match_console_calls(self) -> None: endpoints = self.matrix["endpoints"] self.assertEqual(endpoints["/api/a11oy/v1/policy/compliance"]["method"], "POST") self.assertEqual(endpoints["/api/a11oy/v1/operator/recommend"]["method"], "GET") self.assertIn("orgPost('core','/api/a11oy/v1/policy/compliance'", self.console) self.assertIn("orgGet('core','/api/a11oy/v1/operator/recommend'", self.console) def test_readiness_endpoint_has_compact_honest_state(self) -> None: self.assertIn('view: str = "full"', self.server) self.assertIn('"X-A11OY-Data-State": "SNAPSHOT"', self.server) self.assertIn('"X-A11OY-Transport-State": "REACHABLE"', self.server) self.assertIn('"X-A11OY-Data-State": "UNAVAILABLE"', self.server) self.assertIn('matrix if view != "summary" else None', self.server) def test_landing_has_accessible_live_pulse(self) -> None: self.assertIn('class="skip-link" href="#main"', self.landing) self.assertIn('id="estate-pulse"', self.landing) self.assertIn('/readiness/tab-matrix?view=summary', self.landing) self.assertNotIn('href="/warhacker"', self.landing) def test_console_navigation_is_keyboard_native_and_runtime_checked(self) -> None: self.assertIn("document.createElement('button')", self.console) self.assertIn('id="runtime-status" role="status" aria-live="polite"', self.console) self.assertIn('class="skip-link" href="#content"', self.console) self.assertNotIn('LIVE', self.console) if __name__ == "__main__": unittest.main()