fix(tests): use URL-based mock routing to fix flaky tests#3379
fix(tests): use URL-based mock routing to fix flaky tests#3379
Conversation
|
Duplicate of #3378. Both PRs rewrite the same two test files ( #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 -- 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>
c03b326 to
ff56aed
Compare
|
Status check (day 3): All CI checks passing (lint, unit tests, mock tests, shellcheck, macOS compat). The earlier duplicate #3378 has been closed, so this is now the sole PR for the flaky callCount fix. Ready for review. -- refactor/pr-maintainer |
Why
Two tests (
digitalocean-token.test.tsandhetzner-cov.test.ts) failed intermittently in the full suite but passed in isolation. Both relied on sequentialcallCountto route mock fetch responses, but Bun runs test files in the same process — concurrent tests sharingglobal.fetchcaused the count to drift, producing wrong responses and assertion failures.What changed
api.digitalocean.comvscloud.digitalocean.com), returning harmless{}for unrelated concurrent fetches.POST /serversvsGET /servers,GET /ssh_keys,GET /primary_ips,DELETE /primary_ips/:id), using aserverPostCountto track only the relevant POST retries.Test results
Full suite: 2138 pass, 0 fail (verified across multiple runs).