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:
committed by
gsxdsm
parent
b594160e77
commit
7c1ccb4b31
@@ -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({
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user