provider: TestWalletCapHolds holds its clock at local noon (#6474)

The test read the wallet at time.Now() plus 1 to 5 minutes. A run that
started within 5 minutes of local midnight read the later balances in the
next day, the wallet's daily spend started again, and the cap checks
failed: red on mote at 23:56 PST and on macOS CI at 00:00:12 UTC (run
43653589915, "500 of 10,000 spent, cap 4: held <nil>"). Every function on
the path (withWalletSpend, allowanceOf, CapHeld) takes its time as an
argument, so the test now starts from today's local noon, as f53c4a1a1
did for three usage tests.

Run (mica, at origin/main 0dbdc7481 + this):
- TestWallet* and TestPluginWalletCapHolds, -count=2, in TZ=UTC,
  Asia/Shanghai and America/Los_Angeles: ok
- broken by hand: held at 23:57 instead of noon, red at
  wallet_spend_test.go:123 with SpentSince the next day's 00:00, the
  same failure as CI's

Not tried: the full suite (a test-only change in one test).
This commit is contained in:
yetone
2026-11-15 08:24:18 +08:00
parent 0dbdc7481c
commit 6af327e2b3
+4 -1
View File
@@ -83,7 +83,10 @@ func TestWalletSpendCounted(t *testing.T) {
// and the cap holds it.
func TestWalletCapHolds(t *testing.T) {
signIn(t)
now := time.Now()
// today's local noon, so the reads up to 5 minutes on never cross
// into the next day and restart its spend (#6474)
y, m, d := time.Now().Date()
now := time.Date(y, m, d, 12, 0, 0, 0, time.Local)
if err := SetAccountCap("codex", "me@example.com", 4); err != nil {
t.Fatal(err)
}