From 003aa2b7b6817e3d7370187874142f5c2ac999cb Mon Sep 17 00:00:00 2001 From: azizur100389 Date: Tue, 26 May 2026 03:32:38 +0100 Subject: [PATCH] test(hooks): stabilize concurrency burst reporting --- gitnexus/test/unit/hooks.test.ts | 33 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/gitnexus/test/unit/hooks.test.ts b/gitnexus/test/unit/hooks.test.ts index 892a19483..d049a8ae2 100644 --- a/gitnexus/test/unit/hooks.test.ts +++ b/gitnexus/test/unit/hooks.test.ts @@ -778,27 +778,24 @@ describe('PreToolUse concurrency guard (integration)', () => { `; const N = 10; - const claimers = Array.from({ length: N }, () => - spawn(process.execPath, ['-e', claimerScript], { + const claimers = Array.from({ length: N }, () => { + const child = spawn(process.execPath, ['-e', claimerScript], { stdio: ['ignore', 'pipe', 'ignore'], detached: false, - }), - ); + }); + const decision = new Promise((resolve) => { + let buf = ''; + child.stdout!.on('data', (d) => { + buf += d.toString(); + if (buf.includes('\n')) resolve(buf.split('\n')[0]); + }); + child.on('exit', () => resolve(buf.split('\n')[0] || 'EXIT')); + }); + return { child, decision }; + }); try { // Wait until every claimer has printed its decision. - const decisions = await Promise.all( - claimers.map( - (c) => - new Promise((resolve) => { - let buf = ''; - c.stdout!.on('data', (d) => { - buf += d.toString(); - if (buf.includes('\n')) resolve(buf.split('\n')[0]); - }); - c.on('exit', () => resolve(buf.split('\n')[0] || 'EXIT')); - }), - ), - ); + const decisions = await Promise.all(claimers.map((c) => c.decision)); const claimedCount = decisions.filter((d) => d.startsWith('CLAIMED:')).length; const skippedCount = decisions.filter((d) => d === 'SKIPPED').length; @@ -823,7 +820,7 @@ describe('PreToolUse concurrency guard (integration)', () => { } finally { for (const c of claimers) { try { - c.kill(); + c.child.kill(); } catch { /* ignore */ }