From ffd3949dcbae4c2f5dbfca107618b7327e2e0513 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 2 Oct 2026 16:42:46 +0800 Subject: [PATCH] =?UTF-8?q?usage:=20the=20token=20total's=20line=20names?= =?UTF-8?q?=20the=20cache=20too,=20so=20in=20and=20out=20don't=20look=20li?= =?UTF-8?q?ke=20they=20should=20add=20up=20to=20it=20(John=20on=20Discord:?= =?UTF-8?q?=20=E8=BF=99=E4=B8=AA=E6=80=BB=E9=87=8F=E5=92=8C=E8=BE=93?= =?UTF-8?q?=E5=85=A5+=E8=BE=93=E5=87=BA=E4=B8=8D=E7=9B=B8=E7=AD=89?= =?UTF-8?q?=EF=BC=8C=E6=98=AFbug=E4=B9=88=EF=BC=9F)=20=E2=80=94=20the=20Us?= =?UTF-8?q?age=20card's=20Tokens=20total=20counts=20input,=20output,=20cac?= =?UTF-8?q?he=20reads=20and=20cache=20writes=20(allTokens),=20but=20the=20?= =?UTF-8?q?line=20under=20it=20named=20only=20input=20and=20output,=20so?= =?UTF-8?q?=2095M=20over=20"6.5M=20in=20=C2=B7=20785K=20out"=20looked=20wr?= =?UTF-8?q?ong;=20with=20a=2093%=20cache=20hit=20rate=20nearly=20all=20of?= =?UTF-8?q?=20it=20is=20cache=20reads.=20The=20line=20now=20ends=20"=C2=B7?= =?UTF-8?q?=20{n}=20cached"=20(=E7=BC=93=E5=AD=98=20{n})=20with=20the=20ca?= =?UTF-8?q?che's=20reads=20and=20writes=20when=20there=20are=20any.=20pane?= =?UTF-8?q?l-usage.test.cjs=20checks=20the=20cache=20is=20named=20under=20?= =?UTF-8?q?the=20total=20(en=20and=20zh);=20the=20extra=20line=20pushes=20?= =?UTF-8?q?the=20provider=20ranking=20down=20to=20the=20footer's=20edge=20?= =?UTF-8?q?in=20the=20test's=20560px=20panel,=20where=20WebKit=20takes=20a?= =?UTF-8?q?=20half-hidden=20row=20as=20in=20view=20and=20clicks=20the=20fo?= =?UTF-8?q?oter,=20so=20the=20test=20scrolls=20it=20in=20with=20the=20whee?= =?UTF-8?q?l=20first,=20as=20a=20reader=20would.=20panel-usage,=20number-u?= =?UTF-8?q?nits,=20click-scroll,=20usage-ledger=20pass=20in=20WebKit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.js | 4 +++- internal/gui/tests/panel-usage.test.cjs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 4f16e2e28..95d83efc5 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -8424,7 +8424,9 @@ function renderPanelUse() { if (sub) b.append(el("span", "sub" + (subCls ? " " + subCls : ""), sub)); tot.append(b); }; - blk("Tokens", fmtN(allTokens(l)), t("{a} in · {b} out", { a: fmtN(l.input), b: fmtN(l.output) })); + // the total counts the cache's tokens too, so they're named beside in and out + const cached = l.cache_read + l.cache_write; + blk("Tokens", fmtN(allTokens(l)), t("{a} in · {b} out", { a: fmtN(l.input), b: fmtN(l.output) }) + (cached ? " · " + t("{n} cached", { n: fmtN(cached) }) : "")); blk("Requests", ledNum(l.calls), l.errors ? t("{n} failed", { n: ledNum(l.errors) }) : t("none failed"), "", l.errors ? "bad" : ""); const c = fmtCost(l); blk("Cost", c ? "≈" + c : "—", l.unpriced ? t("{n} unpriced", { n: l.unpriced }) : t("effective prices"), c ? "cost" : ""); diff --git a/internal/gui/tests/panel-usage.test.cjs b/internal/gui/tests/panel-usage.test.cjs index 26a4caaa7..1567e2d42 100644 --- a/internal/gui/tests/panel-usage.test.cjs +++ b/internal/gui/tests/panel-usage.test.cjs @@ -154,6 +154,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // Labels in the 440px panel must be readable, not clipped by ellipsis. assert(await p.locator("#panelUsage .pu-tot .blk").first().locator(".sub").evaluate(e => e.scrollWidth <= e.clientWidth + 1 && e.scrollHeight <= e.clientHeight + 1 && getComputedStyle(e).textOverflow !== "ellipsis"), "token input/output is fully visible"); + // the total counts the cache, so the line under it names the cache too, or in + out doesn't add up to it + assert((await p.locator("#panelUsage .pu-tot .blk").first().locator(".sub").textContent()).includes(lang === "zh" ? "缓存" : "cached"), "the cache under the token total"); // nothing runs out of the panel const over = await p.evaluate(() => [...document.querySelectorAll("#panelUsage *")].filter((e) => e.scrollWidth > e.clientWidth + 1 && getComputedStyle(e).overflow === "visible" && e.children.length === 0 && e.tagName !== "text").length); assert.equal(over, 0, "an element wider than itself"); @@ -196,6 +198,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await p.locator("#panelUsage .pu-bar .segs .opt").nth(0).click(); await settled(asked, (q) => q.get("period") === "today"); await p.locator("#panelUsage:not(.pu-loading)").waitFor(); + // half under the footer's edge, WebKit takes it as in view and clicks the footer: scroll it in whole, as a reader would + await p.locator("#panelUsage .pu-tot").hover(); + await p.mouse.wheel(0, 400); + await p.waitForFunction(() => document.querySelector("#panelUsage .led-rank .rk").getBoundingClientRect().bottom <= document.querySelector("footer.foot").getBoundingClientRect().top); await p.locator("#panelUsage .led-rank .rk").first().click(); await settled(asked, (q) => q.get("provider") === "anthropic"); await p.locator("#panelUsage .sess-pick", { hasText: "Claude" }).waitFor(); @@ -204,6 +210,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await p.locator("#panelUsage rect.col").evaluateAll((r) => [...new Set(r.map((x) => x.dataset.k))].sort().join()), "claude-opus-5,claude-sonnet-5"); // Open Usage takes the window to that provider's requests + await p.mouse.wheel(0, -400); await p.locator("#panelUsage .pu-bar .text").click(); for (let i = 0; i < 50 && !opened.length; i++) await p.waitForTimeout(40); assert.equal(opened.at(-1), "?view=usage&tab=requests&provider=anthropic");