From 42c5b44af95b99971466893b6fc16216e1137c99 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Fri, 25 Sep 2026 13:32:43 -0700 Subject: [PATCH] Avoid writing terminal activation mode during lookup Keep the legacy Python activation setting as an effective fallback without persisting an override. Cover legacy setting changes and explicit Python Environments precedence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/features/terminal/utils.ts | 4 +-- src/test/features/terminal/utils.unit.test.ts | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/features/terminal/utils.ts b/src/features/terminal/utils.ts index 866a74861..935dce954 100644 --- a/src/features/terminal/utils.ts +++ b/src/features/terminal/utils.ts @@ -392,7 +392,7 @@ export type AutoActivationType = 'off' | 'command' | 'shellStartup'; * a. globalRemoteValue * b. globalLocalValue * c. globalValue - * 2. python.terminal.activateEnvironment setting (if false, returns 'off' & sets autoActivationType to 'off') + * 2. python.terminal.activateEnvironment setting (if false, returns 'off') * 3. Default to 'command' if no setting is found * * @returns {AutoActivationType} The determined auto-activation type @@ -420,8 +420,6 @@ export function getAutoActivationType(): AutoActivationType { const pythonConfig = getConfiguration('python'); const pythonActivateSetting = pythonConfig.get('terminal.activateEnvironment', undefined); if (pythonActivateSetting === false) { - // Set autoActivationType to 'off' if python.terminal.activateEnvironment is false - pyEnvsConfig.update('terminal.autoActivationType', ACT_TYPE_OFF); return ACT_TYPE_OFF; } diff --git a/src/test/features/terminal/utils.unit.test.ts b/src/test/features/terminal/utils.unit.test.ts index ff890a569..e999c0a5b 100644 --- a/src/test/features/terminal/utils.unit.test.ts +++ b/src/test/features/terminal/utils.unit.test.ts @@ -484,7 +484,7 @@ suite('Terminal Utils - getAutoActivationType', () => { }); suite('Legacy Python Setting Fallback', () => { - test('should return ACT_TYPE_OFF and update config when python.terminal.activateEnvironment is false', () => { + test('should return ACT_TYPE_OFF without writing config when python.terminal.activateEnvironment is false', () => { // Mock - no python-envs settings, python.terminal.activateEnvironment is false pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined); pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false); @@ -494,10 +494,26 @@ suite('Terminal Utils - getAutoActivationType', () => { // Assert assert.strictEqual(result, ACT_TYPE_OFF, 'Should return ACT_TYPE_OFF when legacy setting is false'); - assert.ok( - pyEnvsConfig.update.calledWithExactly('terminal.autoActivationType', ACT_TYPE_OFF), - 'Should update python-envs config to ACT_TYPE_OFF', - ); + sinon.assert.notCalled(pyEnvsConfig.update); + }); + + test('should follow changes to the legacy setting without persisting an override', () => { + pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined); + pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).onFirstCall().returns(false); + pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).onSecondCall().returns(true); + + assert.strictEqual(getAutoActivationType(), ACT_TYPE_OFF); + assert.strictEqual(getAutoActivationType(), ACT_TYPE_COMMAND); + sinon.assert.notCalled(pyEnvsConfig.update); + }); + + test('should keep an explicit activation mode when the legacy setting is false', () => { + pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns({ globalValue: ACT_TYPE_SHELL }); + pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false); + + assert.strictEqual(getAutoActivationType(), ACT_TYPE_SHELL); + sinon.assert.notCalled(pythonConfig.get); + sinon.assert.notCalled(pyEnvsConfig.update); }); test('should return ACT_TYPE_COMMAND when python.terminal.activateEnvironment is true', () => {