From db0a3344f44d0a4e9a70b1e2989fc1e5bbb66e0d Mon Sep 17 00:00:00 2001 From: GinWU Date: Thu, 1 Oct 2026 14:56:25 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20a=20Plugins=20card's=20move=20button=20h?= =?UTF-8?q?as=20a=20row=20of=20its=20own=20and=20says=20how=20many=20accou?= =?UTF-8?q?nts=20it=20moves=20=E2=80=94=20on=20the=20Plugins=20tab,=20a=20?= =?UTF-8?q?card=20that=20offers=20a=20built-in's=20accounts=20put=20"Move?= =?UTF-8?q?=20my=20{name}=20accounts=20({n})"=20in=20its=20top=20row=20bes?= =?UTF-8?q?ide=20the=20plugin's=20name;=20the=20button=20doesn't=20shrink?= =?UTF-8?q?=20(.pm-act=20is=20flex:=20none,=20nowrap),=20so=20in=20a=20two?= =?UTF-8?q?-=20or=20three-column=20window=20"Move=20my=20Grok=20(SuperGrok?= =?UTF-8?q?)=20accounts=20(1)"=20ran=20past=20the=20card's=20right=20edge,?= =?UTF-8?q?=20and=20Kiro's=20shorter=20one=20squeezed=20its=20name=20to=20?= =?UTF-8?q?"K=E2=80=A6"=20and=20cut=20"magpie=20community".=20The=20move?= =?UTF-8?q?=20button=20(and=20its=20"Moving=E2=80=A6")=20now=20has=20a=20r?= =?UTF-8?q?ow=20of=20its=20own=20at=20the=20card's=20foot,=20full=20width,?= =?UTF-8?q?=20wrapping=20if=20it=20must;=20Install,=20Sign=20in=20and=20th?= =?UTF-8?q?e=20rest=20stay=20in=20the=20top=20row.=20Its=20words=20say=20w?= =?UTF-8?q?hat=20the=20number=20is:=20"Move=20my=201=20Grok=20(SuperGrok)?= =?UTF-8?q?=20account",=20"Move=20my=202=20Zed=20accounts",=20=E3=80=8C?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=88=91=E7=9A=84=201=20=E4=B8=AA=20Grok=20(?= =?UTF-8?q?SuperGrok)=20=E8=B4=A6=E5=8F=B7=E3=80=8D.=20plugin-move-overflo?= =?UTF-8?q?w.test.cjs=20(Chromium,=20WebKit,=20en/zh,=20920/600/480px=20wi?= =?UTF-8?q?th=20the=20column=20count=20checked)=20fails=20without=20the=20?= =?UTF-8?q?change=20at=20920=20and=20600px;=20plugin-move,=20plugin-market?= =?UTF-8?q?,=20market-have,=20old-webkit,=20plugin-moved-signin,=20plugin-?= =?UTF-8?q?release,=20plugin-signin=20pass=20(plugin-market's=20"typing=20?= =?UTF-8?q?keeps=20the=20field"=20fails=20now=20and=20then=20on=20main=20h?= =?UTF-8?q?ere=20too).=20Go=20not=20run:=20only=20CSS,=20JS=20and=20string?= =?UTF-8?q?s=20changed.=20(#398)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/i18n.js | 3 +- internal/gui/assets/plugins.css | 1 + internal/gui/assets/plugins.js | 12 ++- internal/gui/tests/README.md | 9 +- .../gui/tests/plugin-move-overflow.test.cjs | 84 +++++++++++++++++++ internal/gui/tests/plugin-move.test.cjs | 4 +- 6 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 internal/gui/tests/plugin-move-overflow.test.cjs diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index ecf8626f4..e751634b0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -392,7 +392,8 @@ const I18N = { "Move {name} here": "把 {name} 迁到这里", "{name}: on magpie's built-in": "{name}:使用 magpie 内置", "{name} runs on magpie's built-in, with your accounts; Move {name} here runs it on this plugin": "{name} 正由 magpie 内置运行,使用你的账号;「把 {name} 迁到这里」可改由这个插件运行", - "Move my {name} accounts ({n})": "迁移我的 {name} 账号({n})", + "Move my {n} {name} account": "迁移我的 {n} 个 {name} 账号", + "Move my {n} {name} accounts": "迁移我的 {n} 个 {name} 账号", "Moving…": "正在迁移…", "Move": "迁移", "Runs {name} on this plugin in place of the built-in, with the same accounts; nothing changes if one doesn't work through it": "改由这个插件运行 {name},账号不变;有账号用不了时什么都不会改", diff --git a/internal/gui/assets/plugins.css b/internal/gui/assets/plugins.css index ee2dcc6d6..8607512e3 100644 --- a/internal/gui/assets/plugins.css +++ b/internal/gui/assets/plugins.css @@ -88,6 +88,7 @@ .pm-act.done:hover:not(:disabled) { background: var(--green-soft); color: var(--green); } .pm-act.busy { color: var(--muted); font-weight: 500; } .pm-act:disabled:not(.busy):not(.done) { opacity: .55; } +.pm-card > .pm-act.move { height: auto; min-height: 26px; padding: 4px 12px; white-space: normal; text-align: center; } .pm-act .spin { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; } /* loading: cards drawn as grey bars */ diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.js index 14c3d86eb..014e16f09 100644 --- a/internal/gui/assets/plugins.js +++ b/internal/gui/assets/plugins.js @@ -128,8 +128,8 @@ } } const moveButton = (b, c, here) => { - b.classList.add("go"); - b.textContent = here ? t("Move {name} here", { name: c.name }) : t("Move my {name} accounts ({n})", { name: c.name, n: c.accounts }); + b.classList.add("go", "move"); + b.textContent = here ? t("Move {name} here", { name: c.name }) : t(c.accounts === 1 ? "Move my {n} {name} account" : "Move my {n} {name} accounts", { name: c.name, n: c.accounts }); b.title = t("Runs {name} on this plugin in place of the built-in, with the same accounts; nothing changes if one doesn't work through it", { name: c.name }); b.disabled = busy.size > 0; b.onclick = (ev) => { ev.stopPropagation(); move(c); }; @@ -147,6 +147,7 @@ const op = busy.get(pkg); if (op === "add" || op === "upgrade" || op === "move") { b.classList.add("busy"); + if (op === "move") b.classList.add("move"); b.append(el("span", "spin"), el("span", "", op === "move" ? t("Moving…") : op === "upgrade" ? t("Updating…") : market?.state.bun ? t("Installing…") : t("Getting Bun…"))); b.disabled = true; if (!market?.state.bun) b.title = t("Plugins run on Bun {v}, downloaded once", { v: market?.state.bunVersion || "" }); @@ -217,7 +218,11 @@ by.append(v); } else by.append(el("span", "", l.npm?.publisher || l.package)); who.append(by); - top.append(logo(l.icon), who, actionFor(l.package, l.name, l)); + const act = actionFor(l.package, l.name, l); + // a move says whose accounts: too long for the top row, it has one of its own + const own = act.classList.contains("move"); + top.append(logo(l.icon), who); + if (!own) top.append(act); const sum = el("p", "pm-sum", summary(l)); const meta = el("div", "pm-meta"); if (l.npm?.weekly) { @@ -236,6 +241,7 @@ meta.append(b); } c.append(top, sum, meta); + if (own) c.append(act); c.onclick = () => detail(l); c.onkeydown = (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); detail(l); } }; return c; diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index 95fa43d7b..f4cf081b5 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -33,6 +33,13 @@ method's questions (a pick, then a text the plugin checks), then takes the code the browser page shows; an API-key way opens the account. English and Chinese, Chromium and WebKit, with the API faked. +`plugin-move-overflow.test.cjs` checks a Plugins card that offers a +built-in's accounts ("Move my 1 Grok (SuperGrok) account"): the button has a +row of its own at the card's foot, so it stays inside the card and the +plugin's name and "magpie community" aren't cut, in a three-, two- and +one-column window. English and Chinese, Chromium and WebKit, with the API +faked. + `plugin-key-hint.test.cjs` checks a plugin's API-key way: its label titles the key's field and its placeholder is the field's hint, while a way labelled only "API key" keeps " API key"; the provider's own icon shows on its @@ -640,7 +647,7 @@ with `/api/plugins` faked. With Node.js and Playwright available: ```sh -node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs +node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs ``` If Playwright is installed outside the repository, set `NODE_PATH` to the diff --git a/internal/gui/tests/plugin-move-overflow.test.cjs b/internal/gui/tests/plugin-move-overflow.test.cjs new file mode 100644 index 000000000..6eff23959 --- /dev/null +++ b/internal/gui/tests/plugin-move-overflow.test.cjs @@ -0,0 +1,84 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A Plugins card that offers a built-in's accounts keeps its button inside +// the card: "Move my Grok (SuperGrok) accounts (1)" ran past the card's right +// edge, and Kiro's shorter one squeezed its name to "K…" and cut "magpie +// community". The button now has a row of its own at the card's foot and +// says how many accounts it moves ("Move my 1 Grok (SuperGrok) account"). +// Every card stays whole, its name and byline uncut, in a three-, two- and +// one-column window. In 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 listing = (id, name, summary) => ({ + package: `@magpie-community/opencode-${id}-auth`, name, icon: id, providers: [id], community: true, replaces: id, + summary: { en: summary, zh: summary }, npm: { version: "0.1.4" }, +}); +const listings = [ + listing("factory", "Factory", "Factory Droid subscriptions: Anthropic, OpenAI, xAI and open models."), + listing("grok", "Grok", "Use SuperGrok and X Premium+ through the Grok Build CLI's sign-in."), + listing("cursor", "Cursor", "Cursor Pro, Pro+, Ultra and Teams: every model of the plan."), + listing("kiro", "Kiro", "Kiro Free, Pro, Pro+ and Power: Kiro sign-in, kiro-cli's, or an API key."), +]; +const movable = [ + { id: "grok", name: "Grok (SuperGrok)", package: listings[1].package, accounts: 1 }, + { id: "kiro", name: "Kiro", package: listings[3].package, accounts: 1 }, +]; + +function serve(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:true};` }); + 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: [], onPlugins: [] }); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/plugins/market") return json({ listings, state: { bun: true, bunVersion: "1.3.0", plugins: [], movable } }); + 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: "" }); } + }; +} + +const card = { en: "Move my 1 Grok (SuperGrok) account", zh: "迁移我的 1 个 Grok (SuperGrok) 账号" }; +const launch = (engine) => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + for (const [width, cols] of [[920, 3], [600, 2], [480, 1]]) { + test(`${engine} ${lang} ${width}px: a card's move button stays inside it`, async (t) => { + const browser = await launch(engine); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=plugins"); + await page.locator("#view-plugins button", { hasText: card[lang] }).waitFor(); + if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `plugin-move-overflow-${engine}-${lang}-${width}.png`) }); + + const cards = await page.locator("#view-plugins .pm-card").evaluateAll((cs) => cs.map((c) => { + const box = c.getBoundingClientRect(); + const out = [...c.querySelectorAll(".pm-top *")].filter((e) => { + const r = e.getBoundingClientRect(); + return r.width && (r.left < box.left || r.right > box.right); + }).map((e) => e.className || e.tagName); + const cut = [...c.querySelectorAll(".pm-name b, .pm-by, .pm-by > span")].filter((e) => e.scrollWidth > e.clientWidth).map((e) => e.textContent); + return { name: c.querySelector(".pm-name b")?.textContent, out, cut }; + })); + assert.ok(cards.length >= listings.length, "the market's cards aren't there"); + const lefts = await page.locator("#view-plugins .pm-card").evaluateAll((cs) => new Set(cs.map((c) => Math.round(c.getBoundingClientRect().left))).size); + assert.equal(lefts, cols, `not ${cols} columns at ${width}px`); + const wrong = cards.flatMap((c) => [...(c.out.length ? [`${c.name}: runs past its card`] : []), ...c.cut.map((x) => `${c.name}: "${x}" is cut`)]); + assert.deepEqual(wrong, []); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/gui/tests/plugin-move.test.cjs b/internal/gui/tests/plugin-move.test.cjs index 74740e4d7..5778609fb 100644 --- a/internal/gui/tests/plugin-move.test.cjs +++ b/internal/gui/tests/plugin-move.test.cjs @@ -73,12 +73,12 @@ const L = { move: "Move to the plugin", busy: "Installing the plugin and checking each account…", again: "Try again", back: "Use the built-in again", failed: "It stays built-in: magpie couldn't reach npm to install the plugin. Check the network or proxy, then try again.", onPlugin: "The community Zed plugin", builtin: "magpie's built-in · or the community Zed plugin", done: "Zed now runs on its plugin — 2 accounts, 1 model.", - subs: "Subscriptions", card: "Move my Zed accounts (2)", own: "Zed itself stays signed in as it is." }, + subs: "Subscriptions", card: "Move my 2 Zed accounts", own: "Zed itself stays signed in as it is." }, zh: { runs: "运行方式", line: "Zed 可以改由社区插件运行,账号不变。", look: "看看", move: "迁移到插件", busy: "正在安装插件并逐个检查账号…", again: "重试", back: "改回内置", failed: "仍使用内置:无法连接 npm 安装插件,请检查网络或代理后重试。", onPlugin: "社区 Zed 插件", builtin: "magpie 内置 · 也可改用社区 Zed 插件", done: "Zed 现在由插件运行——2 个账号,1 个模型。", - subs: "订阅", card: "迁移我的 Zed 账号(2)", own: "Zed 本身的登录保持不变。" }, + subs: "订阅", card: "迁移我的 2 个 Zed 账号", own: "Zed 本身的登录保持不变。" }, }; const launch = (engine) => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" });