Files
t3code/apps/server/src/provider/opencodeRuntime.test.ts
T
ce94feeea1 feat: add opencode provider support (#1758)
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: codex <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-04-17 13:31:41 -07:00

39 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it, vi } from "vitest";
const childProcessMock = vi.hoisted(() => ({
execFileSync: vi.fn((command: string, args: ReadonlyArray<string>) => {
if (command === "which" && args[0] === "opencode") {
return "/opt/homebrew/bin/opencode\n";
}
return "";
}),
spawn: vi.fn(),
}));
vi.mock("node:child_process", () => childProcessMock);
describe("resolveOpenCodeBinaryPath", () => {
it("returns absolute binary paths without PATH lookup", async () => {
const { resolveOpenCodeBinaryPath } = await import("./opencodeRuntime.ts");
assert.equal(resolveOpenCodeBinaryPath("/usr/local/bin/opencode"), "/usr/local/bin/opencode");
assert.equal(childProcessMock.execFileSync.mock.calls.length, 0);
});
it("resolves command names through PATH", async () => {
const { resolveOpenCodeBinaryPath } = await import("./opencodeRuntime.ts");
assert.equal(resolveOpenCodeBinaryPath("opencode"), "/opt/homebrew/bin/opencode");
assert.deepEqual(childProcessMock.execFileSync.mock.calls[0], [
"which",
["opencode"],
{
encoding: "utf8",
timeout: 3_000,
},
]);
});
});