plugins: "More in Plugins" opens Discover, not the tab visited last (outloudvi on Discord)

On Providers, 「插件里还有更多」 / "More in Plugins" opened whichever
Plugins tab was visited last (Built-in, Installed). pluginQuery("")
returned early when the query was already empty, before it set the
tab to Discover. The early return is gone, so an empty query also
switches to Discover; a non-empty one already did.

plugins-more-discover.test.cjs visits Built-in, then Installed, in en
and zh, goes back to Providers and clicks the add sheet's More in
Plugins tile, expecting Discover with its cards and no Built-in list;
then the "look for a plugin" link with a search, expecting Discover
with that search.

Run:
- plugins-more-discover.test.cjs, chromium and webkit: 3 of 3 green.
- 61 GUI files the change can reach (plugin-*, plugins-*, builtins,
  deprecat*, add-sheet*, provider-search*, i18n-keys, nav-sub-unroll,
  mobile-web, market-have, sidebar-tab-top), both engines: 412 pass,
  1 fail each: builtins.test.cjs's sidebar list lacks the masking
  tab, red the same with the old plugins.js (#3498).
- go test ./internal/gui/ -count=1 (budgets included): ok but
  TestMainWindowCorners/macOS_15_SDK killed at load ~200 (#1936,
  #2645); alone it passes.
- At the rebased head (b28e5ffd8): the new test and i18n-keys green in
  both engines, go test -run Budget ok.
- No bytes added: core and app script budgets untouched.

Broken by hand: with the early return put back, the new test is red
in both engines (expected Discover, got Built-in; expected 发现, got
内置).

Not tried: the tray panel's link, which opens the main window through
window/main?view=plugins and still shows the last tab (#3579, a
sibling); the full Go suite (no suite-lock.sh on this machine).
This commit is contained in:
yetone
2026-10-25 16:00:21 +08:00
parent b28e5ffd81
commit 894ec96036
3 changed files with 112 additions and 1 deletions
-1
View File
@@ -250,7 +250,6 @@
window.pluginTabTo = (id) => { tab = id; };
// pluginQuery: Discover, looking for q (the add sheet found nothing by it)
window.pluginQuery = (q) => {
if (q === query && !q) return;
query = q;
tab = "discover";
clearTimeout(searchTimer);
+5
View File
@@ -339,6 +339,11 @@ why one didn't load, updates one and removes one. The add sheet's
"look for a plugin" link lead there. English and Chinese, Chromium and WebKit,
with the API faked.
`plugins-more-discover.test.cjs` checks that the add sheet's "More in
Plugins" row and its "look for a plugin" link open Plugins on Discover,
after Built-in or Installed was the tab open last (outloudvi on Discord).
English and Chinese, Chromium and WebKit, with the API faked.
`plugin-git.test.cjs` checks a plugin installed from a git repository: the
market's field says it takes a GitHub repo, and Install sends
`github:owner/repo` as typed; Installed names it by the package its
@@ -0,0 +1,107 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The add sheet's More in Plugins always opens Plugins on Discover, where
// the subscriptions' plugins are, whichever tab of Plugins was open last:
// after Built-in it opened Built-in (outloudvi on Discord). Its search's
// "look for a plugin" too. English and Chinese; 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 listings = [
{ package: "@magpie-community/opencode-zed-auth", name: "Zed", icon: "zed", providers: ["zed"], community: true,
summary: { en: "Your Zed plan.", zh: "你的 Zed 订阅。" }, npm: { version: "0.1.0", weekly: 120 } },
];
function server(lang, fetched) {
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: [{ id: "openai", name: "OpenAI", icon: "openai", preset: "openai", models: [], agents: [], key: { set: true, masked: "sk-…ab12" } }],
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({ bun: true, bunVersion: "1.3.0", plugins: [] });
if (url.pathname === "/api/plugins/listings") return json({ listings });
if (url.pathname === "/api/plugins/market") return json({ listings, state: { bun: true, plugins: [] } });
if (url.pathname === "/api/plugins/search") return json({ hits: [] });
if (url.pathname === "/api/plugins/builtin") return json([{ id: "usage", name: "Usage", sub: "Your allowances", on: true, chosen: true, source: "preset", state: "active", inUse: 0 }]);
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") { fetched.push(url.href); 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: { builtin: "Built-in", discover: "Discover", installed: "Installed", lookFor: "look for a plugin" },
zh: { builtin: "内置", discover: "发现", installed: "已安装", lookFor: "找找插件" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": More in Plugins opens Discover", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of ["en", "zh"]) {
await t.test(lang, async () => {
const w = L[lang];
const page = await (await browser.newContext({ viewport: { width: 980, height: 820 } })).newPage();
page.setDefaultTimeout(5000);
const errors = [], fetched = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, fetched));
const view = page.locator("#view-plugins");
const tabOn = () => view.locator(".lib-tabs .opt[aria-pressed=true]").innerText();
const pick = (name) => page.locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: name }).first().click();
const toProviders = async () => {
await page.locator('#nav button[data-view="providers"]').click();
await page.locator("#view-providers").waitFor({ state: "visible" });
// the add sheet, open still from the last search or opened now,
// with nothing looked for
if (!await page.locator("#addSheet input.find").isVisible()) await page.locator("#addProvider").click();
await page.locator("#addSheet input.find").fill("");
};
const expectDiscover = async (why, q = "") => {
await view.waitFor({ state: "visible" });
await page.waitForFunction(() => document.querySelector("#view-plugins .lib-tabs .opt[aria-pressed=true]"));
assert.equal((await tabOn()).trim(), w.discover, why);
assert.equal(await view.locator(".pm-find input").inputValue(), q, why);
if (!q) await view.locator('.pm-card[data-pkg="@magpie-community/opencode-zed-auth"]').waitFor();
assert.equal(await view.locator("#builtinList").count(), 0, why);
};
await page.goto("http://magpie.test/?view=plugins");
for (const [last, name] of [["builtin", w.builtin], ["installed", w.installed]]) {
// a tab of Plugins other than Discover, then back to Providers
await view.locator(".lib-tabs").waitFor();
await pick(name);
await page.waitForFunction((n) => document.querySelector("#view-plugins .lib-tabs .opt[aria-pressed=true]")?.textContent.startsWith(n), name);
if (last === "builtin") await view.locator("#builtinList .row, #builtinList > *").first().waitFor();
await toProviders();
await page.locator("#addSheet .tile.more-plugins").click();
await expectDiscover("More in Plugins after " + last);
// the search's way there too
await pick(name);
await toProviders();
await page.locator("#addSheet input.find").fill("fakeco");
await page.locator("#addSheet .none button", { hasText: w.lookFor }).click();
await expectDiscover("look for a plugin after " + last, "fakeco");
await view.locator(".pm-find input").fill("");
}
assert.deepEqual(fetched, [], "nothing fetched from elsewhere");
assert.deepEqual(errors, []);
});
}
});
}