diff --git a/changelog.d/fix-ci-reuse-neutral-run-caller-head.md b/changelog.d/fix-ci-reuse-neutral-run-caller-head.md new file mode 100644 index 000000000..3c8a40f97 --- /dev/null +++ b/changelog.d/fix-ci-reuse-neutral-run-caller-head.md @@ -0,0 +1 @@ +**A neutral CI run no longer blocks reuse of a passing run on the same commit, and a reusable-workflow lane clears only from a caller run at your exact commit.** A newer run that concluded `neutral` is now passed over like a skipped one by `gstack-pregate` and `gstack-ci-carry wait`; a newer failed, cancelled, timed-out or unfinished run still blocks reuse. `gstack-pregate clear --remote --run-url` on a lane that only runs through `workflow_call` now takes a caller run only when it tested your exact commit. A run of another commit (`head_mismatch`), a pull request run that tested GitHub's merge with the base (`merge_tested`) or a commit whose files differ from what pregate recorded (`tree_mismatch`) is refused, so an old or merged green caller run can't clear today's code. A run of the lane's own workflow is checked as before. Regression tests replay gbrain's real runs at 435e38c5, where a skipped pull request run had blocked a passing manual run. diff --git a/docs/pregate.md b/docs/pregate.md index 93b4e0545..70d8c2fed 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -929,8 +929,8 @@ once: attempt meanwhile is `run_changed`. A newer run of the same workflow on the head, of any event, vetoes it (`newer_run_vetoes`) when that run failed, was cancelled or is still running. A newer green run doesn't, and neither does a - newer skipped run, which ran no job and so says nothing about the tree - (GST-3514). + newer skipped or neutral run, which ran no job that could fail and so says + nothing about the tree (GST-3514, GST-3554). - Every job the profile names appears exactly once in that attempt and succeeded. Jobs and runs are read across every page. - `tree.json` (an artifact of at most 8 MiB) names this run, attempt, event and @@ -1055,7 +1055,11 @@ of a caller: a workflow in the branch's own `.github/workflows/` with a job that says `uses: ./.github/workflows/.yml` (GST-971), read at pregate.json's recorded tree, as long as the lane's own job succeeded in the run under that calling job (` / `); else it refuses -with `caller_job_skipped`. Fix lines only suggest `gh workflow run` for +with `caller_job_skipped`. A caller run counts only when it tested +pregate.json's own head and tree (GST-3554): a run of another commit refuses +with `head_mismatch`, a `pull_request` run (which tested GitHub's merge of the +head with its base) with `merge_tested`, and a head whose tree is not +pregate.json's tree with `tree_mismatch`. Fix lines only suggest `gh workflow run` for a file with a `workflow_dispatch` trigger. The run must also have finished green (GSTA-203 PR 8): a run that is still queued or running diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 990ddb921..384cd1d6d 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -5053,7 +5053,10 @@ line; after the last three, clear again with a finished green run of the lane's own workflow ([run evidence](pregate.md#run-evidence)). For a lane whose workflow runs only through `workflow_call`, a run of a workflow whose job says `uses: ./.github/workflows/.yml` counts as a run of the lane (GST-971); -it refuses `caller_job_skipped` when its ` / ` job did not succeed. +it refuses `caller_job_skipped` when its ` / ` job did not succeed, +`head_mismatch` when the caller run ran at a commit other than pregate.json's head, +`merge_tested` when it is a `pull_request` run, and `tree_mismatch` when the head's tree +is not pregate.json's tree (GST-3554): dispatch the caller at the head and clear with that run. Another tree is accepted in exactly one case: it differs from `pregate.json`'s tree only in the repo's stamp rule (`.gstack/ship-policy.json` on the base diff --git a/lib/ci-carry.ts b/lib/ci-carry.ts index a548fdb5d..98348bbcf 100644 --- a/lib/ci-carry.ts +++ b/lib/ci-carry.ts @@ -176,7 +176,7 @@ export async function waitForRun(deps: RunDeps, o: { workflow: string; events: s const end = o.clock() + o.timeoutMs; for (;;) { const runs = [o.head, ...(o.also ?? [])].flatMap(h => deps.runsForHead(o.workflow, h)).filter(r => o.events.includes(r.event)).sort(newestFirst); - const newest = runs.find(r => !(r.status === 'completed' && r.conclusion === 'skipped')) ?? runs[0]; + const newest = runs.find(r => !(r.status === 'completed' && (r.conclusion === 'skipped' || r.conclusion === 'neutral'))) ?? runs[0]; if (newest?.status === 'completed') { if (newest.conclusion === 'success') return { state: 'green', run: newest }; const failing = deps.jobs(newest.id, newest.run_attempt).filter(j => !PASSING.includes(j.conclusion ?? '')).map(j => j.name); diff --git a/lib/pregate/index.ts b/lib/pregate/index.ts index dce9d4c02..72517b092 100644 --- a/lib/pregate/index.ts +++ b/lib/pregate/index.ts @@ -371,6 +371,14 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput return invalid(`workflow_mismatch — run ${id} attempt ${run?.run_attempt ?? '?'} ran ${run?.path ?? 'an unknown workflow'}, not ${want}${callers.length ? ` or a workflow that calls it (${names})` : ''}`, `clear ${lane} with a run of its own workflow${callers.length ? ` or of a workflow that calls it (${names})` : ''}: ${start}, then gstack-pregate clear --remote ${lane} --run-url `); } const runOf = caller ?? { file: target.workflow, dispatch }; + if (caller) { + const at = `run ${id} attempt ${run.run_attempt} of ${caller.file}`; + const fresh = `${caller.dispatch ? `gh workflow run ${caller.file} --ref ` : `push a commit that starts ${caller.file}`} at ${file.head ? file.head.slice(0, 12) : 'the head'}, then gstack-pregate clear --remote ${lane} --run-url `; + if (run.head_sha !== file.head) return invalid(`head_mismatch — ${at} ran at ${(run.head_sha ?? '').slice(0, 12)}, not pregate.json's head ${file.head ? file.head.slice(0, 12) : '(none recorded)'}, and a caller run clears ${target.workflow} only at that exact head`, file.head ? fresh : `rerun gstack-pregate at the head, then ${fresh}`); + if (run.event === 'pull_request') return invalid(`merge_tested — ${at} is a pull_request run, which tested GitHub's merge of the head with its base, not the head itself`, fresh); + const tested = git(repoRoot, ['rev-parse', `${run.head_sha}^{tree}`]); + if (tested !== file.tree) return invalid(`tree_mismatch — ${at} tested tree ${(tested ?? 'unreadable').slice(0, 12)} at its head, not pregate.json's tree ${file.tree.slice(0, 12)}`, `commit what pregate.json recorded, rerun gstack-pregate, then ${fresh}`); + } const green = `then gstack-pregate clear --remote ${lane} --run-url `; if (run.status !== 'completed') return invalid(`run_in_progress — run ${id} attempt ${run.run_attempt} is ${run.status}`, `wait for run ${id} to finish green (or rerun ${runOf.file} if it fails), ${green}`); if (run.conclusion !== 'success') return invalid(`run_not_success — run ${id} attempt ${run.run_attempt} concluded ${run.conclusion}`, `rerun ${runOf.file} (gh run rerun ${id}${runOf.dispatch ? `, or gh workflow run ${runOf.file} --ref ` : ''}), ${green}`); diff --git a/lib/run-evidence.ts b/lib/run-evidence.ts index f220b19d4..3fdd6ce19 100644 --- a/lib/run-evidence.ts +++ b/lib/run-evidence.ts @@ -173,6 +173,8 @@ export function runProfileErrors(profiles: unknown, gateRuns: unknown): Array<{ return errors; } +/** Newer-run conclusions that never veto: a green run, and a skipped or neutral one, which ran no job that could fail (GST-3514, GST-3554). */ +const QUIET = ['success', 'skipped', 'neutral']; const fail = (reason: RunRefusal, detail: string, fix?: string): RunVerdict => ({ ok: false, reason, detail, ...(fix ? { fix } : {}) }); /** When a run's newest attempt started. A run vetoes the candidate when it started at or after the second the candidate was created: a red re-run of an older run counts, and re-running the candidate does not hide a failure in between. */ const started = (r: ApiRun): string => r.run_started_at ?? r.created_at ?? ''; @@ -223,7 +225,7 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof } const heads = [...new Set([run.head_sha, ...(o.vetoHeads ?? []).filter(h => SHA.test(h))])]; for (const head of heads) { - const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && (r.conclusion === 'success' || r.conclusion === 'skipped'))); + const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && QUIET.includes(r.conclusion ?? ''))); if (newer.length) return fail('newer_run_vetoes', `newer run ${newer[0]!.id} of ${p.workflow} on ${head.slice(0, 12)} is ${newer[0]!.status === 'completed' ? newer[0]!.conclusion : newer[0]!.status}`); } if (p.skippable && p.skippable.jobs.every(j => skippedJobs.includes(j)) && o.docsOnly?.(run.head_sha)) { diff --git a/test/ci-carry.test.ts b/test/ci-carry.test.ts index 947d34c0f..59d1be4f6 100644 --- a/test/ci-carry.test.ts +++ b/test/ci-carry.test.ts @@ -146,6 +146,14 @@ describe('waitForRun', () => { expect((await o([run(4, { conclusion: 'failure' }), skipped])).state).toBe('red'); expect(await o([skipped])).toMatchObject({ state: 'red', run: { id: 5 } }); }); + + // Value: protects=the wait agrees with verifyRun on a neutral run too (GST-3554); fails_when=a newer neutral run is read as the commit's result + test('a newer neutral run is passed over like a skipped one; a newer failed run is still red', async () => { + const o = (runs: ApiRun[]) => waitForRun(source(runs).deps, { workflow: 'free-tests.yml', events: PROFILE.events, head: HEAD, timeoutMs: 60_000, intervalMs: 20_000, ...clockAt() }); + const neutral = run(5, { event: 'pull_request', conclusion: 'neutral', created_at: run(4).created_at }); + expect(await o([run(4), neutral])).toMatchObject({ state: 'green', run: { id: 4 } }); + expect(await o([run(4), run(5, { event: 'pull_request', conclusion: 'failure', created_at: run(4).created_at })])).toMatchObject({ state: 'red', run: { id: 5 } }); + }); }); describe('ship_lanes_from config and the ci_carried receipt field', () => { diff --git a/test/fixtures/run-evidence/gbrain-435e38c5.json b/test/fixtures/run-evidence/gbrain-435e38c5.json new file mode 100644 index 000000000..3c9c0a6c1 --- /dev/null +++ b/test/fixtures/run-evidence/gbrain-435e38c5.json @@ -0,0 +1,298 @@ +{ + "source": "garrytan/gbrain #10021 at 435e38c5, read with gh api on 2026-11-22 (GST-3554); trimmed to the fields verifyRun reads", + "head": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "tree": "a23834cdcc7849b7f02927a6cbb17e0fc2ab1d03", + "profiles": { + "macos-validation.yml/macos-26": { + "workflow": "macos-validation.yml", + "events": [ + "workflow_dispatch" + ], + "jobs": [ + "macOS 26 validation" + ], + "artifact": "macos-26-tree", + "os": "macOS" + }, + "native-locks.yml/native": { + "workflow": "test.yml", + "events": [ + "workflow_dispatch", + "push" + ], + "jobs": [ + "full-suite", + "native-locks / linux-x64-glibc / Bun 1.4.4", + "native-locks / linux-arm64-glibc / Bun 1.4.4", + "native-locks / darwin-arm64 / Bun 1.4.4", + "native-locks / darwin-x64 / Bun 1.4.4", + "native-locks / win32-x64 / Bun 1.4.4", + "native-locks / win32-arm64 / Bun 1.4.4" + ], + "artifact": "full-suite-tree" + } + }, + "macos": { + "runs_for_head": [ + { + "id": 45041640526, + "run_attempt": 1, + "status": "completed", + "conclusion": "skipped", + "event": "pull_request", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/macos-validation.yml", + "created_at": "2026-11-22T16:03:04Z", + "run_started_at": "2026-11-22T16:03:04Z", + "updated_at": "2026-11-22T16:03:05Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + }, + { + "id": 45041640171, + "run_attempt": 1, + "status": "completed", + "conclusion": "success", + "event": "workflow_dispatch", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/macos-validation.yml", + "created_at": "2026-11-22T16:03:04Z", + "run_started_at": "2026-11-22T16:03:04Z", + "updated_at": "2026-11-22T16:46:07Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + }, + { + "id": 44987920051, + "run_attempt": 1, + "status": "completed", + "conclusion": "skipped", + "event": "pull_request", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/macos-validation.yml", + "created_at": "2026-11-22T05:06:09Z", + "run_started_at": "2026-11-22T05:06:09Z", + "updated_at": "2026-11-22T05:06:10Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + } + ], + "dispatch": { + "id": 45041640171, + "run_attempt": 1, + "status": "completed", + "conclusion": "success", + "event": "workflow_dispatch", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/macos-validation.yml", + "created_at": "2026-11-22T16:03:04Z", + "run_started_at": "2026-11-22T16:03:04Z", + "updated_at": "2026-11-22T16:46:07Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + }, + "jobs": [ + { + "name": "macOS 26 typecheck", + "conclusion": "success", + "started_at": "2026-11-22T16:25:31Z", + "completed_at": "2026-11-22T16:34:43Z" + }, + { + "name": "macOS 26 validation", + "conclusion": "success", + "started_at": "2026-11-22T16:34:46Z", + "completed_at": "2026-11-22T16:46:07Z" + } + ], + "artifact": { + "tree": "a23834cdcc7849b7f02927a6cbb17e0fc2ab1d03", + "sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "workflow": "macOS 26 validation", + "event": "workflow_dispatch", + "run_id": 45041640171, + "run_attempt": 1, + "os": "macOS", + "files": [ + "test/connector-physical-root-device.test.ts", + "test/persistence-physical-root-device.test.ts" + ] + } + }, + "test": { + "runs_for_head": [ + { + "id": 45041701289, + "run_attempt": 1, + "status": "completed", + "conclusion": "success", + "event": "workflow_dispatch", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/test.yml", + "created_at": "2026-11-22T16:03:42Z", + "run_started_at": "2026-11-22T16:03:42Z", + "updated_at": "2026-11-22T16:47:33Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + }, + { + "id": 44987920129, + "run_attempt": 1, + "status": "completed", + "conclusion": "success", + "event": "pull_request", + "head_sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "head_branch": "fix/skill-resolver-symlinked-skills", + "path": ".github/workflows/test.yml", + "created_at": "2026-11-22T05:06:09Z", + "run_started_at": "2026-11-22T05:06:09Z", + "updated_at": "2026-11-22T05:11:49Z", + "repository": { + "full_name": "garrytan/gbrain" + }, + "head_repository": { + "full_name": "garrytan/gbrain" + } + } + ], + "jobs": [ + { + "completed_at": "2026-11-22T16:05:59Z", + "conclusion": "success", + "name": "native-locks / Windows PowerShell console probe / windows-2022 / Bun 1.4.4", + "started_at": "2026-11-22T16:05:12Z" + }, + { + "completed_at": "2026-11-22T16:06:32Z", + "conclusion": "success", + "name": "native-locks / Windows PowerShell console probe / windows-11-arm / Bun 1.4.4", + "started_at": "2026-11-22T16:05:16Z" + }, + { + "completed_at": "2026-11-22T16:06:25Z", + "conclusion": "success", + "name": "native-locks / OpenClaw 2026.9.4 native context-engine startup", + "started_at": "2026-11-22T16:05:09Z" + }, + { + "completed_at": "2026-11-22T16:05:55Z", + "conclusion": "success", + "name": "native-locks / linux-x64-musl / Bun 1.4.4", + "started_at": "2026-11-22T16:05:09Z" + }, + { + "completed_at": "2026-11-22T16:05:35Z", + "conclusion": "success", + "name": "native-locks / linux-arm64-musl / Bun 1.4.4", + "started_at": "2026-11-22T16:04:51Z" + }, + { + "completed_at": "2026-11-22T16:06:38Z", + "conclusion": "success", + "name": "native-locks / Windows ACL API probe / windows-2022 / Bun 1.4.4", + "started_at": "2026-11-22T16:05:45Z" + }, + { + "completed_at": "2026-11-22T16:07:41Z", + "conclusion": "success", + "name": "native-locks / Windows ACL API probe / windows-11-arm / Bun 1.4.4", + "started_at": "2026-11-22T16:05:12Z" + }, + { + "completed_at": "2026-11-22T16:14:50Z", + "conclusion": "success", + "name": "native-locks / win32-arm64 / Bun 1.4.4", + "started_at": "2026-11-22T16:06:07Z" + }, + { + "completed_at": "2026-11-22T16:46:54Z", + "conclusion": "success", + "name": "native-locks / darwin-arm64 / Bun 1.4.4", + "started_at": "2026-11-22T16:43:40Z" + }, + { + "completed_at": "2026-11-22T16:06:58Z", + "conclusion": "success", + "name": "native-locks / linux-x64-glibc / Bun 1.4.4", + "started_at": "2026-11-22T16:05:09Z" + }, + { + "completed_at": "2026-11-22T16:06:55Z", + "conclusion": "success", + "name": "native-locks / linux-arm64-glibc / Bun 1.4.4", + "started_at": "2026-11-22T16:04:51Z" + }, + { + "completed_at": "2026-11-22T16:13:46Z", + "conclusion": "success", + "name": "native-locks / win32-x64 / Bun 1.4.4", + "started_at": "2026-11-22T16:07:05Z" + }, + { + "completed_at": "2026-11-22T16:12:02Z", + "conclusion": "success", + "name": "native-locks / darwin-x64 / Bun 1.4.4", + "started_at": "2026-11-22T16:06:48Z" + }, + { + "completed_at": "2026-11-22T16:04:19Z", + "conclusion": "skipped", + "name": "reused-full-suite", + "started_at": "2026-11-22T16:04:19Z" + }, + { + "completed_at": "2026-11-22T16:47:10Z", + "conclusion": "success", + "name": "native-locks / darwin-x64 heartbeat finalize", + "started_at": "2026-11-22T16:46:57Z" + }, + { + "completed_at": "2026-11-22T16:47:33Z", + "conclusion": "success", + "name": "full-suite", + "started_at": "2026-11-22T16:47:20Z" + } + ], + "artifact": { + "tree": "a23834cdcc7849b7f02927a6cbb17e0fc2ab1d03", + "sha": "435e38c5c2eae4508a0cb0daeb3933efef07a12f", + "workflow": "Test", + "event": "workflow_dispatch", + "run_id": 45041701289, + "run_attempt": 1, + "profile": "full", + "os": "Linux", + "files": [ + "evals/functional-area-resolver/harness-runner.test.ts", + "test/abort-check.test.ts", + "test/accepted-pending-status.test.ts" + ], + "tests": 74955 + } + } +} diff --git a/test/helpers/free-fixtures-data.ts b/test/helpers/free-fixtures-data.ts index 45d53c15f..797673266 100644 --- a/test/helpers/free-fixtures-data.ts +++ b/test/helpers/free-fixtures-data.ts @@ -224,6 +224,7 @@ export const FREE_FIXTURES: Readonly> = { 'test/fixtures/review-design-lite-reports-ci-36633323521.json': ['test/review-finalization-budget.test.ts'], 'test/fixtures/review-gate-integrity-opus-reports.json': ['test/gate-integrity-templates.test.ts'], 'test/fixtures/review-wrong-tree/**': ['test/review-dispatch.test.ts'], + 'test/fixtures/run-evidence/gbrain-435e38c5.json': ['test/run-evidence.test.ts'], 'test/fixtures/scrape-prototype-goto-42571575838.json': ['test/helpers/session-runner.test.ts'], 'test/fixtures/screen-verdict-41662815506/**': ['crew/test/ship-queue-screen-verdict.test.ts'], 'test/fixtures/sealed-guard-off-golden.json': ['test/sealed-guard.test.ts'], diff --git a/test/pregate-clear-runs.test.ts b/test/pregate-clear-runs.test.ts index 37bb17518..049ceac01 100644 --- a/test/pregate-clear-runs.test.ts +++ b/test/pregate-clear-runs.test.ts @@ -78,7 +78,7 @@ function runOfWorkflow(repo: FixtureRepo, head: string, workflow: string, state: const c = check(repo, []); const run = (id: number): ApiRun => { if (id !== 300) throw new Error('HTTP 404'); - return { id, run_attempt: 1, ...state, event: 'pull_request', head_sha: head, path: `.github/workflows/${workflow}`, repository: { full_name: 'fx/fx' }, head_repository: { full_name: 'fx/fx' } }; + return { id, run_attempt: 1, ...state, event: 'workflow_dispatch', head_sha: head, path: `.github/workflows/${workflow}`, repository: { full_name: 'fx/fx' }, head_repository: { full_name: 'fx/fx' } }; }; return { ...c, deps: { ...c.deps, run, jobs: () => jobs } }; } @@ -231,7 +231,7 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo test('a reusable-workflow lane (workflow_call only) clears from a run of a caller whose job uses ./.github/workflows/; an unrelated workflow still refuses, and no fix line dispatches a workflow without workflow_dispatch (GST-971)', async () => { const repo = fixture(); - const head = repo.git('rev-parse', 'HEAD'); + let head = repo.git('rev-parse', 'HEAD'); const base = await pregateAt(repo); const wf = (name: string, text: string) => { fs.mkdirSync(path.join(repo.work, '.github/workflows'), { recursive: true }); fs.writeFileSync(path.join(repo.work, '.github/workflows', name), text); }; wf('r.yml', 'name: Reusable\non:\n workflow_call:\n inputs:\n scope:\n type: string\njobs:\n job:\n runs-on: ubuntu-latest\n steps:\n - run: echo reusable\n'); @@ -241,7 +241,7 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo const file: PregateFile = { ...base, requires_remote: [...base.requires_remote!, { lane: PLATFORM, platform: 'windows', workflow: 'r.yml', job: 'job', tests: ['test/a.test.ts'], receipt: null }] }; const url = 'https://github.com/fx/fx/actions/runs/300'; const msg = (d: ReturnType) => ('refused' in d ? `${d.refused}: ${d.message}; fix: ${d.fix}` : `cleared ${d.receipt}`); - const at = (): PregateFile => { repo.git('add', '-A', '.github'); return { ...file, tree: repo.git('write-tree') }; }; + const at = (): PregateFile => { repo.git('add', '-A', '.github'); repo.git('commit', '-q', '--allow-empty', '-m', 'workflows'); head = repo.git('rev-parse', 'HEAD'); return { ...file, head, tree: repo.git('rev-parse', 'HEAD^{tree}') }; }; expect(msg(clearDecision(at(), PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(`cleared ${url}/attempts/1`); expect(msg(clearDecision(at(), PLATFORM, { runUrl: `${url}/job/9`, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(`cleared ${url}/attempts/1`); expect(msg(clearDecision(at(), PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml', undefined, [{ name: 'native (linux) / job', conclusion: 'success' }]) }, repo.work))).toBe(`cleared ${url}/attempts/1`); @@ -257,9 +257,40 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo expect(msg(clearDecision(at(), PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(`cleared ${url}/attempts/1`); }, 120_000); + // Value: protects=a workflow_call-only lane clears from a caller run only when that run tested pregate.json's exact head and tree (GST-3554); fails_when=a green caller run of another commit, a pull_request merge or a tree pregate.json did not record clears the lane + test('a caller run of a reusable-workflow lane clears only when it tested pregate.json\'s head and tree; another commit, a pull_request merge or another tree refuses (GST-3554)', async () => { + const repo = fixture(); + const before = repo.git('rev-parse', 'HEAD'); + const base = await pregateAt(repo); + const dir = path.join(repo.work, '.github/workflows'); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync(path.join(dir, 'r.yml'), 'name: Reusable\non:\n workflow_call:\njobs:\n job:\n runs-on: ubuntu-latest\n steps:\n - run: echo r\n'); + fs.writeFileSync(path.join(dir, 'c.yml'), 'name: Caller\non:\n pull_request:\n workflow_dispatch:\njobs:\n native:\n uses: ./.github/workflows/r.yml\n'); + repo.git('add', '-A', '.github'); + repo.git('commit', '-q', '-m', 'workflows'); + const head = repo.git('rev-parse', 'HEAD'); + const tree = repo.git('rev-parse', 'HEAD^{tree}'); + const PLATFORM = 'r.yml/job'; + const file: PregateFile = { ...base, head, tree, requires_remote: [...base.requires_remote!, { lane: PLATFORM, platform: 'windows', workflow: 'r.yml', job: 'job', tests: ['test/a.test.ts'], receipt: null }] }; + const url = 'https://github.com/fx/fx/actions/runs/300'; + const msg = (d: ReturnType) => ('refused' in d ? `${d.refused}: ${d.message}; fix: ${d.fix}` : `cleared ${d.receipt}`); + const refused = (why: string, fix: string) => `PREGATE_RECEIPT_INVALID: REUSE: refused reason=${why}; ${PLATFORM} stays uncleared; fix: ${fix}`; + const fresh = `gh workflow run c.yml --ref at ${head.slice(0, 12)}, then gstack-pregate clear --remote ${PLATFORM} --run-url `; + expect(msg(clearDecision(file, PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(`cleared ${url}/attempts/1`); + expect(msg(clearDecision(file, PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, before, 'c.yml') }, repo.work))).toBe(refused(`head_mismatch — run 300 attempt 1 of c.yml ran at ${before.slice(0, 12)}, not pregate.json's head ${head.slice(0, 12)}, and a caller run clears r.yml only at that exact head`, fresh)); + const pr = runOfWorkflow(repo, head, 'c.yml'); + const prRun = pr.deps.run; + expect(msg(clearDecision(file, PLATFORM, { runUrl: url, evidence: { ...pr, deps: { ...pr.deps, run: id => ({ ...prRun(id), event: 'pull_request' }) } } }, repo.work))).toBe(refused('merge_tested — run 300 attempt 1 of c.yml is a pull_request run, which tested GitHub\'s merge of the head with its base, not the head itself', fresh)); + fs.writeFileSync(path.join(repo.work, 'lib/uncommitted.js'), 'exports.x = 1;\n'); + repo.git('add', '-A'); + const dirty = repo.git('write-tree'); + expect(msg(clearDecision({ ...file, tree: dirty }, PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(refused(`tree_mismatch — run 300 attempt 1 of c.yml tested tree ${tree.slice(0, 12)} at its head, not pregate.json's tree ${dirty.slice(0, 12)}`, `commit what pregate.json recorded, rerun gstack-pregate, then ${fresh}`)); + expect(msg(clearDecision({ ...file, head: undefined }, PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml') }, repo.work))).toBe(refused(`head_mismatch — run 300 attempt 1 of c.yml ran at ${head.slice(0, 12)}, not pregate.json's head (none recorded), and a caller run clears r.yml only at that exact head`, `rerun gstack-pregate at the head, then gh workflow run c.yml --ref at the head, then gstack-pregate clear --remote ${PLATFORM} --run-url `)); + }, 120_000); + test('a caller run counts only through a successful / job; names with comments or expressions match; callers are read at pregate.json\'s tree, not the working tree; a flow-mapping on: with workflow_dispatch counts (GST-971 fix-check)', async () => { const repo = fixture(); - const head = repo.git('rev-parse', 'HEAD'); + let head = repo.git('rev-parse', 'HEAD'); const base = await pregateAt(repo); const PLATFORM = 'r.yml/job'; const lane: PregateFile = { ...base, requires_remote: [...base.requires_remote!, { lane: PLATFORM, platform: 'windows', workflow: 'r.yml', job: 'job', tests: ['test/a.test.ts'], receipt: null }] }; @@ -270,7 +301,9 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo 'c.yml': 'name: Caller\non: { pull_request: {}, workflow_dispatch: {} }\njobs:\n native:\n name: Native (${{ inputs.scope }}) # calls r.yml\n uses: ./.github/workflows/r.yml\n', }); repo.git('add', '-A', '.github'); - const file: PregateFile = { ...lane, tree: repo.git('write-tree') }; + repo.git('commit', '-q', '-m', 'workflows'); + head = repo.git('rev-parse', 'HEAD'); + const file: PregateFile = { ...lane, head, tree: repo.git('rev-parse', 'HEAD^{tree}') }; const url = 'https://github.com/fx/fx/actions/runs/300'; const msg = (d: ReturnType) => ('refused' in d ? `${d.refused}: ${d.message}; fix: ${d.fix}` : `cleared ${d.receipt}`); const caller = (jobs: ApiJob[], state?: Pick) => msg(clearDecision(file, PLATFORM, { runUrl: url, evidence: runOfWorkflow(repo, head, 'c.yml', state, jobs) }, repo.work)); diff --git a/test/run-evidence.test.ts b/test/run-evidence.test.ts index d6e2e6708..7c7ee37d5 100644 --- a/test/run-evidence.test.ts +++ b/test/run-evidence.test.ts @@ -111,6 +111,59 @@ describe('verifyRun', () => { expect(reason(world({ others: [skipped({ event: 'workflow_dispatch', status: 'in_progress', conclusion: null })] }))).toBe('newer_run_vetoes'); }); + // Value: protects=gbrain #10021's real runs at 435e38c5 (GST-3554): the dispatch run clears though a pull_request run that skipped itself, or concluded neutral, was created in the same second and is listed first; fails_when=a skipped or neutral run vetoes, or a newer failed, cancelled, timed-out or running run stops vetoing; + // why_new=GST-3514 covered skipped with a synthetic run; this binds the API's real order and timestamps, and neutral; seam=verifyRun's newer-run filter; no_claim=GitHub's API shape (ghRunDeps) + describe('the real gbrain runs at 435e38c5 (GST-3554)', () => { + const fx = JSON.parse(fs.readFileSync(path.join(import.meta.dir, 'fixtures/run-evidence/gbrain-435e38c5.json'), 'utf8')); + const AT = new Date('2026-11-22T17:30:00Z'); + const lane = (key: 'macos' | 'test', over: { runs?: (runs: ApiRun[]) => ApiRun[]; jobs?: (jobs: ApiJob[]) => ApiJob[]; head?: string } = {}) => { + const runs: ApiRun[] = (over.runs ?? (r => r))(structuredClone(fx[key].runs_for_head)); + const d: RunDeps = { + run: id => { const r = runs.find(x => x.id === id); if (!r) throw new Error('HTTP 404'); return r; }, + runsForHead: (_wf, sha) => runs.filter(r => r.head_sha === sha), + jobs: () => (over.jobs ?? (j => j))(structuredClone(fx[key].jobs)), + artifact: () => structuredClone(fx[key].artifact), + commitTree: sha => (sha === fx.head ? fx.tree : null), + }; + return d; + }; + const MAC = 'macos-validation.yml/macos-26'; + const NATIVE = 'native-locks.yml/native'; + const verdict = (name: string, d: RunDeps, runRef: string, vetoHeads: string[] = [fx.head]) => { + const v = verifyRun(d, { repo: REPO, runRef, profileName: name, profile: fx.profiles[name], vetoHeads, now: AT }); + return v.ok ? 'ok' : `${v.reason}: ${v.detail}`; + }; + const skippedRun = 45041640526; + const as = (conclusion: string | null, status = 'completed') => (runs: ApiRun[]) => runs.map(r => (r.id === skippedRun ? { ...r, status, conclusion } : r)); + + test('the macOS dispatch run 45041640171 clears though the skipped pull_request run 45041640526, created the same second, is listed first', () => { + expect(fx.macos.runs_for_head.map((r: ApiRun) => `${r.id} ${r.event} ${r.conclusion} ${r.created_at}`)).toEqual([ + '45041640526 pull_request skipped 2026-11-22T16:03:04Z', '45041640171 workflow_dispatch success 2026-11-22T16:03:04Z', '44987920051 pull_request skipped 2026-11-22T05:06:09Z', + ]); + expect(verdict(MAC, lane('macos'), '45041640171')).toBe('ok'); + }); + + test('a newer neutral run does not veto either; a newer failed, cancelled, timed-out or unfinished run still does', () => { + expect(verdict(MAC, lane('macos', { runs: as('neutral') }), '45041640171')).toBe('ok'); + for (const conclusion of ['failure', 'cancelled', 'timed_out', 'startup_failure', 'action_required']) + expect(verdict(MAC, lane('macos', { runs: as(conclusion) }), '45041640171')).toBe(`newer_run_vetoes: newer run 45041640526 of macos-validation.yml on 435e38c5c2ea is ${conclusion}`); + expect(verdict(MAC, lane('macos', { runs: as(null, 'in_progress') }), '45041640171')).toBe('newer_run_vetoes: newer run 45041640526 of macos-validation.yml on 435e38c5c2ea is in_progress'); + }); + + test('the workflow_call-only native-locks lane clears from the Test dispatch run 45041701289 that called it, through its called job names, and from no other run', () => { + expect(verdict(NATIVE, lane('test'), '45041701289')).toBe('ok'); + const drop = (name: string) => (jobs: ApiJob[]) => jobs.filter(j => j.name !== name); + const red = (name: string) => (jobs: ApiJob[]) => jobs.map(j => (j.name === name ? { ...j, conclusion: 'failure' } : j)); + expect(verdict(NATIVE, lane('test', { jobs: drop('native-locks / win32-arm64 / Bun 1.4.4') }), '45041701289')).toBe('job_missing: run 45041701289 attempt 1 has no job named native-locks / win32-arm64 / Bun 1.4.4'); + expect(verdict(NATIVE, lane('test', { jobs: red('native-locks / darwin-x64 / Bun 1.4.4') }), '45041701289')).toBe('job_not_success: run 45041701289 attempt 1\'s native-locks / darwin-x64 / Bun 1.4.4 job concluded failure'); + const OTHER = 'c'.repeat(40); + const elsewhere: RunDeps = { ...lane('test', { runs: runs => runs.map(r => ({ ...r, head_sha: OTHER })) }), artifact: () => ({ ...structuredClone(fx.test.artifact), sha: OTHER, tree: 'd'.repeat(40) }), commitTree: sha => (sha === OTHER ? 'd'.repeat(40) : sha === fx.head ? fx.tree : null) }; + expect(verdict(NATIVE, lane('test', { runs: runs => runs.map(r => ({ ...r, head_sha: OTHER })) }), '45041701289')).toBe(`artifact_mismatch: run 45041701289 attempt 1's full-suite-tree records sha ${fx.head} (expected ${OTHER})`); + expect(verifyFromRun({ repo: REPO, deps: elsewhere, profiles: fx.profiles, now: AT }, '45041701289', [NATIVE], fx.tree, fx.head)).toEqual({ ok: false, reason: 'tree_mismatch', detail: `run 45041701289 tested tree dddddddddddd, not this tree ${fx.tree.slice(0, 12)}` }); + expect(verdict(NATIVE, lane('macos'), '45041640171')).toMatch(/^workflow_mismatch: /); + }); + }); + test('a newer failure on another head the consumer names (same tree, the lane\'s own head) vetoes too', () => { const w = world(); const other = 'e'.repeat(40);