From 4de8160e9f7a7e606cf984eb8805fdf394041826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 11 Nov 2026 10:22:39 +0000 Subject: [PATCH] fix(test): refuse daemon retry before spawning fixture The retry mock launched a second real child before throwing, leaving its marker outside the client cleanup contract. Refuse before spawning and assert one fixture entry so detection is independent of child scheduling. --- .../daemon-client-startup-race.test.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts b/packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts index 871f425427..fbede191b6 100644 --- a/packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts +++ b/packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts @@ -395,21 +395,20 @@ test('a busy contender that exits sweeps its own pre-lock marker before the retr if (claim.status !== 'acquired') throw new Error('fixture claim refused'); let released = false; spawn.mockImplementation((_command, _args, options) => { + if (spawn.mock.calls.length !== 1) + throw new Error('no second launch: the retry boundary must be observable without a sweeper'); const child = spawnRegisteredDaemonFixture(paths, fields(http.port), options, undefined, { emitStartupMarkerBeforeAcquisition: true, }); - if (spawn.mock.calls.length === 1) { - void child.exited.then((exit) => { - assert.equal(exit.exitCode, DAEMON_STARTUP_EXIT_CODES.busy); - if (!released) { - void claim.acquisition.release().then(() => { - released = true; - }); - } - }); - return child; - } - throw new Error('no second launch: the retry boundary must be observable without a sweeper'); + void child.exited.then((exit) => { + assert.equal(exit.exitCode, DAEMON_STARTUP_EXIT_CODES.busy); + if (!released) { + void claim.acquisition.release().then(() => { + released = true; + }); + } + }); + return child; }); pause.mockImplementation((ms) => actualRetry.sleep(Math.min(Number(ms), 50))); try { @@ -418,6 +417,11 @@ test('a busy contender that exits sweeps its own pre-lock marker before the retr (error: unknown) => error instanceof AppError && error.details?.kind === 'daemon_startup_failed', ); + assert.equal( + fs.readdirSync(path.join(paths.baseDir, 'fixture-entries')).length, + 1, + 'the refused retry must not launch another marker writer', + ); assert.deepEqual( fs.readdirSync(paths.baseDir).filter((e) => e.startsWith('daemon-startup-phases')), [],