@@ -281,61 +281,70 @@ describe('EnvironmentBuilder', () => {
281281 it ( 'should set ENABLE_ANNOTATION_TOOLS=false when setting is disabled' , async ( ) => {
282282 const vscode = await import ( 'vscode' ) ;
283283 const originalGetConfig = vscode . workspace . getConfiguration ;
284- vscode . workspace . getConfiguration = ( ) => ( {
285- get : ( _key : string , defaultVal ?: any ) => {
286- if ( _key === 'enableAnnotationTools' ) return false ;
287- if ( _key === 'additionalDatabaseDirs' ) return [ ] ;
288- if ( _key === 'additionalQueryRunResultsDirs' ) return [ ] ;
289- if ( _key === 'additionalMrvaRunResultsDirs' ) return [ ] ;
290- return defaultVal ;
291- } ,
292- has : ( ) => false ,
293- inspect : ( ) => undefined as any ,
294- update : ( ) => Promise . resolve ( ) ,
295- } ) as any ;
296284
297- builder . invalidate ( ) ;
298- const env = await builder . build ( ) ;
299- expect ( env . ENABLE_ANNOTATION_TOOLS ) . toBe ( 'false' ) ;
300-
301- vscode . workspace . getConfiguration = originalGetConfig ;
285+ try {
286+ vscode . workspace . getConfiguration = ( ) => ( {
287+ get : ( _key : string , defaultVal ?: any ) => {
288+ if ( _key === 'enableAnnotationTools' ) return false ;
289+ if ( _key === 'additionalDatabaseDirs' ) return [ ] ;
290+ if ( _key === 'additionalQueryRunResultsDirs' ) return [ ] ;
291+ if ( _key === 'additionalMrvaRunResultsDirs' ) return [ ] ;
292+ return defaultVal ;
293+ } ,
294+ has : ( ) => false ,
295+ inspect : ( ) => undefined as any ,
296+ update : ( ) => Promise . resolve ( ) ,
297+ } ) as any ;
298+
299+ builder . invalidate ( ) ;
300+ const env = await builder . build ( ) ;
301+ expect ( env . ENABLE_ANNOTATION_TOOLS ) . toBe ( 'false' ) ;
302+ } finally {
303+ vscode . workspace . getConfiguration = originalGetConfig ;
304+ }
302305 } ) ;
303306
304307 it ( 'should set MONITORING_STORAGE_LOCATION to scratch dir when annotations enabled with workspace' , async ( ) => {
305308 const vscode = await import ( 'vscode' ) ;
306309 const origFolders = vscode . workspace . workspaceFolders ;
307- ( vscode . workspace . workspaceFolders as any ) = [
308- { uri : { fsPath : '/mock/workspace' } , name : 'ws' , index : 0 } ,
309- ] ;
310310
311- builder . invalidate ( ) ;
312- const env = await builder . build ( ) ;
313- expect ( env . MONITORING_STORAGE_LOCATION ) . toBe ( '/mock/workspace/.codeql/ql-mcp' ) ;
314-
315- ( vscode . workspace . workspaceFolders as any ) = origFolders ;
311+ try {
312+ ( vscode . workspace . workspaceFolders as any ) = [
313+ { uri : { fsPath : '/mock/workspace' } , name : 'ws' , index : 0 } ,
314+ ] ;
315+
316+ builder . invalidate ( ) ;
317+ const env = await builder . build ( ) ;
318+ expect ( env . MONITORING_STORAGE_LOCATION ) . toBe ( '/mock/workspace/.codeql/ql-mcp' ) ;
319+ } finally {
320+ ( vscode . workspace . workspaceFolders as any ) = origFolders ;
321+ }
316322 } ) ;
317323
318324 it ( 'should allow additionalEnv to override ENABLE_ANNOTATION_TOOLS' , async ( ) => {
319325 const vscode = await import ( 'vscode' ) ;
320326 const originalGetConfig = vscode . workspace . getConfiguration ;
321- vscode . workspace . getConfiguration = ( ) => ( {
322- get : ( _key : string , defaultVal ?: any ) => {
323- if ( _key === 'additionalEnv' ) return { ENABLE_ANNOTATION_TOOLS : 'false' } ;
324- if ( _key === 'additionalDatabaseDirs' ) return [ ] ;
325- if ( _key === 'additionalQueryRunResultsDirs' ) return [ ] ;
326- if ( _key === 'additionalMrvaRunResultsDirs' ) return [ ] ;
327- return defaultVal ;
328- } ,
329- has : ( ) => false ,
330- inspect : ( ) => undefined as any ,
331- update : ( ) => Promise . resolve ( ) ,
332- } ) as any ;
333327
334- builder . invalidate ( ) ;
335- const env = await builder . build ( ) ;
336- // additionalEnv comes after the default, so it should override
337- expect ( env . ENABLE_ANNOTATION_TOOLS ) . toBe ( 'false' ) ;
338-
339- vscode . workspace . getConfiguration = originalGetConfig ;
328+ try {
329+ vscode . workspace . getConfiguration = ( ) => ( {
330+ get : ( _key : string , defaultVal ?: any ) => {
331+ if ( _key === 'additionalEnv' ) return { ENABLE_ANNOTATION_TOOLS : 'false' } ;
332+ if ( _key === 'additionalDatabaseDirs' ) return [ ] ;
333+ if ( _key === 'additionalQueryRunResultsDirs' ) return [ ] ;
334+ if ( _key === 'additionalMrvaRunResultsDirs' ) return [ ] ;
335+ return defaultVal ;
336+ } ,
337+ has : ( ) => false ,
338+ inspect : ( ) => undefined as any ,
339+ update : ( ) => Promise . resolve ( ) ,
340+ } ) as any ;
341+
342+ builder . invalidate ( ) ;
343+ const env = await builder . build ( ) ;
344+ // additionalEnv comes after the default, so it should override
345+ expect ( env . ENABLE_ANNOTATION_TOOLS ) . toBe ( 'false' ) ;
346+ } finally {
347+ vscode . workspace . getConfiguration = originalGetConfig ;
348+ }
340349 } ) ;
341350} ) ;
0 commit comments