Archived
tests: run the dashboard page's JavaScript, in the tree
An independent review of 9cc237f rejected its verification claim: the commit said 18 checks executed the shipped noteSample, triple, acceptTriple, resetWindows and newEngineRun, and the tree contained none of them. The harness was real and passing, but it lived in /tmp, so nobody else could re-run it and the claim was unfalsifiable from the repository. That is a fair rejection regardless of whether the checks were right -- a verification nobody can repeat is a claim about the author's machine. Move both harnesses into tests/js/ and add the extractor they need. The page is one C++ raw string, so a JS test has to pull the script out of the translation unit it ships in; page.js does that, and each test slices the functions it exercises by line range and CALLS them. Both details matter: a retyped copy tests the copy, and a sliced function that is defined but never invoked passes without testing anything, which has already happened once in this code. extremes.test.js, 17 checks: the age clause appears only when an extreme stands alone and is at least a second old, tracks the newest extreme rather than the first, survives a gap with its age, and is gone after a restart along with the extreme itself. poll_spark.test.js, 35 checks: the clamp's floor, ceiling and fallbacks, the in-flight trigger, the old storage key migrating to a flat rate, corrupt storage falling back, the summary label matching what is set, the sparkline's x axis being time-proportional rather than sample index, the right-edge fill at startup, a sample gap drawn as a gap in the line, and the prune loop keeping samples by elapsed time rather than by count. The window expectations derive from the shipped HIST_S, so changing the constant moves them instead of silently passing. Verified: both pass, and both fail when the code is wrong -- setting the age gate to zero fails extremes.test.js, and returning the sparkline to index spacing fails four checks in poll_spark.test.js. dashboard.cpp is unchanged by this commit and dashboard_test still reports 241 checks over 8 cases. Not wired into ctest: they need node, which is not a build dependency here and will not be on a contributor's box or in the ROCm build image. Making a missing optional tool a red build is worse than an opt-in test, so the README says how to run them and when to bother. Found by an independent review pass on the author's own commits. Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
This commit is contained in:
1 parent
72ab60ed64
commit
08c85ea527
4 files changed
+232
No files matched your search
@@ -0,0 +1,26 @@
|
||||
# Dashboard page tests
|
||||
|
||||
The dashboard is one C++ string: `core/server/dashboard.cpp` embeds the whole page,
|
||||
so its JavaScript has no file of its own to test. These harnesses extract the page
|
||||
from the translation unit (`page.js`) and **execute the shipped functions**, sliced
|
||||
by line range, against mocked DOM. A retyped copy would test the copy, not the bytes
|
||||
that ship — and a sliced function that is defined but never *called* proves nothing,
|
||||
which has already happened once here.
|
||||
|
||||
node tests/js/poll_spark.test.js
|
||||
node tests/js/extremes.test.js
|
||||
|
||||
## Why these are not in ctest
|
||||
|
||||
They need node, which is not a build dependency of this project and will not be
|
||||
present on a contributor's box or in the ROCm build image. Wiring them into ctest
|
||||
would turn a missing optional tool into a red build, so they stay opt-in and are run
|
||||
by hand when the page changes. `dashboard_test` covers the C++ side only.
|
||||
|
||||
## History
|
||||
|
||||
Both files came out of the 2026-11-01 dashboard review. Commit `9cc237f` claimed
|
||||
"18 checks execute the shipped noteSample, triple, acceptTriple, resetWindows and
|
||||
newEngineRun" while the harness lived only in `/tmp` — true when written, not
|
||||
reproducible by anyone else, which an independent review correctly rejected. They are
|
||||
in the tree so that claim can be re-run.
|
||||
@@ -0,0 +1,85 @@
|
||||
/* Session extremes: the age clause, and the gap/restart split. Executes the shipped
|
||||
noteSample / triple / acceptTriple / resetWindows / newEngineRun, sliced by line
|
||||
range out of the page and CALLED -- defining a sliced function proves nothing.
|
||||
pct() is stubbed (not under test); nowS is declared here because in the page it is
|
||||
module-level and so invisible inside new Function. */
|
||||
const src = require("./page.js");
|
||||
const L = src.split("\n");
|
||||
let fails = 0, checks = 0;
|
||||
const ok = (c, m) => { checks++; if (!c) { fails++; console.log(" FAIL " + m); } };
|
||||
const eq = (a, b, m) => { checks++; if (a !== b) { fails++; console.log(" FAIL " + m + ": got " + JSON.stringify(a) + " want " + JSON.stringify(b)); } };
|
||||
function lines(a, b) {
|
||||
const i = L.findIndex((x) => x.startsWith(a));
|
||||
if (i < 0) throw new Error("no start line: " + a);
|
||||
let j = -1;
|
||||
for (let k = i; k < L.length; k++) if (L[k].startsWith(b)) { j = k; break; }
|
||||
if (j < 0) throw new Error("no end line: " + b);
|
||||
return L.slice(i, j + 1).join("\n");
|
||||
}
|
||||
const BLOCK = [
|
||||
"let nowS = 0;",
|
||||
/* resetWindows() clears these module-level collaborators; they are not under
|
||||
test, but it READS hist, so they have to exist for it to run at all. */
|
||||
"const hist = {}, moveHist = { up: [], down: [] };",
|
||||
"let prev = null, prevAt = 0, accPrev = null;",
|
||||
'const DASH = "\\u2013";',
|
||||
"const finite = (v) => v != null && isFinite(v);",
|
||||
"const pct = (f, d = 1) => (f == null ? DASH : (f * 100).toFixed(d) + '%');",
|
||||
lines("function dur(", "}"),
|
||||
lines("const RECENT_S =", "const RECENT_PREFILL_S"),
|
||||
lines("const extAt =", "let lastActiveC"),
|
||||
lines("function noteSample(", "}"),
|
||||
lines("function triple(", "}"),
|
||||
lines("function acceptTriple(", "}"),
|
||||
lines("const accPool =", "const accPool ="),
|
||||
lines("function resetWindows", "}"),
|
||||
lines("function newEngineRun", "}"),
|
||||
].join("\n");
|
||||
function fresh() {
|
||||
const box = {};
|
||||
new Function("box", BLOCK + "\nbox.api={noteSample,triple,acceptTriple,resetWindows,newEngineRun,extAt,winAt,extAtS,setNow:(v)=>{nowS=v;}};")(box);
|
||||
return box.api;
|
||||
}
|
||||
const F = (v) => v + " t/s";
|
||||
console.log("== the age clause appears only when the extreme stands alone ==");
|
||||
let b = fresh();
|
||||
b.setNow(100); b.noteSample("dec", 1, 500, 15, true);
|
||||
let out = b.triple("dec", 1, "best", F);
|
||||
ok(!out.includes("ago"), "window full: no age clause (got " + JSON.stringify(out) + ")");
|
||||
ok(out.includes("recent"), "and the window figures still render");
|
||||
b.resetWindows(); b.setNow(150);
|
||||
out = b.triple("dec", 1, "best", F);
|
||||
ok(/best 500 t\/s · 50\.0 s ago$/.test(out), "extreme alone: age names the span (got " + JSON.stringify(out) + ")");
|
||||
b.setNow(100.4);
|
||||
ok(!b.triple("dec", 1, "best", F).includes("ago"), "an extreme set 0.4s ago is current: no clause");
|
||||
console.log("== a stale extreme is distinguishable from a fresh one ==");
|
||||
b = fresh(); b.setNow(100); b.noteSample("dec", 1, 500, 15, false); b.setNow(1000);
|
||||
out = b.triple("dec", 1, "best", F);
|
||||
ok(out.includes("15m 00s ago"), "15-minute-old extreme says so (got " + JSON.stringify(out) + ")");
|
||||
ok(out.includes("best 500"), "and still shows the figure itself");
|
||||
console.log("== a GAP keeps the extreme, and says how old it is ==");
|
||||
b = fresh(); b.setNow(100); b.noteSample("dec", 1, 500, 15, true); b.noteSample("accept", 1, 0.9, 15, false);
|
||||
b.setNow(400); b.resetWindows();
|
||||
out = b.triple("dec", 1, "best", F);
|
||||
ok(out.includes("best 500"), "the session extreme survives a gap (got " + JSON.stringify(out) + ")");
|
||||
ok(out.includes("5m 00s ago"), "and names its age (got " + JSON.stringify(out) + ")");
|
||||
eq(Object.keys(b.extAt).length, 2, "extAt untouched by a gap");
|
||||
console.log("== a RESTART drops the extremes: a new process inherits nothing ==");
|
||||
b = fresh(); b.setNow(100); b.noteSample("dec", 1, 500, 15, true); b.noteSample("accept", 1, 0.9, 15, false);
|
||||
b.setNow(400); b.newEngineRun();
|
||||
eq(Object.keys(b.extAt).length, 0, "extAt cleared by newEngineRun");
|
||||
eq(Object.keys(b.extAtS).length, 0, "extAtS cleared by newEngineRun");
|
||||
eq(b.triple("dec", 1, "best", F), "", "the previous run's extreme no longer renders");
|
||||
eq(b.acceptTriple(1), "", "the previous run's acceptance extreme no longer renders");
|
||||
b.setNow(200); b.noteSample("dec", 1, 700, 15, false);
|
||||
out = b.triple("dec", 1, "best", F);
|
||||
ok(!out.includes("ago"), "a fresh extreme carries no age clause (got " + JSON.stringify(out) + ")");
|
||||
ok(/best 700 t\/s$/.test(out), "and reads as the new run's own figure");
|
||||
console.log("== the age tracks the NEWER extreme, not the first ==");
|
||||
b = fresh(); b.setNow(100); b.noteSample("dec", 1, 500, 15, false);
|
||||
b.setNow(400); b.noteSample("dec", 1, 900, 15, false); b.setNow(460);
|
||||
out = b.triple("dec", 1, "best", F);
|
||||
ok(out.includes("best 900"), "the surviving figure is the newest extreme (got " + JSON.stringify(out) + ")");
|
||||
ok(out.includes("1m 00s ago"), "and its age is the newer stamp (got " + JSON.stringify(out) + ")");
|
||||
console.log(fails ? "\n" + fails + " FAILURE(S) of " + checks : "\nALL " + checks + " CHECKS PASS on the shipped extreme code");
|
||||
process.exit(fails ? 1 : 0);
|
||||
@@ -0,0 +1,15 @@
|
||||
/* Extract the embedded dashboard page's <script> from core/server/dashboard.cpp.
|
||||
The page lives inside a C++ raw string, so a JS test has to pull it out of the
|
||||
translation unit it ships in. Reading the real file is the point: a copy of the
|
||||
page would test the copy. */
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const cpp = fs.readFileSync(
|
||||
path.join(__dirname, "..", "..", "core", "server", "dashboard.cpp"),
|
||||
"utf8",
|
||||
);
|
||||
const page = cpp.match(/R"HTML\(([\s\S]*)\)HTML"/);
|
||||
if (!page) throw new Error("no R\"HTML(...)HTML\" page block in dashboard.cpp");
|
||||
const script = page[1].match(/<script>([\s\S]*)<\/script>/);
|
||||
if (!script) throw new Error("no <script> block in the dashboard page");
|
||||
module.exports = script[1];
|
||||
@@ -0,0 +1,106 @@
|
||||
/* Poll cadence and the time-proportional sparkline. Executes the shipped clampMs,
|
||||
pollCadence, pollSummary, spark and setMetric, sliced by line range out of the page.
|
||||
The window expectations DERIVE from the shipped HIST_S rather than hardcoding 60, so
|
||||
changing the constant moves the expectation instead of silently passing. */
|
||||
const src = require("./page.js");
|
||||
const L = src.split("\n");
|
||||
let fails = 0, checks = 0;
|
||||
const ok = (c, m) => { checks++; if (!c) { fails++; console.log(" FAIL " + m); } };
|
||||
const eq = (a, b, m) => { checks++; if (a !== b) { fails++; console.log(" FAIL " + m + ": got " + JSON.stringify(a) + " want " + JSON.stringify(b)); } };
|
||||
function lines(a, b) {
|
||||
const i = L.findIndex((x) => x.startsWith(a));
|
||||
if (i < 0) throw new Error("no start line: " + a);
|
||||
let j = -1;
|
||||
for (let k = i; k < L.length; k++) if (L[k].startsWith(b)) { j = k; break; }
|
||||
if (j < 0) throw new Error("no end line: " + b);
|
||||
return L.slice(i, j + 1).join("\n");
|
||||
}
|
||||
const HIST_S_SRC = lines("const HIST_S =", "const HIST_S =");
|
||||
const HS = parseInt(HIST_S_SRC.match(/HIST_S\s*=\s*([0-9]+)/)[1], 10);
|
||||
const SPARK = lines("function spark(key, pts) {", "}");
|
||||
const CADENCE = lines("const POLL_K", "const pollCadence =");
|
||||
const SUMMARY = lines("function pollSummary(", "}");
|
||||
const SETMETRIC = lines("function setMetric(key, value, text) {", "}");
|
||||
|
||||
console.log("== the window is a constant, and the expectations read it ==");
|
||||
eq(HS, 60, "HIST_S is 60 as documented");
|
||||
|
||||
function cadence(raw) {
|
||||
const els = {};
|
||||
const lsGet = () => raw;
|
||||
const $ = (id) => (els[id] || (els[id] = { textContent: "" }));
|
||||
return new Function("lsGet", "$", CADENCE + "\n" + SUMMARY +
|
||||
"\npollSummary();\nreturn {clampMs, pollCadence, idle:()=>pollIdleMs, busy:()=>pollBusyMs, sum:()=>$('advsum').textContent};")(lsGet, $);
|
||||
}
|
||||
console.log("== clamp: the field cannot be talked out of a sane rate ==");
|
||||
let c = cadence(null);
|
||||
eq(c.clampMs(50, 500), 100, "below floor clamps to the floor");
|
||||
eq(c.clampMs(9999, 500), 5000, "above ceiling clamps to the ceiling");
|
||||
eq(c.clampMs("", 500), 500, "blank field falls back to its default");
|
||||
eq(c.clampMs("abc", 300), 300, "garbage falls back to its default");
|
||||
eq(c.clampMs(1500, 500), 1500, "in-range passes through");
|
||||
console.log("== defaults, and the in-flight trigger ==");
|
||||
eq(c.idle(), 500, "shipped idle default"); eq(c.busy(), 300, "shipped busy default");
|
||||
eq(c.pollCadence(0), 500, "idle when nothing in flight");
|
||||
eq(c.pollCadence(3), 300, "busy when requests are in flight");
|
||||
console.log("== stored values, and the old key migrating to a flat rate ==");
|
||||
let m = cadence(JSON.stringify({ idle: 700, busy: 200 }));
|
||||
eq(m.idle(), 700, "stored idle honored"); eq(m.busy(), 200, "stored busy honored");
|
||||
m = cadence(JSON.stringify({ ms: 800, adaptive: true }));
|
||||
eq(m.idle(), 800, "old {ms} migrates to idle"); eq(m.busy(), 800, "old {ms} migrates to a FLAT rate");
|
||||
m = cadence("{ not json");
|
||||
eq(m.idle(), 500, "corrupt storage falls back to the default");
|
||||
eq(m.busy(), 300, "corrupt storage keeps the busy default");
|
||||
eq(cadence(JSON.stringify({ idle: 50 })).idle(), 100, "a stored sub-floor value is clamped on read");
|
||||
console.log("== the summary label never lies about what is set ==");
|
||||
eq(c.sum(), "500 ms idle \u00b7 300 ms busy", "two values shown when they differ");
|
||||
eq(cadence(JSON.stringify({ idle: 500, busy: 500 })).sum(), "500 ms", "one value shown when equal");
|
||||
|
||||
let lastD = null;
|
||||
const M = {}, hist = {};
|
||||
let nowS = 0;
|
||||
eval(HIST_S_SRC + "\n" + SPARK);
|
||||
const xs = (d) => (d.match(/[ML]([0-9.]+)/g) || []).map((s) => parseFloat(s.slice(1)));
|
||||
console.log("== the sparkline's x axis is time, not sample index ==");
|
||||
M.k = { line: { setAttribute: (n, v) => { if (n === "d") lastD = v; } } };
|
||||
let pts = []; for (let i = 0; i < 60; i++) pts.push({ t: i, v: 50 + (i % 7) });
|
||||
spark("k", pts); let X = xs(lastD);
|
||||
eq(X.length, 60, "all 60 points drawn");
|
||||
ok(Math.abs(X[59] - 200) < 0.06, "newest sample sits on the right edge (got " + X[59] + ")");
|
||||
ok(Math.abs(X[0] - 200 * (1 - 59 / HS)) < 0.06, "oldest of a 59s span sits at its time position (got " + X[0] + ")");
|
||||
pts = []; for (let i = 0; i < 10; i++) pts.push({ t: i * 0.1, v: 1 });
|
||||
for (let i = 1; i <= 10; i++) pts.push({ t: 0.9 + i, v: 1 });
|
||||
spark("k", pts); X = xs(lastD);
|
||||
const ratio = (X[9] - X[0]) / (X[19] - X[0]);
|
||||
const want = 0.9 / 10.9;
|
||||
ok(Math.abs(ratio - want) < 0.01, "the busy stretch gets its 0.9s of the 10.9s span (got " + ratio.toFixed(4) + " want " + want.toFixed(4) + ")");
|
||||
ok(Math.abs(ratio - 0.5) > 0.2, "and NOT the 10/20 index-spacing answer 0.5 (got " + ratio.toFixed(4) + ")");
|
||||
console.log("== startup fills in from the right; a sample gap draws as a line gap ==");
|
||||
spark("k", [{ t: 100, v: 1 }, { t: 101, v: 2 }, { t: 102, v: 3 }]); X = xs(lastD);
|
||||
ok(X[0] > 190, "3 samples spanning 2s all sit near the right edge (leftmost x=" + X[0] + ")");
|
||||
spark("k", [{ t: 0, v: 1 }, { t: 1, v: 2 }, { t: 50, v: 3 }]); X = xs(lastD);
|
||||
ok(X[2] - X[1] > 10 * (X[1] - X[0]), "a 49s gap draws far wider than a 1s step");
|
||||
spark("k", [{ t: 1, v: 1 }, { t: 2, v: 2 }]); eq(lastD, "", "2 points draw nothing");
|
||||
console.log("== the prune is the SHIPPED setMetric, actually called ==");
|
||||
function shippedPrune(seed, nowSVal, value) {
|
||||
const Mm = { m: { n: { firstChild: { nodeValue: "" } }, line: { setAttribute: () => {} } } };
|
||||
const hh = { m: seed.slice() };
|
||||
new Function("M", "hist", "nowS", "spark", "HIST_S", SETMETRIC + "\nsetMetric('m', " + value + ", 'x');\nreturn hist;")(Mm, hh, nowSVal, () => {}, HS);
|
||||
return hh.m;
|
||||
}
|
||||
let fast = []; for (let i = 0; i < 600; i++) fast.push({ t: i * 0.1, v: 1 });
|
||||
let r = shippedPrune(fast, 60, 1);
|
||||
eq(r.length, 601, HS + "s of 100ms samples: nothing pruned, plus the sample just recorded");
|
||||
eq(r[r.length - 1].t, 60, "the new sample is stamped with nowS");
|
||||
let slow = []; for (let i = 0; i < 600; i++) slow.push({ t: i * 5, v: 1 });
|
||||
r = shippedPrune(slow, 3000, 1);
|
||||
eq(r.length, Math.ceil(HS / 5) + 1, HS + "s of 5s samples keeps " + Math.ceil(HS / 5) + " plus the new one, not 601");
|
||||
eq(r[0].t, 3000 - HS, "the oldest survivor is the first sample inside the window");
|
||||
let edge = []; for (let i = 0; i < 5; i++) edge.push({ t: 1000 + i, v: 1 });
|
||||
eq(shippedPrune(edge, 1000 + HS, 1).length, 6, "a sample exactly at nowS-HIST_S survives (exclusive <)");
|
||||
eq(shippedPrune(edge, 1001 + HS, 1).length, 5, "one second later that same sample is pruned");
|
||||
r = shippedPrune([{ t: 10, v: 1 }], 1005, "null");
|
||||
eq(r.length, 1, "a null reading records nothing and prunes nothing");
|
||||
eq(r[0].t, 10, "the earlier sample is untouched");
|
||||
console.log(fails ? "\n" + fails + " FAILURE(S) of " + checks : "\nALL " + checks + " CHECKS PASS on the shipped page JS");
|
||||
process.exit(fails ? 1 : 0);
|
||||
Reference in new issue
Block a user