From 2f5e75515e61bb687540818350a19cd6beddd44f Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 04:38:51 +0800 Subject: [PATCH] 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 --- internal/gateway/key_limit_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/gateway/key_limit_test.go b/internal/gateway/key_limit_test.go index e81b9213b..5814e0fa6 100644 --- a/internal/gateway/key_limit_test.go +++ b/internal/gateway/key_limit_test.go @@ -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() {