@@ -145,12 +145,28 @@ suite('PythonEnvironmentManagers - getEnvironment', () => {
145145 assert . ok ( getStub . calledOnce , 'Should delegate to manager.get()' ) ;
146146 } ) ;
147147
148- test ( 'should return undefined when no manager is found for scope ' , async ( ) => {
149- // No managers registered for this scope
148+ test ( 'should return undefined when no managers are registered ' , async ( ) => {
149+ // No managers registered at all — size === 0 guard fires
150150 const result = await envManagers . getEnvironment ( Uri . file ( '/some/unknown/path' ) ) ;
151151 assert . strictEqual ( result , undefined ) ;
152152 } ) ;
153153
154+ test ( 'should return undefined when settings point to an unregistered manager' , async ( ) => {
155+ // Register a 'conda' manager, but the config stub returns 'ms-python.python:system'
156+ // as the defaultEnvManager. getEnvironmentManager will look up 'ms-python.python:system'
157+ // in the map, find nothing, check the cache (empty), and return undefined.
158+ // This exercises the fallback path in getEnvironmentManager beyond the size === 0 guard.
159+ const getStub = sandbox . stub ( ) . resolves ( env311 ) ;
160+ registerFakeManager ( 'ms-python.python:conda' , getStub ) ;
161+
162+ const result = await envManagers . getEnvironment ( Uri . file ( '/some/unrelated/path' ) ) ;
163+ assert . strictEqual (
164+ result ,
165+ undefined ,
166+ 'Should return undefined when settings point to an unregistered manager and cache is empty' ,
167+ ) ;
168+ } ) ;
169+
154170 test ( 'setEnvironment should still fire change events and update cache' , async ( ) => {
155171 const getStub = sandbox . stub ( ) . resolves ( env311 ) ;
156172 registerFakeManager ( 'ms-python.python:system' , getStub ) ;
@@ -290,6 +306,11 @@ suite('PythonEnvironmentManagers - refreshEnvironment', () => {
290306 assert . strictEqual ( changeEvents . length , 1 , 'refreshEnvironment should fire change event' ) ;
291307 assert . strictEqual ( changeEvents [ 0 ] . old ?. envId . id , 'system-311' ) ;
292308 assert . strictEqual ( changeEvents [ 0 ] . new ?. envId . id , 'system-314' ) ;
309+
310+ // Verify the cache was updated: a second refresh with the same env must NOT fire again
311+ await envManagers . refreshEnvironment ( undefined ) ;
312+ await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
313+ assert . strictEqual ( changeEvents . length , 1 , 'Second refresh with same env should NOT fire a second event' ) ;
293314 } ) ;
294315
295316 test ( 'should NOT fire change event when manager reports same environment' , async ( ) => {
0 commit comments