/ship keeps a PR's review after a main merge that only updates a shared harness pin, and warns when reviewers ran unlogged (GST-3463) (#4669)

A pull request no longer needs a fresh /ship when merging main only
updates a harness pin file it shares with another PR, and /ship's review
summary now warns when reviewers produced output that the run never
logged.

Why: #4652 paid for a full new review after such a merge, and a
harness-evals run lost its granted follow-up review because nothing was
logged.

Nothing to do.

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-22 10:18:51 +00:00
1 parent 75410da71f
commit 54723680fc
8 files changed
+257 -6

No files matched your search

@@ -0,0 +1,96 @@
/**
* HARN-109 (harness-evals#507): a /ship run dispatched its granted readers, then ran a reader by hand and never ran Step
* 9.4's persistence, so the review log held no row from the run, gstack-review-read printed NO_REVIEWS and the fix-check
* grant could not bind. gstack-review-scope summary reads both the run's dispatch ledgers and its rows, so it warns when
* readers produced output that no row of this run records. A run that logged its rows gets no warning.
*/
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 { collect, readJsonl, recordJudgment, type MergedLine } from '../lib/review-ledger';
import { cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';
setDefaultTimeout(60_000);
const repos: FixtureRepo[] = [];
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
const SINCE = '2026-11-02T01:00:00Z';
const at = (min: number) => new Date(Date.parse(SINCE) + min * 60_000).toISOString();
const review = (min: number) => ({ skill: 'review', via: 'ship', timestamp: at(min), status: 'clean', review_scope: 'frozen', pass: 1, findings: [] });
const fixCheck = (min: number) => ({ skill: 'review-fix-check', via: 'ship', timestamp: at(min), review_scope: 'frozen', completed: true, converged: true, findings: [] });
/** One pass directory of the run: each reader's output collected into its ledger and judged as labelled. */
function ledger(dir: string, reader: string): void {
fs.mkdirSync(dir, { recursive: true });
const file = path.join(dir, 'review-ledger.jsonl');
const mergedFile = path.join(dir, 'merged.jsonl');
fs.writeFileSync(mergedFile, '');
expect(collect(file, reader, 'NO FINDINGS', mergedFile).review).toBe(true);
const merged = readJsonl<MergedLine>(mergedFile);
const judgedFile = path.join(dir, 'judged.jsonl');
fs.writeFileSync(judgedFile, merged.map(m => JSON.stringify({ id: m.id, severity: m.label }) + '\n').join(''));
expect(recordJudgment(file, merged, merged.map(m => ({ id: m.id, severity: m.label })), judgedFile, mergedFile).ok).toBe(true);
}
function branchWith(rows: object[] | null): FixtureRepo {
const repo = makeFixtureRepo({ prefix: 'harn109-' });
repos.push(repo);
repo.git('checkout', '-qb', 'feat');
if (rows) {
const logDir = path.join(repo.home, 'projects', runBin(repo, 'gstack-slug', ['--get', 'SLUG']).out.trim());
fs.mkdirSync(logDir, { recursive: true });
fs.writeFileSync(path.join(logDir, 'feat-reviews.jsonl'), rows.map(r => JSON.stringify(r) + '\n').join(''));
}
return repo;
}
const summary = (repo: FixtureRepo, run: string) => runBin(repo, 'gstack-review-scope', ['summary', '--since', SINCE, '--run', run, '--json']);
describe('summary warns when a run\'s readers ran but it logged no rows (HARN-109)', () => {
// Value: protects=a run that dispatched readers and skipped Step 9.4 hears so before finish refuses on NO_REVIEWS;
// fails_when=summary counts the fix-check ledger and stays silent; seam=bin/gstack-review-scope summary; no_claim=-
test('a granted fix-check reader with no review-log row at all warns', () => {
const repo = branchWith(null);
const run = path.join(repo.root, 'run');
ledger(path.join(run, 'fc'), 'fix-check');
const r = summary(repo, run);
expect(r.err).toContain('REVIEW_ROWS_MISSING:');
expect(r.err).toContain('fc');
expect(r.err).toContain('gstack-review-log');
});
// Value: protects=a fix-check whose row was never logged is named even when the pass rows exist; fails_when=only the
// zero-row case warns; seam=summary; no_claim=-
test('a fix-check ledger with no review-fix-check row warns beside a logged pass', () => {
const repo = branchWith([review(5)]);
const run = path.join(repo.root, 'run');
ledger(path.join(run, 'p1'), 'security');
ledger(path.join(run, 'fc'), 'fix-check');
const r = summary(repo, run);
expect(r.status).toBe(EXIT.ok);
expect(r.err).toContain('REVIEW_ROWS_MISSING:');
expect(r.err).toContain('fc');
});
// Value: protects=a pass whose review row was never logged is named even when a Step 11 voice row was; fails_when=any
// via:ship row counts as the pass's row; seam=summary; no_claim=-
test('a pass ledger with no review row warns beside a logged voice row', () => {
const repo = branchWith([{ skill: 'adversarial-review', via: 'ship', timestamp: at(20), status: 'clean', findings: [] }]);
const run = path.join(repo.root, 'run');
ledger(path.join(run, 'p1'), 'security');
const r = summary(repo, run);
expect(r.err).toContain('REVIEW_ROWS_MISSING: readers ran (ledger p1)');
});
// Value: protects=no warning when every reader's row is logged (negative control); fails_when=the warning fires on a
// normal run; seam=summary; no_claim=-
test('a run that logged its pass and fix-check rows gets no warning', () => {
const repo = branchWith([review(5), fixCheck(30)]);
const run = path.join(repo.root, 'run');
ledger(path.join(run, 'p1'), 'security');
ledger(path.join(run, 'fc'), 'fix-check');
const r = summary(repo, run);
expect(r.status).toBe(EXIT.ok);
expect(r.err).not.toContain('REVIEW_ROWS_MISSING');
});
});
@@ -0,0 +1,116 @@
/**
* gstack-ship-receipt carry across a harness pin that a base merge re-recorded (GSTA-749, #4652 at cc9b831d): the branch
* edits a pinned harness file and records the edit as non-behavioral; the base lands its own edit and re-pin of the same
* file; merging the base re-records the pin's blob for the merged file and nothing else. The pin is then a function of
* the pinned file's bytes, which the carry still compares as product, so it carries as a regenerated output. Controls:
* a pin whose blob is not the file's, a changed reason, a moved harness version and a blob-only re-pin of a pinned test
* helper (which carries as a test change on its own) still refuse.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { cleanup, commit, makeFixtureRepo, runBin, write, type FixtureRepo } from './helpers/pregate-fixture';
const repos: FixtureRepo[] = [];
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
const FILE = 'scripts/profile.ts';
const PIN = `scripts/harness-pins/${FILE}.json`;
const MANIFEST = 'scripts/harness-version.json';
const manifest = (version = 7) => `${JSON.stringify({ version, patterns: ['scripts/profile.ts'] }, null, 2)}\n`;
const BRANCH_REASON = 'the branch adds one free-only workflow name to the list, so no paid case selection can change';
const pin = (blob: string, reason: string, since = 7) => `${JSON.stringify({ blob, since, nonBehavioral: reason })}\n`;
const LINES = ['export const FREE = [', " 'a.yml',", '];', ...Array.from({ length: 8 }, (_, i) => `export const K${i} = ${i};`), ''];
/** main pins FILE; feature edits its start and re-pins, /ship receipt there; main edits its end and re-pins; feature merges main and resolves the pin with `resolve`. */
function repinned(resolve: (merged: string) => Record<string, string>): { body: string; repo: FixtureRepo } {
const repo = makeFixtureRepo(); repos.push(repo);
const blob = () => repo.git('rev-parse', `HEAD:${FILE}`);
repo.git('checkout', '-q', 'main');
commit(repo, { [MANIFEST]: manifest(), [FILE]: LINES.join('\n') }, 'main: harness file');
commit(repo, { [PIN]: pin(blob(), 'main pins the harness file') }, 'main: pin');
repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
repo.git('reset', '-q', '--hard', 'origin/main');
commit(repo, { [FILE]: [...LINES.slice(0, 2), " 'mutation.yml',", ...LINES.slice(2)].join('\n') }, 'feat: add a free-only workflow');
commit(repo, { [PIN]: pin(blob(), BRANCH_REASON) }, 'feat: re-pin as non-behavioral');
const body = path.join(repo.root, 'body.md');
expect(runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '4652', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body]).status).toBe(EXIT.ok);
repo.git('checkout', '-q', 'main');
commit(repo, { [FILE]: [...LINES.slice(0, -1), '// shared harness list', ''].join('\n') }, 'main: comment');
commit(repo, { [PIN]: pin(blob(), 'main adds a comment') }, 'main: re-pin');
repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
try { repo.git('merge', '-q', '--no-edit', 'origin/main'); } catch { /* the pin conflicts; resolved below */ }
for (const [rel, text] of Object.entries(resolve(repo.git('hash-object', FILE)))) write(repo.work, rel, text);
repo.git('add', '-A');
repo.git('commit', '-q', '--no-edit');
return { body, repo };
}
/** main pins a test helper; feature edits it and re-pins it as non-behavioral, /ship receipt there; then changes the helper's behavior and re-pins only its blob. */
function repinnedHelper(): { body: string; repo: FixtureRepo; pinPath: string } {
const helper = 'test/helpers/gate.ts';
const pinPath = `scripts/harness-pins/${helper}.json`;
const repo = makeFixtureRepo(); repos.push(repo);
const blob = () => repo.git('rev-parse', `HEAD:${helper}`);
repo.git('checkout', '-q', 'main');
commit(repo, { [MANIFEST]: manifest(), [helper]: 'export const RETRIES = 1;\n' }, 'main: harness helper');
commit(repo, { [pinPath]: pin(blob(), 'main pins the helper') }, 'main: pin');
repo.git('push', '-q', 'origin', 'main');
repo.git('checkout', '-q', 'feature');
repo.git('reset', '-q', '--hard', 'origin/main');
commit(repo, { [helper]: '// retry budget\nexport const RETRIES = 1;\n' }, 'feat: comment the helper');
commit(repo, { [pinPath]: pin(blob(), 'a comment only, so no case verdict can change') }, 'feat: re-pin as non-behavioral');
const body = path.join(repo.root, 'body.md');
expect(runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '4652', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body]).status).toBe(EXIT.ok);
commit(repo, { [helper]: '// retry budget\nexport const RETRIES = 5;\n' }, 'feat: retry more');
commit(repo, { [pinPath]: pin(blob(), 'a comment only, so no case verdict can change') }, 'feat: re-pin');
return { body, repo, pinPath };
}
const carry = (repo: FixtureRepo, body: string) => runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main', '--dry-run']);
describe('carry across a harness pin a base merge re-recorded (GSTA-749)', () => {
// Value: protects=a sibling PR keeps its receipt when a base merge only re-records a pin it shares (#4652 paid a fresh
// /ship); fails_when=the pin's new blob reads as a product change; seam=lib/ship-receipt-patch.ts productSpec; no_claim=gh pr edit
test('a pin whose only change is the merged file\'s blob carries as a regenerated output', () => {
const { repo, body } = repinned(merged => ({ [PIN]: pin(merged, BRANCH_REASON) }));
const out = carry(repo, body);
expect(out.status, out.err).toBe(EXIT.ok);
expect(out.out + out.err).toContain('regenerated outputs');
}, 90_000);
// Value: protects=fail closed on a pin that is not the pinned file's blob; fails_when=any pin edit carries; seam=productSpec; no_claim=gh pr edit
test('a pin whose blob is not the pinned file\'s still refuses', () => {
const { repo, body } = repinned(() => ({ [PIN]: pin('0'.repeat(40), BRANCH_REASON) }));
const out = carry(repo, body);
expect(out.status).toBe(EXIT.refused);
expect(out.err).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
expect(out.err).toContain(PIN);
}, 90_000);
// Value: protects=the reviewed non-behavioral claim is the one that ships; fails_when=a rewritten reason carries; seam=productSpec; no_claim=gh pr edit
test('a pin whose reason changed since review still refuses', () => {
const { repo, body } = repinned(merged => ({ [PIN]: pin(merged, `${BRANCH_REASON}; also the base comment`) }));
const out = carry(repo, body);
expect(out.status).toBe(EXIT.refused);
expect(out.err).toContain(PIN);
}, 90_000);
// Value: protects=a pinned test helper's behavior change after review still needs a fresh /ship: the helper carries as a test
// change, so its pin is the only product path that stops it (cross-family trail read on #4669); fails_when=any pin whose blob
// is its file's carries; seam=productSpec; no_claim=gh pr edit
test('a blob-only re-pin of a pinned test helper still refuses', () => {
const { repo, body, pinPath } = repinnedHelper();
const out = carry(repo, body);
expect(out.status).toBe(EXIT.refused);
expect(out.err).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
expect(out.err).toContain(pinPath);
}, 90_000);
// Value: protects=a version bump starts a new pass-rate series, a behavior change; fails_when=a bump rides a re-record; seam=productSpec; no_claim=gh pr edit
test('a re-record beside a harness version bump still refuses', () => {
const { repo, body } = repinned(merged => ({ [PIN]: pin(merged, BRANCH_REASON, 8), [MANIFEST]: manifest(8) }));
const out = carry(repo, body);
expect(out.status).toBe(EXIT.refused);
expect(out.err).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
}, 90_000);
});