@@ -423,6 +423,92 @@ describe('LdkClient', () => {
423423 assert . strictEqual ( result , true , 'Should return true when no proxy to stop' )
424424 } )
425425 } )
426+
427+ describe ( 'Client User-Agent' , ( ) => {
428+ it ( 'should create Lambda client with correct user-agent' , async ( ) => {
429+ // Restore the existing stub and create a new one to track calls
430+ const existingStub = ( utils . getLambdaClientWithAgent as any ) . restore
431+ ? ( utils . getLambdaClientWithAgent as sinon . SinonStub )
432+ : undefined
433+ if ( existingStub ) {
434+ existingStub . restore ( )
435+ }
436+
437+ // Stub getUserAgent at the telemetryUtil level to return a known value
438+ const getUserAgentStub = sandbox . stub ( telemetryUtil , 'getUserAgent' )
439+ getUserAgentStub . returns ( 'test-user-agent' )
440+
441+ // Stub the sdkClientBuilderV3 to capture the client options
442+ let capturedClientOptions : any
443+ const createAwsServiceStub = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
444+ createAwsServiceStub . callsFake ( ( options : any ) => {
445+ capturedClientOptions = options
446+ // Return a mock Lambda client that has the required methods
447+ return {
448+ send : async ( ) => ( {
449+ Configuration : createMockFunctionConfig ( {
450+ FunctionArn : 'arn:aws:lambda:us-east-1:123456789012:function:testFunction' ,
451+ } ) ,
452+ } ) ,
453+ middlewareStack : { } as any ,
454+ destroy : ( ) => { } ,
455+ } as any
456+ } )
457+
458+ const mockFunctionConfig : FunctionConfiguration = createMockFunctionConfig ( {
459+ FunctionArn : 'arn:aws:lambda:us-east-1:123456789012:function:testFunction' ,
460+ } )
461+
462+ await ldkClient . getFunctionDetail ( mockFunctionConfig . FunctionArn ! )
463+
464+ assert ( createAwsServiceStub . called , 'Should call createAwsService' )
465+ assert . strictEqual ( capturedClientOptions . clientOptions . region , 'us-east-1' , 'Should use correct region' )
466+ assert . deepStrictEqual (
467+ capturedClientOptions . clientOptions . userAgent ,
468+ [ [ 'LAMBDA-DEBUG/1.0.0 test-user-agent' ] ] ,
469+ 'Should include correct user-agent with LAMBDA-DEBUG prefix in Lambda API calls'
470+ )
471+ } )
472+
473+ it ( 'should create IoT client with correct user-agent' , async ( ) => {
474+ // Restore the existing stub and create a new one to track calls
475+ const existingStub = ( utils . getIoTSTClientWithAgent as any ) . restore
476+ ? ( utils . getIoTSTClientWithAgent as sinon . SinonStub )
477+ : undefined
478+ if ( existingStub ) {
479+ existingStub . restore ( )
480+ }
481+
482+ // Stub getUserAgent to return a known value
483+ const getUserAgentStub = sandbox . stub ( telemetryUtil , 'getUserAgent' )
484+ getUserAgentStub . returns ( 'test-user-agent' )
485+
486+ // Stub the sdkClientBuilderV3 to capture the client options
487+ let capturedClientOptions : any
488+ const createAwsServiceStub = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
489+ createAwsServiceStub . callsFake ( ( options : any ) => {
490+ capturedClientOptions = options
491+ return mockIoTSTClient as any
492+ } )
493+
494+ mockIoTSTClient . on ( ListTunnelsCommand ) . resolves ( { tunnelSummaries : [ ] } )
495+ mockIoTSTClient . on ( OpenTunnelCommand ) . resolves ( {
496+ tunnelId : 'tunnel-123' ,
497+ sourceAccessToken : 'source-token' ,
498+ destinationAccessToken : 'dest-token' ,
499+ } )
500+
501+ await ldkClient . createOrReuseTunnel ( 'us-east-1' )
502+
503+ assert ( createAwsServiceStub . calledOnce , 'Should call createAwsService once' )
504+ assert . strictEqual ( capturedClientOptions . clientOptions . region , 'us-east-1' , 'Should use correct region' )
505+ assert . deepStrictEqual (
506+ capturedClientOptions . clientOptions . userAgent ,
507+ [ [ 'LAMBDA-DEBUG/1.0.0 test-user-agent' ] ] ,
508+ 'Should include correct user-agent with LAMBDA-DEBUG prefix'
509+ )
510+ } )
511+ } )
426512} )
427513
428514describe ( 'Helper Functions' , ( ) => {
0 commit comments