The metric buttons were built with an inline handler inside PAGE_HTML:
+ " onclick=\"setTrendMetric('" + def.id + "')">" + ...
In a plain triple-quoted Python string `\"` is just `"`, so the SERVED JS read
+ " onclick="setTrendMetric('" + ...
— the string closes at `onclick=` and the rest is a syntax error. The whole
script died at that line: no fetches, no tables, no charts. Just the shell.
Two failures compounded:
1. The line itself (a Python-escape mistake, from a patch script that turned
`\\"` into `\"`).
2. The gate certified it. tests/check-page-js.sh sliced PAGE_HTML out of the
SOURCE TEXT between the triple quotes, so it checked the escapes as typed
while the app served them INTERPRETED — a page nobody was ever served.
node --check on that text says OK.
Fixes:
* buildMetricButtons() emits data-metric attributes and the row gets ONE
delegated click listener. No inline handlers, so no quote escape can break
the page again — and the wiring is testable.
* The gate now reads PAGE_HTML with ast.literal_eval: the string Python
actually serves. Proof it works: with the new gate, the pre-fix source FAILS
node --check for both apps; the fixed tree passes.
* The stub element gained stateful attributes and addEventListener/__fire, so
the harness can prove a click reaches setTrendMetric (and that a miss does
nothing).
* The chart harness's "series name is the chart title" assertion now compares
against the shared definition instead of a title that no longer exists.
Found by rendering the served page in a real browser, which is the only check
that could have caught it: the console said
Uncaught SyntaxError: Unexpected identifier 'setTrendMetric' @802:24
Money was its own tab with its own renderers (renderMoney, renderMoneyCumulative,
renderMoneyDaily, renderMoneyLegend), its own period and spend-mode toggles, and
its own titles. It is now a metric of Trends like the others: the definitions come
from CoOpChart.CHART_METRICS, the chart is drawn by the shared renderChart(), and
the Money tab is a shortcut into Trends with that metric selected.
Removed: TREND_CONF, trendVal, trendLabel, the four money renderers, the
period/spend-mode toggles (the single Period row governs every metric now) — 5.1k
chars of duplicate chart code. Added: METRIC_SOURCE (which fetch each metric
needs), buildMetricButtons() (buttons rendered from the shared list, so the panel
and dashboard describe the same charts in the same order), and the metric-aware
renderTrends() that delegates.
The daily token-spend view is now the shared "spend" metric — the same numbers the
metrics endpoint already served, so nothing is lost by dropping the second source.
No caption under the money chart, as before.
Harness rewritten for the new path (it drove renderMoney): invariants preserved —
2 cumulative polylines + single-point balance marker, shared tooltip host, legend
that IS the definition's series list, 5 ascending ticks with the top clearing the
max, 30-day slice. New: every shared metric has a button, and a metric with no
source says so instead of drawing another chart. Tests green (page JS, pins,
guest guard).
The tooltip machinery, axis steps, frames, bars, lines and hover targets move
to the canonical shared module (ops-docs scripts/shared/coop_chart.js,
byte-identical copy spliced into PAGE_HTML at import). PROOF of no visual
change: rendered innerHTML captured across 21 chart states (5 trend metrics x
3 ranges, 2 money modes x 3 periods) is byte-identical pre/post refactor.
CI: oidc + chart sync pins added to the pipeline; vendored check-page-js.sh
splices the module into the extracted page JS.