From a4fb7652458354fa7119e15080c84d2ed0673ab3 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sun, 16 Aug 2026 21:00:16 -0700 Subject: [PATCH] test(e2e): return termination status from legacy close handler - terminateLegacyCloseClient now returns a discriminated union indicating whether the process had already exited ('already-exited') or termination was actually attempted ('termination-attempted') - Allows finishLegacyCloseClient to only set forcedCleanup when termination was genuinely needed, not when the process exited cleanly on its own --- .../daemon-generation-legacy-close-safety.spec.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/e2e/daemon-generation-legacy-close-safety.spec.ts b/tests/e2e/daemon-generation-legacy-close-safety.spec.ts index 9f7e977fc1f..8278bbe3b9e 100644 --- a/tests/e2e/daemon-generation-legacy-close-safety.spec.ts +++ b/tests/e2e/daemon-generation-legacy-close-safety.spec.ts @@ -164,13 +164,13 @@ function launchLegacyCloseClient(options: { async function terminateLegacyCloseClient( client: ReturnType, identity: Awaited> | null -): Promise { +): Promise<'already-exited' | 'termination-attempted'> { if (legacyCloseClientExited(client)) { - return + return 'already-exited' } if (identity) { await terminateRecordedTree(await recordProcessTree(identity)) - return + return 'termination-attempted' } // Why: identity capture can race with teardown; the direct child handle is the last cleanup path. client.child.kill('SIGKILL') @@ -179,6 +179,7 @@ async function terminateLegacyCloseClient( () => legacyCloseClientExited(client), 5_000 ) + return 'termination-attempted' } function legacyCloseClientExited(client: ReturnType): boolean { @@ -209,9 +210,10 @@ async function finishLegacyCloseClient( try { await waitForCondition('legacy close client exit', () => legacyCloseClientExited(client), 2_000) } catch { - forcedCleanup = true try { - await terminateLegacyCloseClient(client, identity) + // Why: the wait can time out while the client exits on its own; only a real termination counts. + forcedCleanup = + (await terminateLegacyCloseClient(client, identity)) === 'termination-attempted' } catch (cleanupError) { if (finishFailed) { throw new AggregateError(