From bf1b2893d4cacb70113139f5f24dbd3032e741b1 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 18 Nov 2026 12:01:41 +0800 Subject: [PATCH] =?UTF-8?q?usage:=20a=20"group=20=C2=B7=20span"=20ring=20r?= =?UTF-8?q?eads=20in=20two=20lines,=20no=20empty=20Every=20model=20(tongzh?= =?UTF-8?q?enbao=20on=20X)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit agy-cli up to 0.1.91 named its windows "Gemini · 7 days", "Gemini · 5 hours", "Claude & GPT · 7 days" with no pool field. The ring label was one line, so all three were cut to "Gemini …" / "Claude …" and two groups' rings read the same. agy-cli 0.1.92 (plugins 207880e1, on dist) sends the antigravity shape again: each group as a pool with its 5h and 7d windows, and each model family in it, so the Usage page's "Every model (n)" lists the models as it did before. - ringParts splits any "X · span" name (and a pool's window, as before) into the group's first word over its short span, so old plugin versions, MiniMax's "Video · 1 days" and agnes' "Text · 5 hours" read Gemini/7d, Gemini/5h, Claude/7d. Every other name stays one line. - familyQuota shows pools alone when no window names a model, instead of an "Every model (0)" button that showed nothing. - No budget raised: the change is 16 code bytes under appScriptBudget. Run (mote/mica): - internal/gui/tests/quota-ring-names.test.cjs (new; chromium + webkit, en + zh): ring labels per line, fit in their ring, reset line, tooltip, "Every model (3)" / 「全部模型(3)」 listing three models, one toggle. With quota-pools.test.cjs: 8 of 8. - The 65 GUI files that reach the panel's quota card, plus the files a first full run had red: 709 of 813 pass. All 18 files with reds were run again at origin/main 889991b15: 17 fail the same way there (102 reds; agent-details-ready, api-key-theme, bark, codex-memories-settings, tray-cell-click and others), and panel-arrange, which failed once here, passed 3 of 3 alone. - go test ./internal/gui/ ok (TestCoreScriptBudget included). - A plugin fetchUsage against the real local agy 1.5.10 gave "Gemini 3.8 Flash" (pool Gemini) and "GPT-OSS 120B" (pool Claude & GPT) model windows beside the pools' "7 days". Broken by hand: quota-ring-names is red on the old app.js (labels on one line), and red without the familyQuota hunk (an "Every model (0)" toggle). A first compaction of ringParts returned false for a plain name, and `?.join` threw on every card; the subset run caught it (TypeError in panel-quota-kept and others) before this commit. Not tried: the full GUI suite on this exact head (mote dropped the ssh link after 11984 tests of an earlier version); a real magpie app with the user's six accounts. --- internal/gui/assets/app.js | 33 ++--- internal/gui/tests/quota-ring-names.test.cjs | 128 +++++++++++++++++++ 2 files changed, 145 insertions(+), 16 deletions(-) create mode 100644 internal/gui/tests/quota-ring-names.test.cjs diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index af90a363f..28487e8cb 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -14842,11 +14842,15 @@ const pooledModels = (ws) => (ws?.some(isPool) ? ws.filter((w) => !isPool(w)) : function poolTip(w) { return t("{pool}: one allowance for these models", { pool: w.pool }) + "\n" + tiersText({ tiers: w.members }); } +// ringParts: a ring's label in two, a pool's first word over its span +// (Gemini / 5h), and so a name that is a group and a span ("Gemini · 7 +// days", "Video · 5 hours", "Text · weekly"): on one line its span was +// cut off, and two groups' rings read the same "Gemini …" (tongzhenbao on +// X). Any other name is one line. +const ringParts = (w, m = w.window ? [w.pool, w.window] : w.name?.split(" · ")) => m?.[1] ? [poolWord(m[0]), shortWindow(m[1])] : void 0; // ringName: a window's name short enough for a ring: a pool's first word // and its span (Gemini 5h, Claude 7d). -function ringName(w) { - return w.window ? poolWord(w.pool) + " " + shortWindow(w.window) : shortWindow(w.name); -} +const ringName = (w) => ringParts(w)?.join(" ") || shortWindow(w.name); // quotaall.js: accounts together, loaded once asked for function quotaAllJS() { @@ -17925,8 +17929,8 @@ function panelQuotaCard(q, first = false) { const at = new Date(w.resetsAt); // the first deadline named as one: a bare "↻ 14:26" read as a // refresh to click (#840, hhh2210) - return at <= Date.now() ? (i || w.members ? ringName(w) + " " : "") + resetText(at) - : i || w.members ? ringName(w) + " " + resetClock(at) : resetText(at); + const n = i || w.members ? ringName(w) + " " : ""; + return n + (at <= Date.now() || !n ? resetText(at) : resetClock(at)); }).join(" · ") : ws.some((w) => w.used > 0) ? "" : t("Not used yet")); // the first window's own pace too, while its line is drawn and the @@ -17943,11 +17947,8 @@ function panelQuotaCard(q, first = false) { dial.style.setProperty("--p", quotaFill(w)); dial.append(el("b", "", quotaFill(w) + "%")); // a pool's ring: its first word over its span, too long for one line - const rn = el("span", "pq-rn", w.window ? undefined : ringName(w)); - if (w.window) { - rn.classList.add("pq-rn2"); - rn.append(el("span", "", poolWord(w.pool)), el("span", "", shortWindow(w.window))); - } + const two = ringParts(w), rn = el("span", "pq-rn" + (two ? " pq-rn2" : ""), two ? void 0 : ringName(w)); + two?.forEach((x) => rn.append(el("span", "", x))); r.append(dial, rn); r.title = t(w.name) + " · " + quotaText(w) + (w.resetsAt ? "\n" + resetText(new Date(w.resetsAt), new Date(w.resetsAt).toLocaleString(intlLang())) + (new Date(w.resetsAt) > Date.now() ? " · " + untilText(new Date(w.resetsAt)) : "") : "") + (w.tiers ? "\n\n" + tiersText(w) + "\n" : "") @@ -18738,10 +18739,11 @@ function quotaRefresh(q, then) { const everyModel = new Set(); // provider|user shown window by window function familyQuota(sub) { const fam = sub.error ? sub.windows : familyWindows(sub.windows); - if (fam === sub.windows) return [quotaWindows(sub), null]; - const key = sub.provider + "|" + (sub.user || ""); const models = pooledModels(sub.windows); - const pooled = models !== sub.windows; + // pools whose models weren't named (agy-cli before agy listed its + // models): the pools alone, not an "Every model (0)" that shows nothing + if (fam === sub.windows || !models.length) return [quotaWindows({ ...sub, windows: fam }), null]; + const key = sub.provider + "|" + (sub.user || ""), pooled = models !== sub.windows; const shown = () => quotaWindows({ ...sub, windows: everyModel.has(key) ? models : fam }); let box = shown(); const b = el("button", "text quota-every"); @@ -18753,11 +18755,10 @@ function familyQuota(sub) { }; label(); b.onclick = () => { - if (everyModel.has(key)) everyModel.delete(key); else everyModel.add(key); + everyModel[everyModel.has(key) ? "delete" : "add"](key); const next = shown(); if (box.classList.contains("brief")) next.classList.add("brief"); - box.replaceWith(next); - box = next; + box.replaceWith(box = next); label(); }; return [box, b]; diff --git a/internal/gui/tests/quota-ring-names.test.cjs b/internal/gui/tests/quota-ring-names.test.cjs new file mode 100644 index 000000000..f0be71013 --- /dev/null +++ b/internal/gui/tests/quota-ring-names.test.cjs @@ -0,0 +1,128 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A ring named for a group and its span (tongzhenbao on X): agy-cli 0.1.91 +// named its windows "Gemini · 7 days", "Gemini · 5 hours", "Claude & GPT · +// 7 days" with no pool, and the menu bar panel drew each on one line, cut +// to "Gemini …", "Gemini …", "Claude …", two rings no one could tell apart. +// Such a ring reads as a pool's does, its first word over its span +// (Gemini / 7d), and so MiniMax's "Video · 5 hours". agy-cli 0.1.92 sends +// its pools as pools, and its models' windows when agy listed them: the +// Usage page's "Every model" lists them; with no model named it shows no +// "Every model (0)". English and Chinese, Chromium and WebKit; 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 at = (h) => new Date(Date.now() + h * 36e5).toISOString(); +const acct = (provider, name, user, windows) => ({ provider, name, icon: "", user, plan: "Pro", windows }); +// agy-cli 0.1.91: a group's window named with its span, no pool +const old = acct("agy-cli", "AGY-CLI", "old@example.com", [ + { name: "Gemini · 7 days", used: 100, resetsAt: at(100), aside: true }, + { name: "Gemini · 5 hours", used: 40, resetsAt: at(2), aside: true }, + { name: "Claude & GPT · 7 days", used: 100, resetsAt: at(90), aside: true }, +]); +// agy-cli 0.1.92 with agy's models listed: the models' windows, then the pools' +const model = (name, family, pool, used) => ({ name, family, pool, used, resetsAt: at(100), aside: true }); +const pool = (pool, name, used, h) => ({ name, pool, used, resetsAt: at(h), aside: true }); +const listed = acct("agy-cli", "AGY-CLI", "new@example.com", [ + model("Claude Opus 5.5", "Claude", "Claude & GPT", 66), model("Gemini 3.8 Flash", "Gemini", "Gemini", 20), + model("GPT-OSS 120B", "GPT-OSS", "Claude & GPT", 66), + pool("Gemini", "7 days", 20, 100), pool("Gemini", "5 hours", 10, 2), pool("Claude & GPT", "7 days", 66, 90), +]); +// the same before agy listed its models: pools alone +const bare = acct("agy-cli", "AGY-CLI", "bare@example.com", [ + pool("Gemini", "7 days", 20, 100), pool("Gemini", "5 hours", 10, 2), pool("Claude & GPT", "7 days", 66, 90), +]); +const minimax = acct("minimax", "MiniMax", "mm@example.com", [ + { name: "5 hours", used: 30, resetsAt: at(2) }, + { name: "Video · 1 days", used: 50, resetsAt: at(20), aside: true }, +]); +const quotas = [old, listed, bare, minimax]; + +function serve(lang, panel) { + const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" }; + 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:${!panel}};` }); + 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 }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/usage/quotas") return json(quotas); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + 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 words = { en: { every: "Every model (3)" }, zh: { every: "全部模型(3)" } }; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + test(`${engine} ${lang}: a ring named for a group and its span reads both`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const pages = []; + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + for (const [name, p] of pages) await p.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-quota-ring-names-${name}.png`) }); + } + await browser.close(); + }); + const errors = []; + const open = async (name, url, viewport) => { + const page = await (await browser.newContext({ viewport, reducedMotion: "reduce" })).newPage(); + pages.push([name, page]); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, url.includes("mode=panel"))); + await page.goto(url); + return page; + }; + + // the menu bar panel: each ring its group over its span, whole + const panel = await open("panel", "http://magpie.test/?mode=panel", { width: 440, height: 900 }); + await panel.locator('#ptabs [data-ptab="usage"]').click(); + for (const more of await panel.locator(".pq-group .pq-more").all()) await more.click(); + const card = (user) => panel.locator(".pq-card", { hasText: user }); + await card("old@example.com").locator(".pq-ring").first().waitFor(); + const labels = (user) => card(user).locator(".pq-rn").evaluateAll((es) => es.map((e) => [...e.children].map((c) => c.textContent))); + assert.deepEqual(await labels("old@example.com"), [["Gemini", "7d"], ["Gemini", "5h"], ["Claude", "7d"]]); + assert.deepEqual(await labels("new@example.com"), [["Gemini", "5h"], ["Gemini", "7d"], ["Claude", "7d"]]); + assert.deepEqual(await labels("bare@example.com"), [["Gemini", "5h"], ["Gemini", "7d"], ["Claude", "7d"]]); + assert.deepEqual((await labels("mm@example.com"))[1], ["Video", "1d"]); + for (const user of ["old@example.com", "new@example.com", "mm@example.com"]) { + const fit = await card(user).locator(".pq-rn > span").evaluateAll((es) => es.every((e) => e.scrollWidth <= e.clientWidth)); + assert(fit, `${user}: the ring labels fit`); + } + // the reset line names the ring as the ring does + const say = await card("old@example.com").locator(".pq-say").textContent(); + assert(say.includes("Gemini 5h"), "the second deadline is named: " + say); + // the tooltip keeps the whole name + assert((await card("old@example.com").locator(".pq-ring").first().getAttribute("title")).startsWith("Gemini · 7 days")); + + // the Usage page: the models' windows under Every model; no pool's models, no toggle + const page = await open("usage", "http://magpie.test/?view=usage", { width: 900, height: 900 }); + const sub = page.locator(".subscription-card", { hasText: "AGY-CLI" }); + await sub.locator(".quota-windows").first().waitFor(); + const account = (user) => sub.locator(".subscription-account", { hasText: user }); + const toggle = account("new@example.com").locator("button.quota-every"); + assert.equal((await toggle.textContent()).trim(), words[lang].every); + await toggle.click(); + await page.waitForTimeout(200); + const names = await sub.locator(".quota-windows").evaluateAll((bs) => bs.map((b) => [...b.querySelectorAll(".quota-labels > span:first-child")].map((e) => e.textContent))); + assert(names.some((n) => JSON.stringify(n) === JSON.stringify(["Claude Opus 5.5", "Gemini 3.8 Flash", "GPT-OSS 120B"])), "the models listed: " + JSON.stringify(names)); + assert.equal(await sub.locator("button.quota-every").count(), 1, "no Every model (0) beside the one with models"); + assert.equal(names.filter((n) => n.length === 3).length, 3, "every account's three windows shown: " + JSON.stringify(names)); + assert.deepEqual(errors, []); + }); + } +}