Implementation:20000419 Fauxnix Differential Runner
| Knowledge Sources | |
|---|---|
| Domains | Testing, Differential_Testing, Validation |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Concrete differential runner that loads a 270-case bash corpus, executes each case on both a fauxnix FauxnixSession and real Git Bash, and compares stdout/stderr/exitCode for byte-identity with CRLF normalization.
Description
The Differential Runner (test/differential/run.ts) is the correctness engine for fauxnix. It provides:
- loadCorpus(path): parses corpus.json into a Corpus (gate definition, shared fixtures, and CorpusCase[]).
- canRunOracle/resolveGitBash/hasPowerShell/oracleSkipReason: determine whether the Git Bash oracle is available (opt-in via FAUXNIX_DIFF_ORACLE + bash.exe found + PowerShell available). Skip-safe on developer machines without Git Bash.
- runCorpus(opts): for each case, creates a fresh pair of file trees (fauxnix dir + bash dir) to prevent cross-engine contamination, cd's fauxnix into its dir, runs the command via a prewarmed FauxnixSession, runs it on Git Bash via runBash (spawnSync with --noprofile --norc -c), and compares with sameIdentity.
- sameIdentity(a, b): CRLF-normalized stdout + CRLF-normalized stderr + exact exitCode equality.
- formatSummary(run): multi-line summary with pass percentage, gate line, and per-mismatch FAIL detail.
- writeTree/runBash/bashEnv/normalizeNewlines: supporting helpers.
The corpus gate is targetCases=200, identity=0.95 (95%), with a knownMismatchIds baseline.
Usage
Imported by the vitest hard-gate test (test/differential.test.ts), the facade variant (test/differential/facade.test.ts), and benchmark scripts. The oracle suite is describe.skipIf(skipOracle)-gated.
Code Reference
Source Location
- Repository: fauxnix
- File: test/differential/run.ts
- Lines: loadCorpus L56-58; canRunOracle L104-106; resolveGitBash L85-92; hasPowerShell L94-101; writeTree L135-141; runBash L155-172; sameIdentity L127-133; formatSummary L180-201; runCorpus L203-260; CORPUS_PATH L54
Signature
export interface CorpusCase { id: string; cmd: string; source?: string; files?: Record<string, string>; }
export interface Corpus {
gate: { targetCases: number; identity: number; knownMismatchIds: string[]; note: string };
files: Record<string, string>;
cases: CorpusCase[];
}
export interface Streams { stdout: string; stderr: string; exitCode: number; }
export interface CaseResult { id: string; cmd: string; identical: boolean; fauxnix: Streams; bash: Streams; error?: string; }
export interface CorpusRun { total: number; identical: number; identity: number; gate: number; bashPath: string; results: CaseResult[]; }
export const CORPUS_PATH: string;
export function loadCorpus(path?: string): Corpus;
export function canRunOracle(env?: NodeJS.ProcessEnv): boolean;
export function resolveGitBash(env?: NodeJS.ProcessEnv): string | null;
export function hasPowerShell(env?: NodeJS.ProcessEnv): boolean;
export function oracleSkipReason(env?: NodeJS.ProcessEnv): string | null;
export function sameIdentity(a: Streams, b: Streams): boolean;
export function writeTree(root: string, files: Record<string, string>): void;
export function runBash(bashPath: string, cwd: string, cmd: string): Streams;
export function formatSummary(run: CorpusRun): string;
export function normalizeNewlines(s: string): string;
export async function runCorpus(opts: { corpus?: Corpus; bashPath: string }): Promise<CorpusRun>;
Import
import {
loadCorpus, canRunOracle, resolveGitBash, runCorpus,
sameIdentity, formatSummary, oracleSkipReason,
} from './differential/run.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| path | string | No (loadCorpus) | Path to corpus.json (default CORPUS_PATH) |
| opts.bashPath | string | Yes (runCorpus) | Git Bash executable path |
| opts.corpus | Corpus | No (runCorpus) | Preloaded corpus (default loadCorpus()) |
Outputs
| Name | Type | Description |
|---|---|---|
| loadCorpus returns | Corpus | Gate + shared files + cases |
| runCorpus returns | CorpusRun | total, identical, identity ratio, per-case results |
| sameIdentity returns | boolean | CRLF-normalized stdout + stderr + exact exitCode match |
Usage Examples
Run the Full Corpus
import { canRunOracle, resolveGitBash, runCorpus, formatSummary } from './differential/run.js';
if (canRunOracle()) {
const run = await runCorpus({ bashPath: resolveGitBash()! });
console.log(formatSummary(run));
// → "differential: 269/270 identical (99.6%) vs C:\...\bash.exe"
}
Compare Two Streams
import { sameIdentity, normalizeNewlines } from './differential/run.js';
const same = sameIdentity(
{ stdout: 'hello\r\n', stderr: '', exitCode: 0 },
{ stdout: 'hello\n', stderr: '', exitCode: 0 },
);
// true — CRLF is normalized before comparison