|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { isDone, nextReadySteps } from "../../packages/loopover-engine/src/plan-step-readiness"; |
| 4 | +import type { PlanStep, PlanStepStatus } from "../../packages/loopover-engine/src/plan-export"; |
| 5 | + |
| 6 | +function step(over: Partial<PlanStep> & { id: string; title: string }): PlanStep { |
| 7 | + return { |
| 8 | + actionClass: undefined, |
| 9 | + dependsOn: [], |
| 10 | + status: "pending", |
| 11 | + attempts: 0, |
| 12 | + maxAttempts: 3, |
| 13 | + lastError: null, |
| 14 | + ...over, |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | +describe("isDone", () => { |
| 19 | + it.each<PlanStepStatus>(["pending", "running", "failed"])("returns false for %s", (status) => { |
| 20 | + expect(isDone(status)).toBe(false); |
| 21 | + }); |
| 22 | + |
| 23 | + it.each<PlanStepStatus>(["completed", "skipped"])("returns true for %s", (status) => { |
| 24 | + expect(isDone(status)).toBe(true); |
| 25 | + }); |
| 26 | +}); |
| 27 | + |
| 28 | +describe("nextReadySteps", () => { |
| 29 | + it("returns a pending step with no dependencies", () => { |
| 30 | + const ready = step({ id: "a", title: "Build", status: "pending" }); |
| 31 | + expect(nextReadySteps({ steps: [ready] })).toEqual([ready]); |
| 32 | + }); |
| 33 | + |
| 34 | + it("returns a pending step when its dependency is completed", () => { |
| 35 | + const dep = step({ id: "a", title: "Build", status: "completed" }); |
| 36 | + const ready = step({ id: "b", title: "Test", status: "pending", dependsOn: ["a"] }); |
| 37 | + expect(nextReadySteps({ steps: [dep, ready] })).toEqual([ready]); |
| 38 | + }); |
| 39 | + |
| 40 | + it("returns a pending step when its dependency is skipped", () => { |
| 41 | + const dep = step({ id: "a", title: "Build", status: "skipped" }); |
| 42 | + const ready = step({ id: "b", title: "Test", status: "pending", dependsOn: ["a"] }); |
| 43 | + expect(nextReadySteps({ steps: [dep, ready] })).toEqual([ready]); |
| 44 | + }); |
| 45 | + |
| 46 | + it.each<PlanStepStatus>(["running", "failed"])("returns no ready steps when a dependency is %s", (status) => { |
| 47 | + const dep = step({ id: "a", title: "Build", status }); |
| 48 | + const blocked = step({ id: "b", title: "Test", status: "pending", dependsOn: ["a"] }); |
| 49 | + expect(nextReadySteps({ steps: [dep, blocked] })).toEqual([]); |
| 50 | + }); |
| 51 | + |
| 52 | + it("returns no ready steps when a dependency is still pending", () => { |
| 53 | + const dep = step({ id: "a", title: "Build", status: "pending", dependsOn: ["ghost"] }); |
| 54 | + const blocked = step({ id: "b", title: "Test", status: "pending", dependsOn: ["a"] }); |
| 55 | + expect(nextReadySteps({ steps: [dep, blocked] })).toEqual([]); |
| 56 | + }); |
| 57 | +}); |
0 commit comments