Ported from NorethSea's fork (abed2e224) and re-derived on main.
What it does:
- A known reset ends a dry run (a stretch where a window read 0% left), even
when the next poll sees the refill later. A stale dry reading taken after
its own reset no longer extends the run. Calls from the reset on are not
treated as "maybe paid from credits".
- A refill observed later than reset minus span
(QuotaPoint.StartsCycleAfter, the boundaries history sampling keeps)
starts what is reckoned. Calls before a fixed-deadline refill stay in the
cycle before it. A first reading is not a reset.
- Picking a past cycle in Usage > Allowances > Trends > Cycle asks
GET /api/usage/quotas/history/holds once per selection
(quotaCycleHoldsOf). The route asks no vendor. HistoricalWindowHolds
reckons each window at its own last reading in the cycle, using the
ledger and readings from before that reading. "Loading..." shows while it
is pending. An answer for a cycle no longer picked is dropped. The card's
Refresh, or an asked read, reckons again. The estimate's tooltip names the
window's start and the reading's time.
Changed from the fork:
- After a run closed at its reset, the fork reset lastLeft to zero. A
window that ran dry again before its next reset then opened a run from
time zero, which hid every window's estimate, the weekly one included.
The next run now starts no earlier than that reset.
TestWindowHoldsDryAgainAfterReset covers it (red with the fork's line).
- The fork narrowed the live card's Span to the observed refill. Span also
feeds provider.WithWindowStarts, so the window's Pace would have moved.
withSpansOf puts the card's spans back after reckoning. A span assertion
in TestWindowHoldsUsesObservedRefillStart covers it (red without it).
- The fork's historical snapshot dropped the card's Balance. That slipped
past the gate a live card has (holdsBounds), so a card that tells a
balance got past-cycle estimates. Balance is now kept. Covered in
TestHistoricalWindowHoldsUsesEachWindowsOwnReading (red without it). The
fork's fixture had a Codex card with a Balance, which no Codex card has.
- Main has since added HoldsWhy (#2045). The fork's own "Whole: not enough
reliable data" line and its .quota-holds-unknown CSS are left out. A past
cycle uses main's holdsUnknownLine and its reasons, as a live card does.
A window with neither an estimate nor a reason shows nothing, where the
fork showed its unknown line.
- withRecordedWindowStarts is ported to main's holdsBounds(start, end, why).
- quota-refresh-order.test.cjs's VM harness now stubs quotaCycleHolds,
which loadQuotas and quotaRefresh clear.
Left out: nothing else from the fork. Past prices aren't kept, so a past
cycle's cost uses today's API list prices (documented). Credits can't be
attributed per call, so none is attempted (documented).
What was run:
- gofmt -l: clean. go vet -tags nogui ./... for GOOS darwin, linux and windows.
- go test -tags nogui ./internal/usage ./internal/gui ./internal/provider:
ok.
- Each of the three fixes above was reverted by hand, and its test went red.
- GUI, Chromium and WebKit:
- quota-curve: 30/30. Also run at 1100 and 420 wide: 60/60 (all five
languages).
- Also: quota-*, i18n-keys, gui-de/ja/zh-tw, usage-card-refresh,
usage-refresh*, usage-stale-answer, usage-remote-cards,
usage-accounts*, usage-quota-head, usage-pack and usage-alert.
- Reds: quota-count-wrap and quota-name-translated are red in WebKit,
the same as on origin/main 707fbb249. Filed as #2228.
- The GUI break-check (main's !sub.history gate put back) turns the new
quota-curve test red.
- Full suite: SUITE_LINE
Co-authored-by: NorethSea <963979204@qq.com>