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
19 changes: 19 additions & 0 deletions apps/server/src/provider/opencodeRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const childProcessMock = vi.hoisted(() => ({
if (command === "which" && args[0] === "opencode") {
return "/opt/homebrew/bin/opencode\n";
}
if (command === "where.exe" && args[0] === "opencode") {
return "C:\\Users\\testuser\\.bun\\bin\\opencode.exe\r\n";
}
return "";
}),
spawn: vi.fn(),
Expand All @@ -25,6 +28,22 @@ describe("resolveOpenCodeBinaryPath", () => {
it("resolves command names through PATH", async () => {
const { resolveOpenCodeBinaryPath } = await import("./opencodeRuntime.ts");

if (process.platform === "win32") {
assert.equal(
resolveOpenCodeBinaryPath("opencode"),
"C:\\Users\\testuser\\.bun\\bin\\opencode.exe",
);
assert.deepEqual(childProcessMock.execFileSync.mock.calls[0], [
"where.exe",
["opencode"],
{
encoding: "utf8",
timeout: 3_000,
},
]);
return;
}

assert.equal(resolveOpenCodeBinaryPath("opencode"), "/opt/homebrew/bin/opencode");
assert.deepEqual(childProcessMock.execFileSync.mock.calls[0], [
"which",
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/provider/opencodeRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ export function resolveOpenCodeBinaryPath(binaryPath: string): string {
if (Path.isAbsolute(binaryPath)) {
return binaryPath;
}
if (process.platform === "win32") {
return (
execFileSync("where.exe", [binaryPath], {
encoding: "utf8",
timeout: 3_000,
})
.split(/\r?\n/)
.map((s) => s.trim())
.find((s) => s.length > 0) ?? ""
);
}
return execFileSync("which", [binaryPath], {
encoding: "utf8",
timeout: 3_000,
Expand Down Expand Up @@ -361,6 +372,8 @@ export async function startOpenCodeServerProcess(input: {
const args = ["serve", `--hostname=${hostname}`, `--port=${port}`];
const child = spawn(input.binaryPath, args, {
stdio: ["ignore", "pipe", "pipe"],
// Windows needs shell mode to resolve opencode.cmd shim
shell: process.platform === "win32",
env: {
...process.env,
OPENCODE_CONFIG_CONTENT: JSON.stringify({}),
Expand Down
Loading