diff --git a/changelog.d/review-readers-start-in-another-checkout.md b/changelog.d/review-readers-start-in-another-checkout.md new file mode 100644 index 000000000..0403e99fc --- /dev/null +++ b/changelog.d/review-readers-start-in-another-checkout.md @@ -0,0 +1 @@ +- **/ship's review pass works when the checkout you ship isn't the project's default checkout.** On Capy, review readers start in the thread's working directory, and /ship used to stop with `STOP: readers on the shared machine start in , not in ` whenever that was a different checkout, for example a project whose default checkout is another repository. Every reader's brief already opens by telling it to `cd` into the shipped checkout and report that checkout's tree on its first line, and a reply naming any other tree or path is still refused, so the pass now dispatches. It still stops before anything starts if readers can't reach the shipped checkout at all, or if they start in another worktree or clone of the same history, where a reader that skipped the `cd` would quietly review the wrong diff. (GST-3145) diff --git a/docs/review-policy.md b/docs/review-policy.md index e649064fe..d99cd931a 100644 --- a/docs/review-policy.md +++ b/docs/review-policy.md @@ -1188,11 +1188,14 @@ ones, and the arm lost blockers. `bin/gstack-review-dispatch` closes both ends: outside voice's tree failure is recorded `unavailable` only when its reply holds no finding. The line catches a reader that worked elsewhere by accident; it is not proof of reading, since diff text can predict it. A `printed:` label before the line (plain, bold or inside its backticks) is still read, and its tree and toplevel are still compared - exactly (GST-776). Capy cannot start a subagent in a chosen directory, so before a stage takes a start token or sends - its first reader, the Capy pass program compares the checkout with the one shared readers start in (the thread's - working directory) and stops when that is another checkout or cannot be read: run /ship in the thread's own checkout. - A start directory outside any checkout, such as a multi-repo workspace root, holds no tree to review by mistake and - dispatches. Step 11's voices take the `adversarial-review` start + exactly (GST-776). Capy cannot start a subagent in a chosen directory, so shared readers start in the thread's working + directory, which may be another checkout, such as a project whose default checkout is a different repository. That is + allowed: the workspace step's `cd` and the `REVIEWED_TREE` check above cover it (GST-3145). Before a stage takes a + start token or sends its first reader, the Capy pass program checks that the shipped checkout can be reached from + the directory readers start in, and stops, with nothing taken or dispatched, when it cannot or when readers start in + any other checkout that holds the pass's diff base commit, such as another worktree or a clone of the same history: + there a command run without its `cd` reads that checkout's diff with no error. A checkout without the diff base + fails on that command instead, so it dispatches. Step 11's voices take the `adversarial-review` start token by default, and a `logStart` list without it stops before anything runs. Decision 3.5's fix-check pass turns a `review` start into `review-fix-check`, so its row is never a pass (GST-1031). diff --git a/lib/capy-review-pass.js b/lib/capy-review-pass.js index 14be511f5..b7d049ff5 100644 --- a/lib/capy-review-pass.js +++ b/lib/capy-review-pass.js @@ -187,11 +187,14 @@ try { if (input.cwd && !m.readers.some((r) => active.includes(r.stage) && !['planned', 'rendered'].includes(r.state))) { const top = 'if d=$(git rev-parse --show-toplevel 2>&1); then cd "$d" && pwd -P; else case "$d" in *"not a git repository"*) echo NOT_A_CHECKOUT ;; *) echo "$d"; exit 1 ;; esac; fi'; const ship = await sh(top); - const start = await tools.capy.bash({ command: top, description: 'Ship review pass ' + input.pass + ' reader start checkout', timeout: 300 }); - const want = ship.out.trim(), got = (start.output || '').trim(); + const want = ship.out.trim(); if (ship.code !== 0 || want === 'NOT_A_CHECKOUT') return stop('cannot read the checkout input.cwd names (' + input.cwd + '): ' + want.slice(-300)); - if (start.exit_code !== 0) return stop('cannot read the directory readers on the shared machine start in: ' + got.slice(-300) + '; no start token was taken and no reader was dispatched'); - if (got !== 'NOT_A_CHECKOUT' && got !== want) return stop('readers on the shared machine start in ' + got + ', not in ' + want + ', the checkout this pass ships, and Capy cannot start a subagent in another directory; no start token was taken and no reader was dispatched. Run /ship in ' + got + " (the thread's working directory) on this branch, with a fresh --out"); + const bases = [...new Set([m.diff_base, ...m.readers.filter((r) => active.includes(r.stage)).map((r) => r.diff_base)].filter(Boolean))]; + const reach = await tools.capy.bash({ command: 'b=none; for c in ' + bases.map(q).join(' ') + '; do git cat-file -e "$c^{commit}" 2>/dev/null && b=$c; done; echo "$b" && echo "$( (' + top + ') 2>&1 | head -n1)" && cd ' + q(want) + ' 2>&1 && ' + top, description: 'Ship review pass ' + input.pass + ' reader reach check', timeout: 300 }); + const [heldBase, startTop, ...rest] = (reach.output || '').trim().split('\n'); + const got = rest.join('\n').trim(); + if (heldBase !== 'none' && startTop !== want) return stop('readers on the shared machine start in ' + startTop + ', not in ' + want + ', the checkout this pass ships, and ' + startTop + ' also holds its diff base ' + heldBase + '; a reader that ran a brief command without its cd would review that checkout\'s diff with no error, so no start token was taken and no reader was dispatched. Start /ship in the shipped checkout: run it from a thread whose working directory is ' + want + ', or one whose working directory holds no checkout of this history'); + if (reach.exit_code !== 0 || got !== want) return stop('readers on the shared machine cannot reach ' + want + ', the checkout this pass ships: ' + got.slice(-300) + '; no start token was taken and no reader was dispatched. Each brief tells its reader to cd there before anything else, so that path must be readable from the directory readers start in'); } const starts = input.stage !== 'voices' && m.next === 'fix-check' ? logStart.map((s) => (s.split(' ')[0] === 'review' ? 'review-fix-check' + s.slice(6) : s)) : logStart; const seen = {}; diff --git a/test/review-pass.test.ts b/test/review-pass.test.ts index 1e3eae6bb..579a5086a 100644 --- a/test/review-pass.test.ts +++ b/test/review-pass.test.ts @@ -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 &&` 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();