Files
gstack/test/review-plan-pr-rounds.test.ts
T
Garry Tanandcapy-ai[bot] f87d4325a3 A round grant at the review round cap buys the fix round it names (GST-2968) (#4479)
When /ship stops at a pull request's review round cap, a grant naming
that stop now buys one scoped review of the fix, in the same run or the
next, instead of another read-only full review.

Before, a grant recorded after the read-only review, or between /ship
runs, bought nothing, so teams paid for extra full reviews or second
grants (ghome#40: $8.78 against about $3).

Nothing to do: /ship prints the grant command when it stops.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=security
Review-Finding: p1/specialist-batched#2 reader=state-machines
Review-Finding: p1/specialist-batched#3 reader=testing
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p1/red-team#3 reader=red-team
2026-11-18 08:34:39 +00:00

101 lines
6.5 KiB
TypeScript

/**
* GST-2673: the review plan caps full review rounds per pull request (R51) with the full rounds earlier /ship runs on the
* PR already spent (--prior-full from PR_REVIEW_FLAGS), prints every earlier round as pr_rounds= (--prior-rounds), and
* a recorded round grant buys one more full round at its head.
*/
import { describe, expect, test } from 'bun:test';
import { FULL_PASS_CAP, nextStep, type History } from '../lib/review-depth';
const h = (x: Partial<History>): History => ({ fullPasses: 0, last: 'none', ...x });
describe('PR round cap', () => {
test('no prior rounds leaves the plan as today', () => {
expect(nextStep(h({})).step).toBe('full');
expect(nextStep(h({ lean: true })).step).toBe('full');
expect(nextStep(h({ priorRounds: 0, priorFull: 0, fullPasses: 1, last: 'full', fixedBlocking: true }), 'standard').reason).not.toContain('PR_ROUND_CAP');
});
// Value: protects=the plan's d3a case: a run of a full pass plus a scoped pass 2 leaves the next head one full round;
// fails_when=the cap counts scoped passes or fix-checks as full rounds; seam=nextStep; no_claim=preflight's re-check route
test('one prior full round (two rounds with a scoped pass 2): pass 1 is the PR\'s second and last full round, in both tables', () => {
for (const lean of [false, true]) {
const n = nextStep(h({ priorRounds: 2, priorFull: 1, lean }));
expect(n.step).toBe('full');
expect(n.reason).toContain('full round 2 of 2, the last');
}
});
test('one prior full round: after pass 1, a below-floor fix keeps its in-run fix-check and a fixed blocker stops for the lane, not the owner', () => {
expect(nextStep(h({ priorFull: 1, fullPasses: 1, last: 'full', fixedBelow: true }), 'standard').step).toBe('fix-check');
const stop = nextStep(h({ priorFull: 1, fullPasses: 1, last: 'full', fixedBlocking: true }), 'standard');
expect(stop.step).toBe('stop');
expect(stop.reason).toStartWith('PR_ROUND_CAP');
expect(stop.reason).not.toContain('for the owner');
});
test('a fix-check stays the in-run table\'s call: lean\'s one fix-check after a fixed blocker still runs', () => {
expect(nextStep(h({ priorFull: 1, fullPasses: 1, last: 'full', fixedBlocking: true, lean: true }), 'standard').step).toBe('fix-check');
});
// Value: protects=F1's past-cap case: a PR with two full rounds whose own code changed gets one read-only full review of
// the merge head; fails_when=a third /ship run gets a fix round without a grant, or the merge head goes unreviewed;
// seam=nextStep; no_claim=the CLI's pr_rounds= print (pr-round-cli)
test('two prior full rounds: pass 1 is one read-only full review with no fix round, in both tables', () => {
for (const lean of [false, true]) {
const n = nextStep(h({ priorRounds: 4, priorFull: FULL_PASS_CAP, lean }));
expect(n.step).toBe('full');
expect(n.reason).toStartWith('read-only final review (R51): this PR already had 2 full review rounds');
}
});
test('after the read-only review: below-floor findings ship as notes, a blocker stops for the lane\'s Captain', () => {
for (const lean of [false, true]) {
expect(nextStep(h({ priorFull: 2, fullPasses: 1, last: 'full', lean })).step).toBe('done');
expect(nextStep(h({ priorFull: 2, fullPasses: 1, last: 'full', fixedBelow: true, lean }), 'standard')).toMatchObject({ step: 'done', reason: expect.stringContaining('no fix round') });
for (const x of [{ blockingOpen: true }, { fixedBlocking: true }, { touchedGate: true, fixedBelow: true }]) {
const stop = nextStep(h({ priorFull: 3, fullPasses: 1, last: 'full', lean, ...x }), 'standard');
expect(stop.step).toBe('stop');
expect(stop.reason).toStartWith('PR_ROUND_CAP: the read-only final review');
expect(stop.reason).toContain("lane's Captain");
}
}
});
// Value: protects=the read-only stop offers only what the Captain can do: a grant recorded after that review can't buy a
// fix round (GST-2706); fails_when=the stop lists a round grant as an option; seam=nextStep; no_claim=history's grant route
// GST-2968 reverses GST-2706's "a later grant buys no fix round": PR_ROUND_CAP printed the grant command anyway, and two grants
// on gstack#4272 bought nothing. The stop now names the fix-check grant that answers its stop record
// (test/round-cap-granted-stop.test.ts covers what that grant buys).
test('the read-only stop offers ship-with-the-note, park, or a fix-check grant naming the stop', () => {
for (const roundGrant of [undefined, 'a-000000000001']) {
const stop = nextStep(h({ priorFull: 3, fullPasses: 1, last: 'full', fixedBlocking: true, roundGrant }), 'standard');
expect(stop.step).toBe('stop');
expect(stop.reason).toContain('(ship with the note, park, or buy its fix round with a fix-check grant naming the stop gstack-ship-receipt stop records)');
expect(stop.reason).not.toContain('does not buy a fix round');
}
});
// GST-2968 (matrix row G3): the granted round keeps its fix round (gstack#4272: the grant raised the cap by one, so a blocker the
// granted pass fixed stopped again at PR_ROUND_CAP), and nothing past it.
test('a round grant buys one more full round at its head with its fix round, never two', () => {
expect(nextStep(h({ priorFull: 2, roundGrant: 'a-1' })).step).toBe('full');
expect(nextStep(h({ priorFull: 3, roundGrant: 'a-1' }))).toMatchObject({ step: 'full', reason: expect.stringContaining('read-only final review') });
for (const depth of ['standard', 'full'] as const) {
const fix = nextStep(h({ priorFull: 2, roundGrant: 'a-1', fullPasses: 1, last: 'full', fixedBlocking: true }), depth);
expect(['full', 'scoped']).toContain(fix.step);
expect(fix.reason).toContain("round grant a-1 bought pass 1 as this PR's full round 3, and this is that round's fix round");
}
expect(nextStep(h({ priorFull: 2, roundGrant: 'a-1', fullPasses: 2, last: 'full', fixedBlocking: true }), 'standard').step).toBe('stop');
expect(nextStep(h({ priorFull: 2, fullPasses: 1, last: 'full', fixedBlocking: true }), 'standard').reason).toStartWith('PR_ROUND_CAP');
});
test('gate class still runs Step 11\'s voices before the PR cap stop', () => {
expect(nextStep(h({ priorFull: 2, fullPasses: 1, last: 'full', blockingOpen: true, gate: true, adversarialRan: false }), 'standard').step).toBe('voices');
});
test('a blocking finding still open keeps today\'s stop', () => {
const n = nextStep(h({ priorFull: 1, fullPasses: 1, last: 'full', blockingOpen: true }), 'standard');
expect(n.step).toBe('stop');
});
});