Skip to content

fix(tests): use URL-aware fetch mocks to fix concurrent test pollution#3341

Closed
la14-1 wants to merge 2 commits intomainfrom
fix/flaky-fetch-mocks
Closed

fix(tests): use URL-aware fetch mocks to fix concurrent test pollution#3341
la14-1 wants to merge 2 commits intomainfrom
fix/flaky-fetch-mocks

Conversation

@la14-1
Copy link
Copy Markdown
Member

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

Summary

  • 2 tests failed on every bun test run on main (2106 pass, 2 fail), masking real regressions
  • Root cause: sequential callCount-based fetch mocks in hetzner-cov.test.ts and digitalocean-token.test.ts break when Bun runs test files concurrently — other test files' fetch calls leak into the shared global.fetch and shift the response sequence
  • Fix: switch hetzner-cov.test.ts to URL-pattern-aware mock routing (match on /servers?per_page=1, /ssh_keys, /primary_ips, POST /servers); relax digitalocean-token.test.ts count assertion to toBeGreaterThanOrEqual(2) since the real assertion (throws "DigitalOcean API error 401") is already on the line above

Test plan

  • bun test passes with 0 failures (2108 pass) after this change
  • bunx @biomejs/biome check src/ passes with 0 errors
  • Both previously-failing tests pass individually and in the full suite

-- refactor/code-health

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 23, 2026

Rebased onto main. CI 'Mock Tests' (coverage mode) has 2 pre-existing failures (doApi 401 OAuth recovery and hetzner/createServer orphaned IP cleanup) — these are the exact tests this PR fixes, but they also fail in coverage mode on main. Unit Tests (non-coverage) pass. Auto-merge cannot be enabled until the Mock Tests check goes green.

-- refactor/pr-maintainer

louisgv and others added 2 commits April 26, 2026 05:03
hetzner-cov and digitalocean-token tests used sequential callCount-based
mocks that break when Bun runs test files concurrently. switch to
URL-pattern routing so leaking fetch calls from other test files don't
shift the expected response sequence.

Agent: code-health
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…etch pollution

The cmdrun-happy-path tests counted total non-manifest fetches, but
raw.githubusercontent.com serves both the manifest and fallback scripts.
Combined with concurrent test pollution, this caused false failures.
Switch to URL-pattern-aware filtering that excludes manifest.json URLs
and uses >= assertions for primary fetches.

Agent: pr-maintainer
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@la14-1 la14-1 force-pushed the fix/flaky-fetch-mocks branch from 8211d5b to 977f8bb Compare April 26, 2026 05:03
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 26, 2026

Closing as superseded by #3353, which addresses the same root cause (PostHog telemetry leaking into fetch mocks) with a more targeted fix — filtering non-test URLs before incrementing callCount. Both PRs fix the same 2 test files (hetzner-cov.test.ts and digitalocean-token.test.ts) and would conflict if both merged.

The cmdrun-happy-path.test.ts improvements from this PR could be submitted separately if still needed.

-- spawn-refactor/pr-maintainer

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