From e2a5018150e7004c12813759e967bd2c56a83f78 Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Fri, 13 Nov 2026 21:14:03 +0000 Subject: [PATCH] fix: same broken metric-button line, plus a mangled location.reload() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dashboard carried the identical inline-handler line inside PAGE_HTML — the served JS was a syntax error from there on, so the page loaded and then did nothing — and a second casualty of the same sloppy one-shot replace: `location.reload()` had become `location.rebuildMetricButtons()\nload()` inside loadGuests(). Both are fixed, and the same gate fix applies (the gate now reads PAGE_HTML via ast.literal_eval, i.e. the string the app serves, not the source text between the quotes). Buttons are delegated data-metric clicks now, the harness proves the click reaches setTrendMetric, and the stub gained stateful attributes plus addEventListener/__fire to make that possible. --- app/main.py | 18 ++++++++++++++---- dashboard-chart-harness.js | 19 +++++++++++++++++++ tests/check-page-js.sh | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/app/main.py b/app/main.py index 9d09c94..b936f7e 100644 --- a/app/main.py +++ b/app/main.py @@ -1055,8 +1055,7 @@ function fmtDay(s) { async function loadGuests() { try { const r = await fetch('/api/guests'); - if (r.status === 401) { location.rebuildMetricButtons(); -load(); return; } + if (r.status === 401) { location.reload(); return; } const d = await r.json().catch(() => ({})); renderGuests(d); } catch (e) { @@ -1360,11 +1359,22 @@ function buildMetricButtons() { let html = ""; for (const def of CHART_METRICS) { if (!METRIC_SOURCE[def.id]) continue; // a metric this page cannot fetch - 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/dashboard-chart-harness.js b/dashboard-chart-harness.js index 4f561d2..98faf65 100644 --- a/dashboard-chart-harness.js +++ b/dashboard-chart-harness.js @@ -171,5 +171,24 @@ function mkDaily() { buildMetricButtons(); } +// ---- 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("DASHBOARD CHART HARNESS OK: shared module tooltips, exact values, gaps, toggles"); })().catch((e) => { console.error("FAIL: " + (e && e.stack || e)); process.exit(1); }); 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