Files
magpie/internal/gui/tests/own-skill.test.cjs
T
yetone 76dc5aed48 gui: Routing flies a request still under way when the page's first frame came before the trace, and the Requests table's sideways scrollbar goes once the table fits; GUI tests brought up to date with the app
Two app bugs, found where GUI tests failed on main in Chromium:
- Routing: the page's first frame looked for requests to fly before the first trace had come in, found none, and nothing flew them after it came, so a request still under way when Routing opened never reached its member's row (routing-try-fixed failed every run). The first trace now flies those under way when a frame has already been drawn, as coming back into sight does (underWay, shared with resume).
- Usage › Requests: a table that had come to fit its window (led tight) kept #ledHScroll's bar under it with nothing to scroll; ledGrow now redraws the bar on every resize, not only when it leaves columns out (usage-speed "no sideways scrollbar").

Stale or racy tests, the app right:
- library-own-folder, list-sort, shared-skills and nine other Library tests counted the loading skeleton's rows (the "5 vs 4 rows" and the empty lists were the skeleton, not the repo group headers); they wait for .lib-body:not(.lib-skel). library-own-folder's 61px scroll was Playwright's own retry on a button still sliding in, not the app (no scroll setter ran): it waits for the entrance to finish.
- sessions-overview measured the picked bar while the folder's overview redrew the bars; it measures once the overview is in.
- menu-scroll: its agent needs wired and a ref to show a model picker, and the page now asks plugins/updates, usage/quotas, agents/install and whatsnew.
- routing-sessions' large-history tests failed from local midnight until the UTC offset passed: the fixture's times were UTC while the gateway writes local times with their offset, which openRoute takes the day from.
- ledger-hscroll and view-scrollbar measured scrollbars in Chromium launched with --hide-scrollbars; they launch without it, as menu-scroll does.

routing-try-fixed and usage-speed fail without the app changes and pass with them (checked by putting origin/main's routing.js and app.js back). go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (TestHostJSCancellation timed out once under the full run's load and passes on its own, 3 runs).
2026-10-06 03:20:34 +08:00

145 lines
8.4 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// StringKe and JasonLeeForOnly on Discord: after Bring in all, "Claude Code
// already has a skill of its own called impeccable" stood in the Library's
// warning with nothing to do about it. The warning row now says it in the
// reader's language and settles it in place: "Use the library's" posts
// skills/use-library (the agent's own kept aside), "Keep Claude Code's"
// posts skills/keep-own (the agent off the skill), the warning goes, and the
// click scrolls nothing. A skill found in an agent with a byte copy in
// another is shown as that agent's too, not as differing there. 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/stringke";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills` });
const problem = { agent: "claude", what: "skill:impeccable", error: "Claude Code already has a skill of its own called impeccable", own: true };
const lib = (agents, problems, foundSkills = []) => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [agent("claude", "Claude Code"), agent("codex", "Codex"), agent("gemini", "Gemini CLI")],
instructions: { agents: [] }, servers: [], foundServers: [], projects: [], foundSkills,
skills: [
{ name: "impeccable", description: "Design", kind: "", agents },
...Array.from({ length: 12 }, (_, i) => ({ name: "s" + i, description: "d", kind: "", agents: ["codex"] })),
],
problems,
});
const found = [
{ name: "polish", description: "Polish", agents: ["claude"], copies: ["codex"] },
{ name: "audit", description: "Audit", agents: ["claude"], others: ["gemini"] },
];
function server(lang, posts) {
return async (route) => {
const req = route.request(), url = new URL(req.url());
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 route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib(["claude", "codex"], [problem], found) });
if (url.pathname === "/api/library/skills/use-library") {
posts.push([url.pathname, req.postDataJSON()]);
return route.fulfill({ json: { ...lib(["claude", "codex"], [], found), result: { changed: ["claude"], problems: [] } } });
}
if (url.pathname === "/api/library/skills/keep-own") {
posts.push([url.pathname, req.postDataJSON()]);
return route.fulfill({ json: { ...lib(["codex"], [], found), result: { changed: [], problems: [] } } });
}
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const words = {
en: {
line: "Claude Code · Skill impeccable",
err: "Claude Code has a skill of its own called impeccable, not the same as the library's",
use: "Use the library's", keep: "Keep Claude Code's",
used: "Claude Code has the library's impeccable now; its own is kept with the backups",
kept: "Claude Code keeps its own impeccable",
differs: "differs in Gemini CLI",
},
zh: {
line: "Claude Code · 技能 impeccable",
err: "Claude Code 已有自己的同名技能 impeccable,与资源库中的不同",
use: "用资源库的", keep: "保留 Claude Code 自己的",
used: "Claude Code 已换成资源库的 impeccable,它自己的已放进备份",
kept: "Claude Code 保留了自己的 impeccable",
differs: "Gemini CLI 中不同",
},
};
const scrolled = (page) => page.evaluate(() => [window.scrollX, window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop || e.scrollLeft).map((e) => `${e.className}:${e.scrollTop},${e.scrollLeft}`)].join(" "));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": an agent's own skill in the library's way", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(async () => {
if (errors.length) console.log(errors);
await browser.close();
});
const open = async (lang, posts) => {
const ctx = await browser.newContext({ viewport: { width: 980, height: 700 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
await page.locator("#view-library .lib-body:not(.lib-skel) .lib-row").first().waitFor();
return page;
};
for (const lang of ["en", "zh"]) {
const w = words[lang];
for (const [which, route, done, agents] of [["use", "/api/library/skills/use-library", "used"], ["keep", "/api/library/skills/keep-own", "kept"]]) {
await t.test(`${lang}: ${w[which]} settles it from the warning`, async () => {
const posts = [];
const page = await open(lang, posts);
const card = page.locator("#view-library > .lib-problems");
const li = card.locator("li");
await li.waitFor();
assert.equal(await li.evaluate((l) => [...l.children].filter((c) => !c.matches(".lib-problems-err, .lib-problems-fix")).map((c) => c.textContent).join("")), w.line);
assert.equal(await li.locator(".lib-problems-err").textContent(), w.err);
const buttons = li.locator(".lib-problems-fix button");
assert.deepEqual(await buttons.allTextContents(), [w.use, w.keep]);
// a dot says it, not a coloured stripe down its side
assert.equal(await card.evaluate((c) => getComputedStyle(c).borderLeftWidth), "0px");
assert.equal(await li.evaluate((c) => getComputedStyle(c).borderLeftWidth), "0px");
const before = await scrolled(page);
await li.getByRole("button", { name: w[which], exact: true }).click();
await card.waitFor({ state: "detached" });
assert.deepEqual(posts, [[route, { name: "impeccable", agent: "claude" }]]);
await page.locator("#status").filter({ hasText: w[done] }).waitFor();
assert.equal(await scrolled(page), before, "the click scrolled the page");
await page.close();
});
}
await t.test(lang + ": a byte copy in another agent isn't said to differ", async () => {
const page = await open(lang, []);
const polish = page.locator("#view-library .lib-row").filter({ has: page.locator(".name", { hasText: /^polish$/ }) });
const audit = page.locator("#view-library .lib-row").filter({ has: page.locator(".name", { hasText: /^audit$/ }) });
await polish.waitFor();
assert.equal(await polish.locator(".lib-have > *").count(), 2, "Claude Code and Codex have it");
assert.equal(await polish.getByText(w.differs.replace("Gemini CLI", "Codex")).count(), 0);
assert.equal(await audit.getByText(w.differs).count(), 1);
await page.close();
});
}
assert.deepEqual(errors, []);
});
}