Selaa lähdekoodia

fix(core): preserve PowerShell exit codes

Capture native and PowerShell command status after the UTF-8 wrapper so failing commands still settle with a non-zero exit.

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Dax Raad 4 viikkoa sitten
vanhempi
sitoutus
7632b49d28
2 muutettua tiedostoa jossa 5 lisäystä ja 1 poistoa
  1. 4 0
      packages/core/src/shell/select.ts
  2. 1 1
      packages/core/test/shell.test.ts

+ 4 - 0
packages/core/src/shell/select.ts

@@ -181,6 +181,10 @@ export function args(file: string, command: string) {
       "[Console]::OutputEncoding = $utf8",
       "$OutputEncoding = $utf8",
       `& ([scriptblock]::Create([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${payload}'))))`,
+      "$success = $?",
+      "$code = $LASTEXITCODE",
+      "if ($null -ne $code) { exit $code }",
+      "if (-not $success) { exit 1 }",
     ].join("; ")
     return [
       "-NoLogo",

+ 1 - 1
packages/core/test/shell.test.ts

@@ -69,7 +69,7 @@ describe("shell", () => {
     const args = ShellSelect.args("pwsh", 'Write-Output "你好"')
     expect(args.slice(0, 4)).toEqual(["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand"])
     expect(Buffer.from(args[4], "base64").toString("utf16le")).toBe(
-      "$utf8 = [System.Text.UTF8Encoding]::new($false); [Console]::InputEncoding = $utf8; [Console]::OutputEncoding = $utf8; $OutputEncoding = $utf8; & ([scriptblock]::Create([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('V3JpdGUtT3V0cHV0ICLkvaDlpb0i'))))",
+      "$utf8 = [System.Text.UTF8Encoding]::new($false); [Console]::InputEncoding = $utf8; [Console]::OutputEncoding = $utf8; $OutputEncoding = $utf8; & ([scriptblock]::Create([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('V3JpdGUtT3V0cHV0ICLkvaDlpb0i')))); $success = $?; $code = $LASTEXITCODE; if ($null -ne $code) { exit $code }; if (-not $success) { exit 1 }",
     )
   })