Files
magpie/internal/gui/tests/editor-short-window.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

112 lines
7.0 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// A provider's editor in a short window (悠悠哥 on Discord: a small window's
// WorkBuddy editor showed part of its models, and the wheel took it no
// further until the window was maximized). The dialog fits the window, its
// head and Save stay in sight, and the wheel held over the model chips runs
// them to their last one and then takes the editor's body on to its end,
// where it used to stop part way down. The page itself never moves. In
// Chromium and WebKit, English and Chinese, at three window sizes.
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 IDS = Array.from({ length: 40 }, (_, i) => `workbuddy-model-${String(i + 1).padStart(2, "0")}`);
const wb = {
id: "workbuddy", name: "WorkBuddy", icon: "generic", chat: "https://copilot.example.com/v1", responses: "", anthropic: "", catalog: "",
models: IDS.map((id) => ({ id, name: id, on: true })), agents: [], fallback: [], headers: {},
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
};
function serve(lang) {
const providers = { providers: [wb], 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 === "/api/plugins") return json({ plugins: [] });
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 words = { en: { save: "Save" }, zh: { save: "保存" } };
const inside = (a, b, what) => {
assert.ok(a.top >= b.top - 1 && a.bottom <= b.bottom + 1 && a.left >= b.left - 1 && a.right <= b.right + 1,
`${what}: ${JSON.stringify(a)} within ${JSON.stringify(b)}`);
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
for (const [width, height] of [[800, 500], [600, 420], [420, 340]]) {
test(`${engine} ${lang} ${width}x${height}: the wheel takes a provider's editor past its models to the end`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { has: page.locator(".name", { hasText: /^WorkBuddy$/ }) }).click();
const ed = page.locator("#modal .editor");
await ed.waitFor();
await page.waitForTimeout(200);
const rects = () => page.evaluate(() => {
const r = (e) => { const b = e.getBoundingClientRect(); return { top: b.top, bottom: b.bottom, left: b.left, right: b.right }; };
const d = document.querySelector("#modal .dialog"), body = d.querySelector(".ebody"), chips = body.querySelector(".mchips");
return {
view: { top: 0, bottom: innerHeight, left: 0, right: innerWidth }, dialog: r(d), body: r(body), chips: r(chips),
last: r(chips.lastElementChild), head: r(d.querySelector(".ehead")), bar: r(d.querySelector(".editor > .bar")),
bodyAt: body.scrollTop, bodyEnd: body.scrollHeight - body.clientHeight,
chipsAt: chips.scrollTop, chipsEnd: chips.scrollHeight - chips.clientHeight,
lastId: chips.lastElementChild.textContent, page: document.scrollingElement.scrollTop,
};
});
let at = await rects();
inside(at.dialog, at.view, "the dialog fits the window");
inside(at.head, at.view, "the editor's head is in sight");
inside(at.bar, at.view, "its buttons are in sight");
assert.ok(at.bodyEnd > 0, "the fields are more than the body shows");
assert.ok(at.chipsEnd > 0, "the models are more than their list shows");
// bring the models into the body's view, then wheel over them alone
await page.evaluate(() => document.querySelector("#modal .ebody .mchips").scrollIntoView({ block: "start" }));
at = await rects();
await page.mouse.move((at.chips.left + at.chips.right) / 2, Math.max(at.chips.top, at.body.top) + 20);
for (let i = 0; i < 30; i++) {
await page.mouse.wheel(0, 120);
await page.waitForTimeout(30);
const now = await rects();
if (now.chipsAt >= now.chipsEnd - 1 && now.bodyAt >= now.bodyEnd - 1) break;
}
await page.waitForTimeout(150);
at = await rects();
assert.ok(at.chipsAt >= at.chipsEnd - 1, `the models run to their end (${at.chipsAt} of ${at.chipsEnd})`);
assert.equal(at.lastId.trim().startsWith(IDS[IDS.length - 1]), true, "the last chip is the last model");
assert.ok(at.last.bottom <= at.chips.bottom + 1 && at.last.top >= at.chips.top - 1, "the last model shows in its list");
assert.ok(at.bodyAt >= at.bodyEnd - 1, `the wheel takes the body on to its end (${at.bodyAt} of ${at.bodyEnd})`);
assert.equal(at.page, 0, "the page itself stays put");
inside(at.head, at.view, "the head is still in sight");
inside(at.bar, at.view, "Save is still in sight");
const save = ed.locator(".bar").getByRole("button", { name: words[lang].save, exact: true });
const box = await save.boundingBox();
assert.ok(box, "Save is there");
const hit = await page.evaluate(([x, y]) => document.elementFromPoint(x, y)?.closest("button")?.textContent, [box.x + box.width / 2, box.y + box.height / 2]);
assert.equal(hit, words[lang].save, "nothing covers Save");
assert.deepEqual(errors, []);
});
}
}
}