import { describe, expect, it } from "vitest"; import { normalizeAutonomyState } from "../src/repositories/autonomyRepository.js"; import { canonicalLifecycleFromAutonomy } from "../src/services/canonicalLifecycle.js"; describe("backend canonical lifecycle projection", () => { it("uses the same seven-state semantics as the product contract", () => { expect(canonicalLifecycleFromAutonomy(normalizeAutonomyState({ enabled: false, status: "off" }))).toBe("ready"); expect(canonicalLifecycleFromAutonomy(normalizeAutonomyState({ enabled: true, status: "blocked", blocker: { kind: "human", reason: "Owner decision required", at: "2026-09-01T00:00:00Z" }, }))).toBe("needs_user"); expect(canonicalLifecycleFromAutonomy(normalizeAutonomyState({ enabled: true, status: "blocked", blocker: { kind: "retryable", reason: "Runner timeout", at: "2026-09-01T00:00:00Z" }, }))).toBe("recovering"); const completed = normalizeAutonomyState({ enabled: true, status: "completed" }); expect(canonicalLifecycleFromAutonomy({ ...completed, status: "completed" })).toBe("done"); }); });