shared chart module: canonical coop_chart.js + sync/check scripts

Hand-rolled chart rendering + exact-value hover tooltips as ONE module
(no library, no CDN): tooltip machinery, niceStep (count vs 1/2/5 x 10^k),
measured runs (NULL stays a gap), frame/date-marks/bars/lines/hover-targets.
Byte-identical copies ship in admin-panel and member-dashboard (app/coop_chart.js),
pinned by tests/test_chart_sync.py in each; check-chart-sync.py is the
pre-deploy gate, sync-chart-module.sh re-copies + re-pins both apps.
Vendored check-page-js.sh (skill copy + both apps) now splices the module
into the extracted page JS exactly as the apps do at import time.
This commit is contained in:
inference-bot committed 2026-11-13 16:11:16 +00:00
1 parent 23d2fc0eb2
commit 65e3726d90
4 files changed
+491 -6

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""Verify the shared chart module is single-sourced and byte-identical.
Checks, in order, and exits non-zero naming every failure:
1. canonical ops-docs/scripts/shared/coop_chart.js
== member-dashboard/app/coop_chart.js (byte-identical, sha256)
== admin-panel/app/coop_chart.js (byte-identical, sha256)
2. each repo's tests/test_chart_sync.py pins the CANONICAL revision
(so CI — which has no ops-docs checkout — still goes red when a repo
copy is hand-edited).
3. each repo's app/main.py splices the module into PAGE_HTML
(loader + placeholder replace present).
Run from anywhere: python3 ops-docs/scripts/check-chart-sync.py
This is the pre-deploy gate for either thin app; sync-chart-module.sh runs it
at the end of every sync.
"""
import hashlib
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent # ops-docs/scripts
REPOS = HERE.parent.parent # ~/repos
CANONICAL = HERE / "shared" / "coop_chart.js"
SPLICE = 'PAGE_HTML = PAGE_HTML.replace("/*@@CHART_MODULE@@*/", CHART_MODULE_JS)'
LOADER = 'CHART_MODULE_JS = (Path(__file__).resolve().parent / "coop_chart.js").read_text()'
APPS = {
"member-dashboard": ("app/coop_chart.js", "tests/test_chart_sync.py", "app/main.py"),
"admin-panel": ("app/coop_chart.js", "tests/test_chart_sync.py", "app/main.py"),
}
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
failures: list[str] = []
if not CANONICAL.exists():
print(f"FAILED: canonical module missing: {CANONICAL}")
sys.exit(1)
canonical_sha = sha256(CANONICAL)
print(f"canonical sha256: {canonical_sha}")
for repo, (copy_rel, test_rel, main_rel) in APPS.items():
copy = REPOS / repo / copy_rel
test = REPOS / repo / test_rel
main = REPOS / repo / main_rel
if not copy.exists():
failures.append(f"{repo}: {copy_rel} missing")
else:
got = sha256(copy)
if got == canonical_sha:
print(f"ok - {repo}: {copy_rel} byte-identical to canonical")
else:
failures.append(
f"{repo}: {copy_rel} DRIFTED from the canonical module\n"
f" canonical {canonical_sha}\n"
f" actual {got}\n"
f" fix: edit the canonical module (ops-docs: scripts/shared/coop_chart.js) "
f"and run ops-docs/scripts/sync-chart-module.sh — never hand-edit the copy.")
if not test.exists():
failures.append(f"{repo}: {test_rel} missing")
else:
tsrc = test.read_text()
if canonical_sha in tsrc:
print(f"ok - {repo}: {test_rel} pins the canonical revision")
else:
failures.append(
f"{repo}: {test_rel} does not pin the CURRENT canonical revision "
f"({canonical_sha[:16]}…) — run ops-docs/scripts/sync-chart-module.sh to re-pin.")
if not main.exists():
failures.append(f"{repo}: {main_rel} missing")
else:
msrc = main.read_text()
missing = [name for name, needle in (("loader", LOADER), ("splice", SPLICE)) if needle not in msrc]
if missing:
failures.append(f"{repo}: {main_rel} lacks the chart-module {', '.join(missing)}")
else:
print(f"ok - {repo}: {main_rel} loads and splices the module")
if failures:
print()
for f in failures:
print("FAILED: " + f)
sys.exit(1)
print("chart module sync: OK")