Skip to content

Commit 15b3712

Browse files
authored
Merge pull request #67 from github/copilot/fix-code-for-review-comments
Fix cross-platform process creation in tests: use `cmd /c more` on Windows
2 parents c05b0a2 + 20acdbf commit 15b3712

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ void connectToServerTcpMode() throws Exception {
7070
}
7171
}
7272

73+
private static Process startBlockingProcess() throws IOException {
74+
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
75+
return (isWindows ? new ProcessBuilder("cmd", "/c", "more") : new ProcessBuilder("cat")).start();
76+
}
77+
7378
@Test
7479
void connectToServerStdioMode() throws Exception {
7580
var options = new CopilotClientOptions();
7681
var manager = new CliServerManager(options);
7782

7883
// Create a dummy process for stdio mode
79-
Process process = new ProcessBuilder("cat").start();
84+
Process process = startBlockingProcess();
8085
try {
8186
JsonRpcClient client = manager.connectToServer(process, null, null);
8287
assertNotNull(client);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,22 @@ void testIsConnectedWithSocketClosed() throws Exception {
133133
pair.serverSocket.close();
134134
}
135135

136+
private static Process startBlockingProcess() throws IOException {
137+
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
138+
return (isWindows ? new ProcessBuilder("cmd", "/c", "more") : new ProcessBuilder("cat")).start();
139+
}
140+
136141
@Test
137142
void testIsConnectedWithProcess() throws Exception {
138-
Process proc = new ProcessBuilder("cat").start();
143+
Process proc = startBlockingProcess();
139144
try (var client = JsonRpcClient.fromProcess(proc)) {
140145
assertTrue(client.isConnected());
141146
}
142147
}
143148

144149
@Test
145150
void testIsConnectedWithProcessDead() throws Exception {
146-
Process proc = new ProcessBuilder("cat").start();
151+
Process proc = startBlockingProcess();
147152
var client = JsonRpcClient.fromProcess(proc);
148153
proc.destroy();
149154
proc.waitFor(5, TimeUnit.SECONDS);
@@ -155,7 +160,7 @@ void testIsConnectedWithProcessDead() throws Exception {
155160

156161
@Test
157162
void testGetProcessReturnsProcess() throws Exception {
158-
Process proc = new ProcessBuilder("cat").start();
163+
Process proc = startBlockingProcess();
159164
try (var client = JsonRpcClient.fromProcess(proc)) {
160165
assertSame(proc, client.getProcess());
161166
}

0 commit comments

Comments
 (0)