perf(test): speed up subagent persistence e2e flushes

This commit is contained in:
Peter Steinberger
2026-02-18 18:06:56 +00:00
parent fae5ba637c
commit b7c75f3918

View File

@@ -24,7 +24,9 @@ vi.mock("../infra/agent-events.js", () => ({
onAgentEvent: vi.fn(() => noop), onAgentEvent: vi.fn(() => noop),
})); }));
const announceSpy = vi.fn(async () => true); const { announceSpy } = vi.hoisted(() => ({
announceSpy: vi.fn(async () => true),
}));
vi.mock("./subagent-announce.js", () => ({ vi.mock("./subagent-announce.js", () => ({
runSubagentAnnounceFlow: announceSpy, runSubagentAnnounceFlow: announceSpy,
})); }));
@@ -47,7 +49,9 @@ describe("subagent registry persistence", () => {
childSessionKey: string; childSessionKey: string;
task: string; task: string;
cleanup: "keep" | "delete"; cleanup: "keep" | "delete";
}) => ({ }) => {
const now = Date.now();
return {
version: 2, version: 2,
runs: { runs: {
[params.runId]: { [params.runId]: {
@@ -57,17 +61,23 @@ describe("subagent registry persistence", () => {
requesterDisplayKey: "main", requesterDisplayKey: "main",
task: params.task, task: params.task,
cleanup: params.cleanup, cleanup: params.cleanup,
createdAt: 1, createdAt: now - 2,
startedAt: 1, startedAt: now - 1,
endedAt: 2, endedAt: now,
}, },
}, },
}); };
};
const flushQueuedRegistryWork = async () => {
await Promise.resolve();
await Promise.resolve();
};
const restartRegistryAndFlush = async () => { const restartRegistryAndFlush = async () => {
resetSubagentRegistryForTests({ persist: false }); resetSubagentRegistryForTests({ persist: false });
initSubagentRegistry(); initSubagentRegistry();
await new Promise((r) => setTimeout(r, 0)); await flushQueuedRegistryWork();
}; };
afterEach(async () => { afterEach(async () => {
@@ -117,7 +127,7 @@ describe("subagent registry persistence", () => {
initSubagentRegistry(); initSubagentRegistry();
// allow queued async wait/cleanup to execute // allow queued async wait/cleanup to execute
await new Promise((r) => setTimeout(r, 0)); await flushQueuedRegistryWork();
expect(announceSpy).toHaveBeenCalled(); expect(announceSpy).toHaveBeenCalled();
@@ -169,7 +179,7 @@ describe("subagent registry persistence", () => {
resetSubagentRegistryForTests({ persist: false }); resetSubagentRegistryForTests({ persist: false });
initSubagentRegistry(); initSubagentRegistry();
await new Promise((r) => setTimeout(r, 0)); await flushQueuedRegistryWork();
// announce should NOT be called since cleanupHandled was true // announce should NOT be called since cleanupHandled was true
const calls = (announceSpy.mock.calls as unknown as Array<[unknown]>).map((call) => call[0]); const calls = (announceSpy.mock.calls as unknown as Array<[unknown]>).map((call) => call[0]);