Files
magpie/internal/gui/tests/skill-install-link.test.cjs
T
yetone dc098c1e82 library: a skill from a folder follows GitHub once installed from there (biubiu8802 on X)
biubiu8802 (X, 2119602075864903924) downloaded a skill from GitHub and
put it in the Library from its folder, so it had nothing to update from
and no way to link it to GitHub. Installing it from its GitHub link now
links the two, the way an update of a CC Switch skill already does: the
library's skill by that name takes GitHub's files and GitHub as its
source. A check and an update cover it from then on, and the agents'
links keep pointing at it. When its own files aren't GitHub's, they go to
the backups like UpdateSkill's replace does, and the result says so. A
folder of the user's it was linked to stays as it is.

followsHere (skill_link.go) decides it. It links only a skill with no
remote source that wasn't renamed and is that skill: it traces to this
repository (CC Switch, the skills CLI's lock, a git checkout, From), or
it traces nowhere and its SKILL.md has the same description as GitHub's,
as an older download of it does. One traced to another repository, or
an untraced one that describes something else (mora1n's case,
TestInstallSetPutsAnotherByTheSameNameBeside), still goes in beside it
(skill_beside.go). A had skill with
the same files and no source is bound to the GitHub source it was found
in, so a later install of another repository's skill by that name goes
beside it, not over it (TestSameFilesByNameAreHad).

The probe marks such a candidate links:true. The GUI's Add list tags it
"links to GitHub" with a tooltip, and the report names "updates from
GitHub now" and "files of their own kept with the backups". The TUI's
probe list and result line say the same. The new strings are in zh,
zh-TW, ja and de.

Run on mote (macOS), on 64ecd0f69, then rebased on 8a58c0e30, whose
new commits touch none of internal/library, the TUI's library or the
library page:
- gofmt -l clean; go vet ./..., GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=linux go build -tags nogui
  ./..., GOOS=windows go build ./... all ok
- go test ./internal/library/... ok at this tree; ./internal/tui/...,
  ./internal/cli/... and ./internal/gui/ ok at the tree before the
  description check (that change touches internal/library only)
- GUI (chromium + webkit, 5 languages, wide and narrow):
  skill-install-link (new), skill-install-beside, skill-install-skip,
  skill-install-agents-all, skill-git-source, skill-too-big,
  provider-discovery, i18n-en-no-cjk pass. i18n-keys' "a plugin's words
  are its own" is red on main for three strings this change doesn't
  touch, already filed: #5332/#5327 ("View routing"), #5482 ("Use the
  library's"), #5426 ("No session ID").

Broken by hand: without the description check (the first version),
TestInstallSetPutsAnotherByTheSameNameBeside is red (caveman taken over).
followsHere returning false always turns
TestFolderSkillFollowsGitHub red (probed As:pdf-pro-biubiu) and
TestOwnSkillFollowsGitHubKeepsItsFiles red (linked [] kept []).

Not run: the full go test ./... suite. mote's suite lock had a queue
waiting up to 16h, so this change ran the packages it touches.
No real GitHub install either: the tests use a fake tarball server. Not
tried on Windows or Linux. The market's had-check (haveSkill) is
unchanged: a market skill with a folder copy by that name still counts
as had.
2026-11-09 11:29:51 +08:00

111 lines
7.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// biubiu8802 on X: a skill downloaded from GitHub and added to the library
// from its folder couldn't follow GitHub. Installing it from GitHub links
// the library's to it (skill_link.go): the list of what the repository has
// says so before the click, "links to GitHub", with what happens in its
// title, the skill is picked for you, and after the install the status
// says it updates from GitHub now and its own files went to the backups.
// Every language, 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/biubiu";
const probe = {
source: "biubiu/skills", kind: "github", candidates: [
{ path: "skills/pdf-pro", name: "pdf-pro", description: "PDFs, v2", have: false, links: true },
],
};
const lib = () => ({
dir: `${HOME}/.config/magpie/library`, backups: `${HOME}/.config/magpie/backups`, home: HOME,
agents: [{ id: "claude", name: "Claude Code", icon: "", skills: `${HOME}/.claude/skills` }],
instructions: { agents: [] }, servers: [], skills: [], foundServers: [], projects: [], foundSkills: [],
});
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() });
if (url.pathname === "/api/library/skills/probe") return route.fulfill({ json: probe });
if (url.pathname === "/api/library/skills/install") {
posts.push(req.postDataJSON().paths);
return route.fulfill({ json: { ...lib(), result: { changed: ["claude"], problems: [], installed: [], had: [], skipped: [], linked: ["pdf-pro"], linkedKept: ["pdf-pro"] } } });
}
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: { tag: "links to GitHub", why: "The library's pdf-pro came from a folder. This one takes its place and it updates from GitHub from then on; files of its own that differ are kept with the backups.", done: "updates from GitHub now: pdf-pro · files of their own kept with the backups: pdf-pro" },
zh: { tag: "链接到 GitHub", why: "资源库里的 pdf-pro 来自一个文件夹。这个会取代它,之后它从 GitHub 更新;与此不同的原有文件会保留在备份里。", done: "现在从 GitHub 更新:pdf-pro · 原有文件已保留在备份里:pdf-pro" },
"zh-TW": { tag: "連結到 GitHub", why: "資源庫裡的 pdf-pro 來自一個資料夾。這個會取代它,之後它從 GitHub 更新;與此不同的原有檔案會保留在備份裡。", done: "現在從 GitHub 更新:pdf-pro · 原有檔案已保留在備份裡:pdf-pro" },
ja: { tag: "GitHub にリンク", why: "ライブラリの pdf-pro はフォルダから追加されたものです。これがその代わりになり、以後は GitHub から更新されます。異なる元のファイルはバックアップに保存されます。", done: "今後は GitHub から更新:pdf-pro · 元のファイルはバックアップに保存:pdf-pro" },
de: { tag: "mit GitHub verknüpfen", why: "pdf-pro in der Bibliothek stammt aus einem Ordner. Dieser Skill tritt an seine Stelle und wird ab dann von GitHub aktualisiert; abweichende eigene Dateien bleiben in den Backups.", done: "wird jetzt von GitHub aktualisiert: pdf-pro · eigene Dateien in den Backups behalten: pdf-pro" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a skill the library has from a folder is linked to GitHub by installing it from there", 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 run = async (lang, width) => {
const posts = [];
const ctx = await browser.newContext({ viewport: { width, height: 800 } });
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));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const src = page.locator('#view-library input[data-lib="source"]');
await src.fill("biubiu/skills");
await src.press("Enter");
const row = page.locator("#view-library .lib-pick");
await row.first().waitFor();
const w = words[lang];
const tag = row.locator(".lib-tag");
assert.equal((await tag.textContent()).trim(), w.tag);
assert.equal(await tag.getAttribute("title"), w.why);
const fit = await row.evaluate((r) => {
const b = r.querySelector(".lib-tag").getBoundingClientRect(), box = r.getBoundingClientRect();
return { inside: b.right <= box.right + 0.5, over: r.closest(".lib-picks").scrollWidth - r.closest(".lib-picks").clientWidth };
});
assert.equal(fit.inside, true, "the tag stays in its row");
assert.equal(fit.over, 0, "the list doesn't scroll sideways");
assert.equal(await row.locator("input").isChecked(), true, "picked for you");
await page.locator("#view-library .lib-probefoot button.primary").click();
await page.waitForTimeout(300);
assert.deepEqual(posts, [["skills/pdf-pro"]]);
const status = page.locator("#status");
assert.equal((await status.textContent()).trim(), w.done);
await ctx.close();
};
for (const lang of Object.keys(words)) {
await t.test(lang + ", wide", () => run(lang, 980));
await t.test(lang + ", narrow", () => run(lang, 420));
}
assert.deepEqual(errors, []);
});
}