Skip to content

Commit db56504

Browse files
authored
Merge pull request #66 from edburns/edburns/windows-test-environment-fixes
Fix Windows test compatibility for ProcessBuilder usage
2 parents 15b3712 + fc71b95 commit db56504

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/test/java/com/github/copilot/sdk/CapiProxy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ public String start() throws IOException, InterruptedException {
8989
}
9090

9191
// Start the harness server using npx tsx
92-
var pb = new ProcessBuilder("npx", "tsx", "server.ts");
92+
// On Windows, npx is installed as npx.cmd which requires cmd /c to launch
93+
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
94+
var pb = isWindows
95+
? new ProcessBuilder("cmd", "/c", "npx", "tsx", "server.ts")
96+
: new ProcessBuilder("npx", "tsx", "server.ts");
9397
pb.directory(harnessDir.toFile());
9498
pb.redirectErrorStream(false);
9599

src/test/java/com/github/copilot/sdk/CliServerManagerTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ void processInfoWithNullPort() {
131131
// resolveCliCommand is private, so we test indirectly through startCliServer
132132
// with specific cliPath values.
133133

134+
// On Windows, "/nonexistent/copilot" is not an absolute path (no drive letter),
135+
// so resolveCliCommand wraps it with "cmd /c" and ProcessBuilder.start()
136+
// succeeds
137+
// (launching cmd.exe). Use a Windows-absolute path to ensure IOException.
138+
private static final String NONEXISTENT_CLI = System.getProperty("os.name").toLowerCase().contains("win")
139+
? "C:\\nonexistent\\copilot"
140+
: "/nonexistent/copilot";
141+
134142
@Test
135143
void startCliServerWithJsFile() throws Exception {
136144
// Using a .js file path causes resolveCliCommand to prepend "node"
@@ -152,8 +160,8 @@ void startCliServerWithJsFile() throws Exception {
152160
@Test
153161
void startCliServerWithCliArgs() throws Exception {
154162
// Test that cliArgs are included in the command
155-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot")
156-
.setCliArgs(new String[]{"--extra-flag"}).setUseStdio(true);
163+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setCliArgs(new String[]{"--extra-flag"})
164+
.setUseStdio(true);
157165
var manager = new CliServerManager(options);
158166

159167
var ex = assertThrows(IOException.class, () -> manager.startCliServer());
@@ -163,7 +171,7 @@ void startCliServerWithCliArgs() throws Exception {
163171
@Test
164172
void startCliServerWithExplicitPort() throws Exception {
165173
// Test the explicit port branch (useStdio=false, port > 0)
166-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setUseStdio(false).setPort(9999);
174+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setUseStdio(false).setPort(9999);
167175
var manager = new CliServerManager(options);
168176

169177
var ex = assertThrows(IOException.class, () -> manager.startCliServer());
@@ -173,7 +181,7 @@ void startCliServerWithExplicitPort() throws Exception {
173181
@Test
174182
void startCliServerWithGitHubToken() throws Exception {
175183
// Test the github token branch
176-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setGitHubToken("ghp_test123")
184+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setGitHubToken("ghp_test123")
177185
.setUseStdio(true);
178186
var manager = new CliServerManager(options);
179187

@@ -184,7 +192,7 @@ void startCliServerWithGitHubToken() throws Exception {
184192
@Test
185193
void startCliServerWithUseLoggedInUserExplicit() throws Exception {
186194
// Test the explicit useLoggedInUser=false branch (adds --no-auto-login)
187-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setUseLoggedInUser(false)
195+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setUseLoggedInUser(false)
188196
.setUseStdio(true);
189197
var manager = new CliServerManager(options);
190198

@@ -195,7 +203,7 @@ void startCliServerWithUseLoggedInUserExplicit() throws Exception {
195203
@Test
196204
void startCliServerWithGitHubTokenAndNoExplicitUseLoggedInUser() throws Exception {
197205
// When gitHubToken is set and useLoggedInUser is null, defaults to false
198-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setGitHubToken("ghp_test123")
206+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setGitHubToken("ghp_test123")
199207
.setUseStdio(true);
200208
var manager = new CliServerManager(options);
201209

@@ -225,8 +233,7 @@ void startCliServerWithTelemetryAllOptions() throws Exception {
225233
// so even with a nonexistent CLI path, the telemetry code path is exercised
226234
var telemetry = new TelemetryConfig().setOtlpEndpoint("http://localhost:4318").setFilePath("/tmp/telemetry.log")
227235
.setExporterType("otlp-http").setSourceName("test-app").setCaptureContent(true);
228-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
229-
.setUseStdio(true);
236+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setTelemetry(telemetry).setUseStdio(true);
230237
var manager = new CliServerManager(options);
231238

232239
var ex = assertThrows(IOException.class, () -> manager.startCliServer());
@@ -237,8 +244,7 @@ void startCliServerWithTelemetryAllOptions() throws Exception {
237244
void startCliServerWithTelemetryCaptureContentFalse() throws Exception {
238245
// Test the false branch of getCaptureContent()
239246
var telemetry = new TelemetryConfig().setCaptureContent(false);
240-
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
241-
.setUseStdio(true);
247+
var options = new CopilotClientOptions().setCliPath(NONEXISTENT_CLI).setTelemetry(telemetry).setUseStdio(true);
242248
var manager = new CliServerManager(options);
243249

244250
var ex = assertThrows(IOException.class, () -> manager.startCliServer());

0 commit comments

Comments
 (0)