The owner asked for one market instead of three (magpie's community, other npm authors and repositories tagged magpie-plugin on GitHub) and approved the mockup: every plugin is the same card, its source said under its name, a strip picks the kind and a menu the source. The top is the week's picks: one a day from the community's most downloaded not installed yet, the most downloaded and the most starred. A search looks through every source at once, most used first. GitHub's slower answer shows a word that it is being asked, and a failed ask a quiet line with another go. The GUI tests that named the three sections now find the cards by source. plugin-manual-float picks Subscriptions so all 40 cards draw (Discover's shelves cap at 6). plugin-github waits for WebKit's wheel scroll to come to rest after reaching a card: it went on after the last wheel, and the scroll that was measured as the click's was its own (logged before, settled, open and closed: it moved before the click, never after). Run at 563b3dd92, the pushed head's tree (only messages changed since), on origin/main40fbec705: - mote: gofmt -l internal/gui empty; go vet ./internal/gui, GOOS=linux go vet -tags nogui, GOOS=windows go vet; go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok. go test ./internal/gui ./internal/plugin ok (TestCoreScriptBudget in it). - mote GUI, plugin*, old-webkit, market*, builtins, skill-edit, i18n*, gui-*, about*, agent-plugin* files: 1,283 ok, 50 not ok, in plugin-move-unserved (#4410), market-have (#5997), old-webkit's app.css :has() (#5919), gui-ja's {model} (#5943), plugin-signin-no-url (#5938), plugin-signed-out-account (#5998) and plugin-card-update once; each red the same alone at origin/main90f9f01a2, where plugin-card-update was red too. - Rebased onto459405960(c4da9a97d's title-bar drag in app.js and app.css among it): gofmt, go vet ./internal/gui and the Budget and Script tests of internal/gui again: ok. - Before the rebase (on783cd0f84): the whole GUI suite on magpie-desktop (WSL), its 132 red files again beside main: 95 red the same on main (#4600, commented), key-replace red 3 of 3 alone on main too; old-webkit's color-mix and plugin-github were this change's and are fixed; library-hooks, -items, -loading and -subagents red the same alone on main (#5997). Not tried: the real app; screenshots come from the GUI test pages.
150 lines
9.4 KiB
JavaScript
150 lines
9.4 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A plugin its author publishes from their own repository is listed in
|
|
// registry.json without "community": true (the owner on
|
|
// magpie-community/plugins#479). Discover browses it with the rest
|
|
// (yetone: 社区插件、非官方插件散落的太厉害了,你要把它统筹起来): in Agents,
|
|
// and alone under the Other authors origin. Browsed or found by a search,
|
|
// by its name or its publisher, it is under its publisher's name and never
|
|
// with the magpie community badge, on its card and on its page. PinK's listing is
|
|
// registry.json's before plugins#617. Every language, both engines, at a
|
|
// narrow width too; 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 PINK = "magpie-plugin-pink";
|
|
const RIVER = "@magpie-community/opencode-river-auth";
|
|
const KILO = "@magpie-community/agent-kilo";
|
|
// as /api/plugins/listings gives them: Listing's fields, community left out
|
|
// when false (omitempty), and no npm yet
|
|
const listings = () => [
|
|
{ package: RIVER, name: "River", providers: ["river"], community: true,
|
|
summary: { en: "River (river.ai) pay-as-you-go inference with your API key: per-account models from /v1/models, documented reasoning efforts and live prices from River's public pricing endpoint.", zh: "用你的 API key 接入 River (river.ai) 按量计费推理:按账号从 /v1/models 列出模型,带官方推理档位与实时价格。" } },
|
|
{ package: KILO, name: "Kilo Code", kind: "agent", community: true, summary: { en: "Kilo Code on magpie's Agents page.", zh: "把 Kilo Code 加到 Agent 页。" } },
|
|
{ package: PINK, name: "PinK", kind: "agent", icon: "https://raw.githubusercontent.com/YuchenWell/magpie-plugin-pink/main/assets/pink.png",
|
|
summary: { en: "Connect PinK to Magpie's models from the Agents page and track gateway usage and cost. Disconnecting restores the managed configuration.", zh: "在 Agent 页面连接 PinK,使用 Magpie 中配置的模型并查看调用用量与费用;断开时恢复插件管理的配置。" } },
|
|
];
|
|
const npm = {
|
|
[PINK]: { version: "0.1.1", publisher: "zhouzhenzhou", license: "MIT", weekly: 12 },
|
|
[RIVER]: { version: "0.1.3", publisher: "GitHub Actions", weekly: 40 },
|
|
[KILO]: { version: "0.1.0", weekly: 3 },
|
|
};
|
|
const state = { bun: true, bunVersion: "1.3.0", 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: listings() });
|
|
if (url.pathname === "/api/plugins/market") return json({ listings: listings(), state });
|
|
if (url.pathname === "/api/plugins/npm") {
|
|
const out = {};
|
|
for (const n of (url.searchParams.get("names") || "").split(",")) if (npm[n]) out[n] = npm[n];
|
|
return json({ npm: out });
|
|
}
|
|
// npm's own search has it too: still one card
|
|
if (url.pathname === "/api/plugins/search") return json({ hits: [{ package: PINK, version: "0.1.1", publisher: "zhouzhenzhou" }] });
|
|
if (url.pathname === "/api/plugins/github") return json({ repos: [] });
|
|
if (url.pathname === "/api/plugins/page") return json({ readme: "# PinK", updated: "2026-10-30T00:00:00Z" });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
if (url.hostname !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
|
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: "" }); }
|
|
};
|
|
}
|
|
|
|
const L = {
|
|
en: { agents: "Agents", community: "magpie community" },
|
|
zh: { agents: "Agent", community: "magpie 社区" },
|
|
"zh-TW": { agents: "Agent", community: "magpie 社群" },
|
|
ja: { agents: "エージェント", community: "magpie コミュニティ" },
|
|
de: { agents: "Agenten", community: "magpie-Community" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": an author's own listing is found by a search, under its publisher", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of Object.keys(L)) for (const width of [980, 420]) {
|
|
await t.test(lang + " " + width, async () => {
|
|
const w = L[lang];
|
|
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 card = (pkg) => view.locator(`.pm-card[data-pkg="${pkg}"]`);
|
|
const shot = (name) => process.env.ARTIFACT_DIR && view.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `plugin-authors-${name}-${engine}-${lang}-${width}.png`) });
|
|
|
|
// browsed: the community's agent and PinK in Agents, PinK under
|
|
// its publisher, after npm has answered too (a redraw)
|
|
const agents = view.locator(".pm-sec.pm-agents");
|
|
await agents.locator(".pm-sechead h3", { hasText: new RegExp("^" + w.agents + "$") }).waitFor();
|
|
await card(KILO).locator(".pm-ver").waitFor();
|
|
await card(RIVER).waitFor();
|
|
assert.equal(await agents.locator(`.pm-card[data-pkg="${PINK}"]`).count(), 1, "PinK is in Agents");
|
|
assert.equal(await card(PINK).locator(".pm-verified").count(), 0);
|
|
assert.equal((await card(PINK).locator(".pm-by").innerText()).trim(), "zhouzhenzhou");
|
|
// the Other authors origin: PinK alone
|
|
await view.locator(".pm-bar .pm-pop").first().click();
|
|
await page.locator(".proto-menu .pm-item", { hasText: await page.evaluate(() => t("Other authors")) }).click();
|
|
await page.locator(".proto-menu").waitFor({ state: "hidden" }).catch(() => {});
|
|
assert.deepEqual(await view.locator(".pm-sec[data-kind] .pm-card").evaluateAll((cs) => cs.map((c) => c.dataset.pkg)), [PINK]);
|
|
await view.locator(".pm-bar .pm-pop").first().click();
|
|
await page.locator(".proto-menu .pm-item").first().click();
|
|
await page.locator(".proto-menu").waitFor({ state: "hidden" }).catch(() => {});
|
|
assert.equal(await card(RIVER).locator(".pm-verified").count(), 1);
|
|
assert.equal((await card(RIVER).locator(".pm-verified").innerText()).trim(), w.community);
|
|
await shot("browse");
|
|
|
|
// searched by its name: its card once, by its publisher, no badge
|
|
const q = view.locator(".pm-find input");
|
|
await q.fill("pink");
|
|
await card(PINK).waitFor();
|
|
await card(PINK).locator(".pm-ver").waitFor();
|
|
assert.equal(await card(PINK).count(), 1, "the listing and npm's hit are one card");
|
|
assert.equal(await card(PINK).locator(".pm-verified").count(), 0);
|
|
assert.equal((await card(PINK).locator(".pm-by").innerText()).trim(), "zhouzhenzhou");
|
|
assert.doesNotMatch(await card(PINK).innerText(), new RegExp(w.community));
|
|
assert.equal(await card(RIVER).count(), 0);
|
|
await shot("search");
|
|
|
|
// the search cleared: browsed again, PinK with them
|
|
await q.fill("");
|
|
await card(KILO).waitFor();
|
|
assert.equal(await card(PINK).count(), 1);
|
|
|
|
// found by its publisher's name too
|
|
await q.fill("zhouzhen");
|
|
await card(PINK).waitFor();
|
|
|
|
// its page says the same: publisher · package, never the badge
|
|
await card(PINK).locator(".pm-sum").click();
|
|
const dlg = page.locator("#modal .pm-detail");
|
|
await dlg.waitFor();
|
|
assert.equal((await dlg.locator(".pm-dhead .pm-by").innerText()).trim(), "zhouzhenzhou · " + PINK);
|
|
assert.doesNotMatch(await dlg.locator(".pm-dhead").innerText(), new RegExp(w.community));
|
|
const over = await page.evaluate(() => document.scrollingElement.scrollWidth - document.scrollingElement.clientWidth);
|
|
assert.ok(over <= 0, "page scrolls sideways by " + over);
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
});
|
|
}
|
|
});
|
|
}
|