From 0d3eef9a90e4fa334679dfbbbc3be986ed3a9050 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 20:59:07 -0800 Subject: [PATCH 1/8] chore(quest): claim quest/m0/gate-test-leak.md Quest-Claim: c4334b1b4f1f97d0 From e47bbf98d0d7cdd62f9909d9b161d65bbf8aeb84 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 21:19:10 -0800 Subject: [PATCH 2/8] test(gate): stop the scopes a test starts when it fails or its run is signalled Co-Authored-By: Claude Sonnet 5.5 --- quest/m0/gate-test-leak.md | 27 --------------------------- test/gate.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 quest/m0/gate-test-leak.md diff --git a/quest/m0/gate-test-leak.md b/quest/m0/gate-test-leak.md deleted file mode 100644 index 5bcacfba..00000000 --- a/quest/m0/gate-test-leak.md +++ /dev/null @@ -1,27 +0,0 @@ -# [XS] The gate's nested-scope tests leave no scope running - -## Goal - -`just test` leaves no `quest-gate-*.scope` running after it finishes, -pass or fail. - -## Plan - -Found 2026-11-12 on the maintainer's host: two gate scopes from a test -run on 2026-11-11 at 00:57 were still running 42 hours later, one holding -`just --justfile /tmp/quest-test-KEYeCs/justfile ... phase` and the other -`bun /tmp/quest-test-KEYeCs/nested.ts`. They match `test/gate.test.ts`'s -`nestedGate` and `phase` helpers, the tests around "is stopped when the -enclosing scope's owner kills it". Both were stopped by hand on -2026-11-12, so reproduce the leak before fixing it, per the rule. - -Decided 2026-11-12 (maintainer, /quest-plan): ✅ plan it in m0 -(rejected: m1). - -Fix it at the root: a leaked scope means some path, a failed or -timed-out test included, ends without stopping the scope it bound, which -may also leak in real nested gates outside the tests. - -## Hosts - -- linux - only systemd scopes can leak diff --git a/test/gate.test.ts b/test/gate.test.ts index b5210c85..d02dd88f 100644 --- a/test/gate.test.ts +++ b/test/gate.test.ts @@ -45,6 +45,7 @@ import { forwards, foregroundStat, statProcess } from "../src/cli/interrupt"; import { gateBoundary, main } from "../src/cli/main"; import { alive as ownerAlive, questScope } from "../src/cli/supervise"; import { created, onTerminal, run, signalled, tempDir } from "./fixture"; +import * as supervise from "../src/cli/supervise"; // Linux reports a /proc read that races a process's exit as ESRCH rather than ENOENT, so fail // one process's stat read with either code, without timing. @@ -71,6 +72,33 @@ const me = { pid: process.pid, start: processStart(process.pid) }; afterEach(() => vi.unstubAllEnvs()); +// A test that fails or times out never ends its run, nor does one whose run is signalled, and the +// scope it started outlives the process. Record every scope this file starts until its run ends. +const live = new Set(); +const { systemdScopes } = supervise; +const startScope = systemdScopes.run; +systemdScopes.run = (unit, ...rest) => { + live.add(unit); + return startScope(unit, ...rest).finally(() => live.delete(unit)); +}; + +// Stops the scopes a test left running, and the gates bound to them. +afterEach(async () => { + for (const unit of live) await systemdScopes.stop(unit); + live.clear(); +}); + +// A run signalled mid-test ends without reaching afterEach: stop the scopes, then die of the signal. +if (process.platform === "linux") + for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) + process.once(signal, () => { + for (const unit of live) { + const group = supervise.scopeGroup(unit); + if (group) supervise.kill(group); + } + process.kill(process.pid, signal); + }); + test("limits derive from the host's CPUs and memory", () => { // The host-wide load average is compared with every host CPU, not the // process's affinity subset, so an idle assigned CPU is not held back. From 1300e38b6ace7af38c862b330db777bb055862a6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 21:38:03 -0800 Subject: [PATCH 3/8] test: stop leaked scopes from every test file, keep a rejected run's scope tracked Co-Authored-By: Claude Sonnet 5.5 --- test/gate.test.ts | 28 ---------------------------- test/scopes.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vitest.config.ts | 2 +- 3 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 test/scopes.ts diff --git a/test/gate.test.ts b/test/gate.test.ts index d02dd88f..b5210c85 100644 --- a/test/gate.test.ts +++ b/test/gate.test.ts @@ -45,7 +45,6 @@ import { forwards, foregroundStat, statProcess } from "../src/cli/interrupt"; import { gateBoundary, main } from "../src/cli/main"; import { alive as ownerAlive, questScope } from "../src/cli/supervise"; import { created, onTerminal, run, signalled, tempDir } from "./fixture"; -import * as supervise from "../src/cli/supervise"; // Linux reports a /proc read that races a process's exit as ESRCH rather than ENOENT, so fail // one process's stat read with either code, without timing. @@ -72,33 +71,6 @@ const me = { pid: process.pid, start: processStart(process.pid) }; afterEach(() => vi.unstubAllEnvs()); -// A test that fails or times out never ends its run, nor does one whose run is signalled, and the -// scope it started outlives the process. Record every scope this file starts until its run ends. -const live = new Set(); -const { systemdScopes } = supervise; -const startScope = systemdScopes.run; -systemdScopes.run = (unit, ...rest) => { - live.add(unit); - return startScope(unit, ...rest).finally(() => live.delete(unit)); -}; - -// Stops the scopes a test left running, and the gates bound to them. -afterEach(async () => { - for (const unit of live) await systemdScopes.stop(unit); - live.clear(); -}); - -// A run signalled mid-test ends without reaching afterEach: stop the scopes, then die of the signal. -if (process.platform === "linux") - for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) - process.once(signal, () => { - for (const unit of live) { - const group = supervise.scopeGroup(unit); - if (group) supervise.kill(group); - } - process.kill(process.pid, signal); - }); - test("limits derive from the host's CPUs and memory", () => { // The host-wide load average is compared with every host CPU, not the // process's affinity subset, so an idle assigned CPU is not held back. diff --git a/test/scopes.ts b/test/scopes.ts new file mode 100644 index 00000000..8dde2b85 --- /dev/null +++ b/test/scopes.ts @@ -0,0 +1,47 @@ +// Stops the systemd scopes a test starts and leaves running. A scope outlives the process that +// started it, so a test that fails or times out, or a run signalled mid-test (a cancelled +// `quest gate` delivers its signal to every process in the test run), would leave it running. + +import { afterEach, beforeAll } from "vitest"; + +type Supervise = typeof import("../src/cli/supervise"); + +/** The scopes this file started whose run has not ended. A run that rejects may still hold processes, so it stays. */ +const live = new Set(); +let supervise: Supervise | undefined; + +// Loaded once the test file has registered its mocks, so they apply to the module the tests share. +beforeAll(async () => { + const loaded = await import("../src/cli/supervise"); + const start = loaded.systemdScopes.run; + loaded.systemdScopes.run = async (unit, ...rest) => { + live.add(unit); + const result = await start(unit, ...rest); + live.delete(unit); + return result; + }; + supervise = loaded; +}); + +// Stops what a failed or timed-out test left, and the gates bound to it; one failure never hides the rest. +afterEach(async () => { + const units = [...live]; + live.clear(); + const stops = await Promise.allSettled(units.map((unit) => supervise!.systemdScopes.stop(unit))); + const failed = stops.flatMap((stop) => (stop.status === "rejected" ? [stop.reason] : [])); + if (failed.length) throw new AggregateError(failed, `cannot stop ${failed.length} of ${units.length} test scopes`); +}); + +// A signalled run never reaches afterEach: kill the scopes, then die of the signal. +if (process.platform === "linux") + for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) + process.once(signal, () => { + try { + for (const unit of live) { + const group = supervise!.scopeGroup(unit); + if (group) supervise!.kill(group); + } + } finally { + process.kill(process.pid, signal); + } + }); diff --git a/vitest.config.ts b/vitest.config.ts index a5757b30..f3abb863 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -27,7 +27,7 @@ export default defineConfig({ exclude: [...configDefaults.exclude, "test/live/**"], // A test's CPU budget (test/budget.ts) bounds how slow it may be; this wall-clock // limit only catches a test awaiting what never comes, so a loaded host never reaches it. - setupFiles: ["test/budget.ts"], + setupFiles: ["test/budget.ts", "test/scopes.ts"], testTimeout: 5 * 60_000, hookTimeout: 5 * 60_000, }), From 1e256c630c5c3ca2410e5f0ac481ce5add66100f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 22:05:56 -0800 Subject: [PATCH 4/8] test: one scope that cannot be killed no longer spares the rest on a signal Co-Authored-By: Claude Sonnet 5.5 --- test/scopes.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/scopes.ts b/test/scopes.ts index 8dde2b85..a774db10 100644 --- a/test/scopes.ts +++ b/test/scopes.ts @@ -36,12 +36,14 @@ afterEach(async () => { if (process.platform === "linux") for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) process.once(signal, () => { - try { - for (const unit of live) { + for (const unit of live) { + // One scope that cannot be killed must not spare the rest, nor keep the run alive. + try { const group = supervise!.scopeGroup(unit); if (group) supervise!.kill(group); + } catch (error) { + process.stderr.write(`cannot kill test scope ${unit}: ${error}\n`); } - } finally { - process.kill(process.pid, signal); } + process.kill(process.pid, signal); }); From 61054cf32a4187f35963dce222579215a5105322 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 22:27:41 -0800 Subject: [PATCH 5/8] test: keep a scope tracked until its stop succeeds Co-Authored-By: Claude Opus 5.5 --- test/scopes.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/scopes.ts b/test/scopes.ts index a774db10..dfab233a 100644 --- a/test/scopes.ts +++ b/test/scopes.ts @@ -26,8 +26,13 @@ beforeAll(async () => { // Stops what a failed or timed-out test left, and the gates bound to it; one failure never hides the rest. afterEach(async () => { const units = [...live]; - live.clear(); - const stops = await Promise.allSettled(units.map((unit) => supervise!.systemdScopes.stop(unit))); + // A unit leaves only once stopped, so a later hook or the signal handler retries one whose stop failed. + const stops = await Promise.allSettled( + units.map(async (unit) => { + await supervise!.systemdScopes.stop(unit); + live.delete(unit); + }), + ); const failed = stops.flatMap((stop) => (stop.status === "rejected" ? [stop.reason] : [])); if (failed.length) throw new AggregateError(failed, `cannot stop ${failed.length} of ${units.length} test scopes`); }); From e806902420777d9c7f0ad11f3bec3ffb411ff062 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 23:26:57 -0800 Subject: [PATCH 6/8] test: sweep every scope a test run leaves, by a marker its processes inherit The per-test hook saw only scopes the worker started through systemdScopes.run, so a supervisor a test SIGKILLs left its quest-worktree scope running whenever the test failed before stopping it. A global setup now marks the run in the environment every test process and child CLI inherits, and stops each Quest scope holding a marked process: this run's at teardown and on SIGHUP/SIGINT/SIGTERM, and those of runs that exited, such as by SIGKILL, at the next run's setup. Co-Authored-By: Claude Opus 5.5 --- src/cli/supervise.ts | 2 +- test/scopes.test.ts | 63 +++++++++++++++++++ test/scopes.ts | 142 ++++++++++++++++++++++++++++--------------- vitest.config.ts | 3 +- 4 files changed, 159 insertions(+), 51 deletions(-) create mode 100644 test/scopes.test.ts diff --git a/src/cli/supervise.ts b/src/cli/supervise.ts index feac04a2..7bde5a57 100644 --- a/src/cli/supervise.ts +++ b/src/cli/supervise.ts @@ -210,7 +210,7 @@ function signalGroup(group: string, signal: NodeJS.Signals): void { } /** The processes in the cgroup and every cgroup below it; none once it is removed. */ -function members(group: string): number[] { +export function members(group: string): number[] { try { const own = readFileSync(join(group, "cgroup.procs"), "utf8").split("\n").filter(Boolean).map(Number); const children = readdirSync(group, { withFileTypes: true }).filter((entry) => entry.isDirectory()); diff --git a/test/scopes.test.ts b/test/scopes.test.ts new file mode 100644 index 00000000..57a24eec --- /dev/null +++ b/test/scopes.test.ts @@ -0,0 +1,63 @@ +import { spawn } from "node:child_process"; +import { randomUUID } from "node:crypto"; +import { once } from "node:events"; +import { hostname } from "node:os"; +import { join } from "node:path"; + +import { describe, expect, test } from "vitest"; + +import { alive, startTime, systemdScopes } from "../src/cli/supervise"; +import { created, tempDir } from "./fixture"; +import { RUN, sweep } from "./scopes"; + +describe.runIf(process.platform === "linux")("the test run's scope sweep", () => { + test("marks every test process with the live run it belongs to", () => { + const [pid, start] = process.env[RUN]!.split(":"); + expect(alive({ host: hostname(), pid: Number(pid), start })).toBe(true); + }); + + /** Start `sleep` in a new Quest scope as a process of `run`, resolving once it runs there. */ + async function leave(run: string) { + const dir = tempDir(); + const ready = join(dir, "ready"); + const unit = `quest-gate-${randomUUID()}.scope`; + const child = spawn( + "systemd-run", + [ + "--user", + "--scope", + "--quiet", + "--collect", + `--unit=${unit}`, + "/bin/sh", + "-c", + `: > ${JSON.stringify(ready)}; exec sleep 1000`, + ], + { env: { ...process.env, [RUN]: run }, stdio: "ignore" }, + ); + const exited = once(child, "exit"); + await created(ready); + return { unit, exited }; + } + + test("stops a scope a dead run left and spares one of a live run", async () => { + // This process's PID with a start time it never had names a run that has exited. + const left = await leave(`${process.pid}:0`); + const kept = await leave(process.env[RUN]!); + await sweep(); + expect(systemdScopes.live(left.unit)).toBe(false); + expect(systemdScopes.live(kept.unit)).toBe(true); + expect(await left.exited).toEqual([null, "SIGKILL"]); + await systemdScopes.stop(kept.unit); + expect(await kept.exited).toEqual([null, "SIGKILL"]); + }); + + test("stops the scopes of the live run it names", async () => { + // This worker names a live run other than the one every test belongs to. + const run = `${process.pid}:${startTime(process.pid)}`; + const left = await leave(run); + await sweep(run); + expect(systemdScopes.live(left.unit)).toBe(false); + expect(await left.exited).toEqual([null, "SIGKILL"]); + }); +}); diff --git a/test/scopes.ts b/test/scopes.ts index dfab233a..18fddc4c 100644 --- a/test/scopes.ts +++ b/test/scopes.ts @@ -1,54 +1,98 @@ -// Stops the systemd scopes a test starts and leaves running. A scope outlives the process that -// started it, so a test that fails or times out, or a run signalled mid-test (a cancelled -// `quest gate` delivers its signal to every process in the test run), would leave it running. - -import { afterEach, beforeAll } from "vitest"; - -type Supervise = typeof import("../src/cli/supervise"); - -/** The scopes this file started whose run has not ended. A run that rejects may still hold processes, so it stays. */ -const live = new Set(); -let supervise: Supervise | undefined; - -// Loaded once the test file has registered its mocks, so they apply to the module the tests share. -beforeAll(async () => { - const loaded = await import("../src/cli/supervise"); - const start = loaded.systemdScopes.run; - loaded.systemdScopes.run = async (unit, ...rest) => { - live.add(unit); - const result = await start(unit, ...rest); - live.delete(unit); - return result; - }; - supervise = loaded; -}); - -// Stops what a failed or timed-out test left, and the gates bound to it; one failure never hides the rest. -afterEach(async () => { - const units = [...live]; - // A unit leaves only once stopped, so a later hook or the signal handler retries one whose stop failed. - const stops = await Promise.allSettled( - units.map(async (unit) => { - await supervise!.systemdScopes.stop(unit); - live.delete(unit); - }), - ); +// Stops the Quest scopes a test run leaves running. A scope outlives the process that started it, +// so a test that fails or times out before stopping one, a supervisor a test kills, or a run +// signalled mid-test (a cancelled `quest gate` signals every process in the run) would leave it. +// Every process the run starts, child CLIs and their scopes included, inherits the run's marker in +// its environment, so the sweep finds a scope by what runs in it rather than by who started it. + +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { hostname } from "node:os"; +import { join } from "node:path"; + +import { alive, kill, members, startTime, systemdScopes } from "../src/cli/supervise"; + +/** Names the test run a process belongs to, as its main process's `:`. */ +export const RUN = "QUEST_TEST_RUN"; + +/** Whether the test run `run` names has exited. */ +function dead(run: string): boolean { + const match = /^(\d+):(\d+)$/.exec(run); + if (!match) throw new Error(`malformed ${RUN}: ${run}`); + return !alive({ host: hostname(), pid: Number(match[1]), start: match[2] }); +} + +/** + * The run `pid` belongs to, or undefined for a process outside every run, already gone, or hiding + * its environment, as a setuid program another session runs does; no test runs one. + */ +function runOf(pid: number): string | undefined { + try { + const environ = readFileSync(`/proc/${pid}/environ`, "utf8").split("\0"); + return environ.find((entry) => entry.startsWith(`${RUN}=`))?.slice(RUN.length + 1); + } catch (error) { + if (["ENOENT", "ESRCH", "EACCES"].includes((error as NodeJS.ErrnoException).code ?? "")) return undefined; + throw error; + } +} + +/** + * The cgroups of the Quest scopes holding a process of run `own` or of a run that has exited, but + * never one holding this process, such as the gate's scope around `just test`. + */ +function strays(own?: string): Map { + const self = readFileSync("/proc/self/cgroup", "utf8") + .split("\n") + .find((line) => line.startsWith("0::"))! + .slice(3); + const show = execFileSync("systemctl", ["--user", "show", "--property=Id,ControlGroup", "quest-*.scope"], { + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }); + const found = new Map(); + for (const entry of show.split("\n\n")) { + const unit = /^Id=(.+)$/m.exec(entry)?.[1]; + const group = /^ControlGroup=(.+)$/m.exec(entry)?.[1]; + if (!unit || !group || self === group || self.startsWith(`${group}/`)) continue; + const path = join("/sys/fs/cgroup", group); + const runs = members(path).map(runOf); + if (runs.some((run) => run !== undefined && (run === own || dead(run)))) found.set(unit, path); + } + return found; +} + +/** Stop every scope a run that exited left running, and those of run `own`; resolves once each is empty. */ +export async function sweep(own?: string): Promise { + const stops = await Promise.allSettled([...strays(own).keys()].map((unit) => systemdScopes.stop(unit))); const failed = stops.flatMap((stop) => (stop.status === "rejected" ? [stop.reason] : [])); - if (failed.length) throw new AggregateError(failed, `cannot stop ${failed.length} of ${units.length} test scopes`); -}); + if (failed.length) throw new AggregateError(failed, `cannot stop ${failed.length} test scopes`); +} -// A signalled run never reaches afterEach: kill the scopes, then die of the signal. -if (process.platform === "linux") - for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) +/** Vitest's global setup: marks the run, clears what dead runs left, and stops this run's scopes when it ends. */ +export default async function setup(): Promise<(() => Promise) | undefined> { + if (process.platform !== "linux") return undefined; + const own = `${process.pid}:${startTime(process.pid)}`; + // Set before the workers start, so they and everything they spawn inherit it. + process.env[RUN] = own; + // A run killed outright, such as by SIGKILL, never reached its teardown. + await sweep(); + // A signalled run never reaches its teardown either. + for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) { process.once(signal, () => { - for (const unit of live) { - // One scope that cannot be killed must not spare the rest, nor keep the run alive. - try { - const group = supervise!.scopeGroup(unit); - if (group) supervise!.kill(group); - } catch (error) { - process.stderr.write(`cannot kill test scope ${unit}: ${error}\n`); - } + // One scope that cannot be killed must not spare the rest, nor keep the run alive. + try { + for (const [unit, group] of strays(own)) + try { + kill(group); + } catch (error) { + process.stderr.write(`cannot kill test scope ${unit}: ${error}\n`); + } + } catch (error) { + process.stderr.write(`cannot find the test scopes: ${error}\n`); } - process.kill(process.pid, signal); + // Raised again once this listener is gone, the signal ends the run as it would have without + // it: signal-exit, which Vite's bundler loads, re-raises a signal only when it listens alone. + setImmediate(() => process.kill(process.pid, signal)); }); + } + return () => sweep(own); +} diff --git a/vitest.config.ts b/vitest.config.ts index f3abb863..3d66f802 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -27,7 +27,8 @@ export default defineConfig({ exclude: [...configDefaults.exclude, "test/live/**"], // A test's CPU budget (test/budget.ts) bounds how slow it may be; this wall-clock // limit only catches a test awaiting what never comes, so a loaded host never reaches it. - setupFiles: ["test/budget.ts", "test/scopes.ts"], + setupFiles: ["test/budget.ts"], + globalSetup: ["test/scopes.ts"], testTimeout: 5 * 60_000, hookTimeout: 5 * 60_000, }), From c30984707da952e8dcf87d8cd49e91769acbf452 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 13 Nov 2026 00:56:41 -0800 Subject: [PATCH 7/8] test: run every test where no user manager answers, sweeping nothing Without a reachable user manager, the sweep's systemctl call failed the global setup and so every run, even focused runs that start no scope. No test can start a scope there, so setup now checks once and skips the sweep and its signal handlers. Co-Authored-By: Claude Opus 5.5 --- test/scopes.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/scopes.ts b/test/scopes.ts index 18fddc4c..2323f926 100644 --- a/test/scopes.ts +++ b/test/scopes.ts @@ -67,12 +67,24 @@ export async function sweep(own?: string): Promise { if (failed.length) throw new AggregateError(failed, `cannot stop ${failed.length} test scopes`); } +/** Whether a user manager answers; without one, no test can start a scope, and none was left. */ +function managed(): boolean { + try { + execFileSync("systemctl", ["--user", "show", "--property=Version", "--value"], { stdio: "ignore" }); + return true; + } catch { + return false; + } +} + /** Vitest's global setup: marks the run, clears what dead runs left, and stops this run's scopes when it ends. */ export default async function setup(): Promise<(() => Promise) | undefined> { if (process.platform !== "linux") return undefined; const own = `${process.pid}:${startTime(process.pid)}`; // Set before the workers start, so they and everything they spawn inherit it. process.env[RUN] = own; + // Such as in a container: the tests that start scopes fail there on their own, and the rest still run. + if (!managed()) return undefined; // A run killed outright, such as by SIGKILL, never reached its teardown. await sweep(); // A signalled run never reaches its teardown either. From d652981c33ee8e39069315ea415e8e26c9f322a1 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 13 Nov 2026 01:04:54 -0800 Subject: [PATCH 8/8] test: fail a sweep test at once when its scope never starts A launcher that exited before creating its ready file, such as one no user manager answers, left the test waiting out its five-minute timeout. Co-Authored-By: Claude Opus 5.5 --- test/scopes.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/scopes.test.ts b/test/scopes.test.ts index 57a24eec..750f5d86 100644 --- a/test/scopes.test.ts +++ b/test/scopes.test.ts @@ -36,7 +36,14 @@ describe.runIf(process.platform === "linux")("the test run's scope sweep", () => { env: { ...process.env, [RUN]: run }, stdio: "ignore" }, ); const exited = once(child, "exit"); - await created(ready); + // A launcher that exits first, such as one no user manager answers, fails the test at once. + await new Promise((resolve, reject) => { + created(ready).then(resolve, reject); + exited.then( + ([code, signal]) => reject(new Error(`systemd-run ended (${code ?? signal}) before its command ran`)), + reject, + ); + }); return { unit, exited }; }