From 40c8d0c81aeba506e40dae078e7f0029b93f2a73 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 12 Nov 2026 03:51:33 +0800 Subject: [PATCH] routing: an account whose windows are all set aside shows what the Usage page read, not "not known" (@apple_test_src on X) A Cursor account signed in through its plugin (pooled plan, or on-demand or free credit that can pay) sets every window aside, since none can stop the account. Routing's allowance then holds no figure for it, so the Accounts and keys row (and the stage row) said "what's left not known yet" while the Usage page showed its percentages. This is true of any plugin-served subscription that sets all its windows aside, not only Cursor. Both Routing rows now say the card's first window (as Usage read it) when routing has no figure, the rest on hover; with no card the unknown line stays. Display only: how accounts are weighed is unchanged. Run: new routing-pooled-card.test.cjs (5 languages, 1100/420px, chromium and webkit) 22 pass; red 22 of 22 with client.js put back to origin/main's (broken by hand). Routing, i18n-keys, use-first, account-mask and codex-credits GUI files on mote: the only reds are in routing-context-fold, routing-pin-away, routing-row-swap, routing-story-shrinks, many-keys and accounts-narrow; the first four fail the same on the origin/main client.js (umbrella #4494, #5475). Not tried: a real Cursor account; the Go suite starts after the tag. --- internal/gui/assets/plugins/routing/client.js | 16 ++- .../gui/tests/routing-pooled-card.test.cjs | 110 ++++++++++++++++++ 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 internal/gui/tests/routing-pooled-card.test.cjs diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 31ba42a6a..82097250d 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -3022,7 +3022,7 @@ function routingPage(part) { : b === "sooner" && soon ? quota(w, "{n} used · renews in {d} · one renewing sooner goes first", "{n} left · renews in {d} · one renewing sooner goes first", { d: dur(soon - n) }) : b === "expires" && soon ? quota(w, "{n} used · renews in {d} · one whose credits expire sooner goes first", "{n} left · renews in {d} · one whose credits expire sooner goes first", { d: dur(soon - n) }) : soon ? quota(w, "{n} used · renews in {d}", "{n} left · renews in {d}", { d: dur(soon - n) }) : quota(w, "{n} used", "{n} left"); - } else if (w.kind === "account") s = t("what's left not known yet"); + } else if (w.kind === "account") s = (!day && winsOf(w)[0]) || t("what's left not known yet"); else if (w.routing === "usage") s = t("{n} tokens lately", { n: tokens(w.tokens || 0) }); else if (w.aside) s = t("{api} only · after the others", { api: API[w.speaks] || w.speaks || t("any API") }); else if (w.speaks) s = t("{api} only", { api: API[w.speaks] || w.speaks }); @@ -4896,7 +4896,7 @@ function routingPage(part) { // a provider's own row: its model, the provider's name is the heading if (w.kind === "provider") name.append(el("b", "", w.model || w.name)); else name.append(el("b", "", who(w)), el("span", "", planName(w.plan) || (w.kind === "key" ? t("API key") : ""))); - let st, cls = "", asOf = ""; + let st, cls = "", asOf = "", carded = false; const resting = a.rest && at(a.rest.until) > n; // its models resting alone, while the account answers its others: // a line of their own, naming them, under what the account has left @@ -4912,8 +4912,14 @@ function routingPage(part) { // when it was read is on hover: the line says what is left and // when it renews, on one line in every language (danzi002) if (!(soon && soon <= n)) asOf = t("as of {time}", { time: clock(a.at) }); - } else if (w.kind === "account") st = t("what's left not known yet"); - else st = ""; + } else if (w.kind === "account") { + // routing weighs no figure for it (every window of its card is set + // aside, as a plugin's pooled Cursor plan is), but the Usage page + // read what it has left: that is said, not "not known" (X) + const card = day ? [] : winsOf(w); + if (card.length) { st = card[0]; carded = true; } + else st = t("what's left not known yet"); + } else st = ""; const tally = el("div", "tally"); // refused for its sign-in, and not answered since: it is to be signed // in again, here where the card says so. Answered since, the @@ -4932,7 +4938,7 @@ function routingPage(part) { // routing went by, the others on hover and on the Usage page. Live // only: a kept day's requests were weighed by readings long gone. const ws = day ? [] : [...winsOf(w).map((text) => ({ text })), ...remoteWinsOf(w)]; - const figure = !!st && (resting || w.known || w.unlisted || w.noURL); + const figure = !!st && (resting || w.known || w.unlisted || w.noURL || carded); if (resting && restTip(a.rest)) stEl.title = restTip(a.rest); else if (figure && (ws.length || asOf)) stEl.title = [...ws.map((x) => x.text), asOf].filter(Boolean).join("\n"); row.append(name, stEl); diff --git a/internal/gui/tests/routing-pooled-card.test.cjs b/internal/gui/tests/routing-pooled-card.test.cjs new file mode 100644 index 000000000..242a97abd --- /dev/null +++ b/internal/gui/tests/routing-pooled-card.test.cjs @@ -0,0 +1,110 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// X (@apple_test_src): a Cursor account signed in through its plugin showed +// "what's left not known yet" in Routing's Accounts and keys while the Usage +// page read its allowance. Every window of a pooled Cursor plan is set aside +// (it can't stop the account), so routing weighs no figure for it, and the +// row said nothing was known. It now says the card's first window, as the +// Usage page read it, the rest on hover; the unknown line stays for an +// account with no card. Every language, 1100 and 420px, both engines. +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 now = Date.now(); +const iso = (ms) => new Date(ms).toISOString(); +const accts = [ + { id: "cursor", provider: "cursor", name: "Cursor", who: "work@example.com", kind: "account", agent: "cursor", model: "claude-opus-5", known: false, plan: "Pro" }, + { id: "cursor@spare", provider: "cursor", name: "Cursor", who: "spare@example.com", kind: "account", agent: "cursor", model: "claude-opus-5", known: false, plan: "Pro" }, +]; +const route = { + id: 7, seq: 7, time: iso(now - 2000), agent: "cursor", model: "claude-opus-5", provider: "cursor", done: true, status: 200, ms: 900, tokens: 1500, + order: accts, tries: [{ id: "cursor", model: "claude-opus-5", start: iso(now - 2000), done: true, ms: 800, status: 200 }], +}; +const cards = [ + { provider: "cursor", name: "Cursor", kind: "subscription", user: "Work@Example.com", plan: "Max", windows: [ + { name: "5 hours", used: 40, aside: true, resetsAt: iso(now + 130 * 60e3) }, + { name: "7 days", used: 12, aside: true, resetsAt: iso(now + 73 * 3600e3) }, + ] }, + // another computer's reading of the spare account: not this one's + { provider: "cursor", name: "Cursor · Home", kind: "subscription", user: "spare@example.com", from: "Home", windows: [{ name: "5 hours", used: 90 }] }, +]; + +function serve(lang, asks) { + const state = { agents: [{ id: "cursor", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light", quotaLeft: false } }; + return async (r) => { + const url = new URL(r.request().url()); + const json = (data) => r.fulfill({ json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes + return json({ mine: true, now: new Date().toISOString(), seq: 7, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [route] }); + } + if (url.pathname === "/api/usage/quotas") { asks.push(url.search); return json(cards); } + if (url.pathname === "/api/usage/quotas/history") return json([]); + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + 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)]; + await r.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const words = { + en: ["5 hours 40% used · resets in 2h", "7 days 12% used · resets in 3d"], + zh: ["5 小时 已用 40% · 2 小时后重置", "7 天 已用 12% · 3 天后重置"], + "zh-TW": ["5 小時 已用 40% · 2 小時後重置", "7 天 已用 12% · 3 天后重置"], + ja: ["5 時間 使用済み 40% · 2 時間後にリセット", "7 日 使用済み 12% · 3 日後にリセット"], + de: ["5 Stunden 40% verbraucht · Reset in 2 Std.", "7 Tage 12% verbraucht · Reset in 3 T."], +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(`${engine}: a plugin account whose windows are all aside shows them, not unknown`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + for (const lang of Object.keys(words)) { + for (const width of [1100, 420]) { + await t.test(`${lang} at ${width}px`, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" }); + try { + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], asks = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, asks)); + await page.goto("http://magpie.test/?view=routing"); + const act = page.locator(".rt-act", { hasText: "work@example.com" }).first(); + // the one figure routing went by, the windows each on hover over + // it: a card keeps one line of what is left (ferock4669 on + // Discord), and when it was read comes last on hover (danzi002) + await act.waitFor(); + // the card's first window is the row's figure, the second on hover + await page.waitForFunction((want) => [...document.querySelectorAll(".rt-act")].some((e) => e.textContent.includes("work@example.com") && e.querySelector(".st")?.textContent === want), words[lang][0]); + assert.equal((await act.locator(".st").getAttribute("title")).split("\n").slice(0, 2).join("\n"), words[lang].join("\n")); + assert.equal(await act.locator(".wins").count(), 0); + // no card of its own (another computer's isn't this one's): unknown + const spare = page.locator(".rt-act", { hasText: "spare@example.com" }).first(); + await spare.waitFor(); + assert.notEqual(await spare.locator(".st").textContent(), words[lang][0]); + assert.equal(await spare.locator(".wins").count(), 0); + // nothing in the row runs past the list + const over = await act.evaluate((e) => Math.max(e.scrollWidth - e.clientWidth, document.documentElement.scrollWidth - innerWidth)); + assert.ok(over <= 1, `${lang} at ${width}: ${over}px past`); + assert.ok(asks.length >= 1, "the readings were asked for"); + assert.ok(asks.every((s) => !s.includes("asked")), "never an asked read: " + asks.join(", ")); + assert.deepEqual(errors, []); + } finally { + await ctx.close(); + } + }); + } + } + }); +}