import { describe, expect, it } from "vitest"; import { detectGoProject } from "./detect-go-project.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); }, }; } describe("detectGoProject", () => { const cwd = "/workspace/service"; it("detects a Go module from go.mod", async () => { const candidate = await detectGoProject({ cwd, probe: probeWithExistingPaths(["/workspace/service/go.mod"]), }); expect(candidate).toMatchObject({ language: "go", root: cwd, confidence: "high", }); expect(candidate?.reason).toContain("go.mod"); }); it("detects a Go workspace from go.work", async () => { const candidate = await detectGoProject({ cwd, probe: probeWithExistingPaths(["/workspace/service/go.work"]), }); expect(candidate).toMatchObject({ language: "go", root: cwd, confidence: "high", }); expect(candidate?.reason).toContain("go.work"); }); it("does not detect Go when neither go.mod nor go.work is present", async () => { const candidate = await detectGoProject({ cwd, probe: probeWithExistingPaths([]), }); expect(candidate).toBeUndefined(); }); });