mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-19 06:34:43 +01:00
Reused CI runs that passed only after a re-run are now marked instead of shown as clean passes (GST-3054) (#4473)
When /ship reuses a CI run that passed only after its failed jobs were re-run, its CI line and its final summary line now add `rerun= attempts=`. Why: gbrain's CI now records which test files passed on a re-run (gbrain#9690), and a pass on a re-run must read as flaky, never as clean. Nothing to do: runs without that record print as before; a malformed record is refused with `CI_CARRY_RERUN_MALFORMED`. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/adversarial-native#2 reader=adversarial-native Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
1 parent
237371474b
commit
0a6bb42e74
17 files changed
+270
-17
No files matched your search
+15
-6
@@ -101,7 +101,7 @@ import { isUnavailable, loadPolicyFromBase, resolveBaseBranch } from "../lib/shi
|
||||
import { versionAtRef } from "../lib/restamp";
|
||||
import { bashCommandInvocation, runScriptSync, wtreeFingerprint } from "../lib/script-invocation";
|
||||
import { carriedFromLine, findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry";
|
||||
import { DEFAULT_MAX_AGE_HOURS, runChanged } from "../lib/run-evidence";
|
||||
import { DEFAULT_MAX_AGE_HOURS, rerunByRun, rerunMarker, runChanged } from "../lib/run-evidence";
|
||||
import { isConfigUnavailable, loadConfigFromBase } from "../lib/pregate/config";
|
||||
import { buildRunCheck } from "../lib/pregate/run-check";
|
||||
import { readTestLaneExceptions, testLaneExceptionText, type BoundLaneException } from "../lib/test-lane-exception";
|
||||
@@ -149,6 +149,8 @@ interface EvidenceRecord {
|
||||
skipped_here?: { label: string; files: string[]; tests_ran: number | "unknown"; not_owed?: string[] };
|
||||
/** The owner's test-lane exception that let a lane carry with uncovered inventory files, and the preflight of exactly them here (GST-1595). */
|
||||
exception?: BoundLaneException;
|
||||
/** Per carried run (`<id>/<attempt>`) whose tree.json lists files that passed only on a re-run: how many, and the run's attempts (record-ci, GST-3054). */
|
||||
rerun?: Record<string, { files: number; attempts: number[] }>;
|
||||
}
|
||||
|
||||
/** Bytes of streamed output kept for the tests_ran parse (the 2MB log would truncate the summary). */
|
||||
@@ -714,7 +716,7 @@ function reused(file: string, label: string, cmdSha: string, maxAgeHours: number
|
||||
|
||||
/** record-ci's record line, the one lib/ci-carry.ts recordCiResult reads. */
|
||||
const recordedCiLine = (r: EvidenceRecord): string =>
|
||||
`gstack-evidence: recorded label=${r.label} exit=0 tests_ran=${r.tests_ran}${r.tests_unit ? ` unit=${r.tests_unit}` : ""} log=- source=ci runs=${r.runs!.join(",")} policy=${r.policy}${r.skipped_here ? ` skipped_here=${r.skipped_here.files.length} tests_ran_here=${r.skipped_here.tests_ran}${r.skipped_here.not_owed ? ` not_owed_here=${r.skipped_here.not_owed.length}` : ""}` : ""}`;
|
||||
`gstack-evidence: recorded label=${r.label} exit=0 tests_ran=${r.tests_ran}${r.tests_unit ? ` unit=${r.tests_unit}` : ""} log=- source=ci runs=${r.runs!.join(",")}${rerunMarker(Object.values(r.rerun ?? {}))} policy=${r.policy}${r.skipped_here ? ` skipped_here=${r.skipped_here.files.length} tests_ran_here=${r.skipped_here.tests_ran}${r.skipped_here.not_owed ? ` not_owed_here=${r.skipped_here.not_owed.length}` : ""}` : ""}`;
|
||||
|
||||
/**
|
||||
* record-ci's reuse (GST-1795): the label's newest ledger row stands only when it is the CI row this record-ci would write again
|
||||
@@ -802,7 +804,9 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
|
||||
}
|
||||
if (!v.ok) return none(v.reason, `${v.detail}${v.reason === "inventory_uncovered" && !atHead.length && elsewhere.length ? `; test-lane exception ${elsewhere.join(", ")} binds another head, not HEAD ${head.slice(0, 12)}` : ""}`, v.diagnosis);
|
||||
const runs = v.runs.map((r) => `${r.run_id}/${r.run_attempt}`);
|
||||
const prior = v.excepted?.length ? null : reusableCiRow(label, { commit: head, wtree: tree, cmd_sha256: sha256(command), runs, profiles: m.profiles, policy: loaded.label, jobs: m.jobs, tests_ran: v.tests, tests_unit: v.unit, not_owed: v.notOwed }, v.remainder ?? [], m.per_file);
|
||||
const reran = rerunByRun(v.runs);
|
||||
const rerun = reran.size ? Object.fromEntries(reran) : undefined;
|
||||
const prior = v.excepted?.length ? null : reusableCiRow(label, { commit: head, wtree: tree, cmd_sha256: sha256(command), runs, profiles: m.profiles, policy: loaded.label, jobs: m.jobs, tests_ran: v.tests, tests_unit: v.unit, not_owed: v.notOwed, rerun }, v.remainder ?? [], m.per_file);
|
||||
if (prior) {
|
||||
console.error(recordedCiLine(prior));
|
||||
if (prior.not_owed) console.error(`gstack-evidence: not owed: ${prior.not_owed}`);
|
||||
@@ -867,7 +871,7 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
|
||||
}
|
||||
const rec: EvidenceRecord = {
|
||||
ts: new Date(v.runs.map((r) => r.finished_at).sort()[0]!).toISOString(), label, command, cmd_sha256: sha256(command), exit: 0, duration_s: 0,
|
||||
commit: head, tree, dirty: false, wtree: tree, tests_ran: testsRan, source: "ci", runs, profiles: m.profiles, policy: loaded.label, ...(m.jobs ? { jobs: m.jobs } : {}), ...(v.unit ? { tests_unit: v.unit } : {}), ...(v.notOwed ? { not_owed: v.notOwed } : {}), ...(here ? { skipped_here: here } : {}), ...(exception ? { exception } : {}),
|
||||
commit: head, tree, dirty: false, wtree: tree, tests_ran: testsRan, source: "ci", runs, profiles: m.profiles, policy: loaded.label, ...(m.jobs ? { jobs: m.jobs } : {}), ...(v.unit ? { tests_unit: v.unit } : {}), ...(v.notOwed ? { not_owed: v.notOwed } : {}), ...(here ? { skipped_here: here } : {}), ...(exception ? { exception } : {}), ...(rerun ? { rerun } : {}),
|
||||
};
|
||||
appendJsonl(paths.file, rec, { mode: 0o600 });
|
||||
console.error(recordedCiLine(rec));
|
||||
@@ -897,9 +901,14 @@ function cmdCarried(argv: string[]): number {
|
||||
for (const r of records) latest.set(r.label, r);
|
||||
const carried = [...latest.values()].filter((r) => r.source === "ci" && !!wtree && r.wtree === wtree && Array.isArray(r.runs) && typeof r.policy === "string" && r.policy.startsWith(policyRef)
|
||||
&& gradeRecord(r, { maxAgeHours: DEFAULT_MAX_AGE_HOURS, allowPaths: [], wtreeNow: wtree }).verdict === "FRESH")
|
||||
.flatMap((r) => r.runs!.map((ref) => { const [run, attempt] = ref.split("/").map(Number); return { lane: r.label, run, attempt, tree: r.wtree!, ...(r.exception ? { exception: r.exception } : {}) }; }));
|
||||
.flatMap((r) => r.runs!.map((ref) => {
|
||||
const [run, attempt] = ref.split("/").map(Number);
|
||||
const re = r.rerun?.[ref];
|
||||
const reran = re && Number.isInteger(re.files) && re.files > 0 && Array.isArray(re.attempts) && re.attempts.every((n) => Number.isInteger(n) && n > 0) ? { rerun: re.files, attempts: re.attempts } : {};
|
||||
return { lane: r.label, run, attempt, tree: r.wtree!, ...reran, ...(r.exception ? { exception: r.exception } : {}) };
|
||||
}));
|
||||
if (argv.includes("--json")) console.log(JSON.stringify(carried));
|
||||
else for (const c of carried) console.log(`CI_CARRIED: ${c.lane} run=${c.run}/${c.attempt} tree=${c.tree.slice(0, 12)}`);
|
||||
else for (const c of carried) console.log(`CI_CARRIED: ${c.lane} run=${c.run}/${c.attempt} tree=${c.tree.slice(0, 12)}${"rerun" in c ? rerunMarker([{ files: c.rerun!, attempts: c.attempts! }]) : ""}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user