gateway: the reservation test reads an account window it can cross (#6706)

6256d9956 added the "account" period to access.Periods, and
TestKeyLimitReservationsStayInTheirWindow, which runs every period, went
red for it: with no account reading the window's reset is unknown, so by
design it never resets and the reservation stays. The test now gives the
account's 5 hours through provider.AccountWindowVia, as internal/budget's
account_test.go does, so the boundary it crosses is a real one.

Run (mote, at ab08a9e7c + this change):
- go test -count=1 -run TestKeyLimitReservationsStayInTheirWindow
  ./internal/gateway: ok; -v shows account/tokens and account/cost run.
- Broken by hand: the stub answering known=false turns both account
  subtests red, as on main.
- Earlier, at 6256d9956: go test . ./internal/access ./internal/budget
  ./internal/tui ./internal/gateway: all ok but this test in gateway.
Not run: the whole gateway package again after the change.

Fixes #6706
This commit is contained in:
yetone
2026-11-15 04:38:51 +08:00
parent ab08a9e7c1
commit 2f5e75515e
+15
View File
@@ -276,6 +276,21 @@ func TestKeyLimitReservationsStayInTheirWindow(t *testing.T) {
if period == "days" {
lim.Days, lim.Since = 3, at.Add(-50*time.Hour)
}
if period == "account" {
// the account's 5 hours, read: each begins where the last ended
// (a window not read holds its reservations, internal/budget's
// account_test.go)
lim.Account, lim.AccountWindow = "codex/me@example.com", "5h"
origin := at.Add(-2 * time.Hour)
t.Cleanup(provider.AccountWindowVia(func(_, _ string, now time.Time) (time.Time, time.Time, bool) {
n := now.Sub(origin) / (5 * time.Hour)
if now.Before(origin) {
n--
}
start := origin.Add(n * 5 * time.Hour)
return start, start.Add(5 * time.Hour), true
}))
}
_, after := lim.Window(at)
before := after.Add(-time.Second)
reserve := func(at time.Time) func() {