Files
magpie/internal/gui/tests/side-gateway-lan.test.cjs
T
yetone 97b6a36c5b gui: the sidebar's gateway names the LAN address while it is shared
coeo91 on Discord: with "Share on local network" on, the sidebar's line
still said "Gateway 127.0.0.1:3425". Shared, it now names where other
machines reach it: MAGPIE_PUBLIC_URL if set, else the address picked in
Settings (magpie.lanAddress), else the first LAN address. Its tooltip
names that and this computer's url. Not shared, it is unchanged.

- api.go: boot.js's sideGateway carries lan and lanURLs when shared, so
  the first paint is right.
- plugins/gateway/settings.js: sideLAN() picks the address and redraws
  the boot line once loaded (it loads after app.js); turning sharing
  on/off re-reads /api/providers and redraws, and picking an address
  redraws. The choice lives in the plugin so app.js and the core script
  budget stay under their limits (TestCoreScriptBudget passes); no budget
  raised, no new strings.
- app.js renderSideGw: uses self.sideLAN?.(g), tooltip adds " · " + url.

Run at this commit's tree, rebased on d4f1d6480 (after 581d64b7d's
lanPublic and the Gateway card; conflicts in settings.js and
public-url-default kept both sides), on mote (macOS 27, Playwright 1.62,
Chromium + WebKit, 5 languages):
- side-gateway-lan, public-url-default, public-url, sidebar,
  gateway-port, connect-address-kept, lan-public, lan-docker,
  gateway-card, browser-access, plugin-gateway, gateway-connect-keys,
  gateway-keys-empty, gateway-caller-keys, i18n-keys: 195 pass, 1 fail
  (i18n-keys "a plugin's words are its own", #4053, red on main).
- go test -timeout 45m ./internal/gui/...: only TestMainWindowCorners
  (#3949); budgets pass. gofmt -l clean; go vet ./internal/gui darwin,
  GOOS=windows, GOOS=linux -tags nogui ok.

Before the rebase (base 51e3169fb):
- side-gateway-lan (new), public-url-default, sidebar, gateway-port,
  connect-address-kept: 82 pass, 0 fail.
- gateway-caller-keys, i18n-keys, plugin-gateway, gateway-connect-keys,
  gateway-keys-empty: 47 pass, 1 fail (i18n-keys "a plugin's words are
  its own", red on origin/main 6104e88aa, #4053). gateway-caller-keys
  chromium en failed once at :137 in an earlier run and passed on the
  next; base 6104e88aa is red at the same line in webkit (#3797).
- go test -timeout 45m ./internal/gui/...: only TestMainWindowCorners
  fails, red on base too (#3949). TestCoreScriptBudget and
  TestBootSaysWhereItsGatewayListens pass.
- gofmt -l clean; go vet darwin, GOOS=windows ./..., GOOS=linux -tags
  nogui ./... ok (Go unchanged since).
- Full GUI suite: stopped at ~8,400 results under load 25-105 from other
  sessions (20 not ok). Each red file was rerun on base 6104e88aa; red
  there: gateway-key-models (#2648), header-centre (#3479), i18n-keys
  (#4053), key-replace webkit (#3476), menu-input-scroll (#3402),
  mobile-web (#3952), models-fold webkit (#4071, filed), quota-count-wrap
  webkit (#3404). credit-days, library-row-remove and plugin-github
  passed on rerun.

Broken by hand: origin/main's app.js -> side-gateway-lan red 10/10 at the
first-paint check (:35); without settings.js's /api/providers refresh ->
red 10/10 at the sharing-off check (:57); without the load-time redraw ->
red 10/10 at :35.

Not tried: the real app on a real LAN, the Linux and Windows GUIs, and
the rest of the full GUI suite past where it was stopped.
2026-10-28 22:26:02 +08:00

86 lines
4.8 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: with Share on local network on, the sidebar's gateway
// line at its foot still said "Gateway 127.0.0.1:3425", which other
// computers can't reach. Shared, it names the LAN address, the one picked
// under Share on local network, from the first paint; its tooltip names
// both that and this computer's. Sharing turned off or on in Settings, or
// another address picked there, redraws it at once. Not shared, it is
// this computer's, as before.
const LOCAL = "http://127.0.0.1:3999";
const lanURLs = ["http://192.168.1.10:3999", "http://10.0.0.10:3999"];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: the sidebar's gateway names the address shared on the local network`, 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: 1100, height: 800 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
// boot.js says the gateway (bootGateway); the providers' read comes
// 1.5s after, so what is read at once is boot.js's line
await page.route("**/*", fixture(lang, "light", [], { lan: true, lanURLs, bootGateway: true }));
const line = () => page.locator("#sideGw span").textContent();
const tip = () => page.locator("#sideGw").getAttribute("title");
const says = (host) => page.waitForFunction((h) => document.querySelector("#sideGw span")?.textContent.includes(h), host);
await page.goto("http://magpie.test/?view=settings");
await page.locator("#sideGw").waitFor();
assert.match(await line(), /192\.168\.1\.10:3999/);
assert.doesNotMatch(await line(), /127\.0\.0\.1/);
assert.match(await tip(), /192\.168\.1\.10:3999/);
assert.match(await tip(), /127\.0\.0\.1:3999/);
// another address picked under Share on local network: the line
// follows at once, and after a reload
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
await reach(page, page.locator("#lanList .lan-interface"));
await page.locator("#lanList .lan-interface").click();
await page.locator(".proto-menu .pm-item", { hasText: "10.0.0.10" }).click();
await says("10.0.0.10:3999");
await page.reload();
await page.locator("#sideGw").waitFor();
assert.match(await line(), /10\.0\.0\.10:3999/);
// sharing off: this computer's address, and nothing else in the tooltip
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
await page.locator("#lanList .segs").first().locator(".opt").nth(0).click();
await page.locator("#lanList .lan-address-row").waitFor({ state: "detached" });
await says("127.0.0.1:3999");
assert.doesNotMatch(await tip(), /192\.168|10\.0\.0/);
assert.match(await tip(), new RegExp(LOCAL.replace(/\./g, "\\.") + "$"));
// and on again: the address picked comes back
await page.locator("#lanList .segs").first().locator(".opt").nth(1).click();
await page.locator("#lanList .lan-address-row").waitFor();
await says("10.0.0.10:3999");
assert.deepEqual(errors, []);
});
}
test(`${engine}: not shared, the sidebar's gateway is this computer's`, 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: 1100, height: 800 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", fixture("en", "light", [], { lanURLs, bootGateway: true }));
// past the providers' read, which says the same
const read = page.waitForResponse((r) => r.url().endsWith("/api/providers"));
await page.goto("http://magpie.test/?view=settings");
await page.locator("#sideGw").waitFor();
await read;
await page.evaluate(() => new Promise(requestAnimationFrame));
assert.equal(await page.locator("#sideGw span").textContent(), "Gateway 127.0.0.1:3999");
assert.equal(await page.locator("#sideGw").getAttribute("title"), "Gateway " + LOCAL);
assert.deepEqual(errors, []);
});
}