Skip to content

Fix Windows test compatibility for ProcessBuilder usage#66

Merged
edburns merged 1 commit intogithub:mainfrom
edburns:edburns/windows-test-environment-fixes
Apr 11, 2026
Merged

Fix Windows test compatibility for ProcessBuilder usage#66
edburns merged 1 commit intogithub:mainfrom
edburns:edburns/windows-test-environment-fixes

Conversation

@edburns
Copy link
Copy Markdown
Collaborator

@edburns edburns commented Apr 11, 2026

Fixes #65 .

On Windows, Java's ProcessBuilder cannot directly run shell wrappers like npx (installed as npx.cmd) or Unix commands like cat. Tests that used these commands failed with "Cannot run program" errors. Additionally, Unix-style paths like "/nonexistent/copilot" are not absolute on Windows, causing assertThrows(IOException) tests to pass unexpectedly when CliServerManager wrapped them with "cmd /c".

Changes:

  • CapiProxy: use "cmd /c npx" on Windows to launch the test harness
  • CliServerManagerTest: replace "cat" with cross-platform dummy process; use a platform-appropriate nonexistent absolute path so IOException is thrown on all platforms
  • JsonRpcClientTest: replace "cat" with cross-platform dummy process

All changes use runtime os.name detection and preserve existing behavior on Linux and macOS. Full test suite passes on all platforms (556 tests, 0 failures, 0 errors).

Resolves #65

Copilot AI review requested due to automatic review settings April 11, 2026 14:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves Windows compatibility for tests that spawn external processes via ProcessBuilder, avoiding failures due to Windows-specific executable resolution (.cmd) and Unix-only commands/paths.

Changes:

  • Update CapiProxy to start the test harness via cmd /c npx ... on Windows.
  • Update unit tests to avoid Unix-only process commands and to use a Windows-absolute nonexistent CLI path.
  • Preserve existing behavior on Linux/macOS via runtime os.name detection.
Show a summary per file
File Description
src/test/java/com/github/copilot/sdk/JsonRpcClientTest.java Switches dummy process creation to use a Windows-compatible command.
src/test/java/com/github/copilot/sdk/CliServerManagerTest.java Uses a Windows-absolute nonexistent CLI path and updates stdio dummy process creation.
src/test/java/com/github/copilot/sdk/CapiProxy.java Launches npx tsx server.ts through cmd /c on Windows to handle npx.cmd.

Copilot's findings

Comments suppressed due to low confidence (1)

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

  • Same issue as above: the Windows dummy process (cmd /c type NUL) can exit immediately, so this test may not actually cover the “process becomes dead after being alive” scenario. Consider switching the Windows branch to a command that blocks on stdin so the process is reliably alive until you destroy it in the test.
        boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
        Process proc = isWindows
                ? new ProcessBuilder("cmd", "/c", "type", "NUL").start()
                : new ProcessBuilder("cat").start();
        var client = JsonRpcClient.fromProcess(proc);
        proc.destroy();
        proc.waitFor(5, TimeUnit.SECONDS);
        assertFalse(client.isConnected());
  • Files reviewed: 3/3 changed files
  • Comments generated: 2

On Windows, Java's ProcessBuilder cannot directly run shell wrappers
like `npx` (installed as npx.cmd) or Unix commands like `cat`. Tests
that used these commands failed with "Cannot run program" errors.
Additionally, Unix-style paths like "/nonexistent/copilot" are not
absolute on Windows, causing assertThrows(IOException) tests to pass
unexpectedly when CliServerManager wrapped them with "cmd /c".

Changes:
- CapiProxy: use "cmd /c npx" on Windows to launch the test harness
- CliServerManagerTest: replace "cat" with cross-platform dummy process;
  use a platform-appropriate nonexistent absolute path so IOException
  is thrown on all platforms
- JsonRpcClientTest: replace "cat" with cross-platform dummy process

All changes use runtime os.name detection and preserve existing
behavior on Linux and macOS. Full test suite passes on all platforms
(556 tests, 0 failures, 0 errors).
@edburns edburns force-pushed the edburns/windows-test-environment-fixes branch from 6cabb00 to fc71b95 Compare April 11, 2026 16:00
@edburns edburns merged commit db56504 into github:main Apr 11, 2026
3 checks passed
@edburns edburns deleted the edburns/windows-test-environment-fixes branch April 11, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MAINT]: Make it so tests can run on Windows

2 participants