Fix ready notes, landing decisions, release PR descriptions and squash messages (GST-3343) (#4596)

Landing a ready PR now reads its gate decisions from the PR's ready
note, and the ready note, a reopened release PR and a stacked PR's
squash message now say the right thing.

Each of these stopped a landing or left a wrong public record until
someone fixed it by hand; the goal is unattended shipping that lands on
its own.

Nothing to do as a reader.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-21 08:52:11 +00:00
1 parent b281effa07
commit 7fe1900f8b
18 files changed
+304 -42

No files matched your search

+17
View File
@@ -416,6 +416,23 @@ describe('bug-fix exemption wording and the plan finish recorded (GSTA-649, GSTA
for (const r of ['bug fix with failing-first tests', 'Bugfix', 'bug-fix: retry backoff', 'bug fixes (R65)']) expect(exemptReason(r)).toBe('bug fix');
expect(exemptReason('bugfixing everything')).toBeNull();
});
// Value: protects=the READY note, which rides a public notes ref, never carries finish's raw --plan text: an approved line keeps only
// the opaque record id, an exempt line only its listed reason; fails_when=a local run path, a row id or a note in parentheses
// reaches the note's plan record; why_new=#4529 final review (GST-1955 family); seam=readyPlan's finish fallback, landPlan
test('the plan record finish supplies is redacted before it reaches the READY note (#4529)', () => {
const f = fixture({ y: [{ ask: 'R41 A1: cut a skill' }] });
const env = { ...f.env, GSTACK_PLAN_RECORD: 'require' };
const rowId = f.ids['R41 A1: cut a skill']!;
const approved = readyPlan({ cwd: f.cwd, env, body: 'Fixes a thing.', changed: ['lib/x.ts'], finishLine: `Plan: approved: ${rowId}` });
expect(approved.record).toMatchObject({ line: `Plan: approved (record ${planRecordId(rowId)})`, ref: planRecordId(rowId), state: 'approved', from: 'finish' });
expect(JSON.stringify(approved.record)).not.toContain(rowId);
expect(landPlan({ env, record: approved.record, body: 'Fixes a thing.' }).failure).toBeUndefined();
const exempt = readyPlan({ cwd: f.cwd, env, body: 'Fixes a thing.', changed: ['lib/x.ts'], finishLine: 'Plan: exempt: bug fix (see /home/user/.capy/work/ship-4529/run)' });
expect(exempt.record).toMatchObject({ line: 'Plan: exempt: bug fix', reason: 'bug fix', from: 'finish' });
expect(JSON.stringify(exempt.record)).not.toContain('/home/user');
const own = readyPlan({ cwd: f.cwd, env, body: `Plan: approved: ${rowId}`, changed: ['lib/x.ts'] });
expect(own.record).toMatchObject({ line: `Plan: approved: ${rowId}`, row_id: rowId });
});
test('ready reads the Plan line finish resolved when the body has none, and land accepts it', () => {
const f = fixture();
const env = { ...f.env, GSTACK_PLAN_RECORD: 'require' };
+35
View File
@@ -204,6 +204,41 @@ describe('gstack-release-stamp open', () => {
expect(repo.git('branch', '--list', 'release/*')).toBe('');
});
// Value: protects=a reopen that force-pushes a new stamp also rewrites the open release PR's body, so its change count, notes, base and
// land pin match the pushed head; fails_when=the open PR keeps the old body (GSTA-677 on #4573); seam=openRelease with a gh stub
test('reopening at a moved base rewrites the open release PR\'s body to the new stamp', () => {
const repo = landed();
const calls: string[][] = [];
const r = openRelease({ repoRoot: repo.work, base: 'main', gh: (args) => { calls.push(args); return { ok: true, out: 'https://github.com/o/r/pull/44\n', err: '' }; } });
expect(r.ok).toBe(true);
if (!r.ok) return;
expect(calls.map(a => a.slice(0, 3))).toEqual([['pr', 'list', '--head'], ['pr', 'edit', 'https://github.com/o/r/pull/44']]);
const body = calls[1]![calls[1]!.indexOf('--body') + 1]!;
expect(body).toContain(`--pin ${r.head}`);
expect(sectionText(body, 'Release notes')).toBe('- a change\n- b feature');
const refused = openRelease({ repoRoot: repo.work, base: 'main', now: new Date('2030-01-02T00:00:00Z'), gh: (args) => (args[1] === 'edit' ? { ok: false, out: '', err: 'HTTP 502' } : { ok: true, out: 'https://github.com/o/r/pull/44\n', err: '' }) });
expect(refused).toMatchObject({ ok: false, code: 'RELEASE_STAMP_INVALID' });
});
test('on Capy, a reopen hands the new body to the host tool without gh pr edit', () => {
const repo = landed();
const state = fs.mkdtempSync(path.join(repo.work, '..', 'state-'));
const calls: string[][] = [];
const r = openRelease({ repoRoot: repo.work, base: 'main', env: { GSTACK_CAPY: '1', GSTACK_STATE_ROOT: state }, gh: (args) => {
calls.push(args);
if (args[0] === 'repo') return { ok: true, out: JSON.stringify({ nameWithOwner: 'o/r', url: 'https://github.com/o/r' }), err: '' };
return { ok: true, out: 'https://github.com/o/r/pull/44\n', err: '' };
} });
expect(r.ok).toBe(true);
if (!r.ok) return;
expect(calls.map(a => a.slice(0, 2).join(' '))).toEqual(['pr list', 'repo view']);
const handed = r.lines.find(l => l.startsWith('HOST_PUBLISH: '))!;
expect(handed).toStartWith('HOST_PUBLISH: pr-body 44 repo=o/r');
const body = fs.readFileSync(/ body-file=(\S+)/.exec(handed)![1]!, 'utf8');
expect(body).toContain(`--pin ${r.head}`);
expect(r.lines).toContain('RELEASE_PR: #44 https://github.com/o/r/pull/44');
});
test('--dry-run creates nothing; an empty base is refused', () => {
const repo = landed();
const dry = openRelease({ repoRoot: repo.work, base: 'main', dryRun: true, gh: () => { throw new Error('no gh in a dry run'); } });
+59
View File
@@ -1329,6 +1329,65 @@ describe('land --pin and verify --pin accept owner gate dispositions (GST-2491)'
expect(gateLines(landed.out)[1]).toContain(`accepted=${id}`);
}, 180_000);
// Value: protects=a disposition recorded on the /ship machine reaches a lander on another machine through the READY note, still
// only by the lander's explicit acceptance, and a note row edited after ready wrote it counts for nothing; fails_when=land on a
// machine without the store refuses QUEUE_GATE_DISPOSITION (#4581 needed GSTACK_APPROVALS_DIR pointed at a hand copy), lands an
// unaccepted disposition, or trusts an edited note row; seam=ready's note and pinAcceptance; no_claim=a security-class row, which
// stays store-only so the public notes ref never carries its words
test('#4581: land on a machine without the store reads the signed row ready copied into the READY note', () => {
const fx = prep();
const head = openPr(fx, '44', { ready: false });
fx.repo.git('checkout', '-q', 'pr-44');
const rec = record(fx, '44', head);
expect(rec.status, rec.err).toBe(0);
const id = rec.out.split(' ')[1]!;
const ds = applied(fx, '44', head);
setBody(fx, '44', bodyWith('44', head, ds));
const pregate = path.join(fx.repo.root, 'pregate.json');
fs.writeFileSync(pregate, JSON.stringify({ schema_version: 1, tree: runBin(fx.repo, 'gstack-wtree', []).out.trim(), head, verdict: 'pass', checks: FULL_CHECKS }));
const ready = runBin(fx.repo, 'gstack-ship-queue', ['ready', '--pr', '44', '--pregate', pregate, '--base', 'main'], fx.env);
expect(ready.status, ready.out + ready.err).toBe(EXIT.ok);
fx.repo.git('checkout', '-q', '--detach', 'origin/main');
const elsewhere = { ...fx.env, GSTACK_STATE_ROOT: path.join(fx.repo.root, 'lander-state') };
const landAt = (env: Record<string, string>, extra: string[] = []) => runBin(fx.repo, 'gstack-ship-queue', ['land', '--pr', '44', '--pin', head, '--base', 'main', ...extra], env);
expect(appliedGateDispositions(fx.repo.work, { branch: 'pr-44', pin: head, env: { ...storeEnv(fx), GSTACK_STATE_ROOT: elsewhere.GSTACK_STATE_ROOT } }).applied).toEqual([]);
const bare = landAt(elsewhere);
expect([bare.status, bare.err]).toEqual([EXIT.refused, expect.stringContaining(`disposition ${id} is not accepted`)]);
expect(gateLines(bare.out)[0]).toBe(`GATE_DISPOSITION: ${gateDispositionText(ds[0]!)}`);
expect(gateLines(bare.out)[1]).toContain('ready_note_rows=1');
const landed = landAt(elsewhere, ['--accept-gate-disposition', id]);
expect(landed.status, landed.out + landed.err).toBe(EXIT.ok);
expect(landed.out).toContain('MERGED: #44 as ');
}, 180_000);
test('#4581: an edited READY note row counts for nothing, so land elsewhere still refuses', () => {
const fx = prep();
const head = openPr(fx, '45', { ready: false });
const rec = record(fx, '45', head);
expect(rec.status, rec.err).toBe(0);
const loc = locate({ cwd: fx.repo.work, env: storeEnv(fx), branch: 'pr-45' }) as StoreLocation;
const row = JSON.parse(fs.readFileSync(loc.file, 'utf8').trim().split('\n').at(-1)!) as ApprovalRow;
const edited = { ...row, ask: row.ask.replace(REASON, 'the gate is fine') };
const env = { ...storeEnv(fx), GSTACK_STATE_ROOT: path.join(fx.repo.root, 'lander-state') };
expect(appliedGateDispositions(fx.repo.work, { branch: 'pr-45', pin: head, env, noted: [edited] }).applied).toEqual([]);
expect(appliedGateDispositions(fx.repo.work, { branch: 'pr-45', pin: head, env, noted: [row] }).applied.map(d => d.approval)).toEqual([row.id]);
const other = appliedGateDispositions(fx.repo.work, { branch: 'pr-46', pin: head, env, noted: [row] }).applied;
expect(other).toEqual([]);
}, 120_000);
test('#4581: a newer store row for the same finding wins over an older READY note row', () => {
const fx = prep();
const head = openPr(fx, '47', { ready: false });
expect(record(fx, '47', head).status).toBe(0);
const loc = locate({ cwd: fx.repo.work, env: storeEnv(fx), branch: 'pr-47' }) as StoreLocation;
const older = JSON.parse(fs.readFileSync(loc.file, 'utf8').trim().split('\n').at(-1)!) as ApprovalRow;
const again = runBin(fx.repo, 'gstack-approvals', ['gate', '--branch', 'pr-47', '--finding', F, '--gate-id', G, '--head', head, '--reason', 'owner re-ruled after ready', '--words', 'Do it', '--by', 'Founderstar Captain (FOUN-1)'], fx.env);
expect(again.status, again.err).toBe(0);
const newer = JSON.parse(fs.readFileSync(loc.file, 'utf8').trim().split('\n').at(-1)!) as ApprovalRow;
expect(newer.id).not.toBe(older.id);
expect(appliedGateDispositions(fx.repo.work, { branch: 'pr-47', pin: head, env: storeEnv(fx), noted: [older] }).applied.map(d => d.approval)).toEqual([newer.id]);
}, 120_000);
test('a row the lane appends to the store by hand, digest and all, still needs the lander: land refuses and prints it, a wrong id refuses, and the accepted id lands', () => {
const fx = prep();
const head = openPr(fx, '42');
+64
View File
@@ -0,0 +1,64 @@
/**
* The READY tail's last two template gaps (#4529, #4575, #4578): the Attention section printed
* "<flags against decision-trail row numbers, or No flags>" for the lane to fill, and TRIAL_MERGES listed outside fork PRs such as
* #4499 as conflicts a lane must resolve. The flags line now comes from the trail-read row's result, and a fork PR is labelled and
* never fetched or merged.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { trailReadRow, trialMergeLines } from '../lib/ship-queue';
import type { ShipReceipt } from '../lib/headless-artifacts';
import { readyTailLines } from '../lib/ship-receipt';
const dirs: string[] = [];
afterEach(() => { while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
const tmp = () => { const d = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-ready-tail-')); dirs.push(d); return d; };
const HEADER = 'ts\tphase\tdecision\twhy\tevidence\tresult\n';
const trail = (rows: string[]) => { const f = path.join(tmp(), 'decisions.tsv'); fs.writeFileSync(f, HEADER + rows.map(r => r + '\n').join('')); return f; };
const READ = (flags: string) => `2026-11-20T00:01:00Z\ttrail-read\topenai/gpt-6.2-sol (Subagent 4)\trule 27\tflags.md\t${flags}`;
const GATE = { review_depth: { class: 'gate', risk: [] } } as unknown as ShipReceipt;
const CODE = { review_depth: { class: 'code', risk: [] } } as unknown as ShipReceipt;
const attention = (r: ShipReceipt, file?: string) => { const l = readyTailLines(r, { trialMerges: ['TRIAL_MERGES: none share a file (0 open PRs checked)'], trailRead: trailReadRow(file) }); return l.slice(l.indexOf('Attention:') + 1); };
describe('the Attention flags line comes from the trail (#4529)', () => {
// Value: protects=READY never prints the flags placeholder: a risk-class PR prints the trail-read row's flags against its row number
// and a self-audited PR prints only its opener; fails_when=the placeholder line comes back or a flag is dropped; why_new=lanes
// pasted the placeholder on #4529, #4575 and #4578; seam=trailReadRow and readyTailLines as ready calls them
test('a trail-read row\'s flags, or No flags, against its row; no line without a row or on a self-audited PR', () => {
expect(attention(GATE, trail([READ('rows 4 and 7: retry claimed without a log')]))).toEqual([
'reviewed by openai/gpt-6.2-sol (Subagent 4) (risk class: gate; rule 27 cross-family trail read, trail row 1)',
'Flags (trail row 1): rows 4 and 7: retry claimed without a log',
]);
for (const none of ['No flags', 'none', '']) expect(attention(GATE, trail([READ(none)]))[1]).toBe('No flags (trail row 1)');
expect(attention(GATE)).toHaveLength(1);
expect(attention(GATE)[0]).toStartWith('MISSING: cross-family trail read');
expect(attention(CODE, trail([READ('row 2')]))).toEqual(['self-audited (not a risk class: no cross-family trail read)']);
for (const r of [GATE, CODE]) expect(readyTailLines(r).join('\n')).not.toContain('<flags against');
});
});
describe('TRIAL_MERGES labels an outside fork PR instead of merging it (#4499)', () => {
// Value: protects=an outside PR from a fork that shares a file is named as outside and never fetched or merged, while a sibling lane
// is still trial-merged; fails_when=a fork PR is listed as a CONFLICT the lane must resolve, or its head is fetched; why_new=#4529,
// #4575 and #4578 listed #4499 as a real conflict; seam=trialMergeLines with a gh stub
test('a fork PR sharing a file is labelled; a sibling sharing the same file is still merged', () => {
const root = tmp();
const git = (...a: string[]) => { const r = spawnSync('git', ['-c', 'user.name=Fx', '-c', 'user.email=fx@example.com', ...a], { cwd: root, encoding: 'utf8', timeout: 30_000 }); if (r.status !== 0) throw new Error(r.stderr); return r.stdout.trim(); };
git('init', '-q', '-b', 'main');
fs.writeFileSync(path.join(root, 'a.txt'), 'a\n'); git('add', '-A'); git('commit', '-q', '-m', 'base');
const branch = (name: string, text: string) => { git('checkout', '-q', '-b', name, 'main'); fs.writeFileSync(path.join(root, 'a.txt'), text); git('commit', '-q', '-am', name); return git('rev-parse', 'HEAD'); };
const sibling = branch('sib', 'sibling\n');
const head = branch('mine', 'mine\n');
const calls: string[][] = [];
const list = [{ number: 1, headRefOid: head, files: [{ path: 'a.txt' }] }, { number: 2, headRefOid: sibling, files: [{ path: 'a.txt' }] }, { number: 4499, headRefOid: 'f'.repeat(40), files: [{ path: 'a.txt' }], isCrossRepository: true }];
const lines = trialMergeLines({ repoRoot: root, base: 'main', gh: a => { calls.push(a); return { ok: true, out: JSON.stringify(list) }; } }, '1', head, ['a.txt']);
expect(lines).toEqual([
`TRIAL_MERGES: #2 ${sibling.slice(0, 12)} shares a.txt: CONFLICT in a.txt; the lane states the resolution`,
`TRIAL_MERGES: #4499 ${'f'.repeat(12)} shares a.txt: outside PR from a fork, not a sibling lane; not trial-merged (rule 19)`,
]);
expect(calls[0]).toContain('number,headRefOid,files,isCrossRepository');
});
});
+21
View File
@@ -92,6 +92,27 @@ describe('the commit message', () => {
expect(m).toMatchObject({ skippedParent: parent, body: 'Co-authored-by: Erin <erin@example.com>' });
expect(branchTrailers(r.root, r.base, pin)).toEqual(['Co-authored-by: Dan <dan@example.com>', 'Co-authored-by: Erin <erin@example.com>']);
});
// Value: protects=a stacked child that merged main after its parent squash-landed still leaves out the parent's credit lines, and
// main's own; fails_when=land measures the parent with the reviewed-range rule (a parent the merge base already holds is no
// parent, GST-3315) or reads the trailers from the parent alone; why_new=#4580 note: the child's squash body repeated the parent's
// trailers; seam=landMessage as land calls it, with the merge base of the pin and main's tip
test('a stacked child that merged main after its parent landed leaves out the parent\'s and main\'s trailers', () => {
const r = repo();
r.git(['checkout', '-q', '-b', 'stack']);
const parent = r.commit('src/parent.ts', 'parent\n\nCo-authored-by: Dan <dan@example.com>');
r.commit('src/child.ts', 'child\n\nCo-authored-by: Erin <erin@example.com>');
r.git(['checkout', '-q', 'main']);
r.git(['checkout', '-q', parent, '--', 'src/parent.ts']);
r.git(['commit', '-q', '-m', 'Parent PR (#4)\n\nReview-Finding: p1/red-team#1 reader=red-team']);
r.commit('docs/other.md', 'Other PR (#5)\n\nCo-authored-by: Fay <fay@example.com>');
const tip = r.git(['rev-parse', 'HEAD']);
r.git(['checkout', '-q', 'stack']);
r.git(['merge', '-q', '--no-edit', 'main']);
const pin = r.git(['rev-parse', 'HEAD']);
const mergeBase = r.git(['merge-base', pin, tip]);
const m = landMessage(r.root, { pr: '6', title: 'Child', prBody: '', mergeBase, pin, tip, policy: SQUASH });
expect(m).toMatchObject({ skippedParent: parent, body: 'Co-authored-by: Erin <erin@example.com>' });
});
});
describe('the merge method', () => {