Skip to content

fix(windows): preserve Unicode paths in terminal launch scripts - #1451

Merged
Scriptwonder merged 2 commits into
CoplayDev:betafrom
yyt1216:fix/windows-terminal-utf8
Oct 19, 2026
Merged

Scriptwonder merged 2 commits into
CoplayDev:betafrom
yyt1216:fix/windows-terminal-utf8

Conversation

@yyt1216

@yyt1216 yyt1216 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

On Windows, the terminal launcher writes mcp-terminal.cmd as UTF-8 but cmd reads it using the inherited console code page. With a Chinese project path and code page 936, the MCP server receives a mojibake --pidfile path, creates a sibling directory with the corrupted name, and Unity cannot find the expected pidfile when stopping the server.

Set code page 65001 before the script's command is read and explicitly write UTF-8 without a BOM. This preserves Unicode paths passed to the server.

Type of Change

  • Bug fix (non-breaking change)
  • Test update

Changes Made

  • Add chcp 65001 >nul on its own line before the Windows launch command.
  • Write the Windows batch script using new UTF8Encoding(false).
  • Add Windows regression cases that execute the generated script bytes from a directory containing Chinese characters and spaces, starting with code pages 437 and 936, and verify that the pidfile appears at its intended Unicode path. The tests run cmd without opening a terminal and restore the original generated script afterward.

Compatibility / Package Source

  • Unity tested: 2022.3.56f1c1 on Windows.
  • PR branched from upstream beta.
  • Also applied the same minimal fix to local embedded file: packages at version 9.7.1; the connected consumer project completed compilation and regenerated a script containing the UTF-8 setup.
  • Git package lock hash: N/A (file: packages).

Testing

  • Unity EditMode: the full TerminalLauncherTests fixture, 26 passed, 0 failed, in an isolated minimal Unity project compiling the upstream launcher, interface, and test source.
  • Baseline regression check: the same fixture against the pre-fix launcher gives 24 passed, 2 failed; both new Unicode/code-page cases fail because cmd cannot find the intended path.
  • Real Windows argv probe: a UTF-8 batch script under code page 936 corrupts a Chinese --pidfile argument before the fix and preserves it with the fix.
  • Consumer package compilation and live generated-script check.
  • git diff --check.
  • Full repository EditMode/PlayMode suite and other Unity versions were not run locally.

The Windows regression tests execute cmd and perform actual filesystem writes; they do not launch an MCP server or an interactive terminal. No live server restart is claimed by this validation.

Documentation Updates

No tool/resource schemas or generated documentation change.

Summary by CodeRabbit

  • Bug Fixes
    • Windows terminal scripts are now written in UTF-8 without a byte-order mark, and the command prompt is switched to UTF-8 before execution. This keeps the script encoding and command prompt code page aligned, improving handling of Unicode characters, including in paths, across differing Windows code-page settings when launching terminal commands.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c33401fb-7c34-4ad2-836b-9e7c17cfcce7
📥 Commits

Reviewing files that changed from the base of the PR and between 7ba4906 and c1f9344.

📒 Files selected for processing: 1
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/TerminalLauncherTests.cs
+---------------------------------------------+
| You shall not pass...without a code review! |
+---------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ead19b2-55d1-4c8b-88af-cd350b6a9b8d
📥 Commits

Reviewing files that changed from the base of the PR and between ef713af and 7ba4906.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Services/Server/TerminalLauncher.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/TerminalLauncherTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The Windows terminal script is now written as UTF-8 without a BOM and sets cmd to code page 65001 before running. Windows-only tests verify execution and PID file creation from a Unicode directory under code pages 437 and 936.

Changes: Windows terminal script encoding

Layer / File(s) Summary
Script generation and execution validation
MCPForUnity/Editor/Services/Server/TerminalLauncher.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/TerminalLauncherTests.cs
The generated script uses UTF-8 without a BOM and switches cmd to code page 65001. Windows tests execute it under code pages 437 and 936 from a Unicode directory, then verify the PID file contents.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: scriptwonder

Merge Risk: ⚪ Minimal · up to 7ba49

The supplied review identifies no issue that needs resolution before merging. Complete the normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bug, implementation, compatibility details, tests, limitations, and documentation impact. It is mostly complete despite omitting the template's Related Issues and …
Title check ✅ Passed The title clearly and concisely identifies the Windows fix for preserving Unicode paths in terminal launch scripts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Scriptwonder
Scriptwonder merged commit 40955c8 into CoplayDev:beta Oct 19, 2026
6 of 7 checks passed
Scriptwonder added a commit to Scriptwonder/unity-mcp that referenced this pull request Oct 19, 2026
The cleanup commit in CoplayDev#1451 deleted the whole TerminalLauncherTests.cs instead of only
the Unicode-path case the PR added. This brings back the 24 tests that existed before
(including the CoplayDev#1279 stdin-redirect guard) and pairs the file with its .meta again.
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.

2 participants