@@ -509,39 +509,9 @@ if (args[0] === "api" && args[1] === "--help") {
509509 ) ;
510510} ) ;
511511
512- describe ( "committed CI timing loader" , ( ) => {
513- afterEach ( ( ) => {
514- vi . restoreAllMocks ( ) ;
515- syncBuiltinESMExports ( ) ;
516- vi . unstubAllEnvs ( ) ;
517- vi . resetModules ( ) ;
518- } ) ;
519-
520- async function readTimings ( contents : string | Error ) {
521- vi . resetModules ( ) ;
522- vi . stubEnv ( "OPENCLAW_CI_TEST_TIMINGS" , undefined ) ;
523- const original = fs . readFileSync ;
524- const timingPath = fileURLToPath ( new URL ( "../../config/ci-test-timings.json" , import . meta. url ) ) ;
525- const read = vi . spyOn ( fs , "readFileSync" ) . mockImplementation ( ( file , options ) => {
526- if ( ( file instanceof URL ? fileURLToPath ( file ) : file ) === timingPath ) {
527- if ( contents instanceof Error ) {
528- throw contents ;
529- }
530- return contents ;
531- }
532- return original ( file , options ) ;
533- } ) ;
534- syncBuiltinESMExports ( ) ;
535- const loader = await import ( "../../scripts/lib/ci-test-timings.mts" ) ;
536- return { loader, read, timingPath } ;
537- }
538-
539- const invalidFiles : Array < [ string , string | Error ] > = [
540- [ "missing" , new Error ( "ENOENT" ) ] ,
541- [ "unreadable" , new Error ( "EACCES" ) ] ,
542- [ "truncated" , '{"version":1' ] ,
512+ describe ( "CI timing schema" , ( ) => {
513+ const invalidTimings : Array < [ string , string ] > = [
543514 [ "non-object root" , "null" ] ,
544- [ "wrong version" , JSON . stringify ( { ...baseline , version : 2 } ) ] ,
545515 [ "unknown root key" , JSON . stringify ( { ...baseline , extra : 1 } ) ] ,
546516 [ "empty source" , JSON . stringify ( { ...baseline , source : "" } ) ] ,
547517 ...[ "2026-02-29" , "1900-02-29" , "2026-04-31" , "2026-8-22" , "2026-08-22T00:00:00Z" ] . map (
@@ -595,26 +565,64 @@ describe("committed CI timing loader", () => {
595565 [ "non-finite overhead" , JSON . stringify ( baseline ) . replace ( ":0.6" , ":1e999" ) ] ,
596566 ] ;
597567
598- it . each ( invalidFiles ) ( "ignores the entire %s file without throwing" , async ( _name , contents ) => {
599- const { loader } = await readTimings ( contents ) ;
600- expect ( loader . readUiE2eFileTimings ( ) ) . toEqual ( { fileSeconds : { } , perFileOverheadSeconds : 0 } ) ;
601- expect ( loader . readCompactGroupTimings ( "blacksmith" ) ) . toEqual ( { } ) ;
602- expect ( loader . readCompactGroupTimings ( "github" ) ) . toEqual ( { } ) ;
568+ it . each ( invalidTimings ) ( "rejects %s" , ( _name , contents ) => {
569+ expect ( ( ) => ciTestTimingsSchema . parse ( JSON . parse ( contents ) ) ) . toThrow (
570+ "Invalid CI test timings" ,
571+ ) ;
603572 } ) ;
604573
605- it . each ( [ 0 , 5 ] ) (
606- "accepts overhead boundary %s, safe integers and leap dates" ,
607- async ( overhead ) => {
608- const data = {
609- ...baseline ,
610- updatedAt : "2000-02-29" ,
611- uiE2e : {
612- fileSeconds : { [ measuredFile ] : Number . MAX_SAFE_INTEGER } ,
613- perFileOverheadSeconds : overhead ,
614- } ,
615- } ;
616- const { loader } = await readTimings ( JSON . stringify ( data ) ) ;
617- expect ( loader . readUiE2eFileTimings ( ) ) . toEqual ( data . uiE2e ) ;
574+ it . each ( [ 0 , 5 ] ) ( "accepts overhead boundary %s, safe integers and leap dates" , ( overhead ) => {
575+ const data = {
576+ ...baseline ,
577+ updatedAt : "2000-02-29" ,
578+ uiE2e : {
579+ fileSeconds : { [ measuredFile ] : Number . MAX_SAFE_INTEGER } ,
580+ perFileOverheadSeconds : overhead ,
581+ } ,
582+ } ;
583+ expect ( ciTestTimingsSchema . parse ( data ) ) . toEqual ( data ) ;
584+ } ) ;
585+ } ) ;
586+
587+ describe ( "committed CI timing loader" , ( ) => {
588+ afterEach ( ( ) => {
589+ vi . restoreAllMocks ( ) ;
590+ syncBuiltinESMExports ( ) ;
591+ vi . unstubAllEnvs ( ) ;
592+ vi . resetModules ( ) ;
593+ } ) ;
594+
595+ async function readTimings ( contents : string | Error ) {
596+ vi . resetModules ( ) ;
597+ vi . stubEnv ( "OPENCLAW_CI_TEST_TIMINGS" , undefined ) ;
598+ const original = fs . readFileSync ;
599+ const timingPath = fileURLToPath ( new URL ( "../../config/ci-test-timings.json" , import . meta. url ) ) ;
600+ const read = vi . spyOn ( fs , "readFileSync" ) . mockImplementation ( ( file , options ) => {
601+ if ( ( file instanceof URL ? fileURLToPath ( file ) : file ) === timingPath ) {
602+ if ( contents instanceof Error ) {
603+ throw contents ;
604+ }
605+ return contents ;
606+ }
607+ return original ( file , options ) ;
608+ } ) ;
609+ syncBuiltinESMExports ( ) ;
610+ const loader = await import ( "../../scripts/lib/ci-test-timings.mts" ) ;
611+ return { loader, read, timingPath } ;
612+ }
613+
614+ it . each ( [
615+ [ "missing" , new Error ( "ENOENT" ) ] ,
616+ [ "unreadable" , new Error ( "EACCES" ) ] ,
617+ [ "truncated" , '{"version":1' ] ,
618+ [ "wrong version" , JSON . stringify ( { ...baseline , version : 2 } ) ] ,
619+ ] satisfies Array < [ string , string | Error ] > ) (
620+ "ignores the entire %s file without throwing" ,
621+ async ( _name , contents ) => {
622+ const { loader } = await readTimings ( contents ) ;
623+ expect ( loader . readUiE2eFileTimings ( ) ) . toEqual ( { fileSeconds : { } , perFileOverheadSeconds : 0 } ) ;
624+ expect ( loader . readCompactGroupTimings ( "blacksmith" ) ) . toEqual ( { } ) ;
625+ expect ( loader . readCompactGroupTimings ( "github" ) ) . toEqual ( { } ) ;
618626 } ,
619627 ) ;
620628
0 commit comments