Files
magpie/internal/gui/tests/connect-address-kept.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

85 lines
4.7 KiB
JavaScript

const assert = require("node:assert/strict");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { fixture } = require("./fixtures/caller-keys.cjs");
const { openPart, reach } = require("./reader.cjs");
// coeo91 on Discord: the LAN address picked as Gateway's Base URL went back
// to 127.0.0.1 after a restart or an update. The address and the gateway key
// picked in Connect, and the address picked under Share on local network,
// are kept across reloads; an address the machine doesn't have right now
// (the network not up yet after a start) shows this computer's, and the
// pick comes back with it.
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}: the address and key picked in Connect are kept`, 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: 800 }, reducedMotion: "reduce" })).newPage();
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
page.setDefaultTimeout(6000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const lanURLs = ["http://192.168.1.10:3999", "http://10.0.0.10:3999"];
await page.route("**/*", fixture(lang, "light", [], { lan: true, lanURLs }));
const pick = async (button, text) => {
await page.locator(button).click();
await page.locator(".proto-menu .pm-item", { hasText: text }).click();
await page.locator(".proto-menu").waitFor({ state: "detached" });
};
const shown = (sel) => page.locator(sel).textContent();
const open = async () => {
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#connect .val code").first().waitFor();
};
await open();
await pick("#connectAddress", "10.0.0.10");
await page.waitForFunction(() => document.querySelector("#connectAddress")?.textContent.includes("10.0.0.10"));
await page.locator("#connectKey").waitFor();
await pick("#connectKey", "Server");
await page.waitForFunction(() => document.querySelector("#connectKey")?.textContent.includes("Server"));
// a restart or an update opens the page again
await open();
await page.waitForFunction(() => document.querySelector("#connectKey")?.textContent.includes("Server"));
assert.match(await shown("#connectAddress"), /10\.0\.0\.10:3999\/v1/);
assert.match(await shown("#connectKey"), /Server/);
await page.waitForFunction(() => document.querySelector("#connect pre.snip")?.textContent.includes("fixture-server"));
// the network isn't up yet: this computer's address is shown, and
// nothing of the pick is lost
lanURLs.length = 0;
await open();
assert.match(await page.locator("#connect").textContent(), /127\.0\.0\.1:3999\/v1/);
assert.equal(await page.locator("#connectAddress").count(), 0);
lanURLs.push("http://192.168.1.10:3999", "http://10.0.0.10:3999");
await open();
assert.match(await shown("#connectAddress"), /10\.0\.0\.10:3999\/v1/);
await page.waitForFunction(() => document.querySelector("#connectKey")?.textContent.includes("Server"));
// Share on local network's address is kept the same way
await page.locator("#prefs").click();
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
// wheeled to as a reader would: the rows above, their lines wrapped
// whole (arculongus on Discord), put it below a narrow window, and
// Playwright's own scroll to it is undone, its menu opened out of sight
await reach(page, page.locator("#lanList .lan-interface"));
await pick("#lanList .lan-interface", "10.0.0.10");
await page.reload();
await page.locator("#prefs").click();
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
assert.match(await shown("#lanList .lan-interface"), /10\.0\.0\.10:3999/);
// nothing on the page is wider than the window
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
assert.deepEqual(errors, []);
});
}
}
}