mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-24 09:01:28 +01:00
A green CI run now counts for your branch when only main moved under it (GST-3567) (#4728)
/ship's final CI check (`gstack-ship-release accept`) now accepts a green pull request run that tested your branch merged onto a newer main, when main changed none of your lines. Why: before, it refused that run and you had to merge main and rerun CI, which never settles on a busy repo (harness-evals #576, gstack #4722). Nothing to do. Repos with a land step still re-check the merged tree; repos with `land: null` get no merged-tree check. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: lib/pregate/run-check.ts:70:functional-contract reader=qa Review-Finding: p2/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
8751b382dd
commit
261f380002
13 files changed
+344
-27
No files matched your search
+1
-1
@@ -190,7 +190,7 @@ the new defaults.
|
||||
| Run one free test file while repairing | `bun test <file>` | Free, seconds | Never bare `bun test` for the suite |
|
||||
| Run full free acceptance before publishing | `bun run test` | Free, a few minutes | Bun 1.4.2 |
|
||||
| Run the full free suite from a small machine | `bun run test:ubicloud` | Free suite on a billed 16-vCPU VM, about 5 minutes | `UBICLOUD_API_KEY`, `UBI_OWNER` |
|
||||
| Clear pregate's test tier on a machine under 8 cores from CI, the default on gstack ([CI carry](docs/pregate.md#ci-carry)) | push, `gstack-ci-carry wait --base main`, then `gstack-pregate --allow-repo-commands` (a branch behind main first runs `gh workflow run free-tests.yml --ref <branch>`) | Free; reuses the green Free Tests run at your pushed tree | Pushed branch, `gh` |
|
||||
| Clear pregate's test tier on a machine under 8 cores from CI, the default on gstack ([CI carry](docs/pregate.md#ci-carry)) | push, `gstack-ci-carry wait --base main`, then `gstack-pregate --allow-repo-commands` (on a branch behind main, a green pull request run still counts when main changed none of your lines; when a `CARRY_DIAGNOSIS:` line says it doesn't, run `gh workflow run free-tests.yml --ref <branch>` first) | Free; reuses the green Free Tests run at your pushed tree | Pushed branch, `gh` |
|
||||
| Clear pregate's test tier on a machine under 8 cores when no CI run covers your tree ([remote gate](docs/pregate.md#remote-gate), opt-in) | `gstack-pregate --stage tests --remote --spend-cap 2 --timeout 2700 --allow-repo-commands` (same command keyed or keyless) | Keyed: one billed 16-vCPU VM, about 7 minutes and $0.06 for the whole free tier, worst case $0.38; keyless: free, local parallel shards, practical for small selections only (98 files took 103 s on 4 cores) | Keyed: `UBICLOUD_API_KEY`, `UBI_OWNER`; keyless: nothing |
|
||||
| Run the curated Windows-safe subset | `bun run test:windows` (CI: eight `windows-latest` jobs, nightly on main; PRs run the shorter `windows-smoke` check, and a PR that touches path, file-name or process code also runs its changed Windows-safe test files in `Windows Scoped Tests`) | Free | Windows, Git Bash |
|
||||
| Rerun chosen Windows-safe test files on Windows CI | `gh workflow run windows-scoped-tests.yml --ref <branch> -f files='<file> <file>'` (pick files from `bun run test:windows --list`) | Free CI runners | Pushed branch, `gh` with workflow rights |
|
||||
|
||||
@@ -75,6 +75,7 @@ function find(): number {
|
||||
else out(v.ok ? `CI_CARRY: accepted ${v.receipt}` : `CI_CARRY: none (${v.reason}: ${v.detail})`);
|
||||
const from = v.ok && !argv.includes('--json') ? carriedFromLine(v.runs, head) : undefined;
|
||||
if (from) out(from);
|
||||
if (!v.ok && !argv.includes('--json')) for (const d of v.diagnosis ?? []) out(`CARRY_DIAGNOSIS: ${d}`);
|
||||
return v.ok ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
important: blocker
|
||||
---
|
||||
**/ship's final CI check no longer makes you rerun CI just because main moved.** A green pull request run that tested your branch merged onto a newer main now counts for your branch when your own added and removed lines in that merge are byte-identical to your branch's, so main changed none of your lines and none next to them; before, `gstack-ship-release accept` refused it with `tree_mismatch` and busy repos never converged. It still refuses when main changed one of your lines or one next to it or the run tested another commit, and a `CARRY_DIAGNOSIS:` line says which. Landing still checks the merged tree with `land.merged_ci`; a repo whose `land` is `null` gets no merged-tree check. docs/ship-policy.md#ci-carry-base-moved (GST-3567)
|
||||
+14
-3
@@ -951,7 +951,8 @@ once:
|
||||
`tree.json` must name the head (`head_sha`) and the merge commit (`sha`), and
|
||||
the tree git computes for that merge commit must equal the head's tree: the
|
||||
head already contained its base, so the merge tested exactly the head tree
|
||||
(`tree_mismatch` otherwise). The API answers with
|
||||
(`tree_mismatch` otherwise), unless only the base moved
|
||||
([below](#base-moved-carry)). The API answers with
|
||||
the newest attempt, so an earlier green attempt under a newer red one is
|
||||
refused, and the run is read again after the evidence is collected: a new
|
||||
attempt meanwhile is `run_changed`. A newer run of the same workflow on the
|
||||
@@ -1259,8 +1260,18 @@ the Ubicloud VM (`gstack-pregate --stage tests --remote`) is an opt-in for when
|
||||
no such run exists. The order after a push: wait for Free Tests
|
||||
(`gstack-ci-carry wait --base main`), then `gstack-pregate
|
||||
--allow-repo-commands`. A `pull_request` run tests GitHub's merge commit, so on
|
||||
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
|
||||
a branch that does not contain the base tip it tested another tree.
|
||||
<a id="base-moved-carry"></a>That run still carries for HEAD when only the base
|
||||
moved (GST-3567): the merge commit is HEAD merged onto a commit of the base, and
|
||||
the pull request's own added and removed lines in it are byte-identical to
|
||||
HEAD's at the same places (`lib/pregate/run-check.ts` `onlyBaseMoved`, used by every lane carry and by
|
||||
`clear --run`, never by land's merged-tree CI; why that is safe:
|
||||
[ship-policy.md](ship-policy.md#ci-carry-base-moved)). The receipt adds
|
||||
`base_moved=<base commit>`. GitHub merges onto the base as it was when the run
|
||||
started, so when that base commit is newer than your checkout's `origin/main`,
|
||||
the check fetches main once before it refuses. Otherwise `CI_CARRY` says
|
||||
`none (no_verified_run: … tree_mismatch)`, with a `CARRY_DIAGNOSIS:` line
|
||||
when the rule refused: dispatch Free Tests
|
||||
on the branch
|
||||
(`gh workflow run free-tests.yml --ref <branch>`), which tests HEAD's own tree,
|
||||
and wait again. When the pull_request run tested that merge commit, the
|
||||
|
||||
+29
-3
@@ -2955,9 +2955,35 @@ body plain: they become main's history.
|
||||
note each name a sha, so after any push, a merge of main included, land
|
||||
refuses until checks are green and `ready` has run at the new head (the
|
||||
receipt itself can [carry across a base merge](#carrying-a-receipt-across-a-base-merge-or-a-test-only-fix)).
|
||||
A `pull_request` CI run tests GitHub's merge commit rather than your branch,
|
||||
so on a branch behind main `gstack-ci-carry` reports `tree_mismatch`:
|
||||
dispatch the workflow on the branch (`gh workflow run <workflow> --ref <branch>`).
|
||||
A `pull_request` CI run tests GitHub's merge commit rather than your branch:
|
||||
your branch merged onto main as main was when the run started.
|
||||
- <a id="ci-carry-base-moved"></a>**A green run carries across a base move
|
||||
when only the base moved (GST-3567).** When main has moved past your
|
||||
branch's fork point, that merge commit's tree is not your head's tree. The
|
||||
lane carry (`gstack-ship-release accept`, `gstack-evidence record-ci`,
|
||||
`gstack-ci-carry`, and pregate's own carry and `clear --run`) still counts
|
||||
the green run for your head when the merge commit's parents are a commit on
|
||||
main and then your pushed head, and your pull request's own added and
|
||||
removed lines in that merge are byte-identical to your head's, at the same
|
||||
places (the zero-context patch-id and hunk positions `lib/review-round-grant.ts`
|
||||
`ownLinesSame` compares for a base-only merge of a reviewed head). Main may
|
||||
have changed other files, or other parts of the files you changed, but no
|
||||
line you changed and none next to one. The `CI_CARRY:` receipt
|
||||
then adds `base_moved=<main commit>`. This is safe for two reasons. The run
|
||||
tested exactly your pull request's changes, on a main newer than the one
|
||||
your head forked from, so it tested no less than a run of your head's own
|
||||
tree would have. And neither run tested the tree that lands: under
|
||||
`merge: direct`, [`land --pin`](#land-direct) checks that tree itself with
|
||||
`land.merged_ci` (CI on the pin merged onto the tip) and
|
||||
`land.merged_checks`, and its verification never takes this rule
|
||||
(`lib/land-merged-ci.ts` calls `verifyRun` without it). A repo whose `land`
|
||||
is `null` lands a stale base unchecked (`STALE_BASE: warn`) either way.
|
||||
The run still doesn't carry when main also changed a line your pull request
|
||||
changes or one next to it, when the merge is of a commit other than your pushed head, or when
|
||||
the run isn't green. A `CARRY_DIAGNOSIS:` line says which, and `tree_mismatch`
|
||||
keeps its fix: dispatch the workflow on the branch
|
||||
(`gh workflow run <workflow> --ref <branch>`), which tests your head's own
|
||||
tree, or, when it can't be dispatched, merge main and push.
|
||||
- <a id="ci-carry-rerun"></a>**A carried run that passed only after a re-run is marked, not refused.**
|
||||
When only a run's failed jobs were re-run, its `tree.json` may list
|
||||
`rerun_files` (the files whose newest result came from a re-run attempt) and
|
||||
|
||||
+10
-1
@@ -763,7 +763,16 @@ command `origin/<base>`'s `.gstack/pregate.json` maps in `ship_lanes_from`,
|
||||
and no verified CI run carries it at this tree: the `CI_CARRY: none
|
||||
label=<label> (<reason>)` line above the STOP says why (`no_run`: CI has not
|
||||
run this tree yet; `dirty_tree`: uncommitted work; `tree_mismatch`: the run
|
||||
tested a merge with an older base). A mapped lane is the full suite, which can
|
||||
tested a merge of the branch with main that counts for no commit here). A
|
||||
`pull_request` run that tested the branch merged onto a newer main still
|
||||
carries when only the base moved: the merge is of this pushed head, and the
|
||||
branch's own added and removed lines in it are byte-identical to the head's at
|
||||
the same places, so main changed no line the branch changes and none next to
|
||||
one. That is safe because the run tested
|
||||
exactly the branch's changes on a newer main, and land checks the tree that
|
||||
lands with `land.merged_ci` ([ship-policy.md](ship-policy.md#ci-carry-base-moved)).
|
||||
When that rule refuses, a `CARRY_DIAGNOSIS:` line says why: main also changed
|
||||
a line the branch changes or one next to it, or the merge is of another commit. A mapped lane is the full suite, which can
|
||||
take most of an hour on a small machine (gbrain #9662: a 50-minute unit lane on
|
||||
4 CPUs), so preflight never starts it on its own, whatever the reason (GST-3019;
|
||||
a full preflight did until GST-3277).
|
||||
|
||||
+7
-3
@@ -12,7 +12,9 @@
|
||||
* the lookup, so admitted dirty or untracked work never carries;
|
||||
* each run passes verifyRun (same-repository head, the profile's workflow,
|
||||
* event and jobs, the newest attempt, no newer red or running run on HEAD,
|
||||
* max age, the run's own tree.json naming HEAD's tree);
|
||||
* max age, the run's own tree.json naming HEAD's tree, or a pull_request
|
||||
* run's merge of HEAD onto a newer base commit with the pull request's own
|
||||
* lines byte-identical: only the base moved, onlyBaseMoved, GST-3567);
|
||||
* every run executed tests;
|
||||
* with an inventory command, the runs' tree.json files cover every file it
|
||||
* prints (a lane carries only what CI provably ran); with named jobs instead
|
||||
@@ -79,13 +81,15 @@ function newestVerified(src: RunSource, name: string, profile: RunProfile, heads
|
||||
const twins = heads.slice(1).map(h => h.slice(0, 12));
|
||||
if (!listed.length) return no('no_run', `no ${profile.workflow} run (${profile.events.join(', ')}) on ${heads[0]!.slice(0, 12)}${twins.length ? ` or on ${twins.join(', ')}, which git reads as the same tree` : ''} yet`);
|
||||
const refusals: string[] = [];
|
||||
const notMoved: string[] = [];
|
||||
const docsOnly = src.docsOnly && ((sha: string) => src.docsOnly!(sha) && (sha === heads[0] || src.docsOnly!(heads[0]!)));
|
||||
for (const run of listed) {
|
||||
const v = verifyRun(src.deps, { repo: src.repo, runRef: String(run.id), profileName: name, profile, vetoHeads: heads, now: src.now, unchanged: src.unchanged, docsOnly, dispatchable: src.dispatchable?.(profile) });
|
||||
const v = verifyRun(src.deps, { repo: src.repo, runRef: String(run.id), profileName: name, profile, vetoHeads: heads, now: src.now, unchanged: src.unchanged, docsOnly, dispatchable: src.dispatchable?.(profile), onlyBaseMoved: src.onlyBaseMoved });
|
||||
if (v.ok) return v;
|
||||
refusals.push(`run ${run.id}: ${v.reason}${v.reason === 'rerun_malformed' || v.reason === 'tree_log_unbound' || (v.reason === 'artifact_missing' && profile.tree_log_step) ? ` (${v.detail})` : ''}${v.fix ? ` (the pull request's base moved after the run; fix: ${v.fix})` : ''}`);
|
||||
if (v.notMoved) notMoved.push(`run ${run.id} tested a merge onto a newer base, but it does not count for the head: ${v.notMoved} (docs/pregate.md#base-moved-carry)`);
|
||||
}
|
||||
return no('no_verified_run', `${name}: ${refusals.join('; ')}`);
|
||||
return { ...no('no_verified_run', `${name}: ${refusals.join('; ')}`), ...(notMoved.length ? { diagnosis: notMoved } : {}) };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ import { baseBranchOf, baseMismatchFix, describeSubstitution, substituteStampOnl
|
||||
import { EXCEPTION_RECEIPT, exceptionProblem, exceptionSummary, flakyDecision, flakyRuns, parseCases, redRunChanged, type FailureDeps, type FlakyInput } from './flaky-exception';
|
||||
import { buildRunCheck } from './run-check';
|
||||
import { resolveBaseBranch } from '../ship-policy';
|
||||
import { parseRunReceipt, parseRunRef, runChanged, runReceiptFields, uncoveredFiles, verifyRun, type ApiJob, type ApiRun, type RemoteGateRuns, type RunDeps, type RunEvidence, type RunProfile } from '../run-evidence';
|
||||
import { parseRunReceipt, parseRunRef, runChanged, runReceiptFields, uncoveredFiles, verifyRun, type ApiJob, type ApiRun, type BaseMove, type RemoteGateRuns, type RunDeps, type RunEvidence, type RunProfile } from '../run-evidence';
|
||||
import type { CheckDef, CheckResult, PregateContext, Stage } from './types';
|
||||
import { displayNamePattern, workflowCallers } from './workflows';
|
||||
|
||||
@@ -285,7 +285,7 @@ function userPolicyChange(file: PregateFile): string | null {
|
||||
|
||||
export interface ClearInput { runUrl?: string; bundleLane?: string; receiptPath?: string; runs?: string[]; evidence?: RunCheck; flaky?: FlakyInput; allowRepoCommands?: boolean; /** The branch whose run profiles `evidence` holds (gstack-pregate clear: the record's own); absent, origin/HEAD's. */ base?: string }
|
||||
/** What a run clear needs: the base branch's run profiles, the verifier's dependencies, the clock, and the remote gate's inventory. */
|
||||
export interface RunCheck { repo: string; deps: RunDeps; profiles: Record<string, RunProfile>; gateRuns: RemoteGateRuns | null; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: (p: RunProfile) => boolean; inventory: (command: string, tree: string, selected?: string[]) => string[] | { error: string }; failures?: FailureDeps }
|
||||
export interface RunCheck { repo: string; deps: RunDeps; profiles: Record<string, RunProfile>; gateRuns: RemoteGateRuns | null; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: (p: RunProfile) => boolean; onlyBaseMoved?: (merge: string, head: string) => BaseMove; inventory: (command: string, tree: string, selected?: string[]) => string[] | { error: string }; failures?: FailureDeps }
|
||||
export type ClearDecision = { receipt: string; attested: boolean; substitution?: PregateReceiptSubstitution; exception?: PregateException } | { refused: 'usage' | 'PREGATE_RECEIPT_INVALID'; message: string; fix?: string };
|
||||
|
||||
/**
|
||||
@@ -430,7 +430,7 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
|
||||
const verdicts = new Map<string, ReturnType<typeof verifyRun>>();
|
||||
const verdict = (name: string, ref: string) => {
|
||||
const key = `${name}\0${ref}`;
|
||||
if (!verdicts.has(key)) verdicts.set(key, verifyRun(check.deps, { repo: check.repo, runRef: ref, profileName: name, profile: check.profiles[name]!, vetoHeads: file.head ? [file.head] : [], now: check.now }));
|
||||
if (!verdicts.has(key)) verdicts.set(key, verifyRun(check.deps, { repo: check.repo, runRef: ref, profileName: name, profile: check.profiles[name]!, vetoHeads: file.head ? [file.head] : [], now: check.now, onlyBaseMoved: check.onlyBaseMoved }));
|
||||
return verdicts.get(key)!;
|
||||
};
|
||||
const missingProfile = names.find(name => !check.profiles[name]);
|
||||
|
||||
@@ -11,7 +11,8 @@ import { spawnSync } from '../spawn-sync';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ghArtifactDeps, ghRunDeps, runInventory, type RunProfile } from '../run-evidence';
|
||||
import { ghArtifactDeps, ghRunDeps, runInventory, type BaseMove, type RunProfile } from '../run-evidence';
|
||||
import { ownLinesSame } from '../review-round-grant';
|
||||
import { classifyDocsOnly } from '../docs-only';
|
||||
import { wtreeFingerprint } from '../script-invocation';
|
||||
import { resolveBaseBranch } from '../ship-policy';
|
||||
@@ -58,6 +59,34 @@ export function gateInputsChanged(root: string, base: string, p: RunProfile): st
|
||||
return null;
|
||||
}
|
||||
|
||||
const SHA = /^[0-9a-f]{40}$/;
|
||||
const refreshedBases = new Set<string>();
|
||||
|
||||
/**
|
||||
* Whether pull_request merge commit `merge` is `head` merged onto a newer commit of the base with only the base moved (GST-3567):
|
||||
* its parents are a commit on `baseRef` and then `head`, and the pull request's own added and removed lines in the merge are
|
||||
* byte-identical to the head's own, at the same places (ownLinesSame, the rule a base-only merge of a reviewed head meets). So
|
||||
* the run that tested the merge tested exactly the pull request's changes, on a newer base. GitHub merges onto the base as it was
|
||||
* when the run started, often newer than this checkout's `origin/<base>`, so a base parent missing from it fetches that branch
|
||||
* once per process before refusing.
|
||||
*/
|
||||
export function onlyBaseMoved(root: string, o: { merge: string; head: string; baseRef: string }): BaseMove {
|
||||
const git = (args: string[], timeout = 30_000) => spawnSync('git', args, { cwd: root, encoding: 'utf8', timeout });
|
||||
const listed = git(['rev-list', '--parents', '-n', '1', o.merge]);
|
||||
const parents = listed.status === 0 ? (listed.stdout ?? '').trim().split(' ').slice(1) : [];
|
||||
if (parents.length !== 2 || parents[1] !== o.head || !SHA.test(parents[0]!)) return { ok: false, why: `merge commit ${o.merge.slice(0, 12)} is not a base commit merged with the head ${o.head.slice(0, 12)} (its parents: ${parents.map(p => p.slice(0, 12)).join(', ') || 'none'})` };
|
||||
const base = parents[0]!;
|
||||
const onBase = () => git(['merge-base', '--is-ancestor', base, o.baseRef]).status === 0;
|
||||
const branch = o.baseRef.startsWith('origin/') ? o.baseRef.slice('origin/'.length) : null;
|
||||
if (!onBase() && branch && !refreshedBases.has(`${root}\0${branch}`)) {
|
||||
refreshedBases.add(`${root}\0${branch}`);
|
||||
git(['fetch', '--quiet', '--no-tags', 'origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`], 120_000);
|
||||
}
|
||||
if (!onBase()) return { ok: false, why: `its base parent ${base.slice(0, 12)} is not on ${o.baseRef}${branch ? ', even after fetching it' : ''}` };
|
||||
if (!ownLinesSame(root, o.baseRef, o.head, o.merge)) return { ok: false, why: `the pull request's own added and removed lines in the tested merge are not byte-identical to the head's at the same places (the base edited a line the pull request changes, or one next to it), so more than the base moved` };
|
||||
return { ok: true, base };
|
||||
}
|
||||
|
||||
/**
|
||||
* `profiled` says whether `lane` may have a run profile: an unreadable base counts as profiled, so a lane is
|
||||
* recorded unverified only once the base shows it has none. `policy: 'head'` reads the branch's profiles instead, only
|
||||
@@ -74,6 +103,7 @@ export function buildRunCheck(root: string, lane: string | null, allowRepoComman
|
||||
repo, deps: ghRunDeps(repo, root), failures: ghArtifactDeps(repo), profiles: loaded.config.run_profiles, gateRuns: loaded.config.remote_gate_runs, now: new Date(),
|
||||
unchanged: p => gateInputsChanged(root, base, p),
|
||||
dispatchable: p => canDispatch(root, policy === 'head' ? 'HEAD' : `origin/${base}`, p),
|
||||
onlyBaseMoved: (merge, head) => onlyBaseMoved(root, { merge, head, baseRef: `origin/${base}` }),
|
||||
docsOnly: head => {
|
||||
const mb = spawnSync('git', ['merge-base', `origin/${base}`, head], { cwd: root, encoding: 'utf8', timeout: 30_000 });
|
||||
try { return mb.status === 0 && classifyDocsOnly({ root, base: mb.stdout.trim(), head, policyRef: `origin/${base}` }).docsOnly; } catch { return false; }
|
||||
|
||||
+24
-12
@@ -27,7 +27,12 @@
|
||||
* (run_changed otherwise). A pull_request run tested GitHub's merge commit,
|
||||
* not its head, so it counts only when its tree.json names that head and a
|
||||
* merge commit (sha) whose tree git computes equal to the head's tree: the
|
||||
* head already contained its base, so the merge tested the head tree.
|
||||
* head already contained its base, so the merge tested the head tree. A lane
|
||||
* carry (the caller passes onlyBaseMoved, GST-3567) also counts it when the
|
||||
* merge commit is the head merged onto a commit of the base branch and the
|
||||
* pull request's own added and removed lines in it are byte-identical to the
|
||||
* head's own (lib/pregate/run-check.ts onlyBaseMoved):
|
||||
* only the base moved. Land's merged-tree CI never passes it.
|
||||
*
|
||||
* Profiles are the base branch's `.gstack/pregate.json` `run_profiles`, so a
|
||||
* pull request can tighten them but never relax them. The workflow a run
|
||||
@@ -95,9 +100,12 @@ export type RunRefusal = 'run_ref_invalid' | 'other_repository' | 'fork_run' | '
|
||||
/** `docs_only`: a pull_request run whose gate skipped every skippable job on a change lib/docs-only.ts calls human docs only; it ran and recorded no tests (R81). */
|
||||
/** `tree_source`: `job-log` when tree.json came from the job log because the run held no artifact (HARN-118); absent for an artifact. */
|
||||
/** `rerun`: the files whose newest result came from a re-run attempt (tree.json `rerun_files`, gbrain#9690), with the run's `attempts`; set only when a file passed on a re-run (GST-3054). */
|
||||
export interface RunEvidence { run_id: number; run_attempt: number; head_sha: string; tree: string; profile: string; event: string; finished_at: string; files: string[]; tests: number | null; skipped?: string[]; skipped_jobs?: string[]; docs_only?: true; rerun?: string[]; attempts?: number[]; tree_source?: 'job-log' }
|
||||
/** `fix`: the one command that clears a refusal the caller can repair, such as a pull_request run that tested a merge with an older base. */
|
||||
export type RunVerdict = { ok: true; evidence: RunEvidence } | { ok: false; reason: RunRefusal; detail: string; fix?: string };
|
||||
/** `base_moved`: the pull_request run tested its head merged onto `base`, a newer base commit, with the pull request's own lines byte-identical (lib/pregate/run-check.ts onlyBaseMoved, GST-3567); `tree` is then the head's tree it counts for and `tested_tree` the merge's. */
|
||||
export interface RunEvidence { run_id: number; run_attempt: number; head_sha: string; tree: string; profile: string; event: string; finished_at: string; files: string[]; tests: number | null; skipped?: string[]; skipped_jobs?: string[]; docs_only?: true; rerun?: string[]; attempts?: number[]; tree_source?: 'job-log'; base_moved?: { merge: string; base: string; tested_tree: string } }
|
||||
/** `fix`: the one command that clears a refusal the caller can repair, such as a pull_request run that tested a merge with an older base. `notMoved`: why onlyBaseMoved did not count that run for its head. */
|
||||
export type RunVerdict = { ok: true; evidence: RunEvidence } | { ok: false; reason: RunRefusal; detail: string; fix?: string; notMoved?: string };
|
||||
/** What lib/pregate/run-check.ts onlyBaseMoved decides about a pull_request run's merge commit (GST-3567): the base it merged onto, or why it does not count for the head. */
|
||||
export type BaseMove = { ok: true; base: string } | { ok: false; why: string };
|
||||
|
||||
const SHA = /^[0-9a-f]{40}$/;
|
||||
const RUN_EVENTS = ['push', 'workflow_dispatch', 'pull_request'];
|
||||
@@ -184,7 +192,7 @@ export const normalPath = (f: string): string => f.replace(/^(\.\/)+/, '');
|
||||
* The verdict for run `runRef` under `profile`. `vetoHeads` are further heads
|
||||
* whose newer runs of the same workflow can veto (the consumer's own head).
|
||||
*/
|
||||
export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; profileName: string; profile: RunProfile; vetoHeads?: string[]; ignoreRun?: number; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: boolean }): RunVerdict {
|
||||
export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; profileName: string; profile: RunProfile; vetoHeads?: string[]; ignoreRun?: number; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: boolean; onlyBaseMoved?: (merge: string, head: string) => BaseMove }): RunVerdict {
|
||||
const id = parseRunRef(o.runRef, o.repo);
|
||||
if (id === null) return fail('run_ref_invalid', `${JSON.stringify(o.runRef)} is not a run id or a run URL on ${o.repo}`);
|
||||
const p = o.profile;
|
||||
@@ -258,12 +266,15 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof
|
||||
const baseMoved = o.dispatchable === false
|
||||
? `push a merge of the base to ${run.head_branch || '<branch>'}, or ask the pull request's author to (${p.workflow} cannot be dispatched for this run profile), then gstack-ci-carry wait`
|
||||
: `gh workflow run ${p.workflow} --ref ${run.head_branch || '<branch>'}, then gstack-ci-carry wait`;
|
||||
let moved: RunEvidence['base_moved'];
|
||||
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 (!testedMerge) return fail('tree_mismatch', `${at} recorded tree ${String(rec.tree)}, but its head ${run.head_sha.slice(0, 12)} has tree ${headTree}`);
|
||||
const m = o.onlyBaseMoved?.(rec.sha as string, run.head_sha);
|
||||
if (!m?.ok) 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)${m ? `; it does not count for the head because ${m.why}` : ''}`, baseMoved), ...(m ? { notMoved: m.why } : {}) };
|
||||
moved = { merge: rec.sha as string, base: m.base, tested_tree: rec.tree as string };
|
||||
}
|
||||
if (pr) {
|
||||
if (pr && !moved) {
|
||||
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}`);
|
||||
@@ -283,7 +294,7 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof
|
||||
const skipped = rec.skipped_files === undefined ? {} : { skipped: (rec.skipped_files as string[]).map(normalPath) };
|
||||
const rerun = ((rec.rerun_files ?? []) as string[]).map(normalPath);
|
||||
const reran = rerun.length ? { rerun, attempts: [...new Set((rec.attempts ?? []) as number[])].sort((a, b) => a - b) } : {};
|
||||
return { ok: true, evidence: { run_id: id, run_attempt: run.run_attempt, head_sha: run.head_sha, tree: headTree, profile: o.profileName, event: run.event, finished_at: finishedAt!, files, tests, ...skipped, ...(skippedJobs.length ? { skipped_jobs: skippedJobs } : {}), ...reran, ...(fromLog ? { tree_source: 'job-log' as const } : {}) } };
|
||||
return { ok: true, evidence: { run_id: id, run_attempt: run.run_attempt, head_sha: run.head_sha, tree: headTree, profile: o.profileName, event: run.event, finished_at: finishedAt!, files, tests, ...skipped, ...(skippedJobs.length ? { skipped_jobs: skippedJobs } : {}), ...reran, ...(fromLog ? { tree_source: 'job-log' as const } : {}), ...(moved ? { base_moved: moved } : {}) } };
|
||||
} catch (e: any) {
|
||||
return fail('api_error', `reading run ${id} failed: ${String(e?.message ?? e).slice(0, 300)}`);
|
||||
}
|
||||
@@ -383,7 +394,8 @@ export function uncoveredFiles(inventory: string[], evidence: RunEvidence[], ski
|
||||
|
||||
/** What a run check reads: the repository, the verifier's dependencies, the base branch's profiles and the clock. */
|
||||
/** `unchanged` (findCarry only): null when a profile's workflow and gate inputs match the base, else which file differs. */
|
||||
export interface RunSource { repo: string; deps: RunDeps; profiles: Record<string, RunProfile>; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: (p: RunProfile) => boolean }
|
||||
/** `onlyBaseMoved`: onlyBaseMoved bound to the checkout and its base branch, so a lane carry counts a run whose base moved (GST-3567). */
|
||||
export interface RunSource { repo: string; deps: RunDeps; profiles: Record<string, RunProfile>; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; dispatchable?: (p: RunProfile) => boolean; onlyBaseMoved?: (merge: string, head: string) => BaseMove }
|
||||
export type FromRunVerdict = { ok: true; evidence: RunEvidence; receipt: string } | { ok: false; reason: string; detail: string };
|
||||
|
||||
/**
|
||||
@@ -395,7 +407,7 @@ export function verifyFromRun(src: RunSource, ref: string, names: string[], tree
|
||||
if (!names.length) return { ok: false, reason: 'no_profile', detail: 'the base branch declares no run_profiles entry for this machine\'s OS whose workflow holds a lane this machine runs (gstack\'s ci-reuse/free-tests, for example)' };
|
||||
const refusals: Array<{ reason: string; detail: string }> = [];
|
||||
for (const name of names) {
|
||||
const v = verifyRun(src.deps, { repo: src.repo, runRef: ref, profileName: name, profile: src.profiles[name]!, vetoHeads: SHA.test(head) ? [head] : [], now: src.now });
|
||||
const v = verifyRun(src.deps, { repo: src.repo, runRef: ref, profileName: name, profile: src.profiles[name]!, vetoHeads: SHA.test(head) ? [head] : [], now: src.now, onlyBaseMoved: src.onlyBaseMoved });
|
||||
if (!v.ok) { refusals.push({ reason: v.reason, detail: `${name}: ${v.detail}` }); continue; }
|
||||
const e = v.evidence;
|
||||
if (e.tree !== tree) return { ok: false, reason: 'tree_mismatch', detail: `run ${e.run_id} tested tree ${e.tree.slice(0, 12)}, not this tree ${tree.slice(0, 12)}` };
|
||||
@@ -410,7 +422,7 @@ export function verifyFromRun(src: RunSource, ref: string, names: string[], tree
|
||||
* whose files passed only on a re-run adds `rerun=<files> attempts=<list>` (GST-3054): allowed, but never shown as a clean pass.
|
||||
*/
|
||||
export function runReceiptFields(evidence: RunEvidence[], now: Date): string {
|
||||
return `runs=${evidence.map(e => `${e.run_id}/${e.run_attempt}`).join(',')} profiles=${evidence.map(e => e.profile).join(',')} heads=${[...new Set(evidence.map(e => e.head_sha.slice(0, 12)))].join(',')}${rerunMarker([...rerunByRun(evidence).values()])}${evidence.some(e => e.tree_source === 'job-log') ? ' tree_source=job-log' : ''} verified=${now.toISOString()}`;
|
||||
return `runs=${evidence.map(e => `${e.run_id}/${e.run_attempt}`).join(',')} profiles=${evidence.map(e => e.profile).join(',')} heads=${[...new Set(evidence.map(e => e.head_sha.slice(0, 12)))].join(',')}${rerunMarker([...rerunByRun(evidence).values()])}${evidence.some(e => e.tree_source === 'job-log') ? ' tree_source=job-log' : ''}${evidence.some(e => e.base_moved) ? ` base_moved=${[...new Set(evidence.flatMap(e => (e.base_moved ? [e.base_moved.base.slice(0, 12)] : [])))].join(',')}` : ''} verified=${now.toISOString()}`;
|
||||
}
|
||||
|
||||
/** The re-run record per carried run (`<id>/<attempt>`): the distinct re-run files and attempts across every profile that read that run, so two profiles on one run count each file once. */
|
||||
|
||||
@@ -460,6 +460,10 @@ export const KNOWN_WINDOWS_INCOMPATIBLE: Array<{ file: string; reason: string }>
|
||||
file: 'test/ship-accept-record-timeout.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-evidence, gstack-ship-policy and gstack-pregate (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-accept-head-policy.test.ts, which windows-latest fails at the first bin spawn (windows-scoped-shard, run 41607840098)',
|
||||
},
|
||||
{
|
||||
file: 'test/ship-accept-base-moved.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-ci-carry, gstack-evidence and gstack-pregate (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-accept-record-timeout.test.ts, which windows-latest fails at the first bin spawn (windows-scoped-shard, run 41607840098)',
|
||||
},
|
||||
{
|
||||
file: 'test/ship-mechanical-retake.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-review-plan, gstack-ship-receipt, gstack-docs-candidate and gstack-wtree (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-finish-stack-parent.test.ts; windows-latest fails every case at the first bin spawn (windows-scoped-shard, run 42156939158)',
|
||||
|
||||
@@ -69,6 +69,25 @@ describe.skipIf(process.platform === 'win32')('CI carry clears the remote gate o
|
||||
expect(file.verdict).toBe('requires-remote cleared');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=clear --run (clearByRuns) takes the base-moved rule from its RunCheck, as the lane carry does (GST-3567);
|
||||
// fails_when=clearByRuns stops forwarding onlyBaseMoved, so pregate refuses a run accept counted; seam=RunCheck.onlyBaseMoved stub
|
||||
test('clear --run counts a pull_request run whose base moved only through the check\'s onlyBaseMoved', async () => {
|
||||
const repo = fixture();
|
||||
const check = runCheck(repo, FREE);
|
||||
const { file } = await carried(repo, check);
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const tested = repo.git('rev-parse', 'HEAD~1^{tree}');
|
||||
const merge = repo.git('commit-tree', tested, '-p', 'HEAD', '-m', 'test merge');
|
||||
const pr = { ...check, deps: { ...check.deps, run: () => ({ ...check.deps.run(100), event: 'pull_request' }), artifact: () => ({ ...check.deps.artifact(100, 'tested-tree', 1), event: 'pull_request', sha: merge, head_sha: head, tree: tested }) } } as RunCheck;
|
||||
const reopened = { ...file, requires_remote: [{ ...gate(file)!, receipt: null }] };
|
||||
expect(clearDecision(reopened, LANE, { runs: ['100'], evidence: pr }, repo.work)).toMatchObject({ refused: 'PREGATE_RECEIPT_INVALID', message: expect.stringContaining('reason=tree_mismatch') });
|
||||
const calls: string[][] = [];
|
||||
const moved = { ...pr, onlyBaseMoved: (m: string, h: string) => { calls.push([m, h]); return { ok: true as const, base: head }; } } as RunCheck;
|
||||
const d = clearDecision(reopened, LANE, { runs: ['100'], evidence: moved }, repo.work);
|
||||
expect(calls).toEqual([[merge, head]]);
|
||||
expect(d).toMatchObject({ refused: 'PREGATE_RECEIPT_INVALID', message: expect.stringContaining('reason=paid_only') });
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the carry clears the gate only under clear --run's own checks; fails_when=a run that misses an inventory file clears it
|
||||
test('a run that misses a gate inventory file leaves the gate uncleared and says why', async () => {
|
||||
const repo = fixture();
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* GST-3567 (harness-evals #576): under direct landing, a pull_request run tests GitHub's merge of the head onto the base as
|
||||
* it was when the run started. When main moved past the head's fork point, that merge's tree is not the head's tree, so
|
||||
* accept refused CI_CARRY tree_mismatch and the lane had to merge main and run CI again, which never converges on a busy
|
||||
* repo. A green run still counts for the head when the merge commit is the head merged onto a base commit and the pull
|
||||
* request's own added and removed lines in it are byte-identical to the head's, at the same places: only the base moved. Land checks the tree that
|
||||
* lands (land.merged_ci), and its verify never takes this rule.
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { onlyBaseMoved } from '../lib/pregate/run-check';
|
||||
import { verifyRun, type ApiRun, type RunDeps, type RunProfile, type TreeRecord } from '../lib/run-evidence';
|
||||
import { fakeGhScript, type FakeWorld } from './helpers/fake-gh-runs';
|
||||
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(120_000);
|
||||
const BIN = path.dirname(RELEASE);
|
||||
const fixtures: ShipFx[] = [];
|
||||
afterEach(() => { while (fixtures.length) fixtures.pop()!.cleanup(); });
|
||||
|
||||
const FREE = "printf x >> ../free-runs; printf ' 3 pass\\n 0 fail\\nRan 3 tests across 1 file. [1.00ms]\\n' >&2";
|
||||
const PROFILE: RunProfile = { workflow: 'free.yml', events: ['pull_request', 'workflow_dispatch'], jobs: ['suite'], artifact: 'tested-tree', os: 'Linux' };
|
||||
const BASE = {
|
||||
'.gstack/pregate.json': JSON.stringify({ run_profiles: { 'ci/free': PROFILE }, ship_lanes_from: { [FREE]: { profiles: ['ci/free'], inventory: "printf 'test/a.test.ts\\ntest/b.test.ts\\n'" } } }, null, 2) + '\n',
|
||||
'.github/workflows/free.yml': 'name: Free\non: [pull_request, workflow_dispatch]\njobs:\n suite:\n runs-on: ubuntu-latest\n steps:\n - run: bun test\n',
|
||||
'src/b.ts': 'export const b = 1;\n// two\n// three\n// four\n// five\n// six\n// seven\n// eight\n',
|
||||
};
|
||||
const FEAT = { 'src/b.ts': 'export const b = 2;\n// two\n// three\n// four\n// five\n// six\n// seven\n// eight\n' };
|
||||
/** main's edit to the pull request's own file: far from its line 1 (#4722's shape: both edited docs/troubleshooting.md), or right next to it. */
|
||||
const FAR = { 'src/b.ts': 'export const b = 1;\n// two\n// three\n// four\n// five\n// six\n// seven\n// eight, edited on main\n' };
|
||||
const NEXT_TO = { 'src/b.ts': 'export const b = 1;\n// two, edited on main\n// three\n// four\n// five\n// six\n// seven\n// eight\n' };
|
||||
const at = (minutesAgo: number) => new Date(Date.now() - minutesAgo * 60_000).toISOString();
|
||||
const sha = (f: ShipFx, ref: string) => f.git('rev-parse', ref).stdout.trim();
|
||||
const runs = (f: ShipFx) => { const p = path.join(f.root, 'free-runs'); return fs.existsSync(p) ? fs.readFileSync(p, 'utf8').length : 0; };
|
||||
|
||||
/** feat pushed at HEAD, then main moves under it with `baseFiles` (src/c.ts by default), as it did under #576. */
|
||||
function behind(baseFiles: Record<string, string> = { 'src/c.ts': 'export const c = 3;\n' }): ShipFx {
|
||||
const f = shipFixture(BASE, FEAT);
|
||||
fixtures.push(f);
|
||||
expect(f.run(RELEASE, ['push', '--branch', 'feat', '--early', '--base', 'main'], { GSTACK_SESSION_KIND: 'unattended' }).status).toBe(0);
|
||||
f.advanceBase(baseFiles);
|
||||
expect(f.git('fetch', '-q', 'origin', 'main').status).toBe(0);
|
||||
return f;
|
||||
}
|
||||
|
||||
/** GitHub's test merge commit for a pull_request run: the base first, the head second (#576's 2c6b624d: parents 0f7b4003, 2a5e69c4). */
|
||||
function mergeCommit(f: ShipFx, head = sha(f, 'HEAD'), o: { tree?: string } = {}): { merge: string; tree: string } {
|
||||
const tree = o.tree ?? f.git('merge-tree', '--write-tree', 'origin/main', head).stdout.trim().split('\n')[0]!;
|
||||
const merge = f.git('commit-tree', tree, '-p', 'origin/main', '-p', head, '-m', `Merge ${head} into ${sha(f, 'origin/main').slice(0, 8)}`).stdout.trim();
|
||||
return { merge, tree };
|
||||
}
|
||||
|
||||
/** One green pull_request run of free.yml at HEAD (id 7) whose tree.json records the merge it tested, as #576's run 45058890128 did. */
|
||||
function prRun(f: ShipFx, m: { merge: string; tree: string }, over: { run?: Record<string, unknown> } = {}): void {
|
||||
const head = sha(f, 'HEAD');
|
||||
const run = { id: 7, run_attempt: 1, status: 'completed', conclusion: 'success', event: 'pull_request', head_sha: head, head_branch: 'feat', path: '.github/workflows/free.yml', created_at: at(20), run_started_at: at(20), updated_at: at(5), repository: { full_name: 'fx/fx' }, head_repository: { full_name: 'fx/fx' }, ...over.run };
|
||||
const w: FakeWorld = {
|
||||
runs: [run] as FakeWorld['runs'],
|
||||
jobs: { 7: [{ name: 'suite', conclusion: over.run?.conclusion === 'failure' ? 'failure' : 'success', completed_at: at(5) }] },
|
||||
trees: { 7: { run_id: 7, run_attempt: 1, event: 'pull_request', sha: m.merge, head_sha: head, tree: m.tree, files: ['test/a.test.ts', 'test/b.test.ts'], tests: 12, os: 'Linux' } },
|
||||
};
|
||||
fs.writeFileSync(path.join(f.root, 'world.json'), JSON.stringify(w));
|
||||
f.gh(fakeGhScript(path.join(f.root, 'world.json')));
|
||||
}
|
||||
const accept = (f: ShipFx) => f.run(RELEASE, ['accept', '--base', 'main', '--lane', `free=${FREE}`, '--wait', '0']);
|
||||
const lane = (out: string) => out.split('\n').find(l => l.startsWith('LANE: free ')) ?? '';
|
||||
|
||||
describe('accept carries a run whose base moved when the pull request\'s own changes are byte-identical (GST-3567)', () => {
|
||||
// Value: protects=#576's shape carries: a green pull_request run at the pushed head that tested the head merged onto a newer main, with the
|
||||
// pull request's own diff byte-identical, carries the lane and the final pregate without a local run or a fresh CI run;
|
||||
// fails_when=accept refuses tree_mismatch and the lane merges main and reruns CI forever; seam=fake gh, real git merge commit
|
||||
test('the #576 shape: accept carries the lane and the final pregate from the run, and nothing runs here', () => {
|
||||
const f = behind();
|
||||
const m = mergeCommit(f);
|
||||
expect(m.tree).not.toBe(sha(f, 'HEAD^{tree}'));
|
||||
prRun(f, m);
|
||||
const ok = accept(f);
|
||||
expect([ok.status, lane(ok.stdout)], ok.stdout + ok.stderr).toEqual([0, 'LANE: free carried run=7/1 tests_ran=2 (files)']);
|
||||
expect(lineOf(ok.stdout, 'EVIDENCE')).toMatch(/^EVIDENCE: FRESH label=free .* source=ci runs=7\/1$/);
|
||||
expect(lineOf(ok.stdout, 'CI_CARRY')).toMatch(new RegExp(`^CI_CARRY: accepted ci-carry tree=${sha(f, 'HEAD^{tree}').slice(0, 12)} .*runs=7/1 .* base_moved=${sha(f, 'origin/main').slice(0, 12)} `));
|
||||
expect(ok.stdout).toMatch(/^PREGATE: (pass|warn)\b.* \(final tree\)$/m);
|
||||
expect(runs(f)).toBe(0);
|
||||
const found = f.run(path.join(BIN, 'gstack-ci-carry'), ['find', '--base', 'main']);
|
||||
expect([found.status, found.stdout]).toEqual([0, expect.stringMatching(/^CI_CARRY: accepted ci-carry tree=.* base_moved=/)]);
|
||||
});
|
||||
|
||||
// Value: protects=main editing another part of a file the pull request also changes still carries: the pull request's own lines are
|
||||
// byte-identical at the same places (#4722's run 45089670503: main and the PR both edited docs/troubleshooting.md); fails_when=the
|
||||
// rule compares whole files and refuses; seam=fake gh, real git merge commit
|
||||
test('main edited another part of the pull request\'s own file: the run still carries', () => {
|
||||
const f = behind(FAR);
|
||||
prRun(f, mergeCommit(f));
|
||||
const found = f.run(path.join(BIN, 'gstack-ci-carry'), ['find', '--base', 'main']);
|
||||
expect([found.status, found.stdout]).toEqual([0, expect.stringMatching(/^CI_CARRY: accepted ci-carry tree=.* base_moved=/)]);
|
||||
});
|
||||
|
||||
// Value: protects=the negative controls: a merge whose pull-request side differs from the head (a conflict resolution, another head),
|
||||
// a base that also edited the pull request's own file, and a red run never carry; fails_when=any of them carries; seam=fake gh, real git
|
||||
test('the pull request\'s own lines differ: an edited merge, or main editing the line next to the pull request\'s, refuses tree_mismatch', () => {
|
||||
const f = behind();
|
||||
const clean = mergeCommit(f);
|
||||
f.git('read-tree', clean.tree);
|
||||
const blob = spawnSync('git', ['hash-object', '-w', '--stdin'], { cwd: f.work, input: 'export const b = 99;\n', encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
f.git('update-index', '--cacheinfo', `100644,${blob},src/b.ts`);
|
||||
const edited = f.git('write-tree').stdout.trim();
|
||||
f.git('read-tree', 'HEAD');
|
||||
prRun(f, mergeCommit(f, sha(f, 'HEAD'), { tree: edited }));
|
||||
const out = f.run(path.join(BIN, 'gstack-ci-carry'), ['find', '--base', 'main']).stdout;
|
||||
expect(out).toContain("tree_mismatch (the pull request's base moved after the run; fix: gh workflow run free.yml --ref feat, then gstack-ci-carry wait))");
|
||||
expect(out).toContain("CARRY_DIAGNOSIS: run 7 tested a merge onto a newer base, but it does not count for the head: the pull request's own added and removed lines in the tested merge are not byte-identical to the head's at the same places (the base edited a line the pull request changes, or one next to it), so more than the base moved (docs/pregate.md#base-moved-carry)");
|
||||
expect(out).not.toContain('CI_CARRY: accepted');
|
||||
|
||||
const g = behind(NEXT_TO);
|
||||
const both = mergeCommit(g);
|
||||
expect(both.tree).toMatch(/^[0-9a-f]{40}$/);
|
||||
prRun(g, both);
|
||||
const refused = accept(g);
|
||||
expect(refused.status).not.toBe(0);
|
||||
expect(refused.stdout).toContain('CI_CARRY: none label=free (no_verified_run: ci/free: run 7: tree_mismatch');
|
||||
expect(refused.stdout).toContain("CARRY_DIAGNOSIS: run 7 tested a merge onto a newer base, but it does not count for the head: the pull request's own added and removed lines in the tested merge are not byte-identical");
|
||||
expect(runs(g)).toBe(0);
|
||||
});
|
||||
|
||||
test('the run tested another head: a merge of an earlier commit of the branch refuses tree_mismatch', () => {
|
||||
const f = behind();
|
||||
const earlier = sha(f, 'HEAD');
|
||||
f.write({ 'src/d.ts': 'export const d = 4;\n' });
|
||||
f.commit('second feat commit');
|
||||
expect(f.run(RELEASE, ['push', '--branch', 'feat', '--early', '--base', 'main'], { GSTACK_SESSION_KIND: 'unattended' }).status).toBe(0);
|
||||
prRun(f, mergeCommit(f, earlier));
|
||||
const out = f.run(path.join(BIN, 'gstack-ci-carry'), ['find', '--base', 'main']).stdout;
|
||||
expect(out).toContain('it does not count for the head: merge commit ');
|
||||
expect(out).toContain(' is not a base commit merged with the head ' + sha(f, 'HEAD').slice(0, 12) + ' (its parents: ');
|
||||
expect(out).not.toContain('CI_CARRY: accepted');
|
||||
});
|
||||
|
||||
test('a red run never carries, whatever its merge', () => {
|
||||
const f = behind();
|
||||
prRun(f, mergeCommit(f), { run: { conclusion: 'failure' } });
|
||||
const red = accept(f);
|
||||
expect(red.status).not.toBe(0);
|
||||
expect(red.stdout).toContain('STOP: free.yml run 7 failed (suite)');
|
||||
expect(f.run(path.join(BIN, 'gstack-ci-carry'), ['find', '--base', 'main']).stdout).not.toContain('CI_CARRY: accepted');
|
||||
});
|
||||
});
|
||||
|
||||
describe('only lane carries take the rule; land\'s merged-tree CI never does (GST-3567)', () => {
|
||||
/** In-process RunDeps over the fixture's git, serving the one pull_request run. */
|
||||
function deps(f: ShipFx, m: { merge: string; tree: string }): RunDeps {
|
||||
const head = sha(f, 'HEAD');
|
||||
const run: ApiRun = { id: 7, run_attempt: 1, status: 'completed', conclusion: 'success', event: 'pull_request', head_sha: head, head_branch: 'feat', path: '.github/workflows/free.yml', created_at: at(20), run_started_at: at(20), updated_at: at(5), repository: { full_name: 'fx/fx' }, head_repository: { full_name: 'fx/fx' } };
|
||||
const rec: TreeRecord = { run_id: 7, run_attempt: 1, event: 'pull_request', sha: m.merge, head_sha: head, tree: m.tree, files: ['test/a.test.ts'], tests: 3, os: 'Linux' };
|
||||
return {
|
||||
run: () => run, runsForHead: () => [run], jobs: () => [{ name: 'suite', conclusion: 'success', completed_at: at(5) }], artifact: () => rec,
|
||||
commitTree: s => { const r = f.git('rev-parse', '--verify', '--quiet', `${s}^{tree}`); return r.status === 0 ? r.stdout.trim() : null; },
|
||||
};
|
||||
}
|
||||
|
||||
// Value: protects=item 3 of GST-3567: land.merged_ci's verify (lib/land-merged-ci.ts ghCiDeps) calls verifyRun with no onlyBaseMoved, so a
|
||||
// run that tested an older merge can never stand in for CI on the tree that lands; fails_when=verifyRun takes the rule by default
|
||||
test('verifyRun refuses the base-moved run unless the caller passes onlyBaseMoved, and then counts it for the head tree', () => {
|
||||
const f = behind();
|
||||
const m = mergeCommit(f);
|
||||
const d = deps(f, m);
|
||||
const base = { repo: 'fx/fx', runRef: '7', profileName: 'ci/free', profile: PROFILE, now: new Date() };
|
||||
const land = verifyRun(d, base);
|
||||
expect(land.ok ? 'ok' : land.reason).toBe('tree_mismatch');
|
||||
const carry = verifyRun(d, { ...base, onlyBaseMoved: (merge, head) => onlyBaseMoved(f.work, { merge, head, baseRef: 'origin/main' }) });
|
||||
expect(carry.ok && carry.evidence).toEqual(expect.objectContaining({ tree: sha(f, 'HEAD^{tree}'), base_moved: { merge: m.merge, base: sha(f, 'origin/main'), tested_tree: m.tree } }));
|
||||
});
|
||||
|
||||
test('onlyBaseMoved: a base parent that is not on the base branch refuses', () => {
|
||||
const f = behind();
|
||||
const stray = f.git('commit-tree', sha(f, 'origin/main^{tree}'), '-p', 'origin/main', '-m', 'not on main').stdout.trim();
|
||||
const tree = f.git('merge-tree', '--write-tree', stray, 'HEAD').stdout.trim().split('\n')[0]!;
|
||||
const merge = f.git('commit-tree', tree, '-p', stray, '-p', 'HEAD', '-m', 'merge').stdout.trim();
|
||||
const v = onlyBaseMoved(f.work, { merge, head: sha(f, 'HEAD'), baseRef: 'origin/main' });
|
||||
expect(v).toEqual({ ok: false, why: expect.stringContaining('is not on origin/main, even after fetching it') });
|
||||
});
|
||||
|
||||
// Value: protects=GitHub merging onto a main newer than the checkout's origin/main still counts: onlyBaseMoved fetches the base once
|
||||
// before refusing; fails_when=a stale origin/main refuses the carry and the lane reruns CI for nothing; seam=real git, local origin
|
||||
test('onlyBaseMoved: a base parent newer than the checkout\'s origin/main is fetched, then counts', () => {
|
||||
const f = behind();
|
||||
const stale = sha(f, 'origin/main');
|
||||
f.advanceBase({ 'src/e.ts': 'export const e = 5;\n' });
|
||||
expect(f.git('fetch', '-q', '--refmap=', 'origin', '+refs/heads/main:refs/ci-tested/main').status).toBe(0);
|
||||
const tested = sha(f, 'refs/ci-tested/main');
|
||||
const tree = f.git('merge-tree', '--write-tree', tested, 'HEAD').stdout.trim().split('\n')[0]!;
|
||||
const merge = f.git('commit-tree', tree, '-p', tested, '-p', 'HEAD', '-m', 'merge').stdout.trim();
|
||||
expect([sha(f, 'origin/main'), tested]).toEqual([stale, expect.not.stringMatching(stale)]);
|
||||
expect(onlyBaseMoved(f.work, { merge, head: sha(f, 'HEAD'), baseRef: 'origin/main' })).toEqual({ ok: true, base: tested });
|
||||
expect(sha(f, 'origin/main')).toBe(tested);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user