From dcc887362a695abead49f7d0b8a341c0c601f7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 24 Aug 2026 14:52:34 +0200 Subject: [PATCH] fix(test): drain session-event-log writes before rmSync cleanup The save-script transport tests' afterEach removed the per-test temp root while a fire-and-forget session-event-log append (queued by every request the tests send) could still be in flight. Under coverage-shard load the append re-created the session dir between rmSync's unlink sweep and its rmdir, failing cleanup with ENOTEMPTY. Await flushSessionEventLogWrites() before removing the roots. Closes #1998 --- src/daemon/__tests__/request-save-script-transports.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/daemon/__tests__/request-save-script-transports.test.ts b/src/daemon/__tests__/request-save-script-transports.test.ts index 9a68ec939..545ebdb03 100644 --- a/src/daemon/__tests__/request-save-script-transports.test.ts +++ b/src/daemon/__tests__/request-save-script-transports.test.ts @@ -31,6 +31,7 @@ import { skipWhenLoopbackUnavailable, } from '../../__tests__/test-utils/loopback.ts'; import { mkdtempForTestSync } from '../../__tests__/test-utils/tmp-dir.ts'; +import { flushSessionEventLogWrites } from '../session-event-log.ts'; const TOKEN = 'save-script-transport-token'; const SESSION = 'save-script-transport'; @@ -53,7 +54,10 @@ type Harness = { const roots: string[] = []; -afterEach(() => { +afterEach(async () => { + // #1998: request handling queues fire-and-forget session-event-log appends; + // drain them before rmSync or a late append re-creates the dir → ENOTEMPTY. + await flushSessionEventLogWrites(); for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true }); });