diff --git a/packages/gittensory-engine/src/index.ts b/packages/gittensory-engine/src/index.ts index 1cbb9b2757..d5dd8ded5a 100644 --- a/packages/gittensory-engine/src/index.ts +++ b/packages/gittensory-engine/src/index.ts @@ -123,6 +123,7 @@ export { countPlanStepsByStatus } from "./plan-step-stats.js"; export { isPlanFullyCompleted } from "./plan-completion.js"; export { hasPlanFailedSteps } from "./plan-failure.js"; export { hasPlanPendingSteps } from "./plan-pending.js"; +export { hasPlanRunningSteps } from "./plan-running.js"; export * from "./plan-templates.js"; export * from "./portfolio/queue.js"; export { diff --git a/packages/gittensory-engine/src/plan-running.ts b/packages/gittensory-engine/src/plan-running.ts new file mode 100644 index 0000000000..6909ddb184 --- /dev/null +++ b/packages/gittensory-engine/src/plan-running.ts @@ -0,0 +1,8 @@ +import type { PlanDag } from "./plan-export.js"; + +/** + * Return whether any step in the plan is currently running. Pure — reads the plan DAG only. + */ +export function hasPlanRunningSteps(plan: PlanDag): boolean { + return plan.steps.some((step) => step.status === "running"); +} diff --git a/test/unit/plan-running.test.ts b/test/unit/plan-running.test.ts new file mode 100644 index 0000000000..f684e1af97 --- /dev/null +++ b/test/unit/plan-running.test.ts @@ -0,0 +1,54 @@ +import { describe, expect, it } from "vitest"; + +import { hasPlanRunningSteps } from "../../packages/gittensory-engine/src/plan-running"; +import type { PlanStep } from "../../packages/gittensory-engine/src/plan-export"; + +function step(over: Partial & { id: string; title: string }): PlanStep { + return { + actionClass: undefined, + dependsOn: [], + status: "pending", + attempts: 0, + maxAttempts: 3, + lastError: null, + ...over, + }; +} + +describe("hasPlanRunningSteps", () => { + it("returns false for an empty plan", () => { + expect(hasPlanRunningSteps({ steps: [] })).toBe(false); + }); + + it("returns false when no step is running", () => { + expect( + hasPlanRunningSteps({ + steps: [ + step({ id: "a", title: "Build", status: "completed" }), + step({ id: "b", title: "Test", status: "pending" }), + ], + }), + ).toBe(false); + }); + + it("returns true when at least one step is running", () => { + expect( + hasPlanRunningSteps({ + steps: [ + step({ id: "a", title: "Build", status: "completed" }), + step({ id: "b", title: "Deploy", status: "running", attempts: 1 }), + ], + }), + ).toBe(true); + }); + + it("is exported from the package barrel", async () => { + const barrel = await import("../../packages/gittensory-engine/src/index"); + expect(typeof barrel.hasPlanRunningSteps).toBe("function"); + expect( + barrel.hasPlanRunningSteps({ + steps: [step({ id: "a", title: "A", status: "running", attempts: 1 })], + }), + ).toBe(true); + }); +});