Files
magpie/internal/gui/tests/agent-details-ready.test.cjs
T
yetoneandvincent 549813abb5 gui tests: every short default gives navigation a minute, and CI runs the browser-free guards (#5425)
nav-timeout.test.cjs was red on main since #5425 was filed (11-06),
first for four files and now for 24: each new GUI test copied
page.setDefaultTimeout(5000) without a navigation timeout, and nothing
caught it because CI runs no GUI file. Each short default now sits
beside page.setDefaultNavigationTimeout(60000); clicks and waits keep
their 5s/6s/8s/30s bar. skygunner's 10275d5a6 did the same for the nine
files listed on 11-08, and was never taken; this covers those and the 15
added since.

The class: nav-timeout, i18n-keys and i18n-en-no-cjk read the sources
and need no browser, and LESSONS.md records each of them red on main
after a push that ran chosen GUI files. test.yml's Linux cli job, which
already sets up Node 22, now runs them, so the push that adds the next
offender goes red on CI.

Run (mica; mote was at load 26):
- node --test nav-timeout, i18n-keys, i18n-en-no-cjk at this tree on
  origin/main b2b3d488c: 9/9 ok.
- usage-drag, form-align, accounts-switch-alone (changed files, both
  engines, every language): 34/34 ok.
- Broken by hand: origin/main's usage-drag copied in beside the fix,
  nav-timeout red, naming it.
Not run: the other 21 changed files in a browser (one added line each)
and the whole GUI suite; both machines were running other sessions'
GUI runs.

Co-authored-by: vincent <webmaster@palmit.com.au>
2026-11-18 02:24:05 +08:00

212 lines
12 KiB
JavaScript

// First Details must measure the settings it will show, including the lazy
// Long conversations row. Hold each read rather than racing a wall-clock
// delay; sample the sheet's last animation frame and its natural height.
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 { agentRow } = require("./reader.cjs");
const assets = process.env.MAGPIE_ASSETS || path.resolve(__dirname, "../assets");
const languages = ["en", "zh", "zh-TW", "ja", "de"];
const row = (id) => `.row.agent[data-id="${id}"]`;
const link = (page, id) => page.locator(row(id) + " .ag-link");
function held() {
let release;
const promise = new Promise((r) => { release = r; });
return { promise, release };
}
async function openPage(t, engine, lang = "en", width = 1180, reducedMotion = "no-preference") {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 1000 }, reducedMotion });
page.setDefaultTimeout(8000);
page.setDefaultNavigationTimeout(60000);
const errors = [], settingsAsked = held(), settings = held(), compactAsked = held(), compact = held();
t.after(async () => { settings.release(); compact.release(); await browser.close(); });
let reads = 0, fail = false;
page.on("pageerror", (e) => errors.push(e.message));
await page.addInitScript(() => {
const animate = Element.prototype.animate;
window.detailSlides = [];
Element.prototype.animate = function (...args) {
const run = animate.apply(this, args);
if (this.classList.contains("ag-exp")) {
run.pause();
window.detailSlides.push(run);
}
return run;
};
});
await page.route("**/*", async (route) => {
const url = new URL(route.request().url()), json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs={lang:${JSON.stringify(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: [agentRow("codex", "Codex"), agentRow("claude", "Claude Code"), agentRow("grok", "Grok Build"), agentRow("goose", "Goose")], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/settings") {
reads++;
settingsAsked.release();
await settings.promise;
if (fail) return route.fulfill({ status: 500, body: "settings unavailable" });
return json({ lang, theme: "light", tray: "panel", compactAt: 200000, codexAgentsV1: true, visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], titleModels: [], redactWords: [] });
}
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname.startsWith("/api/")) return json({});
if (url.pathname === "/agentcompact.js") { compactAsked.release(); await compact.promise; }
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: "" }); }
});
await page.goto("http://magpie.test/?view=agents");
await link(page, "codex").waitFor();
return { page, errors, settingsAsked, settings, compactAsked, compact, reads: () => reads, fail: (v) => { fail = v; } };
}
async function slideEndsWhole(page, id) {
await page.waitForFunction(() => detailSlides.length > 0);
const heights = await page.evaluate(async (selector) => {
const run = detailSlides.at(-1), box = document.querySelector(selector);
await run.ready;
run.currentTime = run.effect.getTiming().duration - 1;
const before = box.getBoundingClientRect().height;
run.finish();
await run.finished;
await new Promise(requestAnimationFrame);
return [before, box.getBoundingClientRect().height];
}, row(id));
assert(Math.abs(heights[1] - heights[0]) < 1, `Details must end without a height jump: ${heights.join(" -> ")}`);
return heights[1];
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of languages) for (const width of [1180, 560]) {
test(`${engine} ${lang} ${width}: first Details waits for settings and ends at its full height`, async (t) => {
const f = await openPage(t, engine, lang, width), { page } = f;
const shut = await page.locator(row("codex")).boundingBox();
await link(page, "codex").click();
await f.settingsAsked.promise;
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0, "no partial Details while settings are unread");
assert.equal(await link(page, "codex").getAttribute("aria-busy"), "true", "the read has immediate feedback");
f.settings.release();
await f.compactAsked.promise;
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0, "no partial Details while its last settings row loads");
f.compact.release();
await page.locator(row("codex") + " .ag-prefs .agent-compact").waitFor();
const full = await slideEndsWhole(page, "codex");
assert(full > shut.height + 100, "the whole settings list is present");
assert.equal(await page.locator("#view-agents").evaluate((v) => v.scrollTop), 0, "opening never scrolls the page");
assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "no horizontal overflow");
await link(page, "codex").click();
await page.evaluate(async () => { const run = detailSlides.at(-1); run.finish(); await run.finished; });
await page.locator(row("codex") + " .ag-exp").waitFor({ state: "detached" });
await link(page, "codex").click();
assert.equal(await slideEndsWhole(page, "codex"), full, "warm Details opens to the same full height");
assert.equal(f.reads(), 1, "warm opening reuses the settings");
assert.deepEqual(f.errors, []);
if (process.env.ARTIFACT_DIR && lang === "zh" && width === 1180) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.locator(row("codex") + " .ag-exp").evaluate((b) => b.getAnimations({ subtree: true }).forEach((a) => a.finish()));
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `details-${engine}.png`) });
}
});
}
for (const id of ["claude", "grok"]) test(`${engine}: ${id} first Details prepares its settings too`, async (t) => {
const f = await openPage(t, engine), { page } = f;
await link(page, id).click();
await f.settingsAsked.promise;
assert.equal(await page.locator(row(id) + " .ag-exp").count(), 0);
f.settings.release(); f.compact.release();
await page.locator(row(id) + " .agent-compact").waitFor();
await slideEndsWhole(page, id);
assert.deepEqual(f.errors, []);
});
test(`${engine}: the first animation ends at the natural height after both reads answer`, async (t) => {
const f = await openPage(t, engine), { page } = f;
await link(page, "codex").click();
await f.settingsAsked.promise;
f.settings.release(); f.compact.release();
await page.locator(row("codex") + " .ag-prefs .agent-compact").waitFor();
await slideEndsWhole(page, "codex");
assert.deepEqual(f.errors, []);
});
test(`${engine}: settings already read still waits for the first controls import`, async (t) => {
const f = await openPage(t, engine), { page } = f;
f.settings.release();
await page.locator("#prefs").click();
await page.locator("#view-settings").waitFor();
await page.waitForFunction(() => document.querySelector("#fullContextSegs .opt"));
await page.locator('#nav button[data-view="agents"]').click();
await link(page, "codex").click();
await f.compactAsked.promise;
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0, "a cold controls module still delays measurement");
f.compact.release();
await page.locator(row("codex") + " .agent-compact").waitFor();
await slideEndsWhole(page, "codex");
assert.equal(f.reads(), 1);
assert.deepEqual(f.errors, []);
});
test(`${engine}: a failed settings read leaves Details closed and retryable`, async (t) => {
const f = await openPage(t, engine), { page } = f;
f.fail(true); f.compact.release();
await link(page, "codex").click();
await f.settingsAsked.promise;
f.settings.release();
await page.waitForFunction(() => !document.querySelector('.row.agent[data-id="codex"] .ag-link').disabled);
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0, "failure never shows guessed defaults");
assert.match(await page.locator("#status").textContent(), /settings unavailable/);
f.fail(false);
await link(page, "codex").click();
await page.locator(row("codex") + " .agent-compact").waitFor();
await slideEndsWhole(page, "codex");
assert.equal(f.reads(), 2);
assert.deepEqual(f.errors, []);
});
test(`${engine}: a late settings read cannot replace the agent clicked next`, async (t) => {
const f = await openPage(t, engine), { page } = f;
await link(page, "codex").click();
await f.settingsAsked.promise;
await link(page, "goose").click();
await slideEndsWhole(page, "goose");
const answered = page.waitForResponse((r) => new URL(r.url()).pathname === "/api/settings");
f.settings.release(); f.compact.release();
await answered;
await page.waitForFunction(() => !document.querySelector('.row.agent[data-id="codex"] .ag-link').hasAttribute("aria-busy"));
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0);
assert.equal(await link(page, "goose").getAttribute("aria-expanded"), "true");
assert.deepEqual(f.errors, []);
});
test(`${engine}: reduced motion waits for real settings, then opens at once`, async (t) => {
const f = await openPage(t, engine, "en", 1180, "reduce"), { page } = f;
await link(page, "codex").click();
await f.settingsAsked.promise;
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0);
f.settings.release(); f.compact.release();
await page.locator(row("codex") + " .agent-compact").waitFor();
assert.equal(await page.evaluate(() => detailSlides.length), 0, "no sheet animation with reduced motion");
assert.deepEqual(f.errors, []);
});
test(`${engine}: leaving Agents while settings load does not open a hidden row`, async (t) => {
const f = await openPage(t, engine), { page } = f;
await link(page, "codex").click();
await f.settingsAsked.promise;
await page.locator('#nav button[data-view="providers"]').click();
await page.locator("#view-providers").waitFor();
f.settings.release(); f.compact.release();
await page.waitForFunction(() => !document.querySelector('.row.agent[data-id="codex"] .ag-link').hasAttribute("aria-busy"));
assert.equal(await page.locator(row("codex") + " .ag-exp").count(), 0);
assert.deepEqual(f.errors, []);
});
}