test(KB-315): enhance cron-runner and worktree-pool test coverage

- Add error handling tests for cron-runner job execution
- Add stop idempotency and unknown step type tests to cron-runner
- Add startPoint parameter tests for worktree-pool
- Add worktree-pool error handling and edge case tests
This commit is contained in:
gsxdsm
2026-03-31 11:45:01 -07:00
parent ade5ac6523
commit 89bd17f06b
2 changed files with 102 additions and 1 deletions

View File

@@ -149,6 +149,16 @@ describe("WorktreePool", () => {
}
});
it("creates branch from custom startPoint when provided", () => {
pool.prepareForTask("/tmp/wt", "kb/kb-042", "kb/kb-041");
const checkoutCall = mockedExecSync.mock.calls.find(
(c) => typeof c[0] === "string" && (c[0] as string).includes("checkout -B"),
);
expect(checkoutCall).toBeDefined();
expect(checkoutCall![0]).toBe('git checkout -B "kb/kb-042" kb/kb-041');
});
it("tolerates git checkout -- . failure (already clean)", () => {
mockedExecSync.mockImplementation((cmd: any) => {
if (cmd === "git checkout -- .") throw new Error("nothing to checkout");
@@ -297,6 +307,16 @@ describe("scanIdleWorktrees", () => {
expect(idle).toContain("/root/.worktrees/wt-1");
expect(idle).toContain("/root/.worktrees/wt-2");
});
it("returns empty array when readdirSync throws", async () => {
mockedReaddirSync.mockImplementation(() => {
throw new Error("Permission denied");
});
const store = createMockStore([]);
const idle = await scanIdleWorktrees("/root", store);
expect(idle).toEqual([]);
});
});
// ── cleanupOrphanedWorktrees tests ────────────────────────────────────
@@ -377,4 +397,20 @@ describe("cleanupOrphanedWorktrees", () => {
expect(cleaned).toBe(0);
expect(mockedExecSync).not.toHaveBeenCalled();
});
it("returns 0 when all worktrees are assigned to active tasks", async () => {
mockedReaddirSync.mockReturnValue([
makeDirEntry("active-1"),
makeDirEntry("active-2"),
] as any);
const store = createMockStore([
makeTask("KB-001", "in-progress", "/root/.worktrees/active-1"),
makeTask("KB-002", "in-review", "/root/.worktrees/active-2"),
]);
const cleaned = await cleanupOrphanedWorktrees("/root", store);
expect(cleaned).toBe(0);
expect(mockedExecSync).not.toHaveBeenCalled();
});
});