A plugin installed from git whose package.json says
"magpie": { "name": "华为云 HUAWEI" } read as its dependency key
(magpie-officeace) on Settings → Plugins. Bun takes no non-ASCII key, so
a package outside the community's list had no way to show a readable
name. magpie.name was never read at all: #3608's route (MYCF711's branch
1cc33700) didn't reach main, so no release has it, git or npm.
plugin.InstalledName reads magpie.name from the installed package's own
package.json, beside magpie.icon (installedOwn, one parse for both): one
line of at most 80 bytes, no control or format characters (a bidi
override would show it as another name), else nothing. /api/plugins gives
each row it as ownName, and plugins.js's shownName takes it after the
community list's name and before the git package or the spec, so a
listed package is still named by the list. The row's page, the "is up to
date" status and every message that names the row (options, prefer, Update
all) go through shownName; a page plugin's sidebar tab takes it when the
page names no title (windowParts). It is never used to resolve a name and
never shown with the community badge. Not changed: the CLI's plugin list
(the dependency key, as the reporter expects), Discover's cards for
uninstalled GitHub/npm packages, and magpie.summary. Documented in
docs/reference.md and site/public/docs (en, zh, ja).
Run:
- mote: go test -timeout 45m ./internal/plugin/ ./internal/gui/ — plugin
ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
the AppKit window tests killed at their deadline (TestPanelCloseHidesIt,
TestPluginPageLoadsItsFilesInTheWindow, TestMainWindowCorners, …;
#4125, #2645). The first three run the same red on origin/main 7aa67e9e5.
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
internal/plugin and internal/gui: clean. gofmt -l internal/: nothing.
- wsl-run (magpie-desktop): plugin-own-name.test.cjs, Chromium and
WebKit, en/zh/zh-TW/ja/de at 980 and 420: 22/22. Every plugin*,
plugins-*, agent-plugin*, account-plugin*, signin-paste-plugin,
sidebar* and i18n-keys file (67): all green but i18n-keys "a plugin's words are its own" (#4524), plugin-card-update webkit en/zh (#3079) and plugin-github-filter webkit ja 420px (#4564, filed now), each red the same at origin/main 7aa67e9e5
- Rebased on origin/main 7b883cc61, mote: -run "Budget|OwnName|TestPluginsState|
TestWindowParts" on internal/gui and internal/plugin: ok (core scripts
under the budget, no raise).
Broken by hand:
- InstalledName returning "": TestPluginsStateGivesAGitPackagesOwnName red
(ownName "", and the sidebar title magpie-officeace).
- shownName without e.ownName: plugin-own-name.test.cjs red, the row
reads 'magpie-officeace'.
Not tried: the desktop window itself, and a real git repository with
magpie.name (the fixture is shaped from the reporter's installed
package.json: name magpie-officeace, version 0.2.4).
84 lines
5.8 KiB
JavaScript
84 lines
5.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// #4558 (MYCF711): a plugin installed from git whose package.json gives
|
|
// itself a name in magpie.name ("华为云 HUAWEI") read as its dependency key
|
|
// (magpie-officeace) on Installed. Bun takes no non-ASCII key, so the
|
|
// package's own name is the only readable one it has. Its row and its page
|
|
// say that name, with the package beside it on the page; a git one that
|
|
// gives none still says its package; a package the community's list names
|
|
// is still named by the list, whatever its package.json says. Every
|
|
// language, both engines, wide and narrow; 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 OFFICE = "github:example/magpie-officeace", LOOMY = "github:example/magpie-loomy-auth", LISTED = "@magpie-community/opencode-qoder-auth";
|
|
const state = { bun: true, bunVersion: "1.3.0", picker: false, movable: [], plugins: [
|
|
{ spec: OFFICE, package: "magpie-officeace", ownName: "华为云 HUAWEI", version: "0.2.4", commit: "c594984", head: "c594984", providers: [], moved: [] },
|
|
{ spec: LOOMY, package: "magpie-loomy-auth", version: "0.1.0", commit: "8fd2d9a", head: "8fd2d9a", providers: [], moved: [] },
|
|
{ spec: LISTED, ownName: "Not the list's", version: "0.3.0", providers: [], moved: [] },
|
|
] };
|
|
const listings = [{ package: LISTED, name: "Qoder", summary: "Qoder's plan", providers: ["qoder"], community: true, github: { owner: "magpie-community", repo: "plugins" } }];
|
|
|
|
function server(lang) {
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
|
if (url.pathname === "/api/plugins") return json(state);
|
|
if (url.pathname === "/api/plugins/listings") return json({ listings });
|
|
if (url.pathname === "/api/plugins/market") return json({ listings, state });
|
|
if (url.pathname === "/api/plugins/search") return json({ hits: [] });
|
|
if (url.pathname === "/api/plugins/updates") return json({ waiting: [], updated: [] });
|
|
if (url.pathname === "/api/plugins/git") return json({ heads: { [OFFICE]: "c594984", [LOOMY]: "8fd2d9a" } });
|
|
if (url.pathname === "/api/plugins/page") return json({ readme: "# magpie-officeace", updated: "2026-10-01T10:00:00Z" });
|
|
if (url.pathname.startsWith("/api/")) return 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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a git plugin's row says the name its package.json gives", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [980, 420]) {
|
|
await t.test(lang + " " + width, async () => {
|
|
const page = await (await browser.newContext({ viewport: { width, height: 820 } })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang));
|
|
await page.goto("http://magpie.test/?view=plugins");
|
|
const view = page.locator("#view-plugins");
|
|
const installed = await page.evaluate((l) => l === "en" ? "Installed" : I18N[l]["Installed"], lang);
|
|
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: installed }).click();
|
|
await view.locator(".pm-row").nth(2).waitFor();
|
|
const names = await view.locator(".pm-row .name > span:first-child").allTextContents();
|
|
assert.deepEqual([...names].sort(), ["Qoder", "magpie-loomy-auth", "华为云 HUAWEI"].sort(), "the package's own name, the package where it gives none, the list's where it lists one");
|
|
const row = view.locator(".pm-row").filter({ has: page.locator(".name", { hasText: "华为云 HUAWEI" }) });
|
|
const box = await row.boundingBox();
|
|
assert.ok(box.x >= 0 && box.x + box.width <= width, `the row fits: ${JSON.stringify(box)}`);
|
|
|
|
// its page says it too, with the repository it came from
|
|
await row.locator(".name").click();
|
|
const dlg = page.locator("#modal .pm-detail");
|
|
await dlg.waitFor();
|
|
assert.equal(await dlg.locator(".pm-dhead .pm-name b").textContent(), "华为云 HUAWEI");
|
|
assert.ok((await dlg.locator(".pm-dhead .pm-by").textContent()).includes(OFFICE), "the page names where it came from");
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
});
|
|
}
|
|
});
|
|
}
|