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 @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions packages/gittensory-engine/src/plan-running.ts
Original file line number Diff line number Diff line change
@@ -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");
}
54 changes: 54 additions & 0 deletions test/unit/plan-running.test.ts
Original file line number Diff line number Diff line change
@@ -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<PlanStep> & { 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);
});
});
Loading