Files
magpie/internal/gui/tests/api-key-theme.test.cjs
T
yetone 18e82adc62 gui: the window's pages down a sidebar in groups, the open page's tabs under it, and a button to have the header's tabs instead
From 1024 points wide (SIDE_AT) the window lays its pages down the left
as a Mac app's sidebar: Work (Agents, Sessions, Library), Models
(Providers, Routing, Gateway), Insights (Usage), Extend (Plugins), with
Settings and the gateway's address at the foot. The open page's own tabs
(Usage, Library, Plugins, Settings) are listed under it, opening and
folding on an iOS-like spring, and the page's strip is hidden. The header
becomes a breadcrumb, and pages whose head held only tools have them in
the title bar. Graphite: the open page is in the text's ink, not purple.
A pressed row darkens and never shrinks. The selection under the tabs
sets off as the row is pressed, on a 0.3s curve (it felt behind the
finger), and is the list's only shape: a sub-row hovered or pressed has
no ground of its own, which showed a block under the finger before the
selection slid there. The page's tab is clicked at once, so what is
typed next goes to it.

The title bar's button (or ⌃⌘S, Ctrl+Shift+S), there at every width,
picks the sidebar or the header's tabs. The choice is kept in
localStorage magpie.navLayout (side or top) at every width, so it is laid
out from the first frame; picked in a narrow window the sidebar is 184
points under 860. The two trade places in
a view transition: the sidebar slides, each tab flies to its place, and
the page slides as one. Without view transitions or under reduced
motion, the change is at once.

With nothing picked, narrower than 1024 the page beside a sidebar would
be narrower than Usage's requests table needs, so the header's tabs come
back. A resize
drops what a click held (heldWidth). Usage's KPI strip goes two to a line
by the room the page gives it (a container query), and Japanese counts
wrap there. Tests whose window is 1024+ were updated for the sidebar,
and docs/subsystems/gui-shell.md says how it works.

Run: sidebar.test.cjs and side-toggle.test.cjs 16/16 in chromium and
webkit, in en, zh, zh-TW, ja and de. Each was broken by hand (press
shrink, address cut, press glide, sub-row ground, view transition, kept
choice) and went red. Every page at 560 points with the sidebar picked,
zh and de, both engines: nothing scrolls sideways. session-identity's
ledger row sits under the footer beside the sidebar; WebKit's click
doesn't scroll to it, so the test wheels it up first. Animation frames were checked from a recorded video. The 105
affected GUI files in both engines; their reds were rerun alone and fixed
(filter-ime: the sub-row's click now at once; session-identity, above) or
fail the same on main (tray-logos). The full GUI suite in chromium, on
the rebase onto d5cae267a, was cut short at 352 tests on the owner's
"ship": 6 reds (account-alias, account-models, codex-auto-review,
codex-credits, context-text) each pass alone, here and on main d5cae267a,
so they are timing under the full run's load and are to be filed. After
rebasing onto e4e22b23e: sidebar, side-toggle, session-identity,
filter-ime, library-instr-busy, usage-speed-count and view-scrollbar,
50/50 in chromium and webkit. go build ./... passes.
2026-10-12 00:41:34 +08:00

139 lines
7.8 KiB
JavaScript

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 { fixture } = require("./fixtures/caller-keys.cjs");
async function palette(page, selectors) {
return page.evaluate((selectors) => {
const root = getComputedStyle(document.documentElement);
const rgb = (name) => {
const hex = root.getPropertyValue(name).trim();
return `rgb(${[1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)).join(", ")})`;
};
const colors = Object.fromEntries(["bg", "card", "card-2", "fg", "fg-2", "muted", "ctl-fg", "pill", "line", "accent", "accent-fg"]
.map((name) => [name, rgb("--" + name)]));
const elements = Object.fromEntries(Object.entries(selectors).map(([name, selector]) => {
const s = getComputedStyle(document.querySelector(selector));
return [name, { color: s.color, bg: s.backgroundColor, border: s.borderTopColor }];
}));
return { colors, elements };
}, selectors);
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const theme of (process.env.THEME ? [process.env.THEME] : ["light", "dark", "system"])) {
test(`${engine} ${theme}: API key controls follow the global palette`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const context = await browser.newContext({ viewport: { width: 1000, height: 760 }, reducedMotion: "reduce", colorScheme: "light" });
const page = await context.newPage();
page.setDefaultTimeout(6000);
const events = [], errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", fixture("en", theme, events, { lan: true }));
await page.goto("http://magpie.test/?view=gateway");
await page.locator('#gatewayKeys .acc[data-key="server"] .dot').click();
await page.locator('#gatewayKeys .acc.off[data-key="server"]').waitFor();
await page.locator("#addGatewayKey").click();
await page.locator('#gatewayKeys .acc[data-key="laptop"] .rename').click();
await page.locator("#gatewayKeys .rename-in").waitFor();
await page.mouse.move(500, 20);
const gatewaySelectors = { card: "#gatewayKeys .accts", enabled: '#gatewayKeys .acc[data-key="work"] .dot',
disabled: "#gatewayKeys .acc.off .dot", masked: "#gatewayKeys .acc .plan", form: "#gatewayKeys .adding",
input: "#gatewayKeys .adding input", rename: "#gatewayKeys .rename-in", create: "#gatewayKeys .primary", rotate: '#gatewayKeys .acc[data-key="work"] .text', keyPick: "#connectKey" };
const gatewayPaints = [];
for (const scheme of ["light", "dark"]) {
await page.emulateMedia({ colorScheme: scheme });
await page.waitForTimeout(200);
const { colors: c, elements: e } = await palette(page, gatewaySelectors);
assert.equal(e.card.bg, c.card);
assert.equal(e.card.border, c.line);
assert.equal(e.enabled.bg, c.fg);
assert.equal(e.enabled.color, c.card);
assert.equal(e.disabled.color, c.muted);
assert.equal(e.masked.bg, c.pill);
assert.equal(e.masked.color, c.muted);
assert.equal(e.form.bg, c["card-2"]);
for (const input of [e.input, e.rename]) {
assert.equal(input.bg, c.card, "key inputs must not use the browser's default background");
assert.equal(input.color, c.fg);
}
assert.equal(e.rotate.color, c["ctl-fg"]); // a text button, in a control's quiet text (#477)
assert.equal(e.keyPick.bg, "rgba(0, 0, 0, 0)");
assert.equal(e.create.bg, c.accent);
assert.equal(e.create.color, c["accent-fg"]);
gatewayPaints.push(c.bg);
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${theme}-${scheme}-keys.png`) });
}
}
assert.equal(gatewayPaints[0] === gatewayPaints[1], theme !== "system", "only System follows an OS palette change");
await page.locator('#gatewayKeys .acc[data-key="work"]').getByRole("button", { name: "Rotate key", exact: true }).click();
await page.locator("#modal .lib-confirm").waitFor();
for (const scheme of ["light", "dark"]) {
await page.emulateMedia({ colorScheme: scheme });
await page.waitForTimeout(200);
const { colors: c, elements: e } = await palette(page, {
dialog: "#modal .dialog", message: "#modal .lib-confirm", confirm: "#modal .primary",
});
assert.equal(e.dialog.bg, c.card);
assert.equal(e.message.color, c["fg-2"]);
assert.equal(e.confirm.bg, c.accent);
assert.equal(e.confirm.color, c["accent-fg"]);
if (process.env.ARTIFACT_DIR) {
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${theme}-${scheme}-confirm.png`) });
}
}
await page.locator("#modal").getByRole("button", { name: "Cancel", exact: true }).click();
await page.locator("#modal").waitFor({ state: "hidden" });
assert.equal(events.filter((e) => e.action === "rotate-key").length, 0);
await page.goto("http://magpie.test/?view=settings&tab=network");
const on = page.locator("#lanList").getByRole("button", { name: "On", exact: true });
await on.waitFor();
// the settings are read twice as the page opens (its own read and the
// state's), each drawing #lanList again: where On is comes from one read
// in the page, since a box asked of a button already replaced is null
const y = await (await page.waitForFunction(() => [...document.querySelectorAll("#lanList button")]
.find((b) => b.textContent.trim() === "On")?.getBoundingClientRect().y)).jsonValue();
await page.mouse.move(500, 400);
await page.mouse.wheel(0, y - 250);
await on.click();
await page.locator("#lanList .lan-url").waitFor();
await page.mouse.move(500, 20);
for (const scheme of ["light", "dark"]) {
await page.emulateMedia({ colorScheme: scheme });
await page.waitForTimeout(200);
const { colors: c, elements: e } = await palette(page, { card: "#lanList", text: "#lanList .row.pref:last-child .name",
key: "#lanList .lan-url", copy: "#lanList .row.pref:last-child .copy" });
assert.equal(e.card.bg, c.card);
assert.equal(e.text.color, c.fg);
assert.equal(e.key.color, c["fg-2"]);
assert.equal(e.copy.color, c.muted);
}
if (theme === "system") {
await page.mouse.move(500, 400);
await page.mouse.wheel(0, -5000);
for (const choice of ["Dark", "Light", "System"]) {
await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").click();
await page.locator("#themeSegs").getByRole("button", { name: choice, exact: true }).click();
await page.waitForFunction((want) => (document.documentElement.dataset.theme || "system") === want, choice.toLowerCase());
await page.waitForFunction(() => !document.documentElement.classList.contains("theming"));
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
const { colors: c, elements: e } = await palette(page, { card: "#lanList", key: "#lanList .lan-url" });
assert.equal(e.card.bg, c.card);
assert.equal(e.key.color, c["fg-2"]);
}
await page.reload();
await page.locator("#themeSegs button.on").waitFor({ state: "attached" });
assert.equal(await page.locator("#themeSegs button.on").textContent(), "System");
}
assert.deepEqual(errors, []);
});
}
}