Archived
The history summary row had grown crowded -- the figures, then a "json" button and a "clear" button -- and the operator asked for the export to live in the Requests panel header instead, top-left by the title, as a download icon with a "Download JSON file" tooltip. The Requests header already carries running/waiting on the right, so the export sits opposite it on the left rather than lumped in with the history figures. The button is an inline SVG download glyph (a <button>, so it is keyboard-focusable and announced), in a new .pleft group so the space-between header keeps it on the left with the title. The handler now saves a file rather than copying to the clipboard: a Blob of the stored rows, an anchor with a download name, clicked and removed, the object URL revoked after the click. The old #hjson clipboard button is gone. This also fixes a clipping bug the previous commit introduced. Making each category a nowrap span and the separator a padded element removed every whitespace text node between categories, so the summary line became one unbreakable run: a long line overflowed the row and clipped the buttons after it -- the "json" the operator saw cut off at the panel edge. A zero-width space between groups restores a break opportunity: the line can now wrap between categories, while each category still stays atomic. The break point sits between groups, never inside one, where nowrap would make it inert. tests/js/download.test.js, 27 checks, drives the shipped handler against stubs: the button is in the Requests header on the left of the aside, exactly one of them (a duplicate id would bind only the first and leave a dead control), tooltip and aria-label present, an icon not a text label; the handler builds one anchor, names it radiance-history.json, types the blob application/json, clicks it, attaches it to the document (Firefox needs that), removes it, and revokes the object URL only after the click. The payload round-trips through JSON.parse. history.test.js gained the break-point checks: three zero-width spaces between four categories, each immediately before its group, none buried inside a nowrap group. Verified by mutation: dropping the download attribute, never clicking, never revoking, a wrong blob type, changed tooltip text, and moving the button to the right of the aside each fail the suite. extremes 27, poll_spark 35, history 29, download 27, dashboard_test 241 over 8 cases, sched_test 62646 over 184, no failures. Not deployed. Goes to review with the separator commits. Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
125 lines
7.7 KiB
JavaScript
125 lines
7.7 KiB
JavaScript
/* The history summary line: how it groups, and how it wraps.
|
|
*
|
|
* The line packs several categories into one strip -- a count, tok/s, prefill, ttft -- and each
|
|
* category carries its own figures. Two rules the page must keep:
|
|
*
|
|
* a category is ATOMIC. If it does not fit on the line it moves whole to the next line. It
|
|
* must never break mid-figure: "810" at the end of one line and "ms" on the next is worse
|
|
* than the wrap it replaced.
|
|
* the category break is a DOT and the break between figures inside one category is a PIPE.
|
|
*
|
|
* Both rules are structural, not string-level: HTML collapses runs of spaces, so the width of a
|
|
* category break cannot come from spaces in the joined string. It comes from a padded element.
|
|
* That is why these checks inspect the DOM the shipped code builds rather than the string it
|
|
* used to build -- a string assertion here would have passed while the page rendered wrong. */
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const src = require("./page.js"); // the page's <script> block
|
|
/* The CSS lives in the <style> block, which page.js does not return (the JS tests have no
|
|
reason to read it). Read it from the same shipped file rather than widen page.js's export and
|
|
break the two suites that treat its result as a plain string. */
|
|
const cpp = fs.readFileSync(path.join(__dirname, "..", "..", "core", "server", "dashboard.cpp"), "utf8");
|
|
const css = (cpp.match(/<style>([\s\S]*?)<\/style>/) || [, ""])[1];
|
|
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");
|
|
}
|
|
|
|
console.log("== the CSS makes a category atomic and the break actually wide ==");
|
|
const grpCss = css.match(/#hist \.hgrp \{([^}]*)\}/);
|
|
ok(css.length > 200, "read the page <style> block (" + css.length + " chars)");
|
|
ok(grpCss, "#hist .hgrp rule exists");
|
|
ok(/white-space:\s*nowrap/.test(grpCss ? grpCss[1] : ""), "a category cannot break mid-figure");
|
|
const sepCss = css.match(/#hist \.hsep \{([^}]*)\}/);
|
|
ok(sepCss, "#hist .hsep rule exists");
|
|
ok(/padding:\s*0\s+\d+px/.test(sepCss ? sepCss[1] : ""), "the category break gets width from padding, not spaces");
|
|
const pad = sepCss ? +sepCss[1].match(/padding:0 (\d+)px/)[1] : 0;
|
|
ok(pad >= 4, "the padding is wide enough to read as a break (" + pad + "px, want >= 4)");
|
|
|
|
console.log("== the shipped summary assembly builds one atomic group per category ==");
|
|
/* Slice ONLY the summary-line assembly (mean/group -> the forEach that fills #hsum), not the
|
|
whole renderer: the rest of histRender draws the table and needs a dozen module globals that
|
|
have nothing to do with how the line groups or wraps. */
|
|
const si = L.findIndex((x) => x.startsWith(" const mean = (a) =>"));
|
|
if (si < 0) throw new Error("no summary start");
|
|
const ai = L.findIndex((x, k) => k > si && x.includes("hsum.appendChild(g);"));
|
|
if (ai < 0) throw new Error("no assembly anchor");
|
|
let ei = -1;
|
|
for (let k = ai; k < L.length; k++) if (L[k] === " });") { ei = k; break; }
|
|
if (ei < 0) throw new Error("no assembly end");
|
|
const BLOCK = L.slice(si, ei + 1).join("\n");
|
|
ok(BLOCK.includes("hgrp") && BLOCK.includes("hsep"), "slice captured the grouping code (" + BLOCK.length + " chars)");
|
|
|
|
function mk(tag, cls, txt) {
|
|
const o = { tag, cls, _t: txt || "", kids: [],
|
|
appendChild(c) { this.kids.push(c); return c; },
|
|
set textContent(v) { this._t = v; if (v === "") this.kids = []; },
|
|
get textContent() { return this._t || ""; } };
|
|
Object.defineProperty(o, "txt", { get() { return o._t || ""; } });
|
|
return o;
|
|
}
|
|
const hsum = mk("span", "hsum");
|
|
const el = (t, c, x) => mk(t, c, x);
|
|
const doc = { createTextNode: (t) => ({ tag: "#text", cls: null, txt: t }) };
|
|
const rows = [];
|
|
for (let i = 0; i < 24; i++) rows.push({ tps: 200 + (i % 9), pf: 690 + (i % 5), ttft: 810, age: i * 3 });
|
|
new Function("el", "document", "$", "hRows", "tps", "cnt3", "dur", BLOCK)(
|
|
el, doc, () => hsum, rows,
|
|
(v) => Math.round(v) + " t/s", (v) => String(Math.round(v)), (v) => v + " ms");
|
|
|
|
/* #hsum now holds the four category groups AND the zero-width-space break points between them,
|
|
so select by class rather than assuming every child is a group. */
|
|
const groups = hsum.kids.filter((k) => k.cls === "hgrp");
|
|
const zwsps = hsum.kids.filter((k) => k.tag === "#text" && k.txt === "\u200b");
|
|
eq(groups.length, 4, "four categories: count, tok/s, prefill, ttft");
|
|
console.log("== the line has a break point, so a long summary wraps instead of clipping ==");
|
|
/* The groups are nowrap; without a break opportunity between them the whole line is one
|
|
* unbreakable run that overflows the row and clips whatever follows it. */
|
|
eq(zwsps.length, 3, "a zero-width break point between each pair of categories");
|
|
ok(hsum.kids.every((k) => k.cls === "hgrp" || (k.tag === "#text" && k.txt === "\u200b")),
|
|
"#hsum holds only groups and break points, nothing else");
|
|
/* The break point must sit BETWEEN groups, not inside one: a ZWSP inside a nowrap span cannot
|
|
* break, so it would buy nothing. */
|
|
for (let i = 1; i < groups.length; i++) {
|
|
const first = hsum.kids.indexOf(groups[i]);
|
|
eq(hsum.kids[first - 1].txt, "\u200b", "break point immediately precedes category " + i);
|
|
}
|
|
ok(!JSON.stringify(groups.map((g) => g.kids)).includes("\u200b"),
|
|
"no break point buried inside a nowrap group, where it could not act");
|
|
console.log("== the dot introduces its category and travels with it ==");
|
|
eq(groups[0].kids.filter((k) => k.cls === "hsep").length, 0, "the first category carries no leading dot");
|
|
[1, 2, 3].forEach((i) => {
|
|
const seps = groups[i].kids.filter((k) => k.cls === "hsep");
|
|
eq(seps.length, 1, "category " + i + " carries exactly one dot");
|
|
eq(groups[i].kids[0].cls, "hsep", "the dot is the FIRST child of its own group, not a sibling of it");
|
|
eq(groups[i].kids[0].txt, "\u00b7", "and it is a middle dot, not a pipe");
|
|
});
|
|
console.log("== within a category the fields are separated by pipes ==");
|
|
const textOf = (g) => g.kids.map((k) => (k.txt || "")).join("");
|
|
/* The category's own text, excluding the leading dot that introduces it (that dot is the
|
|
category BREAK and is SUPPOSED to be a dot; "no dot inside" is about the figures. */
|
|
const ownText = (g) => g.kids.filter((k) => k.cls !== "hsep").map((k) => k.txt || "").join("");
|
|
const tpsGroup = textOf(groups[1]);
|
|
const tpsOwn = ownText(groups[1]);
|
|
ok(tpsGroup.includes("|"), "tok/s separates mean / last 20 / last 5 with pipes: " + JSON.stringify(tpsGroup));
|
|
ok(!tpsOwn.includes("\u00b7"), "no dot among a category's own figures (the dot means category change): " + JSON.stringify(tpsOwn));
|
|
ok(/last 20:.*\|.*last 5:/.test(tpsGroup), "both windows present and pipe-separated");
|
|
console.log("== nothing can orphan a unit ==");
|
|
/* The failure this exists to prevent: "ttft median 810" ending a line and "ms" starting the next.
|
|
* That happens when the value and its unit are separate wrap opportunities. */
|
|
const ttft = textOf(groups[3]);
|
|
const ttftGroup = groups[3];
|
|
const textNodes = ttftGroup.kids.filter((k) => k.cls !== "hsep");
|
|
eq(textNodes.length, 1, "the ttft category is a single text node, so value and unit cannot split");
|
|
ok(/ttft median \d+ ms$/.test(textNodes[0].txt), "value and unit are one string: " + JSON.stringify(textNodes[0].txt));
|
|
console.log(fails ? "\n" + fails + " FAILURE(S) of " + checks : "\nALL " + checks + " CHECKS PASS on the shipped history line");
|
|
process.exit(fails ? 1 : 0);
|