feat: add silentCompletion + onComplete to spawnBackgroundSubagentTask (#1217)

This commit is contained in:
Devansh Jain
2026-02-27 19:14:05 -08:00
committed by GitHub
parent ba6df7a9ed
commit 0c1f2182a0
2 changed files with 106 additions and 45 deletions

View File

@@ -142,6 +142,45 @@ describe("spawnBackgroundSubagentTask", () => {
expect(outputContent).toContain("[Task completed]");
});
test("silentCompletion skips message queue notification", async () => {
const spawnSubagentImpl = mock(async () => ({
agentId: "agent-silent",
conversationId: "default",
report: "init done",
success: true,
totalTokens: 30,
}));
const launched = spawnBackgroundSubagentTask({
subagentType: "init",
prompt: "Init memory",
description: "Initializing memory",
silentCompletion: true,
deps: {
spawnSubagentImpl,
addToMessageQueueImpl,
formatTaskNotificationImpl,
runSubagentStopHooksImpl,
generateSubagentIdImpl,
registerSubagentImpl,
completeSubagentImpl,
getSubagentSnapshotImpl,
},
});
await new Promise((resolve) => setTimeout(resolve, 0));
const task = backgroundTasks.get(launched.taskId);
expect(task?.status).toBe("completed");
expect(task?.output[0]).toContain("init done");
expect(completeSubagentImpl).toHaveBeenCalledTimes(1);
// No notification queued
expect(queueMessages.length).toBe(0);
expect(formatTaskNotificationImpl).not.toHaveBeenCalled();
// Hooks still run
expect(runSubagentStopHooksImpl).toHaveBeenCalledTimes(1);
});
test("marks background task failed and emits notification on error", async () => {
const spawnSubagentImpl = mock(async () => {
throw new Error("subagent exploded");