fix(core): force UTF-8 for Windows shells

Force cmd, PowerShell, and piped Python subprocesses to emit UTF-8 so V2 shell output is decoded without CJK mojibake.

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
This commit is contained in:
Dax Raad 2026-07-13 03:48:24 +00:00
commit 34cfa8601f
5 changed files with 43 additions and 4 deletions

View file

@ -61,6 +61,23 @@ describe("shell", () => {
expect(ShellSelect.args("/bin/bash", "echo hi")).toEqual(["-c", "echo hi"])
})
test("switches cmd output to UTF-8", () => {
expect(ShellSelect.args("cmd", 'echo "你好"')).toEqual(["/d", "/c", 'chcp 65001 >nul 2>nul & echo "你好"'])
})
test("transports PowerShell commands independently of the active code page", () => {
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'))))",
)
})
test("forces piped Python output to UTF-8 on Windows", () => {
expect(ShellSelect.env("win32")).toEqual({ PYTHONIOENCODING: "utf-8" })
expect(ShellSelect.env("linux")).toEqual({})
})
if (process.platform === "win32") {
test("rejects blacklisted shells case-insensitively", async () => {
await withShell("NU.EXE", async () => {