Files
magpie/internal/gui/tests/editor-fold-clickable.test.cjs
T
yetone 900852e1c9 gui: an editor's Advanced fold reads as a control (sylvenPR on X)
sylvenPR on X: the 高级 fold at the foot of Codex's editor didn't look
like something to click. It was a 5px "▸" text glyph in the muted grey,
with a default cursor and nothing on hover, so it read as a disabled hint.

An editor's fold (.editor .more: Advanced on every provider, and a custom
provider's More endpoints) is now a macOS disclosure: a 10px chevron drawn
with a mask (turned down when open, as before), the label in the form
labels' colour (--fg-2), a pointer, the label and chevron brighter under
it, and a focus ring. The chevron still starts where the fields do
(--ed-at); no gradient, accent or layout change beyond the control.
The reporter's misalignment is not on main: editor-advanced-align already
holds it to the field column (their build predates that).

New test: editor-fold-clickable.test.cjs, Chromium and WebKit, dark and
light, en/zh/zh-TW/ja/de, Codex's Advanced and a custom provider's More
endpoints: pointer cursor, chevron >= ~10px and not a text glyph, label
colour equal to the form labels', a hover change, and it still opens.

Run (mote, through mote-run / ssh, playwright 1.62.0):
- At the pushed head, rebased on origin/main da275848b: editor-fold-clickable
  and editor-advanced-align ok in both engines; nav-timeout red from
  window-visibility.test.cjs (dfe868a1e), filed #4787.
- At the previous rebase (origin/main ec104b862): the 36 GUI files
  that reach an editor fold (editor-fold-clickable, editor-advanced-align,
  balance-*, provider-*, vertex-editor, zhipu-team, ...): 910 tests, 864
  pass. The 46 reds are balance-fix (#4682, #4683), vertex-editor (#4720,
  #4721) and zhipu-team (#4728); each red alone the same count at
  origin/main as at this head.
- Whole GUI suite (both engines) at base 1d8ded3ec with this change: mote
  rebooted after 243 of 1099 files; files 244-1099 rerun from there. Reds
  named, each run alone at origin/main and at this change:
  account-arrange webkit (#2200, passes alone), agent-panel-name-width
  (#4203), allow-ips (#4357, #3699), balance-fix (#4682, #4683),
  editor-advanced-align chromium under load (#4615, passes alone),
  cors-origins, context-map and gateway-key-models webkit (red the same
  at base). Second half: 39 red files, none reaching the fold; alone,
  main vs this change: model-chip-steady, model-copy-id,
  models-works-only, provider-fetch-again, provider-models-rest,
  provider-picks-stay, provider-typed, provider-levels-scroll,
  models-select-all-api equal; key-replace 5 vs 4, rest-try-now 5 vs 6,
  models-fold 1 vs 0 fails (timing, mote's main reds #4304, #4471,
  #3393); nav-timeout's red is balance-quota-left. The resumed second
  half was still running at push (184 not-ok lines so far).

Broken by hand: the old CSS fails the new test (cursor default); a 6px
chevron fails it ("the chevron is 6x6"); a hover rule with no change
fails it ("doesn't change under the pointer").

Before/after screenshots (Codex editor, zh and en, dark and light, both
engines, plus hover) were compared by eye.

Not tried: the real app's WebKitGTK on Linux and WebView2 on Windows; the
other <details> disclosure (Context's cx-part, a different component,
already a pointer) is left as it was.
2026-11-01 21:36:01 +08:00

94 lines
6.4 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// sylvenPR on X: the 高级 (Advanced) fold at the foot of Codex's editor
// didn't look like something to click: a 5px "▸" glyph in the muted grey,
// no pointer, nothing on hover. An editor's fold (Advanced, and a custom
// provider's More endpoints) is a macOS disclosure now: a chevron at least
// 10px, its label in the form labels' colour, a pointer, a brighter label
// under it, and the chevron where the fields start. Dark and light, every
// language, 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(process.env.MAGPIE_GUI_ASSETS || path.resolve(__dirname, "../assets"));
const codex = {
id: "codex", name: "Codex", icon: "codex-color", chat: "", responses: "https://chatgpt.com/backend-api/codex", anthropic: "", catalog: "",
models: [{ id: "gpt-6", name: "GPT-6", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
account: { agent: "codex", agentName: "Codex", user: "me@example.com", plan: "PRO", logins: [{ user: "me@example.com", plan: "PRO", active: true, on: true }] },
};
const relay = {
id: "relay", name: "Relay", icon: "", chat: "https://relay.example.com/v1/chat/completions", responses: "", anthropic: "", catalog: "",
models: [{ id: "m1", name: "m1", on: true }], agents: [], fallback: [], headers: {}, keyList: [], key: { set: true, masked: "sk-…1234" }, ready: true,
};
const serve = (lang, theme) => 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:${JSON.stringify(lang)},theme:${JSON.stringify(theme)},web:false};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme } });
if (url.pathname === "/api/providers") return json({ providers: [codex, relay], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
// how a fold's summary looks: cursor, label and chevron colours and size,
// where it starts against the fields
const look = (page, sel) => page.evaluate((sel) => {
const s = document.querySelector(sel), cs = getComputedStyle(s), b = getComputedStyle(s, "::before");
// the grid the fold sits in, and its first label beside a field
const g = s.parentElement.parentElement, label = [...g.children].find((c) => c.tagName === "LABEL" && c.offsetWidth && !c.classList.contains("tick"));
const lab = getComputedStyle(label);
return {
cursor: cs.cursor, color: cs.color, labelColor: lab.color,
chevW: parseFloat(b.width) || 0, chevH: parseFloat(b.height) || 0, glyph: b.content,
left: s.getBoundingClientRect().left, fields: label.nextElementSibling.getBoundingClientRect().left,
stacked: getComputedStyle(g).gridTemplateColumns.split(" ").length === 1,
};
}, sel);
for (const [engine, browserType] of [["chromium", chromium], ["webkit", webkit]]) {
test(engine + ": an editor's fold reads as a control", async (t) => {
const browser = await browserType.launch();
t.after(() => browser.close());
for (const theme of ["dark", "light"]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const [name, sel] of [["Codex", ".editor details.advanced > summary"], ["Relay", ".editor details.more:not(.advanced) > summary"]]) {
const at = `${name} ${theme} ${lang}`;
const context = await browser.newContext({ viewport: { width: 900, height: 900 }, colorScheme: theme, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, theme));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: name }).first().click();
const sum = page.locator(sel);
await sum.waitFor();
await page.waitForFunction((sel) => document.querySelector(sel)?.parentElement.style.getPropertyValue("--ed-at"), sel);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
const m = await look(page, sel);
assert.equal(m.cursor, "pointer", `${at}: the fold's cursor is ${m.cursor}`);
assert.ok(m.chevW >= 9.5 && m.chevH >= 9.5, `${at}: the chevron is ${m.chevW}x${m.chevH}`);
assert.ok(!/[▸▶►]/.test(m.glyph), `${at}: the chevron is a text glyph ${m.glyph}`);
assert.equal(m.color, m.labelColor, `${at}: the fold's label is ${m.color}, the form's labels ${m.labelColor}`);
if (!m.stacked) assert.ok(Math.abs(m.left - m.fields) <= 1, `${at}: the fold starts at ${m.left}, the fields at ${m.fields}`);
await sum.hover();
await page.waitForFunction(([sel, c]) => getComputedStyle(document.querySelector(sel)).color !== c, [sel, m.color]).catch(() => {});
const hovered = await look(page, sel);
assert.notEqual(hovered.color, m.color, `${at}: the fold's label doesn't change under the pointer`);
// it still opens and turns its chevron down
await sum.click();
await page.waitForFunction((sel) => document.querySelector(sel).parentElement.open, sel);
const turned = await page.evaluate((sel) => getComputedStyle(document.querySelector(sel), "::before").transform, sel);
assert.notEqual(turned, "none", `${at}: the chevron doesn't turn when open`);
assert.deepEqual(errors, []);
await context.close();
}
});
}