From f1bbd1e1994ba77dd5c61c29135dada46a204774 Mon Sep 17 00:00:00 2001 From: luvs01 Date: Mon, 31 Aug 2026 00:08:22 +0900 Subject: [PATCH] test: use private temp dir for route scanner probe --- tests/management-route-registry.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/management-route-registry.test.ts b/tests/management-route-registry.test.ts index d5ccab6efe..dcea7f0fc0 100644 --- a/tests/management-route-registry.test.ts +++ b/tests/management-route-registry.test.ts @@ -1,5 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { existsSync, readFileSync, readdirSync } from "node:fs"; +import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { MANAGEMENT_ROUTES } from "../src/server/management/route-registry"; @@ -122,7 +123,8 @@ describe("management route registry reconciliation", () => { // Drives the fail-loud path red on purpose: without this, a scanner that silently // defaulted to GET would satisfy every other test in this file while producing a // route table nobody could trust. - const tmp = join(repoRoot, ".tmp-scanner-probe.ts"); + const tempDir = mkdtempSync(join(tmpdir(), "ocx-route-scanner-")); + const tmp = join(tempDir, "scanner-probe.ts"); const source = [ "export async function handleProbe(ctx: any): Promise {", " const { url, req } = ctx;", @@ -133,13 +135,13 @@ describe("management route registry reconciliation", () => { " return null;", "}", ].join("\n"); - require("node:fs").writeFileSync(tmp, source); + writeFileSync(tmp, source); try { const { unresolved } = distinctRoutes(scanRoutes(tmp)); expect(unresolved.map(r => r.path)).toEqual(["/api/probe/unknowable"]); expect(unresolved[0]?.method).toBeNull(); } finally { - require("node:fs").rmSync(tmp, { force: true }); + rmSync(tempDir, { recursive: true, force: true }); } });