From 45e6d549e34ee3a4f891f52ae952b3905c9ab4b5 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 19 Nov 2026 21:33:04 +0800 Subject: [PATCH] A second review round reviews a gate-class fix instead of reporting done (GST-3187) (#4520) /ship's second review round now reviews a fix that touched a gate-class path, instead of reporting done with nothing read. A plan told "nothing was fixed" while the branch has new commits since the reviewed head now refuses with `review_required_no_readers` rather than printing done. Nothing to do: the next /ship picks it up. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team --- bin/gstack-review-dispatch | 15 +- bin/gstack-review-plan | 5 + .../round-2-review-runs-after-a-gate-fix.md | 1 + docs/review-policy.md | 1 + docs/troubleshooting.md | 19 +++ lib/gate-outcomes.ts | 5 + lib/review-depth.ts | 2 +- lib/review-targeted-delta.ts | 6 +- .../files/lib/review-depth.ts.json | 2 +- .../review-pins/replays/GST-3187.json | 1 + test/review-depth.test.ts | 25 +++- test/review-risk-token-paths.test.ts | 10 +- test/review-round2-plan.test.ts | 141 ++++++++++++++++++ 13 files changed, 218 insertions(+), 15 deletions(-) create mode 100644 changelog.d/round-2-review-runs-after-a-gate-fix.md create mode 100644 test/fixtures/review-pins/replays/GST-3187.json create mode 100644 test/review-round2-plan.test.ts diff --git a/bin/gstack-review-dispatch b/bin/gstack-review-dispatch index 9db36a121..584a24864 100755 --- a/bin/gstack-review-dispatch +++ b/bin/gstack-review-dispatch @@ -133,7 +133,8 @@ const HELP = `gstack-review-dispatch — verbatim reviewer briefs and loss-free ${exitTableHelp()}`; const args = process.argv.slice(2); -const flag = (n: string) => { const i = args.indexOf(n); return i >= 0 ? args[i + 1] : undefined; }; +const own = args.includes('--') ? args.slice(0, args.indexOf('--')) : args; +const flag = (n: string) => { const i = own.indexOf(n); return i >= 0 ? own[i + 1] : undefined; }; const readFile = (f: string | undefined, what: string) => { if (!f) return undefined; try { return fs.readFileSync(f, 'utf8'); } catch { throw new BriefError(`cannot read ${what} file ${f}`); } @@ -378,17 +379,17 @@ function pass(): number { if (fs.existsSync(file)) { const m = readManifest(file); if (m.pass !== id) throw new BriefError(`${file} belongs to pass ${m.pass}, not ${id}`); - if (m.voices_only && !args.includes('--voices')) throw new BriefError(`${file} holds only Step 11's voices (pass --voices); a reviewer pass needs its own --out`); + if (m.voices_only && !own.includes('--voices')) throw new BriefError(`${file} holds only Step 11's voices (pass --voices); a reviewer pass needs its own --out`); process.stdout.write([...m.plan_lines, `MANIFEST: file=${file} pass=${m.pass} readers=${m.readers.length} resumed`, ...m.readers.map(r => readerLine(m, r))].join('\n') + '\n'); return EXIT.ok; } const planArgs = args.includes('--') ? args.slice(args.indexOf('--') + 1) : []; - if (args.includes('--audit-only')) { + if (own.includes('--audit-only')) { const extrasFile = flag('--extras'); if (!extrasFile) { process.stderr.write('gstack-review-dispatch pass --audit-only: needs --extras (the audit readers, e.g. Step 14.5\'s docs reader)\n'); return EXIT.usage; } const { extras, lines } = withAuditModel(JSON.parse(readFile(extrasFile, 'extras')!) as Extra[]); const m = buildManifest({ pass: id, out, ledger: flag('--ledger') ?? path.join(out, 'review-ledger.jsonl'), base, diffBase: mergeBaseWith(base) ?? 'HEAD', root: git(['rev-parse', '--show-toplevel'])?.trim() ?? process.cwd(), - checklistRoot: flag('--checklist-root') ?? ROOT, dispatches: [], next: 'audit', planLines: ['PASS: audit-only (no reviewer plan; its extras run as one batch)', ...lines], extras, voices: args.includes('--voices') }); + checklistRoot: flag('--checklist-root') ?? ROOT, dispatches: [], next: 'audit', planLines: ['PASS: audit-only (no reviewer plan; its extras run as one batch)', ...lines], extras, voices: own.includes('--voices') }); fs.mkdirSync(m.out, { recursive: true, mode: 0o700 }); const t = sectionTexts(ROOT); renderStage(m, 'first', t, branchDiff); @@ -415,7 +416,7 @@ function pass(): number { const step = p.next.step; const fixChecks = step === 'fix-check' ? [] : p.dispatches.filter(d => d.role === 'fix-check'); const planLines = [...text.stdout.trimEnd().split('\n'), ...fixChecks.map(d => `FIX_CHECK: planned effort=${d.effort} (Step 3.5 runs it on its own; not in this manifest)`)]; - if (step !== 'full' && step !== 'scoped' && step !== 'fix-check' && step !== 'targeted' && !(step === 'voices' && args.includes('--voices'))) { process.stdout.write([...planLines, `PASS: none next=${step} (no reviewer pass; follow NEXT)`].join('\n') + '\n'); return EXIT.ok; } + if (step !== 'full' && step !== 'scoped' && step !== 'fix-check' && step !== 'targeted' && !(step === 'voices' && own.includes('--voices'))) { process.stdout.write([...planLines, `PASS: none next=${step} (no reviewer pass; follow NEXT)`].join('\n') + '\n'); return EXIT.ok; } const rangeBase = step === 'scoped' ? git(['rev-parse', '--verify', '--quiet', `${p.fix_range?.base ?? ''}^{commit}`])?.trim() : undefined; if (step === 'scoped' && !rangeBase) throw new BriefError('a scoped plan names no readable fix range base'); const mergeBase = mergeBaseWith(base); @@ -429,7 +430,7 @@ function pass(): number { dispatches: step === 'fix-check' ? p.dispatches : p.dispatches.filter(d => d.role !== 'fix-check'), next: step, planLines, learnings: readFile(flag('--learnings-file'), 'learnings') ?? null, extras, targetedClasses: p.targeted?.classes, mergeBase, rangeBase: flag('--diff-base') ? undefined : rangeBase, fixCheck: step === 'fix-check' && (flag('--fix-list') || flag('--hunks') || flag('--tests')) ? { fix_list: flag('--fix-list')!, hunks: flag('--hunks')!, tests: flag('--tests')!, callers: flag('--callers') } : undefined, - ...planExclude(p.review_exclude), ...(p.readers ? { readers: p.readers } : {}), voices: args.includes('--voices') }); + ...planExclude(p.review_exclude), ...(p.readers ? { readers: p.readers } : {}), voices: own.includes('--voices') }); const over = ceiling('gstack-review-dispatch pass', base, m.out, m.readers, m.diff_base, (m.review_exclude as PlanExclude) ?? null); if (over) { process.stdout.write(planLines.join('\n') + '\n'); process.stderr.write(over.line + '\n'); return over.exit; } fs.mkdirSync(m.out, { recursive: true, mode: 0o700 }); @@ -505,7 +506,7 @@ function passStep(cmd: string): number { if (before) { const [tokens, credits] = before.split(',').map(Number); if (!Number.isFinite(tokens) || !Number.isFinite(credits)) { process.stderr.write('gstack-review-dispatch mark: --before , [--voices]\n'); return EXIT.usage; } - const key = args.includes('--voices') ? 'before_voices' : 'before'; + const key = own.includes('--voices') ? 'before_voices' : 'before'; m[key] ??= { tokens: tokens!, credits: credits! }; writeManifest(file, m); process.stdout.write(`BEFORE: ${key === 'before_voices' ? 'stage=voices ' : ''}tokens=${m[key]!.tokens} credits=${m[key]!.credits}\n`); diff --git a/bin/gstack-review-plan b/bin/gstack-review-plan index 2f57800e4..9e0d5ff2b 100755 --- a/bin/gstack-review-plan +++ b/bin/gstack-review-plan @@ -28,6 +28,7 @@ import { locate, readRecord } from '../lib/approval-record'; import { reviewRoundGrants } from '../lib/review-round-grant'; import { EXIT, exitTableHelp } from '../lib/headless-artifacts'; import { resultLine } from '../lib/result-codes'; +import { gateOutcomeLine } from '../lib/gate-outcomes'; import { runScriptSync } from '../lib/script-invocation'; import { baseNote } from '../lib/gate-diff/git'; import { collectCommit, collectLive, reviewPlanTimeoutMs } from '../lib/review-collect'; @@ -298,6 +299,10 @@ function main(): number { plan.next = { step: 'targeted', reason: `the loop is done and ${why} after the targeted read at ${delta.range_base.slice(0, 12)}: one targeted reader reads HEAD for ${classList(targeted.classes)}; it is not a review round` }; plan.dispatches.push({ role: 'targeted', name: 'targeted', effort: ROLE_EFFORT.targeted, exclude: active ? [...active.specs] : [], classes: [...targeted.classes], ...(active?.keep.length ? { keep: [...active.keep] } : {}) }); } else if (delta) plan.skipped.push(`targeted-only read (${delta.reason})`); + if (last === 'full' && plan.next.step === 'done' && fixRange && fixRange.runtime_lines !== null && !ran && !(delta?.state === 'skip' && delta.carried) && !postReview && !['--fixed-blocking', '--fixed-below', '--blocking-open', '--touched-gate'].some(has)) { + process.stderr.write(`${gateOutcomeLine('gstack-review-plan', 'review_required_no_readers', `--pass ${pass} --last ${last} names no fix, but the PR's own change since --range-base ${fixRange.base.slice(0, 12)} has ${fixRange.runtime_lines} runtime line${fixRange.runtime_lines === 1 ? '' : 's'}`)} (review_required_no_readers)\n`); + return EXIT.refused; + } const targetedDeltaOut = delta?.state === 'dispatch' ? { range_base: delta.range_base, paths: delta.paths, classes: targeted.classes } : null; const selection = policySelection(active && { state: 'active', specs: active.specs, keep: active.keep, excerpt: active.excerpt }, readers); plan.dispatches.forEach((d, i) => { if (d.role !== 'fix-check') plan.dispatches[i] = selectFor(d, selection); }); diff --git a/changelog.d/round-2-review-runs-after-a-gate-fix.md b/changelog.d/round-2-review-runs-after-a-gate-fix.md new file mode 100644 index 000000000..3ee74289b --- /dev/null +++ b/changelog.d/round-2-review-runs-after-a-gate-fix.md @@ -0,0 +1 @@ +- **A second review round no longer reports done when nothing was reviewed.** After the first review pass, a fix that touched a gate-class path (CI, auth, merge checks) was planned as "the step applied no edits" unless another fix flag came with it, so /ship's round 2 printed done and no reviewer read the fix. That fix now gets its full review pass on the changed range. When the plan is told nothing was fixed but the branch has new commits since the reviewed head, it now refuses with `review_required_no_readers` instead of printing done. `gstack-review-dispatch` also stops reading its own flags out of the review-plan flags after `--`, so a plan's `--pass 1` can no longer stand in for the pass id. diff --git a/docs/review-policy.md b/docs/review-policy.md index d99cd931a..183b88f79 100644 --- a/docs/review-policy.md +++ b/docs/review-policy.md @@ -247,6 +247,7 @@ caught on another crew's PRs. |---|---| | none | full pass 1 on the whole diff | | a full pass with no edits | done | +| a full pass (`--last full`) with no fix flag, when the PR has its own unreviewed runtime commits since `--range-base` | stop: `review_required_no_readers` (exit 3), not done; see [troubleshooting](troubleshooting.md#review-required-no-readers) | | a full pass that fixed a blocking finding, below the cap, on a diff below full depth with a fix range of at most 150 runtime lines | scoped pass on the range | | a full pass that fixed a blocking finding, below the cap (full depth, a larger range, or a range or depth it could not read) | full pass on the range | | a full pass whose fix touched a gate-class path, below the cap | full pass on the range | diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 87ee3e3a2..ba8249807 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -4187,6 +4187,25 @@ plan that ran past the limit was killed with no output (GST-1442). repository's file count (`git ls-files | wc -l`) to your Captain. For `reason=signal`, check the machine's free memory first. + +### `gstack-review-plan: not run (commits after the reviewed head would ship with no reviewer ...) (review_required_no_readers)` + +**Meaning.** After a full review pass (`--last full`), the plan was told the +step fixed nothing: no `--fixed-blocking`, `--fixed-below`, +`--touched-gate` or `--blocking-open`. But `--range-base` shows the PR has its +own new commits since the reviewed head. Planning `done` there would ship those +commits with no reviewer, so the plan refuses (exit 3) and prints no plan; +`gstack-review-dispatch pass` stops on it before it creates any reader. Before +this refusal, a round-2 /ship could report the review done with nothing read +(GST-3187). + +**Fix.** Pass the flags that hold for what the step changed and plan again: +`--fixed-blocking` for a fixed blocker, `--fixed-below` for fixes below the +floor, `--touched-gate` when a fix edited a gate-class path. A gate-class edit +on its own now plans a full pass on the range. If the commits since +`--range-base` are not review fixes, pass the head the review actually read as +`--range-base`. + ### `REVIEW_EXCLUDE_REFERENCE` diff --git a/lib/gate-outcomes.ts b/lib/gate-outcomes.ts index aec6c9b78..7e1151e6f 100644 --- a/lib/gate-outcomes.ts +++ b/lib/gate-outcomes.ts @@ -138,6 +138,11 @@ export const GATE_OUTCOMES = { summary: 'the configured version file is missing, empty, unreadable or malformed', fix: 'fix that file, or correct --version-path / .gstack/version-path', }, + review_required_no_readers: { + state: 'not_run', anchor: 'review-required-no-readers', + summary: 'commits after the reviewed head would ship with no reviewer, because the plan was told the step applied no fix', + fix: 'pass the flags the step left (--fixed-blocking, --fixed-below, --touched-gate or --blocking-open) and plan again; the plan refuses rather than printing done (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#review-required-no-readers)', + }, no_plan_bound: { state: 'not_run', anchor: 'plan-audit-not-run', summary: 'no plan is bound to this branch and no docs/designs/ file matches', diff --git a/lib/review-depth.ts b/lib/review-depth.ts index 1dc60ee9a..755a8d901 100644 --- a/lib/review-depth.ts +++ b/lib/review-depth.ts @@ -472,7 +472,7 @@ function leanStep(h: History, depth?: Depth): NextStep { function loopStep(h: History, depth?: Depth): NextStep { if (h.last === 'none') return { step: 'full', reason: 'pass 1 reviews the whole diff' }; - const fixed = !!(h.fixedBlocking || h.fixedBelow); + const fixed = !!(h.fixedBlocking || h.fixedBelow || h.touchedGate); if (h.last === 'fix-check') return h.blockingOpen || h.fixedBlocking || h.touchedGate ? { step: 'stop', reason: `the fix-check ${h.touchedGate && !h.blockingOpen && !h.fixedBlocking ? 'edited a gate-class path' : 'found a blocking finding'}: name it for the owner, whose grant may add one scoped fix-check, never a third round` } : { step: 'done', reason: fixed ? 'round cap 2 reached: the below-floor fixes ship as notes in the PR body and receipt' : 'the fix-check found nothing blocking' }; if (h.blockingOpen && h.fullPasses >= FULL_PASS_CAP) return { step: 'stop', reason: `a blocking finding is open after ${FULL_PASS_CAP} rounds: name it for the owner` }; if (h.blockingOpen) return { step: 'stop', reason: 'a blocking finding is still open in fix scope: name it for the owner' }; diff --git a/lib/review-targeted-delta.ts b/lib/review-targeted-delta.ts index ab2c686a6..288c0949a 100644 --- a/lib/review-targeted-delta.ts +++ b/lib/review-targeted-delta.ts @@ -16,7 +16,7 @@ import { spawnSync } from './spawn-sync'; import { comparePath, touchedPaths } from './ship-patch'; import { docsChangeSince } from './ship-receipt-depth'; -export type TargetedDelta = { state: 'dispatch'; range_base: string; paths: string[] } | { state: 'skip'; reason: string }; +export type TargetedDelta = { state: 'dispatch'; range_base: string; paths: string[] } | { state: 'skip'; reason: string; carried?: true }; /** Whether the change since `rangeBase` (where the targeted reader read the patch `ran`) earns the targeted-only read. */ export function targetedDelta(root: string, base: string, rangeBase: string, ran: string, granted = false): TargetedDelta { @@ -24,7 +24,7 @@ export function targetedDelta(root: string, base: string, rangeBase: string, ran const r = spawnSync('git', ['-c', 'core.quotePath=false', ...args], { cwd: root, input, encoding: 'utf8', timeout: 60_000, maxBuffer: 256 * 1024 * 1024 }); return r.status === 0 ? r.stdout : null; }; - const skip = (reason: string): TargetedDelta => ({ state: 'skip', reason }); + const skip = (reason: string, carried?: true): TargetedDelta => ({ state: 'skip', reason, ...(carried ? { carried } : {}) }); const read = git(['rev-parse', '--verify', '--quiet', `${rangeBase}^{commit}`])?.trim(); const head = git(['rev-parse', '--verify', '--quiet', 'HEAD^{commit}'])?.trim(); if (!read || !head || git(['merge-base', '--is-ancestor', read, head]) === null) return skip(`range_base ${rangeBase} is not a commit on this branch`); @@ -44,6 +44,6 @@ export function targetedDelta(root: string, base: string, rangeBase: string, ran const change = docsChangeSince(root, read, head, base); if (!change) return skip(`git could not build the PR's own change since range_base ${read.slice(0, 12)}`); if (change.verdict === 'code' && !granted) return skip(`the change since range_base ${read.slice(0, 12)} is not docs-only (${change.paths.join(', ')}), so it takes the review loop`); - if (change.verdict === 'plain') return skip(`the change since range_base ${read.slice(0, 12)} is ${change.paths.length ? 'plain docs' : 'release stamps'}${change.paths.length && change.stamps.length ? ' and release stamps' : ''}, which the targeted record carries (GST-1195, GST-1689)`); + if (change.verdict === 'plain') return skip(`the change since range_base ${read.slice(0, 12)} is ${change.paths.length ? 'plain docs' : 'release stamps'}${change.paths.length && change.stamps.length ? ' and release stamps' : ''}, which the targeted record carries (GST-1195, GST-1689)`, true); return { state: 'dispatch', range_base: read, paths: [...change.paths] }; } diff --git a/test/fixtures/review-pins/files/lib/review-depth.ts.json b/test/fixtures/review-pins/files/lib/review-depth.ts.json index c0832119c..9e8441b2e 100644 --- a/test/fixtures/review-pins/files/lib/review-depth.ts.json +++ b/test/fixtures/review-pins/files/lib/review-depth.ts.json @@ -1 +1 @@ -{"sha":"e1f36b11928b2310a346f46a031cfa5a955db9c036036f43cc36512c8d772870","replay":"GST-2968"} +{"sha":"769ebe909a205e7968d6e5fb8e9d0ce08d896d358d1d3bae984a3c2a68696796","replay":"GST-3187"} diff --git a/test/fixtures/review-pins/replays/GST-3187.json b/test/fixtures/review-pins/replays/GST-3187.json new file mode 100644 index 000000000..b34180fb3 --- /dev/null +++ b/test/fixtures/review-pins/replays/GST-3187.json @@ -0,0 +1 @@ +{"replay":"GST-3187","justification":"GST-3187: lib/review-depth.ts changes one line in loopStep: a fix that touched a gate-class path (touchedGate) now counts as a fix, as it already did in leanStep and after a fix-check, so --last full --touched-gate with no other fix flag plans its review instead of done 'the step applied no edits' (gbrain#9799's round 2 reported done with nothing reviewed). Deterministic no-loss replay, no paid run, in test/review-depth.test.ts: over the GST-967 1,440-case grid the branch's plans, with the 30 changed cases read back as main's (the same input with touchedGate unset, asserted to be main's done 'the step applied no edits'), hash to MAIN_PLANS from main 1022f4f unchanged; every changed case is last=full with touchedGate as the only fix flag, and each moves from done with no reader to a review step or the owner stop, none the other way (full 20, stop 9, voices 1). The GST-972 and GST-1350 grids keep MAIN_972_PLANS and MAIN_1350_PLANS with the same read-back on their stand-ins and still find every reader main dispatched. No reader, depth, dispatch, brief, checklist or finding rule changes; brief bodies keep their pinned hashes."} diff --git a/test/review-depth.test.ts b/test/review-depth.test.ts index 86a1c63e6..695ff1d02 100644 --- a/test/review-depth.test.ts +++ b/test/review-depth.test.ts @@ -207,6 +207,20 @@ function asMainBeforeR51(p: ReturnType): { dispatches: typeof expect(p.skipped.slice(at, at + 2)).toEqual(['specialists except testing (tests class)', R51_SKIP]); return { dispatches: p.dispatches.slice(1), skipped: [...p.skipped.slice(0, at), 'specialists, red-team and adversarial-native (light depth, runtime 0)', ...p.skipped.slice(at + 2)], added: true }; } +/** + * GST-3187 adds review and drops none: after a full pass, a fix that touched a gate-class path with no other fix flag plans its + * review (a full pass on the range, or the owner stop at the cap, with Step 11's voices first on gate class) where main planned + * done "the step applied no edits". asMainBeforeGst3187 checks each such case and reads it back as main's plan, which is the + * same input with touchedGate unset. + */ +function asMainBeforeGst3187(input: PlanInput, p: ReturnType): { plan: ReturnType; changed?: string } { + const h = input.history; + if (!(h.last === 'full' && h.touchedGate && !h.fixedBlocking && !h.fixedBelow && !h.blockingOpen)) return { plan: p }; + expect(['full', 'stop', 'voices']).toContain(p.next.step); + const main = planReview({ ...input, history: { ...h, touchedGate: false } }); + expect(main.next).toEqual({ step: 'done', reason: 'the step applied no edits' }); + return { plan: main, changed: p.next.step }; +} const MAIN_PLANS = '9d13d6bae86bfc9207ce7e0cec8da5b33db2518c1653e8e009160a98b0f04c89'; const R51_CASES = 28; const MAIN_SECTIONS = '7eb6b4c2dd31edbd7c69f02bd31f8884407187fac8ace4e796632d60957b6bbb'; @@ -225,9 +239,12 @@ describe('GST-967 dispatch-superset no-loss check', () => { const rows: unknown[] = []; let voices = 0; let r51 = 0; + const gst3187: Record = {}; for (const [name, f] of Object.entries(fixtures)) for (const fullPasses of [0, 1, 2]) for (const last of ['none', 'full', 'fix-check'] as const) for (let bits = 0; bits < 16; bits++) for (const adversarialRan of [false, true]) { const history = { fullPasses, last, fixedBlocking: !!(bits & 1), fixedBelow: !!(bits & 2), blockingOpen: !!(bits & 4), touchedGate: !!(bits & 8) }; - const p = planReview({ ...f, numbers: none, history, adversarialRan } as PlanInput); + const input = { ...f, numbers: none, history, adversarialRan } as PlanInput; + const { plan: p, changed } = asMainBeforeGst3187(input, planReview(input)); + if (changed) gst3187[`${name}:${changed}`] = (gst3187[`${name}:${changed}`] ?? 0) + 1; let { step, reason } = p.next; const back = asMainBeforeR51(p); if (back.added) r51++; @@ -240,6 +257,9 @@ describe('GST-967 dispatch-superset no-loss check', () => { rows.push({ name, fullPasses, last, bits, adversarialRan, class: p.class, step, reason, dispatches, skipped: back.skipped }); } expect([rows.length, voices, r51, sha(rows)]).toEqual([1440, 71, R51_CASES, MAIN_PLANS]); + expect(gst3187).toEqual({ + 'docs:full': 4, 'docs:stop': 2, 'gate:full': 4, 'gate:stop': 1, 'gate:voices': 1, 'light:full': 4, 'light:stop': 2, 'standard:full': 4, 'standard:stop': 2, 'tests:full': 4, 'tests:stop': 2, + }); expect(sha(sectionTexts(ROOT))).toBe(MAIN_SECTIONS); }); }); @@ -289,7 +309,8 @@ describe('GST-972 follow-up no-loss check', () => { const rows: { name: string; fullPasses: number; last: string; bits: number; adversarialRan: boolean; class: string; depth: string; step: string; dispatches: { role: string; name: string; effort: string; checklists: string[] }[] }[] = []; for (const [name, c] of Object.entries(cases)) for (const fullPasses of [0, 1, 2]) for (const last of ['none', 'full', 'fix-check'] as const) for (let bits = 0; bits < 16; bits++) for (const adversarialRan of [false, true]) { const history = { fullPasses, last, fixedBlocking: !!(bits & 1), fixedBelow: !!(bits & 2), blockingOpen: !!(bits & 4), touchedGate: !!(bits & 8) }; - const p = planReview({ paths: c[pick], scope: c[2], gateTagged: 0, diffLines: 40, consumed: [], numbers: none, history, adversarialRan }); + const input = { paths: c[pick], scope: c[2], gateTagged: 0, diffLines: 40, consumed: [], numbers: none, history, adversarialRan } as PlanInput; + const p = pick ? asMainBeforeGst3187(input, planReview(input)).plan : planReview(input); rows.push({ name, fullPasses, last, bits, adversarialRan, class: p.class, depth: p.depth, step: p.next.step, dispatches: (pick ? asMainBeforeR51(p).dispatches : p.dispatches).map(d => ({ role: d.role, name: d.name, effort: d.effort, checklists: d.checklists ?? [] })) }); } return rows; diff --git a/test/review-risk-token-paths.test.ts b/test/review-risk-token-paths.test.ts index 4e96b1300..5ba7534ee 100644 --- a/test/review-risk-token-paths.test.ts +++ b/test/review-risk-token-paths.test.ts @@ -124,6 +124,8 @@ describe('GST-1350: founderstar#546 shape, a copy-only edit to a Godot token fil * the specialist effort on the three key files that rise to full, while the Red Team keeps full effort as its own dispatch. */ const MAIN_1350_PLANS = 'bafc2b5329237dbb994ab85d5ee0a696e7bd479615f81206c9b4ce7507af108e'; +// GST-3187: on the stand-ins, a full pass whose only fix flag is touchedGate now plans its review where main planned done; those +// cases are checked to be a review step and read back as main's plan (the same input with touchedGate unset). describe('GST-1350 no-loss check', () => { // Value: protects=the no-loss rule for review-depth changes: narrowing the token name drops readers only on benign token files; // fails_when=a stand-in stops matching main's plans, a token file with a secret or a secrets, credentials or key file loses a @@ -154,7 +156,13 @@ describe('GST-1350 no-loss check', () => { const t = targetedClasses({ paths, added, removed: {}, scope: {}, gateTagged: 0, consumed: [] }).classes; for (const fullPasses of [0, 1, 2]) for (const last of ['none', 'full', 'fix-check'] as const) for (let bits = 0; bits < 16; bits++) for (const adversarialRan of [false, true]) { const history = { fullPasses, last, fixedBlocking: !!(bits & 1), fixedBelow: !!(bits & 2), blockingOpen: !!(bits & 4), touchedGate: !!(bits & 8) }; - const p = planReview({ paths, added, removed: {}, scope: {}, gateTagged: 0, diffLines: 40, consumed: [], numbers: none, history, adversarialRan, targeted: { classes: t } }); + const input = { paths, added, removed: {}, scope: {}, gateTagged: 0, diffLines: 40, consumed: [], numbers: none, history, adversarialRan, targeted: { classes: t } }; + let p = planReview(input); + if (pick && last === 'full' && bits === 8) { + expect(['full', 'stop', 'voices']).toContain(p.next.step); + p = planReview({ ...input, history: { ...history, touchedGate: false } }); + expect(p.next).toEqual({ step: 'done', reason: 'the step applied no edits' }); + } rows.push({ name, fullPasses, last, bits, adversarialRan, targeted: t, class: p.class, depth: p.depth, step: p.next.step, dispatches: p.dispatches.map(d => ({ role: d.role, name: d.name, effort: d.effort, checklists: d.checklists ?? [] })) }); } } diff --git a/test/review-round2-plan.test.ts b/test/review-round2-plan.test.ts new file mode 100644 index 000000000..3189606c2 --- /dev/null +++ b/test/review-round2-plan.test.ts @@ -0,0 +1,141 @@ +/** + * GST-3187: a round-2 /ship on gbrain#9799 planned `done` with nothing reviewed. Its plan flags were + * `--pass 1 --last full --touched-gate`: the full-pass loop counted a fix only from --fixed-blocking or --fixed-below, so a + * fix that touched a gate-class path read as "the step applied no edits". The same pass also showed gstack-review-dispatch + * reading its own flags out of the plan flags after `--`. These cases pin the exact round-2 call shape the Capy pass + * program builds (`pass --base --out --pass -- `) and the refusal that stops a plan from + * printing done over unreviewed commits. + */ +import { afterEach, describe, expect, test } from 'bun:test'; +import { spawnSync } from 'node:child_process'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; +import { FULL_PASS_CAP, nextStep } from '../lib/review-depth'; + +const DISPATCH = path.join(import.meta.dir, '..', 'bin', 'gstack-review-dispatch'); +const PLAN = path.join(import.meta.dir, '..', 'bin', 'gstack-review-plan'); +const dirs: string[] = []; +afterEach(() => { while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); }); + +function fixture() { + const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'round2-plan-'))); + dirs.push(root); + const work = path.join(root, 'work'); + const env = { ...process.env, GSTACK_STATE_ROOT: path.join(root, 'state'), GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t', GIT_CONFIG_GLOBAL: path.join(root, 'gitconfig'), GIT_CONFIG_NOSYSTEM: '1' }; + fs.writeFileSync(path.join(root, 'gitconfig'), '[commit]\n\tgpgsign = false\n[init]\n\tdefaultBranch = main\n'); + const git = (cwd: string, ...a: string[]) => { const r = spawnSync('git', a, { cwd, env, encoding: 'utf8', timeout: 60_000 }); if (r.status !== 0) throw new Error(`git ${a.join(' ')}: ${r.stderr}`); return r.stdout.trim(); }; + git(root, 'init', '-q', '--bare', 'origin.git'); + git(root, 'clone', '-q', 'origin.git', 'work'); + const write = (p: string, text: string) => { fs.mkdirSync(path.dirname(path.join(work, p)), { recursive: true }); fs.writeFileSync(path.join(work, p), text); }; + const commit = (files: Record, msg: string) => { for (const [p, t] of Object.entries(files)) write(p, t); git(work, 'add', '-A'); git(work, 'commit', '-qm', msg); return git(work, 'rev-parse', 'HEAD'); }; + commit({ 'src/a.ts': Array.from({ length: 40 }, (_, i) => `export const a${i} = ${i};\n`).join('') }, 'base'); + git(work, 'push', '-q', 'origin', 'main'); + git(work, 'checkout', '-qb', 'feat'); + const pass1 = commit({ '.github/workflows/ci.yml': 'on: push\n', 'src/b.ts': 'export const b = 2;\n' }, 'feat'); + const run = (bin: string, args: string[]) => spawnSync(bin, args, { cwd: work, env, encoding: 'utf8', timeout: 120_000 }); + const pass = (out: string, planFlags: string[], own = ['--pass', 'e2e1-p2']) => run(DISPATCH, ['pass', '--base', 'main', '--out', path.join(root, out), ...own, '--', ...planFlags]); + return { root, work, commit, pass1, pass, run }; +} +const line = (out: string, prefix: string) => out.split('\n').find(l => l.startsWith(prefix)) ?? ''; + +describe('GST-3187: the round-2 plan flags reach the planner and a gate-class fix is reviewed', () => { + // Value: protects=the exact round-2 pass the Capy program runs on a gate-class PR plans a full pass with readers; + // fails_when=it prints PASS: none next=done (gbrain#9799: "the step applied no edits" after a fix that touched a gate path); + // why_new=GST-3187; seam=gstack-review-dispatch pass on a real repo; no_claim=what the readers find + test('pass --pass -- --pass 1 --last full --touched-gate plans a full pass on the range, with readers', () => { + const f = fixture(); + const r = f.pass('p2', ['--pass', '1', '--last', 'full', '--touched-gate']); + expect(r.status, r.stdout + r.stderr).toBe(0); + expect(line(r.stdout, 'REVIEW_PLAN: ')).toMatch(/^REVIEW_PLAN: class=gate pass=2 next=full /); + expect(r.stdout).toContain('NEXT: full (a fix touched a gate-class path: full pass on the range)'); + expect(r.stdout).not.toContain('PASS: none'); + expect(line(r.stdout, 'MANIFEST: ')).toMatch(/ pass=e2e1-p2 readers=[1-9]/); + }, 180_000); + + // Value: protects=the round-2 shape /ship's Step 9 writes (with --range-base at the reviewed head) after a real gate-class fix + // commit plans a review; fails_when=a fix range the planner itself measured as touching a gate path still plans done; + // seam=gstack-review-dispatch pass; no_claim=the range's runtime line count + test('the same shape with --range-base over a committed gate-class fix plans the full pass', () => { + const f = fixture(); + f.commit({ '.github/workflows/ci.yml': 'on: [push, pull_request]\n' }, 'fix: the workflow trigger'); + const r = f.pass('p2', ['--pass', '1', '--last', 'full', '--touched-gate', '--range-base', f.pass1]); + expect(r.status, r.stdout + r.stderr).toBe(0); + expect(r.stdout).toMatch(/^NEXT: full /m); + expect(line(r.stdout, 'MANIFEST: ')).toMatch(/ readers=[1-9]/); + }, 180_000); + + // Value: protects=dispatch reads its own flags only before `--`: the plan's --pass is never taken as the pass id, and the + // plan's flags reach gstack-review-plan unchanged; fails_when=a pass with no --pass of its own runs as pass "1" (it did on + // main), or a plan flag after -- switches dispatch into --audit-only; seam=gstack-review-dispatch pass; no_claim=render's tail + test('dispatch never takes its own flags from the plan flags after --', () => { + const f = fixture(); + const missing = f.pass('p2', ['--pass', '1', '--last', 'full', '--fixed-blocking'], []); + expect(missing.status).toBe(2); + expect(missing.stderr).toContain('needs --base , --out and --pass '); + expect(fs.existsSync(path.join(f.root, 'p2', 'pass-manifest.json'))).toBe(false); + const audit = f.pass('p3', ['--audit-only', '--pass', '1', '--last', 'full', '--fixed-blocking']); + expect(audit.status, audit.stdout + audit.stderr).toBe(0); + expect(audit.stdout).not.toContain('PASS: audit-only'); + expect(line(audit.stdout, 'REVIEW_PLAN: ')).toMatch(/ pass=2 next=full /); + expect(line(audit.stdout, 'MANIFEST: ')).toMatch(/ pass=e2e1-p2 readers=[1-9]/); + }, 180_000); +}); + +describe('GST-3187: a plan that would ship unreviewed commits refuses instead of printing done', () => { + // Value: protects=after a full pass, commits since --range-base with no fix flag fail closed with review_required_no_readers + // (exit 3 from the plan, no manifest from dispatch); fails_when=the plan prints NEXT: done "the step applied no edits" over + // a runtime commit nobody reviewed; seam=gstack-review-plan and gstack-review-dispatch pass; no_claim=which flag was right + test('a runtime commit since --range-base with no fix flag refuses with review_required_no_readers', () => { + const f = fixture(); + f.commit({ 'src/b.ts': 'export const b = 3;\n' }, 'fix: b'); + const flags = ['--pass', '1', '--last', 'full', '--range-base', f.pass1]; + const plan = f.run(PLAN, ['--base', 'main', ...flags]); + expect(plan.status).toBe(3); + expect(plan.stderr).toContain('gstack-review-plan: not run (commits after the reviewed head would ship with no reviewer'); + expect(plan.stderr.trimEnd().endsWith('(review_required_no_readers)')).toBe(true); + expect(plan.stdout).not.toContain('NEXT: done'); + expect(f.run(PLAN, ['--base', 'main', ...flags, '--json']).status).toBe(3); + const pass = f.pass('p2', flags); + expect(pass.status).not.toBe(0); + expect(pass.stderr).toContain('(review_required_no_readers)'); + expect(fs.existsSync(path.join(f.root, 'p2', 'pass-manifest.json'))).toBe(false); + }, 180_000); + + // Value: protects=--targeted-ran exempts the refusal only when the targeted read covers HEAD or carries the change, never by + // being present; fails_when=a stale or foreign --targeted-ran turns a runtime commit nobody reviewed into NEXT: done; + // seam=gstack-review-plan; no_claim=the docs-carry path, which review-plan-targeted-delta.test.ts covers + test('a --targeted-ran that does not cover the runtime commit still refuses', () => { + const f = fixture(); + f.commit({ 'src/b.ts': 'export const b = 3;\n' }, 'fix: b'); + const plan = f.run(PLAN, ['--base', 'main', '--pass', '1', '--last', 'full', '--range-base', f.pass1, '--targeted-ran', 'deadbeef']); + expect(plan.status, plan.stdout + plan.stderr).toBe(3); + expect(plan.stderr.trimEnd().endsWith('(review_required_no_readers)')).toBe(true); + expect(plan.stdout).not.toContain('NEXT: done'); + }, 180_000); + + // Value: protects=the refusal fires only on unreviewed commits: no commit since the reviewed head is still done, and a flagged + // below-floor fix still plans its fix-check; fails_when=the guard refuses a clean pass 1 or a flagged fix; + // seam=gstack-review-plan; no_claim=the fix-check's verdict + test('no commit since the reviewed head is done, and a flagged fix plans its review', () => { + const f = fixture(); + const clean = f.run(PLAN, ['--base', 'main', '--pass', '1', '--last', 'full', '--range-base', f.pass1]); + expect(clean.status, clean.stderr).toBe(0); + expect(clean.stdout).toContain('NEXT: done (the step applied no edits)'); + f.commit({ 'src/b.ts': 'export const b = 3;\n' }, 'fix: b'); + const flagged = f.run(PLAN, ['--base', 'main', '--pass', '1', '--last', 'full', '--fixed-below', '--range-base', f.pass1]); + expect(flagged.status, flagged.stderr).toBe(0); + expect(flagged.stdout).not.toMatch(/^NEXT: done /m); + }, 180_000); +}); + +describe('GST-3187: nextStep counts a gate-class fix as an edit', () => { + // Value: protects=--touched-gate alone after a full pass plans the full pass on the range, and at the cap it stops for the + // owner; fails_when=loopStep's fix test ignores touchedGate (it returned done "the step applied no edits"); + // seam=nextStep; no_claim=the gate-class voices' ordering, which GST-967's cases cover + test('--touched-gate with no other fix flag is a fix', () => { + expect(nextStep({ fullPasses: 1, last: 'full', touchedGate: true })).toMatchObject({ step: 'full', reason: 'a fix touched a gate-class path: full pass on the range' }); + expect(nextStep({ fullPasses: FULL_PASS_CAP, last: 'full', touchedGate: true }).step).toBe('stop'); + expect(nextStep({ fullPasses: 1, last: 'full' })).toMatchObject({ step: 'done', reason: 'the step applied no edits' }); + }); +});