Files
magpie/internal/gui/tests/accounts-switch-alone.test.cjs
T
yetone 823e7c250b providers: Claude Code's and Codex's Accounts say switching needs no connecting (Greatrobbort on X)
Greatrobbort on X: "多账号这个我一直都没搞明白到底需要在magpie关联agent不". The
owner asked for the window to say it: to have accounts switched
automatically, the agent needn't be connected. magpie moves Claude Code's
and Codex's own sign-in to the next account with room either way
(KeepOnAnAccountWithRoom runs SwitchWhenSpent for both, whether or not the
agent's config points at magpie).

The Accounts field's hint on Claude's and Codex's subscriptions now ends
"Just want accounts switched? {agent} needn't be connected to magpie.", after
whichever hint it shows (Routing's or the sign-in one). zh, zh-TW, ja and de
have it. Other subscriptions, which only the gateway uses, don't.

app.js stays in its budget (9 bytes over main, 12 of room): three
account-row comments cut down, no raise.

accounts-switch-alone.test.cjs opens Claude's (no Routing) and Codex's
(Routing smart) editors and finds the line, Copilot's and doesn't; Chromium
and WebKit, en zh zh-TW ja de, 1000 and 560px, and the editor no wider
than the window.

Run at this head (on origin/main 50aaa5726), on mote through mote-run:
- go test -run Budget ./internal/gui/: ok.
- node --test i18n-keys, agent-failover, agent-switch-accounts,
  claude-setup-token, keep-login, panel-switch-accounts, plugin-move,
  account-rows-fit, accounts-switch-alone: 155 ok, 0 red at f73c2fc8f;
  after 50aaa5726's app.js change, budget ok again and i18n-keys,
  agent-switch-accounts, keep-login, account-rows-fit, accounts-switch-alone
  and codex-subagent-model: 113 ok, 0 red.

Broken by hand: with "+ alone" taken off the hint, accounts-switch-alone is
red 20 of 20 ("Claude's editor doesn't say it needs no connecting").

Not tried: the real app's window; the whole GUI suite (mote at load ~90
with other sessions' suites).
2026-11-04 22:28:53 +08:00

72 lines
4.4 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Claude Code's and Codex's Accounts say that switching accounts needs no
// connecting the agent (Greatrobbort on X: "多账号这个我一直都没搞明白到底需要
// 在magpie关联agent不"): magpie moves the agent's own sign-in either way. A
// subscription the gateway alone uses, Copilot here, doesn't say it.
// Chromium and WebKit, every language, a wide and a narrow window; no
// backend, the API is 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 users = ["one@example.com", "two@example.com"];
const sub = (id, name, icon, agentName, routing) => ({
id, name, icon, models: [], agents: [], fallback: [], headers: {}, keyList: [], ...(routing ? { routing } : {}),
account: { agent: id, agentName, user: users[0], plan: "pro", logins: users.map((user, i) => ({ user, plan: "pro", active: i === 0, on: true })) },
});
const providers = [sub("claude", "Claude", "claudecode-color", "Claude Code"), sub("codex", "Codex", "openai", "Codex", "smart"), sub("copilot", "Copilot", "githubcopilot", "Copilot")];
function serve(lang) {
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:"${lang}",theme:"dark",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({ agents: [], profiles: [], settings: { lang, theme: "dark" } });
if (url.pathname === "/api/providers") return json({ providers, presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
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: "" }); }
};
}
const says = {
en: (a) => `${a} needn't be connected to magpie`,
zh: (a) => `不需要把 ${a} 接入 magpie`,
"zh-TW": (a) => `不需要把 ${a} 接入 magpie`,
ja: (a) => `${a} を magpie に接続する必要はありません`,
de: (a) => `Dafür muss ${a} nicht mit magpie verbunden sein`,
};
const engines = process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"];
for (const engine of engines) {
for (const lang of Object.keys(says)) {
for (const width of [1000, 560]) {
test(`${engine} ${lang} ${width}px: Claude Code's and Codex's Accounts say switching needs no connecting`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
for (const [name, agent, shown] of [["Claude", "Claude Code", true], ["Codex", "Codex", true], ["Copilot", "Copilot", false]]) {
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: name }).first().click();
await page.locator(".editor .acc").first().waitFor();
const text = await page.locator(".editor").innerText();
assert.equal(text.includes(says[lang](agent)), shown, `${name}'s editor ${shown ? "doesn't say" : "says"} it needs no connecting`);
if (shown) assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, `${name}'s editor is wider than the window`);
}
assert.deepEqual(errors, []);
});
}
}
}