diff --git a/bin/gstack-ci-carry b/bin/gstack-ci-carry index 1771c0287..c777cbc21 100755 --- a/bin/gstack-ci-carry +++ b/bin/gstack-ci-carry @@ -9,13 +9,15 @@ * find: the newest verified run of each profile (default: every profile the base branch's * ship_lanes_from names) at HEAD's clean tree. With --command, the base branch's mapping for that exact lane * command supplies the profiles and the inventory the runs must cover (a pin-file command, so it needs - * --allow-repo-commands). Prints CI_CARRY: accepted (exit 0) or CI_CARRY: none () (exit 1). + * --allow-repo-commands). Prints CI_CARRY: accepted (exit 0) or CI_CARRY: none () (exit 1). A run at + * one of HEAD's ancestors whose tree git reads as HEAD's (a base merge that changed no file) carries too, and CI_CARRY_FROM + * names that run and commit (GST-3019). * wait: polls the newest run of the profile's workflow at HEAD (REST, at least 60 s apart) until it completes (default timeout 1800 s), * prints CI_WAIT: green|red|running|none, and on green runs find. Exit 0 green and carried, 1 red or not * carried, 3 still running or no run. Logic: lib/ci-carry.ts; the run checks are lib/run-evidence.ts. */ import { spawnSync } from 'node:child_process'; -import { findCarry, laneMapping, mappingCoverage, waitForRun } from '../lib/ci-carry'; +import { carriedFromLine, findCarry, laneMapping, mappingCoverage, treeTwins, waitForRun } from '../lib/ci-carry'; import { isConfigUnavailable, loadConfigFromBase, loadConfigFromHead } from '../lib/pregate/config'; import { buildRunCheck } from '../lib/pregate/run-check'; import { wtreeFingerprint } from '../lib/script-invocation'; @@ -24,11 +26,12 @@ import { resolveBaseBranch } from '../lib/ship-policy'; const HELP = `gstack-ci-carry — use a verified CI run at HEAD's exact tree instead of running the suite again (docs/pregate.md#ci-carry) find [--base ] [--profile ]... [--command --allow-repo-commands] [--json] - CI_CARRY: accepted (exit 0) or CI_CARRY: none () (exit 1) + CI_CARRY: accepted (exit 0) or CI_CARRY: none () (exit 1); a run at an earlier commit with + HEAD's exact tree (git rev-parse ^{tree}) carries too, and CI_CARRY_FROM: names that run and commit --policy-from head --simulate: the same check under the branch's own map and profiles, every line starting SIMULATION:; a dry run that proves a new mapping before it lands (find never writes evidence; nothing clears) wait [--base ] [--profile ] [--timeout ] [--interval ] - poll the newest run at HEAD (default 1800 s, every 60 s at least, plus jitter): CI_WAIT: green|red|running|none, then find on green; + poll the newest run at HEAD or an earlier commit with its tree (default 1800 s, every 60 s at least, plus jitter): CI_WAIT: green|red|running|none, then find on green; exit 0 carried, 1 red or not carried, 3 still running or no run Profiles and ship_lanes_from come from origin/'s .gstack/pregate.json only (a simulation reads the branch's). Only a clean, committed tree @@ -70,6 +73,8 @@ function find(): number { const v = findCarry(check as Exclude, { profiles, head, tree, wtree, ...(mapping ? mappingCoverage(mapping, root) : {}) }); if (argv.includes('--json')) out(JSON.stringify(v)); 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); return v.ok ? 0 : 1; } @@ -79,6 +84,6 @@ const interval = Number(flag('--interval') ?? '60'); if (!(timeout >= 0 && timeout <= 21_600) || !(interval >= 1 && interval <= 600)) usage('--timeout is 0-21600 seconds and --interval 1-600'); const profile = check.profiles[profiles[0]!]; if (!profile) usage(`${profiles[0]} is not a run_profiles name on origin/${base}`); -const w = await waitForRun(check.deps, { workflow: profile!.workflow, events: profile!.events, head, timeoutMs: timeout * 1000, intervalMs: interval * 1000, sleep: ms => Bun.sleep(ms), clock: Date.now }); +const w = await waitForRun(check.deps, { workflow: profile!.workflow, events: profile!.events, head, also: treeTwins(check.deps, head, tree), timeoutMs: timeout * 1000, intervalMs: interval * 1000, sleep: ms => Bun.sleep(ms), clock: Date.now }); out(`CI_WAIT: ${w.state} ${profiles[0]} ${'run' in w ? `run=${w.run.id}/${w.run.run_attempt}${w.state === 'red' ? ` failing=${w.failing.join(',') || '-'}` : ''}` : w.reason}`); process.exit(w.state === 'green' ? find() : w.state === 'red' ? 1 : 3); diff --git a/bin/gstack-evidence b/bin/gstack-evidence index 26dd4c83e..753a4c445 100755 --- a/bin/gstack-evidence +++ b/bin/gstack-evidence @@ -100,7 +100,7 @@ import { resultLine } from "../lib/result-codes"; import { isUnavailable, loadPolicyFromBase, resolveBaseBranch } from "../lib/ship-policy"; import { versionAtRef } from "../lib/restamp"; import { bashCommandInvocation, runScriptSync, wtreeFingerprint } from "../lib/script-invocation"; -import { findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry"; +import { carriedFromLine, findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry"; import { DEFAULT_MAX_AGE_HOURS, runChanged } from "../lib/run-evidence"; import { isConfigUnavailable, loadConfigFromBase } from "../lib/pregate/config"; import { buildRunCheck } from "../lib/pregate/run-check"; @@ -806,6 +806,8 @@ async function cmdRecordCi(argv: string[]): Promise { if (prior) { console.error(recordedCiLine(prior)); if (prior.not_owed) console.error(`gstack-evidence: not owed: ${prior.not_owed}`); + const priorFrom = carriedFromLine(v.runs, head); + if (priorFrom) console.error(priorFrom); console.error(`CI_RECORD_REUSED: label=${label} runs=${runs.join(",")} tree=${tree.slice(0, 12)} policy=${loaded.label} (the ledger's CI row for this exact tree, run and selection; nothing ran here)`); return 0; } @@ -870,6 +872,8 @@ async function cmdRecordCi(argv: string[]): Promise { appendJsonl(paths.file, rec, { mode: 0o600 }); console.error(recordedCiLine(rec)); if (v.notOwed) console.error(`gstack-evidence: not owed: ${v.notOwed}`); + const from = carriedFromLine(v.runs, head); + if (from) console.error(from); if (exception) console.error(`TEST_LANE_EXCEPTION: ${testLaneExceptionText(exception)}`); return 0; } diff --git a/changelog.d/ci-same-tree-reuse-and-preflight-stops.md b/changelog.d/ci-same-tree-reuse-and-preflight-stops.md new file mode 100644 index 000000000..7814a1852 --- /dev/null +++ b/changelog.d/ci-same-tree-reuse-and-preflight-stops.md @@ -0,0 +1 @@ +- **/ship reuses CI's passing test run when merging the base changed no file, and stops instead of quietly starting hour-long test runs or reviewing an empty diff (GST-3019).** When git reads a commit's file tree as identical to an earlier commit's, a passed CI run of the earlier commit now counts for it, under the same workflow, command and freshness rules, and the output names the commit and run it used. `gstack-ship-preflight --tests-only` now stops with `SHIP_LANE_NOT_CARRIED` and the CI command to run when a mapped test suite has no passing CI run to reuse, instead of running it on this machine (`--run-uncarried-here` still runs it). `--audit --base ` now diffs against that commit, and a base that names no commit stops with `SHIP_BASE_UNKNOWN` instead of reporting zero changed files. diff --git a/docs/pregate.md b/docs/pregate.md index 35da65766..c5e01a53a 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -1075,6 +1075,17 @@ it accepts a run only when all of these hold: running run on HEAD, within `max_age_hours`, and a `tree.json` naming HEAD's tree. A `pull_request` run counts only when the pull request already contained its base. +- HEAD's runs include those of its newest + ancestors (up to 20 back) whose tree `git rev-parse ^{tree}` reads as + HEAD's own, so a base merge that changed no file keeps the green run of the + commit before it (GST-3019). Git decides which commits those are; a run's + own `tree.json` never does. Every rule above still applies to that run, and + a newer red or running run on HEAD or on any of those commits vetoes it. + `gstack-ci-carry find` then prints `CI_CARRY_FROM: run / at + commit , not HEAD ; git rev-parse reads the same tree for + both`, a Step 5 lane reads `LANE: