@@ -7,14 +7,19 @@ import { globFiles } from "../src/glob";
77import { prepareBundleForDebugIdUpload } from "../src/debug-id-upload" ;
88import { describe , it , expect , afterEach , beforeEach , vi , MockedFunction } from "vitest" ;
99
10- const { mockCliExecute, mockCliUploadSourceMaps, mockCliNewDeploy } = vi . hoisted ( ( ) => ( {
11- mockCliExecute : vi . fn ( ) ,
12- mockCliUploadSourceMaps : vi . fn ( ) ,
13- mockCliNewDeploy : vi . fn ( ) ,
14- } ) ) ;
10+ const { mockCliExecute, mockCliUploadSourceMaps, mockCliNewDeploy, mockCliConstructor } =
11+ vi . hoisted ( ( ) => ( {
12+ mockCliExecute : vi . fn ( ) ,
13+ mockCliUploadSourceMaps : vi . fn ( ) ,
14+ mockCliNewDeploy : vi . fn ( ) ,
15+ mockCliConstructor : vi . fn ( ) ,
16+ } ) ) ;
1517
1618vi . mock ( "@sentry/cli" , ( ) => ( {
1719 default : class {
20+ constructor ( ...args : unknown [ ] ) {
21+ mockCliConstructor ( ...args ) ;
22+ }
1823 execute = mockCliExecute ;
1924 releases = {
2025 uploadSourceMaps : mockCliUploadSourceMaps ,
@@ -640,6 +645,41 @@ describe("createSentryBuildPluginManager", () => {
640645 } ) ;
641646 } ) ;
642647
648+ describe ( "telemetry option" , ( ) => {
649+ it ( "should not pass sentry-trace or baggage headers to CLI when telemetry is false" , async ( ) => {
650+ mockCliExecute . mockResolvedValue ( undefined ) ;
651+
652+ const buildPluginManager = createSentryBuildPluginManager (
653+ {
654+ authToken : "test-token" ,
655+ org : "test-org" ,
656+ project : "test-project" ,
657+ telemetry : false ,
658+ } ,
659+ {
660+ buildTool : "webpack" ,
661+ loggerPrefix : "[sentry-webpack-plugin]" ,
662+ }
663+ ) ;
664+
665+ // Trigger a CLI operation so createCliInstance is called
666+ await buildPluginManager . injectDebugIds ( [ "/path/to/bundle" ] ) ;
667+
668+ // Find the CLI constructor call that was made by createCliInstance (not the one from allowedToSendTelemetry)
669+ const cliConstructorCalls = mockCliConstructor . mock . calls ;
670+ expect ( cliConstructorCalls . length ) . toBeGreaterThan ( 0 ) ;
671+
672+ // Check that none of the CLI instances were created with sentry-trace or baggage headers
673+ for ( const call of cliConstructorCalls ) {
674+ const options = call [ 1 ] as { headers ?: Record < string , string > } ;
675+ if ( options ?. headers ) {
676+ expect ( options . headers ) . not . toHaveProperty ( "sentry-trace" ) ;
677+ expect ( options . headers ) . not . toHaveProperty ( "baggage" ) ;
678+ }
679+ }
680+ } ) ;
681+ } ) ;
682+
643683 describe ( "createRelease deploy deduplication" , ( ) => {
644684 beforeEach ( ( ) => {
645685 vi . clearAllMocks ( ) ;
0 commit comments