From de022efd6176e7d394e6ae9fc87e22c44f55b3ca Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 12 Oct 2026 23:19:48 +0000 Subject: [PATCH] test(env): wait for the foreground job's name, not just any foreground process The shell forks before it execs, so a poll could catch the forked shell (named sh) and fail the name check. --- packages/env/test/terminal.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/env/test/terminal.test.ts b/packages/env/test/terminal.test.ts index 3c0ab1d8c..917ba5723 100644 --- a/packages/env/test/terminal.test.ts +++ b/packages/env/test/terminal.test.ts @@ -87,14 +87,16 @@ describe.skipIf(process.platform === "win32")("openTerminal", () => { await output.waitFor("READY"); expect(await terminal.foreground()).toBeUndefined(); terminal.write("sleep 100\n"); + // The shell forks before it execs: wait until the foreground job is the command itself, not the forked shell. + const named = process.platform === "darwin" || process.platform === "linux"; let foreground = await terminal.foreground(); - for (let tries = 0; !foreground && tries < 100; tries++) { + for (let tries = 0; (!foreground || (named && foreground.name !== "sleep")) && tries < 100; tries++) { await new Promise((resolve) => setTimeout(resolve, 20)); foreground = await terminal.foreground(); } expect(foreground?.pid).toBeGreaterThan(0); expect(foreground?.pid).not.toBe(terminal.pid); - if (process.platform === "darwin" || process.platform === "linux") expect(foreground?.name).toBe("sleep"); + if (named) expect(foreground?.name).toBe("sleep"); terminal.close(); await expect(terminal.exited).rejects.toMatchObject({ code: "aborted" }); await expect(terminal.foreground()).rejects.toMatchObject({ code: "EBADF" });