Staging CI run 6876 failed 'importing the registry creates no runtime directory' with '1' !== '0': the test counted jyotisha-skill-runtime-* entries in the shared OS temp dir while other test files created their own. Each child now gets an empty TMPDIR of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
67 lines
3.0 KiB
TypeScript
67 lines
3.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { test } from "node:test";
|
|
|
|
// BUG-1612: importing skill-package-registry used to create a
|
|
// `jyotisha-skill-runtime-*` directory under the OS temp dir and never remove
|
|
// it, one per node process. The root is now created on first use and removed
|
|
// at process exit. Each case runs in its own child process so the exit hook
|
|
// actually fires.
|
|
|
|
const frontendRoot = fileURLToPath(new URL("../", import.meta.url));
|
|
const projectRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
const registryModule = fileURLToPath(new URL("../src/lib/skill-package-registry.ts", import.meta.url));
|
|
const tsx = fileURLToPath(new URL("../node_modules/.bin/tsx", import.meta.url));
|
|
|
|
// Each child gets its own empty TMPDIR: counting entries in the shared OS temp
|
|
// dir raced with other test files creating runtime roots in parallel (CI run
|
|
// 6876 saw '1' !== '0' on an unrelated commit). The caller removes it after
|
|
// its own assertions.
|
|
function runChild(source: string, privateTmp: string): string {
|
|
return execFileSync(tsx, ["--eval", `(async () => {${source}})().catch((error) => { console.error(error); process.exit(1); });`], {
|
|
cwd: frontendRoot,
|
|
encoding: "utf8",
|
|
env: { ...process.env, JYOTISHA_PROJECT_ROOT: projectRoot, TMPDIR: privateTmp, TMP: privateTmp, TEMP: privateTmp },
|
|
}).trim();
|
|
}
|
|
|
|
function withPrivateTmp(run: (dir: string) => void) {
|
|
const dir = mkdtempSync(join(tmpdir(), "bug-1612-"));
|
|
try {
|
|
run(dir);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
test("importing the registry creates no runtime directory", () => withPrivateTmp((dir) => {
|
|
const out = runChild(`
|
|
const { readdirSync } = await import("node:fs");
|
|
const { tmpdir } = await import("node:os");
|
|
const count = () => readdirSync(tmpdir()).filter((n) => n.startsWith("jyotisha-skill-runtime-")).length;
|
|
const before = count();
|
|
await import(${JSON.stringify(registryModule)});
|
|
console.log(String(count() - before));
|
|
`, dir);
|
|
assert.equal(out.split("\n").at(-1), "0");
|
|
}));
|
|
|
|
test("a used runtime root is removed when the process exits", () => withPrivateTmp((dir) => {
|
|
const out = runChild(`
|
|
const registry = await import(${JSON.stringify(registryModule)});
|
|
const live = registry.resolveLiveJyotishSkill({ projectRoot: ${JSON.stringify(projectRoot)} });
|
|
const first = registry.resolveLiveJyotishSkillRuntimePath(live);
|
|
const second = registry.resolveLiveJyotishSkillRuntimePath(live);
|
|
if (first !== second) throw new Error("runtime root changed within one process");
|
|
console.log(first);
|
|
`, dir);
|
|
const runtimePath = out.split("\n").at(-1)!;
|
|
assert.match(runtimePath, /jyotisha-skill-runtime-/);
|
|
assert.ok(runtimePath.startsWith(dir), "the child used its private TMPDIR");
|
|
assert.equal(existsSync(runtimePath), false, "the alias root outlived its process");
|
|
}));
|