Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132/** Shared run-plan for the property-based fuzz tests. The same `*.property.unit.test.ts` files serve two layers. Run by the normal unit suite (env unset), each property does a bounded number of runs so the suite stays fast and deterministic in wall-clock. Run as the `fuzz` campaign (env set to a per-property millisecond budget), each property runs effectively unbounded until its time budget elapses, so the campaign explores far deeper without a second copy of the arbitraries. The seed is left random in both layers (so coverage broadens across runs); a discovered counterexample is reproduced from the seed fast-check prints and then pinned as a fast-check `examples` entry on the offending property. @module */
/** Environment variable naming the per-property campaign time budget in milliseconds. Unset (or non-positive) selects bounded mode; a positive integer selects campaign mode with that per-property budget. */const FUZZ_BUDGET_ENV_NAME = 'FILE_ENFORCER_FUZZ_BUDGET_MS';
/** Runs per property in bounded mode. High enough to explore each branch space, low enough that a file's properties stay well under the timeout. */const BOUNDED_NUM_RUNS = 300;
/** Per-property timeout in bounded mode. A property runs its body {@link BOUNDED_NUM_RUNS} times, so it needs a wider budget than a single assertion even though each run is sub-millisecond. */const BOUNDED_TIMEOUT_MS = 30_000;
/** Extra time added to a campaign property's budget before the harness timeout fires, leaving room for fast-check to interrupt and shrink. */const CAMPAIGN_TIMEOUT_MARGIN_MS = 30_000;
/** fast-check `Parameters` subset shared by both layers, structurally assignable to `assert`'s options argument. */type FuzzRunParams = { readonly interruptAfterTimeLimit?: number; readonly markInterruptAsFailure?: boolean; readonly numRuns: number;};
/** Resolved plan for one property: the options to hand `assert` and the harness timeout to set on the enclosing `it`. */export type FuzzRunPlan = { readonly params: FuzzRunParams; readonly timeout: number;};
/** Sentinel budget meaning bounded mode; a real campaign budget is always positive, so zero is an unambiguous non-nullish marker for "unset". */const BOUNDED_BUDGET = 0;
/** Parses the campaign budget from the {@link FUZZ_BUDGET_ENV_NAME} environment variable. @returns Positive millisecond budget, or {@link BOUNDED_BUDGET} for bounded mode. @example ```ts const budget = campaignBudgetMs(); ``` */function campaignBudgetMs(): number { /** Raw budget string from the environment, if present. */ const raw = process.env[FUZZ_BUDGET_ENV_NAME]; if ((raw === undefined) || (raw === '')) return BOUNDED_BUDGET; /** Numeric budget parsed from the raw string. */ const parsed = Number(raw,); if (!Number.isInteger(parsed,)) return BOUNDED_BUDGET; if (parsed <= 0) return BOUNDED_BUDGET; return parsed;}
/** Resolves the run plan from the environment via {@link campaignBudgetMs}. Call once per file and reuse across that file's properties. @returns Bounded plan when the campaign budget is unset, otherwise a time-budgeted campaign plan with {@link CAMPAIGN_TIMEOUT_MARGIN_MS} added to the harness timeout. @example ```ts const run = fuzzRunPlan(); await assert(asyncProperty(arb, predicate,), run.params,); ``` */export function fuzzRunPlan(): FuzzRunPlan { /** Campaign budget, or {@link BOUNDED_BUDGET} in bounded mode. */ const budget = campaignBudgetMs(); if (budget === BOUNDED_BUDGET) { return { params: { numRuns: BOUNDED_NUM_RUNS, }, timeout: BOUNDED_TIMEOUT_MS, }; } return { params: { numRuns: Number.MAX_SAFE_INTEGER, interruptAfterTimeLimit: budget, markInterruptAsFailure: false, }, timeout: budget + CAMPAIGN_TIMEOUT_MARGIN_MS, };}