Files
magpie/internal/gui/tests/first-untick.test.cjs
T
yetone 219b60f494 accounts: the first account of a gateway-served subscription ticks off (Rime_Nan on X)
Rime_Nan on X: in WorkBuddy's account list the first account (First) couldn't be ticked off; it took dragging another account above it first. For a subscription the gateway serves itself (plugins, Copilot, ChatGPT API, Gemini, Antigravity), First is only the order the gateway tries accounts in; no agent is signed in to it. setSideLoginOn still refused it ("put another account first"), and the GUI drew its tick fixed.

Now, unticking the first account hands First to the next ticked account that hasn't lapsed and turns this one off. If no other account is ticked, it is still refused, with "tick another to stop using it", and the GUI's fixed tick says the same. An account the user left off is never ticked on. Claude and Codex (pausable) are unchanged.

To keep the core scripts in their budget without raising it, the bytes were paid for by cutting renderAccounts' comment to one line: app.js is +20 bytes, under 1,533,802.

TestCopilotAccounts asserted the old refusal; it now checks the handover and that the only account in use still can't be ticked off.

Run (mote, macOS 27, at f9dda0d3e on origin/main f0e0385a0):
- go test ./internal/provider: ok.
- internal/gui: TestCoreScriptBudget and TestI18n ok.
- gofmt clean; GOOS=windows go vet ./internal/provider ok; at the earlier base, GOOS=linux go vet ./internal/provider and GOOS=windows go vet ./internal/gui ok.
- GUI first-untick.test.cjs (both engines, en/zh/zh-TW/ja/de) and i18n-keys: 24/24.
- Earlier base 694f4a6d6: the whole internal/gui package on mote, red only in TestMainWindowCorners (#3949, macOS 27) and the budget, since fixed. internal/provider passed on Linux (WSL); internal/gui doesn't build there (no gtk4/webkitgtk-6.0 dev packages).
- GUI keep-login, settings-tabs-stick, view-no-sideways, *account*, *plugin*, *copilot* at the earlier base: 1773/1783. The reds, run alone, are red on origin/main 694f4a6d6 as well: plugin-move-unserved's Try again (#4410) and account-eye's Usage card subtest (filed #5052).

Broken by hand: with the old setSideLoginOn, TestFirstTickedOffHandsFirstOn and TestOwnFirstCopilotTickedOff fail ("magpie uses a@x.com first; put another account first"). With the old app.js, first-untick.test.cjs fails 10/10 in Chromium.

Not tried: unticking with a real WorkBuddy plugin account in the app; the tests use Antigravity and Copilot saved logins, and the GUI test uses a stubbed Copilot provider.
2026-11-03 16:43:12 +08:00

101 lines
5.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Rime_Nan on X: in a subscription magpie's gateway serves (Copilot, a
// plugin's), the first account's tick was fixed, so it could be ticked off
// only after dragging it down the list. With another account ticked, its
// tick posts login/off, and the next ticked one is first (the server's);
// with none, it stays fixed and says to tick another. Both engines, 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 copilot = (spareOn) => ({
id: "copilot", name: "Copilot", icon: "githubcopilot", chat: "", responses: "", anthropic: "", catalog: "",
models: [{ id: "gpt-6", name: "GPT-6", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
account: {
agent: "copilot", agentName: "Copilot", user: "first", plan: "PRO",
logins: [
{ user: "first", plan: "PRO", active: true, on: true },
{ user: "spare", plan: "PRO", on: spareOn },
],
},
});
function serve(lang, list, posts) {
const providers = { providers: list, presets: [], excluded: [], gateway: { running: true, window: true } };
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
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:"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.startsWith("/api/") && route.request().method() === "POST") {
posts.push({ action: url.pathname.slice("/api/".length), body: route.request().postDataJSON() });
return json(providers);
}
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 });
};
}
const fixedTitle = "The gateway uses this account first; tick another to stop using it";
const offTitle = "Stop using this account; the next ticked one is used first";
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
const open = async (t, list) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
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));
const posts = [];
await page.route("**/*", serve(lang, list, posts));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: "Copilot" }).first().click();
await page.locator(".editor .acc").first().waitFor();
return { page, errors, posts };
};
const tr = (page, k) => page.evaluate(([l, k]) => (l === "en" ? k : I18N[l][k]), [lang, k]);
test(`${engine} ${lang}: the first account ticks off while another is ticked`, async (t) => {
const { page, errors, posts } = await open(t, [copilot(true)]);
const first = page.locator(".editor .acc", { hasText: "first" }).first();
const tick = first.locator(".tick");
assert.equal(await tick.evaluate((e) => e.classList.contains("fixed")), false, "not fixed");
assert.equal(await tick.getAttribute("title"), await tr(page, offTitle));
const n = posts.length;
await tick.click();
for (let i = 0; i < 50 && posts.length === n; i++) await page.waitForTimeout(50);
const p = posts.at(-1);
assert.equal(p?.action, "login/off");
assert.deepEqual(p.body, { agent: "copilot", user: "first" });
assert.deepEqual(errors, []);
});
test(`${engine} ${lang}: the only ticked account stays, and says to tick another`, async (t) => {
const { page, errors, posts } = await open(t, [copilot(false)]);
const tick = page.locator(".editor .acc", { hasText: "first" }).first().locator(".tick");
assert(await tick.evaluate((e) => e.classList.contains("fixed")), "fixed");
const title = await tick.getAttribute("title");
assert.equal(title, await tr(page, fixedTitle));
assert(title, "translated");
const n = posts.length;
await tick.click();
await page.waitForTimeout(300);
assert.equal(posts.length, n);
assert.deepEqual(errors, []);
});
}
}