From 44bad6f965ce75dfbcae4f33de4532d33c63e111 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 24 Nov 2026 08:20:52 -0600 Subject: [PATCH] test(pm-stack): isolate health-priming server from machine state (#14167) The health-priming test spawned the real aggregator with the caller env and its cwd in the package directory. Quota-current, the quota heartbeat, the meta-renewal state and the gatherer (QUOTA_CURRENT_PATH) all defaulted into the package dir, the freshness IPC port collided with a live aggregator on 4871, and background quota gather ran against the real machine. Point every writable path at the test tmp dir, run the server from there, and add a guard that fails if the run leaves files in the package dir. --- .../aggregator/test/health-priming.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pm-stack/aggregator/test/health-priming.test.ts b/pm-stack/aggregator/test/health-priming.test.ts index 45b514eac9..ebdf30c513 100644 --- a/pm-stack/aggregator/test/health-priming.test.ts +++ b/pm-stack/aggregator/test/health-priming.test.ts @@ -1,6 +1,6 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { spawn, type Subprocess } from "bun"; -import { mkdtemp, writeFile } from "node:fs/promises"; +import { mkdtemp, readdir, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -19,6 +19,8 @@ interface HealthBody { let proc: Subprocess | undefined; let firstHealth: HealthBody | undefined; +let packageDirBefore: string[] = []; +const packageDir = join(import.meta.dir, ".."); // #10467: starting the aggregator subprocess can take longer than bun's // default 5 s hook budget on a loaded machine; give the hook room to @@ -70,14 +72,19 @@ beforeAll(async () => { const feedFile = join(dir, "fleet-feed.json"); await writeFile(feedFile, JSON.stringify(feed)); const port = 5100 + Math.floor(Math.random() * 800); + packageDirBefore = (await readdir(packageDir)).sort(); proc = spawn({ - cmd: ["bun", "run", "src/server.ts"], - cwd: join(import.meta.dir, ".."), + cmd: ["bun", "run", join(packageDir, "src", "server.ts")], + cwd: dir, env: { ...Bun.env, PM_AGG_PORT: String(port), + PM_AGG_FRESHNESS_PORT: String(port + 1000), PM_AGG_SOURCE: "live", PM_AGG_FEED_FILE: feedFile, + PM_AGG_QUOTA_CURRENT_FILE: join(dir, "quota-current.json"), + QUOTA_CURRENT_PATH: join(dir, "quota-current.json"), + META_RENEWAL_STATE_PATH: join(dir, "meta-renewal.json"), PM_AGG_REGISTRY_FILE: join(dir, "registry.json"), PM_AGG_COMMENTS_FILE: join(dir, "comments.json"), PM_AGG_SNAPSHOTS_DIR: join(dir, "snapshots"), @@ -123,4 +130,9 @@ describe("/api/health provenance priming (#1267)", () => { expect(firstHealth?.sections?.orchestration.state).toBe("live"); expect(firstHealth?.sections?.orchestration.runId).toBe("orch-health-test"); }); + + test("the run leaves no files in the package directory", async () => { + await Bun.sleep(500); + expect((await readdir(packageDir)).sort()).toEqual(packageDirBefore); + }); });