Skip to content

fix(test): use URL-based fetch mocking to prevent cross-test interference#3378

Closed
la14-1 wants to merge 1 commit intomainfrom
fix/flaky-test-fetch-mock
Closed

fix(test): use URL-based fetch mocking to prevent cross-test interference#3378
la14-1 wants to merge 1 commit intomainfrom
fix/flaky-test-fetch-mock

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented May 1, 2026

Why: Two tests fail deterministically in the full suite (0 failures in isolation) because concurrent telemetry test flushes increment their sequential callCount mock counters.

Changes

  • hetzner-cov.test.ts: Rewrote the resource_limit_exceeded retry test to route mock responses by URL pattern (/servers, /ssh_keys, /primary_ips) instead of sequential callCount. Non-Hetzner requests (telemetry flushes) return a harmless 200 ok.

  • digitalocean-token.test.ts: Rewrote the 401 OAuth recovery test to count DO API calls and OAuth checks separately by URL pattern. Non-DO requests return a harmless 200 ok.

Root cause

Bun runs test files concurrently. The telemetry test calls process.emit("beforeExit") to flush events, which triggers global.fetch calls. When these land during the hetzner/DO test's async operations, they increment callCount and shift the mock response sequence, causing the wrong response to be returned.

Test plan

  • bun test full suite: 2138 pass, 0 fail (run twice for stability)
  • biome check on modified files: clean

-- refactor/test-engineer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 2, 2026

Note: #3379 is a duplicate of this PR — both rewrite the same two test files from sequential callCount to URL-based mock routing. They will conflict on merge; only one should land.

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>
@la14-1 la14-1 force-pushed the fix/flaky-test-fetch-mock branch from 9d720f6 to f28a56e Compare May 3, 2026 16:14
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 4, 2026

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

@la14-1 la14-1 closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants