Files
magpie/internal/gui/tests/public-url-default.test.cjs
T
yetone 18e82adc62 gui: the window's pages down a sidebar in groups, the open page's tabs under it, and a button to have the header's tabs instead
From 1024 points wide (SIDE_AT) the window lays its pages down the left
as a Mac app's sidebar: Work (Agents, Sessions, Library), Models
(Providers, Routing, Gateway), Insights (Usage), Extend (Plugins), with
Settings and the gateway's address at the foot. The open page's own tabs
(Usage, Library, Plugins, Settings) are listed under it, opening and
folding on an iOS-like spring, and the page's strip is hidden. The header
becomes a breadcrumb, and pages whose head held only tools have them in
the title bar. Graphite: the open page is in the text's ink, not purple.
A pressed row darkens and never shrinks. The selection under the tabs
sets off as the row is pressed, on a 0.3s curve (it felt behind the
finger), and is the list's only shape: a sub-row hovered or pressed has
no ground of its own, which showed a block under the finger before the
selection slid there. The page's tab is clicked at once, so what is
typed next goes to it.

The title bar's button (or ⌃⌘S, Ctrl+Shift+S), there at every width,
picks the sidebar or the header's tabs. The choice is kept in
localStorage magpie.navLayout (side or top) at every width, so it is laid
out from the first frame; picked in a narrow window the sidebar is 184
points under 860. The two trade places in
a view transition: the sidebar slides, each tab flies to its place, and
the page slides as one. Without view transitions or under reduced
motion, the change is at once.

With nothing picked, narrower than 1024 the page beside a sidebar would
be narrower than Usage's requests table needs, so the header's tabs come
back. A resize
drops what a click held (heldWidth). Usage's KPI strip goes two to a line
by the room the page gives it (a container query), and Japanese counts
wrap there. Tests whose window is 1024+ were updated for the sidebar,
and docs/subsystems/gui-shell.md says how it works.

Run: sidebar.test.cjs and side-toggle.test.cjs 16/16 in chromium and
webkit, in en, zh, zh-TW, ja and de. Each was broken by hand (press
shrink, address cut, press glide, sub-row ground, view transition, kept
choice) and went red. Every page at 560 points with the sidebar picked,
zh and de, both engines: nothing scrolls sideways. session-identity's
ledger row sits under the footer beside the sidebar; WebKit's click
doesn't scroll to it, so the test wheels it up first. Animation frames were checked from a recorded video. The 105
affected GUI files in both engines; their reds were rerun alone and fixed
(filter-ime: the sub-row's click now at once; session-identity, above) or
fail the same on main (tray-logos). The full GUI suite in chromium, on
the rebase onto d5cae267a, was cut short at 352 tests on the owner's
"ship": 6 reds (account-alias, account-models, codex-auto-review,
codex-credits, context-text) each pass alone, here and on main d5cae267a,
so they are timing under the full run's load and are to be filed. After
rebasing onto e4e22b23e: sidebar, side-toggle, session-identity,
filter-ime, library-instr-busy, usage-speed-count and view-scrollbar,
50/50 in chromium and webkit. go build ./... passes.
2026-10-12 00:41:34 +08:00

113 lines
6.0 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");
// #1551 (everpcpc): magpie web in Docker behind a reverse proxy, with
// MAGPIE_PUBLIC_URL=https://magpie.example.com. The page is opened from
// other machines, yet Gateway's Connect started at http://127.0.0.1:3425,
// and so did the copied snippets and the gateway's own address. With no
// address picked, Connect now starts at the public URL, labelled as such,
// the snippets with it, and About shows it beside the local address agents
// here use. An address the user picked, this computer's included, still
// wins after a reload. Served to other machines (magpie web), the
// gateway's address and Settings' MCP server show the public URL too; in
// the app they stay this computer's. Without MAGPIE_PUBLIC_URL nothing
// changes: Connect starts at this computer's.
const PUBLIC = "https://magpie.example.com";
const LOCAL = "http://127.0.0.1:3999";
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
const words = {
en: "Public address", zh: "公网地址", "zh-TW": "公開位址", ja: "公開アドレス", de: "Öffentliche Adresse",
};
async function setup(t, engine, lang, width, options) {
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();
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", fixture(lang, "light", [], { lan: true, ...options }));
const open = async () => {
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#connectAddress").waitFor();
};
const shown = (sel) => page.locator(sel).textContent();
const settingsTab = async (tab) => {
if (!(await page.locator("#view-settings").isVisible())) await page.locator("#prefs").click();
await page.locator(`:is(#setTab-${tab}, .nav-s[data-of=setTab-${tab}]):visible`).click();
};
const fits = async (where) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, where + " wider than the window");
return { page, errors, open, shown, settingsTab, fits };
}
// the snippets carry the gateway key Connect picked for an address
// elsewhere; its read redraws Connect, which closes a menu open
const keyed = (page, base) => page.waitForFunction((u) => {
const s = document.querySelector("#connect pre.snip")?.textContent || "";
return s.includes(u) && s.includes("fixture-laptop");
}, base);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of LANGS) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}: Connect starts at MAGPIE_PUBLIC_URL until an address is picked`, async (t) => {
const { page, errors, open, shown, settingsTab, fits } = await setup(t, engine, lang, width, { lanURLs: [PUBLIC], publicURL: PUBLIC });
// nothing picked yet: the public URL, with a gateway key, in the
// snippet too
await open();
assert.equal(await shown("#connectAddress"), PUBLIC + "/v1");
await keyed(page, PUBLIC + "/v1");
assert.doesNotMatch(await shown("#connect pre.snip"), /127\.0\.0\.1/);
// in the app, the gateway's own address stays this computer's
assert.equal(await shown("#gateway .url code"), LOCAL);
await page.locator("#connectAddress").click();
assert.match(await page.locator(".proto-menu .pm-item", { hasText: "magpie.example.com" }).textContent(), new RegExp(words[lang]));
await fits("Gateway");
// the user's own pick, this computer, wins over the public URL
await page.locator(".proto-menu .pm-item", { hasText: "127.0.0.1" }).click();
await page.locator(".proto-menu").waitFor({ state: "detached" });
assert.equal(await shown("#connectAddress"), LOCAL + "/v1");
await open();
assert.equal(await shown("#connectAddress"), LOCAL + "/v1");
// About keeps the local address agents use, and shows the public one
await settingsTab("about");
await page.locator("#publicURLRow").waitFor();
assert.match(await shown("#publicURLRow .who"), new RegExp(words[lang]));
assert.equal(await shown("#publicURLRow code"), PUBLIC);
assert.match(await shown("#about"), /127\.0\.0\.1:3999/);
await fits("About");
await settingsTab("models");
assert.equal(await shown("#searchMcpRow code"), LOCAL + "/mcp/magpie/web-search");
assert.deepEqual(errors, []);
});
}
}
for (const width of [1100, 420]) {
test(`${engine} ${width}: magpie web shows MAGPIE_PUBLIC_URL as the gateway's address`, async (t) => {
const { page, errors, open, shown, settingsTab } = await setup(t, engine, "en", width, { lanURLs: [PUBLIC], publicURL: PUBLIC, web: true });
await open();
assert.equal(await shown("#connectAddress"), PUBLIC + "/v1");
await keyed(page, PUBLIC + "/v1");
assert.equal(await shown("#gateway .url code"), PUBLIC);
await settingsTab("models");
assert.equal(await shown("#searchMcpRow code"), PUBLIC + "/mcp/magpie/web-search");
assert.deepEqual(errors, []);
});
}
test(`${engine}: without MAGPIE_PUBLIC_URL Connect starts at this computer's address`, async (t) => {
const { page, errors, open, shown, settingsTab } = await setup(t, engine, "en", 1100, { lanURLs: ["http://192.168.1.10:3999"], web: true });
await open();
assert.equal(await shown("#connectAddress"), LOCAL + "/v1");
assert.equal(await shown("#gateway .url code"), LOCAL);
await settingsTab("about");
await page.locator("#about .row").first().waitFor();
assert.equal(await page.locator("#publicURLRow").count(), 0);
assert.deepEqual(errors, []);
});
}