test(agents): stabilize steer restart ordering

This commit is contained in:
Vincent Koc
2026-04-13 01:25:39 +01:00
parent de1b6abf94
commit 4c8337f27b

View File

@@ -19,7 +19,7 @@ vi.mock("../gateway/call.js", () => ({
callGateway: vi.fn(async (opts: unknown) => {
const request = opts as { method?: string };
if (request.method === "agent.wait") {
return { status: "timeout" };
return { status: "pending" };
}
return {};
}),
@@ -107,6 +107,11 @@ describe("subagent registry steer restarts", () => {
beforeEach(() => {
lifecycleHandler = undefined;
announceSpy.mockReset();
announceSpy.mockResolvedValue(true);
runSubagentEndedHookMock.mockReset();
runSubagentEndedHookMock.mockImplementation(async () => {});
emitSessionLifecycleEventMock.mockReset();
mod.resetSubagentRegistryForTests({ persist: false });
});
@@ -234,10 +239,11 @@ describe("subagent registry steer restarts", () => {
};
afterEach(async () => {
announceSpy.mockClear();
announceSpy.mockReset();
announceSpy.mockResolvedValue(true);
runSubagentEndedHookMock.mockClear();
emitSessionLifecycleEventMock.mockClear();
runSubagentEndedHookMock.mockReset();
runSubagentEndedHookMock.mockImplementation(async () => {});
emitSessionLifecycleEventMock.mockReset();
lifecycleHandler = undefined;
mod.resetSubagentRegistryForTests({ persist: false });
});
@@ -275,7 +281,11 @@ describe("subagent registry steer restarts", () => {
expect(announceSpy).toHaveBeenCalledTimes(1);
});
await vi.waitFor(() => {
expect(runSubagentEndedHookMock).toHaveBeenCalledTimes(1);
const matchingCalls = runSubagentEndedHookMock.mock.calls.filter((call) => {
const ctx = call[1] as { runId?: string } | undefined;
return ctx?.runId === "run-new";
});
expect(matchingCalls).toHaveLength(1);
});
expect(runSubagentEndedHookMock).toHaveBeenCalledWith(
expect.objectContaining({
@@ -669,10 +679,21 @@ describe("subagent registry steer restarts", () => {
});
emitLifecycleEnd("run-parent");
await flushAnnounce();
await vi.waitFor(() => {
const childRunIds = announceSpy.mock.calls.map(
(call) => ((call[0] ?? {}) as { childRunId?: string }).childRunId,
);
expect(childRunIds.filter((id) => id === "run-parent")).toHaveLength(1);
});
emitLifecycleEnd("run-child");
await flushAnnounce();
await vi.waitFor(() => {
const childRunIds = announceSpy.mock.calls.map(
(call) => ((call[0] ?? {}) as { childRunId?: string }).childRunId,
);
expect(childRunIds.filter((id) => id === "run-parent")).toHaveLength(2);
expect(childRunIds.filter((id) => id === "run-child")).toHaveLength(1);
});
const childRunIds = announceSpy.mock.calls.map(
(call) => ((call[0] ?? {}) as { childRunId?: string }).childRunId,