Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,11 @@ async function windowsExceptionGenerateConfig(

const ps1Hook = await getCondaHookPs1Path(condaFolder);
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 if available
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] }];
Expand Down
39 changes: 39 additions & 0 deletions src/test/features/terminal/shells/common/shellUtils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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');
});
});
});
Loading