fix(tests): disable telemetry in afterEach to prevent cross-file fetch leak#3358
fix(tests): disable telemetry in afterEach to prevent cross-file fetch leak#3358
Conversation
96a40ca to
874fd8a
Compare
|
Overlap note: This PR fixes the root cause (telemetry
Recommended merge order: this PR first (root cause), then optionally #3365 (defense in depth). #3353 can likely be closed if both land. All CI checks passing. No merge conflicts. -- refactor/pr-maintainer |
|
This PR has been open for 3+ days with all CI checks passing (ShellCheck, Biome Lint, Unit Tests, Mock Tests, macOS Compatibility — all SUCCESS). It is mergeable with no conflicts. This is the root-cause fix for the flaky test issue (telemetry leak). Recommended merge order: this PR first, then #3365 (defense in depth). #3353 can be closed after both land. Requesting human review when convenient. -- spawn-refactor/pr-maintainer |
…test files The telemetry test enables telemetry globally by deleting BUN_ENV/NODE_ENV and calling initTelemetry(). Once enabled, every logWarn/logError in the process fires sendEvent() → fetch(), which consumes mock callCounts in concurrent test files (hetzner-cov, digitalocean-token), causing 2 consistent test failures. Add _testHelpers.enabled to telemetry.ts and reset it in afterEach so telemetry is disabled before other test files' mocks can be affected. Agent: test-engineer Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
874fd8a to
e7861eb
Compare
|
Dedup update: #3376 (opened Apr 30) supersedes this PR — it also modifies -- refactor/pr-maintainer |
|
Closing as superseded by #3376, which provides a more comprehensive fix for the same telemetry singleton leak (runtime env-var guard in sendEvent() + SPAWN_TELEMETRY=0 in test preload). -- refactor/pr-maintainer |
|
Superseded by #3376. |
Why: 2 tests fail on every
bun testrun (hetzner-cov, digitalocean-token) because the telemetry test enables_enabled = trueglobally and never resets it — every subsequentlogWarn/logErrortriggers fire-and-forgetfetch()calls that corrupt other tests' callCount-based mocks.Root cause
telemetry.test.tsdeletesBUN_ENV/NODE_ENVand callsinitTelemetry()to enable telemetry for testing. Once_enabledistrue, it staystruefor the entire process. AnylogWarn()orlogError()in concurrent test files (hetzner, digitalocean) firessendEvent()→fetch()through the calling test's mock, consuming callCounts.Fix (2 lines of real change)
_testHelpers.enabledgetter/setter fromtelemetry.tstelemetryTestHelpers.enabled = falseintelemetry.test.tsafterEachThis fixes the leak at the source rather than patching each affected test to filter PostHog URLs.
Relationship to #3341 and #3353
Both existing PRs work around the symptom (patching individual test mocks to ignore telemetry URLs). This PR fixes the root cause — once merged, those workarounds become unnecessary and no future test can be affected by telemetry fetch leaks.
Test plan
bun testpasses with 0 failures (2108 pass, 5376 expect() calls)biome checkpasses on changed files-- spawn-refactor/test-engineer