/ship counts a clean base merge as reviewed (GST-3562) (#4754)

When you merge main into a reviewed branch and your own lines, file
modes and symlink targets come through byte-identical, /ship now treats
the head as reviewed and lets CI check it, instead of asking for another
reader.

Why: these routine merges cost a reader stop on almost every PR that sat
a day, and the reader only ever re-read lines that had not changed.

Part of the /ship simplification Garry approved (items G and H); nothing
for readers to do.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Review-Finding: p1/outside-voice#3 reader=outside-voice
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p1/targeted#1 reader=targeted
Review-Finding: p1/adversarial-native#1 reader=adversarial-native
Review-Finding: p1/adversarial-native#4 reader=adversarial-native
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-24 02:41:52 +00:00
1 parent e78a1bfe32
commit 6ef3861302
14 files changed
+423 -228

No files matched your search

+117 -7
View File
@@ -2,13 +2,15 @@
* GST-2975: /ship finish stopped with "behavior, tests or build inputs changed since review" after a base merge whose only
* effect on the branch's files was base-side: the shared-preamble hash id in regenerated skill files (#4383, 94 files), and
* main's new entry spliced into an expected-value list the branch also appended to (ghome#16). Both now compare with the
* base-side difference masked; the spliced list goes to the scoped reader, and a real change to the branch's own lines
* still stops.
* base-side difference masked; the spliced list goes to the scoped reader, moved base context next to unchanged own lines
* counts as reviewed (GST-3562 G), and a real change to the branch's own lines still stops.
*/
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { comparePath } from '../lib/ship-patch';
import { extractReceipt, placeReceipt } from '../lib/ship-receipt';
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
setDefaultTimeout(90_000);
@@ -59,15 +61,15 @@ describe('regenerated skill files whose only base-side change is the shared-prea
// Value: protects=#4383: a main merge that only moved the shared-preamble hash id in the branch's regenerated files is a
// base merge, not a behavior change; fails_when=finish stops with behavior=N for the id lines; seam=comparePath via finish;
// no_claim=a hash id outside the two generated forms
test('the id lines are masked: the paths route as base or context and finish never stops for a behavior change', () => {
test('the id lines are masked: both paths route as base and finish never stops for a behavior change', () => {
const { f, reviewed, reviewedBase, post } = preambleMerge();
const sides = sidesOf(f, reviewed, reviewedBase);
expect(comparePath(f.work, sides, SKILL)).toBe('same');
expect(comparePath(f.work, sides, PREAMBLE)).toBe('context');
const r = finish(f, reviewed, post, reviewedBase);
expect(lineOf(r.stdout, 'ROUTE')).toMatch(/ behavior=0 .* base=1 context=1$/);
expect(lineOf(r.stdout, 'ROUTE')).toMatch(/ behavior=0 .* base=2 context=0$/);
expect(r.stdout).not.toContain('behavior, tests or build inputs changed since review');
expect(r.stdout).toContain(`STOP: base context moved next to the reviewed hunks in ${PREAMBLE}`);
expect(r.stdout).not.toContain('STOP:');
});
// Value: protects=#4383's own files: a branch that edits the shared preamble changes every generated file by its id alone, and
@@ -120,9 +122,9 @@ describe('an expected-value list the base merge spliced (ghome#16)', () => {
// Value: protects=ghome#16: a resolved line that is main's line plus exactly the entry the branch added goes to the scoped
// reader of its test hunks, not to an owner grant; fails_when=gateEditedPaths sends it to behavior (the owner-grant stop) or
// it passes with no reader; seam=comparePath + finish route; no_claim=the scoped reader's verdict
test('the union is context: finish stops for the scoped reader, never for a behavior change', () => {
test('the union is spliced: finish stops for the scoped reader, never for a behavior change', () => {
const { f, reviewed, reviewedBase, post } = listMerge(methods([...BASE_METHODS, 'ghome.talk.target', 'ghome.brief']));
expect(comparePath(f.work, sidesOf(f, reviewed, reviewedBase), LIST)).toBe('context');
expect(comparePath(f.work, sidesOf(f, reviewed, reviewedBase), LIST)).toBe('spliced');
const r = finish(f, reviewed, post, reviewedBase);
expect(lineOf(r.stdout, 'ROUTE')).toMatch(/ behavior=0 .*tests=1 /);
expect(r.stdout).not.toContain('behavior, tests or build inputs changed since review');
@@ -149,3 +151,111 @@ describe('an expected-value list the base merge spliced (ghome#16)', () => {
}
});
});
const ROWS = 'src/rows.ts';
const RUN = 'bin/run.sh';
const LINK = 'src/link.ts';
const rows = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `export const r${i + 1} = ${i + 1};`).join('\n') + '\n';
const OWN = { 6: 'export const r6 = 600;' };
/**
* GST-3562 G: the branch edits rows.ts, a script it marks executable and a symlink it adds; the base edits the line next to
* the branch's hunk, so the merge conflicts and the resolution decides what the head holds. `resolve` runs on the merged
* working tree before the merge commit.
*/
function noLossMerge(resolve: (work: string) => void) {
const f = fx({ [ROWS]: rows(), [RUN]: '#!/bin/sh\necho base\n' }, { [ROWS]: rows(OWN), [RUN]: '#!/bin/sh\necho branch\n' });
fs.chmodSync(path.join(f.work, RUN), 0o755);
fs.symlinkSync('rows.ts', path.join(f.work, LINK));
f.commit('feat: executable script and link');
const reviewed = wtree(f);
const reviewedBase = mergeBase(f);
const reviewedHead = f.git('rev-parse', 'HEAD').stdout.trim();
const post = snapshot(f);
f.advanceBase({ [ROWS]: rows({ 5: 'export const r5 = 50;' }) });
f.git('fetch', '-q', 'origin');
f.git('merge', '-q', '--no-commit', '--no-edit', 'origin/main');
f.write({ [ROWS]: rows({ 5: 'export const r5 = 50;', ...OWN }) });
resolve(f.work);
f.commit('merge main');
const body = path.join(f.root, 'body.md');
fs.writeFileSync(body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: reviewedHead, base: 'main', queue_mode: 'stamp-at-merge' } as any));
const carry = () => f.run(path.join(BIN, 'gstack-ship-receipt'), ['carry', '--body', body, '--base', 'main']);
return { f, sides: sidesOf(f, reviewed, reviewedBase), finish: () => finish(f, reviewed, post, reviewedBase), carry, body };
}
describe('a base merge counts as reviewed only when the branch\'s own lines, modes and symlink targets are unchanged (GST-3562 G)', () => {
// Value: protects=no review is lost by G: a base merge whose resolution keeps the branch's own lines, file modes and symlink
// targets byte-identical counts as reviewed in finish and carry, and a mode flip, a symlink retarget or a resolution that
// edits the branch's own line inside the conflict never does; fails_when=any adversarial resolution routes as base or
// carries, or the identical one asks for a reader; seam=comparePath via finish and carry; no_claim=CI's verdict at the head
test('byte-identical own lines, modes and symlink targets route as base in finish and carry with no reader', () => {
const x = noLossMerge(() => {});
expect([ROWS, RUN, LINK].map(p => comparePath(x.f.work, x.sides, p))).toEqual(['context', 'same', 'same']);
const r = x.finish();
expect([r.status, lineOf(r.stdout, 'ROUTE')], r.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* base=1 context=0$/)]);
const c = x.carry();
expect(c.status, c.stderr).toBe(EXIT.ok);
expect(extractReceipt(fs.readFileSync(x.body, 'utf8')).receipt!.carry!.reason).toContain(`base context moved next to unchanged own lines (${ROWS}; CI at head checks it)`);
});
test('a mode flip, a symlink retarget and a resolution inside the branch\'s own line are changed: finish stops and carry refuses', () => {
const cases: [string, (work: string) => void][] = [
[RUN, work => fs.chmodSync(path.join(work, RUN), 0o644)],
[LINK, work => { fs.unlinkSync(path.join(work, LINK)); fs.symlinkSync('a.ts', path.join(work, LINK)); }],
[ROWS, work => fs.writeFileSync(path.join(work, ROWS), rows({ 5: 'export const r5 = 50;', 6: 'export const r6 = 6000;' }))],
];
for (const [p, resolve] of cases) {
const x = noLossMerge(resolve);
expect([p, comparePath(x.f.work, x.sides, p)]).toEqual([p, 'changed']);
const r = x.finish();
expect([p, r.status, r.stdout.includes('behavior, tests or build inputs changed since review')], r.stdout).toEqual([p, 3, true]);
const c = x.carry();
expect([p, c.status, c.stdout.trim().split('\n')[0]], c.stderr).toEqual([p, EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)']);
expect(c.stderr).toContain(p);
}
});
});
describe('a merge that chose its own order, a base mode flip, or bytes that are not UTF-8 never count as reviewed (GST-3562 G)', () => {
const P = 'src/tool.sh';
/** Four sides in one repository: A, the reviewed branch R on A, the base B on A, and the merge C of R and B with `resolved`. */
const sides = (base: string | Buffer, reviewed: string | Buffer, baseSide: string | Buffer, resolved: string | Buffer, baseExec = false) => {
const f = fx();
const put = (text: string | Buffer) => fs.writeFileSync(path.join(f.work, P), text);
fs.mkdirSync(path.join(f.work, 'src'), { recursive: true });
put(base); f.commit('A');
const A = f.git('rev-parse', 'HEAD').stdout.trim();
put(reviewed); f.commit('R');
const R = f.git('rev-parse', 'HEAD').stdout.trim();
f.git('checkout', '-q', '-b', 'side', A);
put(baseSide); if (baseExec) fs.chmodSync(path.join(f.work, P), 0o755); f.commit('B');
const B = f.git('rev-parse', 'HEAD').stdout.trim();
f.git('checkout', '-q', '-b', 'merged', R);
f.git('merge', '-q', '--no-commit', '--no-edit', B);
put(resolved); if (baseExec) fs.chmodSync(path.join(f.work, P), 0o755); f.commit('C');
return comparePath(f.work, { reviewedBase: A, reviewed: R, currentBase: B, current: f.git('rev-parse', 'HEAD').stdout.trim() }, P);
};
const at = (edit: Record<number, string[]>) => rows().trimEnd().split('\n').flatMap((l, i) => [edit[i + 1]?.[0] ?? l, ...(edit[i + 1]?.slice(1) ?? [])]).join('\n') + '\n';
const GUARD = 'export const guard = 1;';
const [X1, X2] = ['export const x1 = 1;', 'export const x2 = 2;'];
const R3 = 'export const r3 = 3;';
// Value: protects=no review is lost by G: an insertion whose place against lines the base inserted or replaced at the same
// spot was chosen by the merge, a base exec-bit flip on a file the branch edits, and a diff of bytes that are not UTF-8 all
// leave the reviewed state; fails_when=any compares as context (no reader) or the controls lose their verdicts;
// seam=comparePath; no_claim=the routes, which the cases above cover for spliced and changed
test('same-spot insertions are spliced in either order; a base exec-bit flip and non-UTF-8 bytes are changed', () => {
expect(sides(rows(), at({ 3: [R3, GUARD] }), at({ 3: [R3, X1, X2] }), at({ 3: [R3, X1, GUARD, X2] }))).toBe('spliced');
expect(sides(rows(), at({ 3: [R3, GUARD] }), at({ 3: [R3, X1, X2] }), at({ 3: [R3, GUARD, X1, X2] }))).toBe('spliced');
expect(sides(rows(), at({ 3: [R3, GUARD] }), at({ 3: ['export const r3 = 30;'] }), at({ 3: ['export const r3 = 30;', GUARD] }))).toBe('spliced');
expect(sides(rows(), at({ 3: [R3, GUARD] }), at({ 10: ['export const r10 = 100;'] }), at({ 3: [R3, GUARD], 10: ['export const r10 = 100;'] }))).toBe('same');
expect(sides(rows(), rows(OWN), rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', ...OWN }))).toBe('context');
expect(sides(rows(), rows(OWN), rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', ...OWN }), true)).toBe('changed');
const latin = (own: number, five = 'r5 = 5') => Buffer.concat([Buffer.from(rows({ 5: `export const ${five};` }).split('export const r6 = 6;')[0]!), Buffer.from('export const r6 = "caf'), Buffer.from([own]), Buffer.from('";\n'), Buffer.from(rows().split('export const r6 = 6;\n')[1]!)]);
const plain = rows({ 6: 'export const r6 = "cafe";' });
expect(sides(rows(), latin(0xe9), rows({ 5: 'export const r5 = 50;' }), latin(0xe9, 'r5 = 50'))).toBe('changed');
expect(sides(rows(), latin(0xe9), rows({ 5: 'export const r5 = 50;' }), latin(0xe8, 'r5 = 50'))).toBe('changed');
expect(sides(rows(), plain, rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', 6: 'export const r6 = "cafe";' }))).toBe('context');
});
});
+40 -13
View File
@@ -13,7 +13,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { comparePath } from '../lib/ship-patch';
import { bindReceipt, extractReceipt } from '../lib/ship-receipt';
import { bindReceipt, CARRY_NAMED_PATHS, extractReceipt, placeReceipt, planCarry } from '../lib/ship-receipt';
import { RECHECK_RANGE_DIFF_CAP } from '../crew/lib/ship-recheck';
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
@@ -155,7 +155,7 @@ describe('carry: a changed path plus context paths compose into one bounded re-c
expect(eligible(r.stderr)).toBeNull();
});
test('changed-only keeps J1 as it is; context-only keeps the scoped review', () => {
test('changed-only keeps J1 as it is; context-only carries with no reader (GST-3562 G)', () => {
const changed = reviewedBranch({ [SCORE]: 'var score := 1\n' }, { [SCORE]: 'var score := 2\n' });
changed.f.write({ [SCORE]: 'var score := 3\n' }); changed.f.commit('fix: score 3');
const c = changed.carry();
@@ -168,25 +168,22 @@ describe('carry: a changed path plus context paths compose into one bounded re-c
context.f.advanceBase({ [VESTING]: vesting(BASE_VESTING) });
mergeMain(context.f, { [VESTING]: vesting({ ...BASE_VESTING, ...BRANCH_VESTING }) });
const s = context.carry();
expect([s.status, s.stdout.trim().split('\n')[0]]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)']);
expect(s.status, s.stderr).toBe(EXIT.ok);
expect(s.stderr).not.toContain('RECHECK:');
expect(extractReceipt(fs.readFileSync(context.body, 'utf8')).receipt!.carry!.reason).toContain(`base context moved next to unchanged own lines (${VESTING}; CI at head checks it)`);
});
});
describe('finish: the founderstar#563 shape takes the scoped reader too', () => {
test('ROUTE sends nothing to behavior, and one clean scoped record lets finish go on', () => {
describe('finish: the founderstar#563 shape needs no reader (GST-3562 G)', () => {
test('ROUTE sends nothing to behavior or context: the moved base context next to unchanged own lines counts as reviewed', () => {
const x = founderstar();
const post = path.join(x.f.root, 'post.json');
expect(x.f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
const finish = (extra: string[] = []) => x.f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', x.reviewedTree, '--docs-post', post, '--lane', LANE, '--reviewed-base', x.reviewedBase, ...extra]);
const ask = finish();
expect([ask.status, lineOf(ask.stdout, 'ROUTE')], ask.stdout).toEqual([3, expect.stringMatching(/ behavior=0 .* context=[12]$/)]);
const packet = /reads (\S+\.md)[ ,]/.exec(ask.stdout)?.[1];
expect(fs.readFileSync(packet!, 'utf8')).toContain('moved by the base');
const tree = x.f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const ok = finish(['--context-reviewed', recordAt(x.f, 'ctx.json', { tree, paths: [GAME, VESTING], reviewer: READER, verdict: 'clean' })]);
expect(lineOf(ok.stdout, 'SCOPED_REVIEW'), ok.stdout).toStartWith(`SCOPED_REVIEW: clean by ${READER} (`);
expect(ok.stdout).not.toContain('STOP: behavior');
const ok = finish();
expect([ok.status, lineOf(ok.stdout, 'ROUTE')], ok.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* base=[12] context=0$/)]);
expect(ok.stdout).not.toContain('SCOPED_REVIEW');
expect(ok.stdout).not.toContain('STOP:');
});
});
@@ -231,3 +228,33 @@ describe('a receipt a scoped re-check carried never carries on or lands (GST-270
}
});
});
describe('a receipt that records only what binding needs (GST-3562 H)', () => {
// Value: protects=/ship's receipt no longer needs the docs, review-loop, issue or budget records: a write with none of them
// binds at its head, and a receipt from before H that carries them still binds; fails_when=write or bindReceipt starts
// requiring one of those records again, or rejects an older receipt that has them; seam=gstack-ship-receipt write +
// bindReceipt; no_claim=the queue's other ready checks
test('a slim receipt writes and binds, and an older receipt with every record still binds', () => {
const x = reviewedBranch({ [VESTING]: vesting() }, { [VESTING]: vesting(BRANCH_VESTING) });
const body = fs.readFileSync(x.body, 'utf8');
const slim = extractReceipt(body).receipt!;
expect(['review_loop', 'calls', 'spend_usd', 'docs_audit_read'].filter(k => k in slim)).toEqual([]);
expect(bindReceipt(body, '5', [x.from], { base: 'main' })).toMatchObject({ ok: true, head: x.from });
const older = placeReceipt('## Summary\n', { ...slim, review_loop: { passes: 2, blocking_found: 1, deferred: 1, fixed: 1, rounds: 2 }, calls: 14, spend_usd: 3.25, docs_audit_read: { paths: ['README.md'], reviewer: READER, packet_sha256: 'a'.repeat(64) } } as any);
expect(bindReceipt(older, '5', [x.from], { base: 'main' })).toMatchObject({ ok: true, head: x.from });
});
});
describe('the carry reason names at most CARRY_NAMED_PATHS moved-context paths (GST-3562 G)', () => {
// Value: protects=a PR that merges main often keeps its receipt line bounded: the reason names at most CARRY_NAMED_PATHS
// paths and counts the rest; fails_when=every path is named on every hop and the PR body grows past GitHub's limit;
// seam=planCarry; no_claim=none
test('25 context paths name 20 and count 5', () => {
const paths = Array.from({ length: 25 }, (_, i) => `src/f${String(i).padStart(2, '0')}.ts`);
const plan = planCarry({ from: 'a'.repeat(40), head: 'b'.repeat(40), changed: [], productPatchId: { from: 'p1', head: 'p2' }, testPatchId: { from: '', head: '' }, changedProduct: [], mergeCommits: 1, rangeDiff: '', baseContext: paths });
expect(plan.ok).toBe(true);
const reason = plan.ok ? plan.carry.reason : '';
expect(reason).toContain(`(${paths.slice(0, CARRY_NAMED_PATHS).join(', ')} (+5 more); CI at head checks it)`);
expect(reason).not.toContain(paths[CARRY_NAMED_PATHS]!);
});
});
+19 -19
View File
@@ -215,17 +215,16 @@ describe('carry after a stack parent squash-merges, receipt written against main
expect(receiptIn(s.body).head).toBe(s.child);
}, 120_000);
// Value: protects=a base change next to the child's reviewed hunks gets one fix-check reviewer, not a carry and not a full
// /ship; fails_when=the landed-parent comparison ignores base context or refuses it outright; seam=none; no_claim=-
test('a base change next to the child\'s reviewed hunks routes to RECEIPT_CARRY_SCOPED_REVIEW', () => {
// Value: protects=GST-3562 G: a base change next to the child's unchanged reviewed hunks carries with no reader and the
// reason names the file, not a full /ship; fails_when=the landed-parent comparison ignores base context (the reason
// says only "base merge") or refuses it; seam=none; no_claim=-
test('a base change next to the child\'s reviewed hunks carries and names the moved context', () => {
const repo = makeFixtureRepo({ baseFiles: { 'lib/config.js': CONFIG } }); repos.push(repo);
const { child, body } = stack(repo, undefined, { 'lib/config.js': configWith({ 'd = 4': 'd = 40' }) }, 'main');
const { body } = stack(repo, undefined, { 'lib/config.js': configWith({ 'd = 4': 'd = 40' }) }, 'main');
landOnMain(repo, { 'lib/util.js': SUB, 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
const out = carry(repo, body);
expect(out.status).toBe(EXIT.refused);
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)');
expect(out.err).toContain('lib/config.js');
expect(receiptIn(body).head).toBe(child);
expect(out.status, out.err).toBe(EXIT.ok);
expect(receiptIn(body).carry!.reason).toContain('base context moved next to unchanged own lines (lib/config.js; CI at head checks it)');
}, 90_000);
// Value: protects=the receipt never names a stack parent that does not exist; fails_when=a test-first commit with no
@@ -338,26 +337,27 @@ function landedFirst(files: Record<string, string>) {
}
describe('a stack parent the reviewed base already held is no landed parent (qm#3457, GST-3315)', () => {
// Value: protects=qm#3457: base context moved beside the child's own hunk takes one scoped review of that file, not a
// refusal naming the parent's files; fails_when=landedStackParent counts a parent the reviewed base already held and the
// carry measures from it; seam=gstack-ship-receipt carry; no_claim=the scoped review itself
test('#3457: context moved next to the child\'s hunk routes to a scoped review of that file alone', () => {
// Value: protects=qm#3457: base context moved beside the child's own hunk carries naming that file alone (GST-3562 G), not
// a refusal naming the parent's files; fails_when=landedStackParent counts a parent the reviewed base already held and the
// carry measures from it; seam=gstack-ship-receipt carry; no_claim=-
test('#3457: context moved next to the child\'s hunk carries naming that file alone', () => {
const { repo, reviewed, rangeBase, body } = landedFirst({ 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
expect(landedStackParent(repo.work, { rangeBase, reviewed, currentBase: repo.git('merge-base', 'origin/main', 'HEAD') }, ['.', ':(exclude,glob)test/**'])).toBeNull();
const out = carry(repo, body);
expect([out.status, out.out]).toEqual([EXIT.refused, expect.stringContaining('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)')]);
expect(out.err).toContain('lib/config.js');
expect(out.err).not.toContain('lib/util.js');
expect(receiptIn(body).head).toBe(reviewed);
expect(out.status, out.err).toBe(EXIT.ok);
const reason = receiptIn(body).carry!.reason;
expect(reason).toContain('base context moved next to unchanged own lines (lib/config.js; CI at head checks it)');
expect(reason).not.toContain('lib/util.js');
}, 90_000);
// Value: protects=the patch-id keeps three lines of context whatever the user's git config says; fails_when=diff.context=0
// drops the moved context from both hashes and the carry passes unread base edits; seam=patchId; no_claim=-
test('diff.context=0 in the user\'s git config still routes moved context to a scoped review', () => {
// drops the moved context from both hashes and the carry calls it a plain base merge; seam=patchId; no_claim=-
test('diff.context=0 in the user\'s git config still sees the moved context', () => {
const { repo, body } = landedFirst({ 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
repo.git('config', 'diff.context', '0');
const out = carry(repo, body);
expect([out.status, out.out]).toEqual([EXIT.refused, expect.stringContaining('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)')]);
expect(out.status, out.err).toBe(EXIT.ok);
expect(receiptIn(body).carry!.reason).toContain('base context moved next to unchanged own lines (lib/config.js; CI at head checks it)');
}, 90_000);
test('an unrelated main change carries', () => {
+158 -130
View File
@@ -301,35 +301,21 @@ describe('a restamp after a lost slot (GST-895, GBRA-218, gbrain #8134)', () =>
});
describe('adjacent base edits (GST-384, #3631, founderstar#441)', () => {
// Value: protects=a base edit next to the branch's unchanged hunk asks for a scoped review of only those hunks (finish
// context=N, carry RECEIPT_CARRY_SCOPED_REVIEW), and a clean scoped review lets it through; fails_when=it forces the
// full loop (RECEIPT_CARRY_PRODUCT_CHANGED, behavior=1) or passes silently with no review; seam=lib/ship-patch.ts;
// no_claim=the scoped reviewer's judgment
test('finish stops for a scoped review of the spliced JSON entry, then continues with a clean record', () => {
// Value: protects=GST-3562 G: a base edit next to the branch's unchanged hunk (the JSON entry where the branch changed one
// key and the base the next, an inserted guard() under a base-edited line) counts as reviewed, with CI on the merged head
// as the check; a hunk the merge spliced still stops for one scoped reader and a clean record lets it through;
// fails_when=the adjacent edit forces the full loop (behavior=1) or a reader, or a spliced hunk passes silently;
// seam=lib/ship-patch.ts via finish; no_claim=the scoped reviewer's judgment
test('finish routes an adjacent base edit as base, and stops for a scoped review of a spliced hunk', () => {
const f = fx({ 'data/flavor.json': FLAVOR('old', 'old') }, { 'data/flavor.json': FLAVOR('Bright and new', 'old') });
const reviewed = wtree(f);
const reviewedBase = mergeBase(f);
const post = snapshot(f);
f.advanceBase({ 'data/flavor.json': FLAVOR('old', 'pat-pat') });
mergeMain(f, { 'data/flavor.json': FLAVOR('Bright and new', 'pat-pat') });
const r = finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
expect(lineOf(r.stdout, 'ROUTE')).toMatch(/ behavior=0 .* context=1$/);
expect(r.status).toBe(3);
const packet = /STOP: base context moved next to the reviewed hunks in data\/flavor\.json: .* reads (\S+),/.exec(r.stdout)?.[1];
expect(packet).toBeDefined();
const text = fs.readFileSync(packet!, 'utf8');
expect(text).toContain('"pat": "pat-pat"');
expect(text).toContain('"headline": "Bright and new"');
const record = path.join(f.root, 'scoped.json');
fs.writeFileSync(record, JSON.stringify({ tree: wtree(f), paths: ['data/flavor.json'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'blocking' }));
expect(finish(f, reviewed, post, ['--reviewed-base', reviewedBase, '--context-reviewed', record]).stdout).toContain('STOP: --context-reviewed: the scoped review is "blocking"');
fs.writeFileSync(record, JSON.stringify({ tree: reviewed, paths: ['data/flavor.json'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
expect(finish(f, reviewed, post, ['--reviewed-base', reviewedBase, '--context-reviewed', record]).stdout).toContain(`STOP: --context-reviewed: the scoped review is for tree ${reviewed.slice(0, 12)}`);
fs.writeFileSync(record, JSON.stringify({ tree: wtree(f), paths: [], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
expect(finish(f, reviewed, post, ['--reviewed-base', reviewedBase, '--context-reviewed', record]).stdout).toContain('STOP: --context-reviewed: the scoped review does not cover data/flavor.json');
fs.writeFileSync(record, JSON.stringify({ tree: wtree(f), paths: ['data/flavor.json'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
const ok = finish(f, reviewed, post, ['--reviewed-base', reviewedBase, '--context-reviewed', record]);
expect([ok.status, ok.stdout.includes('NEXT: Step 16 stage 5')]).toEqual([0, true]);
const adjacent = finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
expect([adjacent.status, lineOf(adjacent.stdout, 'ROUTE')], adjacent.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* base=1 context=0$/)]);
expect(adjacent.stdout).toContain('NEXT: Step 16 stage 5');
const guard = (text: string) => text.replace('export const l5 = 5;\n', 'export const l5 = 5;\nguard();\n');
const inserted = fx({ 'src/m.ts': lines(9) }, { 'src/m.ts': guard(lines(9)) });
@@ -339,28 +325,70 @@ describe('adjacent base edits (GST-384, #3631, founderstar#441)', () => {
inserted.advanceBase({ 'src/m.ts': lines(9, { 4: 'export const l4 = 40;' }) });
mergeMain(inserted, { 'src/m.ts': guard(lines(9, { 4: 'export const l4 = 40;' })) });
const i = finish(inserted, reviewed2, post2, ['--reviewed-base', base2]);
expect([i.status, lineOf(i.stdout, 'ROUTE')]).toEqual([3, expect.stringMatching(/ behavior=0 .* context=1$/)]);
expect([i.status, lineOf(i.stdout, 'ROUTE')], i.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* base=1 context=0$/)]);
const list = (entries: string) => `export const METHODS = [${entries}];\n`;
const s = fx({ 'src/methods.ts': list('"prep"') }, { 'src/methods.ts': list('"prep", "brief"') });
const reviewed3 = wtree(s);
const base3 = mergeBase(s);
const post3 = snapshot(s);
s.advanceBase({ 'src/methods.ts': list('"prep", "talk"') });
mergeMain(s, { 'src/methods.ts': list('"prep", "talk", "brief"') });
const r = finish(s, reviewed3, post3, ['--reviewed-base', base3]);
expect([r.status, lineOf(r.stdout, 'ROUTE')], r.stdout).toEqual([3, expect.stringMatching(/ behavior=0 .* context=1$/)]);
const packet = /STOP: the base merge spliced lines into the reviewed hunks in src\/methods\.ts: .* reads (\S+),/.exec(r.stdout)?.[1];
expect(packet).toBeDefined();
expect(fs.readFileSync(packet!, 'utf8')).toContain('"prep", "talk", "brief"');
const record = path.join(s.root, 'scoped.json');
fs.writeFileSync(record, JSON.stringify({ tree: wtree(s), paths: ['src/methods.ts'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'blocking' }));
expect(finish(s, reviewed3, post3, ['--reviewed-base', base3, '--context-reviewed', record]).stdout).toContain('STOP: --context-reviewed: the scoped review is "blocking"');
fs.writeFileSync(record, JSON.stringify({ tree: reviewed3, paths: ['src/methods.ts'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
expect(finish(s, reviewed3, post3, ['--reviewed-base', base3, '--context-reviewed', record]).stdout).toContain(`STOP: --context-reviewed: the scoped review is for tree ${reviewed3.slice(0, 12)}`);
fs.writeFileSync(record, JSON.stringify({ tree: wtree(s), paths: [], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
expect(finish(s, reviewed3, post3, ['--reviewed-base', base3, '--context-reviewed', record]).stdout).toContain('STOP: --context-reviewed: the scoped review does not cover src/methods.ts');
fs.writeFileSync(record, JSON.stringify({ tree: wtree(s), paths: ['src/methods.ts'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
const ok = finish(s, reviewed3, post3, ['--reviewed-base', base3, '--context-reviewed', record]);
expect([ok.status, ok.stdout.includes('NEXT: Step 16 stage 5')], ok.stdout).toEqual([0, true]);
});
// Value: protects=same as above, for the receipt carry; and the same added line moved to another function is
// RECEIPT_CARRY_PRODUCT_CHANGED; fails_when=carry refuses the adjacent edit outright, carries it silently, or carries
// a moved hunk; seam=lib/ship-patch.ts; no_claim=gh pr edit (--body stands in)
test('carry asks for a scoped review of an adjacent base edit, carries with a clean one, and refuses a moved hunk', () => {
const repo = makeFixtureRepo({ prefix: 'ship-rereview-' }); repos.push(repo);
// Value: protects=GST-3562 G for the receipt carry: an adjacent base edit next to the branch's unchanged hunk carries with
// no reader (CI at head checks it); a hunk the merge spliced asks for one scoped review and carries with a clean one; the
// same added line moved to another function is RECEIPT_CARRY_PRODUCT_CHANGED; fails_when=carry refuses the adjacent edit,
// carries a spliced hunk silently, or carries a moved hunk; seam=lib/ship-patch.ts; no_claim=gh pr edit (--body stands in)
test('carry passes an adjacent base edit, asks for a scoped review of a spliced hunk, and refuses a moved hunk', () => {
const src = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `exports.v${i + 1} = ${i + 1};`).join('\n') + '\n';
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/rows.js', src()); repo.git('add', '-A'); repo.git('commit', '-qm', 'rows'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature'); repo.git('merge', '-q', '--no-edit', 'main');
write(repo.work, 'lib/rows.js', src({ 6: 'exports.v6 = 600;' })); repo.git('commit', '-qam', 'feat: v6');
const reviewed = repo.git('rev-parse', 'HEAD');
const body = path.join(repo.root, 'body.md');
fs.writeFileSync(body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: reviewed, base: 'main', queue_mode: 'stamp-at-merge' } as any));
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/rows.js', src({ 5: 'exports.v5 = "five";' })); repo.git('commit', '-qam', 'main: v5'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
spawnMerge(repo, { 'lib/rows.js': src({ 5: 'exports.v5 = "five";', 6: 'exports.v6 = 600;' }) });
const head = repo.git('rev-parse', 'HEAD');
const carry = (extra: string[] = []) => runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main', ...extra]);
const setup = (reviewedEdit: Record<number, string>, baseEdit: Record<number, string>, merged: Record<number, string>) => {
const repo = makeFixtureRepo({ prefix: 'ship-rereview-' }); repos.push(repo);
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/rows.js', src()); repo.git('add', '-A'); repo.git('commit', '-qm', 'rows'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature'); repo.git('merge', '-q', '--no-edit', 'main');
write(repo.work, 'lib/rows.js', src(reviewedEdit)); repo.git('commit', '-qam', 'feat: v6');
const reviewed = repo.git('rev-parse', 'HEAD');
const body = path.join(repo.root, 'body.md');
fs.writeFileSync(body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: reviewed, base: 'main', queue_mode: 'stamp-at-merge' } as any));
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/rows.js', src(baseEdit)); repo.git('commit', '-qam', 'main: edit'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
spawnMerge(repo, { 'lib/rows.js': src(merged) });
const carry = (extra: string[] = []) => runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main', ...extra]);
return { repo, reviewed, head: repo.git('rev-parse', 'HEAD'), body, carry };
};
const adjacent = setup({ 6: 'exports.v6 = 600;' }, { 5: 'exports.v5 = "five";' }, { 5: 'exports.v5 = "five";', 6: 'exports.v6 = 600;' });
const passed = adjacent.carry();
expect(passed.status, passed.err).toBe(EXIT.ok);
expect(extractReceipt(fs.readFileSync(adjacent.body, 'utf8')).receipt!.carry!.reason).toContain('base context moved next to unchanged own lines (lib/rows.js; CI at head checks it)');
const guard = (text: string, after: string) => text.replace('authorize();\n', '').replace(after + '\n', after + '\nauthorize();\n');
const rows = () => fs.readFileSync(path.join(adjacent.repo.work, 'lib/rows.js'), 'utf8');
write(adjacent.repo.work, 'lib/rows.js', guard(rows(), 'exports.v2 = 2;')); adjacent.repo.git('commit', '-qam', 'feat: guard v2');
fs.writeFileSync(adjacent.body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: adjacent.repo.git('rev-parse', 'HEAD'), base: 'main', queue_mode: 'stamp-at-merge' } as any));
write(adjacent.repo.work, 'lib/rows.js', guard(rows(), 'exports.v4 = 4;')); adjacent.repo.git('commit', '-qam', 'feat: move the guard');
const moved = adjacent.carry();
expect(moved.status).toBe(EXIT.refused);
expect(moved.out).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
expect(moved.err).toContain('lib/rows.js');
const { repo, reviewed, head, body, carry } = setup({ 6: 'exports.v6 = 6 + 60;' }, { 6: 'exports.v6 = 6 + 7;' }, { 6: 'exports.v6 = 6 + 7 + 60;' });
fs.writeFileSync(path.join(repo.work, '.git', 'gstack'), 'not a directory');
const blocked = carry();
expect([blocked.status, blocked.out.includes('RECEIPT_CARRY_REFUSED'), blocked.err.includes('cannot be written')]).toEqual([EXIT.refused, true, true]);
@@ -378,24 +406,15 @@ describe('adjacent base edits (GST-384, #3631, founderstar#441)', () => {
fs.writeFileSync(record, JSON.stringify({ head, paths: ['lib/rows.js'], reviewer: 'anthropic/claude-opus-5-5', verdict: 'clean' }));
const ok = carry(['--scoped-review', record]);
expect(ok.status).toBe(EXIT.ok);
expect(extractReceipt(fs.readFileSync(body, 'utf8')).receipt!.carry!.reason).toBe('base merge + base context moved (scoped review by anthropic/claude-opus-5-5: lib/rows.js)');
const guard = (text: string, after: string) => text.replace('authorize();\n', '').replace(after + '\n', after + '\nauthorize();\n');
const rows = () => fs.readFileSync(path.join(repo.work, 'lib/rows.js'), 'utf8');
write(repo.work, 'lib/rows.js', guard(rows(), 'exports.v2 = 2;')); repo.git('commit', '-qam', 'feat: guard v2');
fs.writeFileSync(body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: repo.git('rev-parse', 'HEAD'), base: 'main', queue_mode: 'stamp-at-merge' } as any));
write(repo.work, 'lib/rows.js', guard(rows(), 'exports.v4 = 4;')); repo.git('commit', '-qam', 'feat: move the guard');
const moved = carry();
expect(moved.status).toBe(EXIT.refused);
expect(moved.out).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
expect(moved.err).toContain('lib/rows.js');
expect(extractReceipt(fs.readFileSync(body, 'utf8')).receipt!.carry!.reason).toBe('base merge + spliced hunks (scoped review by anthropic/claude-opus-5-5: lib/rows.js)');
});
});
describe('carry with a context path and a gap elsewhere (GST-407 cycle 5)', () => {
// Value: protects=a scoped review of the context paths carries only when the rest of the product diff is unchanged;
// fails_when=a product path the walk skips (a stamp_files sibling whose glob a base edit demoted, here plugin/b.json,
// whose branch edit also landed on main) drops out of the product patch-id unnamed and the receipt carries under a
// scoped review that never saw it; seam=bin/gstack-ship-receipt cmdCarry; no_claim=none
// Value: protects=a context path carries only when the rest of the product diff is unchanged, and once it is, a large
// context path carries with no reader (GST-3562 G); fails_when=a product path the walk skips (a stamp_files sibling
// whose glob a base edit demoted, here plugin/b.json, whose branch edit also landed on main) drops out of the product
// patch-id unnamed and the receipt carries without it; seam=bin/gstack-ship-receipt cmdCarry; no_claim=none
test('carry refuses a product patch-id gap outside the context paths', () => {
const repo = makeFixtureRepo({ prefix: 'ship-rereview-gap-' }); repos.push(repo);
const src = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `exports.v${i + 1} = ${i + 1};`).join('\n') + '\n';
@@ -424,7 +443,8 @@ describe('carry with a context path and a gap elsewhere (GST-407 cycle 5)', () =
repo.git('checkout', '-q', 'feature');
spawnMerge(repo, { 'lib/rows.js': src({ 5: 'exports.v5 = "5";', 6: 'exports.v6 = 600;' }) + Array.from({ length: 220 }, (_, i) => `exports.w${i} = ${i};\n`).join('') });
const big = runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
expect([big.status, big.out.trim().split('\n')[0], big.err.includes('too large for the scoped review')]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)', true]);
expect(big.status, big.err).toBe(EXIT.ok);
expect(extractReceipt(fs.readFileSync(body, 'utf8')).receipt!.carry!.reason).toContain('base context moved next to unchanged own lines (lib/rows.js; CI at head checks it)');
});
});
@@ -605,16 +625,17 @@ describe('test-only and audit-requested edits after the docs audit (GST-391, gbr
});
});
describe('preflight carry route for an adjacent base edit (GST-442)', () => {
// Value: protects=/ship Step 1's carry check offers the scoped review when the base edited context next to a reviewed hunk,
// instead of treating the refusal as "run the full loop", and its dry run writes nothing; fails_when=preflight acts only on
// 'CARRY: would carry' or carry --dry-run writes the packet; seam=gstack-ship-receipt carry --dry-run; no_claim=the reviewer
describe('preflight carry route for a spliced hunk (GST-442)', () => {
// Value: protects=/ship Step 1's carry check offers the scoped review when the base merge spliced lines into a reviewed hunk
// (GST-3562 G: an adjacent base edit alone now carries), instead of treating the refusal as "run the full loop", and its
// dry run writes nothing; fails_when=preflight acts only on 'CARRY: would carry' or carry --dry-run writes the packet;
// seam=gstack-ship-receipt carry --dry-run; no_claim=the reviewer
test('preflight routes RECEIPT_CARRY_SCOPED_REVIEW to one scoped review, and the dry run writes no packet', () => {
const src = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `exports.v${i + 1} = ${i + 1};`).join('\n') + '\n';
const f = fx({ 'lib/rows.js': src() }, { 'lib/rows.js': src({ 6: 'exports.v6 = 600;' }) });
const f = fx({ 'lib/rows.js': src() }, { 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 60;' }) });
const reviewed = f.git('rev-parse', 'HEAD').stdout.trim();
f.advanceBase({ 'lib/rows.js': src({ 5: 'exports.v5 = "five";' }) });
mergeMain(f, { 'lib/rows.js': src({ 5: 'exports.v5 = "five";', 6: 'exports.v6 = 600;' }) });
f.advanceBase({ 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 7;' }) });
mergeMain(f, { 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 7 + 60;' }) });
const head = f.git('rev-parse', 'HEAD').stdout.trim();
const view = path.join(f.root, 'view.json');
fs.writeFileSync(view, JSON.stringify({ body: placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: reviewed, base: 'main', queue_mode: 'stamp-at-merge' } as any), headRefOid: head }));
@@ -650,10 +671,10 @@ describe('preflight carry route for an adjacent base edit (GST-442)', () => {
// round 2); fails_when=the dry run returns the scoped refusal before the receipt's other carry checks; seam=gh; no_claim=none
test('a dry run that the receipt would refuse anyway names that refusal, not the scoped route', () => {
const src = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `exports.v${i + 1} = ${i + 1};`).join('\n') + '\n';
const f = fx({ 'lib/rows.js': src() }, { 'lib/rows.js': src({ 6: 'exports.v6 = 600;' }) });
const f = fx({ 'lib/rows.js': src() }, { 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 60;' }) });
const reviewed = f.git('rev-parse', 'HEAD').stdout.trim();
f.advanceBase({ 'lib/rows.js': src({ 5: 'exports.v5 = "five";' }) });
mergeMain(f, { 'lib/rows.js': src({ 5: 'exports.v5 = "five";', 6: 'exports.v6 = 600;' }) });
f.advanceBase({ 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 7;' }) });
mergeMain(f, { 'lib/rows.js': src({ 6: 'exports.v6 = 6 + 7 + 60;' }) });
const head = f.git('rev-parse', 'HEAD').stdout.trim();
const view = path.join(f.root, 'view.json');
fs.writeFileSync(view, JSON.stringify({ body: placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: reviewed, base: 'main', queue_mode: 'stamp-at-merge', gstack_version: '1.0.0' } as any), headRefOid: head }));
@@ -947,17 +968,19 @@ describe('finish after a completed fix-check (GST-1130, GEVA-218)', () => {
});
});
// Value: protects=a base merge that puts lines already merged at base next to the branch's reviewed, unchanged hunk reaches
// the scoped read even when those base lines push a packet section past PACKET_SECTION_CAP (founderstar#515, #3923); only the
// branch's own lines count toward the cap; fails_when=finish forces the behavior route for a section that is over only
// because of base lines, or lets a section the branch's own lines push over reach the scoped read; seam=contextPacket's count
describe('base lines do not count toward the scoped-review cap (GST-1226, founderstar#515, #3923)', () => {
// Value: protects=GST-3562 G: a base merge that puts lines next to the branch's reviewed, unchanged hunk counts as reviewed
// however large either side is (founderstar#515, #3923 once needed a scoped read), with CI on the merged head as the check;
// the scoped-review cap now applies to hunks the merge spliced, where only the branch's own lines count;
// fails_when=finish asks for a reader or the behavior route for unchanged own lines, or lets a spliced section the branch's
// own lines push over the cap reach the scoped read; seam=comparePath + contextPacket's count
describe('base lines next to unchanged own lines need no reader; the cap binds spliced hunks (GST-1226, GST-3562 G)', () => {
const block = (name: string, n: number) => Array.from({ length: n }, (_, i) => `export const ${name}${i + 1} = ${i + 1};`);
const join = (rows: string[]) => rows.join('\n') + '\n';
const at = (n: number, after: number, add: string[]) => { const rows = lines(n).trimEnd().split('\n'); rows.splice(after, 0, ...add); return rows; };
const scoped = (r: { status: number | null; stdout: string }) => [r.status, lineOf(r.stdout, 'ROUTE').replace(/^.* behavior=/, 'behavior='), r.stdout.includes('STOP: base context moved next to the reviewed hunks in src/shots.ts'), r.stdout.includes('SCOPED_REVIEW: too large')];
const routed = (r: { status: number | null; stdout: string }) => [r.status, lineOf(r.stdout, 'ROUTE').replace(/^.* behavior=/, 'behavior='), r.stdout.includes('STOP: the base merge spliced lines into the reviewed hunks in src/shots.ts'), r.stdout.includes('SCOPED_REVIEW: too large')];
const reviewedAsBase = [0, 'behavior=0 docs=0 metadata=0 tests=0 base=1 context=0', false, false];
test('210 lines another PR merged at base next to the branch\'s 76 reviewed lines reach the scoped read', () => {
test('210 lines another PR merged at base next to the branch\'s 76 reviewed lines count as reviewed', () => {
const pr = block('pr', 76), other = block('other', 210);
const f = fx({ 'src/shots.ts': lines(20) }, { 'src/shots.ts': join(at(20, 10, pr)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
@@ -965,10 +988,10 @@ describe('base lines do not count toward the scoped-review cap (GST-1226, founde
const merged = at(20, 11, other); merged.splice(10, 0, ...pr);
mergeMain(f, { 'src/shots.ts': join(merged) });
expect(f.git('show', 'HEAD:src/shots.ts').stdout).toBe(join(merged));
expect(scoped(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual([3, 'behavior=0 docs=0 metadata=0 tests=0 base=0 context=1', true, false]);
expect(routed(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual(reviewedAsBase);
});
test('a changed trailing context line with the same +/- lines reaches the scoped read beside a 221-line base rewrite', () => {
test('a changed trailing context line with the same +/- lines beside a 221-line base rewrite counts as reviewed', () => {
const pr = block('pr', 76);
const f = fx({ 'src/shots.ts': lines(300) }, { 'src/shots.ts': join(at(300, 10, pr)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
@@ -978,39 +1001,43 @@ describe('base lines do not count toward the scoped-review cap (GST-1226, founde
const merged = lines(300, edits).trimEnd().split('\n'); merged.splice(10, 0, ...pr);
mergeMain(f, { 'src/shots.ts': join(merged) });
expect(f.git('show', 'HEAD:src/shots.ts').stdout).toBe(join(merged));
expect(scoped(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual([3, 'behavior=0 docs=0 metadata=0 tests=0 base=0 context=1', true, false]);
expect(routed(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual(reviewedAsBase);
});
test('a section the branch\'s own 230 lines push past the cap still takes the behavior route', () => {
const pr = block('pr', 230), other = block('other', 5);
const f = fx({ 'src/shots.ts': lines(20) }, { 'src/shots.ts': join(at(20, 10, pr)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
f.advanceBase({ 'src/shots.ts': join(at(20, 11, other)) });
const merged = at(20, 11, other); merged.splice(10, 0, ...pr);
mergeMain(f, { 'src/shots.ts': join(merged) });
const r = finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
expect(scoped(r)).toEqual([3, 'behavior=1 docs=0 metadata=0 tests=0 base=0 context=0', false, true]);
expect(r.stdout.includes('STOP: behavior, tests or build inputs changed since review (src/shots.ts)')).toBe(true);
test('the branch\'s own 230 unchanged lines and a base change past BASE_SECTION_CEILING count as reviewed', () => {
for (const [own, base] of [[230, 5], [76, 2100]]) {
const pr = block('pr', own), other = block('other', base);
const f = fx({ 'src/shots.ts': lines(20) }, { 'src/shots.ts': join(at(20, 10, pr)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
f.advanceBase({ 'src/shots.ts': join(at(20, 11, other)) });
const merged = at(20, 11, other); merged.splice(10, 0, ...pr);
mergeMain(f, { 'src/shots.ts': join(merged) });
expect(routed(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual(reviewedAsBase);
}
});
test('a base change past BASE_SECTION_CEILING counts in full again and takes the behavior route', () => {
const pr = block('pr', 76), other = block('other', 2100);
const f = fx({ 'src/shots.ts': lines(20) }, { 'src/shots.ts': join(at(20, 10, pr)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
f.advanceBase({ 'src/shots.ts': join(at(20, 11, other)) });
const merged = at(20, 11, other); merged.splice(10, 0, ...pr);
mergeMain(f, { 'src/shots.ts': join(merged) });
expect(scoped(finish(f, reviewed, post, ['--reviewed-base', reviewedBase]))).toEqual([3, 'behavior=1 docs=0 metadata=0 tests=0 base=0 context=0', false, true]);
test('20 spliced lines reach the scoped read; 120 spliced lines pass the cap and take the behavior route', () => {
const spliced = (n: number) => {
const edit = (v: (i: number) => string) => Object.fromEntries(Array.from({ length: n }, (_, i) => [i + 3, `export const l${i + 3} = ${v(i + 3)};`]));
const f = fx({ 'src/shots.ts': lines(n + 10) }, { 'src/shots.ts': lines(n + 10, edit(i => `${i} + 1000`)) });
const reviewed = wtree(f), reviewedBase = mergeBase(f), post = snapshot(f);
f.advanceBase({ 'src/shots.ts': lines(n + 10, edit(i => `${i} + 7`)) });
mergeMain(f, { 'src/shots.ts': lines(n + 10, edit(i => `${i} + 7 + 1000`)) });
return finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
};
expect(routed(spliced(20))).toEqual([3, 'behavior=0 docs=0 metadata=0 tests=0 base=0 context=1', true, false]);
const big = spliced(120);
expect(routed(big)).toEqual([3, 'behavior=1 docs=0 metadata=0 tests=0 base=0 context=0', false, true]);
expect(big.stdout).toContain('STOP: behavior, tests or build inputs changed since review (src/shots.ts)');
});
});
// Value: protects=a base merge that only changes context lines inside the branch's own unchanged hunks reaches the carry's
// scoped read even when those context lines and hunk headers push a section past PACKET_SECTION_CAP (founderstar#802: 22
// hunks, +66/-11, a section of about 205 lines); a branch whose own +/- lines pass the cap is still refused;
// fails_when=carry counts base context lines (in the branch's hunks or in the base's change) toward the cap and refuses
// with RECEIPT_CARRY_PRODUCT_CHANGED, or lets a section the branch's own lines push over reach the scoped read;
// seam=contextPacket's count; no_claim=the scoped reviewer's judgment
describe('only the branch\'s own +/- lines count toward the scoped-review cap in carry (GST-2229, founderstar#802)', () => {
// Value: protects=GST-3562 G for the carry: a base merge that only changes context lines inside or next to the branch's own
// unchanged hunks carries with no reader however large the sections are (founderstar#802 once needed a scoped read); the
// scoped-review cap binds spliced hunks, counting only the branch's own +/- lines; fails_when=carry refuses unchanged own
// lines, or lets a spliced section the branch's own lines push over the cap reach the scoped read;
// seam=bin/gstack-ship-receipt cmdCarry + contextPacket's count; no_claim=the scoped reviewer's judgment
describe('carry passes moved context next to unchanged own lines; the cap binds spliced hunks (GST-2229, GST-3562 G)', () => {
const row = (at: number, v: string | number = at) => `exports.v${at} = ${v};`;
/** `hunks` branch hunks 15 lines apart, alternating a 1-to-3 replacement and a 3-line insertion; the base edits the line two below each of the first `edits` spots, inside a branch hunk's context where there is one. */
const file = (hunks: number, edits: number, pr: boolean, base: boolean) => Array.from({ length: 15 * Math.max(hunks, edits) + 10 }, (_, i) => {
@@ -1020,46 +1047,47 @@ describe('only the branch\'s own +/- lines count toward the scoped-review cap in
const added = [0, 1, 2].map(j => `exports.pr${at}_${j} = ${j};`);
return k % 2 ? [line, ...added] : added;
}).flat().join('\n') + '\n';
const carry = (hunks: number, edits = hunks) => {
const carryOf = (main: string, branch: string, base: string, merged: string) => {
const repo = makeFixtureRepo({ prefix: 'ship-rereview-own-' }); repos.push(repo);
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/game.js', file(hunks, edits, false, false)); repo.git('add', '-A'); repo.git('commit', '-qm', 'game'); repo.git('push', '-q', 'origin', 'main');
write(repo.work, 'lib/game.js', main); repo.git('add', '-A'); repo.git('commit', '-qm', 'game'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature'); repo.git('merge', '-q', '--no-edit', 'main');
write(repo.work, 'lib/game.js', file(hunks, edits, true, false)); repo.git('commit', '-qam', 'feat: game');
write(repo.work, 'lib/game.js', branch); repo.git('commit', '-qam', 'feat: game');
const body = path.join(repo.root, 'body.md');
fs.writeFileSync(body, placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 9, head: repo.git('rev-parse', 'HEAD'), base: 'main', queue_mode: 'stamp-at-merge' } as any));
repo.git('checkout', '-q', 'main');
write(repo.work, 'lib/game.js', file(hunks, edits, false, true)); repo.git('commit', '-qam', 'main: context'); repo.git('push', '-q', 'origin', 'main');
write(repo.work, 'lib/game.js', base); repo.git('commit', '-qam', 'main: context'); repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
spawnMerge(repo, { 'lib/game.js': file(hunks, edits, true, true) });
expect(fs.readFileSync(path.join(repo.work, 'lib/game.js'), 'utf8')).toBe(file(hunks, edits, true, true));
return runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
spawnMerge(repo, { 'lib/game.js': merged });
expect(fs.readFileSync(path.join(repo.work, 'lib/game.js'), 'utf8')).toBe(merged);
return { r: runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']), body };
};
const carry = (hunks: number, edits = hunks) => carryOf(file(hunks, edits, false, false), file(hunks, edits, true, false), file(hunks, edits, false, true), file(hunks, edits, true, true));
const spliced = (n: number) => {
const text = (v: (i: number) => string) => Array.from({ length: n + 10 }, (_, i) => row(i + 1, i >= 2 && i < n + 2 ? v(i + 1) : i + 1)).join('\n') + '\n';
return carryOf(text(i => String(i)), text(i => `${i} + 1000`), text(i => `${i} + 7`), text(i => `${i} + 7 + 1000`)).r;
};
const section = (text: string, label: string) => (new RegExp(`^${label}\\n\`\`\`diff\\n([\\s\\S]*?)\\n\`\`\`$`, 'm').exec(text)?.[1] ?? '').split('\n');
const packet = (r: { status: number | null; out: string; err: string }) => {
expect([r.status, r.out.trim().split('\n')[0]], r.err).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)']);
const at = /reads (\S+), then/.exec(r.err)?.[1];
expect(at).toBeDefined();
return fs.readFileSync(at!, 'utf8');
};
const own = (rows: string[]) => rows.filter(l => /^[+-]/.test(l)).length;
test('22 unchanged branch hunks whose base context moved reach the scoped read with their sections over 200 lines', () => {
const text = packet(carry(22));
const current = section(text, 'Current hunks'), reviewed = section(text, 'Reviewed hunks');
expect([current.length > 200, own(current), reviewed.length > 200, own(reviewed)]).toEqual([true, 77, true, 77]);
expect(text).toContain('+exports.pr10_0 = 0;');
expect(text).toContain(' exports.v12 = "base 12";');
test('22 or 60 unchanged branch hunks and 30 scattered base edits carry with no reader', () => {
for (const [hunks, edits] of [[22, 22], [60, 60], [4, 30]]) {
const { r, body } = carry(hunks, edits);
expect(r.status, r.err).toBe(EXIT.ok);
expect(r.err).not.toContain('SCOPED_REVIEW');
expect(extractReceipt(fs.readFileSync(body, 'utf8')).receipt!.carry!.reason).toContain('base context moved next to unchanged own lines (lib/game.js; CI at head checks it)');
}
});
test('30 scattered base edits whose context lines pass 200 next to 4 unchanged branch hunks reach the scoped read', () => {
const base = section(packet(carry(4, 30)), "The base's change");
expect([base.length - own(base) > 200, own(base)]).toEqual([true, 60]);
});
test('60 branch hunks whose own +/- lines pass 200 are still too large for the scoped review', () => {
const r = carry(60);
expect([r.status, r.out.trim().split('\n')[0], r.err.includes('lib/game.js (too large for the scoped review: over 200 lines in a section)')]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)', true]);
test('20 spliced lines reach the scoped read with only their own lines counted; 120 are too large for it', () => {
const ask = spliced(20);
expect([ask.status, ask.out.trim().split('\n')[0]], ask.err).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)']);
const at = /reads (\S+), then/.exec(ask.err)?.[1];
expect(at).toBeDefined();
const text = fs.readFileSync(at!, 'utf8');
expect([own(section(text, 'Current hunks')), own(section(text, 'Reviewed hunks'))]).toEqual([40, 40]);
expect(text).toContain('+exports.v3 = 3 + 7 + 1000;');
const big = spliced(120);
expect([big.status, big.out.trim().split('\n')[0], big.err.includes('lib/game.js (too large for the scoped review: over 200 lines in a section)')]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)', true]);
});
});