Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

fix(review-exclude): write, ready and carry bind a digest whose policy gives the PR's files the same selection (GST-1446) (#4041)

Garry Tan4c400661d935
diff --git a/bin/gstack-ship-receipt b/bin/gstack-ship-receipt
index effde9269..4a4509f78 100755
--- a/bin/gstack-ship-receipt
+++ b/bin/gstack-ship-receipt
@@ -104,8 +104,10 @@ write flags: --pr --head --base --version --gated-tree --predecessor --gate <jso
unreadable input records full).
--review-exclude <digest|none> (the digest= on gstack-review-dispatch verify's REVIEW_EXCLUDE_RECORD: line, which the reviewers' briefs
name; none without that line): must equal the digest HEAD has under the base policy's review_exclude_paths, else
- RECEIPT_INVALID field=review_exclude and nothing is written; recorded as review_exclude. Carry and the queue compare that digest; both also
- bind when neither the recorded selection nor HEAD's holds a file the PR changed.
+ RECEIPT_INVALID field=review_exclude and nothing is written; recorded as review_exclude (HEAD's). Write, carry and the queue also bind
+ a digest from an earlier base policy when it gives the PR's files the same selection as HEAD's: the same applied patterns,
+ excluded files and kept files with their reasons (GST-1446; write rebuilds it from the policies the base held, prints
+ REVIEW_EXCLUDE_POLICY_MOVED:, and refuses when none does; an omitted --review-exclude is never rebuilt).
The check binds the digest to the base policy, not to a review: write does not read the review ledger, so the expected=
digest a refusal prints passes too. After a refusal, rerun the review and pass the digest its verify prints.
--docs-post <audit-id>-post.json (Step 14.5's post snapshot, the file finish takes): the reviewed --review-exclude digest also binds
@@ -271,7 +273,7 @@ function cmdWrite(rest: string[], json: boolean): number {
if (review.exclude.state === 'refused') { for (const l of review.exclude.lines) process.stderr.write(`${l}; nothing written\n`); return EXIT.refused; }
const excludeNow = review.exclude.state === 'active' ? review.exclude.record : null;
const excludeGiven = flag(rest, '--review-exclude') ?? 'none';
- const excludeBound = writeExcludeBinds(repoRoot, base, headSha ?? head, review, excludeGiven, flag(rest, '--docs-post'), flag(rest, '--docs-pre'));
+ const excludeBound = writeExcludeBinds(repoRoot, base, headSha ?? head, review, flag(rest, '--review-exclude'), flag(rest, '--docs-post'), flag(rest, '--docs-pre'));
if (!excludeBound.ok) {
process.stderr.write(`gstack-ship-receipt write: field=review_exclude expected=${excludeNow?.digest ?? 'none'} recorded=${excludeGiven} source=${excludeNow?.source ?? `origin/${base} (no review_exclude_paths)`}: the --review-exclude argument names another selection than ${base}'s review_exclude_paths gives ${head.slice(0, 12)} (write compares the argument, not the review ledger)${flag(rest, '--review-exclude') === undefined ? '; no --review-exclude was given, so write compared none' : ''}${excludeBound.why ? `; the docs-audit exception does not apply: ${excludeBound.why}` : ''}; fix: when only Step 14.5's docs audit changed files under review_exclude_paths after the review, pass its --docs-post <audit-id>-post.json and --docs-pre <its Prepare snapshot>; otherwise rerun /ship's review on ${head.slice(0, 12)} (gstack-review-dispatch pass --base ${base}), run gstack-review-dispatch verify --ledger <ledger> and write with the --review-exclude <d> its REVIEW_EXCLUDE_RECORD: line prints (none when it prints no such line); nothing written (RECEIPT_INVALID)\n`);
return EXIT.fail;
@@ -878,7 +880,7 @@ function cmdCarry(rest: string[], json: boolean): number {
const now = review.depth;
if (review.exclude.state === 'refused') return refused('RECEIPT_CARRY_REFUSED', `${review.exclude.lines.join('; ')}; run /ship on ${head.slice(0, 12)} once the base policy reads`);
const digest = review.exclude.state === 'active' ? review.exclude.record.digest : 'none';
- if (!carryExcludeBinds(review.exclude, receipt)) return refused('RECEIPT_CARRY_REFUSED', `review_exclude changed: recorded=${receipt.review_exclude?.digest ?? 'none'} now=${digest} source=${review.exclude.state === 'active' ? review.exclude.record.source : `${base} (no review_exclude_paths)`}; the receipt's digest is the --review-exclude argument write was given, and it names another selection than HEAD ${head.slice(0, 12)} has under the base policy and one of the two selections holds a file the PR changed (carry compares those, not the review ledger), so carry does not apply; run /ship on ${head.slice(0, 12)}`);
+ if (!carryExcludeBinds(review.exclude, receipt)) return refused('RECEIPT_CARRY_REFUSED', `review_exclude changed: recorded=${receipt.review_exclude?.digest ?? 'none'} now=${digest} source=${review.exclude.state === 'active' ? review.exclude.record.source : `${base} (no review_exclude_paths)`}; the receipt's digest is the --review-exclude argument write was given, and it names another selection than HEAD ${head.slice(0, 12)} has under the base policy and the two give the PR's files different selections (carry compares those, not the review ledger), so carry does not apply; run /ship on ${head.slice(0, 12)}`);
const riskOf = (d: { class: string; risk?: readonly string[] }) => `${d.class}:${[...(d.risk ?? [])].sort().join(',')}`;
if (recheck && riskOf(now) !== riskOf(receipt.review_depth)) return refused('RECEIPT_CARRY_REFUSED', `HEAD ${head.slice(0, 12)} is risk class ${riskOf(now)}, not the reviewed ${riskOf(receipt.review_depth)}, so a scoped re-check cannot stand in for review; run /ship on ${head.slice(0, 12)}`);
if (depthBelow(receipt.review_depth.depth, now.depth)) return refused('RECEIPT_CARRY_REFUSED', `HEAD ${head.slice(0, 12)} needs ${now.depth} review depth (${now.reasons.join(', ')}), above the receipt's ${receipt.review_depth.depth}; run /ship on ${head.slice(0, 12)}`);
diff --git a/changelog.d/capy-gst-1446-exclude-same-selection.md b/changelog.d/capy-gst-1446-exclude-same-selection.md
new file mode 100644
index 000000000..06db7f2d3
--- /dev/null
+++ b/changelog.d/capy-gst-1446-exclude-same-selection.md
@@ -0,0 +1 @@
+- **A policy edit that changes nothing about a PR's files no longer forces another review.** After main's `review_exclude_paths` gained patterns that match none of a PR's files, `gstack-ship-receipt write` refused the digest the reviewers read, and ready, carry, train build and land bound it only when both selections were empty (harness-evals #222: its reviewers read 7cf39a7e1150, which excludes 1,260 of its files, and write refused after #278 added six globs that match none of them). The shared check now binds when the recorded selection and HEAD's give the PR's files the same applied patterns, excluded files and kept files. Write gets only the digest, so it rebuilds the recorded selection from the policies the base held and prints `REVIEW_EXCLUDE_POLICY_MOVED:`. A selection that differs, a digest no base policy gives, an omitted `--review-exclude` and an unreadable base policy still refuse. (GST-1446)
diff --git a/docs/ship-policy.md b/docs/ship-policy.md
index b7f7bc172..076c95b90 100644
--- a/docs/ship-policy.md
+++ b/docs/ship-policy.md
@@ -1477,7 +1477,7 @@ checks the digest against the base policy, so a stale selection cannot be
recorded by accident, but it does not read the review ledger: a write given the
`expected=` digest passes without a review, and only the review run shows that
the reviewers read that selection.
-Carry and the queue make one exception (GST-1408, GST-1415, GST-1434): when the digests differ but neither the receipt's recorded selection (no `review_exclude`, or one whose list hash is the empty selection's and whose digest is built from it) nor HEAD's holds a file the PR changed, carry carries the receipt and records HEAD's digest and the queue (`ready`, train build, land) binds it, so a pattern the base gains, adds, removes or reverts does not void it; a selection that holds a PR file, excluded or kept, and an unreadable base policy still refuse.
+Write, carry and the queue make one exception (GST-1408, GST-1415, GST-1434, GST-1446): when the digests differ but the recorded selection and HEAD's give the PR's files the same selection, meaning the same applied patterns, the same excluded files and the same kept files with their reasons, write records HEAD's digest, carry carries the receipt and records HEAD's digest, and the queue (`ready`, train build, land) binds it. So a pattern the base gains, adds, removes or reverts that changes nothing about the PR's files does not void the review. No recorded selection (`none`) counts as the empty one. A receipt's record counts only when its digest is built from its list hash. Write gets only a digest, so it rebuilds the recorded selection: the digest binds when the `review_exclude_paths` the base held at some commit that changed the policy file, combined with HEAD's list hash, gives that digest. It prints `REVIEW_EXCLUDE_POLICY_MOVED:`. A digest no such policy gives, an omitted `--review-exclude`, a selection that differs over the PR's files and an unreadable base policy still refuse.
Write makes one exception for Step 14.5's docs audit, which runs after the review (GST-1429): with `--docs-post <audit-id>-post.json` it accepts the reviewed digest when that digest is HEAD's selection with every file under a pattern that changed since the snapshot's HEAD reset to it, each such file is uncommitted in the snapshot with the content HEAD holds, each is excluded or kept only because code names it, and every other file is excluded or kept alike on both sides. With `--docs-pre <Prepare snapshot>` only the files whose content changed between the audit's two snapshots reset, to their Prepare content, so uncommitted docs the reviewers read stay as they are; content compares as git stores it or as it checks out (autocrlf, filters). It prints `REVIEW_EXCLUDE_DOCS_AUDIT:` and records HEAD's digest. Any other change to the selection, an audit file the exclusion keeps for another reason, an edit after the snapshot and a missing or unreadable snapshot still refuse.
**Adopting it.** (1) Open a PR on the base that adds the patterns and
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 6cc26cb5e..bdeb468be 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -3502,10 +3502,13 @@ removing files under a pattern, pass that run's `--docs-post <audit-id>-post.jso
`--docs-pre` as well instead of rerunning the review; the refusal's `the docs-audit exception does not apply:` clause says why when it cannot
([ship-policy.md](ship-policy.md#review-exclude-paths), GST-1429).
-The queue's check binds a receipt whose digest differs (`recorded=none`, written before the base
-gained `review_exclude_paths`, or a digest from an older policy) when neither the receipt's recorded
-selection nor HEAD's holds a file the PR changed, the rule carry uses (GST-1434), so
-this line then means one of the two selections holds a file the PR changed.
+Write, carry and the queue bind a digest that differs (`recorded=none`, written before the base
+gained `review_exclude_paths`, or a digest from an older policy) when the recorded selection and
+HEAD's give the PR's files the same applied patterns, excluded files and kept files (GST-1434,
+GST-1446). Write rebuilds the recorded selection from the policies the base held and prints
+`REVIEW_EXCLUDE_POLICY_MOVED:` when it binds. So this line means the two selections differ over the
+PR's files, or write could not rebuild the digest from any policy the base held (a shallow clone
+of the base can cause that: fetch its history and rerun write).
<a id="review-diff-too-large"></a>
### `REVIEW_DIFF_TOO_LARGE`
diff --git a/lib/review-exclude.ts b/lib/review-exclude.ts
index 360a8c23e..c5be689c3 100644
--- a/lib/review-exclude.ts
+++ b/lib/review-exclude.ts
@@ -75,9 +75,9 @@ export interface ExcludeInput {
const sha256 = (s: string) => createHash('sha256').update(s).digest('hex');
/** The list_sha256 of a selection that holds no file: no pattern matched the range, so applied, excluded and kept are all empty. */
-const EMPTY_LIST_SHA256 = sha256(JSON.stringify({ applied: [], excluded: [], kept: [] }));
-/** A recorded selection holds no file only when its list hash is the empty list's and its digest is built from that hash. */
-export const recordSelectsNoFile = (r: Pick<ExcludeRecord, 'patterns_sha256' | 'list_sha256' | 'digest'>) => r.list_sha256 === EMPTY_LIST_SHA256 && r.digest === sha256(`${r.patterns_sha256}\n${EMPTY_LIST_SHA256}`);
+export const EMPTY_LIST_SHA256 = sha256(JSON.stringify({ applied: [], excluded: [], kept: [] }));
+/** A recorded selection's list hash (applied patterns, excluded files, kept files with their reasons) when its digest is built from it; null otherwise. */
+export const recordedList = (r: Partial<Pick<ExcludeRecord, 'patterns_sha256' | 'list_sha256' | 'digest'>>) => (r.list_sha256 && r.digest === sha256(`${r.patterns_sha256}\n${r.list_sha256}`) ? r.list_sha256 : null);
const shellQuote = (s: string) => `'${s.replace(/'/g, "'\\''")}'`;
const literal = (p: string) => `:(top,literal)${p}`;
const argBytes = (paths: Iterable<string>) => { let n = 0; for (const p of paths) n += Buffer.byteLength(shellQuote(literal(p))) + 1; return n; };
diff --git a/lib/ship-receipt-depth.ts b/lib/ship-receipt-depth.ts
index a6e70281f..5e86b6d23 100644
--- a/lib/ship-receipt-depth.ts
+++ b/lib/ship-receipt-depth.ts
@@ -24,8 +24,8 @@ import * as path from 'node:path';
import { baseContainsHead } from './default-base';
import type { ShipReceipt } from './headless-artifacts';
import { collectCommit } from './review-collect';
-import { recordSelectsNoFile, reviewExclude, type ActiveExclusion, type Exclusion } from './review-exclude';
-import { isUnavailable } from './ship-policy';
+import { EMPTY_LIST_SHA256, recordedList, reviewExclude, type ActiveExclusion, type ExcludeRecord, type Exclusion } from './review-exclude';
+import { SHIP_POLICY_PATH, isUnavailable } from './ship-policy';
import { loadPolicyAt } from './ship-policy-at';
import { classifyPath, depthOfCommitInput, gateScanNeeded, platformFits, scanNumbers, type Depth } from './review-depth';
import { AUTH_PATH_PREFIXES, AUTH_PATH_TOKENS, MONEY_PATH_TOKENS, matchRisk, type RiskClass } from './review-risk';
@@ -279,18 +279,43 @@ function headInputs(root: string, baseRef: string, head: string, r?: ShipReceipt
return { baseSha, c, scope: scopeOfRange(root, BIN_DIR, baseRev, head, merged), x: exclusionAt(root, baseRef, baseSha.ok ? baseSha.out : null, head, c, tagged, 'gstack-ship-queue') };
}
-/** No file the head changed matches any pattern the base policy declares, so each reviewer reads the full diff (GST-1408). */
-const selectsNoFile = (x: Exclusion) => x.state === 'none' || x.state === 'head-only' || (x.state === 'active' && x.record.unmatched.length === x.record.patterns.length);
+/** The selection's list hash over the PR's files; the empty list's when the base declares no pattern or none matches (GST-1408). */
+const listOf = (x: Exclusion) => (x.state === 'active' ? x.record.list_sha256 : EMPTY_LIST_SHA256);
+type RecordedExclude = Partial<Pick<ExcludeRecord, 'patterns_sha256' | 'list_sha256' | 'digest'>>;
/**
- * Carry's and the queue's exclusion check: the recorded digest against the one HEAD has under the current base policy, except
- * that a policy change alone does not void the receipt (GST-1408, GST-1415, GST-1434): when neither the receipt's selection
- * (none recorded, or an empty one) nor HEAD's holds a file the PR changed, each reviewer read the full diff and still would,
- * whatever the patterns. A policy that cannot be read never binds.
+ * Write's, carry's and the queue's exclusion check: the recorded digest against the one HEAD has under the current base policy,
+ * except that a policy change alone does not void the receipt (GST-1408, GST-1415, GST-1434, GST-1446): when the recorded
+ * selection (none recorded reads as the empty one) and HEAD's give the PR's files the same applied patterns, excluded files and
+ * kept files with their reasons, each reviewer read the diff HEAD's policy gives. A policy that cannot be read, or a record
+ * whose digest is not built from its list hash, never binds.
*/
-export function carryExcludeBinds(x: Exclusion, r: ShipReceipt): boolean {
+export function carryExcludeBinds(x: Exclusion, r: { review_exclude?: RecordedExclude }): boolean {
if (x.state === 'refused') return false;
const e = r.review_exclude;
- return (x.state === 'active' ? x.record.digest : 'none') === (e?.digest ?? 'none') || (selectsNoFile(x) && (!e || recordSelectsNoFile(e)));
+ return (x.state === 'active' ? x.record.digest : 'none') === (e?.digest ?? 'none') || listOf(x) === (e ? recordedList(e) : EMPTY_LIST_SHA256);
+}
+/** The base write reads its policy from: origin/<branch> when it resolves, else the local branch. */
+function writeBase(root: string, base: string): { ref: string; sha: string | null } {
+ const branch = base.replace(/^origin\//, '');
+ const baseSha = baseCommit(root, `origin/${branch}`);
+ return baseSha.ok ? { ref: `origin/${branch}`, sha: baseSha.out } : { ref: branch, sha: git(root, ['rev-parse', '--verify', '--quiet', `${branch}^{commit}`]).out || null };
+}
+/**
+ * The record a reviewed --review-exclude digest stands for, for carryExcludeBinds: none for `none`; with HEAD's list hash when
+ * the review_exclude_paths the base held at a commit that changed the policy file builds the digest from it (the reviewers read
+ * HEAD's selection under an earlier policy); otherwise the digest alone, which binds only an equal one.
+ */
+function reviewedRecord(root: string, base: string, x: Exclusion, given: string): RecordedExclude | undefined {
+ if (given === 'none') return undefined;
+ const { ref, sha } = writeBase(root, base);
+ const log = sha ? git(root, ['log', '--full-history', '--format=%H', sha, '--', SHIP_POLICY_PATH]) : { ok: false, out: '' };
+ for (const commit of log.ok ? log.out.split('\n').filter(Boolean) : []) {
+ const load = loadPolicyAt(root, commit, ref);
+ if (isUnavailable(load) || load.errors.length || !load.policy.review_exclude_paths.length) continue;
+ const record = { patterns_sha256: createHash('sha256').update(JSON.stringify(load.policy.review_exclude_paths)).digest('hex'), list_sha256: listOf(x), digest: given };
+ if (recordedList(record)) return record;
+ }
+ return { digest: given };
}
/** How an exclusion treats one path: excluded, the reason it is kept, or absent from the selection. */
const treatment = (x: ActiveExclusion, p: string) => (x.excluded.has(p) ? 'excluded' : x.kept.find(k => k.path === p)?.reason ?? 'absent');
@@ -305,9 +330,12 @@ const treatment = (x: ActiveExclusion, p: string) => (x.excluded.has(p) ? 'exclu
* it every such file is an audit file, reset to the snapshot's HEAD. Content compares as git stores it or as it checks out
* (autocrlf, filters). Anything else, an unreadable snapshot included, refuses with `why`.
*/
-export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, given: string, docsPost: string | undefined, docsPre?: string): { ok: true; line?: string } | { ok: false; why?: string } {
+export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, flagged: string | undefined, docsPost: string | undefined, docsPre?: string): { ok: true; line?: string } | { ok: false; why?: string } {
const x = review.exclude;
- if ((x.state === 'active' ? x.record.digest : 'none') === given) return { ok: true };
+ const given = flagged ?? 'none';
+ const now = x.state === 'active' ? x.record.digest : 'none';
+ if (now === given) return { ok: true };
+ if (flagged !== undefined && carryExcludeBinds(x, { review_exclude: reviewedRecord(root, base, x, given) })) return { ok: true, line: `REVIEW_EXCLUDE_POLICY_MOVED: reviewed=${short(given)} head=${short(now)} (the base policy changed since the review and gives the PR's files the same selection; the receipt records HEAD's)` };
if (docsPost === undefined || x.state !== 'active') return { ok: false };
const no = (why: string) => ({ ok: false as const, why: `--docs-post ${docsPost}: ${why}` });
const list = (v: unknown): v is string[] => Array.isArray(v) && v.every(p => typeof p === 'string');
@@ -365,11 +393,8 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
if (!c.ok) return no(`git could not build HEAD with ${auditFiles.join(',')} reset to before the audit`);
reset = c.out;
} finally { fs.rmSync(index, { force: true }); }
- const branch = base.replace(/^origin\//, '');
- const baseSha = baseCommit(root, `origin/${branch}`);
- const ref = baseSha.ok ? `origin/${branch}` : branch;
- const sha = baseSha.ok ? baseSha.out : (git(root, ['rev-parse', '--verify', '--quiet', `${branch}^{commit}`]).out || null);
- const before = exclusionAt(root, ref, sha, reset, collectCommit(root, sha ?? branch, reset), review.tagged, 'gstack-ship-receipt');
+ const { ref, sha } = writeBase(root, base);
+ const before = exclusionAt(root, ref, sha, reset, collectCommit(root, sha ?? ref, reset), review.tagged, 'gstack-ship-receipt');
if (before.state !== 'active') return no(`the selection with ${auditFiles.join(',')} reset to before the audit cannot be read`);
if (before.record.digest !== given) return no(`the reviewed digest ${short(given)} is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset to ${pre ? 'their --docs-pre content' : short(at)} (${short(before.record.digest)}), so more than the docs audit changed what the reviewers read`);
for (const p of auditFiles) for (const [side, s] of [['the review', before], ['HEAD', x]] as const) {
@@ -389,7 +414,7 @@ export function excludeMismatch(x: Exclusion, r: ShipReceipt, head: string, base
const recorded = r.review_exclude?.digest ?? 'none';
const source = x.state === 'active' ? x.record.source : r.review_exclude?.source ?? base;
const h = head.slice(0, 12);
- return `field=review_exclude expected=${expected} recorded=${recorded} source=${source}: the receipt records another selection than ${base}'s review_exclude_paths gives ${h}, and one of the two holds a file the PR changed; the receipt is unchanged; fix: rerun /ship's review on ${h} (gstack-review-dispatch pass --base ${base.replace(/^(refs\/remotes\/)?origin\//, '')}), then gstack-ship-receipt write --pr <n> --review-exclude <d> --body <body> with the digest gstack-review-dispatch verify --ledger <ledger> prints on REVIEW_EXCLUDE_RECORD: (write checks the digest against the base policy and does not read the review ledger, so only the rerun shows the reviewers read this selection)`;
+ return `field=review_exclude expected=${expected} recorded=${recorded} source=${source}: the receipt records another selection than ${base}'s review_exclude_paths gives ${h}, and the two give the PR's files different selections; the receipt is unchanged; fix: rerun /ship's review on ${h} (gstack-review-dispatch pass --base ${base.replace(/^(refs\/remotes\/)?origin\//, '')}), then gstack-ship-receipt write --pr <n> --review-exclude <d> --body <body> with the digest gstack-review-dispatch verify --ledger <ledger> prints on REVIEW_EXCLUDE_RECORD: (write checks the digest against the base policy and does not read the review ledger, so only the rerun shows the reviewers read this selection)`;
}
/** The receipt's recorded gate scan when it names this head; otherwise null (unavailable). */
const boundScan = (r: ShipReceipt, head: string): number | null => {
diff --git a/test/review-exclude.test.ts b/test/review-exclude.test.ts
index 80d5b4e53..c030ee2e2 100644
--- a/test/review-exclude.test.ts
+++ b/test/review-exclude.test.ts
@@ -304,7 +304,7 @@ describe('the receipt binds the selection the reviewers read', () => {
expect(carried.status).toBe(EXIT.ok);
expect(receiptIn(body).review_exclude!.digest).toBe(digest!);
- onBase(repo, { '.gstack/ship-policy.json': policyText(['receipts/**', 'results/**']) });
+ onBase(repo, { '.gstack/ship-policy.json': policyText(['receipts/**', 'lib/**']) });
const refused = runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
expect(refused.status).toBe(EXIT.refused);
expect(refused.err).toContain(`review_exclude changed: recorded=${digest}`);
@@ -418,11 +418,11 @@ describe('the receipt binds the selection the reviewers read', () => {
}
}, 240_000);
- test('a recorded digest that differs still refuses when the recorded or the current selection holds a PR file', () => {
+ test('a recorded digest that differs still refuses when the recorded and the current selection differ over the PR files', () => {
const cases: Array<{ name: string; files: Record<string, string>; after: string[] }> = [
{ name: 'recorded excludes a PR file', files: { 'receipts/a/result.json': '{"ok": true}\n' }, after: ['results/**'] },
{ name: 'current excludes a PR file', files: { 'results/a.json': '{"ok": true}\n' }, after: ['receipts/**', 'results/**'] },
- { name: 'both keep a PR file', files: { 'receipts/run.js': 'exports.run = 1;\n' }, after: ['receipts/**', 'results/**'] },
+ { name: 'recorded keeps a PR file', files: { 'receipts/run.js': 'exports.run = 1;\n' }, after: ['results/**'] },
];
for (const c of cases) {
const { repo, body } = shipped({ ...CODE, ...c.files }, ['receipts/**']);
@@ -517,6 +517,122 @@ describe('the receipt binds the selection the reviewers read', () => {
}, 240_000);
});
+ // Value: protects=a base policy edit that gives the PR's files the same selection (the same applied patterns, excluded files
+ // and kept files with their reasons) no longer voids the reviewed digest at write, ready or carry, while a selection that
+ // differs over the PR files, a digest no policy the base held gives, an absent digest and an unreadable base policy still
+ // refuse; fails_when=a caller compares digests, or asks only whether both selections are empty (GST-1446: harness-evals #222
+ // at 558ad26d5, reviewed 7cf39a7e1150 under #272's three globs, which exclude 1,260 of its files, refused at write with
+ // expected dde43b124877 after #278 added six globs matching none of them); why_new=GST-1446; seam=gstack-ship-receipt write
+ // --review-exclude and carry, bindShippedReceipt (ready, train build, land); no_claim=the --docs-post exception (GST-1429 below)
+ describe('a base policy edit that leaves the PR\'s selection alone (GST-1446)', () => {
+ const BRANCH = { 'lib/reader.js': 'exports.p = 1;\n', 'receipts/a/result.json': '{"ok": true}\n', 'receipts/run.js': 'exports.run = 1;\n' };
+ const policyOnBaseOnly = (repo: FixtureRepo, text: string) => {
+ repo.git('checkout', '-q', 'main');
+ commit(repo, { '.gstack/ship-policy.json': text }, 'base policy change');
+ repo.git('push', '-q', 'origin', 'main');
+ repo.git('checkout', '-q', 'feature');
+ repo.git('fetch', '-q', 'origin');
+ };
+ const reviewed = () => {
+ const repo = makeFixtureRepo({ prefix: 'gstack-exclude-same-', baseFiles: { '.gstack/ship-policy.json': policyText(['receipts/**']) } });
+ repos.push(repo);
+ commit(repo, BRANCH);
+ const planned = JSON.parse(plan(repo, ['--json']).out).review_exclude;
+ expect({ excluded: planned.excluded, kept: planned.kept_files }).toEqual({ excluded: 1, kept: [{ path: 'receipts/run.js', reason: 'code' }] });
+ const body = path.join(repo.root, 'body.md');
+ const w = writeReceipt(repo, body, ['--review-exclude', planned.digest, ...targetedAtHead(repo)]);
+ expect({ status: w.status, err: w.err }).toMatchObject({ status: EXIT.ok });
+ return { repo, body, digest: planned.digest as string };
+ };
+ const writeWith = (repo: FixtureRepo, extra: string[]) => writeReceipt(repo, path.join(repo.root, 'body-w.md'), [...extra, ...targetedAtHead(repo)]);
+ const bind = (repo: FixtureRepo, body: string) => bindShippedReceipt(repo.work, 'origin/main', fs.readFileSync(body, 'utf8'), undefined, [repo.git('rev-parse', 'HEAD')]);
+ const carry = (repo: FixtureRepo, body: string) => runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
+
+ test('the #222 shape: write, ready and carry bind the reviewed digest after main adds patterns that match no PR file', () => {
+ const { repo, body, digest } = reviewed();
+ policyOnBaseOnly(repo, policyText(['receipts/**', 'results/**', 'docs/benchmarks/*/results*/**/*.jsonl']));
+ const now = JSON.parse(plan(repo, ['--json']).out).review_exclude.digest;
+ expect(now).not.toBe(digest);
+ const w = writeWith(repo, ['--review-exclude', digest]);
+ expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
+ expect(w.err).toContain(`REVIEW_EXCLUDE_POLICY_MOVED: reviewed=${digest.slice(0, 12)} head=${now.slice(0, 12)}`);
+ expect(receiptIn(path.join(repo.root, 'body-w.md')).review_exclude!.digest).toBe(now);
+ const b = bind(repo, body);
+ expect({ ok: b.ok, message: b.ok ? '' : b.message }).toEqual({ ok: true, message: '' });
+ repo.git('merge', '-q', '--no-edit', 'origin/main');
+ const carried = carry(repo, body);
+ expect({ status: carried.status, err: carried.status === EXIT.ok ? '' : carried.err }).toEqual({ status: EXIT.ok, err: '' });
+ expect(receiptIn(body).review_exclude!.digest).toBe(now);
+ }, 240_000);
+
+ test('a policy edit that changes the selection over the PR files still refuses write, ready and carry', () => {
+ const changes: Array<{ name: string; after: string[] }> = [
+ { name: 'a new pattern keeps a PR file', after: ['receipts/**', 'lib/**'] },
+ { name: 'the matching pattern is dropped', after: ['results/**'] },
+ { name: 'the pattern narrows', after: ['receipts/a/**'] },
+ ];
+ for (const c of changes) {
+ const { repo, body, digest } = reviewed();
+ policyOnBaseOnly(repo, policyText(c.after));
+ const w = writeWith(repo, ['--review-exclude', digest]);
+ expect({ name: c.name, status: w.status }).toEqual({ name: c.name, status: EXIT.fail });
+ expect(w.err).toContain(`field=review_exclude expected=`);
+ expect(w.err).toContain(` recorded=${digest} `);
+ const b = bind(repo, body);
+ expect({ name: c.name, ok: b.ok, code: b.ok ? '' : b.code }).toEqual({ name: c.name, ok: false, code: 'RECEIPT_INVALID' });
+ repo.git('merge', '-q', '--no-edit', 'origin/main');
+ const refused = carry(repo, body);
+ expect({ name: c.name, status: refused.status }).toEqual({ name: c.name, status: EXIT.refused });
+ expect(refused.err).toContain(`review_exclude changed: recorded=${digest} `);
+ }
+ }, 240_000);
+
+ test('an absent digest, a digest no base policy gives and an unreadable base policy still refuse write', () => {
+ const { repo, digest } = reviewed();
+ policyOnBaseOnly(repo, policyText(['receipts/**', 'results/**']));
+ for (const extra of [[], ['--review-exclude', 'none'], ['--review-exclude', 'f'.repeat(64)]]) {
+ const w = writeWith(repo, extra);
+ expect({ extra, status: w.status }).toEqual({ extra, status: EXIT.fail });
+ expect(w.err).toContain('field=review_exclude expected=');
+ }
+ policyOnBaseOnly(repo, '{ "review_exclude_paths": "receipts/**" }\n');
+ const unreadable = writeWith(repo, ['--review-exclude', digest]);
+ expect(unreadable.status).toBe(EXIT.refused);
+ expect(unreadable.err).toContain('so its review_exclude_paths cannot be read');
+ }, 240_000);
+
+ test('two selections that keep the same PR file under different pattern lists bind at ready', () => {
+ const repo = makeFixtureRepo({ prefix: 'gstack-exclude-same-kept-', baseFiles: { '.gstack/ship-policy.json': policyText(['receipts/**']) } });
+ repos.push(repo);
+ commit(repo, { 'lib/reader.js': 'exports.p = 1;\n', 'receipts/run.js': 'exports.run = 1;\n' });
+ const digest = JSON.parse(plan(repo, ['--json']).out).review_exclude.digest;
+ const body = path.join(repo.root, 'body.md');
+ expect(writeReceipt(repo, body, ['--review-exclude', digest, ...targetedAtHead(repo)]).status).toBe(EXIT.ok);
+ policyOnBaseOnly(repo, policyText(['receipts/**', 'results/**']));
+ const b = bind(repo, body);
+ expect({ ok: b.ok, message: b.ok ? '' : b.message }).toEqual({ ok: true, message: '' });
+ }, 240_000);
+
+ test('write rebuilds a reviewed policy that a later merge hides from default path history', () => {
+ const { repo } = reviewed();
+ policyOnBaseOnly(repo, policyText(['receipts/**', 'results/**']));
+ const digest = JSON.parse(plan(repo, ['--json']).out).review_exclude.digest;
+ repo.git('checkout', '-q', '-b', 'side', 'main~1');
+ commit(repo, { 'notes/side.md': '# side\n' }, 'side work');
+ repo.git('checkout', '-q', 'main');
+ repo.git('merge', '-q', '--no-ff', '--no-commit', 'side');
+ repo.git('checkout', 'side', '--', '.gstack/ship-policy.json');
+ repo.git('commit', '-q', '-m', 'merge side, restoring the earlier policy');
+ repo.git('push', '-q', 'origin', 'main');
+ repo.git('checkout', '-q', 'feature');
+ repo.git('fetch', '-q', 'origin');
+ expect(repo.git('log', '--format=%s', 'origin/main', '--', '.gstack/ship-policy.json')).not.toContain('base policy change');
+ const w = writeWith(repo, ['--review-exclude', digest]);
+ expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
+ expect(w.err).toContain(`REVIEW_EXCLUDE_POLICY_MOVED: reviewed=${digest.slice(0, 12)} `);
+ }, 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,