panel: an allowance card says its booster's balance under its rings

apple_test_src on X: Kimi Code's booster (加油包) balance showed only on
the Usage page. The tray panel's Allowances card drew a balance window's
text line only when the card had no rings, so a card with 5-hour and
Week rings dropped "Extra usage"; the menu bar's tooltip left out every
Balance window. Now panelQuotaCard draws "Extra usage ¥X left" (in the
card's language) in a pq-sub line under the rings, sharing one filter
with the text line, and trayCardText adds the same line to the tooltip.
The menu bar's label is unchanged (its two percentages).

Budgets: app.js and core +17 each, reason in the constants.

Run (at 9227c83ab's tree, rebased on 22f8db6c9):
- Red on the old code: panel-quota-wallet.test.cjs (20 cases, chromium
  + webkit, en/zh/zh-TW/ja/de, 440 and 360 px) all fail against the old
  app.js; TestTrayTipSaysWalletLeft fails on the en tip against the old
  trayusage.go. Both green with the change.
- mote: go test ./internal/gui -run Tray|Budget ok after the rebase;
  panel-quota-wallet, panel-quota-kept, i18n-keys 44/44. go vet
  darwin, windows, linux nogui on ./internal/gui ok. gofmt clean.
- mica (before the rebase, at cd030691a): go test ./internal/gui ok.
- mote, 96 GUI files the change can reach (panel*, quota*, tray*, every
  file touching pq-card/pq-sub/panelQuota, i18n*), both engines:
  1503 tests, 84 fail in 11 files; the same 11 files fail the same way
  at base cd030691a: claude-quota-onboarding (#6179), codex-auto-reset
  (#3293), grip-inset (#6293), key-balance-card (#6414), panel-fold
  (#5796), panel-shortcut (#6606), quota-bars-alike (#6700, filed now),
  quota-curve (#4768), quota-refresh-order (#6180), tray-cell-click
  (#5215), usage-fold (#6003).

Not run: the whole GUI suite and go test ./... (mote and mica were each
running another session's full suite). Not tried in the real app with a
real Kimi booster; the window's shape is the one the Kimi probe returned
earlier (balance, unit CNY).
This commit is contained in:
yetone
2026-11-15 01:29:18 +08:00
parent 22f8db6c90
commit 51eb1ae4b6
5 changed files with 129 additions and 3 deletions
+5 -1
View File
@@ -17890,7 +17890,8 @@ function panelQuotaCard(q, first = false) {
// a pool's 5-hour and weekly rings, every pool's (a third pool once left
// Claude's out: 01huadalang on Discord), else three
const fam = familyWindows(q.windows.filter((w) => !w.unlimited && !quotaNoShare(w)));
const tx = q.windows.filter((w) => quotaNoShare(w)).map((w) => t(w.name) + " " + quotaText(w)).join(" · ");
const says = (f) => q.windows.filter(f).map((w) => t(w.name) + " " + quotaText(w)).join(" · ");
const tx = says(quotaNoShare), wallets = says((w) => w.balance != null);
if (!fam.length && (tx || q.windows.some((w) => w.unlimited))) {
card.append(pqLine(tx || t("Unlimited"), q));
if (balance) card.append(balance);
@@ -17937,6 +17938,9 @@ function panelQuotaCard(q, first = false) {
rings.append(r);
}
card.append(rings);
// a wallet beside the rings (Kimi Code's booster, "Extra usage"): what
// is left on it, not only on the Usage page (apple_test_src on X)
if (wallets) card.append(el("span", "pq-sub", wallets));
if (balance) card.append(balance);
// the first window's cycle, a thin line under the card (#651)
const spark = ws[0] && !ws[0].tiers ? quotaSpark(q, ws[0]) : null;
File diff suppressed because one or more lines are too long
@@ -0,0 +1,75 @@
// apple_test_src on X: Kimi Code's booster (加油包) showed only on the
// Usage page. The tray panel's Allowances card drew its 5-hour and weekly
// rings and left out a wallet window beside them; it now says what is left
// on it under the rings, in the reader's language, inside a narrow panel.
// Real page, isolated responses: no vendor or account is used.
// MAGPIE_QUOTA_ASSETS points at older assets to see it fail.
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 = process.env.MAGPIE_QUOTA_ASSETS || path.resolve(__dirname, "../assets");
const iso = n => new Date(n).toISOString();
function fixtures() {
const now = Date.now(), readAt = iso(now - 60000);
return [{
provider: "kimi-code", name: "Kimi Code", icon: "kimi", user: "k@example.com", plan: "Allegretto", readAt, windows: [
{ name: "5 hours", used: 30, resetsAt: iso(now + 2 * 3600000), credits: true },
{ name: "Week", used: 50, resetsAt: iso(now + 3 * 86400000), credits: true },
{ name: "Extra usage", balance: 98.5, unit: "CNY" },
],
}];
}
function serve(lang, data) {
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
return async route => {
const url = new URL(route.request().url()), json = body => route.fulfill({ json: body });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ 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" && url.searchParams.get("last")) return json({ agents: [], profiles: [], settings, last: true });
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(data.quotas); }
if (url.pathname === "/api/usage/quotas/history") return json([]);
if (url.pathname === "/api/usage") return json({ calls: 0, cost: 0, days: [], agents: [], models: [], keys: [] });
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 card = '#panelQuota .pq-card[data-card="kimi-code|k@example.com"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [440, 360]) {
test(`${engine} ${lang} ${width}px: an allowance card says its booster's balance under its rings`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width, height: 640 }, reducedMotion: "reduce" });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", e => errors.push(e.message));
await page.addInitScript(() => { try { localStorage.setItem("magpie.panelTab", "usage"); } catch {} });
await page.route("**/*", serve(lang, { quotas: fixtures() }));
await page.goto("http://magpie.test/?mode=panel");
await page.locator(`${card} .pq-dial b`, { hasText: "30%" }).waitFor();
const wallet = page.locator(`${card} .pq-rings + .pq-sub`);
await wallet.waitFor();
const text = (await wallet.textContent()).trim();
const want = await page.evaluate(() => t("Extra usage") + " " + t("{n} left", { n: "98.5 " + t("CNY") }));
assert.equal(text, want.trim());
if (lang !== "en") assert.ok(!text.includes("Extra usage"), `said in ${lang}: ${text}`);
assert.ok(await page.locator(`${card} .pq-ring`).count() === 2, "both rings stay");
const fits = await page.locator(card).evaluate(c => c.scrollWidth <= c.clientWidth + 1 && c.getBoundingClientRect().right <= innerWidth);
assert.ok(fits, "nothing runs out of the card");
assert.deepEqual(errors, []);
});
}
}
}
+12
View File
@@ -329,6 +329,18 @@ func trayCardText(lang string, q provider.SubscriptionQuota, now time.Time, left
}
long = append(long, line)
}
// a wallet beside the windows (Kimi Code's booster, "Extra usage"):
// what is left on it, as the card's line under its rings says it
for _, w := range q.Windows {
if w.Balance == nil {
continue
}
amt := strconv.FormatFloat(math.Round(*w.Balance*100)/100, 'f', -1, 64)
if u := pageWord(lang, w.Unit); u != "" {
amt += " " + u
}
long = append(long, trayWindowName(lang, w.Name)+" "+trayText(lang, "%s left", amt))
}
return strings.Join(short, " · "), q.Name + "\n" + strings.Join(long, "\n") + trayAsOf(lang, q)
}
+35
View File
@@ -0,0 +1,35 @@
package gui
import (
"strings"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// Kimi Code's booster (加油包) is a wallet window set aside beside the plan's
// windows. The menu bar's tooltip says what is left on it, as the panel's
// card does under its rings (apple_test_src on X: it showed only on the
// Usage page); the label stays the plan's percent.
func TestTrayTipSaysWalletLeft(t *testing.T) {
now := time.Now()
r5, r7 := now.Add(2*time.Hour), now.Add(72*time.Hour)
left := 98.5
q := provider.SubscriptionQuota{Provider: "kimi-code", Name: "Kimi Code", User: "k@example.com", Windows: []provider.QuotaWindow{
{Name: "5 hours", Used: 30, ResetsAt: &r5, Span: 5 * time.Hour},
{Name: "Week", Used: 50, ResetsAt: &r7, Span: 7 * 24 * time.Hour},
{Name: "Extra usage", Balance: &left, Unit: "CNY", Aside: true},
}}
label, tip := trayCardText("en", q, now, false, false, nil)
if label != "30% · 50%" {
t.Fatalf("label: %q", label)
}
if !strings.Contains(tip, "\nExtra usage 98.5 CNY left") {
t.Fatalf("en tip: %q", tip)
}
_, tip = trayCardText("zh", q, now, false, false, nil)
if strings.Contains(tip, "Extra usage") || !strings.Contains(tip, "剩余 98.5") {
t.Fatalf("zh tip: %q", tip)
}
}