Skip to content

Commit 18002a8

Browse files
edburnsCopilot
andauthored
Fix Java builds with scoped npm registries on macOS (#2338)
* Fix Java builds with scoped npm registries on macOS Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Test: replace external blocking processes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a67956b commit 18002a8

4 files changed

Lines changed: 71 additions & 18 deletions

File tree

java/sdk/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
<workingDirectory>${copilot.sdk.root}/test/harness</workingDirectory>
202202
<arguments>
203203
<argument>ci</argument>
204+
<argument>--omit-lockfile-registry-resolved=true</argument>
204205
<argument>--loglevel</argument>
205206
<argument>${npm.loglevel}</argument>
206207
</arguments>
@@ -225,6 +226,7 @@
225226
<arguments>
226227
<argument>ci</argument>
227228
<argument>--ignore-scripts</argument>
229+
<argument>--omit-lockfile-registry-resolved=true</argument>
228230
<argument>--loglevel</argument>
229231
<argument>${npm.loglevel}</argument>
230232
</arguments>

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,13 @@ 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
76-
? new ProcessBuilder(System.getenv("COMSPEC"), "/c", "more")
77-
: new ProcessBuilder("/usr/bin/cat")).start();
78-
}
79-
8073
@Test
8174
void connectToServerStdioMode() throws Exception {
8275
var options = new CopilotClientOptions();
8376
var manager = new CliServerManager(options);
8477

8578
// Create a dummy process for stdio mode
86-
Process process = startBlockingProcess();
79+
Process process = new TestProcess();
8780
try {
8881
JsonRpcClient client = manager.connectToServer(process, null, null);
8982
assertNotNull(client);

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,17 @@ 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
139-
? new ProcessBuilder(System.getenv("COMSPEC"), "/c", "more")
140-
: new ProcessBuilder("/usr/bin/cat")).start();
141-
}
142-
143136
@Test
144137
void testIsConnectedWithProcess() throws Exception {
145-
Process proc = startBlockingProcess();
138+
Process proc = new TestProcess();
146139
try (var client = JsonRpcClient.fromProcess(proc)) {
147140
assertTrue(client.isConnected());
148141
}
149142
}
150143

151144
@Test
152145
void testIsConnectedWithProcessDead() throws Exception {
153-
Process proc = startBlockingProcess();
146+
Process proc = new TestProcess();
154147
var client = JsonRpcClient.fromProcess(proc);
155148
proc.destroy();
156149
proc.waitFor(5, TimeUnit.SECONDS);
@@ -162,7 +155,7 @@ void testIsConnectedWithProcessDead() throws Exception {
162155

163156
@Test
164157
void testGetProcessReturnsProcess() throws Exception {
165-
Process proc = startBlockingProcess();
158+
Process proc = new TestProcess();
166159
try (var client = JsonRpcClient.fromProcess(proc)) {
167160
assertSame(proc, client.getProcess());
168161
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot;
6+
7+
import java.io.InputStream;
8+
import java.io.OutputStream;
9+
import java.util.concurrent.CountDownLatch;
10+
import java.util.concurrent.TimeUnit;
11+
12+
final class TestProcess extends Process {
13+
14+
private final CountDownLatch terminated = new CountDownLatch(1);
15+
16+
@Override
17+
public OutputStream getOutputStream() {
18+
return OutputStream.nullOutputStream();
19+
}
20+
21+
@Override
22+
public InputStream getInputStream() {
23+
return InputStream.nullInputStream();
24+
}
25+
26+
@Override
27+
public InputStream getErrorStream() {
28+
return InputStream.nullInputStream();
29+
}
30+
31+
@Override
32+
public int waitFor() throws InterruptedException {
33+
terminated.await();
34+
return 0;
35+
}
36+
37+
@Override
38+
public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException {
39+
return terminated.await(timeout, unit);
40+
}
41+
42+
@Override
43+
public int exitValue() {
44+
if (isAlive()) {
45+
throw new IllegalThreadStateException("Process has not exited");
46+
}
47+
return 0;
48+
}
49+
50+
@Override
51+
public void destroy() {
52+
terminated.countDown();
53+
}
54+
55+
@Override
56+
public Process destroyForcibly() {
57+
destroy();
58+
return this;
59+
}
60+
61+
@Override
62+
public boolean isAlive() {
63+
return terminated.getCount() > 0;
64+
}
65+
}

0 commit comments

Comments
 (0)