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).
168 lines
10 KiB
JavaScript
168 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The status pill says a long outcome whole (littleHong on Discord): Test
|
|
// models in OfficeAce's editor failed on every model, and the red pill was
|
|
// one line ending in "…", so the part saying what to do was lost. A line
|
|
// longer than its place floats over the window wrapped, up to ten lines,
|
|
// the rest scrolled to; it stays while the pointer is on it and as long as
|
|
// it takes to read; its text can be selected; a short one stays in the
|
|
// footer as it was. In every language, light and dark, wide and narrow.
|
|
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");
|
|
// the reporter's error, as the OfficeAce plugin words it
|
|
const said = "OfficeAce 账号已登录,但还没有接入华为云 MaaS(凭据里没有 modelAppKey)。请在 OfficeAce 客户端完成「接入华为云 MaaS 模型」后重试;额度与签到不受影响,已经可以正常使用。";
|
|
const models = ["glm-5.3", "glm-5.3-flash", "deepseek-v4", "deepseek-v4-flash", "kimi-k3", "qwen4-coder", "qwen4-max", "minimax-m3", "glm-5.2", "deepseek-r3"];
|
|
const provider = {
|
|
id: "officeace", name: "OfficeAce", icon: "generic", chat: "https://officeace.example/v2", responses: "", anthropic: "", catalog: "",
|
|
agents: [], fallback: [], headers: {}, keyList: [], proxy: "", key: { set: true, masked: "sk-…one" },
|
|
models: models.map((id) => ({ id, name: "", on: true })),
|
|
};
|
|
|
|
function serve(lang, theme) {
|
|
const list = { providers: [provider], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
const state = { agents: [], profiles: [], settings: { lang, theme } };
|
|
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:"${theme}",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(list);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/provider/test") {
|
|
const body = route.request().postDataJSON();
|
|
return json({ results: (body.test || []).map((model) => ({ ok: false, model, status: 400, error: said })) });
|
|
}
|
|
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 });
|
|
};
|
|
}
|
|
|
|
// how the pill is drawn: whether it is cut, and where it is
|
|
const look = (page) => page.locator("#status").evaluate((e) => {
|
|
const cs = getComputedStyle(e), r = e.getBoundingClientRect();
|
|
return {
|
|
text: e.textContent, lift: e.classList.contains("lift"),
|
|
cutAcross: e.scrollWidth > e.clientWidth + 1, cutDown: e.scrollHeight > e.clientHeight + 1,
|
|
height: r.height, left: r.left, right: r.right, top: r.top, bottom: r.bottom, vw: innerWidth, vh: innerHeight,
|
|
overflowY: cs.overflowY, select: cs.userSelect || cs.webkitUserSelect, borderLeft: parseFloat(cs.borderLeftWidth) || 0,
|
|
lineHeight: parseFloat(cs.lineHeight),
|
|
};
|
|
});
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
const launch = () => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" });
|
|
const open = async (t, lang, theme, width, name) => {
|
|
const browser = await launch();
|
|
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${theme}-${width}-${name}-status-long.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, theme));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
return { page, errors };
|
|
};
|
|
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
for (const [theme, width] of [["light", 900], ["dark", 390]]) {
|
|
test(`${engine} ${lang} ${theme} ${width}: Test models' failure is said whole over the editor`, async (t) => {
|
|
const { page, errors } = await open(t, lang, theme, width, "editor");
|
|
await page.locator(".row.provider", { hasText: "OfficeAce" }).first().click();
|
|
await page.locator(".editor .mchips .mchip").first().waitFor();
|
|
const name = await page.evaluate(() => t("Test models"));
|
|
await page.locator(".editor .mfoot").getByRole("button", { name, exact: true }).click();
|
|
await page.waitForFunction((s) => document.querySelector("#status").textContent.includes(s), said);
|
|
const want = await page.evaluate(([s, m]) => t("{n} of {all} models didn't answer; {model}: {error}", { n: 10, all: 10, model: m, error: "400 · " + s }), [said, models[0]]);
|
|
const got = await look(page);
|
|
assert.equal(got.text, want);
|
|
assert(got.lift, "the pill floats over the dialog");
|
|
assert(!got.cutAcross && !got.cutDown, `the whole message shows, nothing cut: ${JSON.stringify(got)}`);
|
|
assert(got.height > 2 * got.lineHeight, `it wraps to several lines: ${JSON.stringify(got)}`);
|
|
assert(got.left >= 0 && got.right <= got.vw && got.top >= 0 && got.bottom <= got.vh, `it fits the window: ${JSON.stringify(got)}`);
|
|
assert.equal(got.select, "text", "its text can be selected");
|
|
assert.equal(got.borderLeft, 0, "no left-border accent");
|
|
// the words it ends with can be read where they are drawn
|
|
const end = await page.locator("#status").evaluate((e) => {
|
|
const r = document.createRange();
|
|
r.setStart(e.firstChild, e.firstChild.length - 1);
|
|
r.setEnd(e.firstChild, e.firstChild.length);
|
|
const b = r.getBoundingClientRect(), box = e.getBoundingClientRect();
|
|
return b.bottom <= box.bottom + 0.5 && b.right <= box.right + 0.5 && b.width > 0;
|
|
});
|
|
assert(end, "its last character is inside the pill");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
|
|
for (const lang of ["en", "zh"]) {
|
|
test(`${engine} ${lang}: a long line from a page floats wrapped, a short one stays in the footer`, async (t) => {
|
|
const { page, errors } = await open(t, lang, "light", 900, "footer");
|
|
await page.locator(".row.provider", { hasText: "OfficeAce" }).first().waitFor();
|
|
await page.evaluate(() => status(t("Saved"), "ok"));
|
|
let got = await look(page);
|
|
assert(!got.lift && !got.cutAcross, `a short line stays in the footer: ${JSON.stringify(got)}`);
|
|
for (const kind of ["err", "warn", "ok"]) {
|
|
await page.evaluate(([s, k]) => status(s, k), [said, kind]);
|
|
got = await look(page);
|
|
assert(got.lift, `${kind}: a line longer than the footer floats`);
|
|
assert(!got.cutAcross && !got.cutDown, `${kind}: shown whole: ${JSON.stringify(got)}`);
|
|
assert(got.left >= 0 && got.right <= got.vw && got.bottom <= got.vh, `${kind}: fits the window: ${JSON.stringify(got)}`);
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang}: a very long line is held to ten lines and scrolled to its end`, async (t) => {
|
|
const { page, errors } = await open(t, lang, "dark", 390, "scroll");
|
|
await page.locator(".row.provider", { hasText: "OfficeAce" }).first().waitFor();
|
|
await page.evaluate((s) => status(Array(12).fill(s).join(" "), "err"), said);
|
|
const got = await look(page);
|
|
assert(got.lift && !got.cutAcross, `wrapped: ${JSON.stringify(got)}`);
|
|
assert(got.height <= 10 * got.lineHeight + 8, `held to ten lines: ${JSON.stringify(got)}`);
|
|
assert(got.bottom <= got.vh && got.top >= 0, `fits the window: ${JSON.stringify(got)}`);
|
|
assert.equal(got.overflowY, "auto");
|
|
assert(got.cutDown, "the rest is under it, to scroll to");
|
|
const s = page.locator("#status");
|
|
await s.hover();
|
|
await page.mouse.wheel(0, 4000);
|
|
await page.waitForFunction(() => { const e = document.querySelector("#status"); return e.scrollTop + e.clientHeight >= e.scrollHeight - 1; });
|
|
assert.equal(await page.evaluate(() => scrollY), 0, "the page under it didn't scroll");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang}: the pill stays while the pointer is on it, and goes after`, async (t) => {
|
|
const { page, errors } = await open(t, lang, "light", 900, "hover");
|
|
await page.locator(".row.provider", { hasText: "OfficeAce" }).first().waitFor();
|
|
// a short one goes at the time it was given
|
|
await page.evaluate(() => status("Saved", "ok", 200));
|
|
await page.waitForFunction(() => document.querySelector("#status").textContent === "", null, { timeout: 3000 });
|
|
// a long one is given the time its words take
|
|
await page.evaluate((s) => status(s, "err", 200), said);
|
|
await page.waitForTimeout(600);
|
|
assert.equal(await page.locator("#status").textContent(), said, "a long line stays long enough to read");
|
|
await page.locator("#status").hover();
|
|
// past its reading time, held by the pointer
|
|
await page.waitForTimeout(said.length * 80 + 300);
|
|
assert.equal(await page.locator("#status").textContent(), said, "held while the pointer is on it");
|
|
await page.mouse.move(5, 5);
|
|
await page.waitForFunction(() => document.querySelector("#status").textContent === "", null, { timeout: 5000 });
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|