#!/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_drawer_history_zoom_and_custom_window_help_match_runtime(self): history = doc_text("METRICS_HISTORY.md") api_doc = doc_text("API.md") self.assertEqual( history, (ROOT / "frontend-modern/public/docs/METRICS_HISTORY.md").read_text(encoding="utf-8"), ) self.assertEqual( api_doc, (ROOT / "frontend-modern/public/docs/API.md").read_text(encoding="utf-8"), ) zoom_section = " ".join( history.split("### Zoom and custom time windows\n", 1)[1] .split("\n### ", 1)[0] .replace("**", "") .replace("`", "") .split() ) for phrase in ( "click and drag horizontally across a drawer chart", "synchronized time selection across every panel", "minimum span of 1 minute", "Press Escape while dragging to cancel without closing the drawer", "Select time window", "Start and End editor", "timezone-offset selector", "even when the current preset has no stored readings", "between 1 minute and 365 days and cannot end in the future", "Reset zoom", "Live 30-second background polling and live fallback readings pause", "Double-click a chart, click Reset zoom, or choose a preset in History range", ): with self.subTest(zoom_phrase=phrase): self.assertIn(phrase, zoom_section) history_prose = " ".join(history.replace("**", "").replace("`", "").split()) api_prose = " ".join(api_doc.replace("**", "").replace("`", "").split()) for label, text in (("METRICS_HISTORY.md", history_prose), ("API.md", api_prose)): for phrase in ( "mutually exclusive with range", "Positive integer Unix-millisecond timestamps", "Both must be provided once when either is supplied", "end must be greater than start", "span must be between 1s and 365d", "end cannot be in the future", 'range set to "custom"' if label == "METRICS_HISTORY.md" else 'set range to "custom"', ): with self.subTest(doc=label, phrase=phrase): self.assertIn(phrase, text) drawer_tsx = source("components/Workloads/GuestDrawerHistory.tsx") query_ts = source("components/Workloads/guestDrawerHistoryQuery.ts") router_go = (ROOT / "internal/api/router.go").read_text(encoding="utf-8") for marker in ( "const HISTORY_MIN_ZOOM_SPAN_MS = 60_000;", "Select time window", "Reset zoom", "Select a window of at least 1 minute.", "Window cannot exceed 365 days.", "End time cannot be in the future.", 'label="Start timezone offset"', 'label="End timezone offset"', "if (props.isZoomed) props.onResetZoom();", ): with self.subTest(source="GuestDrawerHistory.tsx", marker=marker): self.assertIn(marker, drawer_tsx) self.assertIn("source()?.customWindow == null", query_ts) for marker in ( "func parseMetricsHistoryCustomWindow(", '"start and end cannot be combined with range"', '"start and end must both be provided once"', '"end must be greater than start"', '"custom window must be between 1s and 365d"', '"end cannot be in the future"', 'timeRange = "custom"', ): with self.subTest(source="router.go", marker=marker): self.assertIn(marker, router_go) def test_upgrade_readiness_banner_and_modal_help_match_runtime(self): auto_update = doc_text("AUTO_UPDATE.md") self.assertEqual( auto_update, (ROOT / "frontend-modern/public/docs/AUTO_UPDATE.md").read_text(encoding="utf-8"), ) section = " ".join( auto_update.split("## Using One-Click Updates\n", 1)[1] .split("\n### Update Process\n", 1)[0] .replace("**", "") .replace("`", "") .split() ) for phrase in ( "global update banner", "Confirm Update dialog", "Update blocked badge and a Review checks button", "1 upgrade warning", "N upgrade warnings", "Upgrade checks need review", "Upgrade checks panel ordered Blocked, Warning, then Pass", "Apply Update Automatically as Install blocked", "disables the acknowledgement checkbox and Start Update as Install blocked", ): with self.subTest(auto_update_phrase=phrase): self.assertIn(phrase, section) banner_tsx = source("components/UpdateBanner.tsx") modal_tsx = source("components/UpdateConfirmationModal.tsx") panel_tsx = source("components/UpdateReadinessChecksPanel.tsx") for marker in ( "Update blocked", "Review checks", "Upgrade checks need review", "Install blocked", "Apply Update Automatically", ): with self.subTest(source="UpdateBanner.tsx", marker=marker): self.assertIn(marker, banner_tsx) for marker in ( "Confirm Update", "Install blocked", "Start Update", "Resolve blocked upgrade checks before starting this update.", ): with self.subTest(source="UpdateConfirmationModal.tsx", marker=marker): self.assertIn(marker, modal_tsx) for marker in ( "Upgrade checks", "label: 'Blocked'", "label: 'Warning'", "label: 'Pass'", ): with self.subTest(source="UpdateReadinessChecksPanel.tsx", marker=marker): self.assertIn(marker, panel_tsx) 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", "API.md", "AUTO_UPDATE.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()