Skip to content

fix(runtime): preserve CJK PowerShell output on Windows - #2569

Merged
Astro-Han merged 6 commits into
apache:mainfrom
me2seeks:fix/2366-windows-powershell-utf8
Aug 12, 2026
Merged

Astro-Han merged 6 commits into
apache:mainfrom
me2seeks:fix/2366-windows-powershell-utf8

Conversation

@me2seeks

@me2seeks me2seeks commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Windows PowerShell 5.1 can emit redirected output in a legacy console code page while both Runtime shell collectors decode UTF-8. This sets the PowerShell and native-pipeline encoding at the shared spawn-plan seam, so CJK filenames survive both pipe and PTY execution.

The user command stays in an isolated script block so setup does not invalidate script-level syntax. It travels through a private process environment slot instead of an expanded command line, and the wrapper clears that slot before user code runs.

Fixes #2366

中文对照

Windows PowerShell 5.1 可能先按旧控制台代码页写出重定向输出,而 Runtime 的两种 shell 收集路径都会按 UTF-8 解码。本 PR 在共享 spawn plan 中同时设置 PowerShell 输出与 native pipeline 编码,使中文文件名在 pipe 和 PTY 两条路径中都能正确保留。

用户命令仍作为独立 ScriptBlock 解析,避免初始化语句破坏脚本级语法。命令通过进程私有环境槽传递,不放大 Windows 命令行;wrapper 会在执行用户代码前清理该槽。

Verification

  • npm run build:test
  • npm --workspace @maka/runtime run test:dist — 3260 tests, 3255 passed, 5 platform skips
  • node --test scripts/windows-baseline-workflow.test.mjs — 2 passed, 1 Windows-only skip
  • npx biome check on all changed source, test, workflow, and script files
  • Added Windows baseline gates that create and enumerate 中文文件名.txt through both pipes and a real PTY; these require Windows PowerShell 5.1 and were not runnable on this Linux host

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@me2seeks
me2seeks force-pushed the fix/2366-windows-powershell-utf8 branch 3 times, most recently from e11ecb5 to a039deb Compare August 11, 2026 11:03

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — the central fix is at the right ownership seam. Both pipe and PTY execution receive the same PowerShell UTF-8 bootstrap, while the user script remains independently parsed, stays out of argv, and retains the existing exit-status behavior. The Windows tests exercise the real PowerShell 5.1 pipe and node-pty paths rather than a mocked encoding layer.

I left one focused P2 inline about preserving the caller-provided environment on the PTY path. The correction is small and local, so it does not need to block this approval. Please feel free to push back if there is another environment-normalization layer I missed.

Before merging, please rebase onto current main and obtain fresh CI. The red Linux format check is inherited from the PR’s old base rather than these changes. The two new CJK assertions themselves passed on Windows, but their test-file cleanup hit the existing SQLite EBUSY noise, so the non-blocking Windows step was not a clean pass.

中文对照

已批准。核心修复位于正确的职责边界:pipe 和 PTY 执行共用同一套 PowerShell UTF-8 bootstrap,同时用户脚本仍独立解析、不进入 argv,并保留原有退出状态语义。Windows 测试也真实经过 PowerShell 5.1 的 pipe 和 node-pty 路径,而不是模拟编码层。

我留下了一条聚焦的 P2 inline,指出 PTY 路径需要保留调用方传入的环境。修复很小且局部,因此不需要阻塞本次批准。如果我遗漏了其他环境归一化层,也欢迎指出。

合并前请 rebase 到当前 main 并取得新的 CI。Linux 的红色格式检查来自 PR 的旧 base,并非本次改动。两条新增 CJK 断言在 Windows 上本身已经通过,但测试文件清理遇到既有 SQLite EBUSY 噪声,所以该非阻塞 Windows step 还不能算干净通过。

AI-assisted review disclosure: Codex assisted with diff inspection, adversarial review of the PowerShell wrapper and Windows test evidence, and draft wording. Astro-Han verified the surviving finding, chose its severity and scope, and made the final approval decision.

@me2seeks
me2seeks force-pushed the fix/2366-windows-powershell-utf8 branch from a039deb to 836e7cf Compare August 12, 2026 13:53

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the PTY environment propagation in 836e7cf. The caller-provided environment now reaches the PowerShell wrapper and the PTY driver consistently, closing the remaining functional regression.

I also checked the latest Windows evidence: both real PowerShell 5.1 CJK gates completed successfully this time, without the earlier SQLite cleanup failure. The branch is cleanly mergeable and all CI checks are green.

One non-blocking test follow-up: the new “preserves the caller environment through a PowerShell PTY” regression is Windows-only, but the Windows baseline name pattern still selects only the two CJK tests and asserts # tests 2. Including this third test in that focused gate would make the regression executable in CI rather than skipped on every current lane.

I did not find any remaining reproducible P0–P3 issues. Approved and ready to merge.

AI-assisted review disclosure

Codex performed the incremental source, test, and Windows CI inspection. I, Astro-Han, reviewed the evidence and made the final review decision.

@Astro-Han
Astro-Han merged commit 5c6d3f4 into apache:main Aug 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(bash): Encoding error with pwsh on windows

2 participants