From c3f5a326c29c70637be16dc6af1796e9e26025ca Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Fri, 13 Nov 2026 21:14:03 +0000 Subject: [PATCH] fix: the panel served a page whose script never ran MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- admin-panel-chart-harness.js | 25 +++++++++++++++++++++++- app/main.py | 15 ++++++++++++-- tests/check-page-js.sh | 38 +++++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/admin-panel-chart-harness.js b/admin-panel-chart-harness.js index b699dda..b6add77 100644 --- a/admin-panel-chart-harness.js +++ b/admin-panel-chart-harness.js @@ -26,7 +26,11 @@ renderTrends(); const pts = chartTipData["trend-body"]; assert(Array.isArray(pts) && pts.length === 4, "registry: one point per row (got " + (pts && pts.length) + ")"); assert(pts[0].label === "2026-11-01", "registry label is the row's exact day"); - assert(pts[0].series[0][0] === "Spend per day", "registry series name is the chart title"); + // The tooltip's series name is the SHARED definition's title (coop_chart.js + // line ~373: a single-series metric labels itself with def.title). Asserting + // the invariant, not the string that happened to be there before the port. + assert(pts[0].series[0][0] === metricDef("spend").title, + "the tooltip series name is the shared definition's title (got " + pts[0].series[0][0] + ")"); // EXACT values: the tooltip string must be the data value through the // panel's own formatter — never a pixel-derived estimate. assert(pts[0].series[0][1] === "$12.34", "exact spend for 11-01 (got " + pts[0].series[0][1] + ")"); @@ -88,5 +92,24 @@ renderTrends(); assert(!!L["pointercancel"], "touch cancel hides the tooltip"); } +// ---- the metric buttons are DELEGATED, so prove a click reaches setTrendMetric ---- +// (An inline onclick inside PAGE_HTML is where a quote escape silently kills the +// whole page: it happened, and it shipped, because the gate read the raw source +// text instead of the string Python serves. Delegation removes that trap — and +// this is the check that the wiring still works.) +{ + buildMetricButtons(); + const rowEl = document.getElementById("trend-metrics"); + assert(!!(rowEl.__handlers && rowEl.__handlers.click), + "the metric row has a delegated click listener"); + setTrendMetric("members"); + const fired = rowEl.__fire("click", { target: { closest: () => ({ getAttribute: () => "money" }) } }); + assert(trendMetric === "money", + "clicking a metric button selects that metric (got " + trendMetric + ")"); + setTrendMetric("members"); + rowEl.__fire("click", { target: { closest: () => null } }); + assert(trendMetric === "members", "a click that misses a button is ignored"); +} + console.log("HARNESS OK: chart tooltips (bars, line, gaps, exact values, clamping, multi-series)"); process.exit(0); diff --git a/app/main.py b/app/main.py index feb7724..db33dee 100644 --- a/app/main.py +++ b/app/main.py @@ -733,11 +733,22 @@ function buildMetricButtons() { if (!row || row.getAttribute("data-built") === "1") return; let html = ""; for (const def of CHART_METRICS) { - html += '"; + html += '"; } row.insertAdjacentHTML("beforeend", html); row.setAttribute("data-built", "1"); + // Delegated, not an inline handler: an inline onclick inside this + // Python triple-quoted string is exactly where a quote escape can + // silently break the whole page, and the escape that ships is not the + // one the raw source text shows. + if (!row.getAttribute("data-wired")) { + row.addEventListener("click", function (e) { + const b = e.target && e.target.closest ? e.target.closest("button[data-metric]") : null; + if (b) setTrendMetric(b.getAttribute("data-metric")); + }); + row.setAttribute("data-wired", "1"); + } syncMetricButtons(); } diff --git a/tests/check-page-js.sh b/tests/check-page-js.sh index dad40b5..b3c46e3 100755 --- a/tests/check-page-js.sh +++ b/tests/check-page-js.sh @@ -30,11 +30,27 @@ TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT python3 - "$MAIN" "$TMP/page.js" <<'PY' -import re, sys -src = open(sys.argv[1]).read() -marker = 'PAGE_HTML = """' -start = src.index(marker) + len(marker) -html = src[start:src.index('"""', start)] +import ast, re, sys +# Read PAGE_HTML the way PYTHON does, not the way the file is typed. Slicing the +# source text between the triple quotes gives you the escapes as written; the app +# gets them INTERPRETED. A JS line written `\" onclick=...` in a plain triple- +# quoted string serves as `" onclick=...` — a syntax error that kills the whole +# page, while a text slice still looks like valid JS and node --check passes. +# That is not hypothetical: on 2026-11-13 this gate certified a page whose script +# died at the first button, and both UIs served no data at all. +tree = ast.parse(open(sys.argv[1]).read()) +html = None +for node in ast.walk(tree): + if not isinstance(node, ast.Assign): + continue + if not any(getattr(t, "id", "") == "PAGE_HTML" for t in node.targets): + continue + # Only the triple-quoted literal — the module-splice line below it reassigns + # PAGE_HTML to a Call, which is not a literal and is not what we check. + if isinstance(node.value, ast.Constant) and isinstance(node.value.value, str): + html = node.value.value +if html is None: + sys.exit("no PAGE_HTML string literal found") blocks = re.findall(r"", html, re.S) if len(blocks) != 1: sys.exit(f"expected exactly 1