From f7fdd10a8ba90204473ff4b0fd73e3a599d3bb0b Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:46:03 +0000 Subject: [PATCH 1/3] test(harness): make VerdaccioRegistry.stop() actually terminate the process stop() was calling this.process.kill(0). In the Node child_process API, signal 0 is a liveness probe: it checks whether the process exists and returns true/false, but sends no signal. The forked verdaccio process therefore kept running after every test file's afterAll(), leaking one process per file that uses VerdaccioRegistry. This restores the default SIGTERM (the behavior before #16540) and suppresses the exit listener's 'exited with signal' log when the exit was triggered by stop(), so normal teardown stays quiet. A new test starts a registry, calls stop(), and asserts the child's exit event fires. --- .../verdaccio-registry-lifecycle.test.ts | 33 +++++++++++++++++++ test/harness.ts | 5 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/cli/install/verdaccio-registry-lifecycle.test.ts diff --git a/test/cli/install/verdaccio-registry-lifecycle.test.ts b/test/cli/install/verdaccio-registry-lifecycle.test.ts new file mode 100644 index 000000000000..4433e9f53e6c --- /dev/null +++ b/test/cli/install/verdaccio-registry-lifecycle.test.ts @@ -0,0 +1,33 @@ +import { afterAll, expect, test } from "bun:test"; +import { VerdaccioRegistry } from "harness"; +import { once } from "node:events"; + +let registry: VerdaccioRegistry | undefined; + +afterAll(() => { + if (registry?.process && registry.process.exitCode === null && registry.process.signalCode === null) { + registry.process.kill("SIGKILL"); + } +}); + +// stop() previously called kill(0), which only probes for liveness and left the +// forked verdaccio running after every test file that used it. +test("VerdaccioRegistry.stop() terminates the forked process", async () => { + registry = new VerdaccioRegistry(); + await registry.start(); + + const child = registry.process!; + expect(child.pid).toBeGreaterThan(0); + expect(() => process.kill(child.pid!, 0)).not.toThrow(); + + const exited = once(child, "exit"); + registry.stop(); + + const result = await Promise.race([ + exited.then(() => "exited" as const), + Bun.sleep(3000).then(() => "still running" as const), + ]); + + expect(result).toBe("exited"); + expect(child.killed).toBe(true); +}); diff --git a/test/harness.ts b/test/harness.ts index 634f34e2e22e..90c1fdb6c8a2 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -1826,6 +1826,7 @@ export class VerdaccioRegistry { configPath: string; packagesPath: string; users: Record = {}; + #stopped = false; constructor(opts?: { configPath?: string; packagesPath?: string; verbose?: boolean }) { this.port = randomPort(); @@ -1857,6 +1858,7 @@ export class VerdaccioRegistry { }); this.process.on("exit", (code, signal) => { + if (this.#stopped) return; if (code !== 0) { console.error(`Verdaccio exited with code ${code} and signal ${signal}`); } else { @@ -1878,8 +1880,9 @@ export class VerdaccioRegistry { } stop() { + this.#stopped = true; rmSync(join(dirname(this.configPath), "htpasswd"), { force: true }); - this.process?.kill(0); + this.process?.kill(); } /** From e9a722c9fef3f24fde8b3994132edc94ec4a4122 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:56:09 +0000 Subject: [PATCH 2/3] test(harness): reset #stopped in VerdaccioRegistry.start() Keeps the flag's invariant correct if an instance is ever restarted. --- test/harness.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/harness.ts b/test/harness.ts index 90c1fdb6c8a2..80b0551a096a 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -1835,6 +1835,7 @@ export class VerdaccioRegistry { } async start(silent: boolean = true) { + this.#stopped = false; await rm(join(dirname(this.configPath), "htpasswd"), { force: true }); this.process = fork(require.resolve("verdaccio/bin/verdaccio"), ["-c", this.configPath, "-l", `${this.port}`], { silent, From d652713ce2dba55159662963c02e7996149669ab Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 29 Jul 2026 11:09:10 +0000 Subject: [PATCH 3/3] ci: retrigger