Skip to content

Commit 67cf61e

Browse files
gitcommit90claude
andcommitted
fix(phase4): execute Windows WSL scripts without BOM
PowerShell 5 adds a UTF-8 BOM when piping text to wsl.exe, so bash received `test` as the first command. A non-login `bash -s` also omitted the installed node path. Write each command to a unique runner-temp script as UTF-8 without BOM, mount that file through /mnt, and execute it from a login shell. The exact transport passed under the real limited helm-ph4 account on VM 115 with an isolated WSL distribution, including nested substitutions and cleanup. Keep structural coverage for no-BOM file transport and login-shell execution. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2606bef commit 67cf61e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎ops/platform-acceptance/windows.ps1‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ function Get-Distros {
2929
return @($raw -split "`r?`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ })
3030
}
3131
function Invoke-Distro([string] $Command) {
32-
# PowerShell 5 re-quotes native command arguments before invoking wsl.exe.
33-
# That mangles bash substitutions and nested quotes even when the
34-
# PowerShell string itself is literal. Send the script over stdin instead;
35-
# this preserves the exact bytes and was proven under the real runner user.
36-
$Command | & $Wsl -d $Distro -u root --exec /bin/bash -s | Out-Host
37-
if ($LASTEXITCODE -ne 0) { Refuse "in-distribution command failed: $Command" }
32+
# PowerShell 5 either re-quotes native arguments or adds a BOM when piping
33+
# text to wsl.exe. Write exact UTF-8 without a BOM to the runner temp mount,
34+
# then execute it from a login shell so the installed node path is present.
35+
$tempRoot = if ($env:RUNNER_TEMP) { $env:RUNNER_TEMP } else { $env:TEMP }
36+
$script = Join-Path $tempRoot ("1helm-distro-{0}.sh" -f [guid]::NewGuid().ToString('N'))
37+
$encoding = New-Object System.Text.UTF8Encoding($false)
38+
[IO.File]::WriteAllText($script, $Command + "`n", $encoding)
39+
$drive = $script.Substring(0, 1).ToLowerInvariant()
40+
$scriptInDistro = "/mnt/$drive/" + ($script.Substring(3) -replace '\\', '/')
41+
try {
42+
& $Wsl -d $Distro -u root --exec /bin/bash -lc "bash '$scriptInDistro'" | Out-Host
43+
if ($LASTEXITCODE -ne 0) { Refuse "in-distribution command failed: $Command" }
44+
} finally {
45+
Remove-Item $script -Force -ErrorAction SilentlyContinue
46+
}
3847
}
3948
function Assert-DistroVersion([string] $ExpectedVersion) {
4049
if ($ExpectedVersion -notmatch '^\d+\.\d+\.\d+$') { Refuse 'expected distribution version is invalid' }

‎test/phase4-platform-acceptance.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ test("Windows code publishes no artifact/signing claim and requires honest reboo
212212
assert.match(windows, /apply-linux-release\.sh/);
213213
assert.match(windows, /function Assert-DistroVersion/);
214214
assert.equal((windows.match(/Assert-DistroVersion \$(?:Version|PreviousVersion)/g) || []).length, 4);
215-
assert.match(windows, /\$Command \| & \$Wsl -d \$Distro -u root --exec \/bin\/bash -s/);
215+
assert.match(windows, /UTF8Encoding\(\$false\)/);
216+
assert.match(windows, /\[IO\.File\]::WriteAllText/);
217+
assert.match(windows, /\/bin\/bash -lc "bash '\$scriptInDistro'"/);
218+
assert.doesNotMatch(windows, /\$Command \| & \$Wsl/);
216219
assert.doesNotMatch(windows, /\/bin\/bash -lc \$Command/);
217220
assert.doesNotMatch(windows, /Invoke-Distro "test .*systemctl/);
218221
assert.match(windows, /LocalRootfs/);

0 commit comments

Comments
 (0)