fix: repair pre-existing engine test failures from missing pi-ai mock

Add @mariozechner/pi-ai mock to restart.integration.test.ts and
project-runtime.test.ts to fix module linking errors. Fix call count
assertions in executor and restart tests to account for the
retry-without-task_done behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-04 13:59:08 -07:00
parent eef87a2aea
commit 0c00194d79
3 changed files with 40 additions and 13 deletions

View File

@@ -38,6 +38,18 @@ vi.mock("node:fs", () => ({
vi.mock("node:fs/promises", () => ({
readFile: vi.fn().mockResolvedValue("# Task prompt content"),
}));
vi.mock("@mariozechner/pi-ai", () => ({
Type: {
Object: (props: Record<string, unknown>) => ({ type: "object", properties: props }),
String: (opts?: unknown) => ({ type: "string", ...((opts as object) ?? {}) }),
Number: (opts?: unknown) => ({ type: "number", ...((opts as object) ?? {}) }),
Boolean: (opts?: unknown) => ({ type: "boolean", ...((opts as object) ?? {}) }),
Optional: (schema: unknown) => schema,
Array: (schema: unknown, opts?: unknown) => ({ type: "array", items: schema, ...((opts as object) ?? {}) }),
Union: (schemas: unknown[], opts?: unknown) => ({ anyOf: schemas, ...((opts as object) ?? {}) }),
Literal: (value: unknown) => ({ const: value }),
},
}));
vi.mock("@mariozechner/pi-coding-agent", () => {
const mockSessionManager = {};
return {
@@ -182,8 +194,8 @@ describe("In-progress task resume after restart", () => {
// Wait for async execute calls to complete
await new Promise((r) => setTimeout(r, 50));
// createKbAgent should have been called once per in-progress task
expect(mockedCreateHaiAgent).toHaveBeenCalledTimes(2);
// createKbAgent called twice per task (initial + retry when agent finishes without task_done)
expect(mockedCreateHaiAgent).toHaveBeenCalledTimes(4);
});
it("resumed task reuses existing worktree — no git worktree add called", async () => {
@@ -633,8 +645,8 @@ describe("Crash scenario edge cases", () => {
await executor.resumeOrphaned();
await new Promise((r) => setTimeout(r, 50));
// Agent should have been created again for the re-resume
expect(mockedCreateHaiAgent).toHaveBeenCalledTimes(1);
// Agent should have been created again for the re-resume (twice: initial + retry without task_done)
expect(mockedCreateHaiAgent).toHaveBeenCalledTimes(2);
});
it("engine killed during merge — git reset --merge cleanup, task stays in-review", async () => {