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 ontod5cae267a, 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 maind5cae267a, so they are timing under the full run's load and are to be filed. After rebasing ontoe4e22b23e: 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.
115 lines
8.1 KiB
JavaScript
115 lines
8.1 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// #1348 (ttmouse): with dozens of skills in the library the market
|
|
// (Discover) sat many screens down, under the list. The Skills and MCP
|
|
// tabs' strip at the top, which stays as the page scrolls, has a Discover
|
|
// button that takes the reader to it, its search box ready to type in. The
|
|
// other tabs don't show it. It fits a narrow window and browser, has no left border,
|
|
// and only its click moves the page. In English and Chinese. No backend:
|
|
// the API is faked here.
|
|
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(__dirname, "../assets");
|
|
const HOME = "/Users/tester";
|
|
const agent = (id, name, icon) => ({ id, name, icon, skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
|
const skills = Array.from({ length: 60 }, (_, i) => ({ name: `skill-${String(i).padStart(2, "0")}`, kind: "folder", description: `Skill number ${i}`, agents: ["claude"], source: `${HOME}/skills/skill-${i}` }));
|
|
const servers = Array.from({ length: 40 }, (_, i) => ({ name: `server-${String(i).padStart(2, "0")}`, transport: "stdio", command: "npx", args: ["-y", `server-${i}`], agents: ["claude"] }));
|
|
|
|
function serve(lang, web) {
|
|
const view = {
|
|
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
|
agents: [agent("claude", "Claude Code", "claudecode-color")],
|
|
instructions: { agents: [], sets: [] }, servers, foundServers: [], projects: [], foundSkills: [], skills, problems: [],
|
|
};
|
|
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:${web}};` });
|
|
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: [] });
|
|
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: [{ id: "acme/skills/pdf", name: "pdf", source: "acme/skills", skillId: "pdf", installs: 1200, description: "PDFs" }] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
|
|
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: "" }));
|
|
};
|
|
}
|
|
|
|
const words = { en: { discover: "Discover", tabs: ["Instructions", "MCP servers", "Skills"] }, zh: { discover: "发现", tabs: ["指令", "MCP 服务器", "技能"] } };
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
for (const [web, width] of [[true, 1000], [true, 560], [false, 1000], [false, 560]]) {
|
|
test(`${engine} ${lang} ${web ? "browser" : "window"} ${width}px: Discover at the top goes to the market under a long list`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const context = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
page.on("console", (m) => { if (/scroll not asked for/.test(m.text())) errors.push(m.text()); });
|
|
await page.route("**/*", serve(lang, web));
|
|
await page.addInitScript(() => { localStorage.setItem("magpie.libTab", "skills"); });
|
|
t.after(() => browser.close());
|
|
await page.goto("http://magpie.test/?view=library");
|
|
const view = page.locator("#view-library");
|
|
const head = view.locator(".lib-head");
|
|
await view.locator('.mk[data-market="skills"] .mk-card').first().waitFor();
|
|
const go = head.getByRole("button", { name: words[lang].discover, exact: true });
|
|
|
|
for (const kind of ["skills", "mcp"]) {
|
|
if (kind === "mcp") {
|
|
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: words[lang].tabs[1] }).click();
|
|
await view.locator('.mk[data-market="mcp"] .mk-card').first().waitFor();
|
|
}
|
|
await t.test(`${kind}: the market is far down, and the button takes the reader there`, async () => {
|
|
await view.evaluate((e) => { e.scrollTop = 0; });
|
|
const mk = view.locator(`.mk[data-market="${kind}"]`);
|
|
const below = await mk.evaluate((m) => m.getBoundingClientRect().top - m.closest(".view").getBoundingClientRect().bottom);
|
|
assert(below > 700, `the market is only ${below}px below the view`);
|
|
await go.waitFor();
|
|
// the strip and its button fit the window; nothing has a left border
|
|
const fit = await head.evaluate((h) => {
|
|
const b = h.querySelector(".lib-discover").getBoundingClientRect(), v = h.closest(".view");
|
|
return { right: b.right, width: v.getBoundingClientRect().right, wrapped: h.querySelector(".lib-discover span:last-child").getClientRects().length > 1 || h.querySelector(".lib-discover").scrollWidth > h.querySelector(".lib-discover").clientWidth, side: v.scrollWidth - v.clientWidth, stripe: ((c) => c.borderLeftWidth !== c.borderRightWidth || c.borderLeftColor !== c.borderRightColor)(getComputedStyle(h.querySelector(".lib-discover"))) };
|
|
});
|
|
assert(fit.right <= fit.width, `the button runs out of the view: ${JSON.stringify(fit)}`);
|
|
assert.equal(fit.side, 0, "the view scrolls sideways");
|
|
assert(!fit.wrapped, "the button's label wraps");
|
|
assert(!fit.stripe, "the button has a left border of its own");
|
|
await go.click();
|
|
// its heading and search box in sight under the strip: at the
|
|
// top, or as high as the end of the page lets it go
|
|
const inSight = (k) => {
|
|
const m = document.querySelector(`.mk[data-market="${k}"]`), v = m.closest(".view"), h = v.querySelector(".lib-head");
|
|
const top = m.getBoundingClientRect().top, end = v.scrollTop + v.clientHeight >= v.scrollHeight - 1;
|
|
return top >= h.getBoundingClientRect().bottom - 1 && (top < v.getBoundingClientRect().top + 120 || end && top < v.getBoundingClientRect().bottom - 120);
|
|
};
|
|
await page.waitForFunction(inSight, kind);
|
|
assert.equal(await page.evaluate(() => document.activeElement?.dataset?.lib), "market-" + kind, "the market's search box isn't focused");
|
|
// and stays there once the page has settled
|
|
await page.waitForTimeout(500);
|
|
assert(await page.evaluate(inSight, kind), "the market went out of sight again");
|
|
});
|
|
}
|
|
|
|
await t.test("the Instructions tab has no Discover button", async () => {
|
|
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: words[lang].tabs[0] }).click();
|
|
await view.locator(".lib-body").first().waitFor();
|
|
assert.equal(await head.locator(".lib-discover").count(), 0);
|
|
});
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|