library: updating a skill from GitHub spins its button and says updated, already up to date, or the error (zhexuanliuoutl1 on X)

A skill row's Update button only bobbed its arrow while the fetch ran, with the
row's actions hidden again as soon as the pointer left, and its toast said
"{name} is up to date" whether the update brought files or not.

- library.Result gets Current: UpdateSkill compares the skill's files, read
  whole (not from the stamp memo), before and after the update.
- The button's arrow spins (0.8s linear; a fade under reduced motion) and the
  row's actions stay in view until it ends. The toast says "{name} is
  updated" or "{name} is already up to date"; a failure is the error toast as
  before. No new labels on the row. Strings in zh, zh-TW, ja, de.

Run (WSL magpie-desktop, rebased on origin/main 31f75ddda):
- go test -tags nogui ./internal/library: ok. New TestUpdateSkillSaysWhenNothingChanged
  is red with Current never set (current [] twice), green with the change.
- go vet linux nogui, windows, darwin on internal/library: clean; gofmt -l clean.
- New GUI test skill-update-feedback (button spins while the reply is held,
  updated / already up to date / error toasts, en and zh): 3 of 3 in chromium
  and webkit; red (waitFor timeout) with the old single toast.
- GUI files the change reaches (skill-update-edited, gui-de/ja/zh-tw,
  i18n-keys, i18n-en-no-cjk): green in chromium and webkit.
- found-skill-pick-remove, inner-scroll-contain and library-loading are red
  the same on origin/main 961427f12 (#4097/#5013, #4689, #5997 are open).

Not run: go test of internal/gui (still going after 40 min on the shared WSL),
the whole GUI suite, a real GitHub update of hugohe3/ppt-master (no
network fetch in a sandbox HOME was tried).
This commit is contained in:
yetone
2026-11-11 17:28:53 +08:00
parent bee9a7200f
commit 772d502ffd
7 changed files with 186 additions and 6 deletions
@@ -615,7 +615,7 @@ magpie.plugin("library", (ctx) => {
}
const n = res.changed?.length || 0;
const out = given ? (res.changed || []).filter((id) => !given.includes(id)).length : 0;
if (done) status(done, "ok");
if (done) status(typeof done === "function" ? done(res) : done, "ok");
else if (out && out === n) status(n === 1 ? t("Removed from {agent}", { agent: nameOf(res.changed[0]) }) : t("Removed from {n} agents", { n }), "ok");
else if (out) status(t("{n} agents updated", { n }), "ok");
else if (n) status(n === 1 ? t("Written to {agent}", { agent: nameOf(res.changed[0]) }) : t("Written to {n} agents", { n }), "ok");
@@ -6871,9 +6871,14 @@ magpie.plugin("library", (ctx) => {
if (!gone && (s.kind === "github" || s.kind === "git" || s.origin)) {
const u = button("", "lib-icon", async (e, b) => {
if (s.edited) return confirmUpdateEdited(s);
// spinning, with the row's actions kept in view while the fetch
// runs; then what came of it: updated, nothing new, or the error
b.classList.add("busy");
await change("skills/update", { name: s.name }, t("{name} is up to date", { name: s.name }));
b.parentElement?.classList.add("busy");
await change("skills/update", { name: s.name }, (res) => res?.current?.includes(s.name)
? t("{name} is already up to date", { name: s.name }) : t("{name} is updated", { name: s.name }));
b.classList.remove("busy");
b.parentElement?.classList.remove("busy");
});
u.append(svg(GLYPH.up, 13, 1.5));
const gitRepo = gitRepoOf(s);
@@ -839,6 +839,8 @@ magpie.strings({
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "从 GitHub 获取 {name} 后你在本地改动过它。更新会用 GitHub 的版本替换它,你的版本会保存在 magpie 的备份里(资源库顶部的「备份」)。",
"Keep mine": "保留我的",
"{name} is up to date; your version is in the backups": "{name} 已是最新,你的版本已存入备份",
"{name} is already up to date": "{name} 已是最新",
"{name} is updated": "{name} 已更新",
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "已保留你改动过的:{names}。如要用 GitHub 的版本替换,请在各自的行里单独更新。",
"Update from GitHub ({repo}, as CC Switch installed it)": "从 GitHub 更新({repo},CC Switch 安装时的来源)",
"Read {name}'s SKILL.md": "查看 {name} 的 SKILL.md",
@@ -1808,6 +1810,8 @@ magpie.strings({
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "從 GitHub 取得 {name} 後你在本機改動過它。更新會用 GitHub 的版本取代它,你的版本會保存在 magpie 的備份裡(資源庫頂部的「備份」)。",
"Keep mine": "保留我的",
"{name} is up to date; your version is in the backups": "{name} 已是最新,你的版本已存入備份",
"{name} is already up to date": "{name} 已是最新",
"{name} is updated": "{name} 已更新",
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "已保留你改動過的:{names}。如要用 GitHub 的版本取代,請在各自的列中單獨更新。",
"Update from GitHub ({repo}, as CC Switch installed it)": "從 GitHub 更新({repo},CC Switch 安裝時的來源)",
"Read {name}'s SKILL.md": "檢視 {name} 的 SKILL.md",
@@ -2776,6 +2780,8 @@ magpie.strings({
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "{name} は GitHub から取得した後、ここで変更されています。更新すると GitHub の版に置き換わります。あなたの版は magpie のバックアップ(ライブラリ上部の「バックアップ」)に残ります。",
"Keep mine": "自分の版を残す",
"{name} is up to date; your version is in the backups": "{name} は最新です。あなたの版はバックアップにあります",
"{name} is already up to date": "{name} は最新のままです",
"{name} is updated": "{name} を更新しました",
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "変更済みのため残しました:{names}。変更を置き換えるには、それぞれの行から更新してください。",
"Update from GitHub ({repo}, as CC Switch installed it)": "GitHub からアップデート({repo}、CC Switch がインストールした取得元)",
"Read {name}'s SKILL.md": "{name} の SKILL.md を読む",
@@ -3745,6 +3751,8 @@ magpie.strings({
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "Du hast {name} hier geändert, seit er von GitHub geholt wurde. Das Update setzt die Version von GitHub an seine Stelle. Deine bleibt in den Backups von magpie (Backups, oben in der Bibliothek).",
"Keep mine": "Meine behalten",
"{name} is up to date; your version is in the backups": "{name} ist aktuell; deine Version liegt in den Backups",
"{name} is already up to date": "{name} ist bereits aktuell",
"{name} is updated": "{name} wurde aktualisiert",
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "Behalten, wie du sie geändert hast: {names}. Aktualisiere jeden in seiner Zeile, um deine Änderungen zu ersetzen.",
"Update from GitHub ({repo}, as CC Switch installed it)": "Von GitHub aktualisieren ({repo}, wie CC Switch es installiert hat)",
"Read {name}'s SKILL.md": "SKILL.md von {name} lesen",
@@ -407,8 +407,12 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
.lib-rowacts { display: flex; gap: 2px; flex: none; opacity: 0; transition: opacity .14s; }
.lib-row:hover .lib-rowacts, .lib-rowacts:focus-within { opacity: 1; }
.lib-icon { width: 26px; height: 26px; padding: 0; display: inline-grid; place-items: center; }
.lib-icon.busy svg { animation: lib-bob .8s var(--ease) infinite alternate; }
@keyframes lib-bob { to { transform: translateY(-2px); } }
.lib-rowacts.busy { opacity: 1; }
.lib-icon.busy, .lib-icon.busy:disabled { opacity: 1; color: var(--muted); }
.lib-icon.busy svg { animation: lib-spin .8s linear infinite; }
@keyframes lib-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .lib-icon.busy svg { animation: lib-pulse 1.2s ease infinite alternate; } }
@keyframes lib-pulse { to { opacity: .35; } }
/* the skill finder */
.lib-install { margin-bottom: 4px; }
@@ -0,0 +1,129 @@
// 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 spins 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 button turns, the row's actions stay in view
await page.waitForFunction(() => document.querySelector(".lib-skill .lib-rowacts.busy button.lib-icon.busy svg")?.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, []);
});
}
+19
View File
@@ -255,3 +255,22 @@ func TestEditStateUnknownForAnUnreadableCopy(t *testing.T) {
t.Fatalf("an unreadable copy's state: edited %v, known %v; want unknown", edited, known)
}
}
// An update of one skill says whether it brought anything: the GUI tells
// "updated" from "already up to date" by Current (zhexuanliuoutl1 on X).
func TestUpdateSkillSaysWhenNothingChanged(t *testing.T) {
sandbox(t)
version := "one"
fakeSkillTarball(t, &version)
ok(t)(InstallSkills("owner/current", []string{"skills/pdf"}, []string{"claude"}))
if res := ok(t)(UpdateSkill("pdf", false)); !slices.Equal(res.Current, []string{"pdf"}) {
t.Errorf("nothing new on GitHub: current %v", res.Current)
}
version = "two"
if res := ok(t)(UpdateSkill("pdf", false)); len(res.Current) != 0 {
t.Errorf("a changed skill is said to be current: %v", res.Current)
}
if res := ok(t)(UpdateSkill("pdf", false)); !slices.Equal(res.Current, []string{"pdf"}) {
t.Errorf("updated again: current %v", res.Current)
}
}
+14 -2
View File
@@ -1762,7 +1762,8 @@ func UpdateSkill(name string, replace bool) (*Result, error) {
if err != nil {
return nil, err
}
return change(func(l *Library) error {
same := false
res, err := change(func(l *Library) error {
targets := Targets()
if s := l.skill(name); s != nil && !replace {
// changed while it was fetched
@@ -1770,8 +1771,19 @@ func UpdateSkill(name string, replace bool) (*Result, error) {
return editedError(s)
}
}
return up.apply(l, targets)
// read whole, not from the memo: the files are compared, not their stamps
before, _, _, beforeOK := hashWalk(skillDir(name), leaveNothing, true)
if err := up.apply(l, targets); err != nil {
return err
}
after, _, _, afterOK := hashWalk(skillDir(name), leaveNothing, true)
same = beforeOK && afterOK && before == after
return nil
})
if err == nil && res != nil && same {
res.Current = []string{name}
}
return res, err
}
// UpdateSkills fetches again every skill that came from GitHub, each
+3
View File
@@ -24,6 +24,9 @@ type Result struct {
// fetched again and the ones that couldn't be (What is skill:<name>)
Updated []string `json:"updated,omitempty"`
Unupdated []Problem `json:"unupdated,omitempty"`
// Current is, for an update of one skill, that skill when what was
// fetched is the files it already had
Current []string `json:"current,omitempty"`
// Gone are, for an update of skills, the ones their sources no longer
// have: removed there, not failed (skill_gone.go)
Gone []string `json:"gone,omitempty"`