providers: every window on an account row says when it resets, not only one 80% used
An account row in a provider's editor read "5 hours 100% used resets in 1h · 7 days 23% used": the reset was shown only for a window at 80% or more, the others' left to the tooltip (rosarobertist on X, tweet 2116366943146139998: 能在这儿加个重置时间吗?这样就能做到心中有数了). The data had it: Claude's seven_day and Codex's secondary_window both carry their reset, and the Usage page, the menu bar tooltip, the TUI and `magpie accounts` already showed it. accountQuota now appends "resets in 6d" to every window that has a reset. The line already wraps per window, so a narrow sheet takes it on a second line. Not changed: a pooled account's line (Antigravity's Gemini / Claude & GPT pools, poolLine) keeps its resets in the tooltip; four windows with a reset each don't fit a pool's unwrapped meter at a phone's width. The Usage page's brief accounts (several on one card) keep theirs in the tooltip too, as before; opened, they show it. Tests: internal/gui/tests/account-every-reset.test.cjs, Claude Code and Codex rows, en/zh/zh-TW/ja/de, 1000px, 560px and a 390px web page: each window's reset text and that it stays in the row, no sideways scroll. - mote (mote-run), Chromium: ok. On the old app.js (MAGPIE_ACC_ASSETS) red in both engines' runs: '' where 'resets in 6d' was expected. - mote, WebKit: browserType.launch times out (180s) on mote now, with ten stale pw_run.sh launches from other runs hanging there; a bare webkit.launch() probe times out too. Not a test failure; WebKit and the files this can reach (account-row-line, account-cap, window-cap, quota-pools, quota-families, reset-providers, gui-de/ja/zh-tw, i18n-keys and 11 more account-row files) are running in both engines on the Linux VM (wsl-run) after this push; any red gets its own issue. No Go changed; no new strings.
This commit is contained in:
@@ -13881,7 +13881,9 @@ function accountQuota(data, user, capFor = () => 0, settable = null) {
|
||||
if (w.resetsAt) {
|
||||
const at = new Date(w.resetsAt);
|
||||
m.title = resetText(at, at.toLocaleString(intlLang()));
|
||||
if (used >= 80) m.append(el("span", "aq-r", resetInText(at)));
|
||||
// every window's, not only a nearly used one's: the week's at 23%
|
||||
// is what the user plans by too (rosarobertist on X)
|
||||
m.append(el("span", "aq-r", resetInText(at)));
|
||||
}
|
||||
const out = runsOutText(w, (at) => at.toLocaleString(intlLang()));
|
||||
if (out) m.title = tipLines(m.title, out);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Every window on a provider editor's account row says when it resets, not
|
||||
// only one nearly used up (rosarobertist on X: 能在这儿加个重置时间吗?这样
|
||||
// 就能做到心中有数了). The row read "5 hours 100% used resets in 1h · 7 days
|
||||
// 23% used" — the week's reset was left to the tooltip below 80%. Claude
|
||||
// Code and Codex accounts, every language, Chromium and WebKit, at a desk's
|
||||
// width, the window's narrowest and a phone's: the reset stays in the row
|
||||
// and the sheet doesn't scroll sideways. MAGPIE_ACC_ASSETS runs it on older
|
||||
// assets.
|
||||
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(process.env.MAGPIE_ACC_ASSETS || path.resolve(__dirname, "../assets"));
|
||||
const soon = new Date(Date.now() + 2 * 36e5).toISOString();
|
||||
const week = new Date(Date.now() + (6 * 24 + 1) * 36e5).toISOString();
|
||||
const provider = (id, name, icon, user) => ({
|
||||
id, name, icon, chat: "", responses: "", anthropic: "", catalog: "", routing: "",
|
||||
models: [{ id: "m", name: "", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: { agent: id, agentName: name, user, plan: "pro", logins: [{ user, plan: "pro", active: true, on: true }] },
|
||||
});
|
||||
const providers = [provider("claude", "Claude Code", "claude-color", "me@example.com"), provider("codex", "Codex", "codex-color", "you@example.com")];
|
||||
const windows = () => [{ name: "5 hours", used: 100, resetsAt: soon }, { name: "7 days", used: 23, resetsAt: week }];
|
||||
const serve = (lang, web) => 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:${JSON.stringify(lang)},theme:"light",web:${web}};` });
|
||||
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", quotaLeft: false } });
|
||||
if (url.pathname === "/api/providers") return json({ providers, presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/login/usage") {
|
||||
const agent = url.searchParams.get("agent");
|
||||
const p = providers.find((x) => x.id === agent);
|
||||
return json(p ? { [p.account.user]: { provider: agent, windows: windows(), asOf: new Date(Date.now() - 6e4).toISOString(), readDeferred: true } } : {});
|
||||
}
|
||||
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 langs = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
for (const [engine, browserType] of [["chromium", chromium], ["webkit", webkit]]) {
|
||||
test(engine + ": every window on an account row says when it resets", async (t) => {
|
||||
const browser = await browserType.launch();
|
||||
t.after(() => browser.close());
|
||||
for (const [web, width] of [[false, 1000], [false, 560], [true, 390]]) for (const lang of langs) for (const p of providers) {
|
||||
const at = `${p.name} ${lang} ${web ? "web " : ""}${width}`;
|
||||
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, web));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: p.name }).first().click();
|
||||
const row = page.locator(`.editor .acc[data-account-id="${p.account.user}"]`);
|
||||
await row.locator(".aq-w").nth(1).waitFor();
|
||||
// the words the row should say, in its language
|
||||
const want = await page.evaluate((lang) => {
|
||||
const tr = (k, v) => Object.entries(v).reduce((s, [n, x]) => s.replace("{" + n + "}", x), (lang === "en" ? k : I18N[lang][k]) || k);
|
||||
return [tr("resets {in}", { in: tr("in {n}h", { n: 2 }) }), tr("resets {in}", { in: tr("in {n}d", { n: 6 }) })];
|
||||
}, lang);
|
||||
const got = await row.locator(".aq-w").evaluateAll((ms) => ms.map((m) => m.querySelector(".aq-r")?.textContent || ""));
|
||||
assert.deepEqual(got, want, `${at}: the 5 hours and the 7 days each say when they reset`);
|
||||
// in the row, and the sheet not scrolling sideways
|
||||
const fit = await row.evaluate((r) => {
|
||||
const rb = r.getBoundingClientRect(), body = document.querySelector(".modal .ebody");
|
||||
return { out: [...r.querySelectorAll(".aq-w")].map((m) => Math.round(m.getBoundingClientRect().right - rb.right)), wide: body ? body.scrollWidth - body.clientWidth : 0 };
|
||||
});
|
||||
for (const o of fit.out) assert.ok(o <= 0, `${at}: a window's reset stays in its row (${o}px past it)`);
|
||||
assert.ok(fit.wide <= 0, `${at}: the sheet doesn't scroll sideways (${fit.wide}px)`);
|
||||
assert.deepEqual(errors, [], at);
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user