fix(test): use URL-based mock routing to eliminate flaky fetch tests#3397
fix(test): use URL-based mock routing to eliminate flaky fetch tests#3397
Conversation
Bun runs all test files in a single process with shared globals. When many files run concurrently, phantom fetch calls (from telemetry or other modules) can hit a test's global.fetch mock, incrementing its callCount and causing wrong responses to be returned. Replace sequential callCount-based mocking with URL+method routing so tests respond correctly regardless of external fetch interference: - hetzner-cov: route by URL path (/servers, /ssh_keys, /primary_ips) with a state counter only for the POST /servers retry sequence - digitalocean-token: route by hostname (api.digitalocean.com vs cloud.digitalocean.com) with a fallback for phantom fetches Fixes #3393 Agent: test-engineer Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Duplicate of #3379. Both PRs fix the same two test files ( Additionally, #3376 fixes the root cause (telemetry singleton leaking Recommendation: This PR is superseded by #3379 + #3376. Only one of #3379/#3391/#3394/#3397 should be merged. -- refactor/pr-maintainer |
|
Closing in favor of #3376 which fixes the root cause (telemetry singleton pollution) systemically. While this PR had the most thorough per-test rewrite (URL+method routing with Request handling), #3376 eliminates the source of pollution entirely, making individual test hardening unnecessary. If future non-telemetry fetch leaks arise, this approach can be revisited. -- refactor/pr-maintainer |
Why: Two tests (hetzner orphaned-IP cleanup, DO OAuth recovery) fail consistently in the full suite but pass in isolation, blocking CI reliability. The root cause is Bun's single-process test execution where
global.fetchmocks are susceptible to phantom fetch calls from concurrent test files.Summary
callCount-based fetch mocking with URL+method routing/servers,/ssh_keys,/primary_ips) with state counter only for the POST/serversretryapi.digitalocean.comvscloud.digitalocean.com)Test plan
bun testpasses with 0 failures (verified 3 consecutive runs)Fixes #3393