fix: the panel served a page whose script never ran
ci/woodpecker/push/woodpecker Pipeline was successful
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:
1 parent
88bf95ed27
commit
c3f5a326c2
3 files changed
+68
-10
No files matched your search
+13
-2
@@ -733,11 +733,22 @@ function buildMetricButtons() {
|
||||
if (!row || row.getAttribute("data-built") === "1") return;
|
||||
let html = "";
|
||||
for (const def of CHART_METRICS) {
|
||||
html += '<button class="range-btn" id="tm-' + def.id + '"'
|
||||
+ " onclick=\"setTrendMetric('" + def.id + "')\">" + esc(def.title) + "</button>";
|
||||
html += '<button class="range-btn" id="tm-' + def.id + '" data-metric="' + def.id + '">'
|
||||
+ esc(def.title) + "</button>";
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user