test: expand subagent announce completion coverage

This commit is contained in:
Peter Steinberger
2026-02-18 03:21:52 +01:00
parent edf7d6af61
commit ae3637b23b
2 changed files with 194 additions and 0 deletions

View File

@@ -239,4 +239,67 @@ describe("subagent registry steer restarts", () => {
expect(childRunIds.filter((id) => id === "run-parent")).toHaveLength(2);
expect(childRunIds.filter((id) => id === "run-child")).toHaveLength(1);
});
it("retries completion-mode announce delivery with backoff and then gives up after retry limit", async () => {
const callGateway = vi.mocked((await import("../gateway/call.js")).callGateway);
const originalCallGateway = callGateway.getMockImplementation();
callGateway.mockImplementation(async (request: unknown) => {
const typed = request as { method?: string };
if (typed.method === "agent.wait") {
return new Promise<unknown>(() => undefined);
}
if (originalCallGateway) {
return originalCallGateway(request as Parameters<typeof callGateway>[0]);
}
return {};
});
vi.useFakeTimers();
try {
announceSpy.mockResolvedValue(false);
mod.registerSubagentRun({
runId: "run-completion-retry",
childSessionKey: "agent:main:subagent:completion",
requesterSessionKey: "agent:main:main",
requesterDisplayKey: "main",
task: "completion retry",
cleanup: "keep",
expectsCompletionMessage: true,
});
lifecycleHandler?.({
stream: "lifecycle",
runId: "run-completion-retry",
data: { phase: "end" },
});
await vi.advanceTimersByTimeAsync(0);
expect(announceSpy).toHaveBeenCalledTimes(1);
expect(mod.listSubagentRunsForRequester("agent:main:main")[0]?.announceRetryCount).toBe(1);
await vi.advanceTimersByTimeAsync(999);
expect(announceSpy).toHaveBeenCalledTimes(1);
await vi.advanceTimersByTimeAsync(1);
expect(announceSpy).toHaveBeenCalledTimes(2);
expect(mod.listSubagentRunsForRequester("agent:main:main")[0]?.announceRetryCount).toBe(2);
await vi.advanceTimersByTimeAsync(1_999);
expect(announceSpy).toHaveBeenCalledTimes(2);
await vi.advanceTimersByTimeAsync(1);
expect(announceSpy).toHaveBeenCalledTimes(3);
expect(mod.listSubagentRunsForRequester("agent:main:main")[0]?.announceRetryCount).toBe(3);
await vi.advanceTimersByTimeAsync(10_000);
expect(announceSpy).toHaveBeenCalledTimes(3);
expect(mod.listSubagentRunsForRequester("agent:main:main")[0]?.cleanupCompletedAt).toBeTypeOf(
"number",
);
} finally {
if (originalCallGateway) {
callGateway.mockImplementation(originalCallGateway);
}
vi.useRealTimers();
}
});
});