Fix/hardcoded legacy powershell#12411
Open
Charlweed wants to merge 4 commits into
Open
Conversation
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Centralize and Modernize PowerShell Command Detection
Resolves issue #12410
Overview
This PR eliminates hardcoded dependencies on legacy Windows PowerShell (
powershell.exe) across the codebase and introduces a dynamic, centralized detection mechanism. By preferring modern PowerShell Core (pwsh), we resolve critical runtime failures caused by executing modern scripts in legacy environments, while maintaining backward compatibility.Rationale & Technical Implementation Choices
1. Centralized Synchronous Detection
A new utility
getPowerShellCommand()has been added tocore/util/shell.ts.spawnSync)? Several call sites, notablycore/tools/definitions/runTerminalCommand.ts, invoke the shell detection during module initialization to populate static metadata and configuration. A synchronous implementation was mandatory to prevent[object Promise]from bleeding into module-level constants.2. Architectural Boundaries & Public API
child_processmodule is strictly isolated incore/util/shell.ts. This prevents Node-specific dependencies from being accidentally pulled into non-Node environments (like browser extensions or WASM contexts) that might import from the general utility barrel.core/util/shell.js, the function is re-exported viacore/util/index.ts. This enforces strict encapsulation and provides a stable import path through thecorepackage's public API.3. Robust Test Infrastructure
extensions/cli/vitest.config.tswith a broadcorealias mapping to the source directory (../../core/src). This correctly mirrors thetsconfig.jsonpath resolution, allowing tests to run directly against the source files via the public API without requiring tightly coupled, file-specific aliases or a prior build step.core/util/index.jspublic API rather than intercepting internalexecAsyncorchild_processcalls. This makes the tests resilient to internal implementation changes and focuses verification strictly on the logic's boundaries.AI Code Review
@continue-reviewChecklist
Tests
Verification Results
pwshis correctly preferred when available on Windows.powershellon legacy Windows environments.Summary by cubic
Centralizes PowerShell detection and switches Windows tooling to prefer PowerShell Core (
pwsh) with a safe fallback to legacypowershell. Fixes Windows runtime issues in terminal, TTS, and clipboard flows by routing all calls through one API.Bug Fixes
pwshon Windows; fall back topowershellwhen unavailable inrunTerminalCommand, TTS, and clipboard utilities.System.Windows.FormsAPIs and-STAfor image checks and saves.Refactors
getPowerShellCommand()incore/util/shell.ts(sync, cached) and re-export viacore/util/index.ts.powershell.exeacrosscoreandextensions/cliwithgetPowerShellCommand().extensions/clivitest.config.tsto aliascoreto source and adjust tests to mock thecore/util/index.jspublic API.Written for commit 5bf7d3e. Summary will update on new commits.