fix(test): use URL-based fetch mocking to prevent cross-test interference#3378
fix(test): use URL-based fetch mocking to prevent cross-test interference#3378
Conversation
|
Note: #3379 is a duplicate of this PR — both rewrite the same two test files from sequential This PR (#3378) was opened first. Both are complementary to #3376 which fixes the root cause (telemetry singleton leak). Once one of these and #3376 both merge, the flaky test issue is fully resolved (root cause + defensive mock hardening). -- refactor/pr-maintainer |
…ence
The hetzner resource_limit and digitalocean OAuth recovery tests used
sequential callCount to route mock fetch responses. When bun runs test
files concurrently, the telemetry test's global.fetch mock (via
process.emit("beforeExit")) would increment the counter, causing
deterministic failures in the full suite. Switch to URL-based routing
so non-Hetzner/DO requests (e.g. telemetry flushes) are safely ignored.
Agent: refactor/test-engineer
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9d720f6 to
f28a56e
Compare
|
Superseded by #3379 which rewrites the same two test files (digitalocean-token.test.ts, hetzner-cov.test.ts) from callCount to URL-based mock routing. #3379 adds HTTP method routing in the hetzner test for slightly more precise matching. Both are equivalent fixes; keeping only one to avoid merge conflicts. -- refactor/pr-maintainer |
Why: Two tests fail deterministically in the full suite (0 failures in isolation) because concurrent telemetry test flushes increment their sequential
callCountmock counters.Changes
hetzner-cov.test.ts: Rewrote theresource_limit_exceededretry test to route mock responses by URL pattern (/servers,/ssh_keys,/primary_ips) instead of sequentialcallCount. Non-Hetzner requests (telemetry flushes) return a harmless200 ok.digitalocean-token.test.ts: Rewrote the401 OAuth recoverytest to count DO API calls and OAuth checks separately by URL pattern. Non-DO requests return a harmless200 ok.Root cause
Bun runs test files concurrently. The telemetry test calls
process.emit("beforeExit")to flush events, which triggersglobal.fetchcalls. When these land during the hetzner/DO test's async operations, they incrementcallCountand shift the mock response sequence, causing the wrong response to be returned.Test plan
bun testfull suite: 2138 pass, 0 fail (run twice for stability)biome checkon modified files: clean-- refactor/test-engineer