@@ -139,30 +139,32 @@ suite('ShellStartupActivationVariablesManager', () => {
139139 test ( 'refreshes global startup variables after a global selection changes' , async ( ) => {
140140 const newEnvironment = makeEnvironment ( 'global-venv-b' , 'ms-python.python:venv' ) ;
141141 await changeListener ! ( { uri : undefined , new : folderEnvironment , old : undefined } ) ;
142- getEnvironmentStub . resolves ( newEnvironment ) ;
143-
144142 await changeListener ! ( { uri : undefined , new : newEnvironment , old : folderEnvironment } ) ;
145143
146- sinon . assert . calledTwice ( getEnvironmentStub ) ;
147- sinon . assert . alwaysCalledWithExactly ( getEnvironmentStub , undefined ) ;
144+ sinon . assert . notCalled ( getEnvironmentStub ) ;
148145 assert . deepStrictEqual ( provider . updated , [ folderEnvironment , newEnvironment ] ) ;
149146 assert . deepStrictEqual ( provider . updatedCollections , [ envCollection , envCollection ] ) ;
150147 } ) ;
151148
152- test ( 'does not let an older global refresh overwrite a newer selection' , async ( ) => {
149+ test ( 'uses the global change payload while the API still returns the previous selection' , async ( ) => {
153150 const newEnvironment = makeEnvironment ( 'global-venv-b' , 'ms-python.python:venv' ) ;
154- const olderRefresh = createDeferred < PythonEnvironment | undefined > ( ) ;
155- const newerRefresh = createDeferred < PythonEnvironment | undefined > ( ) ;
156- getEnvironmentStub . onFirstCall ( ) . returns ( olderRefresh . promise ) ;
157- getEnvironmentStub . onSecondCall ( ) . returns ( newerRefresh . promise ) ;
151+ getEnvironmentStub . resolves ( folderEnvironment ) ;
158152
159- const firstChange = changeListener ! ( { uri : undefined , new : folderEnvironment , old : undefined } ) ;
160- const secondChange = changeListener ! ( { uri : undefined , new : newEnvironment , old : folderEnvironment } ) ;
153+ await changeListener ! ( { uri : undefined , new : newEnvironment , old : folderEnvironment } ) ;
161154
162- newerRefresh . resolve ( newEnvironment ) ;
163- await secondChange ;
164- olderRefresh . resolve ( folderEnvironment ) ;
165- await firstChange ;
155+ sinon . assert . notCalled ( getEnvironmentStub ) ;
156+ assert . deepStrictEqual ( provider . updated , [ newEnvironment ] ) ;
157+ } ) ;
158+
159+ test ( 'does not let pending global initialization overwrite a newer selection' , async ( ) => {
160+ const newEnvironment = makeEnvironment ( 'global-venv-b' , 'ms-python.python:venv' ) ;
161+ const pendingInitialization = createDeferred < PythonEnvironment | undefined > ( ) ;
162+ getEnvironmentStub . returns ( pendingInitialization . promise ) ;
163+
164+ const initialization = manager . initialize ( ) ;
165+ await changeListener ! ( { uri : undefined , new : newEnvironment , old : folderEnvironment } ) ;
166+ pendingInitialization . resolve ( folderEnvironment ) ;
167+ await initialization ;
166168
167169 assert . deepStrictEqual ( provider . updated , [ newEnvironment ] ) ;
168170 assert . deepStrictEqual ( provider . updatedCollections , [ envCollection ] ) ;
@@ -189,7 +191,7 @@ suite('ShellStartupActivationVariablesManager', () => {
189191
190192 await changeListener ! ( { uri : undefined , new : undefined , old : folderEnvironment } ) ;
191193
192- sinon . assert . calledOnceWithExactly ( getEnvironmentStub , undefined ) ;
194+ sinon . assert . notCalled ( getEnvironmentStub ) ;
193195 assert . deepStrictEqual ( provider . removedCollections , [ envCollection ] ) ;
194196 assert . strictEqual ( provider . updated . length , 0 ) ;
195197 } ) ;
0 commit comments