import { describe, expect, it } from "vitest"; import { PiCommandExecutor, type PiExecApi } from "./pi-command-executor.ts"; type PiExecOptions = Parameters[2]; describe("PiCommandExecutor", () => { it("delegates command execution to pi.exec with cwd, timeout, and abort signal", async () => { const signal = new AbortController().signal; const calls: Array<{ command: string; args: string[]; options: PiExecOptions; }> = []; const pi: PiExecApi = { async exec(command, args, options) { calls.push({ command, args, options }); return { stdout: "", stderr: "", code: 0, killed: false }; }, sendUserMessage() {}, }; const executor = new PiCommandExecutor(pi); await executor.exec("go", ["test", "./..."], { cwd: "/workspace/service", timeoutMs: 30_000, signal, }); expect(calls).toEqual([ { command: "go", args: ["test", "./..."], options: { cwd: "/workspace/service", timeout: 30_000, signal, }, }, ]); }); it("returns pi.exec output without transformation", async () => { const executor = new PiCommandExecutor({ async exec() { return { stdout: "PASS", stderr: "warning", code: 2, killed: true, }; }, sendUserMessage() {}, }); await expect( executor.exec("go", ["test", "./..."], { cwd: "/workspace/service" }), ).resolves.toEqual({ stdout: "PASS", stderr: "warning", code: 2, killed: true, }); }); });