feat(FN-1982): merge fusion/fn-1982
This commit is contained in:
@@ -173,9 +173,17 @@ function createMockMissionStore() {
|
||||
}),
|
||||
listAssertionsForFeature: vi.fn(() => []),
|
||||
getAssertionsForFeature: vi.fn(() => []),
|
||||
getSlice: vi.fn((id: string) => {
|
||||
// Return a mock slice with milestoneId for the hierarchy
|
||||
return createMockSlice({ id });
|
||||
}),
|
||||
getMilestone: vi.fn((id: string) => {
|
||||
// Return a mock milestone with missionId for the hierarchy
|
||||
return createMockMilestone({ id });
|
||||
}),
|
||||
|
||||
// Validator run methods
|
||||
startValidatorRun: vi.fn((featureId: string, _triggerType?: string) => {
|
||||
startValidatorRun: vi.fn((featureId: string, _triggerType?: string, _taskId?: string) => {
|
||||
const run = createMockValidatorRun({ featureId });
|
||||
validatorRuns.set(run.id, run);
|
||||
return run;
|
||||
@@ -249,12 +257,18 @@ function createMockMissionStore() {
|
||||
}
|
||||
|
||||
function createMockTaskStore() {
|
||||
const tasks = new Map<string, { id: string; title?: string; description?: string; log?: Array<{ action?: string }> }>();
|
||||
const tasks = new Map<string, { id: string; title?: string; description?: string; log?: Array<{ action?: string }>; column?: string; missionId?: string; sliceId?: string; status?: string }>();
|
||||
|
||||
const store = {
|
||||
getTask: vi.fn(async (id: string) => tasks.get(id)),
|
||||
moveTask: vi.fn(),
|
||||
updateTask: vi.fn(),
|
||||
createTask: vi.fn(async (input: { title?: string; description?: string; column?: string; missionId?: string; sliceId?: string }) => {
|
||||
const id = `KB-${tasks.size + 1}`;
|
||||
const task = { id, ...input };
|
||||
tasks.set(id, task);
|
||||
return task;
|
||||
}),
|
||||
moveTask: vi.fn(async () => {}),
|
||||
updateTask: vi.fn(async () => {}),
|
||||
getSettings: vi.fn().mockResolvedValue({
|
||||
missionStaleThresholdMs: 600_000,
|
||||
missionMaxTaskRetries: 3,
|
||||
@@ -262,7 +276,7 @@ function createMockTaskStore() {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
|
||||
_setTask: (t: { id: string; title?: string; description?: string; log?: Array<{ action?: string }> }) => tasks.set(t.id, t),
|
||||
_setTask: (t: { id: string; title?: string; description?: string; log?: Array<{ action?: string }>; column?: string; missionId?: string; sliceId?: string; status?: string }) => tasks.set(t.id, t),
|
||||
_clear: () => tasks.clear(),
|
||||
};
|
||||
|
||||
@@ -449,6 +463,87 @@ describe("MissionExecutionLoop", () => {
|
||||
expect.objectContaining({ featureId: "F-001" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("creates validation board task when feature has assertions", async () => {
|
||||
const feature = createMockFeature({ loopState: "implementing", taskId: "FN-001", sliceId: "SL-001" });
|
||||
missionStore._setFeature(feature);
|
||||
taskStore._setTask({ id: "FN-001", title: "Test", description: "Test task", log: [] });
|
||||
missionStore.getFeatureByTaskId = vi.fn().mockReturnValue(feature);
|
||||
missionStore.listAssertionsForFeature = vi.fn().mockReturnValue([
|
||||
{ id: "CA-1", milestoneId: "MS-001", title: "Test assertion", assertion: "Should work", status: "pending" as const, orderIndex: 0, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() },
|
||||
]);
|
||||
|
||||
loop = new MissionExecutionLoop({
|
||||
taskStore: taskStore as any,
|
||||
missionStore: missionStore as any,
|
||||
rootDir: "/tmp",
|
||||
});
|
||||
loop.start();
|
||||
|
||||
await loop.processTaskOutcome("FN-001");
|
||||
|
||||
// Should create a validation board task
|
||||
expect(taskStore.createTask).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
title: expect.stringContaining("Validate:"),
|
||||
column: "in-progress",
|
||||
sliceId: "SL-001",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("sets validation task status to mission-validation", async () => {
|
||||
const feature = createMockFeature({ loopState: "implementing", taskId: "FN-001", sliceId: "SL-001" });
|
||||
missionStore._setFeature(feature);
|
||||
taskStore._setTask({ id: "FN-001", title: "Test", description: "Test task", log: [] });
|
||||
missionStore.getFeatureByTaskId = vi.fn().mockReturnValue(feature);
|
||||
missionStore.listAssertionsForFeature = vi.fn().mockReturnValue([
|
||||
{ id: "CA-1", milestoneId: "MS-001", title: "Test assertion", assertion: "Should work", status: "pending" as const, orderIndex: 0, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() },
|
||||
]);
|
||||
|
||||
loop = new MissionExecutionLoop({
|
||||
taskStore: taskStore as any,
|
||||
missionStore: missionStore as any,
|
||||
rootDir: "/tmp",
|
||||
});
|
||||
loop.start();
|
||||
|
||||
await loop.processTaskOutcome("FN-001");
|
||||
|
||||
// Should update the task status to mission-validation
|
||||
expect(taskStore.updateTask).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.objectContaining({ status: "mission-validation" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("passes taskId to startValidatorRun", async () => {
|
||||
const feature = createMockFeature({ loopState: "implementing", taskId: "FN-001", sliceId: "SL-001" });
|
||||
missionStore._setFeature(feature);
|
||||
taskStore._setTask({ id: "FN-001", title: "Test", description: "Test task", log: [] });
|
||||
missionStore.getFeatureByTaskId = vi.fn().mockReturnValue(feature);
|
||||
missionStore.listAssertionsForFeature = vi.fn().mockReturnValue([
|
||||
{ id: "CA-1", milestoneId: "MS-001", title: "Test assertion", assertion: "Should work", status: "pending" as const, orderIndex: 0, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() },
|
||||
]);
|
||||
// Make createTask return a predictable ID
|
||||
taskStore.createTask = vi.fn().mockResolvedValue({ id: "KB-999" });
|
||||
|
||||
loop = new MissionExecutionLoop({
|
||||
taskStore: taskStore as any,
|
||||
missionStore: missionStore as any,
|
||||
rootDir: "/tmp",
|
||||
});
|
||||
loop.start();
|
||||
|
||||
await loop.processTaskOutcome("FN-001");
|
||||
|
||||
// Should pass the created task ID to startValidatorRun
|
||||
expect(missionStore.startValidatorRun).toHaveBeenCalledWith(
|
||||
"F-001",
|
||||
"task_completion",
|
||||
"KB-999",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ── recoverActiveMissions ────────────────────────────────────────────────
|
||||
|
||||
@@ -211,6 +211,9 @@ export class MissionExecutionLoop extends EventEmitter {
|
||||
|
||||
loopLog.log(`Processing task outcome for ${taskId}`);
|
||||
|
||||
// Track the validation board task ID (created later if there are assertions)
|
||||
let validationTaskId: string | undefined;
|
||||
|
||||
try {
|
||||
// Find the feature linked to this task
|
||||
const feature = this.missionStore.getFeatureByTaskId(taskId);
|
||||
@@ -230,7 +233,7 @@ export class MissionExecutionLoop extends EventEmitter {
|
||||
if (assertions.length === 0) {
|
||||
loopLog.log(`Feature ${feature.id} has no linked assertions; marking as passed`);
|
||||
// No assertions = automatically pass
|
||||
await this.handleValidationPass(feature.id, undefined, "No assertions linked");
|
||||
await this.handleValidationPass(feature.id, undefined, "No assertions linked", undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -238,8 +241,27 @@ export class MissionExecutionLoop extends EventEmitter {
|
||||
this.activeValidations.add(feature.id);
|
||||
|
||||
try {
|
||||
// Start a validator run
|
||||
const run = this.missionStore.startValidatorRun(feature.id, "task_completion");
|
||||
// Resolve mission context for creating the validation board task
|
||||
const featureSlice = this.missionStore.getSlice(feature.sliceId);
|
||||
const featureMilestone = featureSlice ? this.missionStore.getMilestone(featureSlice.milestoneId) : undefined;
|
||||
const missionId = featureMilestone?.missionId;
|
||||
|
||||
// Create a visible board task for this validation run
|
||||
const validationTask = await this.taskStore.createTask({
|
||||
title: `🔍 Validate: ${feature.title}`,
|
||||
description: `Validating implementation for feature "${feature.title}" against ${assertions.length} contract assertion(s).\n\nFeature: ${feature.id}\nSlice: ${feature.sliceId}\nAssertions: ${assertions.map(a => a.title).join(", ")}`,
|
||||
column: "in-progress",
|
||||
missionId,
|
||||
sliceId: feature.sliceId,
|
||||
});
|
||||
validationTaskId = validationTask.id;
|
||||
|
||||
// Mark as validation task so scheduler/stuck-detector skip it
|
||||
await this.taskStore.updateTask(validationTaskId, { status: "mission-validation" });
|
||||
loopLog.log(`Created validation board task ${validationTaskId} for feature ${feature.id}`);
|
||||
|
||||
// Start the validator run, linked to the board task
|
||||
const run = this.missionStore.startValidatorRun(feature.id, "task_completion", validationTaskId);
|
||||
loopLog.log(`Started validator run ${run.id} for feature ${feature.id}`);
|
||||
|
||||
// Run the validation
|
||||
@@ -247,17 +269,31 @@ export class MissionExecutionLoop extends EventEmitter {
|
||||
|
||||
// Handle the result
|
||||
if (result.status === "pass") {
|
||||
await this.handleValidationPass(feature.id, run.id, result.summary);
|
||||
await this.handleValidationPass(feature.id, run.id, result.summary, validationTaskId);
|
||||
} else if (result.status === "fail") {
|
||||
await this.handleValidationFail(feature.id, run.id, result);
|
||||
await this.handleValidationFail(feature.id, run.id, result, validationTaskId);
|
||||
} else if (result.status === "blocked") {
|
||||
await this.handleValidationBlocked(feature.id, run.id, result.blockedReason);
|
||||
await this.handleValidationBlocked(feature.id, run.id, result.blockedReason, validationTaskId);
|
||||
} else if (result.status === "error") {
|
||||
await this.handleValidationError(feature.id, run.id, result.summary, validationTaskId);
|
||||
}
|
||||
} finally {
|
||||
this.activeValidations.delete(feature.id);
|
||||
}
|
||||
} catch (err) {
|
||||
loopLog.error(`Error processing task outcome for ${taskId}:`, err);
|
||||
// Move the validation task to in-review if it exists
|
||||
if (validationTaskId) {
|
||||
try {
|
||||
await this.taskStore.updateTask(validationTaskId, {
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
summary: "Validation failed unexpectedly",
|
||||
});
|
||||
await this.taskStore.moveTask(validationTaskId, "in-review");
|
||||
} catch (moveErr) {
|
||||
loopLog.error(`Failed to move validation task ${validationTaskId} on error:`, moveErr);
|
||||
}
|
||||
}
|
||||
// Don't crash the loop - log and continue
|
||||
}
|
||||
}
|
||||
@@ -698,6 +734,7 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
featureId: string,
|
||||
runId: string | undefined,
|
||||
summary: string,
|
||||
validationTaskId: string | undefined,
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (runId) {
|
||||
@@ -705,6 +742,15 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
}
|
||||
loopLog.log(`Feature ${featureId} passed validation`);
|
||||
|
||||
// Move the validation board task to done if it exists
|
||||
if (validationTaskId) {
|
||||
await this.taskStore.updateTask(validationTaskId, {
|
||||
summary: summary || "Validation passed",
|
||||
});
|
||||
await this.taskStore.moveTask(validationTaskId, "done");
|
||||
loopLog.log(`Moved validation task ${validationTaskId} to done`);
|
||||
}
|
||||
|
||||
// Notify autopilot if configured
|
||||
if (this.missionAutopilot?.notifyValidationComplete) {
|
||||
await this.missionAutopilot.notifyValidationComplete(featureId, "passed");
|
||||
@@ -723,6 +769,7 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
featureId: string,
|
||||
runId: string | undefined,
|
||||
result: ValidationResult,
|
||||
validationTaskId: string | undefined,
|
||||
): Promise<void> {
|
||||
try {
|
||||
// Record the failures
|
||||
@@ -746,6 +793,16 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
|
||||
loopLog.log(`Feature ${featureId} failed validation with ${failures.length} failures`);
|
||||
|
||||
// Move the validation board task to in-review if it exists
|
||||
if (validationTaskId) {
|
||||
await this.taskStore.updateTask(validationTaskId, {
|
||||
error: result.summary,
|
||||
summary: `Failed: ${failures.length} assertion(s) failed`,
|
||||
});
|
||||
await this.taskStore.moveTask(validationTaskId, "in-review");
|
||||
loopLog.log(`Moved validation task ${validationTaskId} to in-review`);
|
||||
}
|
||||
|
||||
// Create fix feature
|
||||
try {
|
||||
const fixFeature = this.missionStore.createGeneratedFixFeature(
|
||||
@@ -798,6 +855,7 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
featureId: string,
|
||||
runId: string | undefined,
|
||||
blockedReason: string | undefined,
|
||||
validationTaskId: string | undefined,
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (runId) {
|
||||
@@ -805,6 +863,16 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
}
|
||||
loopLog.log(`Feature ${featureId} blocked: ${blockedReason}`);
|
||||
|
||||
// Move the validation board task to in-review if it exists
|
||||
if (validationTaskId) {
|
||||
await this.taskStore.updateTask(validationTaskId, {
|
||||
error: blockedReason,
|
||||
summary: `Blocked: ${blockedReason}`,
|
||||
});
|
||||
await this.taskStore.moveTask(validationTaskId, "in-review");
|
||||
loopLog.log(`Moved validation task ${validationTaskId} to in-review`);
|
||||
}
|
||||
|
||||
// Notify autopilot if configured
|
||||
if (this.missionAutopilot?.notifyValidationComplete) {
|
||||
await this.missionAutopilot.notifyValidationComplete(featureId, "blocked");
|
||||
@@ -823,6 +891,7 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
featureId: string,
|
||||
runId: string | undefined,
|
||||
error: string,
|
||||
validationTaskId: string | undefined,
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (runId) {
|
||||
@@ -830,6 +899,16 @@ ${taskContext ? `\n\nImplementation context:\n${taskContext}` : ""}`;
|
||||
}
|
||||
loopLog.error(`Feature ${featureId} validation error: ${error}`);
|
||||
|
||||
// Move the validation board task to in-review if it exists
|
||||
if (validationTaskId) {
|
||||
await this.taskStore.updateTask(validationTaskId, {
|
||||
error,
|
||||
summary: "Validation error",
|
||||
});
|
||||
await this.taskStore.moveTask(validationTaskId, "in-review");
|
||||
loopLog.log(`Moved validation task ${validationTaskId} to in-review`);
|
||||
}
|
||||
|
||||
// Notify autopilot if configured
|
||||
if (this.missionAutopilot?.notifyValidationComplete) {
|
||||
await this.missionAutopilot.notifyValidationComplete(featureId, "error");
|
||||
|
||||
Reference in New Issue
Block a user