The PR body check ignores comment openers quoted in code, and the review plan refuses a wrong pass count (GST-4110) (#4874)

The PR body check no longer loses the closing Agent notes section when
the text quotes an HTML comment opener in inline code or a code block.

Why: a quoted opener hid that section, so bodies were refused for text
that sat in the right place; the review plan's `--pass` was also easy to
misread as the next pass.

Nothing to do: bodies and plans that passed before still pass.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=specialist-batched
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/specialist-batched#2 reader=specialist-batched
Review-Finding: p2/red-team#1 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-28 12:59:14 +00:00
1 parent 586e51b10e
commit 09e2f44f27
6 files changed
+166 -5

No files matched your search

+25 -3
View File
@@ -2,7 +2,7 @@
/**
* gstack-review-plan — how much review the next /ship step dispatches (docs/review-policy.md#review-depth).
*
* gstack-review-plan --base <ref> [--pass <full passes run>] [--last none|full] [--fixed-blocking] [--fixed-below]
* gstack-review-plan --base <ref> [--pass <full passes finished>] [--last none|full] [--fixed-blocking] [--fixed-below]
* [--blocking-open] [--touched-gate] [--critical-found] [--adversarial-ran] [--gate-tagged <n>] [--gated a,b] [--force a,b|all]
* [--reviewed-numbers <fingerprint>] [--depth-floor standard|full] [--range-base <sha>] [--pass1-depth light|standard|full] [--no-tiers]
* [--targeted-ran <targeted_patch_id>] [--post-review] [--pr <n>] [--json]
@@ -43,11 +43,16 @@ import { ruledCarries, targetedDelta } from '../lib/review-targeted-delta';
import { ownChangeSince, stampPathsSince } from '../lib/ship-receipt-depth';
import { RISK_CLASSES, type RiskClass } from '../lib/review-risk';
import { readRuledNotes, ruledEditLine, ruledEdits } from '../lib/ruled-notes';
import { readRunRecord } from '../lib/ship-run-record';
import { reviewPaths } from '../lib/ship-budget';
import { summarizeReviewLoop } from '../lib/review-scope';
const HELP = `gstack-review-plan — the review depth of the next /ship step (docs/review-policy.md#review-depth)
--base <ref> the base branch (merge base with HEAD is the diff base); required
--pass <n> full review passes already run in this invocation (default 0)
--pass <n> full review passes this /ship run already finished (default 0), printed as PASS_COUNT:;
not the number of the pass about to run: plan pass 2 with --pass 1 --last full. Inside an open /ship
run, --last full refuses (exit 2) a --pass other than the passes this branch's review log holds for it
--last none|full the step that just finished (default none: plan pass 1)
--fixed-blocking the finished step fixed a blocking finding (raises light to standard)
--fixed-below the finished step fixed findings below the floor
@@ -107,6 +112,19 @@ const has = (n: string) => args.includes(n);
const list = (n: string) => (flag(n) ?? '').split(',').map(s => s.trim()).filter(Boolean);
const git = (a: string[]) => { const r = spawnSync('git', ['-c', 'core.quotePath=false', ...a], { encoding: 'utf8', timeout: 60_000, maxBuffer: 64 * 1024 * 1024 }); return r.status === 0 ? r.stdout : null; };
/**
* The full passes the checkout's open /ship run already logged, counted the way the receipt counts them: gstack-review-scope's
* summarizeReviewLoop over this branch's review log since the run record started. Null when no run is open or the log cannot be read.
*/
function loggedPasses(root: string): { passes: number; run: string } | null {
const read = readRunRecord(root);
if (read.kind !== 'record' || read.record.state !== 'open') return null;
let text = '';
try { text = fs.readFileSync(reviewPaths(root, process.env).reviewLog, 'utf8'); } catch (e: any) { if (e?.code !== 'ENOENT') return null; }
const rows = text.split('\n').flatMap(line => { try { return [JSON.parse(line) as Record<string, any>]; } catch { return []; } });
return { passes: summarizeReviewLoop(rows, read.record.started_at).passes, run: read.record.run };
}
function main(): number {
if (has('--help') || has('-h')) { process.stdout.write(HELP + '\n'); return EXIT.ok; }
const base = flag('--base');
@@ -132,6 +150,8 @@ function main(): number {
const priorRounds = Number(flag('--prior-rounds') ?? '0');
const priorFull = Number(flag('--prior-full') ?? '0');
if (![priorRounds, priorFull].every(n => Number.isInteger(n) && n >= 0)) { process.stderr.write('gstack-review-plan: --prior-rounds and --prior-full need integers >= 0 (PR_REVIEW_FLAGS: from gstack-ship-preflight)\n'); return EXIT.usage; }
const logged = last === 'full' ? loggedPasses(root) : null;
if (logged && logged.passes !== pass) { process.stderr.write(`gstack-review-plan: --pass ${pass} says ${pass} full pass${pass === 1 ? '' : 'es'} finished, but the review log holds ${logged.passes} for /ship run ${logged.run}; --pass counts the passes already finished, not the pass about to run, so rerun with --pass ${logged.passes} (GSTA-891)\n`); return EXIT.usage; }
const collected = collectLive(root, base);
if (collected.errors.length) {
for (const e of collected.errors) process.stderr.write(`gstack-review-plan: git could not list the diff (${e.input}: ${e.detail}); fix: ${e.repair}; no plan is safer than a plan for an empty diff\n`);
@@ -275,7 +295,9 @@ function main(): number {
for (const [p, n] of routed?.ruled ?? []) out.push(ruledEditLine(p, n));
for (const x of routed?.refused ?? []) out.push(`RULED_EDIT_REFUSED: ${x}`);
if (targetedDeltaOut) out.push(`TARGETED_DELTA: range_base=${targetedDeltaOut.range_base} paths=${targetedDeltaOut.paths.join(',')} classes=${classList(targetedDeltaOut.classes)}`);
out.push(reviewPlanLine(plan, pass + (plan.next.step === 'full' || plan.next.step === 'scoped' ? 1 : 0), priorRounds), `NEXT: ${plan.next.step} (${plan.next.reason})`);
const another = plan.next.step === 'full' || plan.next.step === 'scoped';
out.push(reviewPlanLine(plan, pass + (another ? 1 : 0), priorRounds), `NEXT: ${plan.next.step} (${plan.next.reason})`);
out.push(`PASS_COUNT: finished=${pass}${another ? ` next_pass=${pass + 1} (after pass ${pass + 1} finishes, plan again with --pass ${pass + 1} --last full)` : ''}`);
for (const e of plan.errors) out.push(`DEPTH_ERROR: ${e.code} input=${e.input} detail=${e.detail}; fix: ${e.repair}${e.result ? ` (${e.result})` : ''}`);
for (const d of plan.dispatches) {
const key = d.name.split(' ')[0];
@@ -0,0 +1 @@
**The PR body check no longer loses the closing Agent notes section when the text quotes a `<!--` comment opener in inline code or a code block,** so a body that explains HTML comments is no longer refused for a receipt and words that already sit in the right place. `gstack-review-plan --pass` now says plainly that it counts the review passes already finished, prints a `PASS_COUNT:` line with the value to give after the next pass, and inside an open /ship run refuses a `--pass` that disagrees with the passes the run's review log holds, instead of quietly planning the read-only final review a round early.
+46 -2
View File
@@ -39,8 +39,52 @@ function classify(body: string): Line[] {
return out;
}
/** HTML comments render as nothing, so they never count as text; the Agent notes marker, itself a comment, is kept. */
const stripComments = (body: string) => body.replace(/<!--[\s\S]*?-->/g, m => (m === AGENT_NOTES_MARKER ? m : m.replace(/[^\n]/g, '')));
const INLINE_CODE = /(`+)(?!`).*?(?<!`)\1(?!`)/y;
/**
* HTML comments render as nothing, so they never count as text; the Agent notes marker, itself a comment, is kept. One scan
* tracks comments and code fences together: a `<!--` or `-->` inside a code fence or an inline code span renders as written, so
* it neither opens nor closes a comment (GSTA-881: a quoted `<!--` above the marker swallowed it, and the Agent notes section
* read as body text), and a fence or code span inside an open comment is comment text, so the comment ends at its first `-->`.
* As in CommonMark, a `<!--` that starts a line opens a comment block that runs to its `-->` or the end; one inside a line
* opens a comment only when a `-->` closes it before the paragraph ends, and otherwise is literal text.
*/
function stripComments(body: string): string {
const lines = body.split('\n');
const closesInParagraph = (from: number, at: number) => {
if (lines[from]!.indexOf('-->', at) >= 0) return true;
for (let j = from + 1; j < lines.length && lines[j]!.trim(); j++) if (lines[j]!.includes('-->')) return true;
return false;
};
let fence: string | null = null, comment = false;
return lines.map((line, n) => {
let i = 0, out = '';
if (comment) {
const close = line.indexOf('-->');
if (close < 0) return '';
comment = false;
i = close + 3;
} else if (fence !== null) {
if (closesFence(fence, line)) fence = null;
return line;
} else {
const open = FENCE_OPEN.exec(line);
if (open) { fence = open[1]!; return line; }
}
while (i < line.length) {
INLINE_CODE.lastIndex = i;
const code = line[i] === '`' ? INLINE_CODE.exec(line) : null;
if (code) { out += code[0]; i += code[0].length; continue; }
if (line.startsWith(AGENT_NOTES_MARKER, i)) { out += AGENT_NOTES_MARKER; i += AGENT_NOTES_MARKER.length; continue; }
if (!line.startsWith('<!--', i)) { const run = line[i] === '`' ? /`+/y : /[^`<]+|</y; run.lastIndex = i; const m = run.exec(line)![0]; out += m; i += m.length; continue; }
const close = line.indexOf('-->', i + 4);
if (close >= 0) { i = close + 3; continue; }
if (/^ {0,3}$/.test(line.slice(0, i)) || closesInParagraph(n, i + 4)) { comment = true; break; }
out += '<!--';
i += 4;
}
return out;
}).join('\n');
}
const blankRun = (lines: string[]) => { while (lines.length && !lines[0]!.trim()) lines.shift(); while (lines.length && !lines.at(-1)!.trim()) lines.pop(); return lines; };
/**
+12
View File
@@ -248,6 +248,18 @@ describe('bin/gstack-plain-title', () => {
expect([r.status, r.last]).toEqual([0, 'PLAIN_TITLE: ok']);
});
// Value: protects=a PR body that quotes a comment opener in code still finds its Agent notes section; fails_when=the receipt and the
// words inside Agent notes are refused as body text; why_new=GSTA-881
test('a comment opener in inline code or a code fence above the Agent notes marker does not hide it', () => {
const notes = '<!-- gstack:agent-notes -->\n<details><summary>Agent notes</summary>\n\n```gstack-ship-receipt\n{"pr": 1}\n```\nRefs: pregate receipts\n\n</details>\n';
const inline = 'The body check keeps its place when the text quotes `<!-- foo -->` or `<!--` in code.\nWhy: a quoted opener hid the closing section.\n\n## What changed\n\n- Code spans such as `<!-- foo` are skipped.\n\n';
const fenced = 'The body check keeps its place when an example quotes a comment opener.\nWhy: a fenced opener hid the closing section.\n\n## Example\n\n```html\n<!-- an unclosed opener\n```\n\n';
for (const body of [inline, fenced]) {
const r = run(dirs.policy, ['check', '--body-file', file('opener.md', body + notes)]);
expect([r.status, r.stdout.trim()]).toEqual([0, 'PLAIN_TITLE: ok']);
}
});
test('warn mode and commit subjects only warn', () => {
const warn = run(dirs.policy, ['check', '--branch', 'capy/gst-1814-autoplan-gate-order', '--body-file', file('b.md', '## Heading\n'), '--mode', 'warn']);
expect([warn.status, warn.last]).toEqual([0, 'PLAIN_TITLE: warned=2']);
+36
View File
@@ -63,6 +63,42 @@ describe('the Agent notes section ends the body', () => {
expect(kinds(withAgentNotes(OPENING, RECEIPT) + '\nA trailing note.\n')).toEqual(['receipt-placement:A trailing note.']);
expect(kinds(withAgentNotes(OPENING, RECEIPT) + '\n<a href="https://capy.ai/x"><img src="b"></a>\n')).toEqual([]);
});
// Value: protects=a comment opener quoted in code renders as text, so it never hides the Agent notes marker below it; fails_when=the
// receipt and listed words inside Agent notes read as body text; why_new=GSTA-881 (a body quoting `<!--` in backticks was refused)
test('a comment opener inside inline code or a code fence above the marker leaves the Agent notes section in place', () => {
const inline = withAgentNotes(OPENING + '\n## What changed\n\n- Code spans such as `<!-- foo` and ``<!--`` are skipped.\n', 'Lane notes.\n\n' + RECEIPT);
const fenced = withAgentNotes(OPENING + '\n## Example\n\n```html\n<!-- an unclosed opener\n```\n', 'Lane notes.\n\n' + RECEIPT);
const closed = withAgentNotes(`Readers see \`<!-- foo -->\` as written.\n\n${OPENING}`, RECEIPT);
for (const body of [inline, fenced]) expect(kinds(foldSections(body), ['lane', 'receipt'])).toEqual([]);
expect(kinds(closed)).toEqual([`visible-lines:4 lines, ${[...visibleOpening(closed).join('\n')].length} characters before the first fold`]);
expect(visibleOpening(closed)[0]).toBe('Readers see `<!-- foo -->` as written.');
expect(kinds('<!-- a note\nfor tools -->\n' + withAgentNotes(OPENING, RECEIPT))).toEqual([]);
});
// Value: protects=a code fence or code span inside a real HTML comment is comment text, so the comment still ends at its own first
// -->; fails_when=the comment runs on to a later --> (the marker's) and hides visible lines or the Agent notes section;
// why_new=review of GSTA-881's fix (specialist-batched#1, red-team#1)
test('a fence inside an HTML comment neither hides the Agent notes marker nor hides visible lines after the comment', () => {
expect(kinds(withAgentNotes(OPENING + '\n<!-- template hint: wrap logs in\n```\n-->\n', RECEIPT))).toEqual([]);
expect(kinds(withAgentNotes(OPENING + '\n<!-- a `-->` inside a comment ends it --> after\n', RECEIPT))).toEqual([`visible-lines:4 lines, ${[...visibleOpening(withAgentNotes(OPENING + '\n<!-- a `-->` inside a comment ends it --> after\n', RECEIPT)).join('\n')].length} characters before the first fold`]);
const hidden = 'One line of what changed.\n\n<!-- template hint\n```\n-->\nTwo.\nThree.\nFour.\nFive.\n```\n<!-- end -->\n' + withAgentNotes('', RECEIPT);
expect(visibleOpening(hidden).slice(0, 5)).toEqual(['One line of what changed.', 'Two.', 'Three.', 'Four.', 'Five.']);
expect(kinds(hidden)[0]).toStartWith('visible-lines:');
});
// Value: protects=a <!-- inside a line that nothing closes in its paragraph is literal text on GitHub, so it hides neither the lines
// after it nor the Agent notes marker; fails_when=everything after a quoted opener in prose drops out of the shape check and the
// squash message; why_new=round 2 review of GSTA-881's fix (red-team, CRITICAL)
test('an unclosed <!-- inside a line stays literal text; one starting a line opens a comment block', () => {
const prose = foldSections('The check now skips a quoted <!-- above the fold.\nline two\nline three\nline four\n\n## Details\n\nmore\n');
expect(visibleOpening(prose)).toEqual(['The check now skips a quoted <!-- above the fold.', 'line two', 'line three', 'line four']);
expect(kinds(prose, ['lane'])[0]).toStartWith('visible-lines:4 lines,');
const noted = withAgentNotes('The check now skips a quoted <!-- above the fold.\n\n## Details\n\nMore.\n', RECEIPT);
expect(kinds(foldSections(noted))).toEqual([]);
expect(visibleOpening(OPENING + '<!-- an open comment block\nhides this line\n')).toEqual(visibleOpening(OPENING));
expect(visibleOpening('One line with <!-- a note\nthat closes --> here.\n')).toEqual(['One line with ', ' here.']);
});
});
describe('folding', () => {
+46
View File
@@ -390,3 +390,49 @@ describe('gstack-review-plan honours edit rulings in the fix range (GST-3814)',
expect(q.stdout).not.toMatch(/^RULED_EDIT: /m);
}, 60_000);
});
// Value: protects=--pass counts the full passes this /ship run already finished, and a value the run's own review log contradicts is refused
// before it plans; fails_when=--pass 2 after one logged pass plans the read-only final review and spends round 2 (GSTA-891);
// seam=gstack-review-plan with an open run record and this branch's review log in the state root; no_claim=runs with no open record
describe('gstack-review-plan: --pass is the finished pass count', () => {
const code = Array.from({ length: 80 }, (_, i) => `export const v${i} = ${i};`).join('\n') + '\n';
const open = (r: { dir: string; state: string }, passes: number[]) => {
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
const started = new Date(Date.now() - 60_000).toISOString();
fs.writeFileSync(path.resolve(r.dir, git('rev-parse', '--git-path', 'gstack-ship-run')), JSON.stringify({ v: 1, run: 'ship-test', state: 'open', head: git('rev-parse', 'HEAD'), started_at: started, beat_at: started }));
const slug = spawnSync(path.join(import.meta.dir, '..', 'bin', 'gstack-slug'), ['--get', 'REPO_SLUG'], { cwd: r.dir, encoding: 'utf8', timeout: 10_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } }).stdout.trim();
const dir = path.join(r.state, 'projects', slug);
fs.mkdirSync(dir, { recursive: true });
const old = { skill: 'review', via: 'ship', pass: 1, timestamp: new Date(Date.now() - 3_600_000).toISOString() };
fs.writeFileSync(path.join(dir, 'feat-reviews.jsonl'), [old, ...passes.map(pass => ({ skill: 'review', via: 'ship', pass, commit_full: `head${pass}`, timestamp: new Date().toISOString() }))].map(row => JSON.stringify(row) + '\n').join(''));
};
test('the help says --pass is the passes already finished, not the next pass number', () => {
const help = spawnSync(BIN, ['--help'], { encoding: 'utf8', timeout: 10_000 }).stdout;
expect(help).toMatch(/--pass <n>\s+full review passes this \/ship run already finished/);
expect(help).toContain('not the number of the pass about to run');
});
test('the plan prints the finished count and the --pass to give after the next pass', () => {
const r = repo({ 'src/a.ts': code });
expect(run(r, []).stdout).toContain('PASS_COUNT: finished=0 next_pass=1 (after pass 1 finishes, plan again with --pass 1 --last full)');
expect(run(r, ['--pass', '1', '--last', 'full', '--fixed-blocking']).stdout).toContain('PASS_COUNT: finished=1 next_pass=2 (after pass 2 finishes, plan again with --pass 2 --last full)');
});
test('inside an open /ship run, --pass must match the passes its review log holds', () => {
const r = repo({ 'src/a.ts': code });
open(r, [1]);
const wrong = run(r, ['--pass', '2', '--last', 'full', '--fixed-blocking']);
expect(wrong.status).toBe(2);
expect(wrong.stderr).toContain('--pass 2 says 2 full passes finished, but the review log holds 1 for /ship run ship-test');
expect(wrong.stderr).toContain('rerun with --pass 1');
expect(wrong.stdout).toBe('');
const right = run(r, ['--pass', '1', '--last', 'full', '--fixed-blocking']);
expect(right.status).toBe(0);
expect(right.stdout).toMatch(/^NEXT: full /m);
expect(run(r, []).status).toBe(0);
open(r, [1, 2, 2]);
expect(run(r, ['--pass', '2', '--last', 'full']).status).toBe(0);
expect(run(r, ['--pass', '1', '--last', 'full', '--fixed-blocking']).stderr).toContain('the review log holds 2');
});
});