mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 09:31:43 +01:00
Local checks reuse every green CI run at your code, not only the first (GST-3381) (#4671)
Local checks before opening a PR now reuse the newest verified CI run per eligible profile at your exact code, so files an end-to-end run already passed beside the test run no longer run again on your machine. Before, only the first matching profile's run counted; a failed run, a run of different code, or a run that changes while it is being read still counts for nothing. Nothing to do: this changes what runs locally, not what CI runs. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
113deeaf9c
commit
3d3ce73eb9
6 files changed
+167
-22
No files matched your search
@@ -41,7 +41,7 @@ import { selectLanes, type Selection } from '../lane-selection';
|
||||
import { launchRuntime } from '../runtime';
|
||||
import { cargoModel, type CargoModel } from '../rust';
|
||||
import { adapterFor, readRange, STALL_IDLE, supervise, type Counter, type Supervised } from '../supervise';
|
||||
import { ranFiles, verifyFromRun, type RunProfile } from '../../run-evidence';
|
||||
import { ranFiles, runChanged, runReceiptFields, verifyFromRun, type RunProfile } from '../../run-evidence';
|
||||
import { matchesAny } from '../../ship-policy';
|
||||
import { testFileArgs } from '../../test-paths';
|
||||
import type { CheckDef, CheckResult, PregateContext, RemoteObligation } from '../types';
|
||||
@@ -734,14 +734,22 @@ export function fromRunProfiles(ctx: PregateContext, profiles: Record<string, Ru
|
||||
* ones it already passed. Profiles are matched by workflow and OS, never by name, so none has to be named after a lane.
|
||||
*/
|
||||
function fromRun(ctx: PregateContext, sel: Selection): { line: string; passed: string[]; receipt?: string } {
|
||||
const { ref, check } = ctx.fromRun!;
|
||||
const names = 'error' in check ? [] : fromRunProfiles(ctx, check.profiles);
|
||||
const v = 'error' in check ? { ok: false as const, reason: 'profiles_unavailable', detail: check.error } : verifyFromRun(check, ref, names, ctx.wtree, ctx.head);
|
||||
if (!v.ok) return { line: `REUSE: refused reason=${v.reason} — ${v.detail}; every selected test runs here`, passed: [] };
|
||||
const ran = new Set(ranFiles(v.evidence));
|
||||
const { ref, check, runs } = ctx.fromRun!;
|
||||
if ('error' in check) return { line: `REUSE: refused reason=profiles_unavailable — ${check.error}; every selected test runs here`, passed: [] };
|
||||
const names = fromRunProfiles(ctx, check.profiles);
|
||||
const verdicts = (runs ?? [{ ref, profile: null }]).map(r => verifyFromRun(check, r.ref, r.profile ? names.filter(n => n === r.profile) : names, ctx.wtree, ctx.head));
|
||||
const ok = verdicts.flatMap(v => (v.ok ? [v.evidence] : []));
|
||||
const v = verdicts[0]!;
|
||||
if (!ok.length && !v.ok) return { line: `REUSE: refused reason=${v.reason} — ${v.detail}; every selected test runs here`, passed: [] };
|
||||
let changed: string | null = null;
|
||||
try { for (const e of ok.length > 1 ? ok : []) changed ??= runChanged(check.deps, e.run_id, e.run_attempt); }
|
||||
catch (err) { changed = `reading the runs again failed: ${String((err as Error)?.message ?? err).slice(0, 200)}`; }
|
||||
if (changed) return { line: `REUSE: refused reason=run_changed — ${changed}; every selected test runs here`, passed: [] };
|
||||
const ran = new Set(ok.flatMap(ranFiles));
|
||||
const passed = sel.localTests.filter(t => ran.has(t));
|
||||
const skipped = sel.localTests.filter(t => v.evidence.skipped?.includes(t)).length;
|
||||
return { line: `REUSE: accepted ${passed.length} of ${sel.localTests.length} selected local test file(s) from ${v.receipt}; ${sel.localTests.length - passed.length} still run${skipped ? ` (${skipped} skipped every test in the run)` : ''}`, passed, receipt: v.receipt };
|
||||
const skipped = sel.localTests.filter(t => !ran.has(t) && ok.some(e => e.skipped?.includes(t))).length;
|
||||
const receipt = `run tree=${ctx.wtree.slice(0, 12)} tests=${ok.reduce((n, e) => n + (e.tests ?? e.files.length), 0)} ${runReceiptFields(ok, check.now)}`;
|
||||
return { line: `REUSE: accepted ${passed.length} of ${sel.localTests.length} selected local test file(s) from ${receipt}; ${sel.localTests.length - passed.length} still run${skipped ? ` (${skipped} skipped every test in the run)` : ''}`, passed, receipt };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-5
@@ -59,8 +59,8 @@ export function applyDowngrades(ctx: PregateContext, result: CheckResult, def: C
|
||||
|
||||
/**
|
||||
* The tests stage's automatic `--from-run` (GSTA-258): when the base branch declares run profiles and no run was named,
|
||||
* the newest verified CI run at HEAD's clean tree under a profile for this OS becomes `ctx.fromRun`, so its tree.json
|
||||
* files count as passed and only the rest run (on a small machine, an all-covered selection records no remote gate
|
||||
* the newest verified CI run at HEAD's clean tree under each profile for this OS goes into `ctx.fromRun`, so the tree.json
|
||||
* files of every one of them count as passed and only the rest run (on a small machine, an all-covered selection records no remote gate
|
||||
* obligation). Returns the CI_CARRY line, or null when the base declares no profiles. Security scans, guards and the
|
||||
* preflight stage are never carried.
|
||||
*/
|
||||
@@ -75,12 +75,17 @@ export function autoCarry(ctx: PregateContext): string | null {
|
||||
if (!names.length) return none('no_profile: no base run profile for this OS covers a lane this machine runs');
|
||||
const wtree = () => { const fp = wtreeFingerprint({ cwd: ctx.repoRoot }); return 'tree' in fp ? fp.tree : null; };
|
||||
const refusals: string[] = [];
|
||||
const runs: Array<{ ref: string; profile: string }> = [];
|
||||
const receipts: string[] = [];
|
||||
for (const name of names) {
|
||||
const v = findCarry(check, { profiles: [name], head: ctx.head, tree, wtree });
|
||||
if (v.ok) { ctx.fromRun = { ref: String(v.runs[0]!.run_id), check }; return `CI_CARRY: accepted ${v.receipt}`; }
|
||||
refusals.push(`${v.reason}: ${v.detail}`);
|
||||
if (!v.ok) { refusals.push(`${v.reason}: ${v.detail}`); continue; }
|
||||
runs.push({ ref: String(v.runs[0]!.run_id), profile: name });
|
||||
receipts.push(v.receipt);
|
||||
}
|
||||
return none(refusals.join(' | '));
|
||||
if (!runs.length) return none(refusals.join(' | '));
|
||||
ctx.fromRun = { ref: (runs.find(r => check.gateRuns?.profiles.includes(r.profile)) ?? runs[0]!).ref, check, runs };
|
||||
return `CI_CARRY: accepted ${receipts.join(' + ')}`;
|
||||
}
|
||||
|
||||
const git = (cwd: string, args: string[]): string | null => {
|
||||
|
||||
@@ -64,8 +64,8 @@ export interface PregateContext {
|
||||
cores: number;
|
||||
testBackend: string;
|
||||
policyFrom: 'base' | 'head';
|
||||
/** `--from-run`: a Free Tests run whose tree.json files count as passed for this tree (lanes, lib/run-evidence.ts verifyFromRun), with the base branch's run check or why it could not be built. */
|
||||
fromRun?: { ref: string; check: RunSource | { error: string } };
|
||||
/** `--from-run`: a Free Tests run whose tree.json files count as passed for this tree (lanes, lib/run-evidence.ts verifyFromRun), with the base branch's run check or why it could not be built. The CI carry sets `runs`, every profile's verified run at this tree (`ref` is the remote gate's, else the first), and their files count together. */
|
||||
fromRun?: { ref: string; check: RunSource | { error: string }; runs?: Array<{ ref: string; profile: string }> };
|
||||
/** `--no-ci-carry`: false skips the tests stage's automatic --from-run (lib/ci-carry.ts findCarry at HEAD's clean tree). */
|
||||
ciCarry?: boolean;
|
||||
/** `--remote`: run the declared remote gate now, under this spend cap. */
|
||||
|
||||
Reference in new issue
Block a user