Commit 4086526
test(auth): seed the pool quota after the clock is pinned (#3147)
* test(auth): seed the pool quota and credential after the clock is pinned
The websocket refresh test still failed on loaded CI runners after #3139, on
both macOS and Linux, and dev's own HEAD fails it too — so it was not something
any open branch introduced.
Two writes stamp real time when they run before the clock is pinned:
updateAccountQuota sets updatedAt: Date.now(), and saveCodexAccountCredential
sets replacedAt. Everything after the pin reads the pinned 2027 value, so the
gap is about 136 days against a 6-hour freshness window
(QUOTA_DISK_MAX_AGE_MS, src/codex/quota.ts:491). The seeded state reads as
stale no matter how fast the runner is, the startup pool-quota prime refreshes
the credential before the first turn is served, and seenAuth[0] is already the
new token — which is why the failure diff was always the first element.
#3139 pinned the clock and the fetch stub before startServer, closing the
window for the prime's own reads. It could not close a window for timestamps
written before either was in place. Both seeds now run after the pin.
Timing-dependent by nature: the mismatch does not reproduce locally either
before or after, so the evidence is the mechanism rather than a local
red-to-green. A 136-day gap against a 6-hour window is arithmetic, not a race.
Twelve consecutive local runs are clean.
* test(auth): restore the affinity test's quota seed after the pin
The previous commit removed `updateAccountQuota("pool-a", 10, 5)` from the
`expired thread affinity` test along with the websocket test's own seeds. That
seed belongs to the affinity test, and its comment kept pointing at a call that
was no longer there.
Restore it on the correct side of the clock pin. Note what the comment now
claims and what it does not: seeding after the pin is what keeps the startup
pool-quota prime quiet, because `primeCodexPoolQuotas` treats a missing entry
as stale exactly like an expired one (src/codex/auth-api.ts:1334). It is not a
race fix for `expect(upstreamRequests).toBe(3)` — `redirectCanonicalCodexTo`
only rewrites `/backend-api/codex`, while the prime's WHAM call goes to
`/backend-api/wham/usage` and never reaches the counted upstream.
Verified with `bun test tests/server-auth.test.ts`: 91 pass, 0 fail.
---------
Co-authored-by: jun <jun@lidge.dev>1 parent 15b0f70 commit 4086526
1 file changed
Lines changed: 23 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2125 | 2125 | | |
2126 | 2126 | | |
2127 | 2127 | | |
2128 | | - | |
2129 | | - | |
2130 | 2128 | | |
2131 | 2129 | | |
2132 | 2130 | | |
2133 | 2131 | | |
2134 | | - | |
2135 | | - | |
2136 | | - | |
2137 | | - | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
2138 | 2137 | | |
| 2138 | + | |
2139 | 2139 | | |
2140 | 2140 | | |
2141 | 2141 | | |
| |||
2240 | 2240 | | |
2241 | 2241 | | |
2242 | 2242 | | |
2243 | | - | |
2244 | | - | |
2245 | | - | |
2246 | | - | |
2247 | | - | |
2248 | | - | |
2249 | | - | |
2250 | | - | |
2251 | 2243 | | |
2252 | 2244 | | |
2253 | 2245 | | |
| |||
2258 | 2250 | | |
2259 | 2251 | | |
2260 | 2252 | | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
2261 | 2270 | | |
2262 | 2271 | | |
2263 | 2272 | | |
| |||
0 commit comments