import { describe, expect, test } from "bun:test"; import { buildCleanupPlan, classifyExitCode, isCompatibleBinaryVersion, parseDevHygieneArgs, type Finding } from "./dev-hygiene.ts"; describe("dev hygiene tooling", () => { test("only accepts development-scoped modes and confirmation flags", () => { expect(parseDevHygieneArgs(["status"])).toEqual({ mode: "status", dryRun: false, yes: false, pruneUnreachable: false, help: false }); expect(parseDevHygieneArgs(["clean", "--dry-run"])).toEqual({ mode: "clean", dryRun: true, yes: false, pruneUnreachable: false, help: false }); expect(parseDevHygieneArgs(["clean", "--yes", "--prune-unreachable"])).toEqual({ mode: "clean", dryRun: false, yes: true, pruneUnreachable: true, help: false }); }); test("uses semantic exit codes for clean, warning, and blocked states", () => { const finding = (level: Finding["level"]): Finding => ({ id: level, level, message: level }); expect(classifyExitCode([])).toBe(0); expect(classifyExitCode([finding("info")])).toBe(0); expect(classifyExitCode([finding("warning")])).toBe(2); expect(classifyExitCode([finding("blocked")])).toBe(3); }); test("accepts a development build based on the current stable version", () => { expect(isCompatibleBinaryVersion("0.8.6", "0.8.6")).toBe(true); expect(isCompatibleBinaryVersion("0.8.6-dev.2+gabc1234", "0.8.6")).toBe(true); expect(isCompatibleBinaryVersion("0.8.5-dev.1+gold", "0.8.6")).toBe(false); expect(isCompatibleBinaryVersion(undefined, "0.8.6")).toBe(false); }); test("only plans deletion for clean merged worktrees and local branches", () => { const snapshot = { repository: {} as any, worktrees: [ { path: "/tmp/merged", head: "a", branch: "feat/merged", current: false, exists: true, clean: true }, { path: "/tmp/dirty", head: "b", branch: "feat/dirty", current: false, exists: true, clean: false }, ], branches: [ { name: "main", sha: "m", merged: true, gone: false }, { name: "feat/merged", sha: "a", merged: true, gone: false }, { name: "feat/dirty", sha: "b", merged: true, gone: false }, { name: "feat/live", sha: "c", merged: false, gone: false }, ], unreachableCommits: ["deadbeef"], skill: {} as any, binaries: [], legacyConfig: {} as any, }; const plan = buildCleanupPlan(snapshot, false); expect(plan.map((action) => action.target)).toEqual(["/tmp/merged", "feat/merged"]); expect(plan[1]?.kind).toBe("branch-delete"); expect(plan.some((action) => action.kind === "git-prune")).toBe(false); }); });