Files
magpie/internal/gui/tests/routing-columns.test.cjs
T
yetone 70a98dd85c routing: a long Accounts and keys shows its first rows, the rest behind Show N more (ferock4669, iyou00 on Discord)
With many keys the Routing page's Accounts and keys ran on and on: each
card held every window, the models it answered and a meter. Now a card
keeps its name, one line of what is left (or its rest) and how it fares,
with Try now or Sign in again when it needs one. The models it answered
are in its tooltip under its id, and a subscription's other windows are
on hover over its figure.

A list longer than 8 rows shows the first 8 and puts the rest behind
"Show N more" at its foot (kept across a reload in
magpie.routingActsAll). Never behind it: a row to sign in again, a
resting account or model, failures with no answer, a remote whose
allowance can't be read, rows under a fold the reader opened, and the
heading of a provider with a row shown. Two more alone aren't folded.
The button clicked stays where it is on the screen. "View usage" beside
it opens Usage's Overview, where each account's card says it all,
without making that tab the reader's own (window.openUsageOverview).

The foot writes only what changed, so an idle page writes nothing
(routing-live-calm).

Tests: routing-acts-compact.test.cjs (new; chromium and webkit, en zh
zh-TW ja de, 1300px and 420px). routing-account-windows,
routing-read-allowances, routing-wallet-lapse, routing-accounts-narrow
and routing-columns follow the card's new shape and the foot.

Run on mote via mote-run, worktree based on origin/main c7bbd3faf:
- Whole Routing GUI set (routing-*, panel-routing*) + i18n-keys,
  chromium and webkit: 2487 pass, 29 fail, every red one of those
  below (many-keys and routing-levels #3620 too)
- Same reds on clean origin/main c7bbd3faf (11 files run there): the
  routing-rule-remove (#3096), rule-drag (#3789), row-swap (#3799),
  order-unknown (#4627), rules-line (#3593), steady, steps-cap and
  story-shrinks reds of #5088, in different languages run to run.
- routing-folder went red 2 of 3 with this change (30/30 on main):
  its press() clicked Save while the group editor was still growing
  open, and the foot moved .rt-gsec 8px. press() now waits for the
  button to hold still: 3 runs x both engines 20/20, webkit alone
  10/10.
- TestCoreScriptBudget red, 1534154 > 1533802, identical on clean
  c7bbd3faf (#5139): this change adds nothing to the core scripts.
- routing-acts-compact twice, alone and beside 5 files: 22/22, 20/20.
- Rebased onto origin/main 14f6d10de (its routing client.js changes
  merged clean), at this commit, both engines: routing-remote-windows,
  week-low, free-expiring, group-strategy, acts-compact, live-calm,
  folder, account-windows, read-allowances, accounts-narrow,
  wallet-lapse, columns and i18n-keys all green.
  Pushed on c4245c4c2, which changes only internal/gateway's
  object_root and its doc after 14f6d10de; not run again on it.

Broken by hand:
- rows needing the reader no longer kept out of the collapse (m.keep
  ignored): routing-acts-compact red (Show 4 more never shown).
- a row to sign in again under a shut fold not drawn: red (Zed's fold
  row 0 !== 1).
- the foot's hidden/aria-expanded written every draw: routing-live-calm
  red in both engines (attrs: 6 !== 0), as in an earlier run of this.
- the button's hold removed: routing-acts-compact red (chromium en
  1300px, "the click moved the button: 572.9 → 592.1").

Not tried: the real app with a real long key list (fixtures only), the
Linux WebKitGTK app, Windows.
2026-11-04 18:33:07 +08:00

141 lines
9.8 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// The Routing page's Requests and Accounts and keys, side by side (a report
// with a screenshot: "这里排版是不是有问题啊?感觉好乱"): the two lists end on one
// line, the accounts scrolling like the requests instead of running on down
// the page beside an empty column; the models an account answered are in
// its tooltip, not wrapped in among its numbers; a provider's row
// says its model once, under the provider's name, not the name again and the
// model twice. One column, the accounts list is as long as it is. Side by
// side only where each request still fits one line; narrower, one column of
// one-line requests, not two with each request on three (#860).
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 now = new Date();
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
const renew = new Date(now.getTime() + 3 * 864e5).toISOString();
const W = {
aihub: { id: "aihubmix", provider: "aihubmix", name: "AiHubMix", kind: "provider", model: "glm-5.3-flash", icon: "aihubmix-color", routing: "smart" },
c1: { id: "codex:a", provider: "codex", name: "Codex", who: "ann@example.com", plan: "plus", kind: "account", model: "gpt-5.6-terra", known: true, used: 9, renews: [renew], icon: "codex-color", routing: "smart" },
c2: { id: "codex:b", provider: "codex", name: "Codex", who: "bob@example.com", plan: "pro", kind: "account", model: "gpt-5.6-terra", known: true, used: 4, renews: [renew], icon: "codex-color", routing: "smart" },
cop: { id: "copilot:a", provider: "copilot", name: "Copilot", who: "ann", kind: "account", model: "gpt-6-sol", known: true, used: 1, renews: [renew], icon: "githubcopilot", routing: "smart" },
ds: { id: "deepseek", provider: "deepseek", name: "DeepSeek", kind: "provider", model: "deepseek-flash", icon: "deepseek-color", routing: "smart" },
or: { id: "openrouter", provider: "openrouter", name: "OpenRouter", kind: "provider", model: "openai/gpt-6-sol", icon: "openrouter", routing: "smart" },
wb: { id: "wb:a", provider: "workbuddy", name: "WorkBuddy", who: "ann", kind: "account", model: "glm", known: false, icon: "generic", routing: "smart" },
};
const mk = (i, w, model, extra = {}) => ({
id: 200 - i, seq: 200 - i, time: at(i), agent: i % 2 ? "codex" : "curl", model, provider: w.provider,
order: Object.values(W).filter((x) => x.provider === w.provider), done: true, status: 200, ms: 5000 + i * 900, tokens: 90000 + i * 700,
tries: [{ id: w.id, model: w.model || model.split("/").pop(), start: at(i), done: true, status: 200, ms: 5000 }], ...extra,
});
const routes = [
mk(0, W.ds, "deepseek/deepseek-flash"), mk(1, W.ds, "deepseek/deepseek-flash"),
...[2, 3, 4, 5].map((i) => ({ ...mk(i, W.c1, "codex/gpt-5.6-terra"), tries: [{ id: W.c1.id, model: "gpt-5.6-terra", start: at(i), done: true, status: 200, ms: 8000, effort: "medium" }] })),
{ ...mk(6, W.c1, "codex/gpt-6-luna"), tries: [{ id: W.c1.id, model: "gpt-6-luna", start: at(6), done: true, status: 200, ms: 8000 }] },
{ ...mk(7, W.c1, "codex/gpt-5.6-luna"), tries: [{ id: W.c1.id, model: "gpt-5.6-luna", start: at(7), done: true, status: 200, ms: 8000 }] },
mk(8, W.cop, "copilot/gpt-6-sol"), mk(9, W.aihub, "aihubmix/glm-5.3-flash"), mk(10, W.or, "openrouter/openai/gpt-6-sol"), mk(11, W.wb, "workbuddy/glm"),
];
function serve(lang) {
const state = { agents: [{ id: "codex", name: "Codex", path: "/t", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
const assets = path.resolve(__dirname, "../assets");
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};` });
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") {
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
return json({ mine: true, now: now.toISOString(), seq: 200, totals: { requests: routes.length, rerouted: 0, errors: 0 }, routes });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
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 route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
test(`${engine} ${lang}: requests and accounts side by side`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width: 1440, height: 1400 } });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.locator(".rt-cols").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-columns.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-act").first().waitFor();
await page.waitForTimeout(300);
const box = (s) => page.locator(s).evaluate((e) => { const b = e.getBoundingClientRect(); return { left: b.left, right: b.right, bottom: b.bottom, scroll: e.scrollHeight > e.clientHeight + 1 }; });
const reqs = await box(".rt-reqs"), acts = await box(".rt-acts"), foot = await box(".rt-acts-foot");
assert(acts.left >= reqs.right, "side by side");
// the accounts' column ends at its foot (Show N more, View usage)
assert(Math.abs(foot.bottom - reqs.bottom) <= 1 && foot.bottom >= acts.bottom, `the lists end on one line: ${reqs.bottom} / ${foot.bottom}`);
assert(acts.scroll, "the rest of the accounts scroll");
// a request on one line: its destination and numbers beside its model
const oneLine = () => page.locator(".rt-req").evaluateAll((rs) => rs.every((r) => {
const y = (s) => { const b = r.querySelector(s).getBoundingClientRect(); return b.width ? b.top : null; };
const a = y(".asked");
return [y(".to"), y(".meta")].every((v) => v === null || Math.abs(v - a) < 4);
}));
for (const width of [940, 1100]) {
await page.setViewportSize({ width, height: 1400 });
await page.waitForTimeout(200);
const requests = await box(".rt-reqs"), accounts = await box(".rt-acts");
assert(accounts.left < requests.right, `${width}px: one column`);
assert(await oneLine(), `${width}px: each request on one line`);
}
for (const width of [1440, 1920]) {
await page.setViewportSize({ width, height: 1400 });
await page.waitForTimeout(200);
const requests = await box(".rt-col:first-child"), accounts = await box(".rt-col:last-child");
const rw = requests.right - requests.left, aw = accounts.right - accounts.left;
assert(rw > aw * 1.6, `${width}px: requests should have more room than accounts (${rw} / ${aw})`);
assert(aw >= 260 && aw <= 360.5, `${width}px: account column stays readable and capped (${aw})`);
const rightList = await box(".rt-acts-foot"), leftList = await box(".rt-reqs");
assert(Math.abs(rightList.bottom - leftList.bottom) <= 1, `${width}px: list bottoms stay aligned`);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, `${width}px: no horizontal overflow`);
assert(await oneLine(), `${width}px: side by side, each request still on one line`);
}
// the Codex account's three models in its tooltip, under its id, none
// in the card: a card says its name, what is left and how it fares
// (ferock4669 on Discord)
const codex = page.locator(".rt-act", { hasText: "ann@example.com" });
const [id, models] = (await codex.getAttribute("title")).split("\n");
assert.equal(id, "codex:a");
assert.deepEqual(models.split(", ").sort(), ["gpt-5.6-luna", "gpt-5.6-terra", "gpt-6-luna"]);
assert.equal(await codex.locator("code").count(), 0);
// a provider's row: its model once, not its name again
const ai = page.locator(".rt-act").first();
assert.equal((await ai.locator(".nm").innerText()).trim(), "glm-5.3-flash");
assert.equal(await ai.locator("code").count(), 0);
// one column: the accounts as long as they are
await page.setViewportSize({ width: 700, height: 1400 });
await page.waitForTimeout(300);
const one = await box(".rt-acts");
assert(!one.scroll, "one column: nothing hidden in the accounts");
assert.equal(await page.locator(".rt-acts").evaluate((e) => e.style.maxHeight), "");
assert.deepEqual(errors, []);
});
}
}