BeiWeiji on X (v0.1.4322, zh): a skill imported from "Agent 中已有"
had no way back, only off or Remove, and removed it was gone from the
agents and from "Agent 中已有" too: Remove sent the folder that had been
moved into the library to magpie's backups and took the agents' links
and marked copies away.
ImportSkill now records where the skill was (Skill.Home, this
computer's own; Put keeps it for the same source, a sync never carries
it): the folder moved in (Home.Dir; handOver points it at the shared
~/.agents/skills place) and each agent's entry, a link with its own
text or a byte copy. RemoveSkill/RemoveSkills put it back (putBack):
the library's folder moves back to Home.Dir with what was changed in
the library, or the library's link goes; each agent's link is made
again as it was and each copy copied back. It is in "In your agents"
again and nothing goes to the backups. An entry the user replaced since
is left alone; when Home.Dir is taken the skill is removed as before,
its folder to the backups. This covers every agent with a skills folder
(the record is per agent entry, links and copies alike).
The page: SkillView.back lists those agents, and such a row has Put
back in the trash's place ("放回 {agents}"), whose sheet says where it
goes and sends skills/remove. Other skills keep the trash.
Old imports: a skill brought in before this has no Home record.
Removed, its folder goes to magpie's backups as before, where it can
be moved back by hand (the reporter's already-removed skill is there).
Run (at this change on acc358f07, then rebased on a75a1fffc and on
d67ccbd3c; the commits between touch no library code):
- go test -tags nogui ./internal/library ./internal/gui on mote at
this head (d67ccbd3c base): ok; go build ./...: ok.
- Full go test -timeout 45m ./... on mica at the acc358f07 base: exit 0,
every package ok. Not run again after the rebases.
- GOOS=windows go vet and GOOS=linux go vet -tags nogui: ok (whole tree
at acc358f07; internal/library and internal/gui at this head).
- gofmt -l internal/: clean.
- GUI: skill-put-back.test.cjs (new) in chromium and webkit, en, zh,
zh-TW, ja, de at 980px and 400px: ok; remove-found-skill ok;
i18n-keys: only #6877 (", with an image"), red the same at a fresh
origin/main copy.
- Whole GUI suite (make test-ui) on mica at the acc358f07 base, beside
another session's suite (load to 200): 28548 tests, 1060 red in 128
files. Each red file was run at a fresh origin/main a75a1fffc copy:
118 files (1039 tests) red there too, filed as #6975 (108 already in
#6934, the rest with their own issues). The other 10 (editor-advanced-
align, group-new-head, ledger-swipe, library-problems-hide,
nav-sub-fold, routing-pulse-composited, search-mcp-library,
signin-closes-sheet, readable-focus, library-env) pass at this change
run alone on mote, 150 of 150.
Broken by hand: canPutBack forced false; TestRemoveSkills,
TestRemovedImportGoesBackToTheAgents and TestRemovedLinkedImportGoesBack
went red (TestPutBackLeavesTheUsersNewFolder guards the fallback and
passes either way).
Not tried: a real magpie with real agents (tests run in a sandbox
HOME); Windows junctions and WSL-distro links (a WSL distro agent's own
entry is recorded like any other but not tried there); the link tests are skipped on Windows.
133 lines
8.2 KiB
JavaScript
133 lines
8.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// BeiWeiji on X: a skill brought into the library from "In your agents"
|
|
// had no way back, only off or Remove, and removed it was gone from the
|
|
// agents too. A skill brought in from the agents (back: the agents it came
|
|
// from) has Put back in their place of the trash: its sheet says where it
|
|
// goes, the button sends skills/remove (which gives it back to them as
|
|
// they had it), and it is under "In your agents" again. A skill from
|
|
// anywhere else keeps its trash. In every language, in Chromium and
|
|
// WebKit, wide and narrow. 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/bei";
|
|
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills` });
|
|
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: [], newSkills: [],
|
|
checkDue: false,
|
|
skills: [
|
|
...st.back ? [] : [{ name: "notes", description: "My notes", agents: ["claude", "codex"], back: ["claude", "codex"] }],
|
|
{ name: "pdf", description: "Read PDFs", kind: "github", source: "https://github.com/a/b/tree/main/pdf", agents: ["claude"] },
|
|
],
|
|
foundSkills: st.back ? [{ name: "notes", description: "My notes", agents: ["claude", "codex"] }] : [],
|
|
});
|
|
|
|
function server(lang, posts, st) {
|
|
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(), body = req.postDataJSON();
|
|
posts.push({ what, body });
|
|
if (what === "remove") st.back = true;
|
|
return route.fulfill({ json: { ...lib(st), result: { changed: ["claude", "codex"] } } });
|
|
}
|
|
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: { title: "Put back in Claude Code, Codex", head: "Put notes back?", go: "Put it back", in: "In your agents",
|
|
text: "It leaves the library and goes back to Claude Code, Codex as it was before you brought it in.", done: "notes went back to Claude Code, Codex" },
|
|
zh: { title: "放回 Claude Code, Codex", head: "把 notes 放回?", go: "放回", in: "Agent 中已有",
|
|
text: "它会离开资源库,按导入前的样子放回 Claude Code, Codex。", done: "notes 已放回 Claude Code, Codex" },
|
|
"zh-TW": { title: "放回 Claude Code, Codex", head: "把 notes 放回?", go: "放回",
|
|
text: "它會離開資源庫,依匯入前的樣子放回 Claude Code, Codex。", done: "notes 已放回 Claude Code, Codex" },
|
|
ja: { title: "Claude Code, Codex に戻す", head: "notes を戻しますか?", go: "戻す",
|
|
text: "ライブラリから外れ、取り込む前の状態で Claude Code, Codex に戻ります。", done: "notes を Claude Code, Codex に戻しました" },
|
|
de: { title: "Zurück zu Claude Code, Codex", head: "notes zurückgeben?", go: "Zurückgeben",
|
|
text: "Er verlässt die Bibliothek und kommt so zu Claude Code, Codex zurück, wie er vor dem Übernehmen war.", done: "notes ist wieder in Claude Code, Codex" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a skill brought in from the agents is put back", 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 width of [980, 400]) for (const lang of Object.keys(words)) {
|
|
await t.test(`${lang} at ${width}px`, async () => {
|
|
const w = words[lang], posts = [], st = { back: false };
|
|
const ctx = await browser.newContext({ viewport: { width, 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));
|
|
await page.goto("http://magpie.test/");
|
|
await page.locator('button[data-view="library"]').click();
|
|
const v = page.locator("#view-library");
|
|
const row = (n) => v.locator(".lib-skill", { has: page.locator(".name", { hasText: new RegExp("^" + n) }) });
|
|
await row("notes").waitFor();
|
|
|
|
// the one from the agents: Put back, not a trash; the other keeps its trash
|
|
const pb = row("notes").locator("button.lib-putback");
|
|
assert.equal(await pb.getAttribute("title"), w.title);
|
|
assert.equal(await row("notes").locator("button.lib-icon.danger").count(), 0);
|
|
assert.equal(await row("pdf").locator("button.lib-putback").count(), 0);
|
|
assert.equal(await row("pdf").locator("button.lib-icon.danger").count(), 1);
|
|
const rb = await row("notes").boundingBox(), bb = await pb.boundingBox();
|
|
assert(bb && bb.width >= 16 && bb.x + bb.width <= rb.x + rb.width + 0.5, `Put back sticks out of its row at ${width}px`);
|
|
|
|
// its sheet says where it goes; Cancel sends nothing
|
|
await pb.click();
|
|
const ed = page.locator(".lib-putback-sheet");
|
|
await ed.waitFor();
|
|
assert.equal((await ed.locator(".ehead b").textContent()).trim(), w.head);
|
|
assert.equal((await ed.locator(".lib-confirm").textContent()).trim(), w.text);
|
|
await ed.locator(".bar button:not(.primary)").click();
|
|
await ed.waitFor({ state: "detached" });
|
|
assert.deepEqual(posts, []);
|
|
|
|
await pb.click();
|
|
await ed.waitFor();
|
|
const go = ed.locator(".bar button.primary");
|
|
assert.equal((await go.textContent()).trim(), w.go);
|
|
await go.click();
|
|
await ed.waitFor({ state: "detached" });
|
|
assert.deepEqual(posts, [{ what: "remove", body: { name: "notes" } }]);
|
|
await row("notes").waitFor({ state: "detached" });
|
|
assert.equal((await page.locator("#status").textContent()).trim(), w.done);
|
|
// and it is in the agents' list again
|
|
const found = v.locator(".lib-foundhead");
|
|
await found.waitFor();
|
|
if (w.in) assert.equal((await found.locator(".label").textContent()).trim(), w.in);
|
|
assert.equal(await v.locator(".lib-row .name", { hasText: /^notes$/ }).count(), 1);
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth), true, "no sideways scroll");
|
|
await ctx.close();
|
|
});
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|