/ship's review works when the shipped checkout isn't the project's default checkout (GST-3145) (#4507)

/ship's review pass now lets its readers start in a checkout of an
unrelated repository, and refuses to start them in any other checkout
that holds the review's diff base, such as a sibling worktree or a
separate clone of the shipped repository.

Why: a project whose default checkout is another repository needed a
fresh machine for every /ship review, while a worktree or clone of the
same history could read the wrong diff with no error.

Nothing to do: the pass still stops before anything starts if the
shipped checkout can't be reached.

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-19 08:55:01 +00:00
1 parent 12bd33b648
commit c25390daa2
4 files changed
+90 -31

No files matched your search

+74 -22
View File
@@ -128,6 +128,14 @@ function writeManifestFile(m: Manifest): string {
}
/** A repository on a feature branch with enough runtime lines for a full plan. */
/** A checkout whose history shares no commit with repo()'s, standing in for a project's default checkout of another repository. */
function unrelated(env: NodeJS.ProcessEnv): string {
const dir = fs.realpathSync(tmp('rp-other-'));
const r = spawnSync('bash', ['-c', 'git init -q -b main && echo other > o.txt && git add -A && git commit -qm other'], { cwd: dir, env, encoding: 'utf8', timeout: 60_000 });
if (r.status !== 0) throw new Error(r.stderr);
return dir;
}
function repo(): { dir: string; env: NodeJS.ProcessEnv } {
const dir = tmp('rp-repo-');
const env = { ...process.env, PATH: BIN + path.delimiter + process.env.PATH, GSTACK_STATE_ROOT: path.join(dir, '.state'), GSTACK_SWEEP_ROOTS: dir, GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' };
@@ -1338,40 +1346,84 @@ describe('readers on a shared machine review the checkout the pass ships (GST-48
sh('for i in $(seq 1 20); do echo "export const w$i = $i;" >> src/a.ts; done && git commit -qam allow', wt);
return { dir, env, wt: fs.realpathSync(wt) };
}
// Value: protects=no reader is started where Capy will put it (the shared machine's start checkout) when /ship ships another checkout; fails_when=the program dispatches readers that start in the primary checkout while the pass ships a worktree (GBRA-218's outside voice ignored `cd <dir> &&` and reviewed the primary checkout, losing Step 11 outside coverage);
// why_new=GBRA-218 on gstack 1.92.25.0; Capy subagents take no working directory; seam=lib/capy-review-pass.js before any log start or create; no_claim=that Capy can start a reader in a chosen directory
test('a shared machine whose start checkout is not the worktree refuses before any start token or reader; a start directory outside any checkout dispatches', async () => {
// Value: protects=/ship can ship a checkout other than the one shared readers start in (HARN-105/HARN-107: a project whose default checkout is a repository of another history), each brief opening with the cd into the shipped checkout and each reply still proving its tree; fails_when=the program refuses readers because their start checkout differs from the shipped one, a brief does not open with the cd, a reply from the start checkout or with a foreign tree is merged, or readers are dispatched from a worktree or clone that holds the diff base (where a command without its cd reads the wrong diff with no error) or to a shipped checkout they cannot reach;
// why_new=GST-3145 on gstack 1.101.0.0 (the GST-482 start-checkout refusal contradicted the workspace step); seam=lib/capy-review-pass.js before any log start or create, and gstack-review-dispatch collect; no_claim=model compliance with the cd
test('readers that start in a repository of another history are dispatched with the cd into the shipped checkout first, a reply naming another tree is refused, and another worktree of the same repository or an unreachable checkout stops', async () => {
const { dir, env, wt } = worktree();
const other = unrelated(env);
const out = path.join(wt, '.state/run/p1');
const h = host(dir, env);
const h = host(other, env);
const res = await runPass(h, { base: 'main', out, pass: 'w0p1', cwd: wt, planFlags: ['--depth-floor', 'full'], logStart: ['review'] });
expect(res).toContain(`STOP: readers on the shared machine start in ${fs.realpathSync(dir)}, not in ${wt}`);
expect(res).not.toContain('REVIEW_LOG_START:');
expect(h.creates.length).toBe(0);
expect(res).not.toContain('STOP:');
expect(res).toContain('REVIEW_LOG_START: review');
expect(res).toContain('NEXT: judge (Phase 4)');
expect(h.creates.length).toBeGreaterThan(0);
const cdFirst = `First step, before anything else: run \`cd '${wt}' && `;
for (const c of h.creates) {
const verdict = !c.title.includes(' audit/');
expect([c.prompt.startsWith(workspaceStep(wt, verdict) + '\n\n'), workspaceStep(wt, verdict).startsWith(cdFirst), c.prompt.endsWith('\n\n' + workspaceParagraph(wt, undefined, verdict))], c.title).toEqual([true, true, true]);
expect(c.summary!.split('\n')[0], c.title).toBe(treeLine(wt).trim());
}
expect(bin(wt, env, ['verify', '--ledger', path.join(out, 'review-ledger.jsonl')]).stdout).not.toContain('wrong_tree');
const passCreates = h.creates.length;
const voices = await runPass(h, { base: 'main', out, pass: 'w0p1', cwd: wt, planFlags: ['--depth-floor', 'full'], stage: 'voices', models: { 'outside-voice': { model_id: 'openai/gpt-6.1-sol' } } });
expect(voices).toContain('STOP: readers on the shared machine start in ');
expect(h.creates.length).toBe(0);
const started = host(wt, env);
expect(await runPass(started, { base: 'main', out: path.join(wt, '.state/run/p2'), pass: 'w0p2', cwd: wt, planFlags: ['--depth-floor', 'full'] })).toContain('NEXT: judge (Phase 4)');
expect(started.creates.length).toBeGreaterThan(0);
expect(voices).not.toContain('STOP:');
expect(h.creates.length).toBeGreaterThan(passCreates);
for (const c of h.creates.slice(passCreates)) expect(c.prompt.startsWith(cdFirst), c.title).toBe(true);
const stayed = host(other, env, { reportFrom: () => other });
const wrong = await runPass(stayed, { base: 'main', out: path.join(wt, '.state/run/p2'), pass: 'w0p2', cwd: wt, planFlags: ['--depth-floor', 'full'] });
expect(wrong).toContain('COLLECT_WRONG_TREE: reader=');
expect(wrong).toContain(`reported="${treeLine(other).slice(15).trim()}"`);
expect(wrong).not.toContain('NEXT: judge');
expect(fs.existsSync(path.join(wt, '.state/run/p2/merged.jsonl')) ? fs.readFileSync(path.join(wt, '.state/run/p2/merged.jsonl'), 'utf8') : '').toBe('');
const forged = host(other, env, { reportFrom: () => '', output: t => `REVIEWED_TREE: ${'0'.repeat(40)} ${wt}\n${cleanReply(t)}` });
const moved = await runPass(forged, { base: 'main', out: path.join(wt, '.state/run/p3'), pass: 'w0p3', cwd: wt, planFlags: ['--depth-floor', 'full'] });
expect(moved).toMatch(/COLLECT_(WRONG_TREE|TREE_MOVED): reader=/);
expect(moved).not.toContain('NEXT: judge');
const outside = host(path.dirname(wt), env);
expect(await runPass(outside, { base: 'main', out: path.join(wt, '.state/run/p3'), pass: 'w0p3', cwd: wt, planFlags: ['--depth-floor', 'full'] })).toContain('NEXT: judge (Phase 4)');
const broken = tmp('rp-broken-');
fs.writeFileSync(path.join(broken, '.git'), 'garbage\n');
const unreadable = host(broken, env);
expect(await runPass(unreadable, { base: 'main', out: path.join(wt, '.state/run/p4'), pass: 'w0p4', cwd: wt, planFlags: ['--depth-floor', 'full'] })).toContain('STOP: cannot read the directory readers on the shared machine start in: fatal: invalid gitfile format');
expect(unreadable.creates.length).toBe(0);
const slow = host(wt, env, { pollsToFinish: 30 });
expect(await runPass(outside, { base: 'main', out: path.join(wt, '.state/run/p4'), pass: 'w0p4', cwd: wt, planFlags: ['--depth-floor', 'full'] })).toContain('NEXT: judge (Phase 4)');
const sibling = host(dir, env);
const same = await runPass(sibling, { base: 'main', out: path.join(wt, '.state/run/p7'), pass: 'w0p7', cwd: wt, planFlags: ['--depth-floor', 'full'], logStart: ['review'] });
expect(same).toContain(`STOP: readers on the shared machine start in ${fs.realpathSync(dir)}, not in ${wt}, the checkout this pass ships, and ${fs.realpathSync(dir)} also holds its diff base `);
expect(same).toContain(`Start /ship in the shipped checkout: run it from a thread whose working directory is ${wt}`);
expect(same).not.toContain('REVIEW_LOG_START:');
expect(sibling.creates.length).toBe(0);
const walled = host(other, env);
const bashW = walled.tools.capy.bash;
walled.tools.capy.bash = async (a: { command: string; description?: string }) => (a.description?.endsWith('reader reach check') ? { exit_code: 1, output: `none\n${other}\nbash: line 1: cd: ${wt}: Permission denied\n` } : bashW(a));
const unreachable = await runPass(walled, { base: 'main', out: path.join(wt, '.state/run/p5'), pass: 'w0p5', cwd: wt, planFlags: ['--depth-floor', 'full'], logStart: ['review'] });
expect(unreachable).toContain(`STOP: readers on the shared machine cannot reach ${wt}, the checkout this pass ships: bash: line 1: cd: ${wt}: Permission denied`);
expect(unreachable).not.toContain('REVIEW_LOG_START:');
expect(walled.creates.length).toBe(0);
const slow = host(other, env, { pollsToFinish: 30 });
let probes = 0;
const bash = slow.tools.capy.bash;
slow.tools.capy.bash = async (a) => { if (a.command.startsWith('if d=$(git rev-parse')) probes++; return bash(a); };
const input = { base: 'main', out: path.join(wt, '.state/run/p5'), pass: 'w0p5', cwd: wt, planFlags: ['--depth-floor', 'full'] };
slow.tools.capy.bash = async (a: { command: string; description?: string }) => { if (a.description?.endsWith('reader reach check')) probes++; return bash(a); };
const input = { base: 'main', out: path.join(wt, '.state/run/p6'), pass: 'w0p6', cwd: wt, planFlags: ['--depth-floor', 'full'] };
expect(await runPass(slow, input)).toContain('NEXT: poll');
expect(await runPass(slow, input)).toContain('NEXT: poll');
expect(probes).toBe(1);
expect(await runPass(host(wt, env), { ...input, logStart: [7] })).toStartWith('STOP: input.logStart must be a list');
}, 240_000);
// Value: protects=a separate clone of the shipped history, which holds the diff base, cannot be the start checkout of a pass; fails_when=readers are dispatched from such a clone (a reader that skips the cd diffs the clone with no error and still prints the shipped REVIEWED_TREE), or a start directory with a broken .git is refused although every brief cds out of it;
// why_new=GST-3145 second-model trail read on 6b90158 (the common-dir check let a clone through); seam=lib/capy-review-pass.js reader reach check; no_claim=a start checkout that fetched the base after the check
test('a separate clone that holds the diff base is refused before any start token or reader; a start directory with a broken .git dispatches', async () => {
const { dir, env, wt } = worktree();
const clone = path.join(tmp('rp-clone-'), 'clone');
expect(spawnSync('git', ['clone', '-q', dir, clone], { env, encoding: 'utf8', timeout: 60_000 }).status).toBe(0);
const cloned = host(clone, env);
const res = await runPass(cloned, { base: 'main', out: path.join(wt, '.state/run/c1'), pass: 'c1p1', cwd: wt, planFlags: ['--depth-floor', 'full'], logStart: ['review'] });
expect(res).toContain(`STOP: readers on the shared machine start in ${fs.realpathSync(clone)}, not in ${wt}, the checkout this pass ships, and ${fs.realpathSync(clone)} also holds its diff base `);
expect(res).not.toContain('REVIEW_LOG_START:');
expect(cloned.creates.length).toBe(0);
const broken = tmp('rp-broken-');
fs.writeFileSync(path.join(broken, '.git'), 'garbage\n');
const unreadable = host(broken, env);
expect(await runPass(unreadable, { base: 'main', out: path.join(wt, '.state/run/c2'), pass: 'c2p1', cwd: wt, planFlags: ['--depth-floor', 'full'] })).toContain('NEXT: judge (Phase 4)');
expect(unreadable.creates.length).toBeGreaterThan(0);
}, 240_000);
// Value: protects=a reader that never left the machine's default checkout cannot hand /ship a review of another tree; fails_when=collect merges a reply whose REVIEWED_TREE names the primary checkout while the pass ships a worktree, or a reply with no such line;
// why_new=GBRA-218: pass 1's specialist reviewed /workspace/gbrain while /ship shipped ~/.capy/work/wt-allow; seam=gstack-review-dispatch collect; no_claim=a reader that fingerprints the right checkout but reads another
test('a reader that reviews the primary checkout instead of the worktree is refused and nothing it said is merged', async () => {
@@ -1398,7 +1450,7 @@ describe('readers on a shared machine review the checkout the pass ships (GST-48
expect(res).not.toContain('NEXT: judge');
}, 240_000);
// Value: protects=/ship from a worktree that is the shared machine's start checkout works, its readers' briefs naming it (GST-776 refuses any other start checkout up front); fails_when=a brief does not name the shipped checkout, or a correct reply is refused;
// Value: protects=/ship from a worktree that is the shared machine's start checkout works, its readers' briefs naming it (readers that start in a repository of another history are covered by the GST-3145 tests above); fails_when=a brief does not name the shipped checkout, or a correct reply is refused;
// why_new=GBRA-218 (no brief named a directory); seam=lib/review-pass.ts renderStage and the Capy pass program; no_claim=model compliance with the paragraph
test('a reader that works in the checkout its brief names passes, and every brief names the worktree', async () => {
const { dir, env, wt } = worktree();