@@ -12,6 +12,7 @@ import {
1212 activateRemoteDebugging ,
1313 revertExistingConfig ,
1414 tryAutoDetectOutFile ,
15+ validateSourceMapFiles ,
1516} from '../../../lambda/remoteDebugging/ldkController'
1617import { getLambdaSnapshot , type DebugConfig } from '../../../lambda/remoteDebugging/lambdaDebugger'
1718import { LdkClient } from '../../../lambda/remoteDebugging/ldkClient'
@@ -32,6 +33,7 @@ import {
3233import { getRemoteDebugLayer } from '../../../lambda/remoteDebugging/remoteLambdaDebugger'
3334import { fs } from '../../../shared/fs/fs'
3435import * as detectCdkProjects from '../../../awsService/cdk/explorer/detectCdkProjects'
36+ import * as glob from 'glob'
3537
3638describe ( 'RemoteDebugController' , ( ) => {
3739 let sandbox : sinon . SinonSandbox
@@ -648,6 +650,94 @@ describe('tryAutoDetectOutFile', () => {
648650 } )
649651} )
650652
653+ describe ( 'Source Map Pattern Extraction' , ( ) => {
654+ let sandbox : sinon . SinonSandbox
655+
656+ beforeEach ( ( ) => {
657+ sandbox = sinon . createSandbox ( )
658+ } )
659+
660+ afterEach ( ( ) => {
661+ sandbox . restore ( )
662+ } )
663+
664+ it ( 'should extract temp patterns from source map files' , async ( ) => {
665+ assert ( vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri , 'Test env should have a workdir' )
666+ const testPath = vscode . Uri . joinPath ( vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri , 'remote-debug-ts-app' ) . fsPath
667+
668+ // Call validateSourceMapFiles which will extract temp patterns
669+ const result = await validateSourceMapFiles ( [ `${ testPath } /*` ] )
670+
671+ assert ( result . isValid , 'Should find valid source map files' )
672+ assert ( result . tempPatterns . has ( 'tmp5bmwuffn' ) , 'Should extract temp pattern tmp5bmwuffn from source map' )
673+ } )
674+
675+ it ( 'should handle multiple temp patterns in source maps' , async ( ) => {
676+ // Create a mock source map with multiple temp patterns
677+ // Updated to use lowercase and underscore patterns matching Python's tempfile.mkdtemp()
678+ const mockSourceMap = {
679+ version : 3 ,
680+ file : 'index.js' ,
681+ sources : [
682+ '../../../../../../tmpa1b2c3d4/index.ts' ,
683+ '../../../../../../tmpx9y8_7w6/utils.ts' ,
684+ '../../../../../../tmp_test123/helper.ts' ,
685+ '/var/task/regular-path.ts' , // This should not match
686+ ] ,
687+ mappings : 'AAAA' ,
688+ }
689+
690+ // Mock fs.readFileText to return our mock source map
691+ sandbox . stub ( fs , 'readFileText' ) . resolves ( JSON . stringify ( mockSourceMap ) )
692+
693+ // Call extractTempPatternsFromSourceMaps directly (we need to export it first)
694+ // For now, we'll test through validateSourceMapFiles
695+
696+ sandbox . stub ( glob , 'glob' ) . resolves ( [ '/test/path/index.js' , '/test/path/index.js.map' ] )
697+
698+ const result = await validateSourceMapFiles ( [ '/test/path/*' ] )
699+
700+ assert ( result . isValid , 'Should be valid' )
701+ assert ( result . tempPatterns . has ( 'tmpa1b2c3d4' ) , 'Should extract first temp pattern' )
702+ assert ( result . tempPatterns . has ( 'tmpx9y8_7w6' ) , 'Should extract second temp pattern' )
703+ assert ( result . tempPatterns . has ( 'tmp_test123' ) , 'Should extract third temp pattern' )
704+ assert . strictEqual ( result . tempPatterns . size , 3 , 'Should have exactly 3 temp patterns' )
705+ } )
706+
707+ it ( 'should handle source maps without temp patterns' , async ( ) => {
708+ // Create a mock source map without temp patterns
709+ const mockSourceMap = {
710+ version : 3 ,
711+ file : 'index.js' ,
712+ sources : [ './index.ts' , '../utils/helper.ts' ] ,
713+ mappings : 'AAAA' ,
714+ }
715+
716+ // Mock fs.readFileText
717+ sandbox . stub ( fs , 'readFileText' ) . resolves ( JSON . stringify ( mockSourceMap ) )
718+
719+ // Mock glob
720+ sandbox . stub ( glob , 'glob' ) . resolves ( [ '/test/path/index.js' , '/test/path/index.js.map' ] )
721+
722+ const result = await validateSourceMapFiles ( [ '/test/path/*' ] )
723+
724+ assert ( result . isValid , 'Should be valid even without temp patterns' )
725+ assert . strictEqual ( result . tempPatterns . size , 0 , 'Should have no temp patterns' )
726+ } )
727+
728+ it ( 'should handle malformed source map files gracefully' , async ( ) => {
729+ // Mock fs.readFileText to return invalid JSON
730+ sandbox . stub ( fs , 'readFileText' ) . resolves ( '{ invalid json }' )
731+
732+ sandbox . stub ( glob , 'glob' ) . resolves ( [ '/test/path/index.js' , '/test/path/index.js.map' ] )
733+
734+ const result = await validateSourceMapFiles ( [ '/test/path/*' ] )
735+
736+ assert ( result . isValid , 'Should still be valid despite malformed source map' )
737+ assert . strictEqual ( result . tempPatterns . size , 0 , 'Should have no temp patterns when parsing fails' )
738+ } )
739+ } )
740+
651741describe ( 'Module Functions' , ( ) => {
652742 let sandbox : sinon . SinonSandbox
653743 let mockGlobalState : any
0 commit comments