Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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>
  • Loading branch information
Copilot and edburns authored Apr 20, 2026
commit ed3307fd3d29ff1337ce0491c2a4e4168003ec2a
18 changes: 16 additions & 2 deletions src/test/java/com/github/copilot/sdk/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@
import java.nio.file.Paths;

/**
* Shared test utilities for locating the Copilot CLI binary.
* Shared test utilities for locating the Copilot CLI binary and other
* cross-platform test helpers.
*/
final class TestUtil {
public final class TestUtil {

private TestUtil() {
}

/**
* Returns a platform-independent path string for a file inside the system
* temporary directory. Uses {@code java.io.tmpdir} so tests run correctly on
* both POSIX and Windows.
*
* @param filename
* the file name (no directory separator required)
* @return absolute path string in the system temp directory
*/
public static String tempPath(String filename) {
return Path.of(System.getProperty("java.io.tmpdir"), filename).toString();
}

/**
* Locates a launchable Copilot CLI executable.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import org.junit.jupiter.api.Test;

import com.github.copilot.sdk.TestUtil;

/**
* Tests for generated RPC param and result record types. Exercises
* constructors, field accessors, and enum variants to provide JaCoCo coverage
Expand Down Expand Up @@ -144,25 +146,25 @@ void sessionFleetStartParams_record() {

@Test
void sessionFsAppendFileParams_record() {
var params = new SessionFsAppendFileParams("sess-12", "/tmp/log.txt", "new line\n", null);
var params = new SessionFsAppendFileParams("sess-12", TestUtil.tempPath("log.txt"), "new line\n", null);
assertEquals("sess-12", params.sessionId());
assertEquals("/tmp/log.txt", params.path());
assertEquals(TestUtil.tempPath("log.txt"), params.path());
assertEquals("new line\n", params.content());
assertNull(params.mode());
}

@Test
void sessionFsExistsParams_record() {
var params = new SessionFsExistsParams("sess-13", "/tmp/file.txt");
var params = new SessionFsExistsParams("sess-13", TestUtil.tempPath("file.txt"));
assertEquals("sess-13", params.sessionId());
assertEquals("/tmp/file.txt", params.path());
assertEquals(TestUtil.tempPath("file.txt"), params.path());
}

@Test
void sessionFsMkdirParams_record() {
var params = new SessionFsMkdirParams("sess-14", "/tmp/newdir", true, null);
var params = new SessionFsMkdirParams("sess-14", TestUtil.tempPath("newdir"), true, null);
assertEquals("sess-14", params.sessionId());
assertEquals("/tmp/newdir", params.path());
assertEquals(TestUtil.tempPath("newdir"), params.path());
assertTrue(params.recursive());
assertNull(params.mode());
}
Expand Down Expand Up @@ -198,9 +200,9 @@ void sessionFsRenameParams_record() {

@Test
void sessionFsRmParams_record() {
var params = new SessionFsRmParams("sess-19", "/tmp/file.txt", false, true);
var params = new SessionFsRmParams("sess-19", TestUtil.tempPath("file.txt"), false, true);
assertEquals("sess-19", params.sessionId());
assertEquals("/tmp/file.txt", params.path());
assertEquals(TestUtil.tempPath("file.txt"), params.path());
assertFalse(params.recursive());
assertTrue(params.force());
}
Expand All @@ -224,11 +226,11 @@ void sessionFsStatParams_record() {

@Test
void sessionFsWriteFileParams_record() {
var params = new SessionFsWriteFileParams("sess-21", "/tmp/out.txt", "content here", 644.0);
var params = new SessionFsWriteFileParams("sess-21", TestUtil.tempPath("out.txt"), "content here", null);
assertEquals("sess-21", params.sessionId());
assertEquals("/tmp/out.txt", params.path());
assertEquals(TestUtil.tempPath("out.txt"), params.path());
assertEquals("content here", params.content());
assertEquals(644.0, params.mode());
assertNull(params.mode());
}

@Test
Expand Down
Loading