From 3a8d990ac7df18c937963dffd819f829b196c717 Mon Sep 17 00:00:00 2001 From: kiannidev <156195510+kiannidev@users.noreply.github.com> Date: Sun, 5 Jul 2026 08:36:47 +0200 Subject: [PATCH] feat(engine): add hasPlanPendingSteps Expose a pure plan-DAG pending check for miner and dashboard flows that need a quick in-progress signal. Co-authored-by: Cursor --- packages/gittensory-engine/src/index.ts | 1 + .../gittensory-engine/src/plan-pending.ts | 8 +++ test/unit/plan-pending.test.ts | 54 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 packages/gittensory-engine/src/plan-pending.ts create mode 100644 test/unit/plan-pending.test.ts diff --git a/packages/gittensory-engine/src/index.ts b/packages/gittensory-engine/src/index.ts index 0c6b9e03dd..1cbb9b2757 100644 --- a/packages/gittensory-engine/src/index.ts +++ b/packages/gittensory-engine/src/index.ts @@ -122,6 +122,7 @@ export * from "./plan-export.js"; 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 * from "./plan-templates.js"; export * from "./portfolio/queue.js"; export { diff --git a/packages/gittensory-engine/src/plan-pending.ts b/packages/gittensory-engine/src/plan-pending.ts new file mode 100644 index 0000000000..57611277d8 --- /dev/null +++ b/packages/gittensory-engine/src/plan-pending.ts @@ -0,0 +1,8 @@ +import type { PlanDag } from "./plan-export.js"; + +/** + * Return whether any step in the plan is still pending. Pure — reads the plan DAG only. + */ +export function hasPlanPendingSteps(plan: PlanDag): boolean { + return plan.steps.some((step) => step.status === "pending"); +} diff --git a/test/unit/plan-pending.test.ts b/test/unit/plan-pending.test.ts new file mode 100644 index 0000000000..593d9a0d93 --- /dev/null +++ b/test/unit/plan-pending.test.ts @@ -0,0 +1,54 @@ +import { describe, expect, it } from "vitest"; + +import { hasPlanPendingSteps } from "../../packages/gittensory-engine/src/plan-pending"; +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("hasPlanPendingSteps", () => { + it("returns false for an empty plan", () => { + expect(hasPlanPendingSteps({ steps: [] })).toBe(false); + }); + + it("returns false when no step is pending", () => { + expect( + hasPlanPendingSteps({ + steps: [ + step({ id: "a", title: "Build", status: "completed" }), + step({ id: "b", title: "Deploy", status: "failed" }), + ], + }), + ).toBe(false); + }); + + it("returns true when at least one step is pending", () => { + expect( + hasPlanPendingSteps({ + steps: [ + step({ id: "a", title: "Build", status: "completed" }), + step({ id: "b", title: "Test", status: "pending" }), + ], + }), + ).toBe(true); + }); + + it("is exported from the package barrel", async () => { + const barrel = await import("../../packages/gittensory-engine/src/index"); + expect(typeof barrel.hasPlanPendingSteps).toBe("function"); + expect( + barrel.hasPlanPendingSteps({ + steps: [step({ id: "a", title: "A", status: "pending" })], + }), + ).toBe(true); + }); +});