usage: three tests hold the clock, so midnight never falls between a call and Today (#6486)

TestAliasCallsAreTheGatewaysNotDirect stamped its direct call 6 minutes
before time.Now() and asked Direct(Today), so in the six minutes after
local midnight the call was yesterday's: red on mote at 00:00 PST and on
macOS CI at 00:07 UTC (run 43523008440). TestLoopsCountedPerModel and
TestRequestsCountedOnceWithTheirRetries do the same with stamps up to 9 s
back (same class). All three now take their time from holdClock at a
fixed noon, as TestPeriodsReadTheClock does.

Run (mica, at 783b69b8c + this):
- the three tests -count=3 in TZ=UTC and TZ=Asia/Shanghai: ok
  (and in UTC, Asia/Shanghai, America/Los_Angeles on mote: ok)
- broken by hand: held at 00:00:03 instead of noon, all three red
  (gateway_alias_test.go:44 "0 calls", loop_count_test.go:55,
  retried_requests_test.go:55), so they read the held clock
- go test -count=1 ./internal/usage: ok 53s; go vet ./internal/usage: ok
Not run: the full suite (test-only change in one package).
Not changed: #6474 (TestWalletCapHolds, the 5 minutes before midnight)
is another package's sibling and stays open.
This commit is contained in:
yetone
2026-11-14 08:31:52 +08:00
parent 783b69b8cf
commit f53c4a1a14
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ import (
// alias, a row for a model that is none, its cost counted twice. A call under
// a model of the agent's own stays (it never went through the gateway).
func TestAliasCallsAreTheGatewaysNotDirect(t *testing.T) {
now := time.Now()
now := holdClock(t, time.Date(2026, 9, 30, 12, 0, 0, 0, time.Local)) // midnight never falls between a call and Today (#6486)
tk := sessions.Tokens{Input: 120, Output: 40}
logs := []sessions.Call{
{Time: now.Add(-1 * time.Minute), Agent: "claude-desktop", Session: "s1", Model: "magpie-7416897221.anthropic.claude-opus-5-5", Tokens: tk},
+1 -1
View File
@@ -19,7 +19,7 @@ func TestLoopsCountedPerModel(t *testing.T) {
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
now := time.Now()
now := holdClock(t, time.Date(2026, 9, 30, 12, 0, 0, 0, time.Local)) // midnight never falls between a call and Today (#6486)
at := func(m int) string { return now.Add(time.Duration(m-10) * time.Second).Format(time.RFC3339Nano) }
lines := []string{
// two replies of kimi ended for looping, as the gateway logs them:
+1 -1
View File
@@ -21,7 +21,7 @@ func TestRequestsCountedOnceWithTheirRetries(t *testing.T) {
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
now := time.Now()
now := holdClock(t, time.Date(2026, 9, 30, 12, 0, 0, 0, time.Local)) // midnight never falls between a call and Today (#6486)
at := func(m int) string { return now.Add(time.Duration(m-10) * time.Second).Format(time.RFC3339Nano) }
lines := []string{
// written before handed_on: a safety refusal that a group's next