Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(installer): stop PS 5.1 stderr wrapping from aborting version probes

Martin Vogel3f926997299c
diff --git a/install.ps1 b/install.ps1
index 1433c926e..d63f1001d 100644
--- a/install.ps1
+++ b/install.ps1
@@ -281,8 +281,21 @@ if ($binaryItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
}
# Prove the downloaded binary runs before touching an existing installation.
+# PS 5.1 wraps redirected native stderr into ErrorRecords, so under the global
+# ErrorActionPreference=Stop a HEALTHY binary that prints one warning while
+# exiting 0 becomes a terminating error here. Relax to Continue for the probe
+# only; failure detection stays on $LASTEXITCODE, and the pre-seed guarantees
+# a binary that fails to START (stale $LASTEXITCODE from an earlier native
+# call) can never read as success.
try {
- $candidateVersion = & $DownloadedBinary --version 2>&1
+ $ProbeEap = $ErrorActionPreference
+ try {
+ $ErrorActionPreference = "Continue"
+ $global:LASTEXITCODE = 1
+ $candidateVersion = & $DownloadedBinary --version 2>&1
+ } finally {
+ $ErrorActionPreference = $ProbeEap
+ }
if ($LASTEXITCODE -ne 0) { throw "candidate exited with $LASTEXITCODE" }
Write-Host "Verified candidate: $candidateVersion"
} catch {
@@ -349,8 +362,18 @@ if (Test-Path -LiteralPath $DownloadedInstaller -PathType Leaf) {
}
# Verify
+# Same PS 5.1 stderr-wrapping guard as the candidate probe above; the pre-seed
+# matters MOST here, because prior successful native calls leave a stale
+# $LASTEXITCODE=0 that a start-failure would otherwise inherit.
try {
- $ver = & $Dest --version 2>&1
+ $ProbeEap = $ErrorActionPreference
+ try {
+ $ErrorActionPreference = "Continue"
+ $global:LASTEXITCODE = 1
+ $ver = & $Dest --version 2>&1
+ } finally {
+ $ErrorActionPreference = $ProbeEap
+ }
if ($LASTEXITCODE -ne 0) { throw "installed binary exited with $LASTEXITCODE" }
Write-Host "Installed: $ver"
} catch {
diff --git a/tests/test_windows_bundle_contract.sh b/tests/test_windows_bundle_contract.sh
index fab5023d5..a40ac3083 100644
--- a/tests/test_windows_bundle_contract.sh
+++ b/tests/test_windows_bundle_contract.sh
@@ -229,6 +229,19 @@ require(
"install.ps1 must verify and install through the downloaded binary",
)
+# PS 5.1 wraps redirected native stderr into ErrorRecords; under the global
+# ErrorActionPreference=Stop a healthy binary that warns on stderr aborts the
+# version probes (#1255). Pin the guard's two load-bearing parts so neither
+# can be silently dropped: the probe-scoped relaxation with an exception-safe
+# restore, and the $LASTEXITCODE pre-seed that keeps a start-failure from
+# inheriting a stale 0 and reading as success.
+require(
+ installer.count('$ErrorActionPreference = "Continue"') == 2
+ and installer.count("$global:LASTEXITCODE = 1") == 2
+ and installer.count("$ErrorActionPreference = $ProbeEap") == 2,
+ "install.ps1 version probes must relax EAP with restore and pre-seed LASTEXITCODE (#1255)",
+)
+
# ── 4. Package-manager shims resolve the single Windows binary ───────────────
single_binary_contracts = {
"pkg/npm/install.js": (