You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f52b90d
Browse filesBrowse the repository at this point in the historyBrowse files
test(auth): install the fake clock and fetch stub before startServer
startServer returns synchronously but arms an async pool-quota prime that outlives its return (src/server/index.ts:2054-2064). That prime calls getValidCodexToken, which can rotate the very credential these assertions read, and fetches a real host unless the stub is up.
Both fixtures installed Date.now and globalThis.fetch AFTER startServer, leaving a window two dynamic import() resolutions wide where the prime ran against the real clock and real fetch. On a warm local module cache it resolved before the fixture finished; on a loaded CI runner it did not, and seenAuth[0] was already the rotated token.
Measured rather than assumed: OPENCODEX_DEBUG_QUOTA=1 prints refreshed=1 on every run of both the fixed and unfixed trees, so the prime always fires. The fix does not suppress it -- it makes it run inside the fixture's controlled world.
The thread-affinity test at :2131 had the identical shape and is fixed too.
Two things happen there, and the fixture controls exactly one of them at `:2251`:
133
+
134
+
1.`getValidCodexToken` may **rotate the credential** — that is the token the assertion
135
+
reads.
136
+
2.`fetch` goes to a real host unless the stub is installed.
137
+
138
+
The stub was installed **after**`startServer`, so for the width of two dynamic
139
+
`import()` resolutions the prime could reach the real `fetch` and the unpinned clock. Which
140
+
of the two turns' credentials it left behind depended on whether it resolved before or after
141
+
the fixture finished setting itself up — module-cache warmth and machine load, exactly the
142
+
shape of a CI-only failure.
143
+
144
+
**So the fix is right for a reason one step over from the one first written down.** Moving
145
+
the clock *and the fetch stub* above `startServer` does not stop the prime from running —
146
+
`refreshed=1` still fires every run — it makes the prime run entirely inside the fixture's
147
+
own controlled world, where its token refresh is served by the stub and its clock is the
148
+
pinned one. The prime becomes deterministic instead of suppressed.
149
+
150
+
That distinction matters for anyone reading this later: if a future change makes the prime
151
+
stop firing, this test is no longer covering what it thinks it covers.
152
+
153
+
Three explanations have now been written for this failure, and two of them were wrong:
154
+
155
+
| version | claim | verdict |
156
+
| --- | --- | --- |
157
+
|`260901_release_train_2390/070_outcome.md`| 60 s of margin against `REFRESH_SKEW_MS`; the read lands on the wrong side | wrong — the margin is months |
158
+
| this doc, first pass | the fake clock inflates cache age past the TTL, so staleness varies | wrong — `refreshed=1` on every run of both trees |
159
+
| this doc, measured | the prime always fetches; what varied was whether it hit the stubbed or the real `fetch`/clock | holds under measurement |
160
+
161
+
The first two were each plausible, each cited a real mechanism, and each would have justified
162
+
the same fix. That is precisely why they were dangerous: a fix that works for the wrong reason
163
+
teaches the wrong lesson to whoever touches it next.
0 commit comments