@@ -75,8 +75,11 @@ void connectToServerStdioMode() throws Exception {
7575 var options = new CopilotClientOptions ();
7676 var manager = new CliServerManager (options );
7777
78- // Create a dummy process for stdio mode
79- Process process = new ProcessBuilder ("cat" ).start ();
78+ // Create a dummy process for stdio mode (use a cross-platform command)
79+ boolean isWindows = System .getProperty ("os.name" ).toLowerCase ().contains ("win" );
80+ Process process = isWindows
81+ ? new ProcessBuilder ("cmd" , "/c" , "type" , "NUL" ).start ()
82+ : new ProcessBuilder ("cat" ).start ();
8083 try {
8184 JsonRpcClient client = manager .connectToServer (process , null , null );
8285 assertNotNull (client );
@@ -126,6 +129,14 @@ void processInfoWithNullPort() {
126129 // resolveCliCommand is private, so we test indirectly through startCliServer
127130 // with specific cliPath values.
128131
132+ // On Windows, "/nonexistent/copilot" is not an absolute path (no drive letter),
133+ // so resolveCliCommand wraps it with "cmd /c" and ProcessBuilder.start()
134+ // succeeds
135+ // (launching cmd.exe). Use a Windows-absolute path to ensure IOException.
136+ private static final String NONEXISTENT_CLI = System .getProperty ("os.name" ).toLowerCase ().contains ("win" )
137+ ? "C:\\ nonexistent\\ copilot"
138+ : "/nonexistent/copilot" ;
139+
129140 @ Test
130141 void startCliServerWithJsFile () throws Exception {
131142 // Using a .js file path causes resolveCliCommand to prepend "node"
@@ -147,8 +158,8 @@ void startCliServerWithJsFile() throws Exception {
147158 @ Test
148159 void startCliServerWithCliArgs () throws Exception {
149160 // Test that cliArgs are included in the command
150- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" )
151- .setCliArgs ( new String []{ "--extra-flag" }). setUseStdio (true );
161+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ). setCliArgs ( new String []{ "--extra-flag" } )
162+ .setUseStdio (true );
152163 var manager = new CliServerManager (options );
153164
154165 var ex = assertThrows (IOException .class , () -> manager .startCliServer ());
@@ -158,7 +169,7 @@ void startCliServerWithCliArgs() throws Exception {
158169 @ Test
159170 void startCliServerWithExplicitPort () throws Exception {
160171 // Test the explicit port branch (useStdio=false, port > 0)
161- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setUseStdio (false ).setPort (9999 );
172+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setUseStdio (false ).setPort (9999 );
162173 var manager = new CliServerManager (options );
163174
164175 var ex = assertThrows (IOException .class , () -> manager .startCliServer ());
@@ -168,7 +179,7 @@ void startCliServerWithExplicitPort() throws Exception {
168179 @ Test
169180 void startCliServerWithGitHubToken () throws Exception {
170181 // Test the github token branch
171- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setGitHubToken ("ghp_test123" )
182+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setGitHubToken ("ghp_test123" )
172183 .setUseStdio (true );
173184 var manager = new CliServerManager (options );
174185
@@ -179,7 +190,7 @@ void startCliServerWithGitHubToken() throws Exception {
179190 @ Test
180191 void startCliServerWithUseLoggedInUserExplicit () throws Exception {
181192 // Test the explicit useLoggedInUser=false branch (adds --no-auto-login)
182- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setUseLoggedInUser (false )
193+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setUseLoggedInUser (false )
183194 .setUseStdio (true );
184195 var manager = new CliServerManager (options );
185196
@@ -190,7 +201,7 @@ void startCliServerWithUseLoggedInUserExplicit() throws Exception {
190201 @ Test
191202 void startCliServerWithGitHubTokenAndNoExplicitUseLoggedInUser () throws Exception {
192203 // When gitHubToken is set and useLoggedInUser is null, defaults to false
193- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setGitHubToken ("ghp_test123" )
204+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setGitHubToken ("ghp_test123" )
194205 .setUseStdio (true );
195206 var manager = new CliServerManager (options );
196207
@@ -220,8 +231,7 @@ void startCliServerWithTelemetryAllOptions() throws Exception {
220231 // so even with a nonexistent CLI path, the telemetry code path is exercised
221232 var telemetry = new TelemetryConfig ().setOtlpEndpoint ("http://localhost:4318" ).setFilePath ("/tmp/telemetry.log" )
222233 .setExporterType ("otlp-http" ).setSourceName ("test-app" ).setCaptureContent (true );
223- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setTelemetry (telemetry )
224- .setUseStdio (true );
234+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setTelemetry (telemetry ).setUseStdio (true );
225235 var manager = new CliServerManager (options );
226236
227237 var ex = assertThrows (IOException .class , () -> manager .startCliServer ());
@@ -232,8 +242,7 @@ void startCliServerWithTelemetryAllOptions() throws Exception {
232242 void startCliServerWithTelemetryCaptureContentFalse () throws Exception {
233243 // Test the false branch of getCaptureContent()
234244 var telemetry = new TelemetryConfig ().setCaptureContent (false );
235- var options = new CopilotClientOptions ().setCliPath ("/nonexistent/copilot" ).setTelemetry (telemetry )
236- .setUseStdio (true );
245+ var options = new CopilotClientOptions ().setCliPath (NONEXISTENT_CLI ).setTelemetry (telemetry ).setUseStdio (true );
237246 var manager = new CliServerManager (options );
238247
239248 var ex = assertThrows (IOException .class , () -> manager .startCliServer ());
0 commit comments