This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/js/extremes.test.js
T
Memoria (Noblistic) 757ad11b0d dashboard: separate distinct fields with pipes, not middle dots
Every line that packs several distinct figures into one string used the middle dot, at two
weights -- a tight dot between sub-figures and a wide one between groups. At 11px the dot is
too short to read as a boundary, so lines like the history summary ran together: count, three
tok/s figures, three prefill figures and ttft all sat at one visual level. The operator's call
was to use the pipe wherever fields are meant to be distinct.

Fifty-eight separators converted across the page -- the history summary, the version line, the
KV and expert asides, the acceptance and step-time detail lines, the graph and model-view
metadata, the control-vector summary, the poll summary. The two weights are kept: a tight dot
becomes a tight pipe, a wide dot a wide pipe, so the group-versus-window hierarchy the wide
dot carried survives the glyph change.

Two dots stay, because they are not field separators: the CSS list-bullet marker
(.gmeta li::before content) and the browser tab title (file - radiance). The range dash in
"layers 1-8" and the DASH placeholder are likewise untouched. The two " + " the earlier
census turned up are inside pctn building "<0.1" and ">99.9" string literals, not separators.

The sweep missed eight separators at first: the age clause and several detail lines build
their separator as the escape "\u00b7" rather than a literal dot, and a literal replace
never sees those. Caught because the tests that pin the age clause went red on the literal
sites but the escaped ones did not -- a partial conversion that would have shipped a page
with pipes and dots mixed. Both forms are now converted.

Tests: the two regexes pinning the age clause and the one string pinning the poll summary
now expect the pipe. They failed when the code changed and pass now, which is the point --
a separator assertion that could not fail would not have caught the escaped-dot miss.
extremes.test.js 27, poll_spark.test.js 35, dashboard_test 241 over 8 cases, sched_test
62646 over 184, no failures.

GUIDE's two example triple lines, which mirror the page's separators, updated to match.

Verified the sweep by reading all 58 changed lines, not by trusting the count: no pipe landed
inside a regex literal (where it would mean alternation) or a prose tooltip. Both hazard
greps were positive-controlled against known-bad input before their empty result was trusted.

Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
2026-11-03 18:09:49 +01:00

179 lines
9.9 KiB
JavaScript

/* Session extremes: the age clause, and the gap/restart split. Executes the shipped
noteSample / triple / acceptTriple / resetWindows / newEngineRun / poll, sliced by line
range out of the page and CALLED -- defining a sliced function proves nothing.
pctn/pct are the SHIPPED formatters rather than a re-typed stand-in: a copy of a formatter
drifts from the real one, and an assertion on its output then silently means nothing.
nowS is declared here because in the page it is module-level, so it is 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 COMMON = [
"let nowS = 0;",
'const DASH = "\\u2013";',
"const finite = (v) => v != null && isFinite(v);",
/* resetWindows() clears these; they are not under test but it READS them. */
"const hist = {}, moveHist = { up: [], down: [] };",
"let prev = null, prevAt = 0, accPrev = null;",
lines("function pctn(", "}"),
lines("const pct =", "const pct ="),
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", COMMON + "\nbox.api={noteSample,triple,acceptTriple,resetWindows,newEngineRun,extAt,winAt,extAtS,accPool,setNow:(v)=>{nowS=v;}};")(box);
return box.api;
}
const F = (v) => v + " t/s";
async function main() {
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("== the stamp marks when the EXTREME was set, not when anything was sampled ==");
/* Re-sampling a key with a WORSE value must not refresh the stamp: the age belongs to the
figure on the left. Refreshing it on every sample makes every age read ~0 -- wrong output,
not missing output, which is the hardest kind of defect for a label to survive. */
b = fresh(); b.setNow(100); b.noteSample("dec", 1, 500, 15, false);
b.setNow(200); b.noteSample("dec", 1, 400, 15, false); /* not a new extreme */
b.setNow(260);
out = b.triple("dec", 1, "best", F);
ok(out.includes("best 500"), "the extreme is still the earlier, better figure (got " + JSON.stringify(out) + ")");
ok(out.includes("2m 40s ago"), "age is measured from the extreme, not the last sample (got " + JSON.stringify(out) + ")");
b.setNow(300); b.noteSample("dec", 1, 900, 15, false); /* a NEW extreme */
b.setNow(330);
out = b.triple("dec", 1, "best", F);
ok(out.includes("best 900") && out.includes("30.0 s ago"), "a new extreme restamps (got " + JSON.stringify(out) + ")");
console.log("== acceptTriple's age clause is exercised on a LIVE extreme ==");
/* The restart case below clears extAt first, so acceptTriple returns at its guard and never
reaches the clause. Nothing else drove it, so the clause could be deleted unnoticed. */
b = fresh(); b.setNow(100); b.noteSample("accept", 1, 0.75, 15, false);
b.setNow(100.5);
ok(!b.acceptTriple(1).includes("ago"), "an acceptance extreme set 0.5s ago is current: no clause (got " + JSON.stringify(b.acceptTriple(1)) + ")");
b.setNow(400);
out = b.acceptTriple(1);
ok(/^highest 75% \| 5m 00s ago$/.test(out), "once it stands alone it names its age (got " + JSON.stringify(out) + ")");
b.accPool[1] = [{ dr: 10, da: 8 }, { dr: 10, da: 6 }];
out = b.acceptTriple(1);
ok(out.includes("recent") && !out.includes("ago"), "with a ring: window figures, no age clause (got " + JSON.stringify(out) + ")");
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");
/* ------------------------------------------------------------------ poll() itself
* The restart DETECTION lives in poll(), not in newEngineRun(). Calling newEngineRun() directly
* proves only that the function clears things -- deleting the detection line in poll() would
* leave every such assertion green. So drive poll() with a scripted /stats sequence and assert
* what it decides. resetWindows / newEngineRun / update are replaced with counters here on
* purpose: this is testing the decision, not the clearing (covered above). */
const POLL = lines("async function poll() {", "}");
function makePoller(seq, clock) {
const body = COMMON + "\n" + [
"let lastPollAt = 0;",
"const GAP_S = 60; let pollIdleMs = 500;",
"const calls = { run: 0, gap: 0, update: 0 };",
"function resetWindows() { calls.gap++; }",
"function newEngineRun() { calls.run++; }",
"function update() { calls.update++; }",
"function schedulePoll() {}",
"function pollCadence() { return 500; }",
"const els = {};",
"function $(id) { return els[id] || (els[id] = { hidden: false, className: \"\", classList: { remove() {} } }); }",
"let i = 0;",
"async function api() { const s = seq[Math.min(i++, seq.length - 1)]; return { ok: true, json: async () => JSON.parse(JSON.stringify(s)) }; }",
POLL,
"return { poll, calls };",
].join("\n");
return new Function("document", "performance", "Date", "seq", "clock", body)(
{ hidden: false }, { now: () => 0 }, { now: () => clock.wall }, seq, clock);
}
const fixed = { wall: 1000 }; /* a fixed clock keeps the GAP path out of these assertions */
console.log("== poll() detects a new engine process ==");
let p = makePoller([
{ started_at: 100, uptime_s: 10 }, /* first poll: baseline, clears nothing */
{ started_at: 100, uptime_s: 20 }, /* same process, uptime rising: nothing happens */
{ started_at: 200, uptime_s: 5 }, /* started_at moved: a new process */
], fixed);
await p.poll(); eq(p.calls.run, 0, "the first poll is a baseline, not a restart");
await p.poll(); eq(p.calls.run, 0, "same started_at with a rising uptime is the same process");
await p.poll(); eq(p.calls.run, 1, "a changed started_at clears the extremes");
console.log("== uptime_s is derived, so it is not a restart signal ==");
/* uptime_s is unix_now() - started_at_, both whole seconds, so started_at + uptime_s is exactly
the wall clock at that poll. A later poll of the SAME process therefore always reports a
larger uptime; a smaller one means the wall clock moved backwards, which is an NTP adjustment
and not a new process. Clearing on it would throw away the session's extremes on a clock
correction, so nothing here treats it as a restart. */
p = makePoller([
{ started_at: 100, uptime_s: 40 },
{ started_at: 100, uptime_s: 2 }, /* same started_at, uptime went backwards */
], fixed);
await p.poll(); await p.poll();
eq(p.calls.run, 0, "a backward uptime with an unchanged started_at is a clock step, not a restart");
console.log("== poll() takes the GAP path, not the restart path, when only the clock moved ==");
const slow = { wall: 1000 };
p = makePoller([{ started_at: 100, uptime_s: 10 }, { started_at: 100, uptime_s: 130 }], slow);
await p.poll();
slow.wall = 1000 + 90 * 1000; /* 90s with nothing polled: a gap */
await p.poll();
eq(p.calls.gap, 1, "a long quiet span clears the windows");
eq(p.calls.run, 0, "and is NOT read as a restart: the extremes survive it");
}
main().then(() => {
console.log(fails ? "\n" + fails + " FAILURE(S) of " + checks : "\nALL " + checks + " CHECKS PASS on the shipped extreme code");
process.exit(fails ? 1 : 0);
});