66import assert from 'assert'
77import sinon from 'sinon'
88import { FunctionConfiguration } from '@aws-sdk/client-lambda'
9+ import type { UserAgent } from '@aws-sdk/types'
910import { LdkClient , getRegionFromArn , isTunnelInfo } from '../../../lambda/remoteDebugging/ldkClient'
1011import { LocalProxy } from '../../../lambda/remoteDebugging/localProxy'
1112import * as utils from '../../../lambda/remoteDebugging/utils'
@@ -524,6 +525,20 @@ describe('LdkClient', () => {
524525 } )
525526
526527 describe ( 'Client User-Agent' , ( ) => {
528+ let expectedUserAgentPairs : UserAgent
529+ before ( ( ) => {
530+ // Stub getUserAgentPairs at the telemetryUtil level to return known pairs
531+ const getUserAgentPairsStub = sandbox . stub ( telemetryUtil , 'getUserAgentPairs' )
532+ const generalUserAgents : UserAgent = [
533+ [ 'AWS-Toolkit-For-VSCode' , 'testVersion' ] ,
534+ [ 'Visual-Studio-Code' , '1.0.0' ] ,
535+ [ 'ClientId' , 'test-client-id' ] ,
536+ ]
537+ getUserAgentPairsStub . returns ( generalUserAgents )
538+ const lambdaDebugUserAgent : UserAgent = [ [ 'LAMBDA-DEBUG' , '1.0.0' ] ]
539+ expectedUserAgentPairs = lambdaDebugUserAgent . concat ( generalUserAgents )
540+ } )
541+
527542 it ( 'should create Lambda client with correct user-agent' , async ( ) => {
528543 // Restore the existing stub and create a new one to track calls
529544 const existingStub = ( utils . getLambdaClientWithAgent as any ) . restore
@@ -533,18 +548,10 @@ describe('LdkClient', () => {
533548 existingStub . restore ( )
534549 }
535550
536- // Stub getUserAgentPairs at the telemetryUtil level to return known pairs
537- const getUserAgentPairsStub = sandbox . stub ( telemetryUtil , 'getUserAgentPairs' )
538- getUserAgentPairsStub . returns ( [
539- [ 'AWS-Toolkit-For-VSCode' , 'testVersion' ] ,
540- [ 'Visual-Studio-Code' , '1.0.0' ] ,
541- [ 'ClientId' , 'test-client-id' ] ,
542- ] )
543-
544- // Stub the sdkClientBuilderV3 to capture the client options
551+ // Stub the Lambda sdkClientBuilderV3 to capture the client options
545552 let capturedClientOptions : any
546- const createAwsServiceStub = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
547- createAwsServiceStub . callsFake ( ( options : any ) => {
553+ const createAwsServiceStubLambda = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
554+ createAwsServiceStubLambda . callsFake ( ( options : any ) => {
548555 capturedClientOptions = options
549556 // Return a mock Lambda client that has the required methods
550557 return {
@@ -564,16 +571,11 @@ describe('LdkClient', () => {
564571
565572 await ldkClient . getFunctionDetail ( mockFunctionConfig . FunctionArn ! )
566573
567- assert ( createAwsServiceStub . called , 'Should call createAwsService' )
574+ assert ( createAwsServiceStubLambda . called , 'Should call createAwsService' )
568575 assert . strictEqual ( capturedClientOptions . clientOptions . region , 'us-east-1' , 'Should use correct region' )
569576 assert . deepStrictEqual (
570577 capturedClientOptions . clientOptions . customUserAgent ,
571- [
572- [ 'LAMBDA-DEBUG' , '1.0.0' ] ,
573- [ 'AWS-Toolkit-For-VSCode' , 'testVersion' ] ,
574- [ 'Visual-Studio-Code' , '1.0.0' ] ,
575- [ 'ClientId' , 'test-client-id' ] ,
576- ] ,
578+ expectedUserAgentPairs ,
577579 'Should include correct customUserAgent pairs with LAMBDA-DEBUG prefix in Lambda API calls'
578580 )
579581 } )
@@ -586,19 +588,10 @@ describe('LdkClient', () => {
586588 if ( existingStub ) {
587589 existingStub . restore ( )
588590 }
589-
590- // Stub getUserAgentPairs to return known pairs
591- const getUserAgentPairsStub = sandbox . stub ( telemetryUtil , 'getUserAgentPairs' )
592- getUserAgentPairsStub . returns ( [
593- [ 'AWS-Toolkit-For-VSCode' , 'testVersion' ] ,
594- [ 'Visual-Studio-Code' , '1.0.0' ] ,
595- [ 'ClientId' , 'test-client-id' ] ,
596- ] )
597-
598591 // Stub the sdkClientBuilderV3 to capture the client options
599592 let capturedClientOptions : any
600- const createAwsServiceStub = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
601- createAwsServiceStub . callsFake ( ( options : any ) => {
593+ const createAwsServiceStubIoT = sandbox . stub ( globals . sdkClientBuilderV3 , 'createAwsService' )
594+ createAwsServiceStubIoT . callsFake ( ( options : any ) => {
602595 capturedClientOptions = options
603596 return mockIoTSTClient as any
604597 } )
@@ -612,16 +605,11 @@ describe('LdkClient', () => {
612605
613606 await ldkClient . createOrReuseTunnel ( 'us-east-1' )
614607
615- assert ( createAwsServiceStub . calledOnce , 'Should call createAwsService once' )
608+ assert ( createAwsServiceStubIoT . calledOnce , 'Should call createAwsService once' )
616609 assert . strictEqual ( capturedClientOptions . clientOptions . region , 'us-east-1' , 'Should use correct region' )
617610 assert . deepStrictEqual (
618611 capturedClientOptions . clientOptions . customUserAgent ,
619- [
620- [ 'LAMBDA-DEBUG' , '1.0.0' ] ,
621- [ 'AWS-Toolkit-For-VSCode' , 'testVersion' ] ,
622- [ 'Visual-Studio-Code' , '1.0.0' ] ,
623- [ 'ClientId' , 'test-client-id' ] ,
624- ] ,
612+ expectedUserAgentPairs ,
625613 'Should include correct customUserAgent pairs with LAMBDA-DEBUG prefix'
626614 )
627615 } )
0 commit comments