Skip to content

Commit ed3307f

Browse files
Copilotedburns
andauthored
Fix POSIXisms: use TestUtil.tempPath() for cross-platform temp paths
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/b7de171b-6625-4ab4-b222-4858b0cacfc2 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 863eba8 commit ed3307f

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010
import java.nio.file.Paths;
1111

1212
/**
13-
* Shared test utilities for locating the Copilot CLI binary.
13+
* Shared test utilities for locating the Copilot CLI binary and other
14+
* cross-platform test helpers.
1415
*/
15-
final class TestUtil {
16+
public final class TestUtil {
1617

1718
private TestUtil() {
1819
}
1920

21+
/**
22+
* Returns a platform-independent path string for a file inside the system
23+
* temporary directory. Uses {@code java.io.tmpdir} so tests run correctly on
24+
* both POSIX and Windows.
25+
*
26+
* @param filename
27+
* the file name (no directory separator required)
28+
* @return absolute path string in the system temp directory
29+
*/
30+
public static String tempPath(String filename) {
31+
return Path.of(System.getProperty("java.io.tmpdir"), filename).toString();
32+
}
33+
2034
/**
2135
* Locates a launchable Copilot CLI executable.
2236
* <p>

src/test/java/com/github/copilot/sdk/generated/rpc/GeneratedRpcRecordsCoverageTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.junit.jupiter.api.Test;
1414

15+
import com.github.copilot.sdk.TestUtil;
16+
1517
/**
1618
* Tests for generated RPC param and result record types. Exercises
1719
* constructors, field accessors, and enum variants to provide JaCoCo coverage
@@ -144,25 +146,25 @@ void sessionFleetStartParams_record() {
144146

145147
@Test
146148
void sessionFsAppendFileParams_record() {
147-
var params = new SessionFsAppendFileParams("sess-12", "/tmp/log.txt", "new line\n", null);
149+
var params = new SessionFsAppendFileParams("sess-12", TestUtil.tempPath("log.txt"), "new line\n", null);
148150
assertEquals("sess-12", params.sessionId());
149-
assertEquals("/tmp/log.txt", params.path());
151+
assertEquals(TestUtil.tempPath("log.txt"), params.path());
150152
assertEquals("new line\n", params.content());
151153
assertNull(params.mode());
152154
}
153155

154156
@Test
155157
void sessionFsExistsParams_record() {
156-
var params = new SessionFsExistsParams("sess-13", "/tmp/file.txt");
158+
var params = new SessionFsExistsParams("sess-13", TestUtil.tempPath("file.txt"));
157159
assertEquals("sess-13", params.sessionId());
158-
assertEquals("/tmp/file.txt", params.path());
160+
assertEquals(TestUtil.tempPath("file.txt"), params.path());
159161
}
160162

161163
@Test
162164
void sessionFsMkdirParams_record() {
163-
var params = new SessionFsMkdirParams("sess-14", "/tmp/newdir", true, null);
165+
var params = new SessionFsMkdirParams("sess-14", TestUtil.tempPath("newdir"), true, null);
164166
assertEquals("sess-14", params.sessionId());
165-
assertEquals("/tmp/newdir", params.path());
167+
assertEquals(TestUtil.tempPath("newdir"), params.path());
166168
assertTrue(params.recursive());
167169
assertNull(params.mode());
168170
}
@@ -198,9 +200,9 @@ void sessionFsRenameParams_record() {
198200

199201
@Test
200202
void sessionFsRmParams_record() {
201-
var params = new SessionFsRmParams("sess-19", "/tmp/file.txt", false, true);
203+
var params = new SessionFsRmParams("sess-19", TestUtil.tempPath("file.txt"), false, true);
202204
assertEquals("sess-19", params.sessionId());
203-
assertEquals("/tmp/file.txt", params.path());
205+
assertEquals(TestUtil.tempPath("file.txt"), params.path());
204206
assertFalse(params.recursive());
205207
assertTrue(params.force());
206208
}
@@ -224,11 +226,11 @@ void sessionFsStatParams_record() {
224226

225227
@Test
226228
void sessionFsWriteFileParams_record() {
227-
var params = new SessionFsWriteFileParams("sess-21", "/tmp/out.txt", "content here", 644.0);
229+
var params = new SessionFsWriteFileParams("sess-21", TestUtil.tempPath("out.txt"), "content here", null);
228230
assertEquals("sess-21", params.sessionId());
229-
assertEquals("/tmp/out.txt", params.path());
231+
assertEquals(TestUtil.tempPath("out.txt"), params.path());
230232
assertEquals("content here", params.content());
231-
assertEquals(644.0, params.mode());
233+
assertNull(params.mode());
232234
}
233235

234236
@Test

0 commit comments

Comments
 (0)