Files
magpie/internal/gui/tests/advanced-headings.test.cjs
T
yetone 31575f71a1 gui: the provider editor's Advanced rows sit under four small headings
The provider editor's Advanced held some thirty rows in one run (item
19). They now sit under four small headings, Routing, Models, Limits and
cost, and Connection, each row keeping its order inside its group; a row
the list doesn't name stays with the one before it, and the headings
show only when two groups are used. No page, row or fold moves
elsewhere. advgroups.js is imported when Providers first draws, so it
weighs nothing on the core script, and the editor opens with the
headings already in place.

Not done from item 19: a routing group's strategy stays under the
group's Advanced. The owner folded it there on purpose (9edc6506e,
11-09, "the Add group form was too long"; and for providers on 11-12,
"这些也要折叠在高级里"), and routing-advanced holds the provider side.

New test: advanced-headings, for an account and a key, both engines,
every language: the headings in order, Routing/Stays under Routing,
Context window under Models, Requests at once under Limits and cost,
Proxy under Connection, the heading across the whole row.

Broken by hand: both groupAdvanced(advIn) calls removed,
advanced-headings 10 of 10 red; put back, 10 of 10 green.

Run (mote, Chromium and WebKit, en zh zh-TW ja de):
- before the rebase, 23 GUI files: every one green except
  plugin-provider-options (my bug, fixed in this branch before the push)
  and settings-groups' "warm-ups and check-in in each service's provider
  editor", red the same way at fresh origin/main 98c487d09 (an extra
  "Spend extra usage" row; #6597, commented with the sha).
- rebased on origin/main 98c487d09: advanced-headings,
  plugin-provider-options, i18n-keys, routing-advanced, provider-prefs,
  settings-search, panel-profiles, builtins, chatgpt-usage-why,
  provider-concurrency, websearch-places, library-mcp-hub all green;
  go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS' ok;
  ./internal/library, pii, plugin, provider and access ok; go vet ok.
  No budget raised.

The Codex client row 07d19510f added to the Codex provider's Advanced
sits under Connection, beside User-Agent: which client the requests say
they come from. advanced-headings has a Codex account for it; with the
row left out of the list, 10 of 10 red.

Again at the pushed head, rebased on origin/main 39c5040d7 and 07d19510f
(mote, Chromium and WebKit, every language): advanced-headings,
plugin-provider-options, i18n-keys, routing-advanced, provider-prefs,
settings-search, panel-profiles, builtins, chatgpt-usage-why,
provider-concurrency, websearch-places, library-mcp-hub, codex-client,
codex-client-editor and nav-timeout all green; go test ./internal/gui
-run 'TestCoreScriptBudget|TestI18n|TestCSS' ok; ./internal/library, pii,
plugin, provider, access, ghtoken, davsync and gwmw ok, and the gateway
and agent tests whose strings changed; gofmt -l empty; go vet,
GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./internal/...
clean. (GOOS=linux go vet ./... without nogui stops in Wails' cgo-only
webview_window_linux.go, the same on origin/main 39c5040d7.)

Not tried: the real app window, and Linux/Windows runs (cross-OS go vet
only).
2026-11-18 14:32:44 +08:00

109 lines
6.5 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// The provider editor's Advanced holds some thirty rows. They sit under
// four small headings, Routing, Models, Limits and cost, and Connection
// (advgroups.js; the 11-17 scan, item 19), each row in its own order
// inside its group. For an account and a key, in 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(__dirname, "../assets");
const base = { icon: "generic", catalog: "", models: [{ id: "glm-5", name: "GLM-5", on: true }], agents: [], fallback: [], headers: {}, routing: "", affinity: "", ready: true };
const sub = {
...base, id: "workbuddy-ai", name: "WorkBuddy AI", chat: "", responses: "", anthropic: "", keyList: [],
account: {
agent: "workbuddy-ai", agentName: "WorkBuddy AI", user: "one@example.test", plan: "Pro",
logins: ["one", "two"].map((n, i) => ({ user: `${n}@example.test`, plan: "Pro", active: i === 0, on: true })),
},
};
// Codex's own Codex client row (07d19510f) goes under Connection, beside User-Agent
const codex = {
...base, id: "codex", name: "ChatGPT", chat: "", responses: "", anthropic: "", keyList: [],
account: {
agent: "codex", agentName: "Codex", user: "one@example.test", plan: "Plus",
logins: ["one", "two"].map((n, i) => ({ user: `${n}@example.test`, plan: "Plus", active: i === 0, on: true })),
},
};
const relay = {
...base, id: "relay", name: "Relay", chat: "https://relay.example.invalid/v1", responses: "", anthropic: "", key: { set: true, masked: "sk-…1234" },
keyList: [1, 2].map((i) => ({ id: `key-${i}`, name: `Key ${i}`, masked: `sk-…000${i}`, active: i === 1, on: true })),
};
function serve(lang, p) {
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
const providers = { providers: [p], presets: [], excluded: [], gateway: { running: true, window: true } };
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:${JSON.stringify(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/providers") return json(providers);
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);
await route.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)] });
};
}
// the heading each label sits under, in order, as the reader sees it
const layout = () => {
const inner = document.querySelector(".editor details.advanced > .inner");
const out = [];
let head = "";
for (const n of inner.children) {
if (n.classList.contains("adv-head")) { head = n.textContent; out.push({ head }); }
else if (n.nodeName === "LABEL" && !n.hidden && n.textContent) out.push({ label: n.textContent, under: head });
}
return out;
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: the provider editor's Advanced rows sit under Routing, Models, Limits and cost, Connection`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const p of [sub, codex, relay]) {
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, p));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: p.name }).first().click();
await page.locator(".editor .accts").first().waitFor();
await page.locator(".editor details.advanced > summary").click();
await page.locator(".editor details.advanced .adv-head").first().waitFor();
const said = await page.evaluate(() => Object.fromEntries(["Routing", "Models", "Limits and cost", "Connection", "Stays", "Context window", "Requests at once", "Headers", "Proxy", "Codex client"].map((k) => [k, t(k)])));
const rows = await page.evaluate(layout);
const at = `${p.name}: ${JSON.stringify(rows)}`;
const heads = rows.filter((r) => r.head).map((r) => r.head);
assert.deepEqual(heads, [said.Routing, said.Models, said["Limits and cost"], said.Connection].filter((h) => heads.includes(h)), `${at}: headings in order`);
assert.ok(heads.length >= 3, `${at}: three headings or more`);
assert.ok(rows[0].head, `${at}: a heading comes first`);
const under = (label) => rows.find((r) => r.label === label)?.under;
assert.equal(under(said.Routing), said.Routing, at);
assert.equal(under(said.Stays), said.Routing, at);
assert.equal(under(said["Context window"]), said.Models, at);
assert.equal(under(said["Requests at once"]), said["Limits and cost"], at);
assert.equal(under(said.Proxy), said.Connection, at);
if (p === codex) assert.equal(under(said["Codex client"]), said.Connection, at);
// the heading takes the whole row: the labels keep their column
const box = await page.evaluate(() => {
const h = document.querySelector(".editor .adv-head"), inner = h.parentElement;
return { h: h.getBoundingClientRect().width, inner: inner.getBoundingClientRect().width - parseFloat(getComputedStyle(inner).paddingLeft) - parseFloat(getComputedStyle(inner).paddingRight) };
});
assert.ok(Math.abs(box.h - box.inner) < 2, `${at}: heading spans the row ${JSON.stringify(box)}`);
assert.deepEqual(errors, [], at);
await page.context().close();
}
});
}
}