@@ -189,6 +189,76 @@ suite('TerminalEnvVarInjector', () => {
189189 } ) ;
190190 } ) ;
191191
192+ suite ( 'Configuration change triggers updateEnvironmentVariables' , ( ) => {
193+ let configChangeCallback : ( ( e : { affectsConfiguration ( section : string ) : boolean } ) => void ) | undefined ;
194+
195+ setup ( ( ) => {
196+ // Capture the onDidChangeConfiguration listener so we can fire it manually
197+ Object . defineProperty ( workspace , 'onDidChangeConfiguration' , {
198+ value : ( listener : ( e : { affectsConfiguration ( section : string ) : boolean } ) => void ) => {
199+ configChangeCallback = listener ;
200+ return new Disposable ( ( ) => { } ) ;
201+ } ,
202+ configurable : true ,
203+ } ) ;
204+ } ) ;
205+
206+ test ( 'should call updateEnvironmentVariables when python.terminal.useEnvFile changes' , async ( ) => {
207+ envVarManager
208+ . setup ( ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) )
209+ . returns ( ( ) => Promise . resolve ( { VAR : 'value' } ) ) ;
210+
211+ injector = new TerminalEnvVarInjector ( envVarCollection . object , envVarManager . object ) ;
212+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
213+
214+ // getEnvironmentVariables is called once during initialization
215+ envVarManager . verify (
216+ ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) ,
217+ typeMoq . Times . once ( ) ,
218+ ) ;
219+
220+ // Fire config change for python.terminal.useEnvFile
221+ assert . ok ( configChangeCallback , 'onDidChangeConfiguration listener should be registered' ) ;
222+ configChangeCallback ! ( {
223+ affectsConfiguration : ( section : string ) => section === 'python.terminal.useEnvFile' ,
224+ } ) ;
225+
226+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
227+
228+ // Should have been called again after the config change
229+ envVarManager . verify (
230+ ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) ,
231+ typeMoq . Times . exactly ( 2 ) ,
232+ ) ;
233+ } ) ;
234+
235+ test ( 'should call updateEnvironmentVariables when python.envFile changes' , async ( ) => {
236+ envVarManager
237+ . setup ( ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) )
238+ . returns ( ( ) => Promise . resolve ( { VAR : 'value' } ) ) ;
239+
240+ injector = new TerminalEnvVarInjector ( envVarCollection . object , envVarManager . object ) ;
241+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
242+
243+ envVarManager . verify (
244+ ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) ,
245+ typeMoq . Times . once ( ) ,
246+ ) ;
247+
248+ // Fire config change for python.envFile
249+ configChangeCallback ! ( {
250+ affectsConfiguration : ( section : string ) => section === 'python.envFile' ,
251+ } ) ;
252+
253+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
254+
255+ envVarManager . verify (
256+ ( m ) => m . getEnvironmentVariables ( typeMoq . It . isAny ( ) ) ,
257+ typeMoq . Times . exactly ( 2 ) ,
258+ ) ;
259+ } ) ;
260+ } ) ;
261+
192262 suite ( 'python.envFile compatibility' , ( ) => {
193263 test ( 'python.envFile has no effect when useEnvFile is false' , async ( ) => {
194264 getConfigurationStub . returns (
0 commit comments