From b1c55d57ef5c7e47bf2eae1ddfb0887d7a3017f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:01:14 +0000 Subject: [PATCH 1/3] Initial plan From 7ce1f05b231c8fdb7fe3db9b7b6de633824228c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:05:16 +0000 Subject: [PATCH 2/3] Changes before error encountered Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- src/managers/conda/condaUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/managers/conda/condaUtils.ts b/src/managers/conda/condaUtils.ts index 418fb62e..54117253 100644 --- a/src/managers/conda/condaUtils.ts +++ b/src/managers/conda/condaUtils.ts @@ -549,7 +549,10 @@ async function windowsExceptionGenerateConfig( traceVerbose(`PS1 hook path: ${ps1Hook ?? 'not found'}`); const activation = ps1Hook ? ps1Hook : sourceInitPath; - const pwshActivate = [{ executable: activation }, { executable: 'conda', args: ['activate', prefix] }]; + // For PowerShell, we need to dot-source the conda-hook.ps1 script + const pwshActivate = ps1Hook + ? [{ executable: '.', args: [ps1Hook] }, { executable: 'conda', args: ['activate', prefix] }] + : [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', prefix] }]; const cmdActivate = [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', prefix] }]; const bashActivate = [{ executable: 'source', args: [sourceInitPath.replace(/\\/g, '/'), prefix] }]; From 4f0a569bfd11482683a847f290a30945eeb2111a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Sep 2025 00:19:36 +0000 Subject: [PATCH 3/3] Fix PowerShell conda activation to properly dot-source conda-hook.ps1 Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- src/managers/conda/condaUtils.ts | 3 +- .../shells/common/shellUtils.unit.test.ts | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/managers/conda/condaUtils.ts b/src/managers/conda/condaUtils.ts index 54117253..056a5db2 100644 --- a/src/managers/conda/condaUtils.ts +++ b/src/managers/conda/condaUtils.ts @@ -547,9 +547,8 @@ async function windowsExceptionGenerateConfig( const ps1Hook = await getCondaHookPs1Path(condaFolder); traceVerbose(`PS1 hook path: ${ps1Hook ?? 'not found'}`); - const activation = ps1Hook ? ps1Hook : sourceInitPath; - // For PowerShell, we need to dot-source the conda-hook.ps1 script + // For PowerShell, we need to dot-source the conda-hook.ps1 script if available const pwshActivate = ps1Hook ? [{ executable: '.', args: [ps1Hook] }, { executable: 'conda', args: ['activate', prefix] }] : [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', prefix] }]; diff --git a/src/test/features/terminal/shells/common/shellUtils.unit.test.ts b/src/test/features/terminal/shells/common/shellUtils.unit.test.ts index 12eedfdb..effcf119 100644 --- a/src/test/features/terminal/shells/common/shellUtils.unit.test.ts +++ b/src/test/features/terminal/shells/common/shellUtils.unit.test.ts @@ -1,9 +1,11 @@ import * as assert from 'assert'; import { extractProfilePath, + getShellCommandAsString, PROFILE_TAG_END, PROFILE_TAG_START, } from '../../../../../features/terminal/shells/common/shellUtils'; +import { ShellConstants } from '../../../../../features/common/shellConstants'; suite('Shell Utils', () => { suite('extractProfilePath', () => { @@ -77,4 +79,41 @@ suite('Shell Utils', () => { assert.strictEqual(result, expectedPath); }); }); + + suite('getShellCommandAsString PowerShell Conda Activation', () => { + test('should format PowerShell conda activation with dot-sourcing correctly', () => { + const command = [ + { executable: '.', args: ['/path/to/conda-hook.ps1'] }, + { executable: 'conda', args: ['activate', 'myenv'] } + ]; + const result = getShellCommandAsString(ShellConstants.PWSH, command); + assert.strictEqual(result, '(. /path/to/conda-hook.ps1) ; (conda activate myenv)'); + }); + + test('should format PowerShell conda activation with spaces in path correctly', () => { + const command = [ + { executable: '.', args: ['/path with spaces/conda-hook.ps1'] }, + { executable: 'conda', args: ['activate', 'my env'] } + ]; + const result = getShellCommandAsString(ShellConstants.PWSH, command); + assert.strictEqual(result, '(. "/path with spaces/conda-hook.ps1") ; (conda activate "my env")'); + }); + + test('should format PowerShell conda activation fallback correctly', () => { + const command = [ + { executable: '/path/to/activate.bat' }, + { executable: 'conda', args: ['activate', 'myenv'] } + ]; + const result = getShellCommandAsString(ShellConstants.PWSH, command); + assert.strictEqual(result, '(/path/to/activate.bat) ; (conda activate myenv)'); + }); + + test('should format single PowerShell command without parentheses', () => { + const command = [ + { executable: 'conda', args: ['activate', 'myenv'] } + ]; + const result = getShellCommandAsString(ShellConstants.PWSH, command); + assert.strictEqual(result, 'conda activate myenv'); + }); + }); });