From 03652ca8a24bd21e224f786b2f937d4b55a8dcd7 Mon Sep 17 00:00:00 2001 From: JATMN Date: Fri, 23 Oct 2026 10:58:25 -0700 Subject: [PATCH] test: make background termination race deterministic (#2355) --- src/cli/bgRegistry.test.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cli/bgRegistry.test.ts b/src/cli/bgRegistry.test.ts index f7d67b7e9..3f6a523d8 100644 --- a/src/cli/bgRegistry.test.ts +++ b/src/cli/bgRegistry.test.ts @@ -2527,14 +2527,20 @@ describe('background session registry', () => { sessionId: 'conversation-kill-natural-race', }) - await Promise.all([ - recordBackgroundSessionNaturalTermination( - 'bg-kill-natural-race', - { exitCode: 0 }, - { ownerPid: 345 }, - ), - markBackgroundSessionKilled('bg-kill-natural-race'), - ]) + // Let kill observe a running session, then finish naturally before its write. + // Force this interleaving without depending on lock retry timing. + await markBackgroundSessionKilled('bg-kill-natural-race', { + _beforeMarkWriteForTesting: async session => { + expect(session.status).toBe('running') + expect( + await recordBackgroundSessionNaturalTermination( + session.id, + { exitCode: 0 }, + { ownerPid: session.pid }, + ), + ).toMatchObject({ status: 'exited', exitCode: 0 }) + }, + }) expect(await resolveBackgroundSession('bg-kill-natural-race')).toMatchObject( {