Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/canonical-temp-root.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { mkdtempSync, realpathSync, rmSync, symlinkSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { canonicalTempRoot } from "./support/canonical-temp-root";

const temporaryDirectories: string[] = [];

afterEach(() => {
for (const directory of temporaryDirectories.splice(0)) {
rmSync(directory, { recursive: true, force: true });
}
});

describe("canonicalTempRoot", () => {
it("resolves a symlinked temp-root alias before security-sensitive fixtures are created", () => {
const physicalRoot = realpathSync(tmpdir());
const directory = mkdtempSync(join(physicalRoot, "noema-canonical-temp-root-"));
temporaryDirectories.push(directory);
const alias = join(directory, "alias");
symlinkSync(physicalRoot, alias, "dir");

expect(canonicalTempRoot(alias)).toBe(physicalRoot);
});
});
8 changes: 8 additions & 0 deletions test/setup/canonical-temp-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { canonicalTempRoot } from "../support/canonical-temp-root";

const physicalTempRoot = canonicalTempRoot();
process.env.TMPDIR = physicalTempRoot;
if (process.platform === "win32") {
process.env.TEMP = physicalTempRoot;
process.env.TMP = physicalTempRoot;
}
7 changes: 7 additions & 0 deletions test/support/canonical-temp-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { realpathSync } from "node:fs";
import { tmpdir } from "node:os";

/** Resolve the platform temp root to its physical directory for security-sensitive fixtures. */
export function canonicalTempRoot(root = tmpdir()) {
return realpathSync(root);
}
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
include: ["test/**/*.test.ts", "test/**/*.test.mjs"],
setupFiles: ["test/setup/canonical-temp-root.ts"],
// Real acquisition-integrity tests execute the production audit, whose
// child-process boundary is itself capped at 30 seconds. Keep the outer
// harness bounded but give it enough time to observe that explicit result
Expand Down
Loading