From 7632b49d28e03e1ee777ac75b858dcb368f6d2d9 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 13 Jul 2026 04:58:06 +0000 Subject: [PATCH] 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] --- packages/core/src/shell/select.ts | 4 ++++ packages/core/test/shell.test.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/shell/select.ts b/packages/core/src/shell/select.ts index 11e6597ce1..92f5f22940 100644 --- a/packages/core/src/shell/select.ts +++ b/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", diff --git a/packages/core/test/shell.test.ts b/packages/core/test/shell.test.ts index ec0a707a99..d8171cbbf9 100644 --- a/packages/core/test/shell.test.ts +++ b/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 }", ) })