fix: recover completed tasks stuck in progress

This commit is contained in:
gsxdsm
2026-04-05 15:24:32 -07:00
parent b051ffcc84
commit eb6fbbb42c
10 changed files with 500 additions and 36 deletions

View File

@@ -4,6 +4,16 @@ import type { Task, TaskStore, CentralCore } from "@fusion/core";
import { InProcessRuntime } from "./in-process-runtime.js";
import type { ProjectRuntimeConfig } from "../project-runtime.js";
const {
mockSelfHealingStart,
mockSelfHealingStop,
mockSelfHealingCtor,
} = vi.hoisted(() => ({
mockSelfHealingStart: vi.fn(),
mockSelfHealingStop: vi.fn(),
mockSelfHealingCtor: vi.fn(),
}));
// Mock the TaskStore class
vi.mock("@fusion/core", async () => {
const actual = await vi.importActual<typeof import("@fusion/core")>("@fusion/core");
@@ -54,6 +64,18 @@ vi.mock("../scheduler.js", async () => {
};
});
vi.mock("../self-healing.js", async () => {
return {
SelfHealingManager: vi.fn().mockImplementation((_store, opts) => {
mockSelfHealingCtor(opts);
return {
start: mockSelfHealingStart,
stop: mockSelfHealingStop,
};
}),
};
});
// Mock the executor
vi.mock("../executor.js", async () => {
return {
@@ -111,6 +133,19 @@ describe("InProcessRuntime", () => {
expect(runtime.getStatus()).toBe("active");
});
it("passes executor recovery callbacks into SelfHealingManager", async () => {
await runtime.start();
expect(mockSelfHealingCtor).toHaveBeenCalledWith(
expect.objectContaining({
rootDir: "/tmp/test-project",
recoverCompletedTask: expect.any(Function),
getExecutingTaskIds: expect.any(Function),
}),
);
expect(mockSelfHealingStart).toHaveBeenCalled();
});
it("should transition to 'stopped' after stop", async () => {
await runtime.start();
await runtime.stop();

View File

@@ -230,6 +230,8 @@ export class InProcessRuntime
// 7. Initialize SelfHealingManager
this.selfHealingManager = new SelfHealingManager(this.taskStore, {
rootDir: this.config.workingDirectory,
recoverCompletedTask: (task) => this.executor.recoverCompletedTask(task),
getExecutingTaskIds: () => this.executor.getExecutingTaskIds(),
});
this.selfHealingManager.start();