#!/usr/bin/env python3 """Keep operator navigation guidance tied to the shipped routes and tab labels. These checks cover documentation accuracy, not collection or appliance health. """ from pathlib import Path import re import unittest ROOT = Path(__file__).resolve().parents[2] def doc_text(name: str) -> str: return (ROOT / "docs" / name).read_text(encoding="utf-8") def source(name: str) -> str: return (ROOT / "frontend-modern/src" / name).read_text(encoding="utf-8") class NavigationHelpDocsTest(unittest.TestCase): def test_entry_routes_match_the_registered_platform_routes(self): guide = doc_text("TROUBLESHOOTING.md").split("#### Old bookmarks don't work", 1)[1] guide = guide.split("### Relay / Mobile", 1)[0] links = source("routing/resourceLinks.ts") app = source("App.tsx") for label, prefix in (("Proxmox", "PROXMOX"), ("Docker", "DOCKER"), ("Kubernetes", "KUBERNETES"), ("TrueNAS", "TRUENAS"), ("vSphere", "VMWARE"), ("Machines", "STANDALONE")): with self.subTest(platform=label): path = re.search(rf"export const {prefix}_PATH = '([^']+)';", links).group(1) tab = re.search(rf"export const {prefix}_DEFAULT_TAB = '([^']+)';", links).group(1) self.assertIn(f"| {label} | `{path}/{tab}` |", guide) self.assertIn(f' (). CPU, memory, disk, and sensor readings shown are last known values until their agents report again.`", "`Stale · ` or `Stale data` on desktop, and `Stale` on narrow screens", "`Agent has stopped reporting.`", "`Showing last known readings.`", "`Last error:`", "`RAID Arrays (last known)`", "| `sort` | Sort field: `name` (default), `status`, `type`, or `lastSeen` |", "`GET /api/resources/{id}`", "PMG domain statistics", ): with self.subTest(doc="UNIFIED_RESOURCES.md", phrase=phrase): self.assertIn(phrase, unified_norm) vm_disk_norm = " ".join(vm_disk.split()) for phrase in ( "**Machines** (`/standalone/machines`) moves that host out of **Healthy** into **Degraded** with an amber **Stale** status indicator", "`Telemetry is stale for ...`", "`Stale · ` or `Stale data` cue beneath the machine name (**Stale** on phones)", "`Agent has stopped reporting.` with `Showing last known readings.` and any recorded `Last error:`", "Explicit **Offline** and awaiting-first-report states remain distinct.", ): with self.subTest(doc="VM_DISK_MONITORING.md", phrase=phrase): self.assertIn(phrase, vm_disk_norm) staleness_ts = source("features/standalone/standaloneStaleness.ts") machines_tsx = source("features/standalone/AgentsMachinesTable.tsx") model_ts = source("features/standalone/agentMachineTableModel.ts") resources_go = (ROOT / "internal/api/resourceapi/resources.go").read_text(encoding="utf-8") for marker in ( "const AGENT_REPORT_STALE_AFTER_MS = 5 * 60 * 1000;", "badge: age ? `Stale · ${age}` : 'Stale data',", "compactBadge: 'Stale',", "detail: `Agent has stopped reporting.${lastReportText} Showing last known readings.${errorText}`,", "{ variant: 'warning', label: 'Stale' }", "Telemetry is stale for ${list}. CPU, memory, disk, and sensor readings shown are last known values until their agents report again.", ): with self.subTest(source="standaloneStaleness.ts", marker=marker): self.assertIn(marker, staleness_ts) for marker in ( "title={lastKnownTitle() ? 'RAID Arrays (last known)' : 'RAID Arrays'}", 'data-testid="agent-machines-stale-banner"', 'data-agent-machine-stale-cue="true"', 'data-testid="agent-machine-stale-notice"', ): with self.subTest(source="AgentsMachinesTable.tsx", marker=marker): self.assertIn(marker, machines_tsx) self.assertIn("const staleNotice = getStandaloneMachineStaleness(machine, nowMs ?? 0);", model_ts) for marker in ( "// HandleGetResource handles GET /api/resources/{id}.", "// PMG domain stats can be very large; keep summary-only in list.", 'case "status":', 'case "type":', 'case "lastSeen":', ): with self.subTest(source="resources.go", marker=marker): self.assertIn(marker, resources_go) def test_all_changed_guides_match_their_shipped_copies(self): for name in ( "README.md", "STORAGE_ARCHITECTURE.md", "TROUBLESHOOTING.md", "TRUENAS.md", "PBS.md", "MAIL_GATEWAY.md", "METRICS_HISTORY.md", "KUBERNETES.md", "UNIFIED_RESOURCES.md", "VM_DISK_MONITORING.md", "MIGRATION_UNIFIED_NAV.md", "RELAY.md", ): with self.subTest(guide=name): self.assertEqual(doc_text(name), (ROOT / "frontend-modern/public/docs" / name).read_text(encoding="utf-8")) if __name__ == "__main__": unittest.main()