Commit 5941064
Fix: Restrict Set-ExecutionPolicy to Windows in PowerShell env activation (microsoft#1477)
fixes
microsoft#1470
`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.
```typescript
// 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]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### 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:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/microsoft/vscode-python-environments/settings/copilot/coding_agent)
(admins only)
>
> </details>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 86d8342 commit 5941064
2 files changed
Lines changed: 50 additions & 14 deletions
File tree
- src
- managers/common
- test/managers/common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
142 | 154 | | |
143 | 155 | | |
144 | 156 | | |
| |||
172 | 184 | | |
173 | 185 | | |
174 | 186 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 187 | + | |
182 | 188 | | |
183 | 189 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
83 | 119 | | |
84 | 120 | | |
85 | 121 | | |
| |||
0 commit comments