From 4643844ea574a0447653ecf84b2c4124e743c078 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 24 Oct 2026 07:42:19 +0800 Subject: [PATCH] test(kuna): wait for probe readiness within command deadline --- .../boundary/cli/kunaDoctorHeldOutput.test.ts | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/boundary/cli/kunaDoctorHeldOutput.test.ts b/tests/boundary/cli/kunaDoctorHeldOutput.test.ts index 69d3fe9cf3..a73dcbda9a 100644 --- a/tests/boundary/cli/kunaDoctorHeldOutput.test.ts +++ b/tests/boundary/cli/kunaDoctorHeldOutput.test.ts @@ -57,11 +57,20 @@ process.exit(0); // regression that waits for the descendant's finite fallback expiry. timeoutMs: 20_000, }); + let commandSettled = false; + void pending.then( + () => { + commandSettled = true; + }, + () => { + commandSettled = true; + }, + ); let ownership: OwnedProcessGroup | undefined; const startedAt = Date.now(); try { let markerContents: string | undefined; - for (let attempt = 0; attempt < 100; attempt++) { + for (;;) { try { markerContents = await readFile(marker, "utf8"); break; @@ -75,9 +84,23 @@ process.exit(0); ) throw cause; } + // CLI startup and the probe are separate phases. The owned command's + // existing deadline bounds this wait; its marker establishes readiness. + if (commandSettled) break; await delay(50); } - expect(markerContents, "fake Kuna probe did not start").toBeDefined(); + if (markerContents === undefined) { + const markerWaitMs = Date.now() - startedAt; + const result = await pending; + expect( + markerContents, + `Kuna probe marker was absent when the CLI settled: ${JSON.stringify({ + markerWaitMs, + cliElapsedMs: Date.now() - startedAt, + ...result, + })}`, + ).toBeDefined(); + } const observed = z .strictObject({ leaderPid: z.number().int().positive(),