Files
magpie/internal/gui/tests/plugin-manual-float.test.cjs
T
yetone 93b31f5b79 plugins: Discover's install box floats at the foot of the list (0x3108 on X)
With many plugins, Discover's "Have one in mind?" box (install by name)
was found only after scrolling to the very end. It now sticks to the
bottom of the view while the cards scroll under it, on a strip of the
page's own background (no shadow, no gradient), with the same dashed
box. At the end of the list it sits in its place, above the npm
registry line, and every card is above it. Its place in the DOM is
unchanged. The strip blocks clicks so they can't reach a card hidden
under it. Because a sticky box paints its ::before over its own border,
the dashed border is now drawn by ::after. A scroll-padding-bottom keeps
a card reached with Tab from stopping under the box.

CSS only (plugins.css), so no script budget moves. Main's existing core
budget red is #4526. Siblings: Discover is the only page that renders
this box (manual() in plugins.js). Library's skills install card is
already at the top of its page.

Run:
- New test, internal/gui/tests/plugin-manual-float.test.cjs: 40 cards,
  en/zh/zh-TW/ja/de, 390x780, 560x800, 980x820 and 1280x800. The box is
  in the view at the foot at the top and mid-way (wheel scrolling), with
  no card showing above or below it. At the end, the last card is above
  the box and the registry line is below it. Tab from the cards never
  stops under the box. The search field takes keys and Escape brings
  the box back.
  Chromium on mote: 6/6 pass, 3 runs. WebKit through wsl-run (Linux):
  6/6 pass.
  With plugins.css at origin/main, both engines are red: "390x780 at
  the top: the box is in the view" (the box sits at ~6100 in a 780 view).
- The 63 GUI files the change can reach (plugin*, plugins-more-discover,
  signin-paste-plugin, account-plugin-user, agent-plugin-agents,
  i18n-keys, click-scroll), run at --test-concurrency=4:
  - WebKit (wsl-run): 9 reds in 5 files. Rerun serially, they are the
    same 9 at base 0956ca49d and on this change: click-scroll's
    late-heard wheel (#4385), i18n-keys "Unmarked" (#4524),
    plugin-card-update (#3079), plugin-move-unserved (#4392, #4410) and
    plugin-move (#4393). All were already filed.
  - Chromium (mote): most reds are "browser has been closed" crashes
    under the parallel load (#4304). A serial rerun on mote was not
    finished when this was pushed.
- Screenshots checked by eye at 980x820 mid-way and end, and 390x780 de.

At the pushed head (on origin/main 2eac91617): the new test is 6/6 in
Chromium on mote and 6/6 in WebKit through wsl-run.

Not tried: WebKit on macOS (it times out at launch on mote), the real
app window.
2026-10-31 13:52:36 +08:00

188 lines
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// Plugins › Discover's "Have one in mind?" box (install by name) floats at
// the foot of the view while the cards scroll under it (0x3108 on X: with
// many plugins it was found only after scrolling to the very end). With
// many cards it is in sight at the top of the list and mid-way, on a strip
// that hides the cards passing under it; at the end of the list every card
// is above it and the npm registry line is below it, as before. A card
// reached with Tab is not left under it, and the search field still takes
// the keys. Every language, both engines, at 390, 560 and window widths;
// 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 listings = Array.from({ length: 40 }, (_, i) => ({
package: "@magpie-community/opencode-p" + i + "-auth", name: "Plan " + i, community: true, providers: ["p" + i],
summary: { en: "Signs in to plan " + i + " and serves its models" }, npm: { version: "0.1." + i },
}));
const state = { bun: true, bunVersion: "1.3.0", plugins: [], picker: true, registry: { url: "https://registry.npmjs.org", from: "npmrc", path: "~/.npmrc" } };
function server(lang) {
return async (route) => {
const url = new URL(route.request().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/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
if (url.pathname === "/api/plugins") return json(state);
if (url.pathname === "/api/plugins/listings") return json({ listings });
if (url.pathname === "/api/plugins/market") return json({ listings, state });
if (url.pathname === "/api/plugins/github") return json({ repos: [], topic: "magpie-plugin" });
if (url.pathname === "/api/plugins/search") return json({ hits: [] });
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const LABEL = { en: "Have one in mind?", zh: "已有想装的?", "zh-TW": "已有想裝的?", ja: "入れたいものがありますか?", de: "Schon eines im Sinn?" };
const SIZES = [[390, 780], [560, 800], [980, 820], [1280, 800]];
const shot = async (page, name) => {
if (!process.env.ARTIFACT_DIR) return;
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, name + ".png") });
};
// where the box is against the view, and what is drawn just above and
// below it: the box (its strip), never a card
function where() {
const view = document.querySelector("#view-plugins");
const box = view.querySelector(".pm-manual");
const v = view.getBoundingClientRect(), b = box.getBoundingClientRect();
const x = b.left + 30;
const at = (y) => {
const e = document.elementFromPoint(x, y);
return e ? (box.contains(e) ? "box" : e.closest(".pm-card") ? "card" : e.className || e.tagName) : "none";
};
return {
top: b.top, bottom: b.bottom, vTop: v.top, vBottom: v.top + view.clientHeight,
scrollTop: view.scrollTop, room: view.scrollHeight - view.clientHeight,
above: at(b.top - 4), below: Math.min(b.bottom + 2, v.top + view.clientHeight - 1) > b.bottom ? at(Math.min(b.bottom + 2, v.top + view.clientHeight - 1)) : "box",
label: box.querySelector(".pm-mlabel").textContent,
};
}
// the reader's wheel takes the view to a share of its scroll (magpie puts
// back a scroll no reader asked for), and waits for it to stop there
async function scrollTo(page, f) {
const v = page.locator("#view-plugins");
const b = await v.boundingBox();
await page.mouse.move(b.x + b.width / 2, b.y + Math.min(b.height / 2, 200));
const near = ([top, max]) => f >= 1 ? top >= max - 1 : Math.abs(top - max * f) <= 40;
const read = () => v.evaluate((e) => [e.scrollTop, e.scrollHeight - e.clientHeight]);
for (let i = 0; i < 100; i++) {
let at = await read();
if (near(at)) {
await page.waitForTimeout(250);
at = await read();
if (near(at)) return at;
}
await page.mouse.wheel(0, Math.max(-600, Math.min(600, Math.round(at[1] * f) - at[0] + (f >= 1 ? 50 : 0))));
await page.waitForTimeout(60);
}
return read();
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Discover's install box stays in sight over many plugins", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(LABEL)) {
await t.test(lang, async () => {
const ctx = await browser.newContext({ viewport: { width: SIZES[0][0], height: SIZES[0][1] } });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.locator(".pm-manual").waitFor();
await page.waitForFunction((n) => document.querySelectorAll("#view-plugins .pm-card").length >= n, listings.length);
await view.locator(".pm-registry").waitFor();
for (const [w, h] of SIZES) {
const size = `${w}x${h}`;
await page.setViewportSize({ width: w, height: h });
await scrollTo(page, 0);
let p = await page.evaluate(where);
assert.ok(p.room > p.vBottom - p.vTop, `${size}: the cards run well past the view (${p.room})`);
assert.equal(p.label, LABEL[lang]);
for (const [when, to] of [["at the top", 0], ["mid-way", 0.5]]) {
const [top, max] = await scrollTo(page, to);
assert.ok(Math.abs(top - max * to) <= 40, `${size} ${when}: scrolled there (${top} of ${max})`);
p = await page.evaluate(where);
assert.ok(p.top >= p.vTop && p.bottom <= p.vBottom + 0.5, `${size} ${when}: the box is in the view (${JSON.stringify(p)})`);
assert.ok(p.vBottom - p.bottom <= 12, `${size} ${when}: at the view's foot (${JSON.stringify(p)})`);
assert.equal(p.above, "box", `${size} ${when}: no card shows just above the box`);
assert.equal(p.below, "box", `${size} ${when}: no card shows just below the box`);
await shot(page, `plugin-manual-float-${engine}-${lang}-${size}-${to}`);
}
// the end of the list: every card above the box, the registry
// line below it, all in the view
const [top, max] = await scrollTo(page, 1);
assert.ok(top >= max - 1, `${size}: scrolled to the end (${top} of ${max})`);
const end = await page.evaluate(() => {
const v = document.querySelector("#view-plugins");
const vb = v.getBoundingClientRect().top + v.clientHeight;
const box = v.querySelector(".pm-manual").getBoundingClientRect();
const cards = [...v.querySelectorAll(".pm-card")].map((c) => c.getBoundingClientRect().bottom);
const reg = v.querySelector(".pm-registry").getBoundingClientRect();
return { lastCard: Math.max(...cards), boxTop: box.top, boxBottom: box.bottom, regTop: reg.top, regBottom: reg.bottom, vb };
});
assert.ok(end.lastCard <= end.boxTop - 8, `${size}: the last card is above the box (${JSON.stringify(end)})`);
assert.ok(end.regTop >= end.boxBottom && end.regBottom <= end.vb + 0.5, `${size}: the registry line is under the box, in sight (${JSON.stringify(end)})`);
await shot(page, `plugin-manual-float-${engine}-${lang}-${size}-end`);
}
// a card reached with Tab is not left under the box
await page.setViewportSize({ width: SIZES[2][0], height: SIZES[2][1] });
await scrollTo(page, 0);
const under = await page.evaluate(() => {
const v = document.querySelector("#view-plugins");
const top = v.querySelector(".pm-manual").getBoundingClientRect().top;
const cards = [...v.querySelectorAll(".pm-card")];
const i = cards.findIndex((c) => c.getBoundingClientRect().bottom > top);
cards[i - 1].focus();
return i;
});
assert.ok(under > 0, "a card is under the box at the top of the list");
for (let k = 0; k < 8; k++) {
await page.keyboard.press("Tab");
await page.waitForTimeout(30);
const f = await page.evaluate(() => {
const a = document.activeElement, v = document.querySelector("#view-plugins");
const card = a.closest(".pm-card");
if (!card) return null;
return { bottom: a.getBoundingClientRect().bottom, top: v.querySelector(".pm-manual").getBoundingClientRect().top };
});
if (f) assert.ok(f.bottom <= f.top + 0.5, `the focused card is above the box (${JSON.stringify(f)})`);
}
// the search field still takes the keys, and gives the list back
const q = view.locator(".pm-find input");
await q.click();
await page.keyboard.type("Plan 3");
assert.equal(await q.inputValue(), "Plan 3");
assert.equal(await page.evaluate(() => document.activeElement === document.querySelector("#view-plugins .pm-find input")), true);
await page.keyboard.press("Escape");
await view.locator(".pm-manual").waitFor();
assert.deepEqual(errors, []);
});
}
});
}