























@@ -77,6 +77,28 @@ describe("announce loop guard (#18264)", () => {
7777return entry;
7878}
797980+async function flushAsync() {
81+await Promise.resolve();
82+await Promise.resolve();
83+}
84+85+async function waitForRun(
86+runId: string,
87+predicate: (run: SubagentRunRecord) => boolean,
88+): Promise<SubagentRunRecord> {
89+for (let attempt = 0; attempt < 40; attempt += 1) {
90+const run = registry
91+.listSubagentRunsForRequester("agent:main:main")
92+.find((candidate) => candidate.runId === runId);
93+if (run && predicate(run)) {
94+return run;
95+}
96+await vi.advanceTimersByTimeAsync(1);
97+await flushAsync();
98+}
99+throw new Error(`subagent run ${runId} did not reach expected state`);
100+}
101+80102beforeAll(async () => {
81103vi.resetModules();
82104registry = await import("./subagent-registry.js");
@@ -184,8 +206,7 @@ describe("announce loop guard (#18264)", () => {
184206// Initialization attempts resume once, then gives up for exhausted entries.
185207const beforeInit = Date.now();
186208registry.initSubagentRegistry();
187-await Promise.resolve();
188-await Promise.resolve();
209+await flushAsync();
189210190211expect(mocks.runSubagentAnnounceFlow).not.toHaveBeenCalled();
191212expect(entry.cleanupCompletedAt).toBeGreaterThanOrEqual(beforeInit);
@@ -220,8 +241,7 @@ describe("announce loop guard (#18264)", () => {
220241);
221242222243registry.initSubagentRegistry();
223-await Promise.resolve();
224-await Promise.resolve();
244+await flushAsync();
225245226246expect(mocks.runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
227247});
@@ -254,14 +274,13 @@ describe("announce loop guard (#18264)", () => {
254274);
255275256276registry.initSubagentRegistry();
257-await Promise.resolve();
258-await Promise.resolve();
277+await flushAsync();
259278260-const runs = registry.listSubagentRunsForRequester("agent:main:main");
261-const stored = runs.find((run) => run.runId === runId);
262-expect(stored?.cleanupHandled).toBe(false);
263-expect(stored?.cleanupCompletedAt).toBeUndefined();
264-expect(stored?.announceRetryCount).toBe(1);
265-expect(stored?.lastAnnounceRetryAt).toBeTypeOf("number");
279+const stored = await waitForRun(
280+ runId,
281+ (run) => run.cleanupHandled === false && run.announceRetryCount === 1,
282+);
283+expect(stored.cleanupCompletedAt).toBeUndefined();
284+expect(stored.lastAnnounceRetryAt).toBeTypeOf("number");
266285});
267286});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。