usage: the Overview read again keeps its cards and its place, and shows it is reading
jiabubu on Discord: a refresh of the Usage page's Overview showed nothing while it read, flashed the page and dropped cards for a moment, and pressing Usage again while on the Overview flashed it or moved its scroll. - Pressing Usage again (show() calls the plugin's open, loadUsage(true)) put the skeleton up, which hid the sections, collapsed the page and clamped its scrollTop. loadUsage now puts the skeleton up only for a first read or another period or zone (usageFor/usageKey); a page that already shows that read reads again quietly through refreshUsage, so nothing is blanked and the scroll stays. - The refresh beside the period turns while such a read is out (#usageReload.reading, after 200ms), and while every card is read (loadQuotas) each card's refresh turns (#subscriptionUsage.reading, quotaReading in page.js). A card's own busy turn is left to its own animation (:not(.busy)). No turning under reduced motion. - renderQuotas draws the cards again in one go, as their reset countdowns need, but now keeps their logo nodes (keepIcons), and the Overview's lists do too: a logo made afresh blinked out while its picture loaded. - app.js stays in its budget: a three-line comment in renderQuotas cut to one. Core 1,533,507 of 1,533,802 before the rebase on0b4cda048. Tests: - New usage-quiet-refresh.test.cjs: Usage pressed again at the top, halfway and at the foot, with the read held: no skeleton, chart not hidden, scrollTop the same, the refresh turning, then the same figure, row and logo nodes; and Refresh with the allowances held: every card stays, each card's refresh is shown and turning, the logos kept. Chromium and WebKit, en and zh, 1180 and 560px. Red on the old assets (8 of 8 per part: "nothing blanked while it reads ['skeleton','chart hidden']", "the cards' logos are the ones drawn before: false,false, false"), green on the new. - usage-quota-head.test.cjs waited for the skeleton on Agents -> Usage; it now waits for the quiet read (the page kept, the refresh turning). - usage-stale-answer.test.cjs lifts loadUsage out of page.js; it now lifts usageFor/usageKey with it and stubs the page's loading state. Run on mote (mote-run), at the rebased head 344cdcde3: go test -run TestCoreScriptBudget ./internal/gui ok; gofmt -l clean; the nine usage, quota and panel files above plus panel-fit-tabs, panel-usage and panel-quota-refresh: 140 of 140. Before the rebase (at d32a7a70c's base, same change less the stale-answer stub): go test ./internal/gui ok apart from TestSettingsSaveKeepsWhatItDoesNotSend, fixed on main by c7c05dcf2; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... clean; every GUI file named usage, quota, allowance, click-scroll, sidebar or last-page (129 files, 1880 tests): red only in files red on main too or filed: usage-agents-hide (#2276, #3414, red atd32a7a70calone), usage-fold (#3415, red atd32a7a70calone), usage-ledger's Requests (#5048), and usage-compact-counts' zh-TW 420px tip under load (#5648, 30 of 30 alone); usage-stale-answer's reds there are fixed here (11 of 11). Not tried: the whole GUI suite (1,274 files; mote at load 60 to 80 from other sessions), the real app and WebKitGTK, languages beyond en and zh in the new test (no new strings), and the other pages' re-open by probe (Sessions, Library, Gateway and Masking were read: none puts a skeleton up over a page already drawn). Reported-by: jiabubu (Discord)
This commit is contained in:
@@ -82,6 +82,17 @@ it; `renderPanelQuota` puts the focus back on the button after the redraw.
|
||||
`panel-quota-refresh.test.cjs` covers it in both engines, all five
|
||||
languages, at 440 and 360px.
|
||||
Redrawing the cards preserves their refresh controls and any running turn.
|
||||
A read of every card (`loadQuotas`) draws the cards again in one go, as
|
||||
their reset countdowns need, but keeps each card's logo node
|
||||
(`keepIcons` in `renderQuotas`): a logo made afresh blinks out while its
|
||||
picture loads. While such a read is on its way for longer than 200 ms,
|
||||
`#subscriptionUsage` is `.reading` and each card's refresh turns
|
||||
(`quotaReading` in `plugins/usage/page.js`). The Overview's skeleton
|
||||
(`renderUsageLoading`) is put up only for a first read or another period
|
||||
or zone (`usageFor`); its tab pressed again while it shows that read reads
|
||||
quietly (`refreshUsage`), so no card leaves and the scroll stays put, and
|
||||
the refresh beside the period turns while it reads. Its lists keep their
|
||||
logos too. See `usage-quiet-refresh.test.cjs` (jiabubu on Discord).
|
||||
The reply updates the reading immediately; the icon then finishes its
|
||||
current full turn before stopping (no rotation under reduced motion).
|
||||
A manual refresh whose HTTP reply succeeds but whose requested card has
|
||||
|
||||
@@ -1179,17 +1179,17 @@ body.masked :hover > .acct-eye, body.masked .pq-card:hover .acct-eye, body.maske
|
||||
/* Inherited text supplies the inline baseline; the icon shares its centered cell. */
|
||||
.quota-refresh::before { content: "\00a0"; grid-area: 1 / 1; }
|
||||
.quota-refresh svg { grid-area: 1 / 1; }
|
||||
.subscription-card:hover .quota-refresh, .pq-card:hover .quota-refresh, .quota-refresh.busy, .quota-refresh.kept, .quota-refresh.reading { width: 14px; margin: 0 -2px 0 3px; opacity: 1; }
|
||||
.subscription-card:hover .quota-refresh, .pq-card:hover .quota-refresh, .quota-refresh.busy, .quota-refresh.kept, .quota-refresh.reading, #subscriptionUsage.reading .quota-refresh { width: 14px; margin: 0 -2px 0 3px; opacity: 1; }
|
||||
/* apart: Safari before 15.4 drops a whole selector list with :focus-visible in it */
|
||||
.quota-refresh:focus-visible { width: 14px; margin: 0 -2px 0 3px; opacity: 1; }
|
||||
.quota-refresh:hover { color: var(--fg); background: var(--pill-hover); }
|
||||
.quota-refresh.busy { cursor: default; }
|
||||
.quota-refresh.busy svg > *, .quota-refresh.reading svg > * { transform-box: view-box; transform-origin: 50% 50%; }
|
||||
.quota-refresh.busy svg > *, .quota-refresh.reading svg > *, #subscriptionUsage.reading .quota-refresh svg > * { transform-box: view-box; transform-origin: 50% 50%; }
|
||||
/* the other place's copy of a control that is turning (the tray panel's and the
|
||||
Usage page's draw the same account) turns by itself, as does a card kept
|
||||
from the last read while it is read again */
|
||||
.quota-refresh.spun svg > *, .quota-refresh.reading svg > * { animation: spin .8s linear infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .quota-refresh.spun svg > *, .quota-refresh.reading svg > * { animation: none; } }
|
||||
.quota-refresh.spun svg > *, .quota-refresh.reading svg > *, #subscriptionUsage.reading .quota-refresh:not(.busy) svg > * { animation: spin .8s linear infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .quota-refresh.spun svg > *, .quota-refresh.reading svg > *, #subscriptionUsage.reading .quota-refresh:not(.busy) svg > * { animation: none; } }
|
||||
@media (hover: none) { .quota-refresh { width: 14px; margin: 0 -2px 0 3px; opacity: 1; } }
|
||||
@media (prefers-reduced-motion: reduce) { .quota-refresh { transition: none; } }
|
||||
.skeleton { display: block; border-radius: 5px; background: linear-gradient(90deg, var(--skel, var(--pill)) 25%, var(--skel-hi, var(--pill-hover)) 45%, var(--skel, var(--pill)) 65%); background-size: 240% 100%; animation: skeleton-shift 1.4s ease-in-out infinite; }
|
||||
@@ -4501,7 +4501,7 @@ body.panel .modal { padding: 16px 12px; }
|
||||
/* how often the Usage page reads its numbers again, and a way to read them now */
|
||||
.usage-refresh { display: inline-flex; align-items: center; gap: 2px; margin-right: 10px; }
|
||||
.usage-refresh .icon { width: 24px; height: 24px; }
|
||||
.usage-refresh .icon.busy svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .8s linear infinite; }
|
||||
.usage-refresh .icon.busy svg > *, .usage-refresh .icon.reading svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .8s linear infinite; }
|
||||
.usage-refresh .sess-pick { height: 24px; }
|
||||
.led-rank .rk .rk-b { overflow-wrap: anywhere; }
|
||||
|
||||
|
||||
@@ -15796,6 +15796,7 @@ function loadQuotas(asked, again) {
|
||||
});
|
||||
p.asked = asked;
|
||||
quotasLoading = p;
|
||||
if (mode !== "panel") globalThis.quotaReading?.(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -15909,10 +15910,9 @@ function renderQuotas(lazy) {
|
||||
const subscriptions = $("#subscriptionUsage");
|
||||
const restoreFlash = keepQuotaFlash(subscriptions);
|
||||
const restoreRefresh = keepQuotaRefresh(subscriptions);
|
||||
const was = [...subscriptions.children];
|
||||
subscriptions.replaceChildren();
|
||||
// the allowances' own heading, apart from the period's cost: used or
|
||||
// left turns their meters, and is only there when some card has one (a
|
||||
// balance is only ever what is left)
|
||||
// the allowances' heading: used or left, shown with a card that has one
|
||||
$("#quotaHead").hidden = !!quotas && !quotas.length;
|
||||
const pick = $("#quotaMode");
|
||||
pick.hidden = !quotas?.some((q) => !q.error && q.windows?.length);
|
||||
@@ -15945,6 +15945,7 @@ function renderQuotas(lazy) {
|
||||
subscriptions.hidden = !shown.length;
|
||||
// an agent with several accounts is one card, a section per account
|
||||
const groups = [];
|
||||
keepIcons(...was);
|
||||
for (const sub of byUsageOrder(keyCards(shown))) {
|
||||
const g = sub.user && groups.find((x) => x[0].user && x[0].provider === sub.provider);
|
||||
if (g) g.push(sub); else groups.push([sub]);
|
||||
@@ -16067,6 +16068,7 @@ function renderQuotas(lazy) {
|
||||
if (accts && (folded.size || usageAcctsAll.has(first.provider))) card.append(acctsMore(first.provider, folded.size));
|
||||
subscriptions.append(card);
|
||||
}
|
||||
keptIcons = null;
|
||||
markUpstream();
|
||||
packUsageNow(subscriptions);
|
||||
restoreFlash();
|
||||
|
||||
@@ -178,14 +178,42 @@ async function loadUsage(asked) {
|
||||
if (usageTab === "sessions") return loadSessions();
|
||||
if (usageTab === "requests") return loadLedger(asked && ledger && ledgerWant === ledParams({ offset: ledOffset, limit: LED_PAGE }) ? "open" : false);
|
||||
if (usageTab === "context") return window.loadContext?.();
|
||||
// the figures on hand are this period's: opened again (its tab pressed
|
||||
// while on it, the Overview's tab) they stay, and are read again behind
|
||||
// them as the timer reads them, so the page neither empties nor moves
|
||||
// (jiabubu on Discord)
|
||||
if (asked && usage && usageFor === usageKey() && !$("#view-usage").classList.contains("loading")) return refreshUsage();
|
||||
renderUsageLoading();
|
||||
if (!asked) loadQuotas();
|
||||
const p = period, read = ++usageRead;
|
||||
const p = period, k = usageKey(), read = ++usageRead;
|
||||
const next = await api("usage?period=" + encodeURIComponent(p) + usageZoneQ());
|
||||
if (read !== usageRead || view !== "usage" || usageTab !== "usage" || period !== p) return;
|
||||
usage = next;
|
||||
usage = next; usageFor = k;
|
||||
renderUsage();
|
||||
}
|
||||
// usageFor: the period and zone the figures on hand (usage) were read for
|
||||
let usageFor = "";
|
||||
const usageKey = () => period + usageZoneQ();
|
||||
// A read past a moment shows as one: the refresh turns (on the Overview each
|
||||
// card's with it), and nothing on the page is taken out (jiabubu on Discord)
|
||||
const readingN = new WeakMap();
|
||||
function usageReading(p, box) {
|
||||
let on = false;
|
||||
const tm = setTimeout(() => { on = true; readingN.set(box, (readingN.get(box) || 0) + 1); box.classList.add("reading"); }, 200);
|
||||
const done = () => {
|
||||
clearTimeout(tm);
|
||||
if (!on) return;
|
||||
const n = readingN.get(box) - 1;
|
||||
readingN.set(box, n);
|
||||
if (!n) box.classList.remove("reading");
|
||||
};
|
||||
p.then(done, done);
|
||||
}
|
||||
// the allowances' whole read (loadQuotas, app.js)
|
||||
function quotaReading(p) {
|
||||
const b = $("#subscriptionUsage");
|
||||
if (b) usageReading(p, b);
|
||||
}
|
||||
|
||||
// the period picker, in the page's head, for the Overview and Requests
|
||||
function renderPeriod(loading) {
|
||||
@@ -729,6 +757,7 @@ function renderUsage() {
|
||||
const total = Math.max(1, usageTokens(u));
|
||||
const list = (id, groups, act) => {
|
||||
const box = typeof id === "string" ? $("#" + id) : id;
|
||||
keepIcons(box); // a logo made again blinks (keepIcons)
|
||||
box.replaceChildren();
|
||||
for (const g of groups) {
|
||||
const r = el("div", "row stat");
|
||||
@@ -780,6 +809,7 @@ function renderUsage() {
|
||||
if (act) act(r, g);
|
||||
box.append(r);
|
||||
}
|
||||
keptIcons = null;
|
||||
};
|
||||
// a client hidden from the Agents list (ikunbots on X: curl,
|
||||
// Go-http-client, python-httpx beside the agents in use) is left out of
|
||||
@@ -4238,9 +4268,10 @@ function refreshUsage(now = false) {
|
||||
if (want) { quotasAsked = performance.now(); q = loadQuotas("all"); }
|
||||
else if (usage && performance.now() - quotasAsked > 60e3) { quotasAsked = performance.now(); loadQuotas(); }
|
||||
if (usage) {
|
||||
const p = period, read = ++usageRead;
|
||||
const p = period, k = usageKey(), read = ++usageRead;
|
||||
const u = await api("usage?period=" + encodeURIComponent(p) + usageZoneQ());
|
||||
if (read === usageRead && view === "usage" && usageTab === "usage" && p === period) {
|
||||
usageFor = k;
|
||||
if (JSON.stringify(u) !== JSON.stringify(usage)) { usage = u; renderUsage(); }
|
||||
// this read claimed the newest one: a pick it superseded had put the
|
||||
// skeleton up, and the figures on hand are what ends it
|
||||
@@ -4263,6 +4294,7 @@ function refreshUsage(now = false) {
|
||||
return refreshUsage(want);
|
||||
});
|
||||
usageFlight = flight;
|
||||
usageReading(flight, $("#usageReload"));
|
||||
return flight;
|
||||
}
|
||||
renderUsageEvery();
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The Usage page's Overview read again stays as it is (jiabubu on Discord):
|
||||
// - its tab pressed again while it is open (at the top, halfway down, at the
|
||||
// foot) neither puts the skeleton up nor moves the page: the figures, the
|
||||
// rows and the cards' logos are the same nodes, no card leaves, scrollTop the same, and the
|
||||
// refresh beside the period turns while the read is on its way;
|
||||
// - a refresh of the allowances leaves every card on the page, each card's
|
||||
// refresh turning while it is read, and keeps the logos it drew (a logo
|
||||
// made afresh blinks out while its picture loads again).
|
||||
// No backend, the API is faked and its reads held.
|
||||
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_QUIET_ASSETS || path.resolve(__dirname, "../assets"));
|
||||
const H = 3600e3;
|
||||
const iso = (ms) => new Date(ms).toISOString();
|
||||
const midnight = new Date();
|
||||
midnight.setHours(0, 0, 0, 0);
|
||||
|
||||
// enough rows that the page scrolls
|
||||
function overview() {
|
||||
const series = Array.from({ length: 7 }, (_, i) => ({ label: "D" + i, time: iso(midnight.getTime() - (6 - i) * 864e5), calls: i + 1, errors: 0, input: 800 * (i + 1), output: 200 * (i + 1), cost: 0.01 }));
|
||||
const row = (n, icon) => ({ id: "r" + n, name: "Row " + n, icon, calls: 3, errors: 0, input: 1000 + n, output: 100, cache_read: 0, cost: 0.01 });
|
||||
return {
|
||||
calls: 28, errors: 0, input: 22400, output: 5600, cache_read: 0, cache_write: 0, reasoning: 0, unpriced: 0, cost: 0.28, bucket: "day", series,
|
||||
agents: Array.from({ length: 14 }, (_, i) => row(i, i % 2 ? "codex-color" : "claude-color")),
|
||||
models: Array.from({ length: 14 }, (_, i) => row(100 + i, "openai")),
|
||||
path: "~/.config/magpie/usage.jsonl",
|
||||
};
|
||||
}
|
||||
function cards(now) {
|
||||
return [
|
||||
{ provider: "claude", name: "Claude Code", icon: "claude-color", plan: "Max", user: "a@x.com", readAt: iso(now - 60e3), windows: [{ name: "5 hours", used: 28, resetsAt: iso(now + 2 * H) }] },
|
||||
{ provider: "codex", name: "Codex", icon: "openai", plan: "Plus", user: "b@x.com", readAt: iso(now - 60e3), windows: [{ name: "5 hours", used: 50, resetsAt: iso(now + 2 * H) }] },
|
||||
{ provider: "kimi", name: "Kimi", icon: "kimi-color", readAt: iso(now - 60e3), windows: [{ name: "Week", used: 10, resetsAt: iso(now + 50 * H) }] },
|
||||
];
|
||||
}
|
||||
|
||||
function serve(lang, st) {
|
||||
const settings = { theme: "light", lang, quotaLeft: false, currency: "usd" };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (body) => route.fulfill({ json: body });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
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/usage") { st.usage++; await st.usageGate; return json(overview()); }
|
||||
if (url.pathname === "/api/usage/quotas") { st.quotas++; await st.quotaGate; st.quotasDone++; return json(cards(st.now)); }
|
||||
if (url.pathname === "/api/usage/quotas/history") return json([]);
|
||||
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
||||
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 }); }
|
||||
};
|
||||
}
|
||||
|
||||
// the cards are drawn again with each read of the allowances (their resets
|
||||
// count down only so), in one go: their logos are what is kept
|
||||
const KEEP = "#stats .kpi, #chart .bar, #usageAgents .row, #usageModels .row, #usageAgents .ic, #subscriptionUsage .subscription-card .ic";
|
||||
// tag what is drawn now, and note from now on a skeleton, a card count
|
||||
// falling, or the chart hidden
|
||||
function watch(p) {
|
||||
return p.evaluate((sel) => {
|
||||
let n = 0;
|
||||
for (const e of document.querySelectorAll(sel)) e.__keep = ++n;
|
||||
window.__seen = [];
|
||||
window.__cards = document.querySelectorAll("#subscriptionUsage .subscription-card:not(.skeleton-card)").length;
|
||||
const note = (w) => { if (!window.__seen.includes(w)) window.__seen.push(w); };
|
||||
new MutationObserver((ms) => {
|
||||
if (document.querySelectorAll("#subscriptionUsage .subscription-card:not(.skeleton-card)").length < window.__cards) note("a card taken out");
|
||||
for (const m of ms) {
|
||||
if (m.type === "attributes" && m.attributeName === "class" && m.target.id === "view-usage" && m.target.classList.contains("loading")) note("skeleton");
|
||||
if (m.type === "attributes" && m.attributeName === "hidden" && m.target.id === "chart" && m.target.hidden) note("chart hidden");
|
||||
}
|
||||
}).observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ["hidden", "class"] });
|
||||
}, KEEP);
|
||||
}
|
||||
const lost = (p) => p.evaluate((sel) => [...document.querySelectorAll(sel)].filter((e) => !e.__keep).map((e) => e.className + " " + (e.dataset.icon || "")).slice(0, 5), KEEP);
|
||||
const seen = (p) => p.evaluate(() => window.__seen);
|
||||
const waitFor = async (p, fn, what) => {
|
||||
for (let i = 0; i < 150; i++) { if (await fn()) return; await p.waitForTimeout(20); }
|
||||
assert.fail("timed out waiting for " + what);
|
||||
};
|
||||
// true once fn is, false if it never is within ~1.5s
|
||||
const comes = async (p, fn) => {
|
||||
for (let i = 0; i < 75; i++) { if (await fn()) return true; await p.waitForTimeout(20); }
|
||||
return false;
|
||||
};
|
||||
|
||||
// the reader's wheel to a place: the page puts back a scroll it didn't ask for
|
||||
async function wheelTo(p, where) {
|
||||
const v = p.locator("#view-usage");
|
||||
const b = await v.boundingBox();
|
||||
await p.mouse.move(b.x + b.width / 2, b.y + b.height / 2);
|
||||
const target = await v.evaluate((e, w) => Math.round(w * (e.scrollHeight - e.clientHeight)), where);
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const at = await v.evaluate((e) => e.scrollTop);
|
||||
if (Math.abs(at - target) < 60 || (where === 1 && at >= target - 1)) break;
|
||||
await p.mouse.wheel(0, Math.sign(target - at) * Math.min(200, Math.abs(target - at)));
|
||||
await p.waitForTimeout(40);
|
||||
}
|
||||
await p.waitForTimeout(400);
|
||||
return v.evaluate((e) => e.scrollTop);
|
||||
}
|
||||
|
||||
const LANGS = (process.env.LANGS || "en,zh").split(",");
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of LANGS) {
|
||||
for (const [width, height] of [[1180, 640], [560, 640]]) {
|
||||
test(`${engine} ${lang} ${width}px: the Overview read again keeps its cards and its place`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const p = await (await browser.newContext({ viewport: { width, height }, reducedMotion: "no-preference" })).newPage();
|
||||
p.setDefaultTimeout(8000);
|
||||
p.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
p.on("pageerror", (e) => errors.push(e.message));
|
||||
const st = { usage: 0, quotas: 0, quotasDone: 0, now: Date.now(), usageGate: null, quotaGate: null };
|
||||
await p.route("**/*", serve(lang, st));
|
||||
await p.goto("http://magpie.test/?view=usage");
|
||||
await p.locator("#subscriptionUsage .subscription-card:not(.skeleton-card)").nth(2).waitFor();
|
||||
await p.locator("#usageModels .row").nth(13).waitFor();
|
||||
await p.waitForTimeout(500);
|
||||
const nav = p.locator('#nav button[data-view="usage"]');
|
||||
assert.equal(await nav.isVisible(), true, "the Usage tab is in the sidebar");
|
||||
|
||||
// its tab pressed again, at the top, halfway down and at the foot
|
||||
for (const where of process.env.QUIET_PART === "cards" ? [] : [0, 0.5, 1]) {
|
||||
const at = await wheelTo(p, where);
|
||||
if (where) assert(at > 50, `the page scrolled (${at})`);
|
||||
await watch(p);
|
||||
let open;
|
||||
st.usageGate = new Promise((r) => { open = r; });
|
||||
const before = st.usage;
|
||||
await nav.click();
|
||||
await waitFor(p, async () => st.usage > before, "the read again");
|
||||
// on its way: the refresh beside the period turns, nothing moved
|
||||
const turned = await comes(p, () => p.locator("#usageReload.reading").count());
|
||||
assert.deepEqual(await seen(p), [], `${where}: nothing blanked while it reads`);
|
||||
assert.equal(await p.locator("#view-usage").evaluate((e) => e.scrollTop), at, `${where}: the page stays while it reads`);
|
||||
assert(turned, `${where}: the refresh turns while it reads`);
|
||||
open(); st.usageGate = null;
|
||||
await waitFor(p, async () => !(await p.locator("#usageReload.reading").count()), "the refresh stopping");
|
||||
await p.waitForTimeout(300);
|
||||
assert.deepEqual(await seen(p), [], `${where}: nothing blanked`);
|
||||
assert.deepEqual(await lost(p), [], `${where}: the same figures, rows and logos`);
|
||||
assert(Math.abs(await p.locator("#view-usage").evaluate((e) => e.scrollTop) - at) <= 1, `${where}: the page didn't move`);
|
||||
}
|
||||
|
||||
// the allowances read again (Refresh): every card stays, each one's
|
||||
// refresh turns while it is read, their logos are kept
|
||||
await wheelTo(p, 0);
|
||||
await watch(p);
|
||||
let release;
|
||||
st.quotaGate = new Promise((r) => { release = r; });
|
||||
const q = st.quotas;
|
||||
await p.locator("#usageReload").click();
|
||||
await waitFor(p, async () => st.quotas > q, "the allowances read");
|
||||
const spin = p.locator("#subscriptionUsage .subscription-card .quota-refresh");
|
||||
const reading = await comes(p, () => p.locator("#subscriptionUsage.reading").count());
|
||||
const shown = reading && await comes(p, async () => (await spin.first().evaluate((b) => b.getBoundingClientRect().width)) > 0);
|
||||
const turning = shown && (engine !== "chromium" || await spin.first().evaluate((b) => b.querySelector("svg > *").getAnimations().length > 0));
|
||||
st.now += 30e3; // the answer differs: the cards are drawn again
|
||||
release(); st.quotaGate = null;
|
||||
await waitFor(p, async () => st.quotasDone > q && !(await p.locator("#subscriptionUsage.reading").count()), "the cards done");
|
||||
await p.waitForTimeout(300);
|
||||
assert.equal(await p.locator("#subscriptionUsage .subscription-card:not(.skeleton-card)").count(), 3);
|
||||
assert.deepEqual(await seen(p), [], "no card taken out, no skeleton");
|
||||
const logos = await p.evaluate(() => [...document.querySelectorAll("#subscriptionUsage .subscription-card .ic")].map((e) => !!e.__keep));
|
||||
assert(logos.length >= 3 && logos.every(Boolean), "the cards' logos are the ones drawn before: " + logos);
|
||||
assert(reading && shown && turning, `each card's refresh turns while they are read (${reading}, ${shown}, ${turning})`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,11 +70,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
gate.quotas = gate.usage;
|
||||
await page.click('nav button[data-view="agents"], button[data-view="agents"]');
|
||||
await page.click('button[data-view="usage"]');
|
||||
await page.waitForFunction(() => document.querySelector("#view-usage").classList.contains("loading"));
|
||||
// the page shown before stays while it reads again (jiabubu on Discord)
|
||||
await page.waitForFunction(() => document.querySelector("#usageReload.reading"));
|
||||
assert.equal(await head.isVisible(), true, "the head went while the page loaded");
|
||||
assert.equal(await page.locator(".subscription-card", { hasText: "Codex" }).isVisible(), true);
|
||||
free();
|
||||
await page.waitForFunction(() => !document.querySelector("#view-usage").classList.contains("loading"));
|
||||
await page.waitForFunction(() => !document.querySelector("#usageReload.reading, #view-usage.loading"));
|
||||
assert.equal(await head.isVisible(), true);
|
||||
|
||||
// a period without calls keeps it over its cards
|
||||
|
||||
@@ -40,6 +40,13 @@ const loadUsageSource = lift("async function loadUsage(asked) {");
|
||||
const gap = source.match(/^const QUOTAS_OPEN_GAP = [^;\n]+;$/m);
|
||||
assert.ok(gap, "app.js no longer has const QUOTAS_OPEN_GAP");
|
||||
const quotasOpenedSource = gap[0] + "\nlet quotasAskedAt = -Infinity;\n" + lift("function quotasOpened() {");
|
||||
// what the figures on the page were read for (a period and a zone): beside
|
||||
// loadUsage in page.js
|
||||
const usageForSource = ["let usageFor = ", "const usageKey = "].map((h) => {
|
||||
const line = source.split("\n").find((l) => l.startsWith(h));
|
||||
assert.ok(line, `page.js no longer has ${h}`);
|
||||
return line;
|
||||
}).join("\n");
|
||||
|
||||
// values cross the vm's realm boundary (its Array and Object are not the
|
||||
// test's), so what is handed to assert is copied into this one first
|
||||
@@ -67,11 +74,15 @@ function renderUsage() { drawn.push({ period, usage: usage && usage.tag }); }
|
||||
function renderUsageTab() {}
|
||||
function renderUsageEvery() {}
|
||||
function renderUsageLoading() {}
|
||||
// the skeleton is up: an asked read draws as a pick does (a page already
|
||||
// drawn read again quietly is usage-quiet-refresh.test.cjs's)
|
||||
function $() { return { classList: { contains: () => true } }; }
|
||||
function loadQuotas(asked) { quotaCalls.push(asked === true); if (asked) quotasAskedAt = performance.now(); }
|
||||
function loadSessions() { return Promise.resolve("sessions"); }
|
||||
function loadLedger() { return Promise.resolve("requests"); }
|
||||
`,
|
||||
quotasOpenedSource,
|
||||
usageForSource,
|
||||
loadUsageSource,
|
||||
`
|
||||
globalThis.page = {
|
||||
@@ -204,11 +215,13 @@ function renderUsage() { loading = false; drawn.push({ period, usage: usage && u
|
||||
function renderUsageTab() {}
|
||||
function renderUsageEvery() {}
|
||||
function renderUsageLoading() { loading = true; }
|
||||
function usageReading() {} // the refresh turning: usage-quiet-refresh.test.cjs
|
||||
function loadQuotas(asked) { quotaCalls.push(asked === true); if (asked) quotasAskedAt = performance.now(); return Promise.resolve(); }
|
||||
function loadSessions() { return Promise.resolve("sessions"); }
|
||||
function loadLedger() { return Promise.resolve("requests"); }
|
||||
`,
|
||||
quotasOpenedSource,
|
||||
usageForSource,
|
||||
loadUsageSource,
|
||||
refreshSource,
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user