@@ -7,14 +7,20 @@ 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 } = vi . hoisted (
11+ ( ) => ( {
12+ mockCliExecute : vi . fn ( ) ,
13+ mockCliUploadSourceMaps : vi . fn ( ) ,
14+ mockCliNewDeploy : vi . fn ( ) ,
15+ mockCliConstructor : vi . fn ( ) ,
16+ } )
17+ ) ;
1518
1619vi . mock ( "@sentry/cli" , ( ) => ( {
1720 default : class {
21+ constructor ( ...args : unknown [ ] ) {
22+ mockCliConstructor ( ...args ) ;
23+ }
1824 execute = mockCliExecute ;
1925 releases = {
2026 uploadSourceMaps : mockCliUploadSourceMaps ,
@@ -640,6 +646,41 @@ describe("createSentryBuildPluginManager", () => {
640646 } ) ;
641647 } ) ;
642648
649+ describe ( "telemetry option" , ( ) => {
650+ it ( "should not pass sentry-trace or baggage headers to CLI when telemetry is false" , async ( ) => {
651+ mockCliExecute . mockResolvedValue ( undefined ) ;
652+
653+ const buildPluginManager = createSentryBuildPluginManager (
654+ {
655+ authToken : "test-token" ,
656+ org : "test-org" ,
657+ project : "test-project" ,
658+ telemetry : false ,
659+ } ,
660+ {
661+ buildTool : "webpack" ,
662+ loggerPrefix : "[sentry-webpack-plugin]" ,
663+ }
664+ ) ;
665+
666+ // Trigger a CLI operation so createCliInstance is called
667+ await buildPluginManager . injectDebugIds ( [ "/path/to/bundle" ] ) ;
668+
669+ // Find the CLI constructor call that was made by createCliInstance (not the one from allowedToSendTelemetry)
670+ const cliConstructorCalls = mockCliConstructor . mock . calls ;
671+ expect ( cliConstructorCalls . length ) . toBeGreaterThan ( 0 ) ;
672+
673+ // Check that none of the CLI instances were created with sentry-trace or baggage headers
674+ for ( const call of cliConstructorCalls ) {
675+ const options = call [ 1 ] as { headers ?: Record < string , string > } ;
676+ if ( options ?. headers ) {
677+ expect ( options . headers ) . not . toHaveProperty ( "sentry-trace" ) ;
678+ expect ( options . headers ) . not . toHaveProperty ( "baggage" ) ;
679+ }
680+ }
681+ } ) ;
682+ } ) ;
683+
643684 describe ( "createRelease deploy deduplication" , ( ) => {
644685 beforeEach ( ( ) => {
645686 vi . clearAllMocks ( ) ;
0 commit comments