Skip to content

fix(test): resolve 2 flaky tests caused by parallel fetch mock interference#3365

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

fix(test): resolve 2 flaky tests caused by parallel fetch mock interference#3365
la14-1 wants to merge 1 commit intomainfrom
fix/flaky-fetch-mock-tests

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 26, 2026

Why: 2 tests (hetzner-cov.test.ts and digitalocean-token.test.ts) fail consistently in full-suite bun test but pass in isolation, masking real regressions and training developers to ignore test failures.

Summary

  • hetzner-cov.test.ts "cleans up orphaned primary IPs on resource_limit_exceeded and retries" and digitalocean-token.test.ts "attempts OAuth recovery on 401 before throwing" both used sequential callCount to determine mock responses
  • When Bun runs the full suite in parallel, other test files also mock global.fetch, causing extra calls that shift the count and break the sequence
  • Fix: route mock responses by URL pattern (api.hetzner.cloud / api.digitalocean.com) and HTTP method instead of raw call count, ignoring unrelated fetch calls from parallel tests

Test plan

  • Full test suite passes: 2112 pass, 0 fail (confirmed on 3 consecutive runs)
  • Biome lint: 0 errors
  • Both previously-failing tests now pass reliably in full-suite context

-- spawn-refactor/code-health

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 28, 2026

Overlap note: This PR fixes the same 2 flaky tests as #3353 and is related to #3358.

If #3358 lands first, the telemetry leak is plugged at the source and #3353/#3365 become defensive hardening. If merging only one defensive fix, this PR (#3365) is preferred over #3353 since it uses per-domain counters rather than just filtering.

Recommended merge order: #3358 first (root cause), then #3365 (defense in depth). #3353 can be closed if both land.

All CI checks passing. No merge conflicts.

-- refactor/pr-maintainer

…est interference

Two tests failed consistently in full-suite runs but passed in isolation because
their global.fetch mocks used sequential call counting, which broke when parallel
test files also intercepted global fetch. Route mock responses by URL pattern instead.

Agent: code-health
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 1, 2026

Dedup update: #3376 (opened Apr 30) provides a more comprehensive root-cause fix for the same telemetry leak — runtime env-var guard in sendEvent() + SPAWN_TELEMETRY=0 in test preload. This PR's URL-pattern routing approach is complementary (touches different files: the test files vs telemetry.ts/preload.ts), but may be unnecessary once #3376 lands since the telemetry fetch calls won't fire at all.

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 1, 2026

Closing as superseded by #3376, which provides a more comprehensive fix for the same telemetry singleton leak (runtime env-var guard in sendEvent() + SPAWN_TELEMETRY=0 in test preload).

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 1, 2026

Superseded by #3376.

@la14-1 la14-1 closed this May 1, 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