Heuristic:20000419 Fauxnix Fresh Tree Isolation
| Knowledge Sources | |
|---|---|
| Domains | Testing, Differential_Testing, Isolation |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Each differential test case gets a fresh pair of file trees (one per engine) to prevent cross-engine contamination and cross-case file leakage from altering results.
Description
The differential runner creates a temp directory per run, then for each of the 270 corpus cases creates two fresh subdirectories: `fauxnix/<case>/` and `bash/<case>/`. Both directories are seeded with the same files from the corpus (shared files + case-specific files). The fauxnix session `cd`s into its directory; bash runs with `cwd` set to its directory. This ensures that (1) the first engine's file mutations cannot affect the second engine's oracle input, and (2) files created by an earlier case cannot change a later case's result. The entire temp tree is removed in a `finally` block after the run completes.
Usage
Use this heuristic when running differential or comparative tests across two engines that mutate the filesystem. Never share a working directory between engines or between test cases — even if a case only reads files, a prior case may have created unexpected files that alter behavior.
The Insight (Rule of Thumb)
- Action: Create `mkdtempSync` per run, then per-case `fauxnix/<case>/` and `bash/<case>/` subdirectories; seed both with identical files.
- Value: One fresh tree pair per case (270 pairs for the full corpus).
- Trade-off: More I/O overhead (directory creation + file writes per case), but guarantees isolation.
- Compatibility: The fauxnix session is shared across cases (prewarmed once), but its cwd changes per case via `cd`.
Reasoning
Without isolation, two failure modes appear: (1) cross-engine contamination — if fauxnix runs first and creates a file, bash's oracle run in the same directory would see that file, producing a false mismatch. (2) cross-case leakage — if case N creates a file and case N+1 expects a clean directory, case N+1's result changes based on execution order. Fresh per-case trees eliminate both. The cost is modest: directory creation and a few `writeFileSync` calls per case, far cheaper than a cold PowerShell boot. The temp root is cleaned up in a `finally` block so crashed runs don't leave debris.
Code Evidence
Per-case fresh trees from `test/differential/run.ts:207-224`:
export async function runCorpus(opts: { corpus?: Corpus; bashPath: string }): Promise<CorpusRun> {
const corpus = opts.corpus ?? loadCorpus();
const dir = mkdtempSync(join(tmpdir(), 'fauxnix-diff-'));
const session = new FauxnixSession();
const results: CaseResult[] = [];
try {
await session.prewarm();
for (const [index, c] of corpus.cases.entries()) {
// Never let the first engine mutate the second engine's oracle input.
// A fresh pair of trees per case also prevents files created by an
// earlier case from changing a later case's result.
const caseName = String(index + 1).padStart(3, '0') + '-' + c.id.replace(/[^a-z0-9_.-]/gi, '_');
const fauxnixDir = join(dir, 'fauxnix', caseName);
const bashDir = join(dir, 'bash', caseName);
const files = { ...(corpus.files ?? {}), ...(c.files ?? {}) };
writeTree(fauxnixDir, files);
writeTree(bashDir, files);
await session.run(translateCommandList(parseCommand('cd "' + fauxnixDir + '"')));
Cleanup from `test/differential/run.ts:244-248`:
} finally {
await session.dispose();
rmSync(dir, { recursive: true, force: true });
}