Fix cross-platform process creation in tests: use cmd /c more on Windows#67
Fix cross-platform process creation in tests: use cmd /c more on Windows#67
cmd /c more on Windows#67Conversation
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/a5638a0d-f412-4810-b724-45bc5f10438d Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
cmd /c more on Windows
|
@copilot did you get all the occurrences? |
Yes — all occurrences are covered. The only |
There was a problem hiding this comment.
Pull request overview
Updates unit tests to create a long-lived dummy stdio process in a cross-platform way (Windows vs Unix), improving reliability of process.isAlive()-based assertions in the SDK’s process-backed JSON-RPC client and CLI server manager tests.
Changes:
- Added a
startBlockingProcess()helper inJsonRpcClientTestto usecmd /c moreon Windows andcatelsewhere. - Added the same helper in
CliServerManagerTestand replaced the stdio dummy process creation. - Replaced all occurrences of
new ProcessBuilder("cat").start()in the affected tests.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/github/copilot/sdk/JsonRpcClientTest.java | Uses an OS-specific blocking process helper to make process-backed connection tests work on Windows. |
| src/test/java/com/github/copilot/sdk/CliServerManagerTest.java | Uses the same blocking process helper for stdio-mode connection testing on Windows. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
| private static Process startBlockingProcess() throws IOException { | ||
| boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); | ||
| return (isWindows ? new ProcessBuilder("cmd", "/c", "more") : new ProcessBuilder("cat")).start(); | ||
| } |
There was a problem hiding this comment.
The startBlockingProcess() helper is duplicated here and in CliServerManagerTest. Consider extracting it into a shared test utility (e.g., a package-private helper in src/test/java/com/github/copilot/sdk/) so future tweaks to the blocking command/OS detection only need to be made in one place.
| private static Process startBlockingProcess() throws IOException { | ||
| boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); | ||
| return (isWindows ? new ProcessBuilder("cmd", "/c", "more") : new ProcessBuilder("cat")).start(); | ||
| } |
There was a problem hiding this comment.
This startBlockingProcess() helper is identical to the one added in JsonRpcClientTest. Consider extracting it into a shared test utility to avoid duplication and keep the OS-specific command logic consistent across tests.
new ProcessBuilder("cat").start()is Unix-only. On Windows,catdoesn't exist, and usingcmd /c type NULas a substitute exits immediately rather than blocking on stdin — making any test that relies onprocess.isAlive()inherently flaky.Before the change?
JsonRpcClientTestandCliServerManagerTestusednew ProcessBuilder("cat").start()to create a long-lived process for testing, which only works on Unix.After the change?
startBlockingProcess()helper is added to both test classes. It selects the right command at runtime —cmd /c moreon Windows (blocks on stdin until destroyed) andcaton Unix — ensuring consistent cross-platform behaviour.new ProcessBuilder("cat").start()across the two test files are replaced:JsonRpcClientTest—testIsConnectedWithProcess,testIsConnectedWithProcessDead,testGetProcessReturnsProcessCliServerManagerTest—connectToServerStdioModeProcessBuilderusages in the test suite required this fix (remaining usages invoke the real Copilot CLI or thenpx tsxproxy server).Pull request checklist
mvn spotless:applyhas been run to format the codemvn clean verifypasses locallyDoes this introduce a breaking change?