fix(ci): run nested smoke scripts on same host + UTF-8 BOM

Windows CI failed because smoke.ps1 nested bare 'powershell' (often 5.1)
to run verify-routing-coherence.ps1. PS5.1 mis-parsed UTF-8 Chinese source
without BOM, so nested verify exited 1 while the standalone pwsh verify step passed.

- Resolve SmokeHostExe from current process (pwsh on GHA windows-latest)
- Rewrite nested invocations to use $SmokeHostExe
- Write UTF-8 BOM on smoke.ps1 and verify-routing-coherence.ps1 for PS5.1 safety
This commit is contained in:
yhc
2026-08-12 12:09:38 +08:00
parent 5d73e05e89
commit 172e03ada0
2 changed files with 22 additions and 6 deletions
+21 -5
View File
@@ -28,7 +28,23 @@ function Bad([string] $m) {
[void]$fail.Add($m)
}
Write-Host ("=== reverse-skill smoke | LogDir={0} ===" -f $LogDir)
# Prefer the same host that launched smoke (pwsh on GHA windows-latest).
# Bare "powershell" often resolves to Windows PowerShell 5.1, which mis-parses
# UTF-8 scripts without BOM when nested from pwsh.
$SmokeHostExe = $null
try {
$procPath = (Get-Process -Id $PID -ErrorAction Stop).Path
if ($procPath -and (Test-Path -LiteralPath $procPath)) { $SmokeHostExe = $procPath }
} catch { }
if (-not $SmokeHostExe) {
$cmd = Get-Command pwsh -ErrorAction SilentlyContinue
if ($cmd -and $cmd.Source) {
$SmokeHostExe = $cmd.Source
} else {
$SmokeHostExe = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
}
}
Write-Host ("=== reverse-skill smoke | LogDir={0} | Host={1} ===" -f $LogDir, $SmokeHostExe)
# --- 1) routing coherence ---
$verify = Join-Path $scriptDir 'verify-routing-coherence.ps1'
@@ -37,7 +53,7 @@ if (-not (Test-Path -LiteralPath $verify)) {
$verifyExit = 1
} else {
$vLog = Join-Path $LogDir '01-verify.txt'
& powershell -NoProfile -ExecutionPolicy Bypass -File $verify 2>&1 | Tee-Object -FilePath $vLog | Out-Null
& $SmokeHostExe -NoProfile -ExecutionPolicy Bypass -File $verify 2>&1 | Tee-Object -FilePath $vLog | Out-Null
$verifyExit = $LASTEXITCODE
if ($verifyExit -eq 0) { Ok 'verify-routing-coherence exit 0' } else { Bad ("verify-routing-coherence exit {0}" -f $verifyExit) }
}
@@ -106,7 +122,7 @@ if (-not (Test-Path -LiteralPath $mr)) {
} else {
foreach ($c in $cases) {
$outFile = Join-Path $LogDir ("route-{0}.txt" -f $c.Name)
$raw = & powershell -NoProfile -ExecutionPolicy Bypass -File $mr -Hint $c.Hint 2>&1 | Out-String
$raw = & $SmokeHostExe -NoProfile -ExecutionPolicy Bypass -File $mr -Hint $c.Hint 2>&1 | Out-String
$raw | Set-Content -Path $outFile -Encoding UTF8
if ($raw -match [regex]::Escape($c.Expect)) {
Ok ("route {0} -> {1}" -f $c.Name, $c.Expect)
@@ -128,7 +144,7 @@ if (-not (Test-Path -LiteralPath $appendEvidence)) {
Bad 'append-evidence.ps1 missing for immutability check'
} else {
New-Item -ItemType Directory -Path $evidenceCase -Force | Out-Null
& powershell -NoProfile -ExecutionPolicy Bypass -File $appendEvidence `
& $SmokeHostExe -NoProfile -ExecutionPolicy Bypass -File $appendEvidence `
-CaseRoot $evidenceCase `
-Id 'E-IMMUTABLE' `
-Title 'first write' `
@@ -142,7 +158,7 @@ if (-not (Test-Path -LiteralPath $appendEvidence)) {
$beforeEvidence = (Get-FileHash -LiteralPath $evidencePath -Algorithm SHA256).Hash
$beforeIndex = (Get-FileHash -LiteralPath $indexPath -Algorithm SHA256).Hash
& powershell -NoProfile -ExecutionPolicy Bypass -File $appendEvidence `
& $SmokeHostExe -NoProfile -ExecutionPolicy Bypass -File $appendEvidence `
-CaseRoot $evidenceCase `
-Id 'E-IMMUTABLE' `
-Title 'second write' `
+1 -1
View File
@@ -1,4 +1,4 @@
#Requires -Version 5.1
#Requires -Version 5.1
# reverse-skill routing + ops contract gates (skill-router only; no host platform runtime)
param([string] $ScratchDir = '')
$ErrorActionPreference = 'Stop'