Files
magpie/internal/gui/tests/zcode-site.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

84 lines
4.9 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// ZCode's sign-in asks where the account is (Z.ai or BigModel/智谱) and posts
// that site; a GLM team plan's resets are counted by window with no "Use" button.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const playwright = require("playwright");
const engines = (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"]);
const assets = path.resolve(__dirname, "../assets");
for (const engine of engines) for (const lang of ["en", "zh"]) {
test(`zcode site chooser and team resets (${engine}, ${lang})`, async (t) => {
const browser = await playwright[engine].launch();
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width: 420, height: 640 } });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const posted = [];
await page.route("**/*", 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: {} });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/signin") {
posted.push(route.request().postDataJSON());
return json({ id: "zflow", agent: "zcode", state: "waiting", url: "http://vendor.test/oauth" });
}
if (url.pathname === "/api/signin/zflow") return new Promise(() => {}); // stays waiting
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)];
return route.fulfill({ body: await fs.readFile(file), contentType });
});
await page.goto("http://magpie.test/?view=providers");
await page.waitForFunction((l) => state.settings.lang === l, lang);
// the sign-in starts on the Providers page, its list read: whether a
// subscription is moved onto its plugin is told from it (subOf)
await page.waitForFunction(() => providers);
// starting ZCode's sign-in asks the site first, posting nothing
await page.evaluate(() => {
window.renderProviders = () => {
const host = document.getElementById("zsite") || Object.assign(document.createElement("div"), { id: "zsite" });
host.style.cssText = "position:fixed;inset:0 auto auto 0;width:100%;z-index:1000;";
host.replaceChildren(signing ? renderSigning(subOf("zcode")) : "");
document.body.append(host);
};
startSignIn("zcode", true);
});
await page.waitForFunction(() => signing?.state === "site");
assert.equal(posted.length, 0);
const title = lang === "zh" ? "你的" : "Where is your";
assert.match(await page.locator("#zsite").innerText(), new RegExp(title));
const sites = await page.locator("#zsite button[data-site]").evaluateAll((bs) => bs.map((b) => [b.dataset.site, b.textContent, b.title]));
assert.deepEqual(sites.map((s) => s[0]), ["zai", "bigmodel"]);
assert.equal(sites[1][1], lang === "zh" ? "智谱 BigModel" : "BigModel (Zhipu)");
assert.equal(sites[1][2], "bigmodel.cn");
// BigModel posts its site and keeps it for "Try again"
await page.locator('#zsite button[data-site="bigmodel"]').click();
await page.waitForFunction(() => signing?.state === "waiting");
assert.deepEqual(posted, [{ agent: "zcode", site: "bigmodel" }]);
assert.equal(await page.evaluate(() => signing.site), "bigmodel");
// a team's resets are counted by window and not spent here
const words = await page.evaluate(() => {
const w = resetsWords({ byWindow: true, fiveHour: 2, weekly: 1, count: 3 });
return [w.querySelector(".resets-n").textContent, w.title];
});
assert.equal(words[0], lang === "zh" ? "↺ 2 张 5 小时重置卡 · 1 张每周重置卡" : "↺ 2 five-hour resets · 1 weekly reset");
assert.ok(words[1].length > 0);
const one = await page.evaluate(() => resetsWords({ byWindow: true, fiveHour: 1, count: 1 }).querySelector(".resets-n").textContent);
assert.equal(one, lang === "zh" ? "↺ 1 张 5 小时重置卡" : "↺ 1 five-hour reset");
assert.deepEqual(errors, []);
});
}