Skip to content

Commit 15fcc57

Browse files
committed
test(pin-drift): track tmp dirs and clean up in afterAll
mkdtempSync dirs in pin_drift tool tests were never removed, leaving stale $TMPDIR/pin-drift-tool-test-* dirs accumulating across runs (28 found in developer env). Route all mkdtempSync calls through a tracked helper and rm them recursively in afterAll, so repeated test runs do not leak temp state.
1 parent a703b2c commit 15fcc57

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/server/pin-drift-tool.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { describe, expect, test } from "bun:test";
2-
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
1+
import { afterAll, describe, expect, test } from "bun:test";
2+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55

@@ -10,8 +10,23 @@ import { captureTool } from "./test-harness.js";
1010
// Helpers: create fixture repos in temp dirs (kept for potential future use)
1111
// ---------------------------------------------------------------------------
1212

13+
const TMP_DIRS: string[] = [];
14+
15+
function makeTrackedTmpDir(prefix: string): string {
16+
const dir = mkdtempSync(join(tmpdir(), prefix));
17+
TMP_DIRS.push(dir);
18+
return dir;
19+
}
20+
21+
afterAll(() => {
22+
for (const dir of TMP_DIRS) {
23+
rmSync(dir, { recursive: true, force: true });
24+
}
25+
TMP_DIRS.length = 0;
26+
});
27+
1328
function _makeTmpDir(): string {
14-
return mkdtempSync(join(tmpdir(), "pin-drift-test-"));
29+
return makeTrackedTmpDir("pin-drift-test-");
1530
}
1631

1732
function _writeFile(dir: string, rel: string, content: string): void {
@@ -283,7 +298,7 @@ describe("parseVersionsEnv", () => {
283298

284299
describe("pin_drift tool (captureTool)", () => {
285300
test("empty directory → 0 pins, JSON format", async () => {
286-
const dir = mkdtempSync(join(tmpdir(), "pin-drift-tool-test-"));
301+
const dir = makeTrackedTmpDir("pin-drift-tool-test-");
287302
const run = captureTool(registerPinDriftTool);
288303
const text = await run({ localPath: dir, format: "json" });
289304
const parsed = JSON.parse(text) as { summary?: { totalPins: number } };
@@ -294,7 +309,7 @@ describe("pin_drift tool (captureTool)", () => {
294309
});
295310

296311
test("empty directory → markdown shows 0 pins", async () => {
297-
const dir = mkdtempSync(join(tmpdir(), "pin-drift-tool-test-"));
312+
const dir = makeTrackedTmpDir("pin-drift-tool-test-");
298313
const run = captureTool(registerPinDriftTool);
299314
const text = await run({ localPath: dir });
300315
// Auth error returns JSON; markdown path contains the pin count header

0 commit comments

Comments
 (0)