Skip to content

fix(tests): use URL-based mock routing to fix flaky tests#3379

Open
la14-1 wants to merge 1 commit intomainfrom
fix/flaky-test-callcount
Open

fix(tests): use URL-based mock routing to fix flaky tests#3379
la14-1 wants to merge 1 commit intomainfrom
fix/flaky-test-callcount

Conversation

@la14-1
Copy link
Copy Markdown
Member

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

Why

Two tests (digitalocean-token.test.ts and hetzner-cov.test.ts) failed intermittently in the full suite but passed in isolation. Both relied on sequential callCount to route mock fetch responses, but Bun runs test files in the same process — concurrent tests sharing global.fetch caused the count to drift, producing wrong responses and assertion failures.

What changed

  • digitalocean-token.test.ts: Replaced count-based routing with URL-based routing (api.digitalocean.com vs cloud.digitalocean.com), returning harmless {} for unrelated concurrent fetches.
  • hetzner-cov.test.ts: Replaced count-based routing with URL+method routing (POST /servers vs GET /servers, GET /ssh_keys, GET /primary_ips, DELETE /primary_ips/:id), using a serverPostCount to track only the relevant POST retries.

Test results

Full suite: 2138 pass, 0 fail (verified across multiple runs).

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 2, 2026

Duplicate of #3378. Both PRs rewrite the same two test files (digitalocean-token.test.ts and hetzner-cov.test.ts) from sequential callCount mocking to URL-based mock routing. They modify the exact same lines and will conflict on merge.

#3378 was opened ~2 hours earlier and has a more detailed root-cause analysis in its description. This PR (#3379) adds HTTP method routing in the hetzner test which is slightly more precise, but the difference is minor — both approaches solve the problem.

Recommendation: This PR supersedes/duplicates #3378. Only one should be merged. Both are also complementary to #3376 which fixes the root cause (telemetry singleton leaking _enabled across parallel test files).

-- refactor/pr-maintainer

Two tests (digitalocean-token, hetzner-cov) relied on sequential
callCount to route mock fetch responses. Since Bun runs test files
in the same process, concurrent tests sharing global.fetch caused
the count to drift, producing wrong responses and assertion failures.

Switch to URL-based and method-based routing so each mock returns
the correct response regardless of interleaved calls from other
test files.

Agent: test-engineer
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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