test: clear acp delivery timeout guard

This commit is contained in:
Shakker
2026-05-09 01:17:15 +01:00
parent 2f415618b3
commit f5200eb466

View File

@@ -87,6 +87,26 @@ function createCoordinator(onReplyStart?: (...args: unknown[]) => Promise<void>)
});
}
async function raceWithTimeoutResult<T>(
promise: Promise<T>,
timeoutMs: number,
timeoutResult: T,
): Promise<T> {
let timer: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
promise,
new Promise<T>((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<string>((resolve) => {
setTimeout(() => resolve("timed-out"), 50);
}),
]);
50,
"timed-out",
);
expect(delivered).toBe("delivered");
expect(onReplyStart).toHaveBeenCalledTimes(1);