Files
magpie/internal/gui/tests/agent-hides-editor.test.cjs
T
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00

111 lines
7.4 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Kylin_Cloud on X: models left out of an agent's own list on the Agents
// page still looked ticked in the provider's editor, as if one setting had
// failed to sync. They are two settings (the picks are every agent's), so
// the editor says, under the models and on each chip, which agent's list
// leaves which ticked model out. While the provider is kept for routing
// groups no agent lists its models, and a picked chip says so instead.
// Chromium and WebKit, wide and narrow, in every language.
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 relay = {
id: "relay", name: "Relay", icon: "generic", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
models: ["alpha", "beta", "gamma"].map((id) => ({ id, name: id, on: true })), chosen: ["alpha", "beta", "gamma"],
groups: {}, unlisted: false, fallback: [], headers: {},
agents: [{ id: "codex", name: "Codex", icon: "generic", hides: ["beta"] }, { id: "claude", name: "Claude Code", icon: "generic" }],
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
};
const LINE = "{agent}'s model list leaves out {models}: shown again from there, on the Agents page.";
const CHIP = "Left out of {agents}'s model list, on the Agents page";
const PICKED = "Picked: the routing groups it is in use it. Agents don't see it.";
const fill = (s, v) => s.replace(/\{(\w+)\}/g, (_, k) => v[k]);
function serve(lang, p) {
return async (r) => {
const req = r.request(), url = new URL(req.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" || url.pathname === "/api/set") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {});
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups" || url.pathname.startsWith("/api/groups/")) return json({ groups: [], pools: [], deciders: [], models: [] });
if (url.pathname === "/api/providers") return json({ providers: [p], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999", groups: [] } });
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 });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1000, 420]) {
test(`${engine} ${lang} ${width}px: the editor says which agent's list leaves a ticked model out`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
const errors = [];
const open = async (p) => {
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
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: "Relay" }).click();
await page.locator(".editor .mchip").first().waitFor();
return page;
};
let page = await open(relay);
const w = await page.evaluate(([keys, lang]) => Object.fromEntries(keys.map((k) => [k, lang === "en" ? k : I18N[lang][k]])), [[LINE, CHIP, PICKED, "Only through routing groups"], lang]);
assert.deepEqual(Object.entries(w).filter(([, v]) => !v).map(([k]) => k), [], "every string has its words");
const hid = page.locator(".editor .agent-hides");
assert.ok(await hid.isVisible(), "said under the models");
assert.equal(await hid.textContent(), fill(w[LINE], { agent: "Codex", models: "beta" }));
const chip = (id) => page.locator(".editor .mchip", { hasText: new RegExp(`^${id}`) });
assert.ok((await chip("beta").getAttribute("title")).includes(fill(w[CHIP], { agents: "Codex" })), "the chip says it too");
assert.ok(!(await chip("alpha").getAttribute("title") || "").includes(fill(w[CHIP], { agents: "Codex" })), "only on the one left out");
const box = await hid.boundingBox();
assert.ok(box.x >= 0 && box.x + box.width <= width, `fits the width: ${JSON.stringify(box)}`);
assert.equal(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), true, "no sideways scroll");
assert.equal(parseFloat(await hid.evaluate((e) => getComputedStyle(e).borderLeftWidth)), 0, "no left-border accent");
// kept for routing groups: no agent lists them, so no agent's list
// is named, and a picked chip says the groups use it
const tick = page.locator(".editor label", { hasText: w["Only through routing groups"] }).locator("input");
const y = await page.evaluate(() => document.scrollingElement.scrollTop);
await tick.check();
assert.equal(await page.evaluate(() => document.scrollingElement.scrollTop), y, "a click never scrolls the page");
assert.ok(await hid.isHidden(), "not said while no agent lists them");
assert.ok((await chip("beta").getAttribute("title")).includes(w[PICKED]));
assert.ok(!(await chip("beta").getAttribute("title")).includes(fill(w[CHIP], { agents: "Codex" })));
await tick.uncheck();
assert.ok(await hid.isVisible(), "said again when unticked");
// saved as kept for routing groups, it opens that way
page = await open({ ...relay, unlisted: true });
assert.ok(await page.locator(".editor .agent-hides").isHidden());
assert.ok((await page.locator(".editor .mchip", { hasText: /^alpha/ }).getAttribute("title")).includes(w[PICKED]));
// nothing left out: nothing said
page = await open({ ...relay, agents: [{ id: "codex", name: "Codex", icon: "generic" }] });
assert.ok(await page.locator(".editor .agent-hides").isHidden());
assert.deepEqual(errors, []);
});
}
}
}