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 @@ -119,6 +119,7 @@ export {
type NormalizedGovernorLedgerEvent,
} from "./governor-ledger.js";
export * from "./plan-export.js";
export { countPlanStepsByStatus } from "./plan-step-stats.js";
export * from "./plan-templates.js";
export * from "./portfolio/queue.js";
export {
Expand Down
8 changes: 8 additions & 0 deletions packages/gittensory-engine/src/plan-step-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { PlanDag, PlanStepStatus } from "./plan-export.js";

/**
* Count plan steps matching a given status. Pure — reads the plan DAG only.
*/
export function countPlanStepsByStatus(plan: PlanDag, status: PlanStepStatus): number {
return plan.steps.filter((step) => step.status === status).length;
}
48 changes: 48 additions & 0 deletions test/unit/plan-step-stats.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";

import { countPlanStepsByStatus } from "../../packages/gittensory-engine/src/plan-step-stats";
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("countPlanStepsByStatus", () => {
it("returns zero for an empty plan", () => {
expect(countPlanStepsByStatus({ steps: [] }, "pending")).toBe(0);
});

it("counts only steps that match the requested status", () => {
const plan = {
steps: [
step({ id: "a", title: "Build", status: "completed" }),
step({ id: "b", title: "Test", status: "pending" }),
step({ id: "c", title: "Deploy", status: "pending" }),
step({ id: "d", title: "Verify", status: "failed" }),
],
};
expect(countPlanStepsByStatus(plan, "pending")).toBe(2);
expect(countPlanStepsByStatus(plan, "completed")).toBe(1);
expect(countPlanStepsByStatus(plan, "failed")).toBe(1);
expect(countPlanStepsByStatus(plan, "running")).toBe(0);
});

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