@@ -154,6 +154,64 @@ public void CreateTerminalProcessStartInfo_SpecialCharacters_HandlesGracefully()
154154 Assert . IsNotNull ( startInfo ) ;
155155 }
156156
157+ #if UNITY_EDITOR_WIN
158+ [ TestCase ( 437 ) ]
159+ [ TestCase ( 936 ) ]
160+ public void CreateTerminalProcessStartInfo_UnicodePaths_SurviveLegacyCodePage ( int codePage )
161+ {
162+ string testDir = System . IO . Path . Combine ( System . IO . Path . GetTempPath ( ) ,
163+ "mcp-terminal-" + Guid . NewGuid ( ) . ToString ( "N" ) , "南京项目 空格" ) ;
164+ System . IO . Directory . CreateDirectory ( testDir ) ;
165+ string pidPath = System . IO . Path . Combine ( testDir , "mcp_http_8090.pid" ) ;
166+ string generatedScript = System . IO . Path . Combine ( _launcher . GetProjectRootPath ( ) ,
167+ "Library" , "MCPForUnity" , "TerminalScripts" , "mcp-terminal.cmd" ) ;
168+ byte [ ] originalScript = System . IO . File . Exists ( generatedScript )
169+ ? System . IO . File . ReadAllBytes ( generatedScript ) : null ;
170+
171+ try
172+ {
173+ _launcher . CreateTerminalProcessStartInfo ( $ "> \" { pidPath } \" echo 123") ;
174+ byte [ ] scriptBytes = System . IO . File . ReadAllBytes ( generatedScript ) ;
175+ Assert . IsFalse ( scriptBytes . Length >= 3 && scriptBytes [ 0 ] == 0xef
176+ && scriptBytes [ 1 ] == 0xbb && scriptBytes [ 2 ] == 0xbf ,
177+ "cmd scripts must not contain a UTF-8 BOM" ) ;
178+
179+ // Execute the generated bytes in a Unicode directory without opening a terminal.
180+ string scriptPath = System . IO . Path . Combine ( testDir , "mcp-terminal.cmd" ) ;
181+ System . IO . File . WriteAllBytes ( scriptPath , scriptBytes ) ;
182+ var startInfo = new System . Diagnostics . ProcessStartInfo
183+ {
184+ FileName = "cmd.exe" ,
185+ Arguments = $ "/d /c chcp { codePage } >nul & call \" { scriptPath } \" ",
186+ UseShellExecute = false ,
187+ CreateNoWindow = true ,
188+ RedirectStandardOutput = true ,
189+ RedirectStandardError = true
190+ } ;
191+ using ( var process = System . Diagnostics . Process . Start ( startInfo ) )
192+ {
193+ if ( ! process . WaitForExit ( 10000 ) )
194+ {
195+ process . Kill ( ) ;
196+ Assert . Fail ( "Generated cmd script did not finish within 10 seconds" ) ;
197+ }
198+ Assert . AreEqual ( 0 , process . ExitCode , process . StandardError . ReadToEnd ( ) ) ;
199+ }
200+
201+ Assert . IsTrue ( System . IO . File . Exists ( pidPath ) , "The Unicode pidfile path must be preserved" ) ;
202+ Assert . AreEqual ( "123" , System . IO . File . ReadAllText ( pidPath ) . Trim ( ) ) ;
203+ }
204+ finally
205+ {
206+ if ( originalScript != null )
207+ System . IO . File . WriteAllBytes ( generatedScript , originalScript ) ;
208+ else if ( System . IO . File . Exists ( generatedScript ) )
209+ System . IO . File . Delete ( generatedScript ) ;
210+ System . IO . Directory . Delete ( System . IO . Path . GetDirectoryName ( testDir ) , true ) ;
211+ }
212+ }
213+ #endif
214+
157215 #endregion
158216
159217 #region CreateHeadlessProcessStartInfo Tests
0 commit comments