Beside the sidebar, Library's, Plugins' and Settings' heads sit in the
title bar after the breadcrumb, between --tools-l (the crumb's right +
16) and the window's buttons, laid out flex-end. When the tools needed
more than that room they ran on to the left, over the crumb: at about
650pt with the sidebar, Library -> MCP servers had 「发现」 over
「MCP 服务器」's last character. The crumb never gave way to them.
app.js tools() now shares the room out, laying out and reading each
step in its one frame, the next only if the tools still run over:
1. the crumb whole (its natural width from its parts, the last one's
scrollWidth) and the tools with their words;
2. body.tools-tight: Library's Discover / Library folder / Backups and
Plugins' "Mirrors in China" show their icon (or switch) alone. Each
keeps its name as aria-label (a hidden span leaves the accessible
name) and its tooltip as before (the folder's path, the backups'
note and path, Discover's and the mirrors' sentences);
3. --crumb-max: the crumb drops its leading parts ("Work /"), a part
and its slash at a time, and last cuts the page's name at its end.
In the side-nav head the Library buttons and the mirror switch are
flex: none and Plugins' search keeps 120px, so what doesn't fit shows
as running over rather than shrinking out of sight. The views'
MutationObserver also asks tools() again, as a tab's own tools change
(Discover only on MCP servers and Skills) without the crumb resizing.
title-bar-tools.test.cjs (new): every Library tab, Plugins' three and
Settings, sidebar picked, window mode, at 560 (the window's least),
650, 760, 900, 1024 and 1280px, in zh, zh-TW, ja, de and en, Chromium
and WebKit. No tool lies over the shown title or another tool or out
of the bar, no label is cut, an icon-only tool has aria-label and
title, only leading crumb parts go and the page's name shows, whole
from 650px. Against the old assets (MAGPIE_GUI_ASSETS) it fails in all
five languages at 560px Library Instructions ("a tool lies over the
title"); with the change Chromium 5/5 and WebKit 5/5. Looked at
screenshots of zh Library MCP servers and Plugins Discover at 560, 650
and 760px.
docs/subsystems/gui-shell.md says how the title bar gives way.
Run with both #2623's and #2625's changes, on b7d9616d0 (macOS, Go
1.26.8, load average 80-270 from other sessions):
- gofmt -l: nothing. go vet -tags nogui ./... with GOOS darwin, linux and
windows: clean.
- set -o pipefail; go test -timeout 45m ./...: every package ok except
internal/agent (2702s) and internal/gateway (2721s), which ran past
45m under the load (#2544, #2108; no test hung, each was seconds into
its run). Rerun with -timeout 90m: internal/agent ok (2816s);
internal/gateway's only red is TestDesktopSubagentUnsetDoesNotDecode,
"allocated 1 times" (10/10 green alone, filed as #2699). The textcalls
tests passed in that run.
- The whole GUI suite, both engines (NODE_PATH at playwright@1.62.0). It
ran in two parts, because another session deleted the first part's log
mid-run; the files from provider-* on were run again. title-bar-tools
passed 10/10 inside the suite. The reds are red the same way on
b7d9616d0's assets, rerun beside them (MAGPIE_GUI_ASSETS) at
concurrency 1-2:
- segs-glide 20/20: filed #2683.
- sidebar under load: filed #2684; 4/6 red on the old assets.
- lightweight: filed #2638.
- Already filed:
- usage-agents-hide (#2276), routing-bodies (#2559, #2658),
routing-keys-fold (#1612), routing-model-rest (#2115),
routing-wb-restricted (#1905), rest-try-now (#2564), s3-sync (#2448).
- quota-count-wrap, quota-name-translated and usage-fold (#2399),
usage-checkin (#2549), usage-refresh (#2184), usage-ledger (#1876).
- codex-predictions (#2624), github-sync (#2631), login-import (#1307).
- The rest were Playwright launch timeouts under load (#2371).
- After rebasing on origin/main 85eef5d87: title-bar-tools Chromium 5/5,
WebKit 5/5. Before that, WebKit zh and ja failed on a page error, "Fetch
API cannot load /api/providers due to access control checks". That is
WebKit's report of a sidebar read cancelled by the test going to the
next page (#1350, #1307). The test now leaves that one WebKit message
out. Against b7d9616d0's assets, WebKit ja is still red: "a tool lies
over the title at 560px library instructions".
Not tried in the real app on Linux (WebKitGTK) or Windows (WebView2);
no motion or new browser API is involved, only layout.
154 lines
10 KiB
JavaScript
154 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// #2625 (linusxiong): beside the sidebar, a page whose head is only its
|
|
// tools (Library, Plugins, Settings) has them in the title bar, after
|
|
// where the reader is ("Work / Library / MCP servers"). In a narrow
|
|
// window the tools ran on to the left, over the title: 「MCP 服务器」's
|
|
// last character sat on 「发现」. Now nothing in the title bar lies over
|
|
// anything else, the tools keep inside it, and the title shows whole
|
|
// wherever the tools can make room for it by showing only their icons;
|
|
// a tool shown as its icon keeps its name for the reader and a tooltip.
|
|
// Every Library tab, Plugins' and Settings', the window from its least
|
|
// width (560px) up, the sidebar picked, in all five languages, Chromium
|
|
// and WebKit. No backend: the API is faked.
|
|
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(process.env.MAGPIE_GUI_ASSETS || path.join(__dirname, "../assets"));
|
|
const HOME = "/Users/tester";
|
|
const agent = (id, name, icon) => ({ id, name, icon, skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
|
|
|
function serve(lang) {
|
|
const view = {
|
|
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
|
agents: [agent("claude", "Claude Code", "claudecode-color")],
|
|
instructions: { agents: [], sets: [] },
|
|
servers: [{ name: "filesystem", transport: "stdio", command: "npx", args: ["-y", "fs"], agents: ["claude"] }],
|
|
foundServers: [], projects: [], foundSkills: [], problems: [], hooks: [], subagents: [],
|
|
skills: [{ name: "pdf", kind: "folder", description: "PDFs", agents: ["claude"], source: `${HOME}/skills/pdf` }],
|
|
};
|
|
return async (route) => {
|
|
const req = route.request(), url = new URL(req.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: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: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [], mirror: false });
|
|
if (url.pathname === "/api/library") return json(view);
|
|
if (url.pathname === "/api/library/market/servers") return json({ items: [{ id: "fetch", name: "fetch", title: "Fetch", description: "Read the web.", transport: "stdio", runs: "uvx", featured: true }] });
|
|
if (url.pathname === "/api/library/market/skills") return json({ items: [] });
|
|
if (url.pathname === "/api/library/rtk") return json({ path: `${HOME}/.local/bin/rtk`, version: "0.51.0", url: "https://www.rtk-ai.app", agents: [{ id: "claude", name: "Claude Code", icon: "", on: true }] });
|
|
if (url.pathname === "/api/plugins/builtin") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, url: "http://127.0.0.1:3425" } });
|
|
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)];
|
|
const body = await fs.readFile(file).catch(() => null);
|
|
await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" }));
|
|
};
|
|
}
|
|
|
|
// what the title bar shows, once it has settled: the title's parts as
|
|
// far as they show, each tool, and the window's own buttons
|
|
function bar(head) {
|
|
const box = (r) => ({ left: Math.round(r.left), right: Math.round(r.right), top: Math.round(r.top), bottom: Math.round(r.bottom) });
|
|
const crumb = document.querySelector("#crumb"), c = crumb.getBoundingClientRect();
|
|
const parts = [...crumb.children].map((e) => {
|
|
const r = e.getBoundingClientRect();
|
|
return { text: e.textContent, shown: r.width > 0, right: Math.min(r.right, c.right), cut: r.right > c.right + 0.5 || e.scrollWidth > e.clientWidth + 0.5 };
|
|
});
|
|
const h = document.querySelector(head);
|
|
const tools = [...h.querySelectorAll("button, label, input")].filter((e) => e.getClientRects().length && getComputedStyle(e).visibility !== "hidden" && !e.closest("[hidden]") && !e.closest(".lib-tabs, .set-tabs"))
|
|
.filter((e) => !e.parentElement.closest("button, label"))
|
|
.map((e) => {
|
|
const label = [...e.querySelectorAll("span")].find((s) => s.textContent.trim() && !s.closest(".lib-mini"));
|
|
return {
|
|
...box(e.getBoundingClientRect()), aria: e.getAttribute("aria-label"), title: e.title,
|
|
label: label ? label.getClientRects().length > 0 : null, clipped: e.scrollWidth > e.clientWidth + 1,
|
|
};
|
|
});
|
|
const acts = document.querySelector(".top .actions").getBoundingClientRect();
|
|
return { parts, crumb: box(c), tools, acts: box(acts), side: document.querySelector("#side").getBoundingClientRect().right, view: innerWidth };
|
|
}
|
|
|
|
const pages = [
|
|
...["instructions", "mcp", "skills", "hooks", "subagents", "rtk"].map((tab) => ({ name: "library " + tab, url: "?view=library", head: "#view-library .lib-head", init: ["magpie.libTab", tab] })),
|
|
...["builtin", "discover", "installed"].map((tab) => ({ name: "plugins " + tab, url: "?view=plugins", head: "#view-plugins .pm-head", init: ["magpie.pluginTab", tab] })),
|
|
{ name: "settings", url: "?view=settings", head: "#view-settings .set-head" },
|
|
];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["zh", "zh-TW", "ja", "de", "en"]) {
|
|
test(`${engine} ${lang}: the title bar's tools never lie over where the reader is`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const width of [560, 650, 760, 900, 1024, 1280]) {
|
|
const context = await browser.newContext({ viewport: { width, height: 640 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
let on = "";
|
|
// going from page to page cancels the reads still on their way, and
|
|
// WebKit reports each one as a page error, "Fetch API cannot load …
|
|
// due to access control checks" (#1350, #1307): not this test's
|
|
page.on("pageerror", (e) => {
|
|
if (engine === "webkit" && /^Fetch API cannot load .* due to access control checks/.test(e.message)) return;
|
|
errors.push(`${width}px ${on}: ${e.stack}`);
|
|
});
|
|
await page.route("**/*", serve(lang));
|
|
await page.addInitScript(() => { localStorage.setItem("magpie.navLayout", "side"); });
|
|
for (const p of pages) {
|
|
on = p.name;
|
|
if (p.init) await page.evaluate(([k, v]) => localStorage.setItem(k, v), p.init).catch(() => {});
|
|
await page.goto("http://magpie.test/" + p.url);
|
|
if (p.init) { await page.evaluate(([k, v]) => localStorage.setItem(k, v), p.init); await page.reload(); }
|
|
await page.locator(p.head).waitFor();
|
|
await page.locator("#crumb b").waitFor();
|
|
// the Library's buttons have their tooltips once it has loaded
|
|
if (p.name.startsWith("library")) await page.locator("#view-library .lib-more:not([disabled])").waitFor();
|
|
if (p.name === "library mcp") await page.locator("#view-library .lib-discover").waitFor();
|
|
if (/plugins (discover|installed)/.test(p.name)) await page.locator("#view-plugins .pm-mirror").waitFor();
|
|
// settled: two frames with the same bar
|
|
let b = null;
|
|
for (let i = 0; i < 40; i++) {
|
|
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
|
const now = await page.evaluate(bar, p.head);
|
|
if (b && JSON.stringify(now) === JSON.stringify(b)) break;
|
|
b = now;
|
|
}
|
|
const at = `${width}px ${p.name}: ${JSON.stringify(b)}`;
|
|
// Plugins' Built-in has no search and no mirrors to pick
|
|
assert(b.tools.length > 0 || p.name === "plugins builtin", `no tools in the bar at ${at}`);
|
|
const title = b.parts[b.parts.length - 1];
|
|
const shown = Math.max(...b.parts.map((x) => x.right));
|
|
for (const tool of b.tools) {
|
|
assert(tool.left >= shown + 8, `a tool lies over the title at ${at}`);
|
|
assert(tool.left >= b.side && tool.right <= b.acts.left, `a tool runs out of the bar at ${at}`);
|
|
assert(!tool.clipped, `a tool's label is cut at ${at}`);
|
|
if (tool.label === false) assert(tool.aria && tool.title, `a tool shown as its icon has no name or tooltip at ${at}`);
|
|
}
|
|
for (let i = 1; i < b.tools.length; i++) {
|
|
const [x, y] = [b.tools[i - 1], b.tools[i]].sort((m, n) => m.left - n.left);
|
|
assert(x.right <= y.left, `two tools lie over each other at ${at}`);
|
|
}
|
|
assert(b.crumb.right <= b.acts.left, `the title runs under the window's buttons at ${at}`);
|
|
// the page the reader is on shows, if its start only; the parts
|
|
// before it go first
|
|
assert(title.shown && title.right - (b.crumb.left) > 0, `the page's name is gone at ${at}`);
|
|
const kept = b.parts.findIndex((x) => x.shown);
|
|
assert(b.parts.slice(kept).every((x) => x.shown), `the title lost a part in its middle at ${at}`);
|
|
if (title.cut) assert(b.parts.slice(0, -1).every((x) => !x.shown), `the page's name is cut while parts before it show at ${at}`);
|
|
// where the tools have their icons alone, nothing more of them
|
|
// can give way: the title shows whole wherever it fits beside them
|
|
if (width >= 650) assert(!title.cut, `the title is cut at ${at}`);
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
}
|
|
});
|
|
}
|
|
}
|