-
Notifications
You must be signed in to change notification settings - Fork 0
fix(phase4): execute Windows WSL scripts without BOM #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" } | ||
| } finally { | ||
| Remove-Item $script -Force -ErrorAction SilentlyContinue | ||
|
Comment on lines
+36
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Move creation, path conversion, and execution inside 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| function Assert-DistroVersion([string] $ExpectedVersion) { | ||
| if ($ExpectedVersion -notmatch '^\d+\.\d+\.\d+$') { Refuse 'expected distribution version is invalid' } | ||
|
|
||
There was a problem hiding this comment.
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
bashwithout-e, and Line 38 does not prependset -e. Bash returns the status of the final command. InAssert-DistroVersion, a failed service check followed by a successful version check returns 0, so Line 43 records false success.Run the script with
bash -eor writeset -eas the first line. Add a regression case with a failed first command and a successful final command. Ifbash -eis used, update Line 217 intest/phase4-platform-acceptance.mjs.🤖 Prompt for AI Agents