From f85a221c96da098c8665b28c53128c1b15d89fb7 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 21:29:03 +0800 Subject: [PATCH] plugins: a plugin installed twice says "another copy" once, not its own name per provider (plugins#565) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ferock (plugins#565) installed the CodeArts / OfficeAce plugin from two specs. Each copy serves codearts and officeace, so each card got one clash line per provider, built from the other copy's shownName, which is the card's own name. In zh it read "CodeArts / OfficeAce 也登录 CodeArts; 由这个插件提供" and then again for OfficeAce. clashLine is now given groups (clashGroups): a row's clashes grouped by side (served here or by the other plugin) and by which specs they clash with, with the provider names joined. When every other spec's name is this row's own name, the line says another copy of this plugin ({spec}) does it. Otherwise several names use new plural keys, and one name uses the old key. All four new keys are in zh, zh-TW, ja and de. The existing zh and zh-TW singular line now reads "{other} 也能登录 {name}, 现由这个插件提供" in place of the clipped "也登录 …;由这个插件提供". Run on mote, at this tree rebased on origin/main 3d063e34f: - plugin-clash.test.cjs: the new test, "one plugin installed twice says so once, not by its own name", covers both specs, every language, widths 1100 and 560, Chromium and WebKit. It passes, and with the old plugins.js and i18n.js (stashed) it is red, as are the zh and zh-TW `serves` lines. - i18n-keys, gui-de/ja/zh-tw, dates-gui-lang and every plugin*.test.cjs in Chromium and WebKit. Before the rebase: 891/899 and 461/468 pass. origin/main 3d063e34f alone: 869/877 and 450/457. Every red is the same on main, and each is filed: gui-ja's {agent} (#4580, filed here), i18n-keys "Unmarked" (#4524), plugin-move-unserved Try again (#4392), plugin-card-update (#3079). plugin-namesake ja 440 and the "Install asks first" case were red once in the full run. Rerun at this head with plugin-card-update, plugin-replaced, i18n-keys, gui-zh-tw and gui-de in both engines, they pass (80/81, the one red is #4524). - go test -tags nogui ./internal/gui: the only reds are TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken (#4510), both red at 3d063e34f alone. The budgets pass. Not tried: the real app with the plugin installed twice. The full GUI suite beyond the plugin and i18n files was not run either, since the change adds no API call and no shared class or layout. Rebased on 3ecc02b78 (nav-lamp only), then 73a12e8bf (wsl, no GUI files): after the rebase, plugin-clash and nav-lamp pass in both engines (32/32 each) and the budget tests pass. --- internal/gui/assets/i18n.js | 20 +++++- internal/gui/assets/plugins.js | 56 +++++++++++---- internal/gui/tests/plugin-clash.test.cjs | 90 +++++++++++++++++++++++- 3 files changed, 150 insertions(+), 16 deletions(-) diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 0cc5fc847..0102452d0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2579,8 +2579,12 @@ const I18N = { "Didn't load: {error}": "没有加载成功:{error}", "Signs in to {names}": "可登录 {names}", "Signs in to nothing magpie can use": "没有 magpie 能用的登录", - "{other} signs in to {name} too; this one serves it": "{other} 也登录 {name};由这个插件提供", + "{other} signs in to {name} too; this one serves it": "{other} 也能登录 {name},现由这个插件提供", "{name} is served by {other}, which signs in to it too": "{name} 由同样登录它的 {other} 提供", + "Another copy of this plugin ({spec}) signs in to {names} too; this copy serves them": "这个插件还装了另一份({spec}),也登录 {names};现在用的是这一份", + "Another copy of this plugin ({spec}) serves {names}": "{names} 现由这个插件的另一份({spec})提供", + "{other} signs in to {names} too; this one serves them": "{other} 也能登录 {names},现由这个插件提供", + "{names} are served by {other}, which signs in to them too": "{names} 由同样登录它们的 {other} 提供", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it": "有两个插件都登录 {name},magpie 只用其中一个。在另一个插件那一行点“用于 {name}”即可切换", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want": "有两个插件都登录 {name},magpie 只用其中一个。点“用于 {name}”换成这个插件,或移除不需要的那个", "Use for {name}": "用于 {name}", @@ -6813,8 +6817,12 @@ const I18N = { "Didn't load: {error}": "沒有載入成功:{error}", "Signs in to {names}": "可登入 {names}", "Signs in to nothing magpie can use": "沒有 magpie 能用的登入", - "{other} signs in to {name} too; this one serves it": "{other} 也登入 {name};由這個外掛提供", + "{other} signs in to {name} too; this one serves it": "{other} 也能登入 {name},現由這個外掛提供", "{name} is served by {other}, which signs in to it too": "{name} 由同樣登入它的 {other} 提供", + "Another copy of this plugin ({spec}) signs in to {names} too; this copy serves them": "這個外掛還裝了另一份({spec}),也登入 {names};現在用的是這一份", + "Another copy of this plugin ({spec}) serves {names}": "{names} 現由這個外掛的另一份({spec})提供", + "{other} signs in to {names} too; this one serves them": "{other} 也能登入 {names},現由這個外掛提供", + "{names} are served by {other}, which signs in to them too": "{names} 由同樣登入它們的 {other} 提供", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it": "有兩個外掛都登入 {name},magpie 只用其中一個。在另一個外掛那一列點「用於 {name}」即可切換", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want": "有兩個外掛都登入 {name},magpie 只用其中一個。點「用於 {name}」換成這個外掛,或移除不需要的那個", "Use for {name}": "用於 {name}", @@ -11071,6 +11079,10 @@ const I18N = { "Signs in to nothing magpie can use": "magpie で使えるサインインはありません", "{other} signs in to {name} too; this one serves it": "{other} も {name} にサインインします。このプラグインが提供中です", "{name} is served by {other}, which signs in to it too": "{name} は、同じくサインインする {other} が提供しています", + "Another copy of this plugin ({spec}) signs in to {names} too; this copy serves them": "このプラグインはもう一つ({spec})インストールされていて、{names} にもサインインします。使われているのはこちらです", + "Another copy of this plugin ({spec}) serves {names}": "このプラグインのもう一つのインストール({spec})が {names} を提供しています", + "{other} signs in to {names} too; this one serves them": "{other} も {names} にサインインします。このプラグインが提供中です", + "{names} are served by {other}, which signs in to them too": "{names} は、同じくサインインする {other} が提供しています", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it": "2 つのプラグインが {name} にサインインします。magpie が使うのは 1 つだけです。もう一方の行の「{name} に使う」で切り替えられます", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want": "2 つのプラグインが {name} にサインインします。magpie が使うのは 1 つだけです。「{name} に使う」でこのプラグインに切り替えるか、不要な方を削除してください", "Use for {name}": "{name} に使う", @@ -15338,6 +15350,10 @@ const I18N = { "Signs in to nothing magpie can use": "Meldet bei nichts an, das magpie nutzen kann", "{other} signs in to {name} too; this one serves it": "{other} meldet sich auch bei {name} an; diese Erweiterung stellt es bereit", "{name} is served by {other}, which signs in to it too": "{name} wird von {other} bereitgestellt, die sich ebenfalls dort anmeldet", + "Another copy of this plugin ({spec}) signs in to {names} too; this copy serves them": "Eine weitere Kopie dieser Erweiterung ({spec}) meldet sich auch bei {names} an; diese Kopie stellt sie bereit", + "Another copy of this plugin ({spec}) serves {names}": "Eine weitere Kopie dieser Erweiterung ({spec}) stellt {names} bereit", + "{other} signs in to {names} too; this one serves them": "{other} meldet sich auch bei {names} an; diese Erweiterung stellt sie bereit", + "{names} are served by {other}, which signs in to them too": "{names} werden von {other} bereitgestellt, die sich ebenfalls dort anmeldet", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it": "Zwei Erweiterungen melden sich bei {name} an; magpie nutzt nur eine. „Für {name} nutzen“ in der Zeile der anderen wechselt", "Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want": "Zwei Erweiterungen melden sich bei {name} an; magpie nutzt nur eine. „Für {name} nutzen“ wechselt zu dieser, oder entfernen Sie die nicht gewünschte", "Use for {name}": "Für {name} nutzen", diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.js index 89bf8b9ec..045f5d2e4 100644 --- a/internal/gui/assets/plugins.js +++ b/internal/gui/assets/plugins.js @@ -1265,7 +1265,7 @@ // can use, which isn't known until the answer comes (#1112) else if (e.named) sub.textContent = t("Signs in to nothing magpie can use"); if (sub.textContent) who.append(sub); - if (!ask) for (const c of clashes) who.append(clashLine(e, c, nameOfSpec)); + if (!ask) for (const g of clashGroups(e, clashes)) who.append(clashLine(e, g, nameOfSpec)); if (mw && !e.off && !ask) who.append(mwLine(mw)); if (gw && !e.off && !ask) who.append(gatewayLine(gw)); if (ag && !e.off && !ask) who.append(agentLine(ag)); @@ -1409,17 +1409,49 @@ // mwLine is a middleware's line in its plugin's row: its hooks, how many // calls and how long each took, and the calls that failed (which went on // as if it weren't there), or why it didn't load - // clashLine is one provider two installed plugins both sign in to, as - // the row of either says it: served here, or served by the other one - function clashLine(e, c, nameOfSpec) { - const d = el("div", "sub pm-clash" + (c.by === e.spec ? "" : " warn")); - const others = (c.by === e.spec ? c.with : [c.by]).map(nameOfSpec).join(t(", ")); - d.append(el("span", "dot"), el("span", "", c.by === e.spec - ? t("{other} signs in to {name} too; this one serves it", { name: c.name, other: others }) - : t("{name} is served by {other}, which signs in to it too", { name: c.name, other: others }))); - d.title = c.by === e.spec - ? t("Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it", { name: c.name }) - : t("Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want", { name: c.name }); + // clashGroups are a row's clashes, one per other plugin and side: a + // plugin that signs in to two providers another one does too is one + // line naming both, not a line each saying the same thing (#565) + function clashGroups(e, clashes) { + const out = []; + for (const c of clashes) { + const here = c.by === e.spec; + const others = here ? c.with : [c.by]; + const g = out.find((x) => x.here === here && x.others.join("\n") === others.join("\n")); + if (g) g.names.push(c.name); + else out.push({ here, others, names: [c.name] }); + } + return out; + } + + // clashLine is the providers two installed plugins both sign in to, as + // the row of either says it: served here, or served by the other one. + // The other one goes by its name; when that is this row's own name too + // (the same plugin installed twice, from two places), by where it came + // from, since "CodeArts / OfficeAce also signs in to CodeArts" on the + // CodeArts / OfficeAce row read as the plugin naming itself (#565) + function clashLine(e, g, nameOfSpec) { + const d = el("div", "sub pm-clash" + (g.here ? "" : " warn")); + const own = shownName(e); + const copies = g.others.filter((s) => nameOfSpec(s) === own); + const names = g.names.join(t(", ")); + const many = g.names.length > 1; + let text; + if (copies.length && copies.length === g.others.length) { + const spec = copies.join(t(", ")); + text = g.here + ? t("Another copy of this plugin ({spec}) signs in to {names} too; this copy serves them", { spec, names }) + : t("Another copy of this plugin ({spec}) serves {names}", { spec, names }); + } else { + const other = g.others.map(nameOfSpec).join(t(", ")); + text = g.here + ? many ? t("{other} signs in to {names} too; this one serves them", { other, names }) : t("{other} signs in to {name} too; this one serves it", { other, name: names }) + : many ? t("{names} are served by {other}, which signs in to them too", { other, names }) : t("{name} is served by {other}, which signs in to it too", { other, name: names }); + } + d.append(el("span", "dot"), el("span", "", text)); + d.title = g.names.map((name) => g.here + ? t("Two plugins sign in to {name}; magpie runs it on one. Use for {name} on the other one's row switches it", { name }) + : t("Two plugins sign in to {name}; magpie runs it on one. Use for {name} switches it to this one, or remove the one you don't want", { name })).join("\n"); return d; } diff --git a/internal/gui/tests/plugin-clash.test.cjs b/internal/gui/tests/plugin-clash.test.cjs index 2cb043f1a..1fd37ea12 100644 --- a/internal/gui/tests/plugin-clash.test.cjs +++ b/internal/gui/tests/plugin-clash.test.cjs @@ -55,8 +55,8 @@ function server(lang, asked) { // what each row says, in each language const L = { en: { installed: "Installed", nothing: "Signs in to nothing magpie can use", served: "Acme is served by {other}, which signs in to it too", serves: "{other} signs in to Acme too; this one serves it", use: "Use for Acme", done: "Acme now runs on my-acme" }, - zh: { installed: "已安装", nothing: "没有 magpie 能用的登录", served: "Acme 由同样登录它的 {other} 提供", serves: "{other} 也登录 Acme;由这个插件提供", use: "用于 Acme", done: "Acme 现在由 my-acme 提供" }, - "zh-TW": { installed: "已安裝", nothing: "沒有 magpie 能用的登入", served: "Acme 由同樣登入它的 {other} 提供", serves: "{other} 也登入 Acme;由這個外掛提供", use: "用於 Acme", done: "Acme 現在由 my-acme 提供" }, + zh: { installed: "已安装", nothing: "没有 magpie 能用的登录", served: "Acme 由同样登录它的 {other} 提供", serves: "{other} 也能登录 Acme,现由这个插件提供", use: "用于 Acme", done: "Acme 现在由 my-acme 提供" }, + "zh-TW": { installed: "已安裝", nothing: "沒有 magpie 能用的登入", served: "Acme 由同樣登入它的 {other} 提供", serves: "{other} 也能登入 Acme,現由這個外掛提供", use: "用於 Acme", done: "Acme 現在由 my-acme 提供" }, ja: { installed: "インストール済み", nothing: "magpie で使えるサインインはありません", served: "Acme は、同じくサインインする {other} が提供しています", serves: "{other} も Acme にサインインします。このプラグインが提供中です", use: "Acme に使う", done: "Acme は my-acme で動くようになりました" }, de: { installed: "Installiert", nothing: "Meldet bei nichts an, das magpie nutzen kann", served: "Acme wird von {other} bereitgestellt, die sich ebenfalls dort anmeldet", serves: "{other} meldet sich auch bei Acme an; diese Erweiterung stellt es bereit", use: "Für Acme nutzen", done: "Acme läuft jetzt über my-acme" }, }; @@ -124,3 +124,89 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", } }); } + +// #565 (ferocknew): the same plugin installed twice, from two places, and +// signing in to two providers. Its row read "CodeArts / OfficeAce 也登录 +// CodeArts;由这个插件提供" and again for OfficeAce: the plugin naming +// itself, once a provider. Now each row has one line, naming the other copy +// by where it came from. +const NPM = "@magpie-community/opencode-codearts-auth@latest"; +const DEV = "/Users/me/dev/codearts"; +const NAME = "CodeArts / OfficeAce"; + +function twice(lang) { + const clash = (spec) => ["codearts", "officeace"].map((id, i) => ({ id, by: NPM, with: [spec === NPM ? DEV : NPM], name: ["CodeArts", "OfficeAce"][i] })); + const installed = [ + { spec: DEV, ownName: NAME, providers: [], version: "0.3.0", clashes: clash(DEV) }, + { spec: NPM, providers: ["CodeArts", "OfficeAce"], serves: ["CodeArts", "OfficeAce"], version: "0.3.0", clashes: clash(NPM) }, + ]; + const state = { bun: true, bunVersion: "1.3.0", plugins: installed }; + const listings = [{ package: "@magpie-community/opencode-codearts-auth", name: NAME, providers: ["codearts", "officeace"] }]; + 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.startsWith("/api/")) return json({}); + if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "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 T = { + en: { serves: `Another copy of this plugin (${DEV}) signs in to CodeArts, OfficeAce too; this copy serves them`, served: `Another copy of this plugin (${NPM}) serves CodeArts, OfficeAce` }, + zh: { serves: `这个插件还装了另一份(${DEV}),也登录 CodeArts、OfficeAce;现在用的是这一份`, served: `CodeArts、OfficeAce 现由这个插件的另一份(${NPM})提供` }, + "zh-TW": { serves: `這個外掛還裝了另一份(${DEV}),也登入 CodeArts、OfficeAce;現在用的是這一份`, served: `CodeArts、OfficeAce 現由這個外掛的另一份(${NPM})提供` }, + ja: { serves: `このプラグインはもう一つ(${DEV})インストールされていて、CodeArts、OfficeAce にもサインインします。使われているのはこちらです`, served: `このプラグインのもう一つのインストール(${NPM})が CodeArts、OfficeAce を提供しています` }, + de: { serves: `Eine weitere Kopie dieser Erweiterung (${DEV}) meldet sich auch bei CodeArts, OfficeAce an; diese Kopie stellt sie bereit`, served: `Eine weitere Kopie dieser Erweiterung (${NPM}) stellt CodeArts, OfficeAce bereit` }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": one plugin installed twice says so once, not by its own name", async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" })); + t.after(() => browser.close()); + for (const lang of Object.keys(T)) { + for (const width of [1100, 560]) { + await t.test(`${lang} ${width}px`, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 820 } }); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", twice(lang)); + await page.goto("http://magpie.test/?view=plugins"); + const view = page.locator("#view-plugins"); + await view.waitFor({ state: "visible" }); + await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: L[lang].installed }).click(); + const rows = view.locator(".pm-row", { has: page.locator(".name span", { hasText: NAME }) }); + await rows.nth(1).waitFor(); + assert.equal(await rows.count(), 2); + const lines = []; + for (let i = 0; i < 2; i++) { + const clash = rows.nth(i).locator(".pm-clash"); + assert.equal(await clash.count(), 1, "one line for both providers"); + lines.push((await clash.innerText()).trim()); + } + assert.deepEqual(lines.sort(), [T[lang].serves, T[lang].served].sort()); + for (const l of lines) assert.ok(!l.includes(NAME), `the line doesn't name the plugin itself: ${l}`); + const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert.ok(over <= 0, `the page scrolls sideways by ${over}px`); + await shot(view, `plugin-clash-twice-${engine}-${lang}-${width}`); + assert.deepEqual(errors, []); + await ctx.close(); + }); + } + } + }); +}