CHENGJIAHEGOXIS on X (v0.1.4178, Windows) couldn't install GoAnyAPI from Plugins: "agency-agents" failed with 从缓存复制到目标目录失败, and it was on no plugin's row, so nothing could remove it. Cause: every bun add/update/remove installs every dependency in plugins/package.json again, and a failed `bun add` writes its package there before exiting 1. agency-agents (a repository with no package.json) was left by such an add; on Windows a file of its copy in node_modules is held open, Bun fails "EBUSY: failed copying files from cache to destination for package agency-agents", and so every later install failed over a package nothing used. Fix (internal/plugin/leftover.go, store.go): - A package Bun says it couldn't install that no plugin is installed as (on the list, on or off, an add in flight, pi's agent) is taken out of package.json and node_modules and the command runs again: install() and runBun, so add, update, check and remove all get it. - A failed install puts back the dependencies and bun.lock it found. - An add whose own package went in while another listed plugin's failed succeeds; that plugin keeps its dependency. - Remove and add's clean-ups drop the dependency by hand when bun remove fails. - What is left from before is listed under Installed as "Not used by any plugin", each with a Remove (/api/plugins leftovers, POST /api/plugins/leftover; pmLeftovers in plugininstalled.js, imported when Plugins first draws), in every language. - plugins.json there and unreadable: nothing is a leftover. - Core script budget +51 for the one call left in plugins.js (reason in core_budget_test.go). Run: - mote-run: go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. go test ./internal/plugin (169s) and ./internal/provider (148s): ok. - mica-run go test -count=1 ./internal/gui with the leftovers drawing moved into plugininstalled.js: ok (133s); main since touches none of internal/gui's core scripts, internal/plugin or plugins.go. - win-run go test -run 'Leftover|FailedAdd|AnotherPlugin|RemoveTakes| BunFailed' ./internal/plugin on xiaomi-gpu: ok. - Reproduced the EBUSY with Bun 1.4.2 on xiaomi-gpu (a file in node_modules/agency-agents held open, then bun add another package). - Red on the old store.go: TestLeftoverDoesNotFailAnotherAdd, TestFailedAddLeavesNoDependency, TestAnotherPluginsFailureDoesNotFailAdd, TestRemoveTakesDependencyOutWhenBunFails. - GUI: plugin-leftover.test.cjs 42/42 (chromium + webkit, en zh zh-TW ja de, 980/420px, with and without a plugin); old plugins.js: 21/21 chromium red. - mote-run, rebased onfdf42299e: plugin-leftover + i18n-keys 46/46; every other plugin*.test.cjs, old-webkit and i18n-en-no-cjk: 255 ok, reds only in old-webkit (#6030, #5919), plugin-move-unserved (#4392), plugin-option-placement (#6559) and plugin-page-foreign-error (#6117), each red the same on a clean origin/mainfdf42299echeckout. Not run: the full go test ./... and the whole GUI suite (mote over its cores, mica running another session's full suite; one per machine); a real Windows install through the magpie app.
108 lines
5.8 KiB
JavaScript
108 lines
5.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// What a failed install left in plugins/ that no plugin is installed as is
|
|
// listed on Installed, each with a Remove (CHENGJIAHEGOXIS on X:
|
|
// agency-agents, left by a failed add, failed every install after it with
|
|
// "failed copying files from cache to destination", and nothing on the page
|
|
// named it). It shows with no plugin installed too, the empty state's case,
|
|
// and its Remove asks /api/plugins/leftover for that name.
|
|
// No backend here: the API is faked.
|
|
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/aimer";
|
|
const LEFT = "agency-agents";
|
|
const lib = {
|
|
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
|
agents: [], instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], servers: [],
|
|
};
|
|
|
|
function server(lang, state) {
|
|
return async (route) => {
|
|
const req = route.request();
|
|
const 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/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 === "/api/plugins/leftover" && req.method() === "POST") {
|
|
state.asked.push(JSON.parse(req.postData() || "{}"));
|
|
state.plugins.leftovers = [];
|
|
return route.fulfill({ json: state.plugins });
|
|
}
|
|
if (url.pathname === "/api/plugins") return route.fulfill({ json: state.plugins });
|
|
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: { head: "Not used by any plugin", remove: "Remove" },
|
|
zh: { head: "没有插件在用", remove: "移除" },
|
|
"zh-TW": { head: "沒有外掛在用", remove: "移除" },
|
|
ja: { head: "どのプラグインも使っていないもの", remove: "削除" },
|
|
de: { head: "Von keiner Erweiterung verwendet", remove: "Entfernen" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": what a failed install left is listed and removable", 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 Object.keys(words)) {
|
|
for (const width of [980, 420]) {
|
|
for (const installed of [false, true]) {
|
|
await t.test(`${lang} ${width}px ${installed ? "with a plugin" : "no plugin"}`, async () => {
|
|
const w = words[lang];
|
|
const state = {
|
|
asked: [],
|
|
plugins: {
|
|
plugins: installed ? [{ spec: "opencode-copilot-auth", providers: ["GitHub Copilot"], named: true, version: "0.1.0", moved: [] }] : [],
|
|
bun: true, bunVersion: "1.4.2", picker: false, mirror: false,
|
|
leftovers: [{ name: LEFT, spec: "github:msitarzewski/agency-agents" }],
|
|
},
|
|
};
|
|
const ctx = await browser.newContext({ viewport: { width, height: 800 } });
|
|
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.pluginTab", "installed"); } 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, state));
|
|
await page.goto("http://magpie.test/?view=plugins");
|
|
const v = page.locator("#view-plugins");
|
|
const sec = v.locator(".pm-leftovers");
|
|
await sec.waitFor();
|
|
assert.equal((await sec.locator("h3").innerText()).trim(), w.head);
|
|
const row = sec.locator(`[data-leftover="${LEFT}"]`);
|
|
assert((await row.innerText()).includes(LEFT), "the row names it");
|
|
const rm = row.locator("button");
|
|
assert.equal((await rm.innerText()).trim(), w.remove);
|
|
// the row fits the page: its Remove is on screen
|
|
const box = await rm.boundingBox();
|
|
assert(box && box.x >= 0 && box.x + box.width <= width, `Remove off screen at ${width}px: ${JSON.stringify(box)}`);
|
|
assert.equal(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), true, "no sideways scroll");
|
|
await rm.click();
|
|
await sec.waitFor({ state: "detached" });
|
|
assert.deepEqual(state.asked, [{ spec: LEFT }]);
|
|
await ctx.close();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|