Skip to content

fix(cli): stub transport in telemetry tests to prevent production event leakage - #1464

Merged
BYK merged 1 commit into
mainfrom
seer/fix/cli-telemetry-test-transport-mock
Oct 13, 2026
Merged

BYK merged 1 commit into
mainfrom
seer/fix/cli-telemetry-test-transport-mock

Conversation

@sentry

@sentry sentry Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

What was changed

In packages/cli/test/lib/telemetry.test.ts, mocked makeCompressedTransport from ../../src/lib/telemetry/zstd-transport.js using vi.mock so that it returns a no-op Sentry transport (createTransport(options, () => Promise.resolve({}))).

Why

Tests in telemetry.test.ts under the "with telemetry enabled" describe block deliberately unset SENTRY_CLI_NO_TELEMETRY to exercise real withTelemetry code paths, which constructs an active Sentry client pointing at the production SENTRY_CLI_DSN. When testing error handling (such as the deliberate CliError test fixture "Internal error: resolved issue missing org"), the error propagates through reportCliError and invokes Sentry.captureException.

Because makeCompressedTransport sends envelopes via node:http/https, the test suite's global fetch mock in test/preload.ts does not intercept it. Without a mocked transport, hundreds of fake test fixture errors were transmitted directly to the production CLI Sentry project across CI runs (tracked in CLI-299).

Stubbing the transport keeps the full capture pipeline, session scope logic, and existing captureException spies running as intended while guaranteeing no network payloads leave the process.

Fixes CLI-299

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@github-actions github-actions Bot added the risk: low PR risk score: low label Oct 10, 2026

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me at 9d6a7076. No changes from me.

I reproduced the leak locally. I ran test/lib/telemetry.test.ts with a socket hook that records outbound connections and blocks them. Without this change, the file tries to connect to the CLI DSN's ingest host 27 times. With it, it makes no attempts. preload.ts only mocks fetch, and makeCompressedTransport sends over node:http/https, so the explanation in the description holds.

Stubbing the inner transport is the smallest fix. initSentry still wraps it with redactTelemetryEnvelope, so the capture, session and redaction code all still runs. The stub covers every enabled-SDK test in this file, not just the CliError fixture.

Tests: 112 of 113 tests pass locally. The failing test is createTracedDatabase > shows readonly warning when auto-repair fails, and it fails the same way on main in my sandbox because of the sandbox filesystem. All CI checks pass on this head, including test and sentry.

@BYK
BYK merged commit 6c7d57a into main Oct 13, 2026
23 checks passed
@BYK
BYK deleted the seer/fix/cli-telemetry-test-transport-mock branch October 13, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant