Skip to content

Fix: Restrict Set-ExecutionPolicy to Windows in PowerShell env activation#1477

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-env-activation-macos-error
Draft

Fix: Restrict Set-ExecutionPolicy to Windows in PowerShell env activation#1477
Copilot wants to merge 2 commits intomainfrom
copilot/fix-env-activation-macos-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

Set-ExecutionPolicy was unconditionally prepended to PowerShell activation commands, causing Operation is not supported on this platform. errors on macOS/Linux where the command is not available.

Changes

  • src/managers/common/utils.ts: Extracted buildPwshActivationCommands(ps1Path) helper that only emits Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned when isWindows() is true. On non-Windows, only & activate.ps1 is emitted. Also eliminates duplication between the Activate.ps1/activate.ps1 branches.
// Before: always emitted on all platforms
shellActivation.set(ShellConstants.PWSH, [
    { executable: 'Set-ExecutionPolicy', args: ['-Scope', 'Process', '-ExecutionPolicy', 'RemoteSigned'] },
    { executable: '&', args: [path.join(binDir, 'Activate.ps1')] },
]);

// After: Set-ExecutionPolicy only on Windows
function buildPwshActivationCommands(ps1Path: string): PythonCommandRunConfiguration[] {
    const commands: PythonCommandRunConfiguration[] = [];
    if (isWindows()) {
        commands.push({ executable: 'Set-ExecutionPolicy', args: ['-Scope', 'Process', '-ExecutionPolicy', 'RemoteSigned'] });
    }
    commands.push({ executable: '&', args: [ps1Path] });
    return commands;
}
  • src/test/managers/common/utils.getShellActivationCommands.unit.test.ts: Adds tests asserting non-Windows PowerShell activation produces exactly one command (& activate.ps1) with no Set-ExecutionPolicy.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh issue list --state open --limit 5 --json number,title,labels (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix unwanted error on env activation for MacOS Fix: Restrict Set-ExecutionPolicy to Windows in PowerShell env activation Apr 23, 2026
Copilot AI requested a review from eleanorjboyd April 23, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Env activation on MacOS comes with unwanted error

2 participants