Files
magpie/internal/gui/tests/update-row-steady.test.cjs
T
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
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).
2026-10-31 02:09:18 +08:00

176 lines
9.6 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.
// Settings › About and the title bar hold still while the update's state
// comes in (#4057):
// - opened cold, with no state read yet, the Version row keeps the line
// under its name for the answer, rather than growing 12px when it lands;
// - opened with a state read a minute ago ("Up to date") while a check has
// since downloaded a newer version, that old state isn't drawn first and
// swapped for "0.1.401 is downloaded";
// - the header's Update pill showing opens from nothing, so the Settings
// search in the title bar beside the sidebar slides over with it rather
// than jumping 80px left in one frame.
// 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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const words = {
en: { version: "Version", latest: "Up to date", ready: "0.1.401 is downloaded" },
zh: { version: "版本", latest: "已是最新", ready: "0.1.401 已下载" },
};
function server(lang, ctl) {
const settings = {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", proxy: "", redact: false, redactWords: [],
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none",
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
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:false};` });
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: "light" }, fx: settings.fx });
if (url.pathname === "/api/settings") return json(settings);
if (url.pathname === "/api/update") {
if (ctl.hold) await ctl.hold;
return json(ctl.update || { state: "latest", current: "0.1.400" });
}
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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 ready = { state: "ready", current: "0.1.400", latest: "0.1.401" };
// every frame, the Version row's height and the line under its name
const watchRow = (version) => {
window.__rows = [];
const look = () => {
const r = [...document.querySelectorAll("#about .row.pref")].find((r) => r.querySelector(".name")?.textContent === version);
if (r && r.offsetParent && !r.dataset.left) window.__rows.push({ h: r.getBoundingClientRect().height, sub: r.querySelector(".who .sub")?.textContent ?? null });
if (!window.__stop) requestAnimationFrame(look);
};
look();
};
async function open(browser, lang, ctl, width, url) {
const errors = [];
const page = await (await browser.newContext({ viewport: { width, height: 700 } })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, ctl));
await watchSettingsReads(page);
await page.addInitScript(`(${watchRow})(${JSON.stringify(words[lang].version)})`);
await page.goto(url);
return { page, errors };
}
const versionRow = (page, lang) => page.locator("#about .row.pref", { has: page.locator(".name", { hasText: words[lang].version }) }).first();
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Version row and the title bar hold still while the update's state comes in (#4057)", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(words)) {
const w = words[lang];
await t.test(lang + ": opened cold, the row keeps its line for the answer", async () => {
let release;
const ctl = { hold: new Promise((go) => (release = go)) };
const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
await page.waitForFunction(() => window.__rows.length > 20);
release();
const row = versionRow(page, lang);
await row.locator(".sub", { hasText: w.latest }).waitFor();
await page.evaluate(() => (window.__stop = true));
const tall = (await row.boundingBox()).height;
const rows = await page.evaluate(() => window.__rows.slice());
const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px with its answer; ${off.length} of ${rows.length} frames drew it otherwise`);
assert.deepEqual(errors, []);
await page.context().close();
});
await t.test(lang + ": a state read a minute ago isn't drawn before the answer", async () => {
const ctl = {};
const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
const row = versionRow(page, lang);
await row.locator(".sub", { hasText: w.latest }).waitFor();
const tall = (await row.boundingBox()).height;
await page.evaluate(() => show("agents"));
// a minute on, a check has downloaded 0.1.401; its read is held
let release;
ctl.hold = new Promise((go) => (release = go));
ctl.update = ready;
// the row left on screen is drawn again when Settings is: only the
// new row's frames count
await page.evaluate((version) => {
for (const r of document.querySelectorAll("#about .row.pref")) r.dataset.left = "1";
const now = Date.now;
Date.now = () => now() + 60e3;
window.__rows = [];
show("settings");
}, w.version);
await page.waitForFunction(() => window.__rows.length > 20);
release();
await row.locator(".sub", { hasText: w.ready }).waitFor();
await page.evaluate(() => (window.__stop = true));
const rows = await page.evaluate(() => window.__rows.slice());
const stale = rows.filter((s) => s.sub === w.latest);
assert.equal(stale.length, 0, `"${w.latest}", a minute old, was drawn in ${stale.length} of ${rows.length} frames before "${w.ready}"`);
const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px; ${off.length} of ${rows.length} frames drew it otherwise`);
assert.deepEqual(errors, []);
await page.context().close();
});
await t.test(lang + ": the Update pill opens from nothing, the search beside the sidebar sliding with it", async () => {
const ctl = {};
const { page, errors } = await open(browser, lang, ctl, 1200, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
await versionRow(page, lang).locator(".sub", { hasText: w.latest }).waitFor();
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at 1200px");
const frames = () => page.evaluate(() => new Promise((go) => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(go)))));
await frames();
const at = () => page.evaluate(() => $("#setQ").getBoundingClientRect().left);
const before = await at();
// the pill's opening is held at its first frame, as it is shown
ctl.update = ready;
await page.evaluate(() => {
const b = $("#update");
new MutationObserver(() => {
if (b.hidden) return;
window.__opening = b.getAnimations();
for (const a of window.__opening) { a.pause(); a.currentTime = 0; }
}).observe(b, { attributes: true, attributeFilter: ["hidden"] });
renderUpdateBadge();
});
await page.waitForFunction(() => !$("#update").hidden && window.__opening);
await frames();
const first = await at();
assert.ok(Math.abs(first - before) <= 1, `the search moved ${before - first}px in the pill's first frame`);
await page.evaluate(() => { for (const a of window.__opening) a.finish(); });
await frames();
const after = await at();
assert.ok(before - after > 30, `the pill took its room once open: the search at ${before}, then ${after}`);
assert.deepEqual(errors, []);
await page.context().close();
});
}
});
}