11// Unit-lane replay of the parser fuzz regression corpus (#1414).
22//
3- // The nightly lane finds cases; this replays every case it ever found, in-process and
4- // without a watchdog, so a regression fails in seconds on a PR instead of a night later.
5- // Cases run synchronously here on purpose : a corpus case that hangs would hang the unit
6- // suite, which is exactly the signal ( the nightly lane is where hangs are diagnosed) .
3+ // The nightly lane finds cases; this replays every case it ever found so a regression fails in
4+ // seconds on a PR instead of a night later. Cases go through the same worker-backed watchdog the
5+ // nightly lane uses : a promoted hang case must fail this test against its per-case budget, not
6+ // wedge the unit job until the CI timeout .
77
88import fc from 'fast-check' ;
9- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
9+ import { describe , expect , it } from 'vitest' ;
1010import { arbitraryForTarget } from './arbitraries.ts' ;
1111import { readCorpus } from './corpus.ts' ;
12- import { checkCase } from './invariant.ts' ;
12+ import { runCases } from './execute.ts' ;
13+ import { describeFailure } from './invariant.ts' ;
1314import { getFuzzTarget } from './registry.ts' ;
1415import { FUZZ_TARGETS } from './targets.ts' ;
1516
17+ /**
18+ * Generous enough that a loaded CI runner never reports a healthy parser as hung, small enough
19+ * that a genuinely wedged case fails the file in seconds.
20+ */
21+ const CASE_TIMEOUT_MS = 5_000 ;
22+
1623describe ( 'parser fuzz regression corpus' , ( ) => {
1724 const corpus = readCorpus ( ) ;
1825
19- // The batch-steps parser warns on deprecated step shapes; replaying those cases would
20- // print one warning line per case into the unit-suite output.
21- beforeEach ( ( ) => void vi . spyOn ( process . stderr , 'write' ) . mockReturnValue ( true ) ) ;
22- afterEach ( ( ) => void vi . restoreAllMocks ( ) ) ;
23-
2426 it ( 'is non-empty and free of duplicates' , ( ) => {
2527 expect ( corpus . length ) . toBeGreaterThan ( 0 ) ;
2628 const keys = corpus . map ( ( entry ) => `${ entry . target } \u0000${ entry . input } ` ) ;
@@ -35,17 +37,17 @@ describe('parser fuzz regression corpus', () => {
3537 }
3638 } ) ;
3739
38- it . each ( corpus . map ( ( entry , index ) => [ index , entry ] as const ) ) (
39- 'case %i holds the typed-AppError invariant' ,
40- ( _index , entry ) => {
41- expect ( checkCase ( getFuzzTarget ( entry . target ) , entry . input ) ) . toBeNull ( ) ;
42- } ,
43- ) ;
44-
40+ // One worker per target rather than per case: startup is the only real cost here, and the
41+ // watchdog budget is per case either way.
4542 it . each ( FUZZ_TARGETS . map ( ( target ) => [ target . name , target ] as const ) ) (
46- '%s seeds hold the invariant' ,
47- ( _name , target ) => {
48- for ( const seed of target . seeds ) expect ( checkCase ( target , seed ) ) . toBeNull ( ) ;
43+ '%s corpus cases and seeds hold the invariant, under the watchdog' ,
44+ async ( name , target ) => {
45+ const cases = [
46+ ...target . seeds ,
47+ ...corpus . filter ( ( entry ) => entry . target === name ) . map ( ( entry ) => entry . input ) ,
48+ ] ;
49+ const failures = await runCases ( target , cases , CASE_TIMEOUT_MS ) ;
50+ expect ( failures . map ( describeFailure ) ) . toEqual ( [ ] ) ;
4951 } ,
5052 ) ;
5153} ) ;
@@ -59,10 +61,10 @@ describe('fuzz case generation', () => {
5961 expect ( sample ( 7 ) ) . not . toEqual ( sample ( 8 ) ) ;
6062 } ) ;
6163
62- it ( 'generates strings the target can be fed directly' , ( ) => {
63- for ( const input of fc . sample ( arbitraryForTarget ( target ) , { numRuns : 64 , seed : 1 } ) ) {
64- expect ( typeof input ) . toBe ( 'string' ) ;
65- expect ( checkCase ( target , input ) ) . toBeNull ( ) ;
66- }
64+ it ( 'generates strings the target can be fed directly' , async ( ) => {
65+ const inputs = fc . sample ( arbitraryForTarget ( target ) , { numRuns : 64 , seed : 1 } ) ;
66+ expect ( inputs . every ( ( input ) => typeof input === 'string' ) ) . toBe ( true ) ;
67+ const failures = await runCases ( target , inputs , CASE_TIMEOUT_MS ) ;
68+ expect ( failures . map ( describeFailure ) ) . toEqual ( [ ] ) ;
6769 } ) ;
6870} ) ;
0 commit comments