Files
magpie/internal/gui/tests/agent-leave-magpie.test.cjs
T
yetone d7b1145d18 gui: English text no longer carries Chinese words (fangleeway)
fangleeway on Discord: taking Claude Code off magpie said, in the English
window, "「接入」 goes off, and Claude Code is listed under Not set up". An
English reader has no 「接入」 to look for. English is the key of every
string, so every language that lacks a word shows the English one too.

Every English string with Chinese in it, now in English:
- leaving magpie (both forms): "The switch that connects it to magpie
  goes off ..." (the switch has no visible label in English, only the
  aria-label "Connect {agent} to magpie"); ja and de say the same, zh and
  zh-TW keep 「接入」, which is their label.
- the check-in rows and the Check in now title: "as pressing 签到 in X"
  becomes "the same as checking in from X itself" / "Check in now for the
  accounts not checked in today".
- ZCode's site picker and hint: "BigModel (智谱)" and "bigmodel.cn for
  智谱" say Zhipu; zh/zh-TW/ja keep their own 智谱/智譜.
Placeholders are unchanged in every language. ZCode's site buttons were
also how its plugin's way for a site was found (the label "BigModel
(智谱)" inside "ZCode: BigModel (智谱) GLM Coding Plan"), so a site now
carries the plugin's word apart from the label it shows: [id, label,
host, word]. Without that, the BigModel button would sign in on Z.ai and
both site ways would show again under the sites (zcode-site-layout went
12 of 12 red that way before the word was added).

Kept on purpose, listed with why in the guard: the font preview's
"Aa 0123 · 中文", the "万 / 亿" units option, and the three masking rules
that name the words they look for (护照, 生日, 序列号).

Guard: tests/i18n-en-no-cjk.test.cjs (no browser) fails on CJK text in
any English key of i18n.js or a plugin's i18n.js, in NOTICES, in a t()
literal in app.js or a plugin's script, or in index.html's data-t text.

Broken by hand: the old 「接入」 string put back in i18n.js and app.js, and
工作 in index.html's data-t: the guard names each (3 of 4 tests red);
the site's plugin word removed: zcode-site-layout red.

Run (mote, at the pushed head of this commit and the two after it,
bae625cdf on origin/main 8a8079680):
- node --test redact-words-import, i18n-en-no-cjk, zcode-site,
  zcode-site-layout, plugin-moved-signin, plugin-other-ways, zhipu-team,
  gui-de, gui-ja, gui-zh-tw, i18n-keys, agent-leave-magpie,
  agent-own-direct, checkin-now-account, checkin-account, plugin-checkin,
  usage-checkin: 215 of 215 ok.
- go test ./internal/gui/...: ok but TestMainWindowCorners/macOS_26_SDK,
  red the same at origin/main 8a8079680 (#3949, macOS 27 on mote);
  TestCoreScriptBudget ok.
- The whole GUI suite was not run before the push: both test boxes were
  running other sessions' GUI suites (one suite a machine). It runs after
  the tag; reds are filed.
- Rebased on origin/main d02b8a000 (agent-own-direct, app.js, i18n.js
  changed there) and run again at the pushed tree: TestCoreScriptBudget,
  i18n-en-no-cjk, i18n-keys, gui-de, gui-ja, gui-zh-tw and
  agent-own-direct, 37 of 37 ok.

app.js is 82 bytes under origin/main's: the new words and the site's
plugin word are paid for by two comments cut; no budget raised.
Not tried: the real Wails window, a real ZCode BigModel sign-in through
the plugin. The plugin's own method label still says "BigModel (智谱)";
it is the plugin's text (magpie-community/plugins, zcode) and the site
buttons hide it.
2026-11-04 22:19:21 +08:00

197 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// #726 (EZN7L2C3): with Claude Code connected, picking Opus 5.5 in its
// model list moved it under Not set up and turned 「接入」 off, picking
// Sonnet 5.5 then turned it back on, and neither row said why: the Opus
// was Claude Code's own model, asked of Anthropic directly (picking it
// unroutes Claude Code), the Sonnet magpie's, its "· via magpie" cut off
// the end of a long note. Now each model says which way it goes, and a
// pick that takes a connected agent off magpie (one of its own models, or
// Default) is asked first, as the switch's off is; Default's ask offers
// Disconnect and restore beside it, the two not being the same. Switched
// on, the switch says what model it started the agent on and why. No click
// moves the page; in English and Chinese, the API faked here.
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 options = [
{ value: "claude-opus-5-5", note: "Claude Opus 5.5", group: "Claude Code", direct: "Anthropic", icon: "claude-color" },
{ value: "claude-sonnet-5-5", note: "Claude Sonnet 5.5", group: "Claude Code", direct: "Anthropic", icon: "claude-color" },
{ value: "claude/claude-sonnet-5-5[1m]", label: "Claude Sonnet 5.5", ref: "claude/claude-sonnet-5-5", group: "Claude", icon: "claude-color",
note: "someone.with.a.long.address@example.com · via magpie" },
{ value: "claude/claude-opus-5-5[1m]", label: "Claude Opus 5.5", ref: "claude/claude-opus-5-5", group: "Claude", icon: "claude-color",
note: "someone.with.a.long.address@example.com · via magpie" },
];
const fresh = () => ({
agents: [
{ id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", wired: true, fields: [{ key: "model", label: "model", value: "claude/claude-sonnet-5-5[1m]", options }] },
{ id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", wired: true, fields: [{ key: "model", label: "model", value: "", options: [{ value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }] }] },
],
profiles: [],
});
function server(lang, posts) {
let cur = fresh();
const reply = (route, extra = {}) => route.fulfill({ json: { ...cur, ...extra, settings: { lang, theme: "light" } } });
const handle = async (route) => {
const req = route.request(), url = new URL(req.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 reply(route);
if (url.pathname === "/api/set") {
const body = JSON.parse(req.postData());
posts.push(body);
cur = JSON.parse(JSON.stringify(cur));
const a = cur.agents.find((x) => x.id === body.agent);
a.fields[0].value = body.value;
a.wired = body.value.includes("/");
return reply(route);
}
if (url.pathname === "/api/agents/connect/claude") {
posts.push({ connect: "claude" });
cur = JSON.parse(JSON.stringify(cur));
const a = cur.agents.find((x) => x.id === "claude");
a.wired = true;
a.fields[0].value = "claude/claude-sonnet-5-5[1m]";
return reply(route, { connected: { how: "default", field: "model", value: "claude/claude-sonnet-5-5[1m]" } });
}
if (url.pathname.startsWith("/api/agents/preview/")) return json({ changes: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
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), contentType });
};
// Claude Code off magpie, as the next /api/state says too
handle.unwire = () => { cur = JSON.parse(JSON.stringify(cur)); cur.agents.find((x) => x.id === "claude").wired = false; };
return handle;
}
const words = {
en: { via: "via magpie", direct: "direct, not via magpie", off: "off magpie", ask: "Take Claude Code off magpie?", use: "Use claude-opus-5-5", restore: "Disconnect and restore", cancel: "Cancel", connected: "it had no model set, so the first of its own" },
zh: { via: "经 magpie", direct: "直连,不经 magpie", off: "不经 magpie", ask: "让 Claude Code 不再经过 magpie?", use: "使用 claude-opus-5-5", restore: "断开并还原", cancel: "取消", connected: "原先未设模型" },
};
const row = '.row.agent[data-id="claude"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
const w = words[lang];
test(`${engine} ${lang}: a pick that takes Claude Code off magpie says so and is asked first`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width: 980, height: 560 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [], dialogs = [];
page.on("pageerror", (e) => errors.push(e.message));
page.on("dialog", (d) => { dialogs.push(d.message()); d.dismiss(); });
const srv = server(lang, posts);
await page.route("**/*", srv);
await page.goto("http://magpie.test/?view=agents");
await page.locator(`${row} .ag-conn`).waitFor();
const missing = await page.evaluate(() => [
"via magpie", "{agent} asks magpie for it", "direct, not via magpie", "off magpie",
"{agent} as installed: magpie's endpoint and models come out", "Take {agent} off magpie?",
"Default is {agent} as installed: magpie's endpoint and models come out, and {agent} starts on its own default model. What it had before magpie isn't put back; Disconnect and restore does that.",
"{model} is {agent}'s own model: {agent} asks {vendor} for it itself, with its own sign-in, not through magpie. Picking it takes {agent} off magpie, and it starts on {model}.",
"The switch that connects it to magpie goes off, and {agent} is listed under Not set up with the agents not connected. Switch it on again to go back through magpie.",
"The switch that connects it to magpie goes off. Switch it on again to go back through magpie.",
"Use default", "Use {model}", "{agent} no longer goes through magpie · on its own default",
"{agent} is connected to magpie · back on {model}, what it was on when it was switched off",
"{agent} is connected to magpie · on {model} through magpie, the model it was on",
"{agent} is connected to magpie · on {model} through magpie: it had no model set, so the first of its own",
"{agent} is connected to magpie · on {model} through magpie: magpie doesn't serve the model it was on",
"{agent} is connected to magpie · it stays on its own last pick; magpie's models join its {cmd}",
].filter((k) => !I18N.zh[k]));
assert.deepEqual(missing, [], "every string has its Chinese");
const tops = () => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
const top = await tops();
const start = page.locator(`${row} > .field.ag-start`);
const item = (text) => page.locator("#pop #list li", { hasText: text }).first();
const open = async () => { await start.click(); await page.locator("#pop:not([hidden]) #list li").first().waitFor(); };
// each model says which way it goes, the tag whole however long the note
await open();
const tag = (li) => li.locator(".badge.path").textContent();
assert.equal(await tag(item("claude-opus-5-5")), w.direct);
const via = item("someone.with");
assert.equal(await tag(via), w.via);
assert.ok(await via.locator(".badge.path").evaluate((b) => b.scrollWidth <= b.clientWidth + 1 && b.getBoundingClientRect().right <= b.closest("li").getBoundingClientRect().right), "the tag isn't cut off");
assert.ok(!(await via.locator(".n").textContent()).includes("via magpie"), "said once, as the tag");
assert.equal(await tag(page.locator("#pop #list li.reset", { hasText: lang === "en" ? "Default" : "默认" }).first()), w.off);
// Claude Code's own Opus is asked first; Cancel leaves it connected
await item("claude-opus-5-5").click();
const ask = page.locator("#modal .leave-ask");
await ask.waitFor();
assert.equal((await ask.locator(".ehead b").textContent()).trim(), w.ask);
assert.deepEqual(posts, [], "nothing written before it is confirmed");
await ask.locator("button", { hasText: w.cancel }).click();
await ask.waitFor({ state: "detached" });
assert.deepEqual(posts, []);
assert.equal(await page.locator(`${row} .ag-conn`).getAttribute("aria-checked"), "true");
// Default is asked too, with Disconnect and restore beside it
await open();
await page.locator("#pop #list li.reset", { hasText: lang === "en" ? "Default" : "默认" }).first().click();
await ask.waitFor();
assert.equal(await ask.locator("button", { hasText: w.restore }).count(), 1);
await ask.locator("button", { hasText: w.cancel }).click();
await ask.waitFor({ state: "detached" });
assert.deepEqual(posts, []);
// confirmed, it is written: off magpie, 「接入」 off
await open();
await item("claude-opus-5-5").click();
await ask.waitFor();
await ask.locator("button", { hasText: w.use }).click();
await page.waitForFunction(() => document.querySelector("#modal").hidden);
await page.waitForFunction((r) => document.querySelector(r + " .ag-conn")?.getAttribute("aria-checked") === "false", row);
assert.deepEqual(posts, [{ agent: "claude", field: "model", value: "claude-opus-5-5" }]);
// a model of magpie's picked while not connected connects it, no ask
// (the owner's one click), and is said to go through magpie; off
// magpie, the row is folded under Not set up with Codex still on it
assert.equal(await page.locator(".agent-more").getAttribute("aria-expanded"), "false");
await page.locator(".agent-more").click();
await open();
assert.equal(await tag(item("someone.with")), w.via);
await item("someone.with").click();
await page.waitForFunction((r) => document.querySelector(r + " .ag-conn")?.getAttribute("aria-checked") === "true", row);
assert.equal(await page.locator("#modal:not([hidden]) .leave-ask").count(), 0);
assert.equal(posts.length, 2);
// a pick within magpie's models isn't asked
await open();
await page.locator("#pop #list li", { hasText: "someone.with" }).filter({ hasText: "Opus" }).click();
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="claude"] > .field.ag-start')?.textContent.includes("Opus"));
assert.equal(await page.locator("#modal:not([hidden]) .leave-ask").count(), 0);
assert.deepEqual(posts.at(-1), { agent: "claude", field: "model", value: "claude/claude-opus-5-5[1m]" });
// the switch says what it started the agent on, and why
const s = page.locator(`${row} .ag-conn`);
// (off on the server too: closing the model list read /api/state again,
// which put the switch back on under a click in Chromium)
srv.unwire();
await page.evaluate(async () => { state = await api("state"); renderAgents(); });
await page.waitForFunction((r) => document.querySelector(r + " .ag-conn")?.getAttribute("aria-checked") === "false", row);
await s.click();
await page.waitForFunction((r) => document.querySelector(r + " .ag-conn")?.getAttribute("aria-checked") === "true", row);
assert.ok((await page.locator("#status").textContent()).includes(w.connected), await page.locator("#status").textContent());
assert.ok((await page.locator("#status").textContent()).includes("Claude Sonnet 5.5"));
assert.deepEqual(await tops(), top, "no click moved the page");
assert.deepEqual(dialogs, [], "no native dialog");
assert.deepEqual(errors, []);
});
}
}