fix: the panel served a page whose script never ran
ci/woodpecker/push/woodpecker Pipeline was successful

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
This commit is contained in:
inference-admin committed 2026-11-13 21:14:03 +00:00
1 parent 88bf95ed27
commit c3f5a326c2
3 files changed
+68 -10

No files matched your search

+31 -7
View File
@@ -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"<script>(.*?)</script>", html, re.S)
if len(blocks) != 1:
sys.exit(f"expected exactly 1 <script> block in PAGE_HTML, found {len(blocks)}")
@@ -63,13 +79,21 @@ if [ -n "$HARNESS" ]; then
// load()/loadModels() at the end of the script, which need document + fetch.
const els = {};
const mkEl = (id) => {
const attrs = {};
const el = {
id, style: {}, textContent: "", innerHTML: "", className: "",
offsetWidth: 120, offsetHeight: 48,
getAttribute: () => null,
setAttribute: () => {},
// Stateful attributes, like a real element: a stub that always answers null
// cannot tell "wired once" from "wired on every call".
getAttribute: (k) => (k in attrs ? attrs[k] : null),
setAttribute: (k, v) => { attrs[k] = String(v); },
appendChild: () => {},
};
// Delegated listeners are how the pages wire their metric buttons now, so the
// stub must have them — and must be able to fire them, or the harness cannot
// prove the wiring reaches setTrendMetric at all.
el.addEventListener = (type, fn) => { (el.__handlers = el.__handlers || {})[type] = fn; };
el.__fire = (type, ev) => { const h = (el.__handlers || {})[type]; if (h) h(ev); };
// The pages build some markup by inserting HTML into a container
// (buildMetricButtons inserts the SHARED metric list), so the stub has to
// support it or the harness cannot exercise that path at all.