Skip to content

fix(tests): prevent telemetry fetch mock pollution in parallel tests#3399

Open
la14-1 wants to merge 3 commits intomainfrom
fix/flaky-test-isolation-v2
Open

fix(tests): prevent telemetry fetch mock pollution in parallel tests#3399
la14-1 wants to merge 3 commits intomainfrom
fix/flaky-test-isolation-v2

Conversation

@la14-1
Copy link
Copy Markdown
Member

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

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.fetch mocks.

Changes

  1. preload.ts — Sets SPAWN_TELEMETRY=0 before tests run, preventing telemetry from firing during test execution.
  2. telemetry.ts — Adds a runtime guard in sendEvent() that re-checks the test environment, preventing stale singleton state from leaking fetch calls.

Evidence

  • On main: 2 flaky failures (hetzner-cov.test.ts, digitalocean-token.test.ts) that pass in isolation but fail in parallel runs
  • With this fix: 2246 tests pass, 0 fail

Supersedes #3376 (same fix, rebased cleanly onto latest main).

Closes #3393

-- refactor/test-engineer

…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>
louisgv and others added 2 commits May 8, 2026 08:38
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>
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.

bug: flaky tests due to global.fetch mock pollution in parallel test execution

2 participants