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).
95 lines
5.7 KiB
JavaScript
95 lines
5.7 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A machine whose `magpie` command is a copied file (an older installer, a
|
|
// hand cp) keeps running that build after a GUI update moves the app on —
|
|
// the stale command that wedged a WebDAV sync before #531's check. The
|
|
// window can't tell a stale copy from a current one without running the old
|
|
// binary (whose start-up migrates settings), so /api/state reports the copy
|
|
// and the window shows advice with a "Hide until the next version" that
|
|
// POSTs /api/cli-behind/quiet. The panel is too small for a dialog, so it
|
|
// stays out of it. English and Chinese; 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 HEAD = {
|
|
en: "The `magpie` command is a copy",
|
|
zh: "终端里的 `magpie` 命令是一份拷贝",
|
|
};
|
|
|
|
function server(lang, behind, quiet) {
|
|
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") {
|
|
const s = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
if (behind) s.cliBehind = "~/.local/bin/magpie";
|
|
return json(s);
|
|
}
|
|
if (url.pathname === "/api/cli-behind/quiet") { quiet.calls++; return route.fulfill({ status: 204 }); }
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/update" || url.pathname === "/api/drift") return json({});
|
|
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: "" }); }
|
|
};
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
test(`${engine} ${lang}: a copied command gets advice, once, dismissable`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(async () => { await browser.close(); });
|
|
const quiet = { calls: 0 };
|
|
const page = await (await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang, true, quiet));
|
|
await page.goto("http://magpie.test/");
|
|
const dialog = page.locator("#modal:not([hidden])");
|
|
await dialog.waitFor();
|
|
await assert.match(await dialog.textContent(), new RegExp(HEAD[lang].replace(/[.*+?^${}()|[\]\\]/g, "\\$&")), "the dialog names the copy");
|
|
assert.match(await dialog.textContent(), /~\/\.local\/bin\/magpie/, "the dialog names the path");
|
|
// Hide until the next version posts the dismiss and closes
|
|
await dialog.getByRole("button", { name: lang === "zh" ? "隐藏,直到下一个版本" : "Hide until the next version" }).click();
|
|
await page.waitForFunction(() => document.querySelector("#modal").hidden);
|
|
assert.equal(quiet.calls, 1, "the dismiss reached the API");
|
|
// the panel, too small for a dialog, says nothing
|
|
const panel = await (await browser.newContext({ viewport: { width: 380, height: 600 }, reducedMotion: "reduce" })).newPage();
|
|
panel.setDefaultTimeout(5000);
|
|
panel.setDefaultNavigationTimeout(60000);
|
|
panel.on("pageerror", (e) => errors.push(e.message));
|
|
await panel.route("**/*", server(lang, true, quiet));
|
|
await panel.goto("http://magpie.test/?mode=panel");
|
|
await panel.locator("#view-agents, #nav, body").first().waitFor();
|
|
await panel.waitForTimeout(500);
|
|
assert.ok(await panel.locator("#modal").evaluate((m) => m.hidden), "the panel stays quiet");
|
|
// and no advice when the command is the link (no cliBehind)
|
|
const ok = await (await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" })).newPage();
|
|
ok.setDefaultTimeout(5000);
|
|
ok.setDefaultNavigationTimeout(60000);
|
|
ok.on("pageerror", (e) => errors.push(e.message));
|
|
await ok.route("**/*", server(lang, false, quiet));
|
|
await ok.goto("http://magpie.test/");
|
|
await ok.waitForTimeout(500);
|
|
assert.ok(await ok.locator("#modal").evaluate((m) => m.hidden), "a following command is not mentioned");
|
|
const keys = [
|
|
"The `magpie` command is a copy",
|
|
"The `magpie` command at {path} is a copied file, not the installer's link to the app: it won't follow the app's updates, and an old copy can break what a new one fixed. Re-run the installer, or link it by hand.",
|
|
];
|
|
const missing = await ok.evaluate((ks) => ks.filter((x) => !I18N.zh[x]), keys);
|
|
assert.deepEqual(missing, [], "the advice has its Chinese");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|