test(auth): stub the clock in both floor regression tests

Copilot round 3 on #2256: both detectors were one-sided. Each measured
the sub-floor remainder against the real clock, so a preempted worker
overshoots the deadline, the remainder goes negative, and the unfixed
`remainingMs <= 0` bound takes the same branch and prints the same
message — the test passes on an implementation with no floor. It could
never fail wrongly, but it could silently stop testing anything, which on
a flake fix is the wrong half of that guarantee to keep.

Both now stub `performance.now()`: the web case advances it inside the
fetch so the second grant's remainder is exactly
MIN_REVOCATION_REQUEST_BUDGET_MS - 1, and the CLI case freezes it so the
remainder at the check is the budget itself. Positive and under the floor
on every machine, which is the only state that separates the two bounds.

Verified as detectors with the clock stubbed: reverting the core floor
gives 1 failed / 57 passed, reverting the CLI floor 1 failed / 14 passed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017wEXtbs8UEHUMxDEAxbs99
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-05 02:00:08 -04:00
commit 927a70872d

View file

@ -390,6 +390,12 @@ describe("clearStoredAuthForRelogin", () => {
const fetchSpy = vi
.spyOn(globalThis, "fetch")
.mockResolvedValue(new Response(null, { status: 200 }));
// Frozen, so the remainder at the check is exactly the budget. Left to
// the real clock this is a one-sided detector: a worker preempted for
// more than the budget reaches the check with a NEGATIVE remainder, where
// the unfixed `remainingMs <= 0` bound takes the same branch and prints
// the same message — passing without the floor (Copilot).
const nowSpy = vi.spyOn(performance, "now").mockReturnValue(1_000);
try {
const outcome = await clearStoredAuthForRelogin("https://example.com", {
budgetMs: MIN_REVOCATION_REQUEST_BUDGET_MS - 1,
@ -405,6 +411,7 @@ describe("clearStoredAuthForRelogin", () => {
'budget was exhausted before "',
);
} finally {
nowSpy.mockRestore();
fetchSpy.mockRestore();
}
});