Files
magpie/internal/gui/tests/skill-update-feedback.test.cjs
T
yetone 75d0b9feac gui: an icon button at work shows the spinner, not its glyph turning
wiirhan on X (tweet 2123287273043378671): "资源库--技能--更新技能的loading
状态为啥是直接转箭头?" A Library skill's Update turned its own up arrow
while the fetch ran (.lib-icon.busy svg { animation: lib-spin }), so the
busy state looked like a broken arrow, not like work.

glyphBusy (app.js) puts the spinner's arc, CLI_SPIN, the one saving() and
a CLI's update pill turn, in place of the button's glyph while it works,
and puts the glyph back when it is done or fails. The arc turns at .8s,
and under prefers-reduced-motion it stands still.

Siblings: an agent row's Apply again and Restart (.ag-fix) turned their
reapply arrow the same way, and now take glyphBusy too. Kept as they are:
the refresh arrows that re-read data (quota-refresh, usage-refresh,
rt-read, #sync, pu-again). Their glyph is a turning arrow, so turning it
says what it does, and the owner tuned them in #16.

TestCoreScriptBudget: app and core budgets +228. glyphBusy is packed to
its shortest form, and renderAgents and the Library rows draw it on every
window, so there is no page to move it to.

skill-update-feedback.test.cjs waited for the svg itself to animate. It
now waits for the arc's path, with the row's actions still in view.

Run (mote, via mote-run):
- busy-glyph-spinner.test.cjs (new): chromium + webkit, en/zh/zh-TW/ja/de,
  1100px and 420px (reduced motion at 420). Green 22/22. Red 22/22 on
  origin/main f534245f1's assets. Restart's glyphBusy broken by hand:
  chromium 11/11 red.
- go test ./internal/gui: ok at the rebased head (budget included).
- Whole GUI suite at 59e0421f4, beside other sessions' runs (load 20-60):
  29713 tests, 28689 pass, 1024 fail in 122 files. One red was this
  change's: skill-update-feedback, fixed above. The other 121 files were
  run again at head 0f0827c28: 118 still red (2300 tests, 1021 fail). The
  same 118 files at origin/main f534245f1: 2254 tests, 1017 fail, the same
  files red. Subtest counts differ by one or two in account-cap,
  context-cap, desktop-tiers, menu-input-scroll, rest-try-now and
  tray-cell-click, both ways; none touches an icon button.
  provider-base-as-typed was red once at head and passes when rerun.
  Filed already: #6975 (most of the 118), #6782, #7016, #7097, #7131,
  #7132, #7101, #7100, #7242, #7033, #7083, #7046, #6234.

Not tried: the real app (Wails/WebKitGTK). The change is an svg swap with
a transform animation the spinner already uses there.
2026-11-20 03:04:12 +08:00

131 lines
8.1 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// zhexuanliuoutl1 on X: updating a skill from GitHub (hugohe3/ppt-master) said
// nothing while it ran. The row's Update button now shows the spinner until
// the fetch is done, and the toast says what came of it: updated, already up
// to date, or the error. In English and Chinese, in Chromium and WebKit. 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/lionel";
const REPO = "anthropics/skills";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills` });
const sk = (name, extra) => ({ name, description: name + " skill", kind: "github", source: `https://github.com/${REPO}/tree/HEAD/skills/${name}`, agents: ["claude"], ...extra });
const mine = (name) => ({ name, description: name + " of mine", kind: "folder", source: `${HOME}/skills/${name}`, agents: ["claude"] });
const lib = (st) => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [agent("claude", "Claude Code"), agent("codex", "Codex")],
instructions: { agents: [] }, servers: [], foundServers: [], projects: [], foundSkills: [], newSkills: [],
checkDue: false,
skills: [
sk("pdf", { edited: true, check: st.checked ? { name: "pdf", status: "update", commit: "c2", message: "pdf: forms" } : undefined }),
sk("docx", { check: st.checked ? { name: "docx", status: "update", commit: "c2", message: "docx: tables" } : undefined }),
sk("xlsx", { check: st.checked ? { name: "xlsx", status: "current", commit: "c1" } : undefined }),
...Array.from({ length: 10 }, (_, i) => mine("note-" + i)),
],
});
function server(lang, posts, st, hold) {
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(st) });
if (url.pathname.startsWith("/api/library/skills/")) {
const what = url.pathname.split("/").pop();
posts.push({ what, body: req.postDataJSON() });
if (what === "check") return route.fulfill({ json: { ...lib(st), result: { changed: [] } } });
await hold.promise;
const mode = st.modes.shift();
if (mode === "err") return route.fulfill({ status: 500, json: { error: "couldn't reach GitHub: connection reset" } });
return route.fulfill({ json: { ...lib(st), result: { changed: ["claude"], ...(mode === "current" ? { current: [req.postDataJSON().name] } : {}) } } });
}
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 });
};
}
// a mouse press where the button is: a dialog still coming in moves it, so
// the press waits for the dialog to stop, or it lands beside the button
const press = async (page, loc) => {
await page.waitForFunction(() => !document.getAnimations().some((a) => a.playState === "running" && a.effect?.target?.closest?.("#modal")));
const b = await loc.boundingBox();
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
};
// every scrolled box's offset, to tell a click moved none of them
const scrolls = (page) => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => (e.id || e.className) + ":" + e.scrollTop).concat("doc:" + document.scrollingElement.scrollTop).join(" "));
const words = {
en: { updated: "docx is updated", current: "docx is already up to date", err: "couldn't reach GitHub: connection reset" },
zh: { updated: "docx 已更新", current: "docx 已是最新", err: "couldn't reach GitHub: connection reset" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Update on a skill row spins while it runs and says what came of it", 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();
});
for (const lang of ["en", "zh"]) {
await t.test(lang, async () => {
const w = words[lang], posts = [], st = { modes: ["updated", "current", "err"] };
let release;
const hold = { promise: new Promise((r) => { release = r; }) };
const ctx = await browser.newContext({ viewport: { width: 860, height: 900 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, posts, st, hold));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const v = page.locator("#view-library");
const docx = v.locator(".lib-skill", { has: page.locator(".name", { hasText: /^docx/ }) });
await docx.waitFor();
const btn = docx.locator(".lib-rowacts button.lib-icon").first();
const status = async () => (await page.locator("#status").textContent()).trim();
await press(page, btn);
// held: the spinner's arc turns in place of the arrow (@wiirhan on X:
// the arrow itself went round), the row's actions stay in view
await page.waitForFunction(() => document.querySelector(".lib-skill .lib-rowacts.busy button.lib-icon.busy svg path")?.getAnimations().some((a) => a.playState === "running"));
await page.mouse.move(0, 0);
// (its fade-out, if it were going, is under .14s: a state, not a wait)
await page.waitForFunction(() => getComputedStyle(document.querySelector(".lib-rowacts.busy")).opacity === "1");
await page.waitForTimeout(400);
assert.equal(await docx.locator(".lib-rowacts").evaluate((e) => getComputedStyle(e).opacity), "1", "actions hidden while it runs");
release();
await page.waitForFunction((x) => document.querySelector("#status").textContent.trim() === x, w.updated);
assert.equal(await page.locator(".lib-icon.busy").count(), 0, "still busy after it ended");
await press(page, btn);
await page.waitForFunction((x) => document.querySelector("#status").textContent.trim() === x, w.current);
await press(page, btn);
await page.waitForFunction(() => document.querySelector("#status").classList.contains("err"));
assert.equal(await status(), w.err);
assert.equal(await page.locator(".lib-icon.busy").count(), 0, "still busy after the error");
assert.deepEqual(posts.map((p) => p.what), ["update", "update", "update"]);
await ctx.close();
});
}
assert.deepEqual(errors, []);
});
}