routing: an account whose usage read failed says so, the reason on hover (X @iamforu_)

@iamforu_ on X: "antigravity-bridge在路由页面不显示额度". When a plugin's
usage read fails (the bridge's agy read timing out or erroring), its Usage
card holds an error and no windows. cardOf dropped such a card, so
Routing's accounts list and stage said "what's left not known yet", with
no reason, while the Usage page showed why. A row whose card says its
read failed now says "Allowance unavailable — hover for why" (the line
remote rows already use, translated in every language), with the card's
error on hover: the list's status line title, and the stage row's
tooltip. A card with windows keeps them; an account with no card at all
stays "not known yet".

A bridge-shaped probe plugin (two accounts through auth.set, aside
windows, 8s reads) gave matching, error-free cards from
fetchSubscriptionUsage, and the Routing page drew them in a group's
accounts and on its stage, so successful bridge reads already showed;
the gap was the failed read. The probe was not committed.

Run (mica; mote's load was over its cores), at e513cba54 + this change:
- routing-card-error.test.cjs (new; chromium + webkit, en/zh/zh-TW/ja/de,
  1100 and 420px): 22 of 22 pass; with client.js from e513cba54 it is
  22 of 22 red (the failed-read line never appears).
- every routing-*.test.cjs and i18n-*.test.cjs: 3306 of 3324 pass at
  load ~100. The reds' files run alone at load ~25: routing-fold-all,
  -stage-routes and -many-keys pass; routing-signin, -row-swap, -pin-away
  and -story-shrinks fail the same 15 with e513cba54's client.js, filed
  as #6520, #3799, #6512 and #3954.
Not tried: the reporter's real antigravity-bridge account; the failure
was built from the plugin's error-card shape.
This commit is contained in:
yetone
2026-11-15 02:00:23 +08:00
parent 0968cc68a4
commit dd9cd59a17
2 changed files with 132 additions and 5 deletions
+18 -5
View File
@@ -3131,7 +3131,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 = (!day && winsOf(w)[0]) || t("what's left not known yet");
} else if (w.kind === "account") s = (!day && winsOf(w)[0]) || (!day && cardError(w) ? t("Allowance unavailable — hover for why") : 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 });
@@ -3158,7 +3158,7 @@ function routingPage(part) {
// (#1835): the row says the fullest one while idle and what it is
// doing while it answers, and a second line on every seat would
// crowd the stage. Live only, as the list's are (winsOf).
const tip = [w.id, ...(day ? [] : winsOf(w))].join("\n");
const tip = [w.id, ...(day ? [] : [...winsOf(w), cardError(w)].filter(Boolean))].join("\n");
if (row.li.title !== tip) row.li.title = tip;
const bar = w.known && !w.free && w.balance == null;
row.li.classList.toggle("nobar", !bar);
@@ -4806,11 +4806,22 @@ function routingPage(part) {
// when there is none, or it holds no windows. Nothing is read for it:
// the readings are app.js's quotas, as the Usage page has them.
function cardOf(w) {
const q = cardFor(w);
return q && !q.error && q.windows?.length ? q : null;
}
function cardFor(w) {
if (w.kind !== "account" || !Array.isArray(quotas)) return null;
const user = (w.who || "").trim().toLowerCase();
const mine = quotas.filter((q) => !q.from && q.kind === "subscription" && (q.provider === w.agent || q.provider === w.provider));
const q = mine.find((q) => (q.user || "").trim().toLowerCase() === user) || (mine.length === 1 && !mine[0].user ? mine[0] : null);
return q && !q.error && q.windows?.length ? q : null;
return mine.find((q) => (q.user || "").trim().toLowerCase() === user) || (mine.length === 1 && !mine[0].user ? mine[0] : null);
}
// cardError: why the Usage page could not read the account, when its
// card says so (iamforu_ on X: an antigravity-bridge account whose
// plugin failed to read its usage read "not known yet" on Routing,
// with no word of why, while Usage had the reason)
function cardError(w) {
const q = cardFor(w);
return q && !cardOf(w) && q.error ? String(q.error) : "";
}
// foldQuota: what a fold's accounts have left together, from the Usage
// page's readings (mergeQuotas), as its strip of all of a provider's
@@ -5075,7 +5086,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 = "", carded = false;
let st, cls = "", asOf = "", carded = false, readError = "";
const resting = a.rest && at(a.rest.until) > n, grid = winsBy.get(a);
// its models resting alone, while the account answers its others:
// a line of their own, naming them, under what the account has left
@@ -5099,6 +5110,7 @@ function routingPage(part) {
// 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 if (!day && (readError = cardError(w))) st = t("Allowance unavailable — hover for why");
else st = t("what's left not known yet");
} else st = "";
const tally = el("div", "tally");
@@ -5122,6 +5134,7 @@ function routingPage(part) {
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");
else if (readError) stEl.title = readError;
row.append(name, stEl);
if (grid) {
// one line a window: its short name, a bar, what is used or left,
@@ -0,0 +1,114 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// X (@iamforu_): "antigravity-bridge在路由页面不显示额度". The plugin's usage
// read failed for the account, so its Usage card held an error and no
// windows, and Routing said "what's left not known yet" with no word of why.
// A row whose card says its read failed now says the allowance is
// unavailable, with the card's reason on hover, in the accounts list and on
// the stage; an account with a card read keeps its windows, and one with no
// card at all stays unknown. 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 why = "agy usage: timed out after 18s";
const accts = [
{ id: "antigravity-bridge", provider: "antigravity-bridge", name: "antigravity-bridge", who: "saasortsfed", kind: "account", agent: "antigravity-bridge", model: "gemini-3.8-flash", known: false },
{ id: "antigravity-bridge#profile-aa", provider: "antigravity-bridge", name: "antigravity-bridge", who: "minhaco", kind: "account", agent: "antigravity-bridge", model: "gemini-3.8-flash", known: false, shared: true },
{ id: "antigravity-bridge#profile-bb", provider: "antigravity-bridge", name: "antigravity-bridge", who: "nocard", kind: "account", agent: "antigravity-bridge", model: "gemini-3.8-flash", known: false },
];
const route = {
id: 7, seq: 7, time: iso(now - 2000), agent: "claude", model: "gemini-flash-latest", provider: "group/gemini-flash-latest", done: true, status: 200, ms: 900, tokens: 1500,
order: accts, tries: [{ id: "antigravity-bridge", model: "gemini-3.8-flash", start: iso(now - 2000), done: true, ms: 800, status: 200 }],
};
const cards = [
{ provider: "antigravity-bridge", name: "antigravity-bridge", kind: "subscription", user: "saasortsfed", windows: [
{ name: "Gemini · 5 hours", used: 40, aside: true, resetsAt: iso(now + 130 * 60e3) },
{ name: "Gemini · 7 days", used: 12, aside: true },
] },
{ provider: "antigravity-bridge", name: "antigravity-bridge", kind: "subscription", user: "minhaco", windows: [], error: why },
];
function serve(lang, asks) {
const state = { agents: [{ id: "claude", 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: ["Allowance unavailable — hover for why", "what's left not known yet"],
zh: ["暂时无法获取额度 — 悬停查看原因", "剩余额度未知"],
"zh-TW": ["暫時無法取得額度 — 懸停查看原因", "剩餘額度未知"],
ja: ["利用枠を取得できません — ホバーで理由を表示", "残りはまだ不明"],
de: ["Kontingent nicht verfügbar — für den Grund darüberfahren", "Rest noch unbekannt"],
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: a plugin account whose usage read failed says why, 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 [bad, unknown] = words[lang];
// the accounts list: the failed read says so, its reason on hover
const act = page.locator(".rt-act", { hasText: "minhaco" }).first();
await act.waitFor();
await page.waitForFunction((bad) => [...document.querySelectorAll(".rt-act")].some((e) => e.textContent.includes("minhaco") && e.textContent.includes(bad)), bad);
const st = act.locator(".st");
assert.equal((await st.textContent()).trim(), bad);
assert.equal(await st.getAttribute("title"), why);
// a read card keeps its windows; no card at all stays unknown
const ok = page.locator(".rt-act", { hasText: "saasortsfed" }).first();
assert.ok((await ok.textContent()).includes("40%"), "the read card's windows");
const none = page.locator(".rt-act", { hasText: "nocard" }).first();
assert.ok(!(await none.textContent()).includes(bad), "no card is not a failed read");
if (unknown) assert.ok((await none.textContent()).includes(unknown), "no card stays unknown");
// the stage: the row says it too, the reason in its tooltip
const row = page.locator(".rt-stage li", { hasText: "minhaco" }).first();
await row.waitFor();
assert.ok((await row.textContent()).includes(bad), "stage: " + (await row.textContent()));
assert.ok((await row.getAttribute("title")).split("\n").includes(why));
const over = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth);
assert.ok(over <= 1, `${lang} at ${width}: ${over}px past`);
assert.deepEqual(errors, []);
} finally {
await ctx.close();
}
});
}
}
});
}