mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-16 13:21:30 +01:00
pregate: pass-2 review fixes for clear --run (docstrings, tests_uncovered reason, unreadable-base and user-policy tests)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
08451a7520
commit
965dfbc336
5 files changed
+34
-10
No files matched your search
+3
-2
@@ -654,8 +654,9 @@ verification is named with its own reason (`fork_run`, `event_mismatch`,
|
||||
`tree_mismatch`, `newer_run_vetoes`, `run_changed`, `run_stale`,
|
||||
`os_mismatch`, `api_error`, …); the clear-level codes are `base_mismatch`,
|
||||
`no_verified_run`, `tree_mismatch` (runs on different trees),
|
||||
`tree_not_stamp_only`, `no_tests`, `inventory_failed`, `inventory_empty` and
|
||||
`inventory_uncovered`. A wrong run count, a repeated run or a lane with no
|
||||
`tree_not_stamp_only`, `no_tests`, `inventory_failed`, `inventory_empty`,
|
||||
`inventory_uncovered` (the remote gate) and `tests_uncovered` (a lane's own
|
||||
selected tests). A wrong run count, a repeated run or a lane with no
|
||||
profile is a usage error (exit 2), not a REUSE refusal.
|
||||
|
||||
Accepted, `clear` prints `REUSE: accepted <lane> <receipt>`, and the receipt
|
||||
|
||||
@@ -218,6 +218,11 @@ export type ClearDecision = { receipt: string; attested: boolean; substitution?:
|
||||
* the tree mismatch refuses as before. A `test_backend/<backend>` obligation
|
||||
* has no machine-checkable receipt, so its run URL is recorded as attested.
|
||||
* Platform lanes take a run URL or an evidence-bundle lane label.
|
||||
*
|
||||
* `--run` (and `--run-url` on a lane the base branch profiles) goes to
|
||||
* clearByRuns, which accepts only verified Actions runs; a profiled lane
|
||||
* refuses `--bundle-lane`, and the remote gate clears by runs only when the
|
||||
* base declares remote_gate_runs.
|
||||
*/
|
||||
export function clearDecision(file: PregateFile, lane: string, input: ClearInput, repoRoot: string): ClearDecision {
|
||||
const list = file.requires_remote ?? [];
|
||||
@@ -322,7 +327,7 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
|
||||
for (const f of listed) required.add(f);
|
||||
}
|
||||
const missing = uncoveredFiles([...required], evidence);
|
||||
if (missing.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=inventory_uncovered — ${missing.length} of the ${required.size} test file(s) ${lane} must cover 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=${isGate ? 'inventory_uncovered' : 'tests_uncovered'} — ${missing.length} of the ${required.size} test file(s) ${lane} must cover appear in no run's tree.json (${missing.slice(0, 5).join(', ')}${missing.length > 5 ? ', …' : ''}); ${lane} stays uncleared` };
|
||||
const tests = evidence.reduce((n, e) => n + (e.tests ?? e.files.length), 0);
|
||||
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 };
|
||||
|
||||
+10
-5
@@ -13,11 +13,16 @@
|
||||
* completed with success; every job the profile names appears exactly once
|
||||
* in that attempt and succeeded; its artifact names this run, attempt,
|
||||
* event and head (the API always answers with the newest attempt, so an
|
||||
* older green attempt under a newer red one is refused), is not a reuse record, and records the tree git computes
|
||||
* for the head; no newer run of the same workflow on that head, or on any
|
||||
* other head the consumer names, failed, was cancelled or is still running;
|
||||
* it finished within the profile's max_age_hours (default 24); and its
|
||||
* runner OS matches when the profile names one.
|
||||
* older green attempt under a newer red one is refused), is not a reuse
|
||||
* record, records the tree git computes for the head, and holds well-formed
|
||||
* files (a list of paths) and tests (a non-negative integer); no run of the
|
||||
* same workflow on that head, or on any other head the consumer names, that
|
||||
* started after this run was created failed, was cancelled or is still
|
||||
* running (a red re-run of an older run counts, and re-running this run does
|
||||
* not hide a failure in between); it finished within the profile's
|
||||
* max_age_hours (default 24); its runner OS matches when the profile names
|
||||
* one; and a second read of the run still shows the same successful attempt
|
||||
* (run_changed otherwise).
|
||||
*
|
||||
* Profiles are the base branch's `.gstack/pregate.json` `run_profiles`, so a
|
||||
* pull request can tighten them but never relax them. The workflow a run
|
||||
|
||||
@@ -169,7 +169,7 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
if ('refused' in oneProfile) throw new Error(oneProfile.message);
|
||||
expect(oneProfile.receipt).toStartWith(`remote-gate tree=${file.tree.slice(0, 12)} tests=15 runs=200/1 profiles=test `);
|
||||
const uncovered = clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/smoke.test.ts'] }], { profiles: { ...PROFILES, [PLATFORM]: PROFILES.test! } }) }, repo.work);
|
||||
expect('refused' in uncovered && uncovered.message).toContain(`1 of the 1 test file(s) ${PLATFORM} must cover appear in no run's tree.json (test/a.test.ts)`);
|
||||
expect('refused' in uncovered && uncovered.message).toContain(`reason=tests_uncovered — 1 of the 1 test file(s) ${PLATFORM} must cover appear in no run's tree.json (test/a.test.ts)`);
|
||||
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]);
|
||||
@@ -189,6 +189,19 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
expect(JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), 'utf8')).requires_remote[0].receipt).toBeNull();
|
||||
}, 120_000);
|
||||
|
||||
test('an unreadable base config refuses --run-url even on a lane with no profile, since the base may profile it', async () => {
|
||||
const repo = fixture();
|
||||
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 }] };
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), JSON.stringify(file));
|
||||
repo.git('update-ref', '-d', 'refs/remotes/origin/main');
|
||||
const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', PLATFORM, '--run-url', 'https://github.com/fx/fx/actions/runs/200']);
|
||||
expect([r.status, r.err]).toEqual([EXIT.fail, expect.stringContaining(`${PLATFORM} may have a run profile on the base branch, so it clears only with a verified --run`)]);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), 'utf8')).requires_remote.find((o: { lane: string }) => o.lane === PLATFORM).receipt).toBeNull();
|
||||
}, 120_000);
|
||||
|
||||
test('offline verify refuses a run receipt recorded for another tree', async () => {
|
||||
const repo = fixture();
|
||||
const file = await pregateAt(repo);
|
||||
|
||||
@@ -145,7 +145,7 @@ describe('gstack-pregate with a user-owned policy', () => {
|
||||
expect(invalid.err).not.toContain('.gstack/pregate.json has');
|
||||
|
||||
const profile = { workflow: 'test.yml', events: ['push'], jobs: ['full-suite'], artifact: 'full-suite-tree' };
|
||||
for (const [key, value] of [['sealed', { paths: ['evals/**'] }], ['price_file', 'evals/calls.json'], ['run_profiles', { test: profile }]] as const) {
|
||||
for (const [key, value] of [['sealed', { paths: ['evals/**'] }], ['price_file', 'evals/calls.json'], ['run_profiles', { test: profile }], ['remote_gate_runs', { profiles: ['test'], inventory: 'true' }]] as const) {
|
||||
writePolicy(userPolicy, { [key]: value });
|
||||
const r = run();
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
|
||||
Reference in new issue
Block a user