import { describe, expect, it } from "vitest"; import { runProjectTests } from "./run-project-tests.ts"; import type { CommandExecutionOptions, CommandExecutionResult, CommandExecutor, } from "../ports/command-executor.ts"; import type { ProjectProbe } from "../ports/project-probe.ts"; function probeWithExistingPaths(existingPaths: string[]): ProjectProbe { const existing = new Set(existingPaths); return { async exists(path: string): Promise { return existing.has(path); }, }; } type ExecutionCall = { command: string; args: string[]; options: CommandExecutionOptions; }; function recordingExecutor( result: CommandExecutionResult = { stdout: "PASS\n", stderr: "", code: 0, killed: false, }, ): { executor: CommandExecutor; calls: ExecutionCall[] } { const calls: ExecutionCall[] = []; return { calls, executor: { async exec(command, args, options) { calls.push({ command, args, options }); return result; }, }, }; } describe("runProjectTests", () => { const cwd = "/workspace/service"; it("resolves and executes the default Go test plan", async () => { const { executor, calls } = recordingExecutor(); const result = await runProjectTests({ cwd, argsTail: "", probe: probeWithExistingPaths(["/workspace/service/go.mod"]), executor, }); expect(calls).toHaveLength(1); expect(calls[0]).toMatchObject({ command: "go", args: ["test", "-race", "./..."], options: { cwd }, }); expect(result).toEqual({ ok: true, displayCommand: "go test -race ./...", stdout: "PASS\n", stderr: "", exitCode: 0, killed: false, }); }); it("passes slash command arguments through to the resolved Go test plan", async () => { const { executor, calls } = recordingExecutor(); await runProjectTests({ cwd, argsTail: "--tags contract,e2e", probe: probeWithExistingPaths(["/workspace/service/go.work"]), executor, }); expect(calls).toHaveLength(1); expect(calls[0]).toMatchObject({ command: "go", args: ["test", "-race", "-tags=contract,e2e", "./..."], options: { cwd }, }); }); it("forwards timeout and abort signal to command execution", async () => { const signal = new AbortController().signal; const { executor, calls } = recordingExecutor(); await runProjectTests({ cwd, argsTail: "", probe: probeWithExistingPaths(["/workspace/service/go.mod"]), executor, timeoutMs: 45_000, signal, }); expect(calls).toHaveLength(1); expect(calls[0]?.options).toEqual({ cwd, timeoutMs: 45_000, signal, }); }); it("fails before execution when no supported project is detected", async () => { const { executor, calls } = recordingExecutor(); await expect( runProjectTests({ cwd, argsTail: "", probe: probeWithExistingPaths([]), executor, }), ).rejects.toThrow(/unsupported project/i); expect(calls).toEqual([]); }); });