From 5ec4667a134013f8c52ac4af921d66bca8f46c60 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 26 Oct 2026 16:12:57 +0000 Subject: [PATCH] verify --post-merge: honour commit statuses in the settled and red verdicts settled and red were computed from check runs only while ci.green also counted commit statuses, so a pending status was called settled and a failed status was reported as 'red: ' with no name. Pending statuses now keep the verdict pending; a red status with no failed check run is named as such. The fixture gains a statuses knob to drive both. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- lib/ship-queue-post-merge.ts | 12 +++++++----- test/helpers/ship-queue-train-fixture.ts | 4 +++- test/ship-queue-train-ops.test.ts | 14 +++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/ship-queue-post-merge.ts b/lib/ship-queue-post-merge.ts index 4f2d1edaf2..05a5fc56a8 100644 --- a/lib/ship-queue-post-merge.ts +++ b/lib/ship-queue-post-merge.ts @@ -8,7 +8,9 @@ * until none is still running or the timeout passes, prints one `CHECK:` * line per check, and a `POST_MERGE:` summary that is green only when at * least one check completed and none failed; a neutral or skipped check is - * skipped, never red. Rerun it after an interruption and it continues. + * skipped, never red. Commit statuses count too: a pending status keeps the + * commit pending, a failed one makes it red (named as a commit status when no + * check run failed). Rerun it after an interruption and it continues. */ import { ciAtHead, type QueueContext } from './ship-queue'; import { outFailed, outOk, outPending, type TrainOut } from './ship-queue-train'; @@ -25,17 +27,17 @@ export async function verifyPostMerge(ctx: QueueContext, o: PostMergeOptions): P for (;;) { const ci = ciAtHead(ctx, o.sha); const lines = [`POST_MERGE: ${ci.line.replace(/^(\S+) at ([0-9a-f]+)/, '$2 $1')}`, ...ci.checks.map(c => `CHECK: ${c.name} ${c.status === 'completed' ? c.conclusion ?? 'unknown' : c.status}`)]; - const settled = !ci.checks.some(c => c.status !== 'completed') && !ci.line.startsWith('unknown'); + const settled = !ci.none && !/^(pending|unknown) /.test(ci.line) && !ci.checks.some(c => c.status !== 'completed'); if (settled && ci.green) return outOk(lines, 'none', 'none'); - if (settled && ci.checks.length) { + if (settled) { const red = ci.checks.filter(c => c.status === 'completed' && !['success', 'skipped', 'neutral'].includes(c.conclusion ?? '')).map(c => c.name); - return outFailed({ code: 'QUEUE_POST_MERGE_RED', message: `main's push workflows at ${at} are red: ${red.join(', ')}` }, lines, + return outFailed({ code: 'QUEUE_POST_MERGE_RED', message: `main's push workflows at ${at} are red: ${red.join(', ') || 'a commit status (no check run failed)'}` }, lines, `read the red run, repair on a new PR or roll back; ${Q} train status names the freeze if the backstop filed one`, 'none'); } if (Date.now() >= deadline) { const pending = ci.checks.filter(c => c.status !== 'completed').map(c => c.name); const message = ci.line.startsWith('unknown') ? `the check runs at ${at} are unreadable (${ci.line.replace(/^unknown at [0-9a-f]+ /, '')})` - : ci.checks.length ? `main's push workflows at ${at} have not settled at the timeout: ${pending.join(', ')} still running` : `no check run has attached to ${at} yet`; + : ci.none ? `no check run has attached to ${at} yet` : `main's push workflows at ${at} have not settled at the timeout: ${pending.join(', ') || 'a commit status'} still running`; return outPending({ code: 'QUEUE_TRAIN_PENDING', message }, lines, again, 'none'); } await sleep(o.pollMs); diff --git a/test/helpers/ship-queue-train-fixture.ts b/test/helpers/ship-queue-train-fixture.ts index 5fe17d8a53..04d85ef65d 100644 --- a/test/helpers/ship-queue-train-fixture.ts +++ b/test/helpers/ship-queue-train-fixture.ts @@ -45,6 +45,8 @@ export interface ShimData { repo: string; origin: string; nextId: number; prs: Record; runs: Array>; artifacts: Record>; checks: Record>; ci: Record; rules: Record; artifact: string; log: Array>; + /** Commit statuses (the legacy status API) at a sha, beside the check runs in `ci`. */ + statuses?: Record>; } export interface TrainFixture { repo: FixtureRepo; state: string; dataFile: string; env: Record; read: () => ShimData; write: (fn: (d: ShimData) => void) => void } @@ -202,7 +204,7 @@ function shimSource(): string { " const named = /commits\\/([0-9a-f]+)\\/check-runs\\?check_name=([^&]+)/.exec(a[1] || '');", " if (named) { const list = (d.checks[named[1]] || []).filter(c => c.name === decodeURIComponent(named[2])); out({ total_count: list.length, check_runs: list }); }", " const paged = /commits\\/([0-9a-f]+)\\/(check-runs|status)\\?.*page=(\\d+)/.exec(a[1] || '');", - " if (paged) { const list = paged[2] === 'check-runs' ? (d.ci[paged[1]] || []) : []; const key = paged[2] === 'check-runs' ? 'check_runs' : 'statuses';", + " if (paged) { const list = paged[2] === 'check-runs' ? (d.ci[paged[1]] || []) : ((d.statuses || {})[paged[1]] || []); const key = paged[2] === 'check-runs' ? 'check_runs' : 'statuses';", " out(paged[3] === '1' ? { total_count: list.length, state: 'success', [key]: list } : { total_count: list.length, [key]: [] }); }", "}", "fail('gh shim: unsupported ' + a.join(' '));", diff --git a/test/ship-queue-train-ops.test.ts b/test/ship-queue-train-ops.test.ts index 122f6cdc16..d82bc5f4ca 100644 --- a/test/ship-queue-train-ops.test.ts +++ b/test/ship-queue-train-ops.test.ts @@ -313,8 +313,8 @@ describe('train prune --stale and train watch', () => { describe('verify --post-merge', () => { // Value: protects=after a train merges, the coordinator watches main's push workflows at the merged sha until they settle instead of a background gh chain a restart kills (GBrain practice 8); - // fails_when=a pending check is called settled, a red check is called green, or the command needs process state; why_new=no post-merge watch existed; seam=the gh shim's check runs at a sha; no_claim=which workflows main runs - test('waits for every check run at the sha to complete, prints each, is green only when none failed, red with the failed names, and resumable after a timeout', () => { + // fails_when=a pending check is called settled, a red check is called green, a pending or failed commit status (the legacy status API, which ciAtHead counts) is reported as red with no name or as green, or the command needs process state; why_new=no post-merge watch existed; seam=the gh shim's check runs and commit statuses at a sha; no_claim=which workflows main runs + test('waits for every check run at the sha to complete, prints each, is green only when none failed, red with the failed names, pending or red on a commit status, and resumable after a timeout', () => { const fx = make(); const sha = fx.repo.git('rev-parse', 'HEAD'); fx.write(d => { d.ci[sha] = [{ name: 'free-tests', status: 'completed', conclusion: 'success' }, { name: 'windows-free-tests', status: 'in_progress', conclusion: null }, { name: 'main-backstop', status: 'completed', conclusion: 'neutral' }]; }); @@ -337,7 +337,15 @@ describe('verify --post-merge', () => { expect(line(green.out, 'POST_MERGE:')).toBe(`POST_MERGE: ${sha.slice(0, 12)} green (passed=2 failed=0 pending=0 skipped=1)`); expect(green.out.split('\n').filter(l => l.startsWith('CHECK: ')).sort()).toEqual(['CHECK: free-tests success', 'CHECK: main-backstop neutral', 'CHECK: windows-free-tests success']); expect(next(green.out)).toBe('NEXT: none'); - fx.write(d => { d.ci[sha] = []; }); + fx.write(d => { d.statuses = { [sha]: [{ state: 'pending', context: 'ci/vendor' }] }; }); + const statusPending = queue(fx, ['verify', '--post-merge', sha, '--timeout', '1']); + expect([statusPending.status, line(statusPending.out, 'POST_MERGE:')]).toEqual([EXIT.refused, `POST_MERGE: ${sha.slice(0, 12)} pending (passed=2 failed=0 pending=1 skipped=1)`]); + expect(statusPending.err).toMatch(/have not settled at the timeout: a commit status still running.*\(QUEUE_TRAIN_PENDING\)/); + fx.write(d => { d.statuses = { [sha]: [{ state: 'failure', context: 'ci/vendor' }] }; }); + const statusRed = queue(fx, ['verify', '--post-merge', sha, '--timeout', '1']); + expect([statusRed.status, line(statusRed.out, 'POST_MERGE:')]).toEqual([EXIT.fail, `POST_MERGE: ${sha.slice(0, 12)} red (passed=2 failed=1 pending=0 skipped=1)`]); + expect(statusRed.err).toMatch(/are red: a commit status \(no check run failed\).*\(QUEUE_POST_MERGE_RED\)/); + fx.write(d => { d.statuses = {}; d.ci[sha] = []; }); const none = queue(fx, ['verify', '--post-merge', sha, '--timeout', '1']); expect([none.status, line(none.out, 'POST_MERGE:')]).toEqual([EXIT.refused, `POST_MERGE: ${sha.slice(0, 12)} none (passed=0 failed=0 pending=0 skipped=0)`]); expect(none.err).toMatch(new RegExp(`no check run has attached to ${sha.slice(0, 12)} yet.*\\(QUEUE_TRAIN_PENDING\\)`));