From c9bea1fc8141904540d4bc23fbace90be9f37fca Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Mon, 24 Aug 2026 02:20:39 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=F0=9F=94=A7=EF=BC=9Aread?= =?UTF-8?q?=20only=20the=20newest=20run=20of=20a=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A pull request whose description is edited twice leaves two runs of the policy workflow on the same commit: the one that was cancelled for being superseded, and the one that replaced it. Both carry the same name, and the queue counted the cancelled one, so a passing check read as a failed one and the label could not land the branch. It now keeps the newest run of each name, which is the run GitHub itself reports beside the pull request. Signed-off-by: Derek Lewis Assisted-by: Claude-Code:claude-opus-5 --- build/shared/landing.mts | 14 ++++++++++++- build/shared/landing.test.mts | 35 +++++++++++++++++++++++++++++++ build/tasks/land-pull-request.mts | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) 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(