mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 22:24:17 +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
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* GST-3054: a carried CI run whose tree.json says some files passed only on a re-run attempt (gbrain#9690's
|
||||
* `rerun_files` and `attempts`) still carries, but every carry receipt and the SHIP_RECEIPT line say so
|
||||
* (`rerun=<n> attempts=<list>`), and a malformed record fails closed. The dependencies are fakes; nothing reaches GitHub.
|
||||
*/
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { findCarry } from '../lib/ci-carry';
|
||||
import { RESULT_CODES } from '../lib/result-codes';
|
||||
import { receiptSummaryLine, validateReceipt } from '../lib/ship-receipt';
|
||||
import { rerunByRun, runReceiptFields, type ApiRun, type RunDeps, type RunProfile, type RunSource, type TreeRecord } from '../lib/run-evidence';
|
||||
|
||||
const REPO = 'garrytan/gstack';
|
||||
const HEAD = 'a'.repeat(40);
|
||||
const TREE = 'b'.repeat(40);
|
||||
const NOW = new Date('2026-11-02T12:00:00Z');
|
||||
const PROFILE: RunProfile = { workflow: 'free-tests.yml', events: ['workflow_dispatch'], jobs: ['free-tests'], artifact: 'tested-tree', os: 'Linux' };
|
||||
const FIXTURES = path.join(import.meta.dir, 'fixtures', 'ci-carry-rerun');
|
||||
const fixture = (name: string): TreeRecord => JSON.parse(fs.readFileSync(path.join(FIXTURES, name), 'utf8'));
|
||||
const INVENTORY = ['test/a.test.ts', 'test/b.test.ts', 'test/c.test.ts'];
|
||||
|
||||
function source(rec: TreeRecord): RunSource {
|
||||
const r: ApiRun = { id: rec.run_id as number, run_attempt: rec.run_attempt as number, status: 'completed', conclusion: 'success', event: 'workflow_dispatch', head_sha: HEAD,
|
||||
path: '.github/workflows/free-tests.yml', created_at: '2026-11-02T10:00:00Z', updated_at: '2026-11-02T11:30:00Z', repository: { full_name: REPO }, head_repository: { full_name: REPO } };
|
||||
const deps: RunDeps = {
|
||||
run: () => r,
|
||||
runsForHead: (_wf, sha) => (sha === HEAD ? [r] : []),
|
||||
jobs: () => [{ name: 'free-tests', conclusion: 'success', completed_at: '2026-11-02T11:30:00Z' }],
|
||||
artifact: () => rec,
|
||||
commitTree: sha => (sha === HEAD ? TREE : null),
|
||||
};
|
||||
return { repo: REPO, deps, profiles: { 'ci-reuse/free-tests': PROFILE }, now: NOW };
|
||||
}
|
||||
const carry = (rec: TreeRecord, inventory = true) => findCarry(source(rec), { profiles: ['ci-reuse/free-tests'], head: HEAD, tree: TREE, wtree: () => TREE, ...(inventory ? { inventory: () => INVENTORY } : {}) });
|
||||
const receipt = (ci_carried: unknown) => ({ schema_version: 1 as const, head: HEAD, base: 'main', ci_carried } as Parameters<typeof receiptSummaryLine>[0]);
|
||||
|
||||
describe('a carried run that passed only after a re-run (GST-3054)', () => {
|
||||
// Value: protects=a tree.json without rerun_files carries exactly as before; fails_when=the marker appears on a clean first-attempt run
|
||||
test('a tree.json without rerun_files or attempts carries with no rerun marker', () => {
|
||||
for (const inventory of [true, false]) {
|
||||
const v = carry(fixture('no-fields.tree.json'), inventory);
|
||||
expect(v.ok).toBe(true);
|
||||
if (!v.ok) return;
|
||||
expect(v.receipt).not.toMatch(/ rerun=| attempts=/);
|
||||
expect(v.runs[0]!.rerun).toBeUndefined();
|
||||
expect(v.runs[0]!.attempts).toBeUndefined();
|
||||
}
|
||||
const empty = carry({ ...fixture('no-fields.tree.json'), rerun_files: [], attempts: [1] });
|
||||
expect(empty.ok).toBe(true);
|
||||
expect(empty.ok ? empty.receipt : '').not.toContain('rerun=');
|
||||
const line = receiptSummaryLine(receipt([{ lane: 'free', run: 4, attempt: 1, tree: TREE }]));
|
||||
expect(line).toContain('ci_carried=free:4/1');
|
||||
expect(line).not.toMatch(/ rerun=| attempts=/);
|
||||
});
|
||||
|
||||
// Value: protects=a re-run pass is marked, never presented as clean; fails_when=rerun_files is ignored again or the carry refuses it
|
||||
test('rerun_files carries, and the carry receipt names the re-run count and the attempts', () => {
|
||||
for (const inventory of [true, false]) {
|
||||
const v = carry(fixture('rerun.tree.json'), inventory);
|
||||
expect(v.ok).toBe(true);
|
||||
if (!v.ok) return;
|
||||
expect(v.receipt).toContain(' runs=5/2 ');
|
||||
expect(v.receipt).toContain(' rerun=2 attempts=1,2 ');
|
||||
expect([v.runs[0]!.rerun, v.runs[0]!.attempts]).toEqual([['test/b.test.ts', 'test/c.test.ts'], [1, 2]]);
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=the SHIP_RECEIPT line ready and land print shows the marker; fails_when=the receipt drops it or it fails schema validation
|
||||
test('the receipt records rerun and attempts per carried run, and SHIP_RECEIPT shows them after ci_carried', () => {
|
||||
const r = receipt([{ lane: 'free', run: 5, attempt: 2, tree: TREE, rerun: 2, attempts: [1, 2] }, { lane: 'lint', run: 5, attempt: 2, tree: TREE, rerun: 2, attempts: [1, 2] }]);
|
||||
expect(validateReceipt(r)).toEqual([]);
|
||||
expect(receiptSummaryLine(r)).toContain('ci_carried=free:5/2,lint:5/2 rerun=2 attempts=1,2');
|
||||
expect(validateReceipt(receipt([{ lane: 'free', run: 5, attempt: 2, tree: TREE, rerun: '2', attempts: 'x' }])).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// Value: protects=an unmarked lane on the same run never hides the marker, and two profiles on one run count each file once; fails_when=the last entry or profile overwrites or double-counts
|
||||
test('lanes and profiles that share a run keep the marker and count each re-run file once', () => {
|
||||
expect(receiptSummaryLine(receipt([{ lane: 'free', run: 5, attempt: 2, tree: TREE, rerun: 1, attempts: [1, 2] }, { lane: 'lint', run: 5, attempt: 2, tree: TREE }]))).toContain('ci_carried=free:5/2,lint:5/2 rerun=1 attempts=1,2');
|
||||
const run = { run_id: 5, run_attempt: 2, head_sha: HEAD, tree: TREE, event: 'workflow_dispatch', finished_at: '2026-11-02T11:30:00Z', files: INVENTORY, tests: 3, rerun: ['test/b.test.ts'], attempts: [2, 1, 2] };
|
||||
expect(runReceiptFields([{ ...run, profile: 'one' }, { ...run, profile: 'two' }], NOW)).toContain(' rerun=1 attempts=1,2 ');
|
||||
expect([...rerunByRun([run, { ...run, rerun: ['test/c.test.ts'] }])]).toEqual([['5/2', { files: 2, attempts: [1, 2] }]]);
|
||||
});
|
||||
|
||||
// Value: protects=fail closed on a malformed re-run record; fails_when=a non-array or non-string rerun_files, or bad attempts, carries
|
||||
test('a malformed rerun_files or attempts refuses with CI_CARRY_RERUN_MALFORMED', () => {
|
||||
const bad: Array<Partial<TreeRecord>> = [{}, { rerun_files: [1] }, { rerun_files: ['test/b.test.ts'], attempts: '1,2' }, { rerun_files: ['test/b.test.ts'], attempts: [0, 2] }, { rerun_files: ['test/b.test.ts'], attempts: ['2'] }];
|
||||
for (const over of bad) {
|
||||
const v = carry({ ...fixture('malformed.tree.json'), ...over });
|
||||
expect(v.ok).toBe(false);
|
||||
if (v.ok) return;
|
||||
expect(v.reason).toBe('no_verified_run');
|
||||
expect(v.detail).toContain('rerun_malformed');
|
||||
expect(v.detail).toContain('(CI_CARRY_RERUN_MALFORMED)');
|
||||
}
|
||||
expect(RESULT_CODES.CI_CARRY_RERUN_MALFORMED.anchor).toBe('ci-carry-rerun-malformed');
|
||||
});
|
||||
});
|
||||
@@ -128,6 +128,18 @@ describe('gstack-evidence record-ci and carried (A4)', () => {
|
||||
expect(JSON.parse(run(['carried', '--json']).stdout)).toEqual([]);
|
||||
});
|
||||
|
||||
// Value: protects=GST-3054, a carried run that passed only on a re-run reaches the receipt's ci_carried entry marked; fails_when=the
|
||||
// ledger's rerun record is dropped on the way to the receipt, or a forged one with bad attempts is copied into it
|
||||
test('carried copies a CI row\'s re-run record into its ci_carried entry, and drops a malformed one', () => {
|
||||
expect(run(['run', '--label', 'unit', '--', lane(2)]).status).toBe(0);
|
||||
fs.appendFileSync(ledger(), JSON.stringify({ ...ciRow(), rerun: { '41/2': { files: 290, attempts: [1, 2] } } }) + '\n');
|
||||
expect(JSON.parse(run(['carried', '--base', 'main', '--json']).stdout)).toEqual([{ lane: 'free', run: 41, attempt: 2, tree: wtree(), rerun: 290, attempts: [1, 2] }]);
|
||||
expect(run(['carried', '--base', 'main']).stdout).toContain('CI_CARRIED: free run=41/2 tree=');
|
||||
expect(run(['carried', '--base', 'main']).stdout).toContain(' rerun=290 attempts=1,2');
|
||||
fs.appendFileSync(ledger(), JSON.stringify({ ...ciRow(), rerun: { '41/2': { files: 290, attempts: '1,2' } } }) + '\n');
|
||||
expect(JSON.parse(run(['carried', '--base', 'main', '--json']).stdout)).toEqual([{ lane: 'free', run: 41, attempt: 2, tree: wtree() }]);
|
||||
});
|
||||
|
||||
// Value: protects=record-ci finds and verifies the CI run itself, so no caller supplies run ids, a test count or a tree (/ship pass 1 red-team#1);
|
||||
// fails_when=the forged call from that finding writes a FRESH carried row; seam=no origin, so the base's ship_lanes_from is unreadable
|
||||
test('record-ci takes no run facts from its caller and records nothing without a verified run', () => {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"run_id": 6,
|
||||
"run_attempt": 2,
|
||||
"event": "workflow_dispatch",
|
||||
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"tree": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"files": [
|
||||
"test/a.test.ts",
|
||||
"test/b.test.ts",
|
||||
"test/c.test.ts"
|
||||
],
|
||||
"tests": 60,
|
||||
"os": "Linux",
|
||||
"rerun_files": "test/b.test.ts",
|
||||
"attempts": [
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"run_id": 4,
|
||||
"run_attempt": 1,
|
||||
"event": "workflow_dispatch",
|
||||
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"tree": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"files": [
|
||||
"test/a.test.ts",
|
||||
"test/b.test.ts",
|
||||
"test/c.test.ts"
|
||||
],
|
||||
"tests": 60,
|
||||
"os": "Linux"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"run_id": 5,
|
||||
"run_attempt": 2,
|
||||
"event": "workflow_dispatch",
|
||||
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"tree": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"files": [
|
||||
"test/a.test.ts",
|
||||
"test/b.test.ts",
|
||||
"test/c.test.ts"
|
||||
],
|
||||
"tests": 60,
|
||||
"os": "Linux",
|
||||
"rerun_files": [
|
||||
"test/b.test.ts",
|
||||
"test/c.test.ts"
|
||||
],
|
||||
"attempts": [
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
@@ -51,6 +51,7 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
|
||||
'test/fixtures/ceo-split-collection-3638.json': ['test/ceo-split-collection.test.ts'],
|
||||
'test/fixtures/ceo-split-wording-variants.json': ['test/ceo-split-collection.test.ts'],
|
||||
'test/fixtures/ceo-stale-fill-decision/**': ['test/ceo-stale-fill-decision.test.ts'],
|
||||
'test/fixtures/ci-carry-rerun/**': ['test/ci-carry-rerun.test.ts'],
|
||||
'test/fixtures/ci-gate/**': ['test/gstack-ci-gate.test.ts'],
|
||||
'test/fixtures/claude-agent-payload-2.1.292.json': ['test/autoplan-publication-payload.test.ts', 'test/autoplan-schema-canary-compare.test.ts'],
|
||||
'test/fixtures/claude-native-journal-roots-2.1.284.json': ['test/autoplan-publication-hook.test.ts', 'test/plan-count-transcript.test.ts'],
|
||||
|
||||
Reference in new issue
Block a user