Routing's request list showed "缓存 100%" for Codex requests of 77.5K
tokens that read 77,200 of them from the cache (99.6%), beside rows at
99%, and the route line said "请求缓存命中率 99%". Every hit rate was
Math.round(100 * h) + "%", so anything from 99.5% up read 100%.
One formatter now says every hit rate: hitPct(h, d) in app.js, whole
percents (d decimals) unless rounding would say 100% or 0% of a prompt
not all or none cached, then one or two decimals (99.6%, 99.95%; never
past 99.99% or under 0.01%). Its callers: Routing's request rows, their
route line and a session's Avg. cache (plugins/routing/client.js); the
tray panel's Cache hit rate and the ranking rows' hit rate (app.js); the
Usage page's tiles, agent rows, Requests table, request detail and its
KPI strip, which keeps its one decimal (plugins/usage/page.js); the
context card's Prompt cache and the session traits Cache-friendly,
Cache misses and Cache hit (context.js). The TUI's and CLI's sessions
line, which floored the integer, use usage.HitPct, the same rule in Go;
it rounds now, so the TUI test's 67% (25.2K of 37.3K, 67.6%) reads 68%.
No new strings; app.js pays its bytes with six ledger comments cut, so
the core scripts are 15 bytes smaller than at its parent, no raise. Main
is over the core budget already (1,534,476 > 1,533,802 at the parent,
#5918); this commit doesn't add to it.
Run on mote:
- new internal/gui/tests/cache-hit-pct.test.cjs (Routing rows 99.6% /
100% / 99%, the route line, hitPct at its edges) in chromium and
webkit, en and zh: green; with the escalation line removed by hand,
red (99.99% where 99.6% is wanted).
- cache-hit-pct, panel-usage, context-window, i18n-keys, usage-ledger,
tray-totals, ctx-route, ledger-cache-hit, usage-hit-rate,
routing-request-metrics (both engines; ledger-cache-unknown and
ledger-cache-tokens in an earlier run): 186 pass, 6 red, all in
usage-ledger's 'newest live route needs no return-to-live button',
red the same on origin/main 00e8242e8 (#5048, #4078).
- go test ./internal/usage ./internal/cli ./internal/tui: ok, with
TestHitPctNeverRoundsToAllOrNone and a 99.6% case in
TestHitRateCountsCacheWrites (red on the old floor: 99%).
- go test ./internal/gui at the first base: TestCoreScriptBudget ok; one red,
TestGatewayModeStatsNameTheGatewaySessions, run at 00:25 local (#5690,
the first hour of a local day).
- gofmt; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
At the pushed head (rebased, comments cut): cache-hit-pct and
routing-request-metrics again, both engines, 8 of 8.
Not tried: the real app's window, or GUI files beyond those above (a
65-file run waited on mote's suite lock behind four full suites).
22 lines
676 B
Go
22 lines
676 B
Go
package usage
|
|
|
|
import "testing"
|
|
|
|
// A hit rate never reads 100% unless every prompt token was cached, nor 0%
|
|
// when any was: rounding that would hide the difference shows a decimal or
|
|
// two instead (ZhangXiaof48473 on X: Codex requests read "缓存 100%").
|
|
func TestHitPctNeverRoundsToAllOrNone(t *testing.T) {
|
|
for _, c := range []struct {
|
|
h float64
|
|
want string
|
|
}{
|
|
{1, "100%"}, {0, "0%"}, {0.6, "60%"}, {0.994, "99%"},
|
|
{77200.0 / 77500, "99.6%"}, {0.9995, "99.95%"}, {0.99999, "99.99%"},
|
|
{0.003, "0.3%"}, {0.0004, "0.04%"}, {0.0000001, "0.01%"},
|
|
} {
|
|
if got := HitPct(c.h); got != c.want {
|
|
t.Errorf("HitPct(%v) = %q, want %q", c.h, got, c.want)
|
|
}
|
|
}
|
|
}
|