import { describe, expect, it } from "vitest"; import { parseCommandIntent } from "../src/services/commandIntent.js"; import { detectStuckConditions, interpretConnectorHealth } from "../src/services/diagnostics.js"; import { buildPulse } from "../src/services/pulse.js"; import { deliveryValidationsAreGreen } from "../src/services/projectCompletion.js"; import { buildParallelGroups, rankReadyWork, type WorkGraphNodeView } from "../src/services/workGraph.js"; const graphNode = (patch: Partial = {}): WorkGraphNodeView => ({ id: "node-1", projectId: "project-1", stableKey: "node-1", source: "test", sourceId: "node-1", type: "feature", title: "Work", canonicalLifecycle: "ready", domainLifecycle: "pending", scope: "committed", priority: 50, risk: "normal", blockingStatus: "open", executionEligibility: "ready", attemptCount: 0, consecutiveFailureCount: 0, dependencies: [], dependents: [], completionEvidence: [], createdAt: "2026-09-12T10:00:00.000Z", updatedAt: "2026-09-12T10:00:00.000Z", ...patch, }); describe("operating-system user-facing services", () => { it("turns natural language into constrained policy instead of an execution bypass", () => { expect(parseCommandIntent("Continue this project but don't deploy.")).toMatchObject({ objective: "continue", policy: { deploy: "blocked", automaticRecovery: true }, allowedScope: ["required", "committed"], }); expect(parseCommandIntent("Finish everything required for release.")).toMatchObject({ objective: "release", requestedCompletionState: "definition_of_done", policy: { deploy: "unchanged" } }); }); it("distinguishes functional connector failure from process health", () => { expect(interpretConnectorHealth({ process: true, transport: true, authentication: true, api: true, functional_read: false })).toBe("degraded"); expect(interpretConnectorHealth({ process: true, transport: true, api: false })).toBe("unavailable"); expect(interpretConnectorHealth({ process: true, transport: true, authentication: true, authorization: true, api: true, functional_read: true, write_readiness: true })).toBe("healthy"); }); it("detects reclaimable stale work and keeps the repair explicit", () => { const now = Date.parse("2026-09-12T12:00:00.000Z"); expect(detectStuckConditions({ now, running: [{ id: "lease-1", leaseExpiresAt: "2026-09-12T11:00:00.000Z" }], queued: [{ id: "queue-1", queuedAt: "2026-09-12T11:00:00.000Z", consumerPresent: false }], })).toMatchObject([ { kind: "expired_lease", repairable: true }, { kind: "queue_without_consumer", repairable: true }, ]); }); it("summarizes meaningful pulse events instead of returning a raw event dump", () => { const pulse = buildPulse([ { at: "2026-09-12T11:55:00.000Z", kind: "work.completed", title: "Delivery merged", summary: "The delivery was merged." }, { at: "2026-09-12T11:56:00.000Z", kind: "heartbeat", title: "heartbeat", summary: "technical noise", meaningful: false }, { at: "2026-09-12T11:57:00.000Z", kind: "work.blocked", title: "Validation failed", summary: "Retrying automatically." }, ], Date.parse("2026-09-12T12:00:00.000Z")); expect(pulse.counts).toMatchObject({ meaningful: 2, completed: 1, blockers: 1 }); expect(pulse.nextLikelyAction).toContain("Retrying"); }); it("treats a released delivery as a meaningful result while keeping noise out", () => { const pulse = buildPulse([ { at: "2026-09-12T11:55:00.000Z", kind: "delivery.released", title: "Release completed", summary: "The release is live." }, { at: "2026-09-12T11:56:00.000Z", kind: "work.claimed", title: "Claimed", summary: "technical lease", meaningful: false }, ], Date.parse("2026-09-12T12:00:00.000Z")); expect(pulse.counts).toMatchObject({ meaningful: 1, completed: 1, active: 0 }); }); it("does not invent an operating action for unsupported language", () => { expect(parseCommandIntent("Tell me a joke")).toMatchObject({ objective: "unknown", confidence: 35 }); }); it("keeps Future work out of ready scheduling and separates conflicting groups", () => { const ready = [ graphNode({ id: "a", stableKey: "a", metadata: { touchedPaths: ["src/shared/a.ts"] } }), graphNode({ id: "b", stableKey: "b", metadata: { touchedPaths: ["src/shared/a.ts"] } }), graphNode({ id: "c", stableKey: "c", scope: "future" }), ]; expect(rankReadyWork(ready).map((item) => item.id)).toEqual(["a", "b"]); expect(buildParallelGroups(rankReadyWork(ready))).toHaveLength(2); }); it("does not mark a delivery complete before its declared validations have run", () => { expect(deliveryValidationsAreGreen(["pnpm test"], [])).toBe(false); expect(deliveryValidationsAreGreen(["pnpm test"], [{ status: "passed" }])).toBe(true); expect(deliveryValidationsAreGreen(["pnpm test"], [{ status: "failed" }])).toBe(false); expect(deliveryValidationsAreGreen([], [])).toBe(true); }); });