import re from pathlib import Path DASHBOARD_PATH = Path(__file__).parents[1] / "src" / "static" / "dashboard.html" ROUTER_PATH = ( Path(__file__).parents[1] / "rust" / "collector" / "src" / "web" / "mod.rs" ) def _rust_routes() -> set: """Paths the website serves (ping-collector's axum router).""" source = ROUTER_PATH.read_text(encoding="utf-8") return set(re.findall(r'\.route\(\s*"([^"]+)"', source)) def test_every_api_path_the_dashboard_fetches_is_served(): html = DASHBOARD_PATH.read_text(encoding="utf-8") routes = _rust_routes() patterns = [ re.compile("^" + re.sub(r"\\\{[^}]+\\\}", "[^/]+", re.escape(r)) + "$") for r in routes ] fetched = set(re.findall(r"fetch\(\s*[`'\"](/[^`'\"?$]*)", html)) assert fetched, "no fetch() calls found" missing = [ path for path in fetched if not path.startswith("/static/") and not any(p.match(path.rstrip("/") or "/") for p in patterns) and not any(r.startswith(path) for r in routes) ] assert not missing, f"dashboard fetches paths the server does not route: {missing}" def test_dashboard_contains_live_map_and_flow_visualization(): html = DASHBOARD_PATH.read_text(encoding="utf-8") assert 'id="station-map"' in html assert 'id="river-flow"' in html assert "fetch('/stations')" in html or 'fetch("/stations")' in html assert ( "fetch('/measurements/latest" in html or 'fetch("/measurements/latest' in html ) assert "leaflet" in html.lower() def _body(html: str) -> str: """Markup only. The STRINGS table repeats every English phrase, so a whole-file search would pass even if an element were deleted.""" return html[html.index("") : html.index("