diff --git a/docs/pregate.md b/docs/pregate.md index ec4f054a1..4b5c6a33a 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -1013,8 +1013,9 @@ a branch that does not contain the base tip it tested another tree and `CI_CARRY` says `none (no_verified_run: … tree_mismatch)`: dispatch Free Tests on the branch (`gh workflow run free-tests.yml --ref `), which tests HEAD's own tree, -and wait again. The refusal names that command for the run's branch (`fix: gh -workflow run free-tests.yml --ref , then gstack-ci-carry wait`). The preflight stage (generated-file freshness, secrets, strays +and wait again. When the pull_request run tested that merge commit, the +refusal names the command for the run's branch (`fix: gh workflow run +free-tests.yml --ref , then gstack-ci-carry wait`). The preflight stage (generated-file freshness, secrets, strays and the other mechanical checks) and the sealed guard are unchanged and always run here. The macOS and Windows lane obligations still clear with `gstack-pregate clear --remote --run-url diff --git a/lib/run-evidence.ts b/lib/run-evidence.ts index d649460c3..7bf1063b6 100644 --- a/lib/run-evidence.ts +++ b/lib/run-evidence.ts @@ -210,12 +210,17 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof if (wrong.length) return fail('artifact_mismatch', `${at}'s ${p.artifact} records ${wrong.map(([k, got, want]) => `${k} ${String(got)} (expected ${want})`).join(', ')}`); const headTree = deps.commitTree(run.head_sha); if (!headTree) return fail('api_error', `git cannot read the tree of ${run.head_sha}`); - if (rec.tree !== headTree) return fail('tree_mismatch', `${at} recorded tree ${String(rec.tree)}, but its head ${run.head_sha.slice(0, 12)} has tree ${headTree}`); + const baseMoved = `gh workflow run ${p.workflow} --ref ${run.head_branch || ''}, then gstack-ci-carry wait`; + if (rec.tree !== headTree) { + const testedMerge = pr && typeof rec.sha === 'string' && SHA.test(rec.sha) && deps.commitTree(rec.sha) === rec.tree; + if (testedMerge) return fail('tree_mismatch', `${at} tested merge commit ${(rec.sha as string).slice(0, 12)} (tree ${String(rec.tree)}), not its head ${run.head_sha.slice(0, 12)}'s tree ${headTree}: the pull request was behind its base (the base moved after the run, or the branch lacks its tip)`, baseMoved); + return fail('tree_mismatch', `${at} recorded tree ${String(rec.tree)}, but its head ${run.head_sha.slice(0, 12)} has tree ${headTree}`); + } if (pr) { if (typeof rec.sha !== 'string' || !SHA.test(rec.sha)) return fail('artifact_mismatch', `${at}'s ${p.artifact} names no merge commit (sha) for its pull_request run`); const mergeTree = deps.commitTree(rec.sha); if (!mergeTree) return fail('api_error', `git cannot read the tree of merge commit ${rec.sha}`); - if (mergeTree !== headTree) return fail('tree_mismatch', `${at} tested merge commit ${rec.sha.slice(0, 12)} (tree ${mergeTree}), not its head ${run.head_sha.slice(0, 12)}'s tree ${headTree}: the pull request was behind its base (the base moved after the run, or the branch lacks its tip)`, `gh workflow run ${p.workflow} --ref ${run.head_branch || ''}, then gstack-ci-carry wait`); + if (mergeTree !== headTree) return fail('tree_mismatch', `${at} tested merge commit ${rec.sha.slice(0, 12)} (tree ${mergeTree}), not its head ${run.head_sha.slice(0, 12)}'s tree ${headTree}: the pull request was behind its base (the base moved after the run, or the branch lacks its tip)`, baseMoved); } const oses = Array.isArray(rec.os) ? rec.os : [rec.os]; if (p.os && !oses.includes(p.os)) return fail('os_mismatch', `${at} ran on ${oses.filter(Boolean).map(String).join(', ') || 'an unrecorded OS'}; ${o.profileName} requires ${p.os}`); diff --git a/test/ship-ci-carry.test.ts b/test/ship-ci-carry.test.ts index d623bba88..253d474fa 100644 --- a/test/ship-ci-carry.test.ts +++ b/test/ship-ci-carry.test.ts @@ -287,7 +287,9 @@ describe('GST-1189: a lane carries by named CI jobs instead of an inventory', () test('a pull_request run whose base moved names the one-command fix (TRUT-7)', () => { const f = gbrain(); - world(f, { jobs: ALL, run: { event: 'pull_request', head_branch: 'feat' }, tree: { ...NO_FILES, sha: f.git('rev-parse', 'origin/main').stdout.trim() } }); + const mergeTree = f.git('rev-parse', 'origin/main^{tree}').stdout.trim(); + const merge = f.git('commit-tree', mergeTree, '-p', 'HEAD', '-p', 'origin/main', '-m', 'Merge origin/main into feat').stdout.trim(); + world(f, { jobs: ALL, run: { event: 'pull_request', head_branch: 'feat' }, tree: { ...NO_FILES, tree: mergeTree, sha: merge } }); expect(find(f).stdout).toContain("CI_CARRY: none (no_verified_run: ci/free: run 7: tree_mismatch (the pull request's base moved after the run; fix: gh workflow run free.yml --ref feat, then gstack-ci-carry wait))"); });