routing: an account's seat on the stage tells every window it has, under its status (YujunT46308 on X)

The stage's seat said one share and drew a bar; the other windows were only
in its tooltip, so the reader went to Usage to see what was left. Under the
status the seat now lists every window the account has, worded by the Usage
page's own winParts (short name, used or left per the quotaLeft setting,
when it starts again; counts such as "355 / 500 credits" come with
quotaText), each with its full reset time on hover. No new colours, no
motion, no new strings: it wraps on a narrow stage.

Honest about unknown: a seat with no card of its own, or whose read failed,
shows no windows (its status already says so); a wallet's balance stays its
status; the window the status already says is not told twice.

Run (mica, tree at this change rebased on origin/main 03ae057b8):
- routing-seat-wins.test.cjs: 22 of 22 in chromium and webkit, 5 languages,
  1100 and 420px. Broken by hand (line returning no windows): 11 red in
  chromium.
- routing-*, panel-routing*, i18n*, ctx-route* GUI files (207 files, both
  engines): reds were routing-mode-goes (stale since 9ec023a46, fixed in the
  next commit) and routing-pin-away (red on origin/main too, #6512).
- go test ./internal/gui -run 'TestCoreScriptBudget|Asset|I18n|Script': ok.
Not run: the whole GUI suite (both machines already had one running, one
suite per machine); WebKitGTK/Linux app; Windows.
This commit is contained in:
yetone
2026-11-20 03:59:43 +08:00
parent 3eba174fd9
commit b6b6ba752e
4 changed files with 137 additions and 5 deletions
+8 -3
View File
@@ -337,9 +337,14 @@ itself. It shows only live, with a subscription account listed. See
`routing-read-allowances.test.cjs`.
On the stage, an account's seat tells the same windows in its tooltip,
under its id (`render`, #1835). The row itself keeps one line: the
fullest window while idle, what it is doing while it answers. See
`routing-seat-windows.test.cjs`.
under its id (`render`, #1835). The row's status keeps one line: the
fullest window while idle, what it is doing while it answers. Under it the
seat tells every window it has, as `winParts` words them (short name, used or
left as the Usage page's setting says, when it starts again; YujunT46308 on
X), wrapping on a narrow stage. The one the status already says is not told
twice, a wallet's balance is its status, and an account with no card of its
own, or one not read, tells no windows rather than a guess. See
`routing-seat-windows.test.cjs`, `routing-seat-wins.test.cjs`.
### Routing account cards
+21 -2
View File
@@ -2873,9 +2873,11 @@ function routingPage(part) {
if (cut && !st.title) st.title = st.textContent;
};
st.onpointerleave = () => delete st.dataset.cut;
li.append(el("i", "dot"), b, st, bar, tg);
// every window the account has, as Usage reads them (the seat's windows line)
const wn = el("div", "wins");
li.append(el("i", "dot"), b, st, bar, tg, wn);
li.title = w.id;
return { li, wire: path(), st, bi, tg, w, provEl: prov, subEl: sub };
return { li, wire: path(), st, bi, tg, wn, w, provEl: prov, subEl: sub };
}
// keyLed: a key's row is headed by its provider's name, the key's
// after it, muted: a key's name is often only its masked secret
@@ -3349,6 +3351,23 @@ function routingPage(part) {
// crowd the stage. Live only, as the list's are (winsOf).
const tip = [w.id, ...(day ? [] : [...winsOf(w), cardError(w)].filter(Boolean))].join("\n");
if (row.li.title !== tip) row.li.title = tip;
// every window the account has, each with what it has left (or used,
// as the Usage page's setting says) and when it starts again, in the
// seat itself, not only on hover (YujunT46308 on X: a bar alone isn't
// what they read the Usage page for). The one the row's status already
// says is not told twice; a wallet's balance is its status; an account
// not read says so there, not here. Live only, as winsOf.
const wp = day || w.balance != null ? [] : winParts(w).slice(s === winsOf(w)[0] ? 1 : 0);
const sig = wp.map((p) => p.k + "\u0000" + p.v + "\u0000" + p.r).join("\u0001");
if (row.wn.dataset.sig !== sig) {
row.wn.dataset.sig = sig;
row.wn.replaceChildren(...wp.map((p) => {
const e = el("span", "", "");
e.append(el("span", "k", p.k), " ", el("b", "", p.v), ...(p.r ? [" ", el("span", "r", p.r)] : []));
e.title = p.tip;
return e;
}));
}
const bar = w.known && !w.free && w.balance == null;
row.li.classList.toggle("nobar", !bar);
row.bi.style.width = bar ? fill(w) : "0";
@@ -151,6 +151,11 @@
.rt-accts .bar { grid-column: 2 / 4; height: 3px; }
.rt-accts .bar i { width: 0; transition: width .4s; }
.rt-accts li.nobar .bar { display: none; }
/* an account's every window, under its status: name, what is used or left,
when it starts again; wraps, never cut short */
.rt-accts li > .wins { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 11px; line-height: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rt-accts li > .wins:empty { display: none; }
.rt-accts li > .wins b { font-weight: 450; color: var(--fg-2); }
.rt-accts .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.rt-accts li.on { border-color: var(--fg); }
.rt-accts li.on em { color: var(--fg); }
@@ -0,0 +1,103 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// YujunT46308 on X: the stage's seat showed a bar and one share, so they went
// to Usage to see what was left. An account's seat now tells every window it
// has under its status (name, what is used, when it starts again, as the
// Usage page words them: the same winParts), and nothing for a seat with no
// card of its own, whose figure is not guessed. In every language, at a
// window's width and at 420px, in both engines.
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 = path.resolve(__dirname, "../assets");
const now = Date.now();
const iso = (ms) => new Date(ms).toISOString();
const accts = [
{ id: "claude", provider: "claude", name: "Claude", who: "work@example.com", kind: "account", agent: "claude", model: "claude-opus-5", known: true, used: 40, plan: "Max" },
{ id: "claude@spare", provider: "claude", name: "Claude", who: "spare@example.com", kind: "account", agent: "claude", model: "claude-opus-5", known: false, plan: "Pro" },
];
const route = {
id: 7, seq: 7, time: iso(now - 2000), agent: "claude", model: "claude-opus-5", provider: "claude", done: true, status: 200, ms: 900, tokens: 1500,
order: accts, tries: [{ id: "claude", model: "claude-opus-5", start: iso(now - 2000), done: true, ms: 800, status: 200 }],
};
const cards = [
{ provider: "claude", name: "Claude", kind: "subscription", user: "Work@Example.com", plan: "Max", windows: [
{ name: "5 hours", used: 40, resetsAt: iso(now + 130 * 60e3) },
{ name: "7 days", used: 12, resetsAt: iso(now + 73 * 3600e3) },
] },
// another computer's reading of the spare account: not this one's
{ provider: "claude", name: "Claude · Home", kind: "subscription", user: "spare@example.com", from: "Home", windows: [{ name: "5 hours", used: 90 }] },
];
function serve(lang, asks) {
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light", quotaLeft: false } };
return async (r) => {
const url = new URL(r.request().url());
const json = (data) => r.fulfill({ json: data });
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",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(state);
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
return json({ mine: true, now: new Date().toISOString(), seq: 7, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [route] });
}
if (url.pathname === "/api/usage/quotas") { asks.push(url.search); return json(cards); }
if (url.pathname === "/api/usage/quotas/history") return json([]);
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await r.fulfill({ body: await fs.readFile(file), contentType });
};
}
const words = {
en: [["5h", "40% used", "resets in 2h"], ["7d", "12% used", "resets in 3d"]],
zh: [["5h", "已用 40%", "2 小时后重置"], ["7d", "已用 12%", "3 天后重置"]],
"zh-TW": [["5h", "已用 40%", "2 小時後重置"], ["7d", "已用 12%", "3 天后重置"]],
ja: [["5h", "使用済み 40%", "2 時間後にリセット"], ["7d", "使用済み 12%", "3 日後にリセット"]],
de: [["5h", "40% verbraucht", "Reset in 2 Std."], ["7d", "12% verbraucht", "Reset in 3 T."]],
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: an account's seat on the stage tells every window it has`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(words)) {
for (const width of [1100, 420]) {
await t.test(`${lang} at ${width}px`, async () => {
const ctx = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
try {
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, []));
await page.goto("http://magpie.test/?view=routing");
const seat = (who) => page.locator(".rt-accts li", { has: page.locator(".who", { hasText: who }) }).first();
await page.waitForFunction(() => [...document.querySelectorAll(".rt-accts li .wins span")].length >= 2);
const wins = seat("work@example.com").locator(".wins > span");
assert.equal(await wins.count(), 2, "both windows, not only the first");
const got = await wins.evaluateAll((es) => es.map((e) => [e.querySelector(".k").textContent, e.querySelector("b").textContent, e.querySelector(".r")?.textContent]));
assert.deepEqual(got, words[lang]);
// an account with no card of its own says nothing of windows it was not read for
assert.equal(await seat("spare@example.com").locator(".wins > span").count(), 0);
// every window in full on hover, with its reset
assert.match(await wins.nth(1).getAttribute("title"), /12/);
// nothing runs off the seat at any width
const over = await seat("work@example.com").evaluate((li) => li.scrollWidth > li.clientWidth + 1);
assert.equal(over, false);
assert.deepEqual(errors, []);
} finally {
await ctx.close();
}
});
}
}
});
}