fix(ship-receipt): a docs audit after the review no longer forces another review (GST-1429) (#4034)

* fix(ship-receipt): a docs audit after the review no longer voids the review_exclude binding (GST-1429)

Step 14.5's docs audit runs after the review. When it edits, adds or removes a
file under review_exclude_paths, HEAD's selection digest moves and receipt
write refused the reviewed digest. write --docs-post <audit-id>-post.json now
binds the reviewed digest when it is HEAD's selection with the files under a
pattern that changed since the snapshot's HEAD reset to it, each named by the
snapshot with the content HEAD holds and excluded or kept only because code
names it, and every other file selected alike. Anything else still refuses.

The ship driver's Step 19 write omitted --review-exclude, so gbrain #8627
wrote recorded=none; it now passes it, and the refusal says when the flag was
left out.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review-exclude): keep the GST-1429 in-process receipt read off the real state root

The #8627-shape test called receiptReviewAtHead in-process with the runner's
GSTACK_STATE_ROOT, so its gate scan wrote gate-diff and slug-cache entries
under the real ~/.gstack and CI rejected free-suite shard 9
(FREE_SUBSHARD_REJECTED, run 42017628509). It now points GSTACK_STATE_ROOT at
the fixture like the docs-only gate-tagged test does.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes

The docs-audit exception reset every changed file under review_exclude_paths
to the post snapshot's HEAD, so a docs edit the review read while it was still
uncommitted was reverted and write refused a normal /ship run. --docs-pre
<Prepare snapshot> now narrows the reset to the files the audit changed, back
to their Prepare content. Snapshot hashes of working-tree bytes also compare
against HEAD's content as it checks out, so autocrlf or a clean filter no
longer reads as an edit after the audit.

Review-Finding: s11/outside-voice#1 reader=outside-voice
Review-Finding: s11/outside-voice#2 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore: changelog and TODOS

gstack: ok 1.96.0.0 for=ship
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-05 12:25:45 +00:00
1 parent b406820980
commit 467be16ab2
11 files changed
+220 -14

No files matched your search

+92
View File
@@ -493,6 +493,98 @@ describe('the receipt binds the selection the reviewers read', () => {
}
}, 240_000);
});
// Value: protects=a receipt write after /ship's Step 14.5 docs audit binds the digest the reviewers read when the only change to
// the selection since the review is files under review_exclude_paths that the audit's post snapshot names (GST-1429: gbrain
// #8627's audit added a key-files entry, a docs file code names, and write refused with RECEIPT_INVALID field=review_exclude,
// forcing a third review pass), a docs edit the review read uncommitted stays when --docs-pre names the Prepare snapshot and
// checkout line endings compare as committed (the #4034 review), while a selection change from anything else, an audit file the exclusion reads as code, an
// edit after the snapshot and a missing snapshot still refuse; fails_when=write accepts a changed selection without the
// snapshot, or the exception spreads to files the snapshot does not name or the exclusion does not hide or keep as docs;
// why_new=GST-1429; seam=gstack-docs-candidate snapshot, then gstack-ship-receipt write --review-exclude --docs-post;
// no_claim=what the docs audit itself may edit (ship/sections/documentation.md)
describe('a docs audit after the review (GST-1429)', () => {
const BRANCH = { 'lib/reader.js': "exports.p = 'docs/parity.md';\n", 'docs/parity.md': '# parity\n', 'docs/old.md': '# old\n' };
/** A branch reviewed at its head with `dirty` uncommitted (the plan's digest is what verify prints), then audited: the Prepare snapshot is saved, `audit` edits the tree, the post snapshot is saved, `after` edits more, and everything is committed. */
const audited = (audit: Record<string, string | null>, after: Record<string, string | null> = {}, branch: Record<string, string> = BRANCH, opts: { dirty?: Record<string, string>; autocrlf?: boolean } = {}) => {
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-audit-', baseFiles: { '.gstack/ship-policy.json': policyText(['docs/**', 'test/fixtures/goldens/**']), 'docs/key-files.md': '# key files\n', 'lib/index.js': "exports.k = 'docs/key-files.md';\n" } });
repos.push(repo);
commit(repo, branch);
if (opts.autocrlf) repo.git('config', 'core.autocrlf', 'true');
for (const [rel, text] of Object.entries(opts.dirty ?? {})) write(repo.work, rel, text);
const reviewed = JSON.parse(plan(repo, ['--json']).out).review_exclude.digest as string;
const snapshot = (out: string) => {
const snap = runBin(repo, 'gstack-docs-candidate', ['snapshot', '--out', out, '--audit-id', 'a1', '--mode', 'edit', '--base', repo.git('rev-parse', 'origin/main'), '--docs', 'docs']);
expect({ status: snap.status, err: snap.err }).toMatchObject({ status: 0 });
};
const pre = path.join(repo.root, 'a1.json');
snapshot(pre);
for (const [rel, text] of Object.entries(audit)) { if (text === null) fs.rmSync(path.join(repo.work, rel), { force: true }); else write(repo.work, rel, text); }
const post = path.join(repo.root, 'a1-post.json');
snapshot(post);
commit(repo, after, 'docs audit and release');
return { repo, reviewed, pre, post, body: path.join(repo.root, 'body.md') };
};
const writeWith = (a: ReturnType<typeof audited>, post: string | null = a.post, pre: string | null = null) =>
writeReceipt(a.repo, a.body, ['--review-exclude', a.reviewed, ...(post === null ? [] : ['--docs-post', post]), ...(pre === null ? [] : ['--docs-pre', pre]), ...targetedAtHead(a.repo)]);
const refusedWith = (w: { status: number | null; err: string }, a: ReturnType<typeof audited>, why: string) => {
expect({ status: w.status, written: fs.existsSync(a.body) }).toEqual({ status: EXIT.fail, written: false });
expect(w.err).toContain(`field=review_exclude expected=`);
expect(w.err).toContain(`recorded=${a.reviewed} `);
expect(w.err).toContain(why);
};
test('the #8627 shape: an audit edit to a docs file code names binds the reviewed digest with the post snapshot only', () => {
const a = audited({ 'docs/key-files.md': '# key files\n- lib/reader.js: the parity guard\n' }, {}, { 'lib/reader.js': BRANCH['lib/reader.js'], 'docs/parity.md': BRANCH['docs/parity.md'] });
const prior = process.env.GSTACK_STATE_ROOT;
process.env.GSTACK_STATE_ROOT = path.join(a.repo.root, 'receipt-state');
let head: ReturnType<typeof receiptReviewAtHead>['exclude'];
try { head = receiptReviewAtHead(a.repo.work, 'main', path.join(import.meta.dir, '..', 'bin'), a.repo.git('rev-parse', 'HEAD')).exclude; }
finally { if (prior === undefined) delete process.env.GSTACK_STATE_ROOT; else process.env.GSTACK_STATE_ROOT = prior; }
expect(head.state === 'active' ? head.kept.map(k => [k.path, k.reason]) : head.state).toEqual([['docs/key-files.md', 'named-by-code'], ['docs/parity.md', 'named-by-code']]);
expect(head.state === 'active' && head.record.digest).not.toBe(a.reviewed);
refusedWith(writeWith(a, null), a, '(write compares the argument, not the review ledger)');
const w = writeWith(a);
expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
expect(w.err + w.out).toContain(`REVIEW_EXCLUDE_DOCS_AUDIT: reviewed=${a.reviewed.slice(0, 12)} `);
expect(receiptIn(a.body).review_exclude!.digest).toBe(head.state === 'active' ? head.record.digest : 'none');
}, 240_000);
test('an audit that adds an excluded docs file and removes one the branch added binds', () => {
const a = audited({ 'docs/new.md': '# new\n', 'docs/old.md': null });
const w = writeWith(a);
expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
expect(w.err + w.out).toContain('files=docs/new.md,docs/old.md');
}, 240_000);
test('a selection change outside the audit, or an audit file the exclusion reads as code, still refuses', () => {
const code = audited({ 'docs/new.md': '# new\n' }, { 'lib/old.js': "exports.o = 'docs/old.md';\n" });
refusedWith(writeWith(code), code, 'is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset');
const outside = audited({ 'docs/new.md': '# new\n', 'lib/reader.js': "exports.p = 'docs/parity.md';\nexports.o = 'docs/old.md';\n" });
refusedWith(writeWith(outside), outside, 'is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset');
const tool = audited({ 'docs/tool.js': 'exports.t = 1;\n' });
refusedWith(writeWith(tool), tool, 'docs/tool.js is code at HEAD');
}, 240_000);
test('an edit after the snapshot, a file the snapshot does not name and a missing snapshot still refuse', () => {
const late = audited({ 'docs/new.md': '# new\n' }, { 'docs/new.md': '# new, edited after the snapshot\n' });
refusedWith(writeWith(late), late, 'docs/new.md at HEAD is not the content the snapshot recorded');
const unnamed = audited({}, { 'docs/new.md': '# new\n' });
refusedWith(writeWith(unnamed), unnamed, 'docs/new.md changed after the snapshot');
refusedWith(writeWith(unnamed, path.join(unnamed.repo.root, 'missing-post.json')), unnamed, 'missing-post.json: cannot be read');
}, 240_000);
test('a docs edit the review read uncommitted stays with the Prepare snapshot, and checkout line endings compare as committed', () => {
const dirty = audited({ 'docs/new.md': '# new\n' }, {}, BRANCH, { dirty: { 'docs/key-files.md': '# key files\n- lib/reader.js: the parity guard\n' } });
refusedWith(writeWith(dirty), dirty, 'is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset');
const kept = writeWith(dirty, dirty.post, dirty.pre);
expect({ status: kept.status, err: kept.status === EXIT.ok ? '' : kept.err }).toEqual({ status: EXIT.ok, err: '' });
expect(kept.err + kept.out).toContain('files=docs/new.md ');
const crlf = audited({ 'docs/new.md': '# new\r\n' }, {}, BRANCH, { autocrlf: true });
const w = writeWith(crlf, crlf.post, crlf.pre);
expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
}, 240_000);
});
});
describe('a branch cannot hide code under a base pattern', () => {
@@ -0,0 +1,4 @@
{
"bytes": 225,
"why": "GST-1429: pr-body.md names --docs-post and --docs-pre for the docs-audit exclusion exception"
}