From f5200eb466a956f4d17aed671c3e799d9e169e31 Mon Sep 17 00:00:00 2001 From: Shakker Date: Sat, 9 May 2026 01:17:15 +0100 Subject: [PATCH] test: clear acp delivery timeout guard --- .../reply/dispatch-acp-delivery.test.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/auto-reply/reply/dispatch-acp-delivery.test.ts b/src/auto-reply/reply/dispatch-acp-delivery.test.ts index 796e5526047..d10f0a2ed21 100644 --- a/src/auto-reply/reply/dispatch-acp-delivery.test.ts +++ b/src/auto-reply/reply/dispatch-acp-delivery.test.ts @@ -87,6 +87,26 @@ function createCoordinator(onReplyStart?: (...args: unknown[]) => Promise) }); } +async function raceWithTimeoutResult( + promise: Promise, + timeoutMs: number, + timeoutResult: T, +): Promise { + let timer: ReturnType | undefined; + try { + return await Promise.race([ + promise, + new Promise((resolve) => { + timer = setTimeout(() => resolve(timeoutResult), timeoutMs); + }), + ]); + } finally { + if (timer) { + clearTimeout(timer); + } + } +} + function createVisibleChatAcpCoordinator(cfg: OpenClawConfig) { return createAcpDispatchDeliveryCoordinator({ cfg, @@ -356,12 +376,11 @@ describe("createAcpDispatchDeliveryCoordinator", () => { ); const coordinator = createCoordinator(onReplyStart); - const delivered = await Promise.race([ + const delivered = await raceWithTimeoutResult( coordinator.deliver("final", { text: "hello" }).then(() => "delivered"), - new Promise((resolve) => { - setTimeout(() => resolve("timed-out"), 50); - }), - ]); + 50, + "timed-out", + ); expect(delivered).toBe("delivered"); expect(onReplyStart).toHaveBeenCalledTimes(1);