library: the first part of a skill group opens below its heading, not over it (jinpwng on X)

jinpwng on X (macOS, Chinese UI): in Library > Skills, opening the first
group made the page jump, and what was clicked went off the screen; the
others opened downwards. The group was the first part of a big group (a
repository split by folder, drawn in the group's windowed list). A click
on a part's heading draws it anew, and the first part's only neighbour
above it is the list's zero-height pad, which the click's hold passes
over. So the page held the next part's heading, the rows opened pushed it
down, and the view scrolled by the whole part: the clicked heading went
from 152 to -920. A part's heading is now data-unrolls, so the hold keeps
its list, whose top doesn't move. Top-level groups, projects and the
Instructions agents already held still; the new test guards them too.

library-group-steady.test.cjs opens and folds, at the top and scrolled:
the Skills groups and the big group's parts (first and second, and the
first with the second open), the projects in Skills, MCP and Subagents
(first and third), and two Instructions agents. Each heading must stay
within 1.5px of where it was clicked. Clicks and scrolls go through
page.mouse, since Playwright's own scroll before a click reads as the
reader's.

Run (mica, mica-run), at base 436d507f0 unless said:
- library-group-steady in chromium and webkit, en zh zh-TW ja de, at 980
  and 420: 22 of 22 pass.
- Broken by hand (data-unrolls line removed): 20 of 20 cases red in both
  engines, "the first part opened: the heading moved from 152 to -920"
  (420: 242 to -830).
- With click-scroll, every-skill, found-fold, library-groups,
  library-instr-busy, library-instr-sets, nav-sub-unroll,
  project-skills-groups, project-skills-pick, skill-fold-all,
  skill-group-shared, skill-groups, skill-parts and i18n-keys, in both
  engines: 90 pass, 12 fail. The 12 are i18n-keys' "a plugin's words are
  its own" (#6422/#6423) and skill-fold-all's strict POST list seeing
  /api/update/using (#5982), red the same on origin/main 4545790de.
- Rebased on origin/main 4545790de (no Library or hold change between):
  library-group-steady again in both engines, 5 languages, 980 and 420:
  22 of 22 pass.
- mote: node --check client.js, gofmt -l, go vet ./internal/gui for
  darwin, linux nogui and windows: ok.

Not tried: the real app on macOS (the GUI files only), and a filter
showing a part (it takes the same partHead).
This commit is contained in:
yetone
2026-11-13 13:23:41 +08:00
parent 3f6b1b0c94
commit ac1702c330
4 changed files with 206 additions and 2 deletions
+1 -1
View File
@@ -651,7 +651,7 @@ covers it in both engines, every language and a narrow window.
- Settings' search APIs are asked in their listed order: each API's row (with its keys' row) is dragged as one, or moved with Alt+↑/↓, and has a switch that turns it off without removing its key (#2286). See [the search APIs' order](gateway-routing.md#the-search-apis-order-and-one-switched-off), `searchArrange` in [`plugins/search/settings.js`](../../internal/gui/assets/plugins/search/settings.js) and `search-order.test.cjs`.
- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/plugins/search/settings.js) and `search-api.test.cjs`.
- Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it.
- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).
- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. A heading drawn anew whose only neighbour above is a zero-height pad (the first part of a skill group's windowed list) is marked so too: the hold passes over a neighbour with no height, so it held the next part's heading, which the rows opened pushed down, and the clicked one went off the top (jinpwng on X, `partHead` in plugins/library/client.js, `library-group-steady.test.cjs`). Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).
- A page scrolled a screen down shows Scroll to top and Scroll to bottom (emo172, #1090): a small capsule of two chevron buttons at the open page's lower right, in its right margin when a wide window leaves one, else over its corner; above Providers' sticky Add buttons. It goes again near the page's top and over a dialog, and, over the corner, at the page's foot, where the last row can't scroll out from under it, unless it has the pointer or focus. It is placed again on a scroll, a resize, a page shown or hidden, and whenever the open page or one of its own children changes size (a `ResizeObserver`, so a Routing group opened or closed moves it off the editor with no scroll, Jiabubu; see `view-ends-relayout.test.cjs`). It never changes the page's height, which the guard below measures. A press is the reader's scroll (`scrollOnPurpose`, then `arrived` once the page stands still), smooth unless motion is reduced; Scroll to bottom is `aria-disabled` at the foot. Each button's name and tooltip are in every language. The code is [`scrollends.js`](../../internal/gui/assets/scrollends.js), imported on the window's first scroll so the core doesn't carry it; the tray panel has none. Home and End scroll a page as before. See `view-ends.test.cjs`.
- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`. Under a click's 4s hold the same holds: only a put-back that comes with the page redrawn since the hold last held (`redrawn`: the view's height or where the first held parts sit moved from `h.lay`) is the hold's and never counts toward a run, so a profile opened on the Agents page and wheeled through at once scrolls, issennknight on Discord, `view-wheel-after-click.test.cjs`. The parts `h.lay` measures are those still in the page that scroll with it: a part drawn again since (the Usage page's tabs, the agents' list under an agent opened or closed) is a redraw once, not at every scroll, and a sticky one (Settings' tabs at a narrow width) is left out, as it sits still while the page scrolls; `view-wheel-after-redraw.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.
- A load that lands puts the view back where the reader left it (`show`'s `back` on the page's first reads, the Providers pages' reload after `render`): what it drew may have pulled the view up, the browser clamping it to a page shorter for a moment. While the reader scrolls, the place last heard is late (the page hears of a scroll a frame or more after it, WebKit scrolling on its own thread), and putting it back took their last steps and stopped their coast each time a load landed under the wheel, so Routing and Usage, scrolled as they opened, shook and snapped back (issennknight on Discord, macOS 13). `backAfterLoad` keeps a view that has gone on the way the reader's own scrolls go (`readerWay`, set from each scroll of theirs) as theirs, and puts back only a move against it, which is a redraw's clamp. The browser's scroll anchoring stays on: as data comes in above, it lowers `scrollTop` with what's on the screen still, which the reader never sees, so the test tells a put-back (the view up, what was under the pointer going down with it) from that.
File diff suppressed because one or more lines are too long
@@ -5527,6 +5527,11 @@ magpie.plugin("library", (ctx) => {
head.append(el("span", "grow"), groupChips(live, all, null));
}
head.title = folded ? t("Show its skills") : t("Hide its skills");
// a click draws it anew, and the first part's only neighbour above is
// the list's empty pad: the page held the next part's heading, pushed
// down by the rows opened, and scrolled the clicked one away
// (jinpwng on X). Held is its list instead, whose top doesn't move.
head.dataset.unrolls = "";
head.onclick = () => {
if (filtering) { if (folded) unfiltered.delete(fk); else unfiltered.add(fk); }
else { folds[fk] = !folded; saveFolds(); }
@@ -0,0 +1,199 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// jinpwng on X: in Library › Skills, opening the first group made the page
// jump, and what was clicked went off the screen, while the others opened
// downwards. The group was the first part of a big group (a folder of a
// repository, drawn in the group's long list): a click draws its heading
// anew, and the only neighbour above the first part is the list's empty
// pad, so the page held the next part's heading, pushed down by the rows
// opened. A heading opened or folded stays where it was clicked, and what it
// opens comes in below it: the groups and their parts in Skills, the
// projects in Skills, MCP and Subagents, and the agents in Instructions,
// the first and one further down, at the top of the page and scrolled. Both
// engines, five languages, wide and narrow; 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(__dirname, "../assets");
const HOME = "/Users/me";
const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json`, instructions: `${HOME}/.${id}/AGENTS.md`, ...more });
const gh = (repo, dir, name) => ({ name, kind: "github", source: `https://github.com/${repo}/tree/main/${dir}/${name}`, description: "d", agents: ["claude"] });
const AGENTS = ["Claude Code", "Codex", "Gemini CLI", "OpenCode"];
function library() {
// two repositories, 51 skills: past 40 the groups and their parts start
// folded, and big/pack is split by the folders its skills are in
const skills = [];
for (let i = 0; i < 3; i++) skills.push(gh("acme/kit", "skills", "kit-" + i));
for (const d of ["alpha", "beta", "gamma"]) for (let i = 0; i < 16; i++) skills.push(gh("big/pack", "skills/" + d, d + "-" + i));
const project = (name) => ({ dir: `${HOME}/code/${name}`, name, copy: false, skills: { "kit-0": ["claude"], "kit-1": ["claude"] }, placed: [], servers: { fetch: ["claude"] }, subagents: { reviewer: ["claude"] }, wrote: {} });
const ids = ["claude", "codex", "gemini", "opencode"];
return {
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: ids.map((id, i) => agent(id, AGENTS[i], { projectSkills: `.${id}/skills`, projectMCP: `.${id}/mcp.json`, subagents: `${HOME}/.${id}/agents`, projectSubagents: `.${id}/agents` })),
instructions: {
shared: "Be brief.",
sets: [{ id: "default", name: "", active: true, text: "Be brief." }],
agents: ids.map((id, i) => ({ agent: id, name: AGENTS[i], icon: "", path: `${HOME}/.${id}/AGENTS.md`, on: true, extra: "" })),
},
foundServers: [], foundSkills: [], problems: [],
servers: [{ name: "fetch", command: "uvx", args: ["mcp-server-fetch"], agents: ["claude"] }],
subagents: [{ name: "reviewer", description: "Reviews a change", agents: ["claude"] }],
projects: ["app", "web", "api", "docs"].map(project),
skills,
};
}
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:true};` });
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/library") return json(library());
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/usage/quotas") return json([]);
if (url.pathname.startsWith("/api/")) return json({});
if (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 LANGS = ["en", "zh", "zh-TW", "ja", "de"];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a group opened or folded stays where it was clicked", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
for (const lang of (process.env.LANGS ? process.env.LANGS.split(",") : LANGS)) for (const width of [980, 420]) {
await t.test(lang + " " + width, async () => {
const height = 760;
const ctx = await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" });
const page = await ctx.newPage();
page.setDefaultTimeout(8000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
const v = page.locator("#view-library");
let tab = "skills";
const open = async (id) => {
tab = id;
await page.goto("http://magpie.test/");
await page.evaluate((id) => { localStorage.clear(); localStorage.setItem("magpie.libTab", id); }, id);
await page.reload();
await page.locator('button[data-view="library"]').click();
};
const top = (head) => head.evaluate((h) => h.getBoundingClientRect().top);
const settle = () => page.evaluate(() => new Promise((ok) => requestAnimationFrame(() => requestAnimationFrame(ok))));
// the heading put at a point in the window by the reader's own wheel
// (which also ends the hold of the click before)
const place = async (head, at) => {
await page.mouse.move(width / 2, height / 2);
const by = (await top(head())) - at * height;
if (Math.abs(by) > 2) await page.mouse.wheel(0, by);
await page.waitForTimeout(300);
await settle();
// narrow, the library's own heading sticks at the top once
// scrolled, and the heading is kept clear below it
const under = await page.evaluate(() => Math.max(0, ...[...document.querySelectorAll("#view-library .lib-head")].map((h) => h.getBoundingClientRect().bottom)));
const y = await top(head());
if (y < under + 16) {
await page.mouse.wheel(0, y - under - 40);
await page.waitForTimeout(300);
await settle();
}
};
// a click on its name, as the reader's pointer would (Playwright's
// own click scrolls first), and where the heading, drawn anew, is
// once the page has settled
const flip = async (head, what) => {
const was = await head().evaluate((h) => h.classList.contains("open"));
const y = await top(head());
assert.ok(y > 0 && y < height - 30, `${tab}, ${what}: the heading is in the window (${Math.round(y)})`);
const b = await head().locator(".name").first().boundingBox();
const cx = b.x + Math.min(12, b.width / 2), cy = b.y + b.height / 2;
await page.mouse.click(cx, cy);
// drawn anew, so the heading is found again until it has turned
for (const t0 = Date.now(); Date.now() - t0 < 4000;) {
if (await head().evaluate((h) => h.classList.contains("open")).catch(() => was) !== was) break;
await page.waitForTimeout(50);
}
await page.waitForTimeout(300);
await settle();
assert.equal(await head().evaluate((h) => h.classList.contains("open")), !was, `${tab}, ${what}: it ${was ? "folded" : "opened"}`);
const after = await top(head());
assert.ok(Math.abs(after - y) < 1.5, `${tab}, ${what} ${was ? "folded" : "opened"}: the heading moved from ${Math.round(y)} to ${Math.round(after)}`);
};
// Skills: the groups, then the parts of the big one
await open("skills");
const group = (i) => () => v.locator(".lib-grouphead").nth(i);
const part = (i) => () => v.locator(".lib-subhead").nth(i);
await group(0)().waitFor();
assert.equal(await v.locator(".lib-grouphead").count(), 2);
const big = await v.locator(".lib-grouphead").evaluateAll((hs) => hs.findIndex((h) => h.textContent.includes("big/pack")));
const small = 1 - big;
await place(group(0), 0.2);
await flip(group(0), "the first group");
await flip(group(0), "the first group");
await place(group(small), 0.3);
await flip(group(small), "the small group");
await flip(group(small), "the small group");
await place(group(big), 0.25);
await flip(group(big), "the big group");
await v.locator(".lib-subhead").nth(2).waitFor();
assert.equal(await v.locator(".lib-subhead").count(), 3);
// the first part: at the top of its list, its only neighbour above
// the list's empty pad (the report), near the top and lower down
for (const at of [0.2, 0.55]) {
await place(part(0), at);
await flip(part(0), "the first part");
await flip(part(0), "the first part");
}
await place(part(1), 0.4);
await flip(part(1), "the second part");
await flip(part(1), "the second part");
// one already open below while the first opens
await flip(part(1), "the second part");
await place(part(0), 0.3);
await flip(part(0), "the first part");
await flip(part(0), "the first part");
// the projects, in each tab that lists them
for (const id of ["skills", "mcp", "subagents"]) {
await open(id);
const project = (i) => () => v.locator(".lib-projhead").nth(i);
await project(0)().waitFor();
assert.equal(await v.locator(".lib-projhead").count(), 4);
for (const i of [0, 2]) {
await place(project(i), 0.3);
await flip(project(i), "project " + (i + 1));
await flip(project(i), "project " + (i + 1));
}
}
// Instructions: an agent's row opens its file below it
await open("instructions");
const row = (name) => () => v.locator(".lib-row.click", { has: page.locator(".name", { hasText: new RegExp("^" + name + "$") }) }).first();
await row(AGENTS[0])().waitFor();
for (const name of [AGENTS[0], AGENTS[2]]) {
await place(row(name), 0.3);
await flip(row(name), name);
await flip(row(name), name);
}
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), "the page scrolls sideways");
assert.deepEqual(errors, []);
await ctx.close();
});
}
});
}