@@ -5,6 +5,7 @@ import type { Integration } from '../../../src/types/integration';
55import { experimentalReportSdkConfigIntegration } from '../../../src/integrations/reportSdkConfig' ;
66import type * as metricsApi from '../../../src/metrics/public-api' ;
77import { count } from '../../../src/metrics/public-api' ;
8+ import { isBrowser } from '../../../src/utils/isBrowser' ;
89import { captureOptionsSetByUser } from '../../../src/utils/sdkMetadata' ;
910import { getDefaultTestClientOptions , TestClient } from '../../mocks/client' ;
1011
@@ -13,20 +14,26 @@ vi.mock('../../../src/metrics/public-api', async importOriginal => ({
1314 count : vi . fn ( ) ,
1415} ) ) ;
1516
17+ vi . mock ( '../../../src/utils/isBrowser' , ( ) => ( { isBrowser : vi . fn ( ( ) => false ) } ) ) ;
18+
1619const tagIntegration = defineIntegration ( ( _options : { tag ?: string ; filter ?: RegExp } = { } ) => ( { name : 'Tag' } ) ) ;
1720
1821function reportConfig ( options : ReturnType < typeof getDefaultTestClientOptions > ) : Record < string , unknown > {
19- let payload : Record < string , unknown > = { } ;
22+ return JSON . parse ( reportAttributes ( options ) [ 'sentry.sdk_config.payload' ] as string ) ;
23+ }
24+
25+ function reportAttributes ( options : ReturnType < typeof getDefaultTestClientOptions > ) : Record < string , unknown > {
26+ let attributes : Record < string , unknown > = { } ;
2027 vi . mocked ( count ) . mockImplementation ( ( _name , _value , metricOptions ) => {
21- payload = JSON . parse ( String ( metricOptions ?. attributes ?. [ 'sentry.sdk_config.payload' ] ) ) ;
28+ attributes = metricOptions ?. attributes ?? { } ;
2229 } ) ;
2330
2431 const client = new TestClient ( options ) ;
2532 setCurrentClient ( client ) ;
2633 client . init ( ) ;
2734 vi . advanceTimersByTime ( 0 ) ;
2835
29- return payload ;
36+ return attributes ;
3037}
3138
3239describe ( 'experimentalReportSdkConfigIntegration' , ( ) => {
@@ -108,6 +115,44 @@ describe('experimentalReportSdkConfigIntegration', () => {
108115 } ) ;
109116 } ) ;
110117
118+ it ( 'reports a browser runtime when the client sets none' , ( ) => {
119+ vi . mocked ( isBrowser ) . mockReturnValueOnce ( true ) ;
120+
121+ const payload = reportConfig (
122+ getDefaultTestClientOptions ( {
123+ dsn : 'https://username@domain/123' ,
124+ integrations : [ experimentalReportSdkConfigIntegration ( ) ] ,
125+ } ) ,
126+ ) ;
127+
128+ expect ( payload . runtime ) . toEqual ( { name : 'browser' } ) ;
129+ } ) ;
130+
131+ it ( 'reports no runtime outside the browser when the client sets none' , ( ) => {
132+ const payload = reportConfig (
133+ getDefaultTestClientOptions ( {
134+ dsn : 'https://username@domain/123' ,
135+ integrations : [ experimentalReportSdkConfigIntegration ( ) ] ,
136+ } ) ,
137+ ) ;
138+
139+ expect ( payload ) . not . toHaveProperty ( 'runtime' ) ;
140+ } ) ;
141+
142+ it ( 'reports a different hash for a different runtime' , ( ) => {
143+ const options = { dsn : 'https://username@domain/123' , integrations : [ experimentalReportSdkConfigIntegration ( ) ] } ;
144+ // Server clients set the runtime; the test client's options type doesn't declare it.
145+ const nodeRuntime = { runtime : { name : 'node' , version : 'v24.22.1' } } ;
146+ const otherNodeRuntime = { runtime : { name : 'node' , version : 'v26.0.0' } } ;
147+
148+ const node = reportAttributes ( getDefaultTestClientOptions ( { ...options , ...nodeRuntime } ) ) ;
149+ const otherNode = reportAttributes ( getDefaultTestClientOptions ( { ...options , ...otherNodeRuntime } ) ) ;
150+ vi . mocked ( isBrowser ) . mockReturnValueOnce ( true ) ;
151+ const browser = reportAttributes ( getDefaultTestClientOptions ( options ) ) ;
152+
153+ expect ( new Set ( [ node , otherNode , browser ] . map ( attributes => attributes [ 'sentry.sdk_config.hash' ] ) ) . size ) . toBe ( 3 ) ;
154+ } ) ;
155+
111156 it ( 'reports the names of the default integrations the user passed' , ( ) => {
112157 const userOptions = captureOptionsSetByUser ( {
113158 defaultIntegrations : [ experimentalReportSdkConfigIntegration ( ) ] ,
0 commit comments