Files
member-dashboard/tests/test_chart_sync.py
T
inference-admin 2b8b8ade18 charts: take the shared concise metric titles (Members · Requests · Spend · Money · Energy · Carbon)
Same menu, same order, same words as the panel — the two UIs now differ only in
whose usage they show and in their own visual style.
2026-11-13 21:26:28 +00:00

61 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""coop_chart.js sync pin — the repo copy is byte-identical to the canonical
module, and main.py splices it into the served page.
WHY THIS EXISTS
app/coop_chart.js is a byte-identical copy of the canonical module
(co-op/ops-docs repo: scripts/shared/coop_chart.js) — the single source for
the hand-rolled chart rendering + hover tooltips both UIs ship. This test
pins the copy to the canonical revision recorded below: ANY hand edit to
app/coop_chart.js breaks the pin and goes red. To change the module, edit
the canonical file and run ops-docs/scripts/sync-chart-module.sh, which
re-copies and re-pins both repos in one step (check-chart-sync.py is the
pre-deploy gate).
Generated by sync-chart-module.sh — do not edit by hand.
Run: python3 tests/test_chart_sync.py
"""
import hashlib
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
CANONICAL_SHA256 = "d25195d5079da499d6c3788b5678b86af65d9fee8e366cfb08fd5a0201ec1a2e"
SPLICE = 'PAGE_HTML = PAGE_HTML.replace("/*@@CHART_MODULE@@*/", CHART_MODULE_JS)'
failures = []
copy = ROOT / "app" / "coop_chart.js"
if not copy.exists():
failures.append("app/coop_chart.js missing")
else:
got = hashlib.sha256(copy.read_bytes()).hexdigest()
if got == CANONICAL_SHA256:
print(f"ok - app/coop_chart.js matches the pinned canonical revision ({got[:16]}…)")
else:
failures.append(
"app/coop_chart.js DRIFTED from the pinned canonical revision\n"
f" pinned {CANONICAL_SHA256}\n"
f" actual {got}\n"
" fix: edit the canonical module (ops-docs: scripts/shared/coop_chart.js) "
"and run ops-docs/scripts/sync-chart-module.sh — never hand-edit the copy.")
main_src = (ROOT / "app" / "main.py")
if not main_src.exists():
failures.append("app/main.py missing")
else:
msrc = main_src.read_text()
if SPLICE not in msrc:
failures.append(
"app/main.py does not splice the shared chart module into PAGE_HTML:\n"
f" expected literal: {SPLICE}")
if 'parent / "coop_chart.js"' not in msrc:
failures.append("app/main.py does not load app/coop_chart.js")
if failures:
print()
print("FAILED: " + ", ".join(failures))
sys.exit(1)
print("chart sync pin: OK")