Repository navigation
fix(cli): stub transport in telemetry tests to prevent production event leakage - #1464
Conversation
There was a problem hiding this comment.
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.
What was changed
In
packages/cli/test/lib/telemetry.test.ts, mockedmakeCompressedTransportfrom../../src/lib/telemetry/zstd-transport.jsusingvi.mockso that it returns a no-op Sentry transport (createTransport(options, () => Promise.resolve({}))).Why
Tests in
telemetry.test.tsunder the "with telemetry enabled" describe block deliberately unsetSENTRY_CLI_NO_TELEMETRYto exercise realwithTelemetrycode paths, which constructs an active Sentry client pointing at the productionSENTRY_CLI_DSN. When testing error handling (such as the deliberateCliErrortest fixture"Internal error: resolved issue missing org"), the error propagates throughreportCliErrorand invokesSentry.captureException.Because
makeCompressedTransportsends envelopes vianode:http/https, the test suite's globalfetchmock intest/preload.tsdoes 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
captureExceptionspies 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 runThis PR was automatically generated by Sentry. You can adjust this setting at any time.