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:
1 parent
23d2fc0eb2
commit
65e3726d90
4 files changed
+491
-6
No files matched your search
Executable
+116
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# Sync the shared chart module to both thin apps, and re-pin them.
|
||||
#
|
||||
# ops-docs/scripts/sync-chart-module.sh
|
||||
#
|
||||
# The canonical module is scripts/shared/coop_chart.js in THIS repo. The two
|
||||
# consumer repos (member-dashboard, admin-panel) ship BYTE-IDENTICAL copies at
|
||||
# app/coop_chart.js; each app's main.py splices it into PAGE_HTML at import
|
||||
# time. Editing a copy by hand is a dead end: this script overwrites it, and
|
||||
# the repo's tests/test_chart_sync.py goes red on any drift from the pinned
|
||||
# revision.
|
||||
#
|
||||
# What this does:
|
||||
# 1. copies the canonical module over both repos' app/coop_chart.js
|
||||
# 2. regenerates each repo's tests/test_chart_sync.py with the CURRENT
|
||||
# canonical sha256 (the pin CI checks, since CI has no ops-docs checkout)
|
||||
# 3. node --check's the module
|
||||
# 4. runs check-chart-sync.py as the gate — a red check leaves the working
|
||||
# tree dirty so nothing can be silently committed half-synced
|
||||
#
|
||||
# After it passes: commit all three repos (ops-docs + both apps).
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPOS="$(dirname "$(dirname "$HERE")")" # ops-docs/scripts -> ops-docs -> ~/repos
|
||||
CANONICAL="$HERE/shared/coop_chart.js"
|
||||
|
||||
[ -f "$CANONICAL" ] || { echo "canonical module missing: $CANONICAL" >&2; exit 1; }
|
||||
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
node --check "$CANONICAL" && echo "node --check canonical: OK"
|
||||
else
|
||||
echo "node not found; skipping node --check (CI runs it)" >&2
|
||||
fi
|
||||
|
||||
SHA="$(sha256sum "$CANONICAL" | cut -d' ' -f1)"
|
||||
echo "canonical sha256: $SHA"
|
||||
|
||||
gen_pin_test() { # <repo>
|
||||
local repo="$1"
|
||||
local dir="$REPOS/$repo"
|
||||
mkdir -p "$dir/tests"
|
||||
cat > "$dir/tests/test_chart_sync.py" <<EOF
|
||||
#!/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 = "$SHA"
|
||||
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")
|
||||
EOF
|
||||
echo "regenerated $repo/tests/test_chart_sync.py"
|
||||
}
|
||||
|
||||
gen_pin_test member-dashboard
|
||||
gen_pin_test admin-panel
|
||||
|
||||
for repo in member-dashboard admin-panel; do
|
||||
cp "$CANONICAL" "$REPOS/$repo/app/coop_chart.js"
|
||||
echo "copied canonical -> $repo/app/coop_chart.js"
|
||||
done
|
||||
|
||||
python3 "$HERE/check-chart-sync.py"
|
||||
Reference in new issue
Block a user