Open History to see the last commit
1import assert from "node:assert/strict";
2
3import { describe, it, vi } from "vitest";
4
5const childProcessMock = vi.hoisted(() => ({
6 execFileSync: vi.fn((command: string, args: ReadonlyArray<string>) => {
7 if (command === "which" && args[0] === "opencode") {
8 return "/opt/homebrew/bin/opencode\n";
9 }
10 return "";
11 }),
12 spawn: vi.fn(),
13}));
14
15vi.mock("node:child_process", () => childProcessMock);
16
17describe("resolveOpenCodeBinaryPath", () => {
18 it("returns absolute binary paths without PATH lookup", async () => {
19 const { resolveOpenCodeBinaryPath } = await import("./opencodeRuntime.ts");
20
21 assert.equal(resolveOpenCodeBinaryPath("/usr/local/bin/opencode"), "/usr/local/bin/opencode");
22 assert.equal(childProcessMock.execFileSync.mock.calls.length, 0);
23 });
24
25 it("resolves command names through PATH", async () => {
26 const { resolveOpenCodeBinaryPath } = await import("./opencodeRuntime.ts");
27
28 assert.equal(resolveOpenCodeBinaryPath("opencode"), "/opt/homebrew/bin/opencode");
29 assert.deepEqual(childProcessMock.execFileSync.mock.calls[0], [
30 "which",
31 ["opencode"],
32 {
33 encoding: "utf8",
34 timeout: 3_000,
35 },
36 ]);
37 });
38});