From 2f4cef20215a0118bce239a3a81512ea211de38d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 04:57:22 +0000 Subject: [PATCH] perf(test): remove last-route polling in partial reply gating --- .../auto-reply.partial-reply-gating.test.ts | 40 ++++--------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/src/web/auto-reply.partial-reply-gating.test.ts b/src/web/auto-reply.partial-reply-gating.test.ts index 9b62993217..0f75791442 100644 --- a/src/web/auto-reply.partial-reply-gating.test.ts +++ b/src/web/auto-reply.partial-reply-gating.test.ts @@ -224,20 +224,11 @@ describe("partial reply gating", () => { replyResolver, ); - let stored: Record | null = null; - for (let attempt = 0; attempt < 50; attempt += 1) { - stored = JSON.parse(await fs.readFile(store.storePath, "utf8")) as Record< - string, - { lastChannel?: string; lastTo?: string } - >; - if (stored[mainSessionKey]?.lastChannel && stored[mainSessionKey]?.lastTo) { - break; - } - await new Promise((resolve) => setTimeout(resolve, 5)); - } - if (!stored) { - throw new Error("store not loaded"); - } + // `monitorWebChannel(..., keepAlive=false)` waits for background tasks, including last-route writes. + const stored = JSON.parse(await fs.readFile(store.storePath, "utf8")) as Record< + string, + { lastChannel?: string; lastTo?: string } + >; expect(stored[mainSessionKey]?.lastChannel).toBe("whatsapp"); expect(stored[mainSessionKey]?.lastTo).toBe("+1000"); @@ -286,27 +277,10 @@ describe("partial reply gating", () => { replyResolver, ); - let stored: Record< + const stored = JSON.parse(await fs.readFile(store.storePath, "utf8")) as Record< string, { lastChannel?: string; lastTo?: string; lastAccountId?: string } - > | null = null; - for (let attempt = 0; attempt < 50; attempt += 1) { - stored = JSON.parse(await fs.readFile(store.storePath, "utf8")) as Record< - string, - { lastChannel?: string; lastTo?: string; lastAccountId?: string } - >; - if ( - stored[groupSessionKey]?.lastChannel && - stored[groupSessionKey]?.lastTo && - stored[groupSessionKey]?.lastAccountId - ) { - break; - } - await new Promise((resolve) => setTimeout(resolve, 5)); - } - if (!stored) { - throw new Error("store not loaded"); - } + >; expect(stored[groupSessionKey]?.lastChannel).toBe("whatsapp"); expect(stored[groupSessionKey]?.lastTo).toBe("123@g.us"); expect(stored[groupSessionKey]?.lastAccountId).toBe("work");