diff --git a/build/shared/landing.mts b/build/shared/landing.mts index d32032f45..2017880fb 100644 --- a/build/shared/landing.mts +++ b/build/shared/landing.mts @@ -97,6 +97,7 @@ export type CheckRun = { status: string; conclusion: string | null; detailsUrl?: string; + startedAt?: string; }; /** What GitHub reports about one commit status, which is the older kind. */ @@ -130,7 +131,18 @@ export function checksVerdict( (ownRunId !== '' && (run.detailsUrl ?? '').includes(`/actions/runs/${ownRunId}/`)) || (ownCheckName !== '' && run.name === ownCheckName); - const runs = all.filter((run) => !isOwn(run)); + // A workflow that cancels superseded runs leaves the cancelled one on the + // commit beside the run that replaced it. Both carry the same name, and + // only the newest says how that check turned out. + const newest = new Map(); + for (const run of all.filter((run) => !isOwn(run))) { + const seen = newest.get(run.name); + if (seen === undefined || (run.startedAt ?? '') >= (seen.startedAt ?? '')) { + newest.set(run.name, run); + } + } + + const runs = [...newest.values()]; const pending = [ ...runs.filter((run) => run.status !== 'completed').map((run) => run.name), ...statuses diff --git a/build/shared/landing.test.mts b/build/shared/landing.test.mts index dbed9cd3c..e1fb0d25e 100644 --- a/build/shared/landing.test.mts +++ b/build/shared/landing.test.mts @@ -188,10 +188,45 @@ describe('checksVerdict', () => { conclusion, }); + const at = ( + name: string, + conclusion: string | null, + startedAt: string, + status = 'completed' + ) => ({ name, conclusion, startedAt, status }); + test('says nothing when everything passed', () => { deepStrictEqual(checksVerdict([run('Lint and test', 'success')], []), ''); }); + test('reads only the newest run of a check', () => { + // A workflow that cancels superseded runs leaves the cancelled one on the + // commit beside the run that replaced it. + deepStrictEqual( + checksVerdict( + [ + at('Title and description', 'cancelled', '2026-08-24T02:03:54Z'), + at('Title and description', 'success', '2026-08-24T02:03:58Z'), + ], + [] + ), + '' + ); + }); + + test('still reports a check whose newest run failed', () => { + match( + checksVerdict( + [ + at('Lint and test', 'success', '2026-08-24T02:00:00Z'), + at('Lint and test', 'failure', '2026-08-24T02:10:00Z'), + ], + [] + ), + /did not pass: Lint and test/ + ); + }); + test('counts anything still running against it', () => { // A label applied while a check was in flight says nothing about how that // check turned out. diff --git a/build/tasks/land-pull-request.mts b/build/tasks/land-pull-request.mts index 92f3479ce..b1d77a93a 100644 --- a/build/tasks/land-pull-request.mts +++ b/build/tasks/land-pull-request.mts @@ -146,7 +146,7 @@ const checksRefuse = (sha: string) => 'api', `repos/${repository()}/commits/${sha}/check-runs`, '--jq', - '[.check_runs[] | {name, status, conclusion, detailsUrl: .details_url}]' + '[.check_runs[] | {name, status, conclusion, detailsUrl: .details_url, startedAt: .started_at}]' ) ), JSON.parse(