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 @@ -138,6 +138,7 @@ export {
export * from "./plan-export.js";
export { countPlanStepsByStatus } from "./plan-step-stats.js";
export { countPlanSteps } from "./plan-step-count.js";
export { isPlanEmpty } from "./plan-empty.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-empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { PlanDag } from "./plan-export.js";

/**
* Return whether the plan has no steps. Pure — reads the plan DAG only.
*/
export function isPlanEmpty(plan: PlanDag): boolean {
return plan.steps.length === 0;
}
41 changes: 41 additions & 0 deletions test/unit/plan-empty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";

import { isPlanEmpty } from "../../packages/gittensory-engine/src/plan-empty";
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("isPlanEmpty", () => {
it("returns true when the plan has no steps", () => {
expect(isPlanEmpty({ steps: [] })).toBe(true);
});

it("returns false when the plan has at least one step", () => {
expect(isPlanEmpty({ steps: [step({ id: "a", title: "Build" })] })).toBe(false);
expect(
isPlanEmpty({
steps: [
step({ id: "a", title: "Build", status: "completed" }),
step({ id: "b", title: "Test", status: "pending" }),
],
}),
).toBe(false);
});

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