Skip to content

Commit 87f4dea

Browse files
terminal: avoid writing activation mode during lookup (#1826)
## Summary - Return `off` when the legacy `python.terminal.activateEnvironment` setting is false, without writing a persistent `python-envs.terminal.autoActivationType` override from a getter. - Preserve precedence for an explicitly set Python Environments activation mode. - Cover false-to-true legacy setting changes and verify lookup never calls configuration update. The setting is machine-scoped, so the previous implicit workspace-target write likely failed rather than persisting for users; this still removes an unnecessary, unawaited write attempt. This PR is independent of #1823 and contains only the getter and related tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 97dd21c commit 87f4dea

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎src/features/terminal/utils.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export type AutoActivationType = 'off' | 'command' | 'shellStartup';
392392
* a. globalRemoteValue
393393
* b. globalLocalValue
394394
* c. globalValue
395-
* 2. python.terminal.activateEnvironment setting (if false, returns 'off' & sets autoActivationType to 'off')
395+
* 2. python.terminal.activateEnvironment setting (if false, returns 'off')
396396
* 3. Default to 'command' if no setting is found
397397
*
398398
* @returns {AutoActivationType} The determined auto-activation type
@@ -420,8 +420,6 @@ export function getAutoActivationType(): AutoActivationType {
420420
const pythonConfig = getConfiguration('python');
421421
const pythonActivateSetting = pythonConfig.get<boolean | undefined>('terminal.activateEnvironment', undefined);
422422
if (pythonActivateSetting === false) {
423-
// Set autoActivationType to 'off' if python.terminal.activateEnvironment is false
424-
pyEnvsConfig.update('terminal.autoActivationType', ACT_TYPE_OFF);
425423
return ACT_TYPE_OFF;
426424
}
427425

‎src/test/features/terminal/utils.unit.test.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ suite('Terminal Utils - getAutoActivationType', () => {
484484
});
485485

486486
suite('Legacy Python Setting Fallback', () => {
487-
test('should return ACT_TYPE_OFF and update config when python.terminal.activateEnvironment is false', () => {
487+
test('should return ACT_TYPE_OFF without writing config when python.terminal.activateEnvironment is false', () => {
488488
// Mock - no python-envs settings, python.terminal.activateEnvironment is false
489489
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
490490
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false);
@@ -494,10 +494,26 @@ suite('Terminal Utils - getAutoActivationType', () => {
494494

495495
// Assert
496496
assert.strictEqual(result, ACT_TYPE_OFF, 'Should return ACT_TYPE_OFF when legacy setting is false');
497-
assert.ok(
498-
pyEnvsConfig.update.calledWithExactly('terminal.autoActivationType', ACT_TYPE_OFF),
499-
'Should update python-envs config to ACT_TYPE_OFF',
500-
);
497+
sinon.assert.notCalled(pyEnvsConfig.update);
498+
});
499+
500+
test('should follow changes to the legacy setting without persisting an override', () => {
501+
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
502+
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).onFirstCall().returns(false);
503+
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).onSecondCall().returns(true);
504+
505+
assert.strictEqual(getAutoActivationType(), ACT_TYPE_OFF);
506+
assert.strictEqual(getAutoActivationType(), ACT_TYPE_COMMAND);
507+
sinon.assert.notCalled(pyEnvsConfig.update);
508+
});
509+
510+
test('should keep an explicit activation mode when the legacy setting is false', () => {
511+
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns({ globalValue: ACT_TYPE_SHELL });
512+
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false);
513+
514+
assert.strictEqual(getAutoActivationType(), ACT_TYPE_SHELL);
515+
sinon.assert.notCalled(pythonConfig.get);
516+
sinon.assert.notCalled(pyEnvsConfig.update);
501517
});
502518

503519
test('should return ACT_TYPE_COMMAND when python.terminal.activateEnvironment is true', () => {

0 commit comments

Comments
 (0)