Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/gittensory-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export {
} from "./governor-ledger.js";
export * from "./plan-export.js";
export { countPlanStepsByStatus } from "./plan-step-stats.js";
export { countPlanSteps } from "./plan-step-count.js";
export { isPlanFullyCompleted } from "./plan-completion.js";
export { hasPlanFailedSteps } from "./plan-failure.js";
export { hasPlanPendingSteps } from "./plan-pending.js";
Expand Down
8 changes: 8 additions & 0 deletions packages/gittensory-engine/src/plan-step-count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { PlanDag } from "./plan-export.js";

/**
* Return the total number of steps in the plan. Pure — reads the plan DAG only.
*/
export function countPlanSteps(plan: PlanDag): number {
return plan.steps.length;
}
44 changes: 44 additions & 0 deletions test/unit/plan-step-count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";

import { countPlanSteps } from "../../packages/gittensory-engine/src/plan-step-count";
import type { PlanStep } from "../../packages/gittensory-engine/src/plan-export";

function step(over: Partial<PlanStep> & { id: string; title: string }): PlanStep {
return {
actionClass: undefined,
dependsOn: [],
status: "pending",
attempts: 0,
maxAttempts: 3,
lastError: null,
...over,
};
}

describe("countPlanSteps", () => {
it("returns zero for an empty plan", () => {
expect(countPlanSteps({ steps: [] })).toBe(0);
});

it("returns the total number of steps regardless of status", () => {
expect(
countPlanSteps({
steps: [
step({ id: "a", title: "Build", status: "completed" }),
step({ id: "b", title: "Test", status: "pending" }),
step({ id: "c", title: "Deploy", status: "failed" }),
],
}),
).toBe(3);
});

it("is exported from the package barrel", async () => {
const barrel = await import("../../packages/gittensory-engine/src/index");
expect(typeof barrel.countPlanSteps).toBe("function");
expect(
barrel.countPlanSteps({
steps: [step({ id: "a", title: "A" }), step({ id: "b", title: "B" })],
}),
).toBe(2);
});
});
Loading