Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions ops/platform-acceptance/windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ function Get-Distros {
return @($raw -split "`r?`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ })
}
function Invoke-Distro([string] $Command) {
# PowerShell 5 re-quotes native command arguments before invoking wsl.exe.
# That mangles bash substitutions and nested quotes even when the
# PowerShell string itself is literal. Send the script over stdin instead;
# this preserves the exact bytes and was proven under the real runner user.
$Command | & $Wsl -d $Distro -u root --exec /bin/bash -s | Out-Host
if ($LASTEXITCODE -ne 0) { Refuse "in-distribution command failed: $Command" }
# PowerShell 5 either re-quotes native arguments or adds a BOM when piping
# text to wsl.exe. Write exact UTF-8 without a BOM to the runner temp mount,
# then execute it from a login shell so the installed node path is present.
$tempRoot = if ($env:RUNNER_TEMP) { $env:RUNNER_TEMP } else { $env:TEMP }
$script = Join-Path $tempRoot ("1helm-distro-{0}.sh" -f [guid]::NewGuid().ToString('N'))
$encoding = New-Object System.Text.UTF8Encoding($false)
[IO.File]::WriteAllText($script, $Command + "`n", $encoding)
$drive = $script.Substring(0, 1).ToLowerInvariant()
$scriptInDistro = "/mnt/$drive/" + ($script.Substring(3) -replace '\\', '/')
try {
& $Wsl -d $Distro -u root --exec /bin/bash -lc "bash '$scriptInDistro'" | Out-Host
if ($LASTEXITCODE -ne 0) { Refuse "in-distribution command failed: $Command" }
Comment on lines +38 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Propagate failures from every command in the temporary script.

Line 42 runs bash without -e, and Line 38 does not prepend set -e. Bash returns the status of the final command. In Assert-DistroVersion, a failed service check followed by a successful version check returns 0, so Line 43 records false success.

Run the script with bash -e or write set -e as the first line. Add a regression case with a failed first command and a successful final command. If bash -e is used, update Line 217 in test/phase4-platform-acceptance.mjs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ops/platform-acceptance/windows.ps1` around lines 38 - 43, Update the
temporary script execution in the PowerShell flow around WriteAllText and the
WSL bash invocation so every command failure propagates instead of only the
final command status; use bash’s errexit behavior or prepend set -e to the
generated script. Add a regression case in Assert-DistroVersion coverage with a
failing first command followed by a successful final command, and if changing
the invocation to bash -e, update the corresponding expectation in
phase4-platform-acceptance.mjs.

} finally {
Remove-Item $script -Force -ErrorAction SilentlyContinue
Comment on lines +36 to +45

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Keep cleanup active during temporary-file creation.

Line 41 starts try after WriteAllText and path conversion. If either operation fails, finally does not run and a temporary script can remain in the runner temp directory.

Move creation, path conversion, and execution inside try. Initialize $script before try, guard the cleanup, and use Remove-Item -LiteralPath.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ops/platform-acceptance/windows.ps1` around lines 36 - 45, Update the
temporary script handling around $script so creation, path conversion, and WSL
execution all occur inside the try block. Initialize $script before try, guard
cleanup in finally so it only runs when a path was assigned, and use Remove-Item
-LiteralPath for deletion.

}
}
function Assert-DistroVersion([string] $ExpectedVersion) {
if ($ExpectedVersion -notmatch '^\d+\.\d+\.\d+$') { Refuse 'expected distribution version is invalid' }
Expand Down
5 changes: 4 additions & 1 deletion test/phase4-platform-acceptance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ test("Windows code publishes no artifact/signing claim and requires honest reboo
assert.match(windows, /apply-linux-release\.sh/);
assert.match(windows, /function Assert-DistroVersion/);
assert.equal((windows.match(/Assert-DistroVersion \$(?:Version|PreviousVersion)/g) || []).length, 4);
assert.match(windows, /\$Command \| & \$Wsl -d \$Distro -u root --exec \/bin\/bash -s/);
assert.match(windows, /UTF8Encoding\(\$false\)/);
assert.match(windows, /\[IO\.File\]::WriteAllText/);
assert.match(windows, /\/bin\/bash -lc "bash '\$scriptInDistro'"/);
assert.doesNotMatch(windows, /\$Command \| & \$Wsl/);
assert.doesNotMatch(windows, /\/bin\/bash -lc \$Command/);
assert.doesNotMatch(windows, /Invoke-Distro "test .*systemctl/);
assert.match(windows, /LocalRootfs/);
Expand Down
Loading