Skip to content

Commit f421b6a

Browse files
committed
test(fuzz): resolve validation generators in the run path so corpus replay keeps its small module graph
1 parent cd73644 commit f421b6a

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

‎scripts/fuzz/arbitraries.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import fc from 'fast-check';
1111
import { replayScriptArb } from '../../src/__tests__/test-utils/property-arbitraries.ts';
1212
import type { FuzzTarget, FuzzTargetName } from './target-types.ts';
13-
import { cliValidationArb, maestroValidationArb } from './validation-arbitraries.ts';
1413

1514
const SELECTOR_VALUE_HAZARDS = [
1615
'',
@@ -183,20 +182,8 @@ const STRUCTURED_BASES: Partial<Record<FuzzTargetName, fc.Arbitrary<string>>> =
183182
'batch-steps': fc.json({ maxDepth: 3 }),
184183
};
185184

186-
/**
187-
* Validation targets generate their own expectation-carrying envelopes (#1781 B2); splicing
188-
* hazards into the envelope JSON would corrupt the envelope, not the payload, so they are
189-
* exempt from the corruption/noise mix. Payload-level hostility lives inside their generators.
190-
*/
191-
const VALIDATION_ARBITRARIES: Partial<Record<FuzzTargetName, fc.Arbitrary<string>>> = {
192-
'cli-validation': cliValidationArb,
193-
'maestro-validation': maestroValidationArb,
194-
};
195-
196185
/** The case distribution for one target: mostly near-miss, some valid, some pure noise. */
197186
export function arbitraryForTarget(target: FuzzTarget): fc.Arbitrary<string> {
198-
const validation = VALIDATION_ARBITRARIES[target.name];
199-
if (validation !== undefined) return validation;
200187
const seeded = fc.constantFrom(...target.seeds);
201188
const structured = STRUCTURED_BASES[target.name];
202189
const base = structured === undefined ? seeded : fc.oneof(seeded, structured);

‎scripts/fuzz/generate.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import fc from 'fast-check';
99
import { arbitraryForTarget } from './arbitraries.ts';
10+
import { validationArbitraryFor } from './validation-arbitraries.ts';
1011
import { type CaseRunner, createCaseRunner } from './execute.ts';
1112
import type { FuzzFailure } from './invariant.ts';
1213
import type { FuzzTarget } from './target-types.ts';
@@ -68,6 +69,16 @@ export async function generateAndCheck(
6869
}
6970
}
7071

72+
/**
73+
* Validation targets carry their own expectation-encoding generators; splicing hazards into an
74+
* envelope would corrupt the envelope rather than the payload. They are resolved here rather
75+
* than inside `arbitraryForTarget` so the corpus-replay unit file — which only ever samples the
76+
* classic targets — does not pull the CLI schema registry into its instrumented worker (#1824).
77+
*/
78+
function casesFor(target: FuzzTarget): fc.Arbitrary<string> {
79+
return validationArbitraryFor(target.name) ?? arbitraryForTarget(target);
80+
}
81+
7182
/** The generated half of a run: fast-check picks the inputs and shrinks any counterexample. */
7283
async function checkGenerated(
7384
target: FuzzTarget,
@@ -76,7 +87,7 @@ async function checkGenerated(
7687
): Promise<GeneratedRun> {
7788
let cases = target.seeds.length;
7889
const details = await fc.check(
79-
fc.asyncProperty(arbitraryForTarget(target), async (input) => {
90+
fc.asyncProperty(casesFor(target), async (input) => {
8091
cases += 1;
8192
return (await runner.run(input)) === null;
8293
}),

‎scripts/fuzz/validation-arbitraries.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type FlagDefinition,
1818
} from '../../src/cli-schema/command-schema.ts';
1919
import { isFlagSupportedForCommand } from '../../src/cli-schema/option-schema.ts';
20+
import type { FuzzTargetName } from './target-types.ts';
2021
import { encodeValidationCase, type ValidationCase } from './validation-case.ts';
2122

2223
const REJECT = { outcome: 'reject', code: 'INVALID_ARGS' } as const;
@@ -460,3 +461,10 @@ export const maestroValidationArb: fc.Arbitrary<string> = fc
460461
expect: REJECT,
461462
});
462463
});
464+
465+
/** The generator for a validation target, or `undefined` for the classic targets. */
466+
export function validationArbitraryFor(target: FuzzTargetName): fc.Arbitrary<string> | undefined {
467+
if (target === 'cli-validation') return cliValidationArb;
468+
if (target === 'maestro-validation') return maestroValidationArb;
469+
return undefined;
470+
}

0 commit comments

Comments
 (0)