// own-tree.mjs — Fixtures that ARE the process's own working tree (S3c). // // .llm-security/policy.json is honored for an explicit scan root only when // that root is the caller's own working tree: under process.cwd(), never // under os.tmpdir() (scanners/lib/own-working-tree.mjs). Tests of LOCAL // policy behaviour therefore need a fixture that is the caller's own tree — // a throwaway dir outside os.tmpdir() and outside this repo's git tree // (under $HOME, same placement rule as ignore-file-scope.test.mjs), made the // process cwd while the test runs. node --test runs each file in its own // process, so the chdir never leaks into another test file. import { mkdtempSync } from 'node:fs'; import { join } from 'node:path'; import { homedir } from 'node:os'; /** Create a throwaway own-tree fixture dir (caller removes it). */ export function mkOwnTreeDir(prefix) { return mkdtempSync(join(homedir(), `.${prefix}`)); } /** Run fn with dir as the process cwd; the previous cwd is always restored. */ export async function inOwnTree(dir, fn) { const prev = process.cwd(); process.chdir(dir); try { return await fn(); } finally { process.chdir(prev); } }