@@ -6,7 +6,7 @@ import { IExtensionContext } from '../../extension/common/types';
66import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit' ;
77import * as TypeMoq from 'typemoq' ;
88import * as sinon from 'sinon' ;
9- import { DebugConfiguration , DebugSessionOptions , RelativePattern , Uri , workspace } from 'vscode' ;
9+ import { DebugConfiguration , DebugSessionOptions , env , RelativePattern , Uri } from 'vscode' ;
1010import * as utils from '../../extension/utils' ;
1111import { assert } from 'console' ;
1212import * as fs from 'fs' ;
@@ -19,10 +19,10 @@ suite('setup for no-config debug scenario', function () {
1919 let context : TypeMoq . IMock < IExtensionContext > ;
2020 let noConfigScriptsDir : string ;
2121 let bundledDebugPath : string ;
22- let noConfigEndpointDir : string ;
2322 let DEBUGPY_ADAPTER_ENDPOINTS = 'DEBUGPY_ADAPTER_ENDPOINTS' ;
2423 let BUNDLED_DEBUGPY_PATH = 'BUNDLED_DEBUGPY_PATH' ;
25- let workspaceUriStub : sinon . SinonStub ;
24+ const testSessionId = 'test-session-id-1234' ;
25+ const hashedSessionId = crypto . createHash ( 'sha256' ) . update ( testSessionId ) . digest ( 'hex' ) . slice ( 0 , 16 ) ;
2626
2727 const testDataDir = path . join ( __dirname , 'testData' ) ;
2828 const testFilePath = path . join ( testDataDir , 'debuggerAdapterEndpoint.txt' ) ;
@@ -34,21 +34,20 @@ suite('setup for no-config debug scenario', function () {
3434 context . setup ( ( c ) => c . subscriptions ) . returns ( ( ) => [ ] ) ;
3535 noConfigScriptsDir = path . join ( context . object . extensionPath , 'bundled/scripts/noConfigScripts' ) ;
3636 bundledDebugPath = path . join ( context . object . extensionPath , 'bundled/libs/debugpy' ) ;
37- noConfigEndpointDir = path . join ( context . object . extensionPath , '.noConfigDebugAdapterEndpoints' ) ;
3837
3938 // Stub crypto.randomBytes with proper typing
4039 let randomBytesStub = sinon . stub ( crypto , 'randomBytes' ) ;
4140 // Provide a valid Buffer object
4241 randomBytesStub . callsFake ( ( _size : number ) => Buffer . from ( '1234567899' , 'hex' ) ) ;
4342
44- workspaceUriStub = sinon . stub ( workspace , 'workspaceFolders' ) . value ( [ { uri : Uri . parse ( os . tmpdir ( ) ) } ] ) ;
43+ // Stub env.sessionId to return a consistent value for tests
44+ sinon . stub ( env , 'sessionId' ) . value ( testSessionId ) ;
4545 } catch ( error ) {
4646 console . error ( 'Error in setup:' , error ) ;
4747 }
4848 } ) ;
4949 teardown ( ( ) => {
5050 sinon . restore ( ) ;
51- workspaceUriStub . restore ( ) ;
5251 } ) ;
5352
5453 test ( 'should add environment variables for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH' , async ( ) => {
@@ -195,10 +194,10 @@ suite('setup for no-config debug scenario', function () {
195194
196195 // Assert
197196 sinon . assert . calledOnce ( createFileSystemWatcherFunct ) ;
198- const expectedPattern = sinon . match
199- . instanceOf ( RelativePattern )
200- . and ( sinon . match . has ( 'base' , Uri . file ( noConfigEndpointDir ) . fsPath ) )
201- . and ( sinon . match . has ( 'pattern' , sinon . match ( / ^ e n d p o i n t - [ 0 - 9 a - f ] { 16 } \. t x t $ / ) ) ) ;
197+ const expectedPattern = new RelativePattern (
198+ path . join ( os . tmpdir ( ) , '.noConfigDebugAdapterEndpoints' ) ,
199+ `endpoint- ${ hashedSessionId } .txt` ,
200+ ) ;
202201 sinon . assert . calledWith ( createFileSystemWatcherFunct , expectedPattern ) ;
203202 } ) ;
204203
0 commit comments