gui: Routing is back to v0.1.1231's layout; reverts dae2618ad (#1354)

v0.1.1233 shipped community PR #1354 (dae2618ad), which put "How the
last request was routed" in a right column beside the stage on wide
windows, split the context card into overview/contents columns, and
replaced the context card's own head with one lazily built disclosure
header. Two users on Discord asked for the old page back: wongxy
("这是哪个人才要改成这样的,丑死了", "UI方面的需求响应要克制一点", with a
screenshot of the new page) and molvqingtai ("v0.1.1231 没有这个问题").
The owner delegated the call: Routing goes back to v0.1.1231's look.

Only the lazy construction of the context body was a candidate to keep,
as it is invisible. It doesn't separate cleanly: it is built on the new
unified header (ctxSummary in the closed state, ctx-body/ctx-overview in
the open one), which is itself the visible change. So this reverts
dae2618ad whole: assets, its doc section, its README entry, the new
routing-context-layout test, and the test edits that existed only for
the new layout (wheel-scrolling to rows the right column pushed down,
mobile-web's skip of Routing in the pixel comparison). No later commit
on main is a follow-up of it.

Later commits touching the same files are kept: 20350dafa's subagent
reason in routing.js and README entry, a7a38193f/5fc2f87d1's gui-shell.md
lines, 00afcf97a's README entry. routing.css and context.js are now
byte-identical to v0.1.1231; routing.js differs only by later features
(#1068 folders, subagent reasons).

Run (worktree on origin/main 3ec45e715 + this revert):
- Routing page screenshots against v0.1.1231's assets with one counted
  request (the .rt card): Chromium and WebKit, en/zh/zh-TW/ja/de, 1100
  and 420 wide, plus 1440/1800 in en/zh: 0 pixels differ in all 28.
  origin/main differs in all of them (the folded header, the columns).
- node --test routing-*, panel-routing*, group-fold, held-animations,
  phone-rows, context-*: 1025 of 1034 pass. The 9 reds are
  routing-keys-fold's "a request that comes flies to the fold" (WebKit,
  and Chromium de) and routing-model-rest's "Try now" reach. Both files
  run alone fail the same way on origin/main bda271999 (12 fails there,
  11 here, different cases of model-rest each run), at load average
  ~350 from other sessions; filed as #1612 and #2115.
- mobile-web (pixel baseline) with BASE_REF=dae2618ad^: every phone
  case and Routing's desktop compare pass; the 8 reds are all Settings,
  changed since by #2073's colorblind switch, not by this.
- gofmt -l, go vet (darwin, linux nogui, windows) and
  go test -tags nogui ./internal/gui pass.
Not tried: the native Wails window; the complete GUI suite.
This commit is contained in:
yetone
2026-10-14 18:07:59 +08:00
parent 60fa582c80
commit bfef5d51b5
16 changed files with 114 additions and 504 deletions
-33
View File
@@ -33,39 +33,6 @@ three.
## Constraints and failure behavior
### Routing context header and wide layout
Routing keeps its descriptive request heading, visible stage caption and
full request story. At 1100px card width the stage and caption share the
upper left column, with the story on the right. The page keeps its shared
1200px content cap. Context stays below both columns. Its overview and
content list share a row from 800px, using the same split so the separators
align; the content label and scrollable filters remain on one line, and a
long list scrolls within the card. Smaller cards stack these regions.
A request with prompt data has one clickable context header. Closed, it
shows used/window tokens, fill, cache and the occupancy bar; the grid and
content rows are not constructed until opened. Open, the counts appear in
the body, without a second header. The preference is stored separately as
`magpie.routingContext`; an absent preference reads the existing
`magpie.ctxShut` choice. An opening from Usage's Context tab applies to one
request without replacing the saved choice. The next selected request
restores it. Clicking the header keeps its position, and its preference
survives incoming requests and reloads.
The existing live context patching, cache state, text viewer and Routing
story's node and logo retention remain in use. An open card retains its
cells and unchanged rows while a new prompt arrives. The fixed grid row
height bounds the space used by unused tokens. Usage context cards keep
their existing header and layout.
While a new live prompt is still being read, the carried context remains
available for opening and closing without removing the card.
See `routing-context-layout.test.cjs`, `routing-context-fold.test.cjs`,
`routing-ctx-fold.test.cjs`, `routing-live-patch.test.cjs` and
`routing-ctx-still.test.cjs`; `routing-log-icons.test.cjs` guards main's
live story and logo retention in both engines and all five languages.
### Streamed output speed
Usage rows and aggregates use `Record.Decode` and `DecodeOf` in
+20 -80
View File
@@ -82,74 +82,6 @@
return { read: u.cache_read || 0, total };
}
// Routing's closed card uses the same counts, health and final-attempt
// cache as the full card, including the estimate while a request runs.
function ctxState(r) {
const p = r.prompt, live = !r.done;
// Keep the pill as wide as its widest state in this language, on
// both the shared card and Routing's unified header.
const state = live ? "live" : p.counted ? "counted" : "est";
const st = el("span", "ctx-state " + state), words = el("span", "ctx-state-w");
for (const [k, w] of [["live", "Live"], ["counted", "Counted"], ["est", "Estimated"]]) {
const word = el("span", k === state ? "on" : "", t(w));
if (k !== state) word.setAttribute("aria-hidden", "true");
words.append(word);
}
st.append(el("i"), words);
st.title = t(live ? "The request is on its way: the prompt is estimated from what the agent sent"
: p.counted ? "As many tokens as the vendor counted; the parts are measured from the request and scaled to it"
: "Estimated from what the agent sent: the vendor didn't say how many tokens it read");
return st;
}
function ctxStack(p) {
const window = p.window || 0, bar = el("span", "ctx-stack");
bar.setAttribute("role", "img");
bar.setAttribute("aria-label", t("{used} of {window} tokens used", { used: fmtK(p.tokens), window: fmtK(window || p.tokens) }));
const scale = Math.max(window, p.tokens, 1);
for (const k of PARTS) {
const n = p.parts.find((x) => x.kind === k)?.tokens || 0;
const i = el("i", "k-" + k);
i.title = partName(k);
i.style.width = +(Math.max(0, n) / scale * 100).toFixed(2) + "%";
bar.append(i);
}
return bar;
}
function ctxSummary(r, open = false, into = null) {
const p = r.prompt, window = p.window || 0;
const summary = el("span", "ctx-summary");
summary.append(el("span", "ctx-title", t("Context window")));
if (open) {
summary.append(el("span", "grow"), ctxState(r));
} else {
const figures = el("span", "ctx-summary-numbers");
summary.append(figures);
const used = el("span", "ctx-summary-used");
used.append(el("b", "", fmtK(p.tokens)), window ? " / " + fmtK(window) : " " + t("tokens"));
used.title = t(p.counted ? "Counted" : "Estimated");
figures.append(used);
if (window) {
const fill = p.tokens / window, [tone, word] = health(fill);
const h = el("span", "ctx-health " + tone, pct(fill));
h.title = t(word) + " · " + t("{tokens} free", { tokens: fmtK(Math.max(0, window - p.tokens)) });
figures.append(h);
}
if (!p.counted || !r.done) figures.append(el("span", "ctx-summary-est", t(!r.done ? "Live" : "Estimated")));
const cache = cacheOf(r);
if (cache && p.counted !== false) figures.append(el("span", "ctx-summary-cache", t("Cache") + " " + pct(cache.read / cache.total)));
summary.append(ctxStack(p));
}
// A disclosure changes what the head contains. Reusing its figures as
// the empty spacer would make the click guard follow that child's new
// position, even though the head itself stayed put.
if (into && !!into.querySelector(".ctx-summary-numbers") === open) {
into.replaceChildren(...summary.childNodes);
return into;
}
return into ? morph(into, summary) : summary;
}
window.ctxSummary = ctxSummary;
// the cells of the grid, each the part and item it shows; a window
// smaller than the prompt (not known, or overrun) is the prompt
function cellsOf(p, window) {
@@ -305,9 +237,7 @@
// Usage page's Context tab), so it shows unfolded, it alone: the next
// request drawn in the card takes the reader's choice again
function ctxCard(r, opts = {}) {
const headless = !!opts.headless;
const card = el("div", (headless ? "ctx-body" : "ctx-card") + (opts.foldable && ctxShut && !opts.open ? " shut" : ""));
const overview = headless ? el("div", "ctx-overview") : card;
const card = el("div", "ctx-card" + (opts.foldable && ctxShut && !opts.open ? " shut" : ""));
card.dataset.place = opts.place || "";
if (cardWidth[card.dataset.place] !== undefined) sizeCard(card, cardWidth[card.dataset.place]);
cardSizes.observe(card);
@@ -455,6 +385,22 @@
};
title = fold;
}
// the state's words are all there, one shown: the pill is as wide as
// the widest in any language, so the model beside it doesn't move as
// a request goes from Live to Counted (dumplings on Discord: each
// request made the card jitter)
const state = live ? "live" : p.counted ? "counted" : "est";
const st = el("span", "ctx-state " + state);
const words = el("span", "ctx-state-w");
for (const [k, w] of [["live", "Live"], ["counted", "Counted"], ["est", "Estimated"]]) {
const word = el("span", k === state ? "on" : "", t(w));
if (k !== state) word.setAttribute("aria-hidden", "true");
words.append(word);
}
st.append(el("i"), words);
st.title = t(live ? "The request is on its way: the prompt is estimated from what the agent sent"
: p.counted ? "As many tokens as the vendor counted; the parts are measured from the request and scaled to it"
: "Estimated from what the agent sent: the vendor didn't say how many tokens it read");
head.append(title);
if (opts.foldable) {
head.append(el("span", "ctx-short", fmtK(p.tokens) + (window ? " / " + fmtK(window) + " · " + pct(full) : "")));
@@ -475,7 +421,7 @@
}
head.append(el("span", "grow"));
if (r.model) head.append(el("code", "ctx-model", r.model));
head.append(ctxState(r));
head.append(st);
// how full, and the cache
const top = el("div", "ctx-top");
@@ -602,18 +548,12 @@
if (!parts) {
parts = { head, top, legend, foot, sp };
if (headless) {
overview.append(top, grid, legend, foot, ...(sp ? [sp] : []));
card.append(overview, contents, tip);
} else card.append(head, top, grid, legend, contents, foot, ...(sp ? [sp] : []), tip);
card.append(head, top, grid, legend, contents, foot, ...(sp ? [sp] : []), tip);
return;
}
for (const k of ["head", "top", "legend", "foot"]) parts[k] = morph(parts[k], { head, top, legend, foot }[k]);
if (sp && parts.sp) parts.sp = morph(parts.sp, sp);
else if (sp) {
parts.sp = sp;
if (headless) overview.append(sp); else card.insertBefore(sp, tip);
}
else if (sp) card.insertBefore(parts.sp = sp, tip);
else if (parts.sp) { parts.sp.remove(); parts.sp = null; }
};
card.ctxUpdate = fill;
+4 -50
View File
@@ -1,9 +1,7 @@
/* Routing, live: the Gateway view's stage for what routing does with each
request (routing.js). The same stage as the site's Model Routing, only
played by the gateway's own trace. */
#view-routing { overflow-y: scroll; }
#view-routing > .row-head, #view-routing > .rt { flex-shrink: 0; }
.rt { --rt-columns: minmax(0, 1fr) minmax(0, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 12px; margin: 0 0 18px; }
.rt { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 12px; margin: 0 0 18px; }
.rt-top { display: flex; flex-direction: column; gap: 3px; }
.rt-what { font-size: 13px; color: var(--muted); }
.rt-what b { color: var(--fg); font-weight: 600; }
@@ -121,50 +119,6 @@
.rt-log { padding-top: 10px; margin-top: 10px; border-top: 1px solid var(--line); }
.rt-log-head { display: flex; align-items: center; font-size: 12px; font-weight: 600; color: var(--fg); }
.rt-log-head .grow { flex: 1; }
/* Context sits below both upper columns, and its own columns use
the same split so a tall content list cannot leave the stage empty. */
.rt-main, .rt-log { min-width: 0; }
.rt > .rt-ctx { margin-top: 12px; }
.rt.min1100 .rt-main { display: grid; grid-template-columns: var(--rt-columns); column-gap: 24px; align-items: start; }
.rt.min1100 .rt-top, .rt.min1100 .rt-replay { grid-column: 1 / -1; }
.rt.min1100 .rt-stage { grid-column: 1; grid-row: 3; column-gap: 36px; }
.rt.min1100 .rt-foot { grid-column: 1; grid-row: 4; }
.rt.min1100 .rt-log { grid-column: 2; grid-row: 3 / 5; margin-top: 16px; padding: 0 0 0 24px; border-top: 0; border-left: 1px solid var(--line); }
.rt.min1100 .rt-off { grid-column: 1 / -1; }
.rt-ctx-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rt-ctx-toggle > svg { flex: none; }
.rt-ctx-toggle[aria-expanded="true"] > svg { transform: rotate(180deg); }
.rt-ctx { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 12px; font-variant-numeric: tabular-nums; }
.rt-ctx-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; padding: 3px 0; background: none; border: 0; border-radius: 4px; color: var(--fg); }
.rt-ctx-toggle > svg { opacity: .5; }
.rt-ctx-toggle:hover > svg { opacity: 1; }
.ctx-summary { flex: 1; display: flex; align-items: center; gap: 6px 10px; min-width: 0; height: 20px; white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.ctx-summary .ctx-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ctx-summary-numbers { display: flex; align-items: center; gap: inherit; flex: none; }
.ctx-summary .ctx-stack { display: flex; }
.rt:not(.min800) .ctx-summary { gap: 6px; font-size: 11px; }
.rt:not(.min800) .ctx-summary .ctx-stack { min-width: 12px; }
.ctx-summary .grow { flex: 1; }
.ctx-summary .ctx-title { font-size: 12px; }
.ctx-summary-used { color: var(--muted); white-space: nowrap; }
.ctx-summary-used b { color: var(--fg); font-weight: 600; }
.ctx-summary-est, .ctx-summary-cache { font-size: 11px; color: var(--muted); white-space: nowrap; }
.rt-ctx-detail, .rt-ctx-detail .ctx-body { min-width: 0; }
.rt-ctx-detail .ctx-body { position: relative; display: flex; flex-direction: column; gap: 16px; }
.rt-ctx-detail .ctx-overview { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.rt-ctx-detail .ctx-waffle { grid-template-columns: repeat(50, minmax(0, 1fr)); grid-auto-rows: 7px; }
.rt-ctx-detail .ctx-waffle > i { aspect-ratio: auto; animation: none; }
.rt-ctx-detail .ctx-bar i { animation: none; }
.rt-ctx-detail .ctx-contents-head { flex-wrap: nowrap; }
.rt-ctx-detail .ctx-contents-head .ctx-k { flex: none; }
.rt-ctx-detail .ctx-contents-head .grow { display: none; }
.rt-ctx-detail .ctx-contents-head .segs { flex: 0 1 auto; min-width: 0; margin-left: auto; }
.rt-ctx-detail .ctx-contents-head .segs .opt { padding: 0 7px; }
.rt-ctx-detail .ctx-rows { max-height: 234px; overflow-y: auto; overscroll-behavior: contain; padding: 0 6px; margin: 0 -6px; }
.rt.min800 .rt-ctx-detail .ctx-body { display: grid; grid-template-columns: var(--rt-columns); gap: 24px; }
.rt.min800 .rt-ctx-detail .ctx-contents { min-width: 0; padding: 0 0 0 24px; border-top: 0; border-left: 1px solid var(--line); }
.rt-ctx-detail .ctx-body.max420 :is(.ctx-mini, .ctx-tag) { display: none; }
.rt-ctx-detail .ctx-body.max520 .ctx-top { gap: 12px; }
.rt-steps { list-style: none; margin: 6px 0 0; padding: 0; display: grid; align-content: start; gap: 5px; counter-reset: rt; }
.rt-steps li { position: relative; padding-left: 20px; font-size: 12.5px; line-height: 1.45; color: var(--fg-2); }
.rt-steps li::before { content: ""; position: absolute; left: 5px; top: .5em; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
@@ -198,12 +152,12 @@
.rt-accts:where(.max460) li.rt-fold .chev { grid-column: 3; grid-row: 1; }
/* narrow (the tray panel): magpie and the agent side by side, the
accounts under them, on a lane down their left */
:where(.rt-main.max560) .rt-stage { grid-template-columns: 1fr 1fr; column-gap: 28px; row-gap: 26px; padding: 16px 0; }
:where(.rt-main.max560) .rt-accts { grid-column: 1 / -1; padding-left: 22px; }
:where(.rt.max560) .rt-stage { grid-template-columns: 1fr 1fr; column-gap: 28px; row-gap: 26px; padding: 16px 0; }
:where(.rt.max560) .rt-accts { grid-column: 1 / -1; padding-left: 22px; }
.rt-accts:where(.max560) li { grid-template-columns: 10px minmax(0, 1fr); }
.rt-accts:where(.max560) em { grid-column: 2; white-space: normal; }
.rt-accts:where(.max560) .bar { grid-column: 2; }
:where(.rt-main.max560) .rt-stats { gap: 14px; }
:where(.rt.max560) .rt-stats { gap: 14px; }
/* the Routing view */
#view-routing .row-head { margin: 14px 0 6px; padding: 0 2px; gap: 0; }
#view-routing .row-head .note { font-size: 11px; color: var(--faint); margin-left: 8px; }
+20 -63
View File
@@ -67,33 +67,12 @@
stats.append(s);
}
foot.append(cap, stats);
const main = el("div", "rt-main");
const log = el("div", "rt-log");
const logHead = el("div", "rt-log-head");
const steps = el("ol", "rt-steps");
// what the request's prompt held: its context window (context.js)
const ctxBox = el("div", "rt-ctx");
ctxBox.hidden = true;
const ctxToggle = el("button", "ctx-head rt-ctx-toggle");
ctxToggle.type = "button";
ctxToggle.dataset.unrolls = "";
const ctxDetail = el("div", "rt-ctx-detail");
ctxDetail.id = "rtContextDetails";
ctxToggle.setAttribute("aria-controls", ctxDetail.id);
ctxBox.append(ctxToggle, ctxDetail);
let contextOpen = false;
try {
const pref = localStorage.getItem("magpie.routingContext");
contextOpen = pref !== null ? pref === "1" : localStorage.getItem("magpie.ctxShut") === "0";
} catch {}
ctxToggle.onclick = () => {
contextOpen = !(contextOpen || !!ctxFor);
ctxFor = 0;
try { localStorage.setItem("magpie.routingContext", contextOpen ? "1" : "0"); } catch {}
ctxKey = "";
steady(() => { if (logR) renderCtx(logR); });
};
log.append(logHead, steps);
log.append(logHead, steps, ctxBox);
const off = el("div", "none rt-off");
// over the stage while a replay plays: the time it is replaying, which
// requests are in flight then, and where it is among them
@@ -106,8 +85,7 @@
rTrack.append(rHead);
rbar.append(rTop, rWhat, rTrack);
rbar.hidden = true;
main.append(top, rbar, stage, foot, log, off);
box.append(main, ctxBox);
box.append(top, rbar, stage, foot, log, off);
// under the stage: every request the gateway keeps, and each account or
// key as those requests found it
@@ -254,8 +232,7 @@
for (const [cls, fits] of Object.entries(marks)) node.classList.toggle(cls, fits(w));
});
}).observe(node);
byWidth(box, { min800: (w) => w >= 800, min1100: (w) => w >= 1100 });
byWidth(main, { max560: (w) => w <= 560 });
byWidth(box, { max560: (w) => w <= 560 });
byWidth(list, { max460: (w) => w <= 460, max560: (w) => w <= 560 });
byWidth(more, { max520: (w) => w <= 520, min1150: (w) => w >= 1150 });
for (const col of [colA, colB]) byWidth(col, { max440: (w) => w <= 440, max760: (w) => w <= 760 });
@@ -1646,7 +1623,7 @@
function renderLog() {
const r = logR = pinned || cur;
log.hidden = !r;
if (!r) { hideCtx(); return; }
if (!r) return;
const on = () => listed().filter((x) => x.id >= logR.id);
const head = JSON.stringify([document.documentElement.lang, !!rp, pinned?.id, r.id, r.time, r.done, !!pinned && on().length > 1]);
if (headKey !== head) {
@@ -1722,53 +1699,33 @@
// ctxFor is a request opened to see its context window (the Usage
// page's Context tab): its card shows unfolded, it alone, whatever the
// reader keeps folded
let ctxKey = "", ctxShown = 0, ctxTab = "all", ctxFor = 0, ctxCarry = null;
function hideCtx() {
ctxBox.hidden = true;
box.classList.remove("has-context");
ctxKey = "";
ctxCarry = null;
ctxDetail.replaceChildren();
ctxShown = 0;
}
let ctxKey = "", ctxShown = 0, ctxTab = "all", ctxFor = 0;
function renderCtx(r) {
// A Usage context link opens this request only, without changing the
// reader's saved preference for the next request or a reload.
if (ctxFor && ctxFor !== r.id) ctxFor = 0;
const open = contextOpen || ctxFor === r.id;
ctxToggle.setAttribute("aria-expanded", String(open));
ctxDetail.hidden = !open;
// Keep the last live context in place while the next prompt is read,
// including the closed summary. A deliberately picked request is fresh.
if (!r.prompt && !r.done && !pinned && !ctxBox.hidden && ctxCarry) r = ctxCarry;
ctxBox.hidden = !r.prompt || !window.ctxCard;
box.classList.toggle("has-context", !ctxBox.hidden);
if (ctxBox.hidden) {
ctxKey = "";
ctxCarry = null;
ctxDetail.replaceChildren();
if (!r.prompt || !window.ctxCard) {
// a live request whose prompt the gateway is still reading keeps
// the card in its place until it has it, rather than the card
// going and coming back a moment later
if (!r.prompt && !r.done && !pinned && ctxBox.firstElementChild?.ctxUpdate) return;
if (ctxKey) { ctxKey = ""; ctxBox.replaceChildren(); }
return;
}
ctxCarry = r;
const sk = open ? sessionKey(r) : "";
const sk = sessionKey(r);
const same = (x) => x.prompt && x.agent === r.agent && !x.kind && (sk ? sessionKey(x) === sk : r.conv && x.conv === r.conv);
const series = open && (sk || r.conv) && !r.kind ? listed().filter(same).sort((a, b) => a.id - b.id)
const series = (sk || r.conv) && !r.kind ? listed().filter(same).sort((a, b) => a.id - b.id)
.map((x) => ({ id: x.id, tokens: x.prompt.tokens, time: x.time })) : null;
if (series && !series.some((x) => x.id === r.id)) series.push({ id: r.id, tokens: r.prompt.tokens, time: r.time });
const key = JSON.stringify([document.documentElement.lang, r.id, r.done,
r.prompt, r.usage, series, open]);
if (ctxFor && ctxFor !== r.id) ctxFor = 0;
const key = JSON.stringify([document.documentElement.lang, ctxFor, r.id, r.done, r.prompt.tokens, r.prompt.counted, r.prompt.window, r.usage?.length, series?.map((x) => x.id + ":" + x.tokens).join()]);
if (key === ctxKey) return;
ctxKey = key;
if (ctxToggle.firstElementChild) window.ctxSummary(r, open, ctxToggle.firstElementChild);
else ctxToggle.replaceChildren(window.ctxSummary(r, open), svg(CHEV, 12, 1.6));
if (!open) { ctxDetail.replaceChildren(); return; }
const sess = groupSession(r) || r.conv || "";
const still = ctxShown === r.id;
ctxShown = r.id;
const card = ctxDetail.firstElementChild;
const draw = card?.ctxUpdate && (still || !pinned) ? card.ctxUpdate : (r, o) => ctxDetail.replaceChildren(window.ctxCard(r, o));
const sess = groupSession(r) || r.conv || "";
const card = ctxBox.firstElementChild;
const draw = card?.ctxUpdate && (still || !pinned) ? card.ctxUpdate : (r, o) => ctxBox.replaceChildren(window.ctxCard(r, o));
draw(r, {
still: true, series, tab: ctxTab, place: "routing", headless: true,
still, series, tab: ctxTab, place: "routing", foldable: true,
open: ctxFor === r.id, onFold: () => { ctxFor = 0; },
onTab: (id) => { ctxTab = id; },
crumbs: [agentName(r.agent), sess && (sess.length > 14 ? sess.slice(0, 12) + "…" : sess), "#" + r.id],
onPoint: (pt) => {
-12
View File
@@ -6,18 +6,6 @@ covers saving and reloading, escaped and non-UTF-8 credentials, masked
addresses/status, clearing authentication, Tab and Escape, mode switches,
HTTP compatibility, and narrow windows in English and Chinese on Chromium
and WebKit.
## Routing context header
`routing-context-layout.test.cjs` checks one lazy context header, full
routing reasons, the visible stage caption and original heading, aligned
wide-card separators, narrow windows, keyboard controls, reload and
preference retention in both engines and all five languages.
`MAGPIE_CONTEXT_ASSETS` points at base assets for a negative check.
The folded-context, live-patch and every-frame suites retain the upstream
geometry, cache, cell identity and Usage-link assertions using the unified
header. The live story logo tests retain their upstream fixtures and node
identity assertions.
## Installed desktop fonts
`fonts.test.cjs` exercises the interface/code font controls with installed
+1 -11
View File
@@ -97,17 +97,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await head.click();
await page.locator("#status").filter({ hasText: w.first }).waitFor();
assert.equal(await ed.locator("input").first().inputValue(), "Sol 2", "the edit is kept");
const cancel = ed.locator("button", { hasText: new RegExp("^" + w.cancel + "$") });
// A dirty-editor notice changes the footer's room. Reach Cancel
// with the wheel; the app intentionally undoes a click's own scroll.
for (let i = 0; i < 20; i++) {
const box = await cancel.boundingBox(), view = await page.locator("#view-routing").boundingBox();
if (box && box.y >= view.y && box.y + box.height <= view.y + view.height) break;
await page.mouse.move(700, 700);
await page.mouse.wheel(0, box && box.y < view.y ? -250 : 250);
await page.waitForTimeout(100);
}
await cancel.click();
await ed.locator("button", { hasText: new RegExp("^" + w.cancel + "$") }).click();
await page.locator("dialog.action-confirm[open] button").last().click();
await closed();
+3 -4
View File
@@ -38,7 +38,7 @@ const routes = [101, 102, 103].map((id) => {
async function serve(route) {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:true}; localStorage.setItem("magpie.routingContext", "1");` });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang: "en", theme: "light" } });
if (url.pathname === "/api/gateway/trace") {
@@ -67,9 +67,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-ctx .ctx-waffle > i").first().waitFor();
assert.equal(await page.locator(".rt-ctx .ctx-waffle > i").count(), 400);
// Routing draws the context cells without an entrance animation. Wait
// for the page's other entrances too before checking what they retain.
await page.waitForFunction(() => !document.getAnimations().some((a) => ["ctx-cell", "fade-in", "view-in"].includes(a.animationName) && a.playState === "running"), null, { timeout: 4000 });
// the cells come in, staggered: the last has begun within 1.5s
await page.waitForFunction(() => !document.getAnimations().some((a) => a.animationName === "ctx-cell" && a.playState === "running"), null, { timeout: 4000 });
const held = await page.evaluate(() => {
const by = {};
for (const a of document.getAnimations()) {
-3
View File
@@ -7,8 +7,6 @@
// layout and controls. Its height is rounded only for the pixel comparison,
// so unchanged text below keeps the baseline's subpixel antialiasing. API
// boundaries are faked; the page's scrolling helpers are left intact.
// Until BASE_REF has Routing's wide layout, routing-context-layout checks
// that intentional change; this file still checks Routing at phone widths.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -312,7 +310,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const original = await open(browser, lang, width, { touch: false, original: true });
try {
for (const view of views) {
if (view === "routing" && !baselineFile("routing.js").includes('const main = el("div", "rt-main")')) continue;
if (view === "agents" && !baselineFile("app.js").includes("function connectPanel")) continue;
await go(current, view); await go(original, view);
await current.mouse.move(0, 0); await original.mouse.move(0, 0);
+1 -13
View File
@@ -119,19 +119,7 @@ const pages = [
{ view: "providers", rows: ".row.provider", wait: "#view-providers .row.provider" },
{ view: "gateway", rows: ".row.gw, #gwModels .row.model, #activity .call, #gatewayKeys .acc[data-key]", wait: "#gatewayKeys .acc[data-key]" },
// the requests are today's in the history: open the day
{ view: "routing", rows: ".rt-req", wait: ".rt-day >> nth=1", open: async (page) => {
const day = page.locator(".rt-day").nth(1);
// The live card can put history below the phone's footer. Scroll as
// the reader would; the app does not permit a click to scroll it.
for (let i = 0; i < 20; i++) {
const box = await day.boundingBox(), view = await page.locator("#view-routing").boundingBox();
if (box && box.y >= view.y && box.y + box.height <= view.y + view.height) break;
await page.mouse.move(180, 400);
await page.mouse.wheel(0, box && box.y < view.y ? -250 : 250);
await page.waitForTimeout(100);
}
await day.click();
}, then: ".rt-req .upstream" },
{ view: "routing", rows: ".rt-req", wait: ".rt-day >> nth=1", open: (page) => page.locator(".rt-day").nth(1).click(), then: ".rt-req .upstream" },
];
const engines = process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"];
const langs = process.env.LANGS ? process.env.LANGS.split(",") : ["en", "zh", "zh-TW", "ja", "de"];
+1 -16
View File
@@ -59,18 +59,6 @@ const want = {
de: { story: "doch Claude Code hat die Anfrage vorher abgebrochen, daher wird niemand erneut gefragt", retry: "erneut versucht", tag: "499 · abgebrochen" },
};
// History can be below the phone footer after the full story paints.
// Reach it with user input; click scrolling is intentionally blocked.
async function reach(page, target, width) {
for (let i = 0; i < 20; i++) {
const box = await target.boundingBox(), view = await page.locator("#view-routing").boundingBox();
if (box && box.y >= view.y && box.y + box.height <= view.y + view.height) break;
await page.mouse.move(width / 2, 380);
await page.mouse.wheel(0, box && box.y < view.y ? -250 : 250);
await page.waitForTimeout(100);
}
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(want)) {
for (const width of [1100, 420]) {
@@ -90,12 +78,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
const day = page.locator(".rt-days .rt-day").nth(1);
await reach(page, day, width);
await day.click();
await page.locator(".rt-days .rt-day").nth(1).click();
await page.locator(".rt-req").nth(routes.length - 1).waitFor();
const row = page.locator(".rt-req").nth(0);
await reach(page, row, width);
await row.click();
await page.waitForTimeout(400);
const steps = await page.locator(".rt-steps li").allTextContents();
@@ -96,18 +96,6 @@ function serve(lang) {
};
}
// History can be below the phone footer after the full story paints.
// Reach it with user input; click scrolling is intentionally blocked.
async function reach(page, target, width) {
for (let i = 0; i < 20; i++) {
const box = await target.boundingBox(), view = await page.locator("#view-routing").boundingBox();
if (box && box.y >= view.y && box.y + box.height <= view.y + view.height) break;
await page.mouse.move(width / 2, 380);
await page.mouse.wheel(0, box && box.y < view.y ? -250 : 250);
await page.waitForTimeout(100);
}
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
@@ -128,12 +116,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
const day = page.locator(".rt-days .rt-day").nth(1);
await reach(page, day, width);
await day.click();
const row = page.locator(".rt-req").first();
await reach(page, row, width);
await row.click();
await page.locator(".rt-days .rt-day").nth(1).click();
await page.locator(".rt-req").first().click();
const src = page.locator(".rt-src").filter({ hasText: "OpenAI" });
await src.waitFor();
const got = await src.evaluate((n) => ({
@@ -17,7 +17,7 @@ const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = process.env.ASSET_DIR || path.resolve(__dirname, "../assets");
const assets = path.resolve(__dirname, "../assets");
const now = Date.now();
const iso = (ms) => new Date(ms).toISOString();
const seat = { id: "codex@me", provider: "codex", name: "ChatGPT", who: "me@example.com", kind: "account", model: "gpt-6.1-sol", known: true, plan: "Pro" };
@@ -90,18 +90,21 @@ async function open(browser, lang, width, height) {
// does): a card opened afresh can sit under the window's bottom
async function click(page, b) {
const h = page.viewportSize().height;
// the page starts under the window's header, which takes a click over it:
// a button scrolled to just under the window's top edge is still hidden
const top = (await page.locator("#view-routing").boundingBox()).y;
for (let i = 0; i < 20; i++) {
const r = await b.boundingBox();
if (r && r.y >= 0 && r.y + r.height <= h) break;
if (r && r.y >= top && r.y + r.height <= h) break;
await page.mouse.move(page.viewportSize().width / 2, h / 2);
await page.mouse.wheel(0, r && r.y < 0 ? -200 : 200);
await page.mouse.wheel(0, r && r.y < top ? -200 : 200);
await page.waitForTimeout(100);
}
await b.click();
await page.waitForTimeout(300);
}
const scrollTop = (page) => page.evaluate(() => document.querySelector("#view-routing").scrollTop);
const stored = (page) => page.evaluate(() => localStorage.getItem("magpie.routingContext") ?? (localStorage.getItem("magpie.ctxShut") === "1" ? "0" : "1"));
const stored = (page) => page.evaluate(() => localStorage.getItem("magpie.ctxShut"));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: the context window on Routing folds to one line`, async (t) => {
@@ -113,19 +116,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await t.test(`${lang} ${width}x${height}: folded to one line, the stage and the requests in view`, async () => {
const { context, page, errors } = await open(browser, lang, width, height);
const box = page.locator(".rt-ctx");
const fold = box.locator(".rt-ctx-toggle");
assert.equal(await box.locator(".ctx-waffle").count(), 0, "folded details are not built");
const fold = box.locator(".ctx-fold");
assert.equal(await box.locator(".ctx-card.shut").count(), 1, "folded, as the reader keeps it");
assert.equal(await fold.getAttribute("aria-expanded"), "false");
assert.equal(await fold.locator(".ctx-title").innerText(), words[lang]);
assert.equal(await box.locator(".ctx-summary-used").innerText(), "186K / 272K");
assert.equal(await box.locator(".ctx-health").innerText(), "68%");
assert.equal(await box.locator(".ctx-title").count(), 1, "the folded header is the only context title");
assert.equal(await fold.innerText(), words[lang]);
assert.equal(await box.locator(".ctx-short").innerText(), "186K / 272K · 68%");
assert.match(await box.locator(".ctx-crumbs").textContent(), /#112$/);
// a bar of what fills the window, a part each (this prompt has no memory)
assert.deepEqual(await box.locator(".ctx-stack > i").evaluateAll((is) => is.map((i) => i.className + " " + i.style.width)),
["k-system 3.31%", "k-tools 4.41%", "k-memory 0%", "k-files 28.68%", "k-results 16.18%", "k-chat 15.81%"]);
const at = await page.evaluate(() => {
const r = (s) => document.querySelector(s).getBoundingClientRect();
const card = r(".rt-ctx"), head = r(".rt-ctx .ctx-summary"), bar = r(".rt-ctx .ctx-stack"), c = document.querySelector(".rt-ctx");
const card = r(".rt-ctx .ctx-card"), head = r(".rt-ctx .ctx-head"), bar = r(".rt-ctx .ctx-stack"), c = document.querySelector(".rt-ctx .ctx-card");
return { vh: innerHeight, stage: r(".rt-stage").bottom, head: r(".rt-req-head").top + 24, row: r(".rt-req").bottom, cardH: card.height, headH: head.height,
bar: bar.width, barIn: bar.right <= head.right + 0.5, over: c.scrollWidth - c.clientWidth, wide: document.documentElement.scrollWidth <= innerWidth };
});
@@ -152,56 +154,56 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForTimeout(400);
const y = await scrollTop(page);
assert(y > 0, "the page scrolled");
const fold = page.locator(".rt-ctx-toggle");
const fold = page.locator(".rt-ctx .ctx-fold");
const foldTop = await fold.evaluate((e) => e.getBoundingClientRect().top);
await fold.click();
await page.locator(".rt-ctx .ctx-waffle").waitFor();
await page.locator(".rt-ctx .ctx-card:not(.shut) .ctx-waffle").waitFor();
assert.equal(await page.locator(".rt-ctx .ctx-waffle > i").count(), 400);
assert.equal(await fold.getAttribute("aria-expanded"), "true");
assert.equal(await page.locator(".rt-ctx .ctx-stack").count(), 0, "open, the bar is the card's own legend");
assert.equal(await page.locator(".rt-ctx .ctx-stack").evaluate((e) => e.getClientRects().length), 0, "open, the bar is the card's own legend");
await page.waitForTimeout(800);
assert.equal(await scrollTop(page), y, "unfolding doesn't move the page");
const after = await fold.evaluate((e) => e.getBoundingClientRect().top);
assert(Math.abs(after - foldTop) <= 1, `the title stays under the pointer: ${foldTop} → ${after}`);
assert.equal(await stored(page), "1");
assert.equal(await stored(page), "0");
assert.deepEqual(errors, []);
await context.close();
});
await t.test("a request picked keeps the fold; one opened for its context window shows it, for itself only", async () => {
const { context, page, errors } = await open(browser, "en", 1440, 900);
const shut = () => page.locator(".rt-ctx-toggle").evaluate((c) => c.getAttribute("aria-expanded") === "false");
const shut = () => page.locator(".rt-ctx .ctx-card").evaluate((c) => c.classList.contains("shut"));
const crumb = () => page.locator(".rt-ctx .ctx-crumbs").evaluate((c) => c.textContent.split(" › ").pop());
const y = await scrollTop(page);
await page.locator(".rt-req").nth(3).click();
await page.waitForTimeout(300);
assert.equal(await shut(), true, "a request picked stays folded");
assert.equal(await page.locator(".ctx-summary-used b").innerText(), "162K");
assert.equal(await crumb(), "#109");
assert.equal(await scrollTop(page), y, "the pick doesn't move the page");
// the Usage page's Context tab's Latest request, or a point of its line
await page.evaluate((r) => window.openRoute(r.id, r.time, { context: true }), routes[2]);
await page.locator(".rt-ctx .ctx-waffle").waitFor();
await page.locator(".rt-ctx .ctx-card:not(.shut) .ctx-waffle").waitFor();
assert.equal(await crumb(), "#103");
assert.equal(await page.locator(".rt-ctx-toggle").getAttribute("aria-expanded"), "true");
assert.equal(await stored(page), "0", "the reader's own choice is untouched");
assert.equal(await page.locator(".rt-ctx .ctx-fold").getAttribute("aria-expanded"), "true");
assert.equal(await stored(page), "1", "the reader's own choice is untouched");
await page.locator(".rt-req").nth(5).click();
await page.waitForTimeout(300);
assert.equal(await shut(), true, "the next request is folded again");
assert.equal(await page.locator(".ctx-summary-used b").innerText(), "146K");
assert.equal(await page.locator(".rt-ctx-toggle").getAttribute("aria-expanded"), "false");
assert.equal(await crumb(), "#107");
assert.equal(await page.locator(".rt-ctx .ctx-fold").getAttribute("aria-expanded"), "false");
// opened for it again, then folded by its title: folded it stays, for it and the next
await page.evaluate((r) => window.openRoute(r.id, r.time, { context: true }), routes[2]);
await page.locator(".rt-ctx .ctx-waffle").waitFor();
await click(page, page.locator(".rt-ctx-toggle"));
await page.locator(".rt-ctx .ctx-card:not(.shut)").waitFor();
await click(page, page.locator(".rt-ctx .ctx-fold"));
assert.equal(await shut(), true, "the title folds it");
assert.equal(await stored(page), "0");
assert.equal(await stored(page), "1");
await click(page, page.locator(".rt-req").nth(5));
await page.evaluate((r) => window.openRoute(r.id, r.time), routes[2]);
await page.waitForTimeout(300);
assert.equal(await page.locator(".ctx-summary-used b").innerText(), "114K");
assert.equal(await crumb(), "#103");
assert.equal(await shut(), true, "a request opened from the list or a link stays folded");
assert.deepEqual(errors, []);
await context.close();
@@ -1,113 +0,0 @@
// The context header is lazy and stable; Routing keeps its full story.
const assert = require('node:assert/strict');
const fs = require('node:fs/promises');
const path = require('node:path');
const { test } = require('node:test');
const { chromium, webkit } = require('playwright');
const assets = process.env.MAGPIE_CONTEXT_ASSETS || path.resolve(__dirname, '../assets');
const now = new Date().toISOString();
const account = { id: 'codex', provider: 'codex', name: 'Codex', who: 'demo@example.com', icon: 'codex-color', kind: 'account', model: 'gpt-6-luna' };
const prompt = { window: 272000, tokens: 43900, counted: true, turns: 1,
parts: [{ kind: 'system', tokens: 10000, items: [{ name: 'prompt', tokens: 10000 }] },
{ kind: 'tools', tokens: 9500, items: [{ name: 'exec_command', tokens: 9500 }] },
{ kind: 'memory', tokens: 5300, items: [{ name: '/demo/AGENTS.md', tag: 'project', tokens: 5300 }] },
{ kind: 'results', tokens: 14500, items: [{ name: 'exec_command', tag: 'result', n: 4, tokens: 14500 }] },
{ kind: 'chat', tokens: 4600, items: [{ name: '1', tag: 'turn', tokens: 4600 }] }] };
function request(id, extra = {}) {
return { id, seq: id, time: now, agent: 'codex', model: 'codex/gpt-6-luna', provider: 'codex',
kind: 'ambient_suggestions', order: [account], tries: [{ id: account.id, model: account.model, effort: 'medium', start: now, done: true, status: 200, ms: 5900, ttft: 5700 }],
done: true, status: 200, ms: 5900, ttft: 5700, tokens: 44100, out: 200, prompt,
usage: [{ in: 3200, cache_read: 40700, out: 200 }], ...extra };
}
function serve(lang, feed) {
return async (r) => {
const url = new URL(r.request().url()), json = (data) => r.fulfill({ json: data });
if (url.pathname === '/boot.js') return r.fulfill({ contentType: 'text/javascript', body: `window.bootPrefs={lang:"${lang}",theme:"dark",web:true};` });
if (url.pathname === '/wails/runtime.js') return r.fulfill({ contentType: 'text/javascript', body: 'export const Window={};' });
if (url.pathname === '/api/state') return json({ agents: [{ id: 'codex', name: 'Codex', fields: [] }], profiles: [], settings: { lang, theme: 'dark' } });
if (url.pathname === '/api/gateway/trace') {
if (!url.searchParams.has('wait')) { feed.count = 1; feed.next = null; }
const routes = url.searchParams.has('wait') ? await new Promise((resolve) => { feed.next = resolve; }) : [request(100)];
return json({ mine: true, now, seq: routes[0]?.id || 100, totals: { requests: 1, rerouted: 0, errors: 0 }, routes });
}
if (url.pathname === '/api/gateway/history') return json({ days: [], routes: [] });
if (url.pathname === '/api/providers') return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === '/api/groups') return json({ groups: [] });
if (url.pathname.startsWith('/api/')) return json({});
const file = path.join(assets, url.pathname === '/' ? 'index.html' : url.pathname);
await r.fulfill({ body: await fs.readFile(file), contentType: { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.png': 'image/png' }[path.extname(file)] });
};
}
for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ['chromium', 'webkit']) {
for (const lang of ['en', 'zh', 'zh-TW', 'ja', 'de']) {
for (const width of [2048, 1440, 900, 860, 420, 360]) {
test(`${engine} ${lang} ${width}px: a single optional context header preserves the routing story`, async (t) => {
const browser = await (engine === 'webkit' ? webkit.launch() : chromium.launch({ channel: 'chromium' }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width, height: 1250 }, reducedMotion: 'reduce' });
page.setDefaultTimeout(5000);
const feed = {}, errors = [];
page.on('pageerror', (e) => errors.push(e.message));
await page.route('**/*', serve(lang, feed));
await page.goto('http://magpie.test/?view=routing');
const toggle = page.locator('.rt-ctx-toggle');
await page.locator('.rt-ctx').waitFor();
assert.equal(await page.locator('.rt-ctx .ctx-waffle').count(), 0, 'closed context does not build the detail grid');
assert.equal(await toggle.getAttribute('aria-expanded'), 'false');
assert.match(await toggle.innerText(), /43\.9K.*272K.*16%.*93%/s);
assert.equal(await page.locator('.rt-cap').isVisible(), true, 'the stage caption stays visible');
assert.equal(await page.locator('.rt-steps li.why').isVisible(), true, 'routing reasons stay visible by default');
const translated = await page.evaluate(() => t('How the last request was routed'));
assert.ok((await page.locator('.rt-log-head').innerText()).includes(translated), 'the descriptive story heading is preserved');
await page.waitForTimeout(500);
await toggle.hover();
const before = await toggle.evaluate((e) => e.getBoundingClientRect().top);
await toggle.click();
await page.locator('.rt-ctx .ctx-waffle').waitFor();
assert.equal(await page.locator('.rt-ctx .ctx-title').count(), 1, 'one header serves both states');
assert.equal(await page.locator('.ctx-summary-numbers').count(), 0, 'expanded figures appear only in the body');
assert.equal(await page.locator('.ctx-waffle > i').count(), 400);
assert.equal(await toggle.getAttribute('aria-expanded'), 'true');
assert.ok(Math.abs(await toggle.evaluate((e) => e.getBoundingClientRect().top) - before) < 1, `opening keeps the header under the pointer: ${before} -> ${await toggle.evaluate((e) => e.getBoundingClientRect().top)}`);
await page.waitForTimeout(100);
const layout = await page.evaluate(() => {
const root = document.querySelector('.rt'), log = root.querySelector('.rt-log').getBoundingClientRect();
const stage = root.querySelector('.rt-stage').getBoundingClientRect(), contents = root.querySelector('.ctx-contents').getBoundingClientRect();
const head = root.querySelector('.ctx-contents-head');
return { wide: root.classList.contains('min1100'), pair: root.classList.contains('min800'),
log: log.left, stage: stage.right, separator: contents.left,
nowrap: getComputedStyle(head).flexWrap, over: document.documentElement.scrollWidth > innerWidth };
});
if (layout.wide) {
assert.ok(layout.log >= layout.stage, 'stage and request story share a row');
assert.ok(Math.abs(layout.log - layout.separator) <= 1, 'both column separators align');
}
assert.equal(layout.nowrap, 'nowrap', 'content label and filters share a row');
assert.equal(layout.over, false, 'the page fits the window');
await toggle.click();
assert.equal(await page.locator('.ctx-waffle').count(), 0, 'closing releases detail contents');
await toggle.focus();
await page.keyboard.press('Enter');
await page.locator('.ctx-waffle').waitFor();
assert.equal(await page.evaluate(() => localStorage.getItem('magpie.routingContext')), '1');
await page.reload();
await page.locator('.ctx-waffle').waitFor();
assert.equal(await page.locator('.rt-ctx-toggle').getAttribute('aria-expanded'), 'true', 'reload restores the preference');
if (width === 900) {
for (let i = 0; i < 60 && !feed.next; i++) await page.waitForTimeout(50);
assert.ok(feed.next, 'the next trace request is waiting');
const next = feed.next; feed.next = null;
next([request(101, { done: false, prompt: undefined, usage: [], tries: [] })]);
await page.waitForFunction(() => document.querySelectorAll('.rt-req').length === 2);
await page.locator('.rt-ctx-toggle').click();
assert.equal(await page.locator('.rt-ctx').isVisible(), true, 'a disclosure keeps the carried context while the new prompt is being read');
assert.equal(await page.locator('.ctx-waffle').count(), 0);
await page.locator('.rt-ctx-toggle').click();
await page.locator('.ctx-waffle').waitFor();
assert.equal(await page.locator('.rt-ctx-toggle').getAttribute('aria-expanded'), 'true');
}
assert.deepEqual(errors, []);
});
}
}
}
+16 -46
View File
@@ -61,25 +61,28 @@ function serve() {
}
const look = (page) => page.evaluate(() => {
const card = document.querySelector(".rt-ctx"), fold = card.querySelector(".rt-ctx-toggle"), short = card.querySelector(".ctx-summary-used"), fill = fold.querySelector(".ctx-health");
const card = document.querySelector(".rt-ctx .ctx-card"), fold = card.querySelector(".ctx-fold"), short = card.querySelector(".ctx-short");
const shown = (e) => !!e && e.getClientRects().length > 0;
return {
shut: fold.getAttribute("aria-expanded") === "false",
shut: card.classList.contains("shut"),
expanded: fold.getAttribute("aria-expanded"),
height: card.offsetHeight,
short: shown(short) ? short.textContent + (fill ? " · " + fill.textContent : "") : null,
short: shown(short) ? short.textContent : null,
grid: shown(card.querySelector(".ctx-waffle")),
contents: shown(card.querySelector(".ctx-contents")),
cells: card.querySelectorAll(".ctx-waffle > i").length,
crumbs: card.querySelector(".ctx-crumbs")?.textContent,
crumbs: card.querySelector(".ctx-crumbs").textContent,
overflow: card.scrollWidth - card.clientWidth + (document.documentElement.scrollWidth - document.documentElement.clientWidth),
after: card.getBoundingClientRect().bottom,
// the head's space to the card's border, over it and under it
gaps: (() => { const c = card.getBoundingClientRect(), h = card.querySelector(".ctx-head").getBoundingClientRect(), bw = parseFloat(getComputedStyle(card).borderTopWidth);
return [h.top - c.top - bw, c.bottom - h.bottom - bw].map((n) => Math.round(n * 10) / 10); })(),
};
});
// the reader scrolls to what they click with the wheel, as at a phone's
// width the card is under the request list
async function scrollTo(page, b) {
async function click(page, b) {
const h = page.viewportSize().height;
for (let i = 0; i < 20; i++) {
const r = await b.boundingBox();
@@ -88,13 +91,10 @@ async function scrollTo(page, b) {
await page.mouse.wheel(0, r && r.y < 0 ? -200 : 200);
await page.waitForTimeout(100);
}
}
async function click(page, b) {
await scrollTo(page, b);
await b.click();
await page.waitForTimeout(300);
}
const fold = (page) => click(page, page.locator(".rt-ctx-toggle"));
const fold = (page) => click(page, page.locator(".rt-ctx .ctx-fold"));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: Routing's context window folds to its head and stays folded`, async (t) => {
@@ -109,13 +109,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve());
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-ctx-toggle").waitFor();
assert.equal((await look(page)).shut, true, "it starts folded without a saved choice");
await fold(page);
await page.locator(".rt-ctx .ctx-waffle").waitFor();
await page.waitForTimeout(800);
const open = await look(page);
assert.equal(open.shut, false, "the single header opens it");
assert.equal(open.shut, false, "it starts open");
assert.equal(open.expanded, "true");
assert(open.grid && open.contents, "open, the grid and contents are there");
assert.equal(open.short, null, "open, the short figure isn't shown");
@@ -125,9 +123,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(shut.shut, true, "a click folds it");
assert.equal(shut.expanded, "false");
assert(!shut.grid && !shut.contents, "folded, the grid and contents are gone");
assert.equal(shut.cells, 0, "folded details are not constructed");
assert.equal(shut.short, "114K / 272K · 42%", "folded, how full it is is beside the title");
assert(shut.height < 60, `folded, it is one line: ${shut.height}px`);
assert.equal(shut.gaps[0], shut.gaps[1], `folded, the space under its head is the space over it: ${shut.gaps}`);
assert(shut.after < open.after - 200, `what is under it moves up: ${open.after} -> ${shut.after}`);
assert(shut.overflow <= 0, `nothing runs over at ${width}px: ${shut.overflow}`);
@@ -135,19 +133,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await click(page, page.locator(".rt-req").last());
const other = await look(page);
assert.equal(other.shut, true, "the next request's card is folded too");
assert.notEqual(other.short, shut.short, "it tells of the request picked");
assert.notEqual(other.crumbs, shut.crumbs, "it tells of the request picked");
// the page comes back: still folded
await page.reload();
await page.locator(".rt-ctx-toggle").waitFor();
await page.locator(".rt-ctx .ctx-card").waitFor();
await page.waitForTimeout(500);
assert.equal((await look(page)).shut, true, "it stays folded after the page comes back");
// opened again, it is all there; its title stays where it was and
// the page doesn't follow it (a click never moves the page: with
// a folded padding of its own, it moved 4px)
const b = page.locator(".rt-ctx-toggle");
await scrollTo(page, b);
const b = page.locator(".rt-ctx .ctx-fold");
await click(page, page.locator(".rt-ctx .ctx-short"));
const before = await b.evaluate((e) => [e.getBoundingClientRect().top, document.querySelector("#view-routing").scrollTop]);
await b.click();
await page.waitForTimeout(800);
@@ -166,31 +164,3 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
});
}
// A choice saved by the original fold survives the unified Routing header;
// once changed in Routing, that newer choice takes precedence.
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const legacy of ["0", "1"]) {
test(`${engine}: Routing retains the original context fold choice ${legacy}`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width: 1100, height: 1000 }, reducedMotion: "reduce" });
const errors = [];
page.on("pageerror", e => errors.push(e.message));
await page.addInitScript((choice) => {
if (localStorage.getItem("magpie.ctxShut") === null) localStorage.setItem("magpie.ctxShut", choice);
}, legacy);
await page.route("**/*", serve());
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-ctx-toggle").waitFor();
assert.equal((await look(page)).shut, legacy === "1", "retain the original choice");
await fold(page);
assert.equal((await look(page)).shut, legacy !== "1");
await page.reload();
await page.locator(".rt-ctx-toggle").waitFor();
assert.equal((await look(page)).shut, legacy !== "1", "the newer preference wins after reload");
assert.equal(await page.locator(".rt-ctx .ctx-title").count(), 1, "there is one context header");
assert.deepEqual(errors, []);
});
}
}
@@ -56,7 +56,7 @@ function serve(lang, feed) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true}; localStorage.setItem("magpie.routingContext", "1");` });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/gateway/trace") {
@@ -78,7 +78,7 @@ function serve(lang, feed) {
const sizes = [["en", 420], ["en", 1100], ["zh", 420], ["zh", 1100], ["zh-TW", 900], ["ja", 900], ["de", 420]];
// the parts of the card watched on every frame
const WATCH = {
card: ".rt-ctx-detail .ctx-body", header: ".rt-ctx-toggle .ctx-title", state: ".rt-ctx-toggle .ctx-state", used: ".rt-ctx .ctx-stat .ctx-big b",
card: ".rt-ctx .ctx-card", model: ".rt-ctx .ctx-model", state: ".rt-ctx .ctx-state", used: ".rt-ctx .ctx-stat .ctx-big b",
cache: ".rt-ctx .ctx-cache", figure: ".rt-ctx .ctx-cache .ctx-big b", bar: ".rt-ctx .ctx-cache .ctx-bar", grid: ".rt-ctx .ctx-waffle",
legend: ".rt-ctx .ctx-legend", foot: ".rt-ctx .ctx-foot",
};
@@ -150,7 +150,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
seen.push([id, step, await cacheNow()]);
if (process.env.ARTIFACT_DIR && id === 104 && step !== "start") {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.locator(".rt-ctx-detail .ctx-body").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-${step === "read" ? "live" : "done"}.png`) });
await page.locator(".rt-ctx .ctx-card").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-${step === "read" ? "live" : "done"}.png`) });
}
}
}
@@ -196,7 +196,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(est.bar, "hidden", "no empty bar under the dash");
const after = await page.evaluate((s) => [...document.querySelectorAll(s)].map((e) => e.getBoundingClientRect().y), Object.values(WATCH).join(","));
assert.deepEqual(after.map(Math.round), before.map(Math.round), "nothing moved for the estimated request");
if (process.env.ARTIFACT_DIR) await page.locator(".rt-ctx-detail .ctx-body").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-none.png`) });
if (process.env.ARTIFACT_DIR) await page.locator(".rt-ctx .ctx-card").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-none.png`) });
// another session's first request, under way: no last request of
// its own to show, so a dash till it is read, in the same place
const top = await page.locator(".rt-ctx .ctx-cache").evaluate((e) => e.getBoundingClientRect().y);
@@ -208,7 +208,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(soon.gap >= 3, `the dash and its word are apart: ${soon.gap}px`);
assert.equal(soon.bar, "hidden");
assert(Math.abs(await page.locator(".rt-ctx .ctx-cache").evaluate((e) => e.getBoundingClientRect().y) - top) <= 0.5, "the cache kept its place");
if (process.env.ARTIFACT_DIR) await page.locator(".rt-ctx-detail .ctx-body").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-soon.png`) });
if (process.env.ARTIFACT_DIR) await page.locator(".rt-ctx .ctx-card").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-ctx-soon.png`) });
assert.deepEqual(errors, []);
feed.next?.(req(999, "done"));
await context.close();
+13 -11
View File
@@ -51,7 +51,7 @@ function serve(feed) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: 'window.bootPrefs = {lang:"en",theme:"light",web:true}; if(localStorage.getItem("magpie.ctxShut")!=="1")localStorage.setItem("magpie.routingContext","1");' });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: 'window.bootPrefs = {lang:"en",theme:"light",web:true};' });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/gateway/trace") {
@@ -91,7 +91,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// what is there now, and every layout from here on
await page.evaluate(() => {
const box = document.querySelector(".rt-ctx"), grid = box.querySelector(".ctx-waffle");
window.__was = { rows: [...document.querySelectorAll(".rt-req")], items: [...box.querySelectorAll(".ctx-row, .ctx-leg")], card: box.querySelector(".ctx-body"), grid, cells: [...grid.children], box: box.offsetHeight, gridH: grid.offsetHeight };
window.__was = { rows: [...document.querySelectorAll(".rt-req")], items: [...box.querySelectorAll(".ctx-row, .ctx-leg")], card: box.querySelector(".ctx-card"), grid, cells: [...grid.children], box: box.offsetHeight, gridH: grid.offsetHeight };
window.__sizes = [];
window.__ro = new ResizeObserver(() => {
const g = document.querySelector(".rt-ctx .ctx-waffle");
@@ -133,7 +133,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
rows: rows.length,
kept: w.rows.map((r) => rows.includes(r)),
items: w.items.every((e) => e.isConnected && box.contains(e)),
card: box.querySelector(".ctx-body") === w.card,
card: box.querySelector(".ctx-card") === w.card,
grid: grid === w.grid,
cells: w.cells.every((c, i) => grid.children[i] === c) && grid.children.length === w.cells.length,
sizes: window.__sizes, box0: w.box, grid0: w.gridH, gridH: grid.offsetHeight,
@@ -158,6 +158,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
assert.deepEqual(got.scroll, [], "the page doesn't scroll by itself");
assert.deepEqual(errors, []);
feed.next?.(req(999, "done"));
await context.close();
});
await t.test(`${width}x${height}, folded`, async () => {
@@ -171,11 +172,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", serve(feed));
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-req").nth(first.length - 1).waitFor();
await page.locator('.rt-ctx-toggle[aria-expanded="false"]').waitFor();
await page.locator(".rt-ctx .ctx-card.shut").waitFor();
await page.waitForTimeout(600);
await page.evaluate(() => {
const box = document.querySelector(".rt-ctx");
window.__was = { rows: [...document.querySelectorAll(".rt-req")], line: box.querySelector(".ctx-summary"), head: box.querySelector(".ctx-head"), bar: box.querySelector(".ctx-stack"), h: box.offsetHeight, list: document.querySelector(".rt-reqs").getBoundingClientRect().top };
window.__was = { rows: [...document.querySelectorAll(".rt-req")], line: box.querySelector(".ctx-card"), head: box.querySelector(".ctx-head"), bar: box.querySelector(".ctx-stack"), h: box.offsetHeight, list: document.querySelector(".rt-reqs").getBoundingClientRect().top };
window.__sizes = [];
window.__ro = new ResizeObserver(() => window.__sizes.push(box.offsetHeight));
window.__ro.observe(box);
@@ -193,7 +194,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForTimeout(400);
said.push(await page.evaluate(() => {
const box = document.querySelector(".rt-ctx");
return box.querySelector(".ctx-summary-used").textContent + " · " + box.querySelector(".ctx-health").textContent
return box.querySelector(".ctx-short").textContent + " " + box.querySelector(".ctx-crumbs").textContent.split(" › ").pop()
+ " " + [...box.querySelectorAll(".ctx-stack > i")].map((i) => i.style.width).join(",");
}));
}
@@ -201,16 +202,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the folded head waits for a prompt in its place, then tells of it
const bar = (f, r, c) => `3.31%,4.41%,0%,${f}%,${r}%,${c}%`;
assert.deepEqual(said, [
"114K / 272K · 42% " + bar(15.44, 9.56, 9.19),
...Array(3).fill("122K / 272K · 45% " + bar(16.91, 10.29, 9.93)),
...Array(2).fill("130K / 272K · 48% " + bar(18.38, 11.03, 10.66)),
"114K / 272K · 42% #103 " + bar(15.44, 9.56, 9.19),
...Array(3).fill("122K / 272K · 45% #104 " + bar(16.91, 10.29, 9.93)),
...Array(2).fill("130K / 272K · 48% #105 " + bar(18.38, 11.03, 10.66)),
]);
const got = await page.evaluate(() => {
window.__ro.disconnect();
const box = document.querySelector(".rt-ctx"), w = window.__was, rows = [...document.querySelectorAll(".rt-req")];
return {
kept: w.rows.every((r) => rows.includes(r)), line: box.querySelector(".ctx-summary") === w.line && box.querySelector(".ctx-head") === w.head, bar: box.querySelector(".ctx-stack") === w.bar,
card: box.querySelector(".rt-ctx-toggle").getAttribute("aria-expanded") !== "false" || !!box.querySelector(".ctx-waffle"), h: box.offsetHeight, h0: w.h, sizes: window.__sizes, scroll: window.__scroll,
kept: w.rows.every((r) => rows.includes(r)), line: box.querySelector(".ctx-card") === w.line && box.querySelector(".ctx-head") === w.head, bar: box.querySelector(".ctx-stack") === w.bar,
card: !box.querySelector(".ctx-card").classList.contains("shut") || box.querySelector(".ctx-waffle").getClientRects().length > 0, h: box.offsetHeight, h0: w.h, sizes: window.__sizes, scroll: window.__scroll,
list: document.querySelector(".rt-reqs").getBoundingClientRect().top, list0: w.list,
};
});
@@ -221,6 +222,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(got.list, got.list0, "the request list stays where it was");
assert.deepEqual(got.scroll, [], "the page doesn't scroll by itself");
assert.deepEqual(errors, []);
feed.next?.(req(999, "done"));
await context.close();
});
}