@@ -19,7 +19,14 @@ import globals from '../../../shared/extensionGlobals'
1919import * as messages from '../../../shared/utilities/messages'
2020import { getOpenExternalStub } from '../../globalSetup.test'
2121import { assertTelemetry } from '../../testUtil'
22- import { createMockFunctionConfig , createMockDebugConfig } from './testUtils'
22+ import {
23+ createMockFunctionConfig ,
24+ createMockDebugConfig ,
25+ createMockGlobalState ,
26+ setupMockLdkClientOperations ,
27+ setupMockVSCodeDebugAPIs ,
28+ setupMockRevertExistingConfig ,
29+ } from './testUtils'
2330
2431describe ( 'RemoteDebugController' , ( ) => {
2532 let sandbox : sinon . SinonSandbox
@@ -35,18 +42,7 @@ describe('RemoteDebugController', () => {
3542 sandbox . stub ( LdkClient , 'instance' ) . get ( ( ) => mockLdkClient )
3643
3744 // Mock global state with actual storage
38- const stateStorage = new Map < string , any > ( )
39- mockGlobalState = {
40- get : ( key : string ) => stateStorage . get ( key ) ,
41- tryGet : ( key : string , type ?: any , defaultValue ?: any ) => {
42- const value = stateStorage . get ( key )
43- return value !== undefined ? value : defaultValue
44- } ,
45- update : async ( key : string , value : any ) => {
46- stateStorage . set ( key , value )
47- return Promise . resolve ( )
48- } ,
49- }
45+ mockGlobalState = createMockGlobalState ( )
5046 sandbox . stub ( globals , 'globalState' ) . value ( mockGlobalState )
5147
5248 // Get controller instance
@@ -210,27 +206,16 @@ describe('RemoteDebugController', () => {
210206
211207 it ( 'should start debugging successfully' , async ( ) => {
212208 // Mock VSCode APIs
213- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
214- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
215- sandbox . stub ( vscode . debug , 'onDidTerminateDebugSession' ) . returns ( { dispose : sandbox . stub ( ) } )
209+ setupMockVSCodeDebugAPIs ( sandbox )
216210
217211 // Mock runtime support
218212 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
219213
220214 // Mock successful LdkClient operations
221- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
222- mockLdkClient . createOrReuseTunnel . resolves ( {
223- tunnelID : 'tunnel-123' ,
224- sourceToken : 'source-token' ,
225- destinationToken : 'dest-token' ,
226- } )
227- mockLdkClient . createDebugDeployment . resolves ( '$LATEST' )
228- mockLdkClient . startProxy . resolves ( true )
215+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
229216
230217 // Mock revertExistingConfig
231- sandbox
232- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
233- . resolves ( true )
218+ setupMockRevertExistingConfig ( sandbox )
234219
235220 await controller . startDebugging ( mockConfig . functionArn , 'nodejs18.x' , mockConfig )
236221
@@ -248,23 +233,17 @@ describe('RemoteDebugController', () => {
248233
249234 it ( 'should handle debugging start failure and cleanup' , async ( ) => {
250235 // Mock VSCode APIs
251- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
252- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
236+ setupMockVSCodeDebugAPIs ( sandbox )
253237
254238 // Mock runtime support
255239 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
256240
257241 // Mock function config retrieval success but tunnel creation failure
258- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
242+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
259243 mockLdkClient . createOrReuseTunnel . rejects ( new Error ( 'Tunnel creation failed' ) )
260- mockLdkClient . stopProxy . resolves ( true )
261- mockLdkClient . removeDebugDeployment . resolves ( true )
262- mockLdkClient . deleteDebugVersion . resolves ( true )
263244
264245 // Mock revertExistingConfig
265- sandbox
266- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
267- . resolves ( true )
246+ setupMockRevertExistingConfig ( sandbox )
268247
269248 let errorThrown = false
270249 try {
@@ -287,28 +266,19 @@ describe('RemoteDebugController', () => {
287266
288267 it ( 'should handle version publishing workflow' , async ( ) => {
289268 // Mock VSCode APIs
290- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
291- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
292- sandbox . stub ( vscode . debug , 'onDidTerminateDebugSession' ) . returns ( { dispose : sandbox . stub ( ) } )
269+ setupMockVSCodeDebugAPIs ( sandbox )
293270
294271 // Mock runtime support
295272 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
296273
297274 const versionConfig = { ...mockConfig , shouldPublishVersion : true }
298275
299- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
300- mockLdkClient . createOrReuseTunnel . resolves ( {
301- tunnelID : 'tunnel-123' ,
302- sourceToken : 'source-token' ,
303- destinationToken : 'dest-token' ,
304- } )
276+ // Mock successful LdkClient operations with version publishing
277+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
305278 mockLdkClient . createDebugDeployment . resolves ( 'v1' )
306- mockLdkClient . startProxy . resolves ( true )
307279
308280 // Mock revertExistingConfig
309- sandbox
310- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
311- . resolves ( true )
281+ setupMockRevertExistingConfig ( sandbox )
312282
313283 await controller . startDebugging ( versionConfig . functionArn , 'nodejs18.x' , versionConfig )
314284
@@ -431,27 +401,16 @@ describe('RemoteDebugController', () => {
431401
432402 it ( 'should emit lambda_remoteDebugStart telemetry for successful debugging start' , async ( ) => {
433403 // Mock VSCode APIs
434- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
435- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
436- sandbox . stub ( vscode . debug , 'onDidTerminateDebugSession' ) . returns ( { dispose : sandbox . stub ( ) } )
404+ setupMockVSCodeDebugAPIs ( sandbox )
437405
438406 // Mock runtime support
439407 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
440408
441409 // Mock successful LdkClient operations
442- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
443- mockLdkClient . createOrReuseTunnel . resolves ( {
444- tunnelID : 'tunnel-123' ,
445- sourceToken : 'source-token' ,
446- destinationToken : 'dest-token' ,
447- } )
448- mockLdkClient . createDebugDeployment . resolves ( '$LATEST' )
449- mockLdkClient . startProxy . resolves ( true )
410+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
450411
451412 // Mock revertExistingConfig
452- sandbox
453- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
454- . resolves ( true )
413+ setupMockRevertExistingConfig ( sandbox )
455414
456415 await controller . startDebugging ( mockConfig . functionArn , 'nodejs18.x' , mockConfig )
457416
@@ -466,28 +425,19 @@ describe('RemoteDebugController', () => {
466425
467426 it ( 'should emit lambda_remoteDebugStart telemetry for version publishing' , async ( ) => {
468427 // Mock VSCode APIs
469- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
470- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
471- sandbox . stub ( vscode . debug , 'onDidTerminateDebugSession' ) . returns ( { dispose : sandbox . stub ( ) } )
428+ setupMockVSCodeDebugAPIs ( sandbox )
472429
473430 // Mock runtime support
474431 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
475432
476433 const versionConfig = { ...mockConfig , shouldPublishVersion : true }
477434
478- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
479- mockLdkClient . createOrReuseTunnel . resolves ( {
480- tunnelID : 'tunnel-123' ,
481- sourceToken : 'source-token' ,
482- destinationToken : 'dest-token' ,
483- } )
435+ // Mock successful LdkClient operations with version publishing
436+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
484437 mockLdkClient . createDebugDeployment . resolves ( 'v1' )
485- mockLdkClient . startProxy . resolves ( true )
486438
487439 // Mock revertExistingConfig
488- sandbox
489- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
490- . resolves ( true )
440+ setupMockRevertExistingConfig ( sandbox )
491441
492442 await controller . startDebugging ( versionConfig . functionArn , 'nodejs18.x' , versionConfig )
493443
@@ -502,23 +452,17 @@ describe('RemoteDebugController', () => {
502452
503453 it ( 'should emit lambda_remoteDebugStart telemetry for failed debugging start' , async ( ) => {
504454 // Mock VSCode APIs
505- sandbox . stub ( vscode . debug , 'startDebugging' ) . resolves ( true )
506- sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
455+ setupMockVSCodeDebugAPIs ( sandbox )
507456
508457 // Mock runtime support
509458 sandbox . stub ( controller , 'supportRuntimeRemoteDebug' ) . returns ( true )
510459
511460 // Mock function config retrieval success but tunnel creation failure
512- mockLdkClient . getFunctionDetail . resolves ( mockFunctionConfig )
461+ setupMockLdkClientOperations ( mockLdkClient , mockFunctionConfig )
513462 mockLdkClient . createOrReuseTunnel . rejects ( new Error ( 'Tunnel creation failed' ) )
514- mockLdkClient . stopProxy . resolves ( true )
515- mockLdkClient . removeDebugDeployment . resolves ( true )
516- mockLdkClient . deleteDebugVersion . resolves ( true )
517463
518464 // Mock revertExistingConfig
519- sandbox
520- . stub ( require ( '../../../lambda/remoteDebugging/ldkController' ) , 'revertExistingConfig' )
521- . resolves ( true )
465+ setupMockRevertExistingConfig ( sandbox )
522466
523467 try {
524468 await controller . startDebugging ( mockConfig . functionArn , 'nodejs18.x' , mockConfig )
@@ -603,15 +547,7 @@ describe('Module Functions', () => {
603547 sandbox = sinon . createSandbox ( )
604548
605549 // Mock global state with actual storage
606- const stateStorage = new Map < string , any > ( )
607- mockGlobalState = {
608- get : ( key : string ) => stateStorage . get ( key ) ,
609- tryGet : ( key : string ) => stateStorage . get ( key ) ,
610- update : async ( key : string , value : any ) => {
611- stateStorage . set ( key , value )
612- return Promise . resolve ( )
613- } ,
614- }
550+ mockGlobalState = createMockGlobalState ( )
615551 sandbox . stub ( globals , 'globalState' ) . value ( mockGlobalState )
616552 } )
617553
0 commit comments