feat(FN-4770): complete Step 1 — expose createTask hook toggle

Fusion-Task-Id: FN-4770
Fusion-Task-Lineage: 8c8d1786-f81b-4544-9275-595b90ea5689
This commit is contained in:
Fusion (runfusion.ai)
2026-05-16 11:21:56 -07:00
committed by gsxdsm
parent b594160e77
commit 7c1ccb4b31
2 changed files with 22 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import * as projectMemory from "../project-memory.js";
import { AgentStore } from "../agent-store.js";
import { CentralDatabase } from "../central-db.js";
import { TaskStore, TaskHasDependentsError } from "../store.js";
import { setTaskCreatedHook } from "../task-creation-hooks.js";
import { buildResearchDocumentKey, type Task } from "../types.js";
import { createTaskStoreTestHarness, makeTmpDir } from "./store-test-helpers.js";
@@ -24,6 +25,7 @@ describe("TaskStore", () => {
});
afterEach(async () => {
setTaskCreatedHook(undefined);
await harness.afterEach();
});
@@ -100,6 +102,22 @@ describe("TaskStore", () => {
describe("createTask task-created hook invocation", () => {
it("skips hook when invokeTaskCreatedHook is false and defaults to invoking", async () => {
const hookSpy = vi.fn();
setTaskCreatedHook(hookSpy);
await store.createTask(
{ description: "Hook should be skipped" },
{ invokeTaskCreatedHook: false },
);
expect(hookSpy).not.toHaveBeenCalled();
await store.createTask({ description: "Hook should run" });
expect(hookSpy).toHaveBeenCalledTimes(1);
});
});
describe("createTask — model overrides", () => {
it("persists executor and validator model overrides on creation", async () => {
const created = await store.createTask({

View File

@@ -2811,6 +2811,7 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
options?: {
onSummarize?: (description: string) => Promise<string | null>;
settings?: { autoSummarizeTitles?: boolean };
invokeTaskCreatedHook?: boolean;
}
): Promise<Task> {
if (!input.description?.trim()) {
@@ -2824,6 +2825,7 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
input.description.length > 200 &&
(input.summarize === true || options?.settings?.autoSummarizeTitles === true);
const hasPendingSummarization = shouldSummarize && typeof options?.onSummarize === "function";
const shouldInvokeTaskCreatedHook = options?.invokeTaskCreatedHook !== false;
// Determine enabledWorkflowSteps: explicit input takes precedence, otherwise auto-apply default-on steps
let resolvedWorkflowSteps: string[] | undefined = input.enabledWorkflowSteps?.length
@@ -2861,12 +2863,12 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
title,
resolvedWorkflowSteps,
taskId,
{ invokeTaskCreatedHook: !hasPendingSummarization },
{ invokeTaskCreatedHook: shouldInvokeTaskCreatedHook && !hasPendingSummarization },
);
},
});
if (hasPendingSummarization) {
if (hasPendingSummarization && shouldInvokeTaskCreatedHook) {
const id = task.id;
Promise.resolve().then(async () => {
try {