@@ -216,6 +216,70 @@ suite('Terminal Environment Variable Collection Service', () => {
216
216
assert . deepEqual ( opts , { applyAtProcessCreation : false , applyAtShellIntegration : true } ) ;
217
217
} ) ;
218
218
219
+ test ( 'Prepend only "prepend portion of PATH" where applicable' , async ( ) => {
220
+ const processEnv = { PATH : 'hello/1/2/3' } ;
221
+ reset ( environmentActivationService ) ;
222
+ when ( environmentActivationService . getProcessEnvironmentVariables ( anything ( ) , anything ( ) ) ) . thenResolve (
223
+ processEnv ,
224
+ ) ;
225
+ const prependedPart = 'path/to/activate/dir:' ;
226
+ const envVars : NodeJS . ProcessEnv = { PATH : `${ prependedPart } ${ processEnv . PATH } ` } ;
227
+ when (
228
+ environmentActivationService . getActivatedEnvironmentVariables (
229
+ anything ( ) ,
230
+ undefined ,
231
+ undefined ,
232
+ customShell ,
233
+ ) ,
234
+ ) . thenResolve ( envVars ) ;
235
+
236
+ when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
237
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
238
+ let opts : EnvironmentVariableMutatorOptions | undefined ;
239
+ when ( collection . prepend ( 'PATH' , anything ( ) , anything ( ) ) ) . thenCall ( ( _ , _v , o ) => {
240
+ opts = o ;
241
+ } ) ;
242
+
243
+ await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
244
+
245
+ verify ( collection . clear ( ) ) . once ( ) ;
246
+ verify ( collection . prepend ( 'PATH' , prependedPart , anything ( ) ) ) . once ( ) ;
247
+ verify ( collection . replace ( 'PATH' , anything ( ) , anything ( ) ) ) . never ( ) ;
248
+ assert . deepEqual ( opts , { applyAtProcessCreation : true , applyAtShellIntegration : true } ) ;
249
+ } ) ;
250
+
251
+ test ( 'Prepend full PATH otherwise' , async ( ) => {
252
+ const processEnv = { PATH : 'hello/1/2/3' } ;
253
+ reset ( environmentActivationService ) ;
254
+ when ( environmentActivationService . getProcessEnvironmentVariables ( anything ( ) , anything ( ) ) ) . thenResolve (
255
+ processEnv ,
256
+ ) ;
257
+ const finalPath = 'hello/3/2/1' ;
258
+ const envVars : NodeJS . ProcessEnv = { PATH : finalPath } ;
259
+ when (
260
+ environmentActivationService . getActivatedEnvironmentVariables (
261
+ anything ( ) ,
262
+ undefined ,
263
+ undefined ,
264
+ customShell ,
265
+ ) ,
266
+ ) . thenResolve ( envVars ) ;
267
+
268
+ when ( collection . replace ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
269
+ when ( collection . delete ( anything ( ) ) ) . thenResolve ( ) ;
270
+ let opts : EnvironmentVariableMutatorOptions | undefined ;
271
+ when ( collection . prepend ( 'PATH' , anything ( ) , anything ( ) ) ) . thenCall ( ( _ , _v , o ) => {
272
+ opts = o ;
273
+ } ) ;
274
+
275
+ await terminalEnvVarCollectionService . _applyCollection ( undefined , customShell ) ;
276
+
277
+ verify ( collection . clear ( ) ) . once ( ) ;
278
+ verify ( collection . prepend ( 'PATH' , finalPath , anything ( ) ) ) . once ( ) ;
279
+ verify ( collection . replace ( 'PATH' , anything ( ) , anything ( ) ) ) . never ( ) ;
280
+ assert . deepEqual ( opts , { applyAtProcessCreation : true , applyAtShellIntegration : true } ) ;
281
+ } ) ;
282
+
219
283
test ( 'Verify envs are not applied if env activation is disabled' , async ( ) => {
220
284
const envVars : NodeJS . ProcessEnv = { CONDA_PREFIX : 'prefix/to/conda' , ...process . env } ;
221
285
when (
0 commit comments