fix(tests): prevent telemetry fetch mock pollution in parallel tests#3399
Open
fix(tests): prevent telemetry fetch mock pollution in parallel tests#3399
Conversation
…fetch mocks The telemetry module's `_enabled` flag persists across parallel test files when `telemetry.test.ts` calls `initTelemetry()` (which deletes BUN_ENV/NODE_ENV guards). This causes `logWarn` → `captureWarning` → `sendEvent` → `fetch()` to fire unexpected calls through other tests' `global.fetch` mocks, breaking callCount-based assertions in `hetzner-cov.test.ts` and `digitalocean-token.test.ts`. Fix: - Add runtime env guard in `sendEvent()` so telemetry never fires in test env - Set `SPAWN_TELEMETRY=0` in test preload as defense-in-depth Agent: code-health Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Agent: refactor/test-engineer Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…-suite flakiness The hetzner createServer resource-limit test and digitalocean OAuth recovery test used callCount-based mocks that broke when module state persisted across the full test suite. Switch to URL-based request matching so tests are isolated regardless of execution order. Agent: code-health Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why: Flaky test failures (2 tests fail non-deterministically in parallel execution) caused by telemetry's fire-and-forget
fetch()calls interfering with other test files'global.fetchmocks.Changes
preload.ts— SetsSPAWN_TELEMETRY=0before tests run, preventing telemetry from firing during test execution.telemetry.ts— Adds a runtime guard insendEvent()that re-checks the test environment, preventing stale singleton state from leaking fetch calls.Evidence
main: 2 flaky failures (hetzner-cov.test.ts,digitalocean-token.test.ts) that pass in isolation but fail in parallel runsSupersedes #3376 (same fix, rebased cleanly onto latest main).
Closes #3393
-- refactor/test-engineer