From 65f05d7c098bcf349f9498208088a3045276a9d3 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 16 Mar 2026 01:37:38 -0700 Subject: [PATCH] Tests: harden WhatsApp inbound contract cleanup --- .../contracts/inbound.whatsapp.contract.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/channels/plugins/contracts/inbound.whatsapp.contract.test.ts b/src/channels/plugins/contracts/inbound.whatsapp.contract.test.ts index c36c2d50fc8..108131226aa 100644 --- a/src/channels/plugins/contracts/inbound.whatsapp.contract.test.ts +++ b/src/channels/plugins/contracts/inbound.whatsapp.contract.test.ts @@ -74,13 +74,27 @@ function makeProcessArgs(sessionStorePath: string) { } as any; } +async function removeDirEventually(dir: string) { + for (let attempt = 0; attempt < 3; attempt += 1) { + try { + await fs.rm(dir, { recursive: true, force: true }); + return; + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "ENOTEMPTY" || attempt === 2) { + throw error; + } + await new Promise((resolve) => setTimeout(resolve, 25)); + } + } +} + describe("whatsapp inbound contract", () => { let sessionDir = ""; afterEach(async () => { capture.ctx = undefined; if (sessionDir) { - await fs.rm(sessionDir, { recursive: true, force: true }); + await removeDirEventually(sessionDir); sessionDir = ""; } });