@@ -509,4 +509,59 @@ if (endpoint.includes("actions/workflows/ci.yml/runs?")) {
509509 rmSync ( fixtureDir , { force : true , recursive : true } ) ;
510510 }
511511 } ) ;
512+ it ( "excludes manual, failed, and unfinished runs from recent main timings" , ( ) => {
513+ const fixtureDir = mkdtempSync ( path . join ( tmpdir ( ) , "openclaw-ci-timings-recent-" ) ) ;
514+ const fakeGhPath = path . join ( fixtureDir , "gh" ) ;
515+ const callsPath = path . join ( fixtureDir , "calls.jsonl" ) ;
516+ writeFileSync (
517+ fakeGhPath ,
518+ `#!/usr/bin/env node
519+ const { appendFileSync } = require("node:fs");
520+ const args = process.argv.slice(2);
521+ appendFileSync(process.env.FIXTURE_CALLS_PATH, JSON.stringify(args) + "\\n");
522+ if (args[0] === "run" && args[1] === "list") {
523+ console.log(JSON.stringify([
524+ { databaseId: 201, event: "workflow_dispatch", headSha: "manual", status: "completed", conclusion: "success" },
525+ { databaseId: 202, event: "push", headSha: "failed", status: "completed", conclusion: "failure" },
526+ { databaseId: 203, event: "push", headSha: "running", status: "in_progress", conclusion: "" },
527+ { databaseId: 204, event: "push", headSha: "first", status: "completed", conclusion: "success" },
528+ { databaseId: 205, event: "push", headSha: "second", status: "completed", conclusion: "success" }
529+ ]));
530+ } else if (args[0] === "run" && args[1] === "view") {
531+ console.log(JSON.stringify({ status: "completed", conclusion: "success", createdAt: "2026-08-31T00:00:00Z", updatedAt: "2026-08-31T00:01:00Z" }));
532+ } else if (args[0] === "api" && args.some((arg) => arg.includes("/jobs?"))) {
533+ console.log(JSON.stringify({ total_count: 1, jobs: [{ id: 1, name: "checks", status: "completed", conclusion: "success", started_at: "2026-08-31T00:00:10Z", completed_at: "2026-08-31T00:00:40Z" }] }));
534+ } else {
535+ process.exit(2);
536+ }
537+ ` ,
538+ ) ;
539+ chmodSync ( fakeGhPath , 0o755 ) ;
540+ try {
541+ const result = spawnSync ( process . execPath , [ "scripts/ci-run-timings.mjs" , "--recent" , "2" ] , {
542+ cwd : path . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , "../.." ) ,
543+ encoding : "utf8" ,
544+ env : {
545+ ...process . env ,
546+ GH_TOKEN : "fixture-token" ,
547+ OPENCLAW_GH_BIN : fakeGhPath ,
548+ FIXTURE_CALLS_PATH : callsPath ,
549+ } ,
550+ } ) ;
551+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
552+ expect ( result . stdout . match ( / C I r u n \d + / gu) ) . toEqual ( [ "CI run 204" , "CI run 205" ] ) ;
553+ const calls : string [ ] [ ] = readFileSync ( callsPath , "utf8" )
554+ . trim ( )
555+ . split ( "\n" )
556+ . map ( ( line ) => JSON . parse ( line ) ) ;
557+ expect ( calls [ 0 ] ?. slice ( calls [ 0 ] . indexOf ( "--event" ) , calls [ 0 ] . indexOf ( "--event" ) + 2 ) ) . toEqual (
558+ [ "--event" , "push" ] ,
559+ ) ;
560+ expect (
561+ calls . filter ( ( args ) => args [ 0 ] === "run" && args [ 1 ] === "view" ) . map ( ( args ) => args [ 2 ] ) ,
562+ ) . toEqual ( [ "204" , "205" ] ) ;
563+ } finally {
564+ rmSync ( fixtureDir , { force : true , recursive : true } ) ;
565+ }
566+ } ) ;
512567} ) ;
0 commit comments