mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-16 13:21:30 +01:00
pregate: REUSE accepted/refused lines, run-url regression test, receipt bind end to end
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
87387385bc
commit
29cc8ff6a0
4 files changed
+54
-12
No files matched your search
@@ -232,6 +232,7 @@ function cmdClear(root: string, rest: string[]): number {
|
||||
}
|
||||
const file = clearObligation(read.file, lane, decision.receipt, `gstack-pregate clear ${new Date().toISOString()}`, decision.substitution);
|
||||
writePregateFile(root, out, file);
|
||||
if (/ runs=\S+ profiles=/.test(decision.receipt)) process.stdout.write(`REUSE: accepted ${lane} ${decision.receipt}\n`);
|
||||
if (decision.substitution) process.stdout.write(`PREGATE_RECEIPT_SUBSTITUTED: ${describeSubstitution(decision.substitution)}\n`);
|
||||
process.stdout.write(`PREGATE_CLEARED: ${lane} receipt=${decision.receipt} verdict=${file.verdict}${decision.attested ? ` (attested, not validated: ${lane} has no machine-checkable receipt)` : ''}\n`);
|
||||
return EXIT.ok;
|
||||
|
||||
+9
-5
@@ -626,11 +626,15 @@ once:
|
||||
exactly the rule [above](#remote-gate-stamp-only) (a policy whose
|
||||
`stamp_sensitive_gates` names `tests` refuses that substitution).
|
||||
|
||||
Any API or git error refuses. Each refusal prints `REUSE: refused — …` with the
|
||||
run and its reason (`fork_run`, `event_mismatch`, `run_not_success`,
|
||||
`job_missing`, `artifact_mismatch`, `artifact_reused`, `tree_mismatch`,
|
||||
`newer_run_vetoes`, `run_stale`, `os_mismatch`, `api_error`, …), as
|
||||
`PREGATE_RECEIPT_INVALID`. Accepted, the receipt reads
|
||||
Any API or git error refuses. Each refusal prints `REUSE: refused
|
||||
reason=<code> — …` as `PREGATE_RECEIPT_INVALID`, and a run that fails
|
||||
verification is named with its own reason (`fork_run`, `event_mismatch`,
|
||||
`run_not_success`, `job_missing`, `artifact_mismatch`, `artifact_reused`,
|
||||
`tree_mismatch`, `newer_run_vetoes`, `run_stale`, `os_mismatch`, `api_error`,
|
||||
…); the clear-level codes are `no_verified_run`, `tree_mismatch` (runs on
|
||||
different trees), `inventory_failed`, `inventory_empty`, `inventory_uncovered`
|
||||
and `no_tests`. Accepted, `clear` prints `REUSE: accepted <lane> <receipt>`, and
|
||||
the receipt reads
|
||||
`remote-gate tree=<t12> tests=<n> runs=<id>/<attempt>,… profiles=<p>,…
|
||||
heads=<h12> verified=<time>` (with `accepted-for=` and the substitution for a
|
||||
stamp-only predecessor). A lane with its own profile gets `run tree=… runs=…`
|
||||
|
||||
@@ -285,25 +285,25 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
|
||||
const hit = left.findIndex(ref => {
|
||||
const v = verifyRun(check.deps, { repo: check.repo, runRef: ref, profileName: name, profile, vetoHeads: file.head ? [file.head] : [], now: check.now });
|
||||
if (v.ok) { evidence.push(v.evidence); return true; }
|
||||
tried.push(`${ref}: ${v.detail} (${v.reason})`);
|
||||
tried.push(`${ref}: reason=${v.reason} ${v.detail}`);
|
||||
return false;
|
||||
});
|
||||
if (hit < 0) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — no run verifies as ${name}: ${tried.join('; ')}; ${lane} stays uncleared` };
|
||||
if (hit < 0) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=no_verified_run — no run verifies as ${name}: ${tried.join('; ')}; ${lane} stays uncleared` };
|
||||
left.splice(hit, 1);
|
||||
}
|
||||
const trees = [...new Set(evidence.map(e => e.tree))];
|
||||
if (trees.length > 1) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — the runs tested different trees (${trees.map(t => t.slice(0, 12)).join(', ')}); ${lane} stays uncleared` };
|
||||
if (trees.length > 1) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=tree_mismatch — the runs tested different trees (${trees.map(t => t.slice(0, 12)).join(', ')}); ${lane} stays uncleared` };
|
||||
const sub = treeSubstitution(file, trees[0]!, lane, repoRoot);
|
||||
if ('refused' in sub) return sub;
|
||||
const tests = evidence.reduce((n, e) => n + (e.tests ?? e.files.length), 0);
|
||||
if (isGate) {
|
||||
const listed = check.inventory(check.gateRuns!.inventory);
|
||||
if ('error' in listed) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — the remote gate's inventory command failed: ${listed.error}; ${lane} stays uncleared` };
|
||||
if (!listed.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — the remote gate's inventory command listed no test files; ${lane} stays uncleared` };
|
||||
if ('error' in listed) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=inventory_failed — the remote gate's inventory command failed: ${listed.error}; ${lane} stays uncleared` };
|
||||
if (!listed.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=inventory_empty — the remote gate's inventory command listed no test files; ${lane} stays uncleared` };
|
||||
const missing = uncoveredFiles(listed, evidence);
|
||||
if (missing.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — ${missing.length} of the gate's ${listed.length} test file(s) appear in no run's tree.json (${missing.slice(0, 5).join(', ')}${missing.length > 5 ? ', …' : ''}); ${lane} stays uncleared` };
|
||||
if (missing.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=inventory_uncovered — ${missing.length} of the gate's ${listed.length} test file(s) appear in no run's tree.json (${missing.slice(0, 5).join(', ')}${missing.length > 5 ? ', …' : ''}); ${lane} stays uncleared` };
|
||||
}
|
||||
if (tests === 0) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused — the verified runs record no tests; ${lane} stays uncleared` };
|
||||
if (tests === 0) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=no_tests — the verified runs record no tests; ${lane} stays uncleared` };
|
||||
const accepted = sub.substitution ? ` accepted-for=${file.tree.slice(0, 12)} stamp-only=${sub.substitution.files.length}` : '';
|
||||
return { receipt: `${isGate ? 'remote-gate' : 'run'} tree=${trees[0]!.slice(0, 12)} tests=${tests}${accepted} ${runReceiptFields(evidence, check.now)}`, attested: false, substitution: sub.substitution };
|
||||
}
|
||||
|
||||
@@ -83,6 +83,12 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
expect(d.substitution).toBeUndefined();
|
||||
const cleared = clearObligation(file, LANE, d.receipt, 'test');
|
||||
expect(verifyPregate(repo.work, cleared, { tree: file.tree } as any)).toMatchObject({ ok: true });
|
||||
const out = path.join(repo.work, '.gstack/tmp/pregate.json');
|
||||
fs.mkdirSync(path.dirname(out), { recursive: true });
|
||||
fs.writeFileSync(out, JSON.stringify(cleared));
|
||||
const bound = runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'interactive', '--pregate', out, '--json']);
|
||||
expect([bound.status, bound.err]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
expect(bound.out).toContain(d.receipt);
|
||||
}, 120_000);
|
||||
|
||||
test('runs on a stamp-only predecessor are accepted for the stamped head and recorded as a substitution', async () => {
|
||||
@@ -112,6 +118,37 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
expect(msg(clearDecision(file, LANE, { runs: ['200', '201'], evidence: check(repo, both(head), { inventory: () => ({ error: 'boom' }) }) }, repo.work))).toContain('inventory command failed: boom');
|
||||
}, 120_000);
|
||||
|
||||
test('runs that tested different trees, or that record no tests, never clear the gate', async () => {
|
||||
const repo = fixture();
|
||||
const older = repo.git('rev-parse', 'HEAD~1');
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const file = await pregateAt(repo);
|
||||
const split = clearDecision(file, LANE, { runs: ['200', '201'], evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts', 'test/b.test.ts'] }, { id: 201, profile: 'e2e', head: older, files: [] }]) }, repo.work);
|
||||
expect('refused' in split && split.message).toContain('the runs tested different trees');
|
||||
const empty = clearDecision(file, LANE, { runs: ['200', '201'], evidence: check(repo, [{ id: 200, profile: 'test', head, files: [] }, { id: 201, profile: 'e2e', head, files: [] }], { inventory: () => [] }) }, repo.work);
|
||||
expect('refused' in empty && empty.message).toContain('inventory command listed no test files');
|
||||
}, 120_000);
|
||||
|
||||
test('a lane with its own profile clears from --run-url through the verifier; a lane without one keeps the plain run-URL record, even when the base config cannot be read', async () => {
|
||||
const repo = fixture();
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const base = await pregateAt(repo);
|
||||
const PLATFORM = 'test.yml/full-suite';
|
||||
const file: PregateFile = { ...base, requires_remote: [...base.requires_remote!, { lane: PLATFORM, platform: 'macos', workflow: 'test.yml', job: 'full-suite', tests: ['test/a.test.ts'], receipt: null }] };
|
||||
const url = 'https://github.com/fx/fx/actions/runs/200';
|
||||
const profiled = clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts'] }], { profiles: { ...PROFILES, [PLATFORM]: PROFILES.test! } }) }, repo.work);
|
||||
if ('refused' in profiled) throw new Error(profiled.message);
|
||||
expect(profiled).toMatchObject({ attested: false });
|
||||
expect(profiled.receipt).toStartWith(`run tree=${file.tree.slice(0, 12)} tests=5 runs=200/1 profiles=${PLATFORM} `);
|
||||
const failed = clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts'], conclusion: 'failure' }], { profiles: { ...PROFILES, [PLATFORM]: PROFILES.test! } }) }, repo.work);
|
||||
expect('refused' in failed && failed.refused).toBe('PREGATE_RECEIPT_INVALID');
|
||||
expect(clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, []) }, repo.work)).toEqual({ receipt: url, attested: false });
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), JSON.stringify(file));
|
||||
const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', PLATFORM, '--run-url', url]);
|
||||
expect([r.status, r.err]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
}, 120_000);
|
||||
|
||||
test('offline verify refuses a run receipt recorded for another tree', async () => {
|
||||
const repo = fixture();
|
||||
const file = await pregateAt(repo);
|
||||
|
||||
Reference in new issue
Block a user