mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 11:53:55 +01:00
Approved edits after review no longer force a new full review, and ship works in git worktrees (#4862)
Small edits that a project lead approves after the final review no longer force a whole new review. Shipping from a git worktree no longer crashes, and merging main no longer throws away a finished review when main already made one of the PR's exact changes. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/specialist-batched#2 reader=testing
This commit is contained in:
1 parent
9befb56288
commit
d0b59828d6
21 files changed
+582
-66
No files matched your search
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* HARN-108: inside a linked worktree `.git` is a file (`gitdir: …`), so every gstack file kept under the git directory must
|
||||
* come from `git rev-parse --git-path`; the literal `.git/<name>` fallback used when git failed or timed out wrote through
|
||||
* that file and died with ENOTDIR (gstack-review-plan's consumer scan on `.git/gstack-consumers`).
|
||||
*/
|
||||
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 { gitPath } from '../lib/git-path';
|
||||
import { collectLive } from '../lib/review-collect';
|
||||
import { readMechanicalLines, writeMechanicalRecord } from '../lib/ship-mechanical';
|
||||
import { patchId } from '../lib/ship-receipt-patch';
|
||||
|
||||
const dirs: string[] = [];
|
||||
const savedPath = process.env.PATH;
|
||||
const savedScan = process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS;
|
||||
afterEach(() => {
|
||||
process.env.PATH = savedPath;
|
||||
if (savedScan === undefined) delete process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS; else process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS = savedScan;
|
||||
while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function worktree() {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'git-path-'));
|
||||
dirs.push(root);
|
||||
const main = path.join(root, 'main'), wt = path.join(root, 'wt');
|
||||
fs.mkdirSync(main);
|
||||
const git = (cwd: string, ...a: string[]) => spawnSync('git', a, { cwd, encoding: 'utf8', timeout: 30_000 });
|
||||
git(main, 'init', '-q', '-b', 'main'); git(main, 'config', 'user.email', 't@t'); git(main, 'config', 'user.name', 't'); git(main, 'config', 'commit.gpgsign', 'false');
|
||||
fs.writeFileSync(path.join(main, 'README.md'), '# x\n'); git(main, 'add', '.'); git(main, 'commit', '-qm', 'base');
|
||||
expect(git(main, 'worktree', 'add', '-q', '-b', 'feat', wt).status).toBe(0);
|
||||
fs.mkdirSync(path.join(wt, 'src')); fs.writeFileSync(path.join(wt, 'src', 'a.ts'), 'export const a = 1;\n');
|
||||
git(wt, 'add', '.'); git(wt, 'commit', '-qm', 'feat');
|
||||
return { main, wt, git };
|
||||
}
|
||||
/** A PATH whose git fails the calls whose arguments match the shell pattern `only` (every call by default), as a hung or killed git looks to the callers. */
|
||||
function brokenGit(only = '*'): void {
|
||||
const real = path.join(spawnSync('git', ['--exec-path'], { encoding: 'utf8', timeout: 10_000 }).stdout.trim(), 'git');
|
||||
const bin = fs.mkdtempSync(path.join(os.tmpdir(), 'git-path-bin-'));
|
||||
dirs.push(bin);
|
||||
fs.writeFileSync(path.join(bin, 'git'), `#!/bin/sh\ncase "$*" in ${only}) echo "fatal: simulated failure" >&2; exit 128;; esac\nexec '${real}' "$@"\n`, { mode: 0o755 });
|
||||
process.env.PATH = `${bin}${path.delimiter}${savedPath}`;
|
||||
}
|
||||
|
||||
// Value: protects=gstack files under the git dir land in the worktree's own git dir; fails_when=a caller writes through the
|
||||
// .git file (ENOTDIR) or guesses .git/<name> after git fails; seam=lib/git-path.ts and its callers in a real git worktree
|
||||
describe('git-dir paths in a linked worktree (HARN-108)', () => {
|
||||
test('a real worktree: the paths resolve under its gitdir and the writers succeed', () => {
|
||||
const { wt, main, git } = worktree();
|
||||
expect(fs.statSync(path.join(wt, '.git')).isFile()).toBe(true);
|
||||
const at = gitPath(wt, 'gstack-consumers');
|
||||
expect(at.ok).toBe(true);
|
||||
if (!at.ok) return;
|
||||
expect(at.path.startsWith(path.join(fs.realpathSync(main), '.git')) || at.path.startsWith(path.join(main, '.git'))).toBe(true);
|
||||
fs.mkdirSync(at.path, { recursive: true });
|
||||
const base = git(wt, 'rev-parse', 'main').stdout.trim(), head = git(wt, 'rev-parse', 'HEAD').stdout.trim();
|
||||
expect(typeof patchId(wt, base, head, ['.'])).toBe('string');
|
||||
const tree = git(wt, 'rev-parse', 'HEAD^{tree}').stdout.trim();
|
||||
expect(writeMechanicalRecord(wt, tree, { 'src/a.ts': 'golden, regenerated by x' })).toBeNull();
|
||||
expect(readMechanicalLines(wt, tree)).toEqual(['Mechanical retake: src/a.ts (golden, regenerated by x)']);
|
||||
});
|
||||
|
||||
test('git failing: every writer names the failure and nothing is written through the .git file', () => {
|
||||
const { wt, git } = worktree();
|
||||
const base = git(wt, 'rev-parse', 'main').stdout.trim(), head = git(wt, 'rev-parse', 'HEAD').stdout.trim();
|
||||
const tree = git(wt, 'rev-parse', 'HEAD^{tree}').stdout.trim();
|
||||
brokenGit();
|
||||
const at = gitPath(wt, 'gstack-patch-id');
|
||||
expect(at).toEqual({ ok: false, error: expect.stringContaining('gstack does not guess .git/gstack-patch-id') });
|
||||
const id = patchId(wt, base, head, ['.']);
|
||||
expect(id).toEqual({ error: expect.stringContaining('git rev-parse --git-path gstack-patch-id gave no path') });
|
||||
expect(JSON.stringify(id)).not.toContain('ENOTDIR');
|
||||
expect(writeMechanicalRecord(wt, tree, { 'src/a.ts': 'x' })).toContain('gave no path');
|
||||
expect(fs.statSync(path.join(wt, '.git')).isFile()).toBe(true);
|
||||
});
|
||||
|
||||
test('the consumer scan in a worktree whose git dir lookup fails names it, not ENOTDIR on .git/gstack-consumers', () => {
|
||||
const { wt, git } = worktree();
|
||||
fs.mkdirSync(path.join(wt, 'data')); fs.writeFileSync(path.join(wt, 'data', 'rows.json'), '[1]\n');
|
||||
fs.writeFileSync(path.join(wt, 'src', 'read.ts'), "export const f = 'data/rows.json';\n");
|
||||
git(wt, 'add', '.'); git(wt, 'commit', '-qm', 'data');
|
||||
brokenGit('*"--git-path gstack-consumers"*');
|
||||
const errors = JSON.stringify(collectLive(wt, 'main').errors);
|
||||
expect(errors).toContain('git rev-parse --git-path gstack-consumers gave no path');
|
||||
expect(errors).not.toContain('ENOTDIR');
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { DOCS_CAPS_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(90_000);
|
||||
@@ -113,3 +114,52 @@ describe('finish honours an edit ruling after the final review (GST-3775)', () =
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith(`RULED_EDIT_REFUSED: ${routed} (its spelling holds a replacement character (U+FFFD)`);
|
||||
});
|
||||
});
|
||||
|
||||
/** GBRA-108 (gbrain #10492, #10494): Step 14.5's audit hashed `file`, an edit to it followed the final review, and the owner ruled it. */
|
||||
function docEditedAfterAudit(file: string, base: Record<string, string> = {}) {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', [file]: '# Notes\n\nOne line.\n', ...base }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
ships.push(f);
|
||||
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
|
||||
const post = path.join(f.root, 'post.json');
|
||||
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', file]).status).toBe(0);
|
||||
f.write({ [file]: '# Notes\n\nOne line.\nA second line the audit asked for.\n' }); f.commit('docs audit edit after the final review');
|
||||
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
|
||||
}
|
||||
const finishRechecked = (f: ShipFx, reviewed: string, post: string) => f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, '--docs-rechecked', '--lane', LANE]);
|
||||
|
||||
// Value: protects=a ruled edit to a doc the docs audit hashed carries finish's freshness check, at the ruled bytes only;
|
||||
// fails_when=finish prints DOCS: stale (<path>) after RULED_EDIT (GBRA-108), or an unruled doc edit, or one edited again after
|
||||
// its ruling, passes as fresh; seam=lib/ship-release.ts route's ruled paths into docsFresh
|
||||
describe('a ruled edit to an audited doc keeps the docs audit fresh (GBRA-108)', () => {
|
||||
test('agent-prose policy doc (behavior) and a plain doc: ruled, each carries as ruled=1', () => {
|
||||
for (const file of ['docs/ship-policy.md', 'README.md']) {
|
||||
const { f, stopHead, reviewed, post } = docEditedAfterAudit(file);
|
||||
const before = finishRechecked(f, reviewed, post);
|
||||
expect([file, before.status]).toEqual([file, 3]);
|
||||
expect(rule(f, file, stopHead).status).toBe(0);
|
||||
const r = finishRechecked(f, reviewed, post);
|
||||
expect([file, lineOf(r.stdout, 'RULED_EDIT')]).toEqual([file, expect.stringContaining(`RULED_EDIT: ${file} (ruled at ${stopHead.slice(0, 12)}`)]);
|
||||
expect([file, lineOf(r.stdout, 'DOCS')]).toEqual([file, 'DOCS: fresh against the Step 14.5 post-audit snapshot (carried: tests=0 base=0 requested=0 ruled=1)']);
|
||||
}
|
||||
});
|
||||
|
||||
test('an unruled doc edit, or a doc edited again after its ruling, is still stale', () => {
|
||||
const plain = docEditedAfterAudit('README.md');
|
||||
expect(lineOf(finishRechecked(plain.f, plain.reviewed, plain.post).stdout, 'DOCS')).toBe('DOCS: stale (README.md)');
|
||||
const later = docEditedAfterAudit('README.md');
|
||||
expect(rule(later.f, 'README.md', later.stopHead).status).toBe(0);
|
||||
later.f.write({ 'README.md': '# Notes\n\nOne line.\nA different line.\n' }); later.f.commit('edit it again');
|
||||
const r = finishRechecked(later.f, later.reviewed, later.post);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith('RULED_EDIT_REFUSED: README.md (');
|
||||
expect(lineOf(r.stdout, 'DOCS')).toBe('DOCS: stale (README.md)');
|
||||
});
|
||||
|
||||
test('a ruled doc edit that breaks a doc cap the base declares stops finish', () => {
|
||||
const policy = JSON.stringify({ docs: { caps: [{ path: 'README.md', max_bytes: 30 }] }, min_gstack_version: DOCS_CAPS_KEY_VERSION });
|
||||
const { f, stopHead, reviewed, post } = docEditedAfterAudit('README.md', { '.gstack/ship-policy.json': policy });
|
||||
expect(rule(f, 'README.md', stopHead).status).toBe(0);
|
||||
const r = finishRechecked(f, reviewed, post);
|
||||
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining('a ruled doc edit breaks a doc cap')]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* HARN-172 (harness-evals #625): the branch deleted one JSON array entry, main then deleted the same entry, and the lane merged
|
||||
* origin/main. The branch's diff against the new base lost that hunk, so the product patch-id moved and carry refused with
|
||||
* RECEIPT_CARRY_PRODUCT_CHANGED, forcing a fresh full review of a head whose every byte was reviewed. A path is now carried when
|
||||
* it is exactly the reviewed change replayed onto the new base (absorbedByBase); a hunk dropped or edited in the resolution, or
|
||||
* any other change, still refuses.
|
||||
*/
|
||||
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 { absorbedByBase, comparePath } from '../lib/ship-patch';
|
||||
import { extractReceipt } from '../lib/ship-receipt';
|
||||
import { RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(120_000);
|
||||
const BIN = path.dirname(RELEASE);
|
||||
const RECEIPT = path.join(BIN, 'gstack-ship-receipt');
|
||||
const UNATTENDED = { GSTACK_SESSION_KIND: 'unattended' };
|
||||
const ships: ShipFx[] = [];
|
||||
afterEach(() => { while (ships.length) ships.pop()!.cleanup(); });
|
||||
|
||||
const LIST = 'config/cases.json';
|
||||
const CODE = 'src/run.ts';
|
||||
const list = (ids: string[]) => `[\n${ids.map(i => ` "${i}"`).join(',\n')}\n]\n`;
|
||||
const code = (n: number) => Array.from({ length: 12 }, (_, i) => `export const v${i + 1} = ${i + 1 === 6 ? n : i + 1};`).join('\n') + '\n';
|
||||
const ALL = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
||||
const without = (...gone: string[]) => ALL.filter(i => !gone.includes(i));
|
||||
|
||||
/** The branch drops case "c" and edits run.ts; its receipt is written at that head; main then lands `baseList`. */
|
||||
function absorbed(baseList: string[], resolved?: Record<string, string>) {
|
||||
const f = shipFixture({ [LIST]: list(ALL), [CODE]: code(6) }, { [LIST]: list(without('c')), [CODE]: code(60) });
|
||||
ships.push(f);
|
||||
const from = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const reviewedBase = f.git('merge-base', 'origin/main', 'HEAD').stdout.trim();
|
||||
const body = path.join(f.root, 'body.md');
|
||||
fs.writeFileSync(body, '## Summary\n');
|
||||
const w = f.run(RECEIPT, ['write', '--pr', '5', '--base', 'main', '--body', body], UNATTENDED);
|
||||
expect([w.status, w.stderr.slice(0, 400)]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
f.advanceBase({ [LIST]: list(baseList) });
|
||||
f.git('fetch', '-q', 'origin');
|
||||
if (f.git('merge', '-q', '--no-edit', 'origin/main').status !== 0 || resolved) { f.write(resolved ?? {}); f.commit('merge main'); }
|
||||
const head = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const sides = { reviewedBase, reviewed: from, currentBase: f.git('merge-base', 'origin/main', 'HEAD').stdout.trim(), current: head };
|
||||
const carry = () => f.run(RECEIPT, ['carry', '--body', body, '--base', 'main'], UNATTENDED);
|
||||
return { f, sides, body, carry };
|
||||
}
|
||||
|
||||
describe('receipt carry across a base merge that landed one of the branch\'s hunks (HARN-172)', () => {
|
||||
// Value: protects=a clean base merge in which main made the branch's exact deletion keeps the receipt; fails_when=carry refuses
|
||||
// RECEIPT_CARRY_PRODUCT_CHANGED for a head with no unreviewed byte (harness-evals #625); seam=gstack-ship-receipt carry and
|
||||
// absorbedByBase on a real merge
|
||||
test('main deleted the same entry: the path is absorbed and the receipt carries, naming it', () => {
|
||||
const x = absorbed(without('c'));
|
||||
expect(comparePath(x.f.work, x.sides, LIST)).toBe('changed');
|
||||
expect(absorbedByBase(x.f.work, x.sides, LIST)).toBe(true);
|
||||
const r = x.carry();
|
||||
expect([r.status, r.stderr.slice(0, 600)]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
expect(extractReceipt(fs.readFileSync(x.body, 'utf8')).receipt!.carry!.reason).toContain(`branch hunks the base landed identically (${LIST}`);
|
||||
});
|
||||
|
||||
test('main deleted the same entry and another one: still only the reviewed change replayed, so it carries', () => {
|
||||
const x = absorbed(without('c', 'g'));
|
||||
expect(absorbedByBase(x.f.work, x.sides, LIST)).toBe(true);
|
||||
expect(x.carry().status).toBe(EXIT.ok);
|
||||
});
|
||||
|
||||
test('a TMPDIR it cannot write reads as not absorbed instead of crashing the carry', () => {
|
||||
const x = absorbed(without('c'));
|
||||
const r = x.f.run(RECEIPT, ['carry', '--body', x.body, '--base', 'main'], { ...UNATTENDED, TMPDIR: path.join(x.f.root, 'missing', 'tmp') });
|
||||
expect([r.status === EXIT.ok, r.stderr.includes('RECEIPT_CARRY_PRODUCT_CHANGED')]).toEqual([false, true]);
|
||||
});
|
||||
|
||||
test('a symlink is never absorbed: its target is not text to merge', () => {
|
||||
const f = shipFixture({ [LIST]: list(ALL) }, { [CODE]: code(6) });
|
||||
ships.push(f);
|
||||
const link = (to: string, msg: string) => { fs.rmSync(path.join(f.work, 'link'), { force: true }); fs.symlinkSync(to, path.join(f.work, 'link')); f.commit(msg); return f.git('rev-parse', 'HEAD').stdout.trim(); };
|
||||
const before = link('a', 'link to a'), after = link('b', 'link to b');
|
||||
expect(absorbedByBase(f.work, { reviewedBase: before, reviewed: after, currentBase: after, current: after }, 'link')).toBe(false);
|
||||
});
|
||||
|
||||
// Value: protects=the fail-closed controls; fails_when=a resolution that drops or edits a branch hunk main never landed, or that
|
||||
// restores an entry main deleted, carries; seam=absorbedByBase and gstack-ship-receipt carry
|
||||
test('a resolution that also drops a hunk main never landed, edits a line, or keeps an entry main removed still refuses', () => {
|
||||
for (const [name, resolved] of [
|
||||
['dropped the branch edit to run.ts', { [CODE]: code(6) }],
|
||||
['edited the list', { [LIST]: list(without('c', 'd')) }],
|
||||
['kept an entry main removed', { [LIST]: list(without('c')) }],
|
||||
] as const) {
|
||||
const x = absorbed(without('c', 'g'), resolved);
|
||||
const r = x.carry();
|
||||
expect([name, r.status === EXIT.ok, r.stderr.includes('RECEIPT_CARRY_PRODUCT_CHANGED')]).toEqual([name, false, true]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* HARN-1 (harness-evals #638, #646, #632, #644, #490; GSTA-876 on gstack #4853): past R51's two rounds, the lane's Captain rules a
|
||||
* small edit after the read-only final review in (`gstack-approvals rule --finding edit:<path>`). The plan then still stopped
|
||||
* ("a fix followed the read-only final review"), because the fix range held the release stamps Step 12 wrote, which nobody rules,
|
||||
* and the receipt refused the targeted record read before the edit, so the only exit was another whole read-only full review.
|
||||
* Now stamps carry without a ruling, a ruled range with no targeted class in it carries the record (and the receipt names the
|
||||
* rulings that carried it), and a ruled range that does touch a targeted class plans exactly one targeted reader.
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ledgerPass, summarizeReviewLoop } from '../lib/review-scope';
|
||||
import { parseReviewTargeted, plainDocsSince, ruledChangeSince, targetedClassesSince } from '../lib/ship-receipt-depth';
|
||||
import { spawnSync } from '../lib/spawn-sync';
|
||||
import { BASE_POLICY, cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
setDefaultTimeout(120_000);
|
||||
const repos: FixtureRepo[] = [];
|
||||
const dirs: string[] = [];
|
||||
const saved = { ...process.env };
|
||||
afterEach(() => { process.env = { ...saved }; while (repos.length) cleanup(repos.pop()!); while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
|
||||
|
||||
const MONEY_CODE = 'export const spendCapUsd = 25;\nexport function charge(amountUsd: number) { if (amountUsd > spendCapUsd) throw new Error("over cap"); return amountUsd; }\n';
|
||||
const UTIL = 'export const label = (s: string) => s.trim();\n';
|
||||
const ENV = { GSTACK_APPROVALS_MIRROR: '0' };
|
||||
const run = (repo: FixtureRepo, name: string, args: string[]) => { const r = runBin(repo, name, args, ENV); return { status: r.status, stdout: r.out, stderr: r.err }; };
|
||||
|
||||
/** A money-class PR whose final review (and its targeted reader) read `passHead`, then Step 12's stamps, then one more edit. */
|
||||
function shipped(edit: Record<string, string>) {
|
||||
const repo = makeFixtureRepo({ policy: BASE_POLICY });
|
||||
repos.push(repo);
|
||||
const write = (files: Record<string, string>, msg: string) => {
|
||||
for (const [p, text] of Object.entries(files)) { fs.mkdirSync(path.dirname(path.join(repo.work, p)), { recursive: true }); fs.writeFileSync(path.join(repo.work, p), text); }
|
||||
repo.git('add', '-A'); repo.git('commit', '-q', '-m', msg);
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
};
|
||||
const log = fs.readFileSync(path.join(repo.work, 'CHANGELOG.md'), 'utf8');
|
||||
repo.git('checkout', '-q', '-b', 'feat');
|
||||
const passHead = write({ 'src/billing.ts': MONEY_CODE, 'src/util.ts': UTIL, 'CHANGELOG.md': log.replace('## [1.2.3.0]', '## [Unreleased]\n\n- charge() caps spend\n\n## [1.2.3.0]') }, 'feat');
|
||||
write({ VERSION: '1.2.4.0\n', 'CHANGELOG.md': log.replace('## [1.2.3.0]', '## [1.2.4.0] - 2026-11-27\n\n- charge() caps spend\n\n## [1.2.3.0]') }, 'release stamps');
|
||||
const head = write(edit, 'edit after the read-only final review');
|
||||
return { repo, passHead, head };
|
||||
}
|
||||
const rule = (repo: FixtureRepo, file: string, head: string) => run(repo, 'gstack-approvals', ['rule', '--finding', `edit:${file}`, '--head', head, '--reason', 'a one-line edit after the final review ships as a disclosed note', '--words', 'ship it with the note', '--by', 'GStack Minder (GSTA-36)']);
|
||||
const plan = (repo: FixtureRepo, args: string[]) => run(repo, 'gstack-review-plan', ['--base', 'main', '--post-review', '--pass', '3', '--last', 'full', '--adversarial-ran', ...args]);
|
||||
const patchAt = (repo: FixtureRepo, rev: string) => {
|
||||
repo.git('checkout', '-q', rev);
|
||||
try { return JSON.parse(run(repo, 'gstack-review-plan', ['--base', 'main', '--json']).stdout).targeted.targeted_patch_id as string; } finally { repo.git('checkout', '-q', 'feat'); }
|
||||
};
|
||||
const next = (stdout: string) => stdout.split('\n').find(l => l.startsWith('NEXT: ')) ?? '';
|
||||
const dispatches = (stdout: string) => stdout.split('\n').filter(l => l.startsWith('DISPATCH: '));
|
||||
|
||||
/** parseReviewTargeted with the receipt's own predicates (bin/gstack-ship-receipt write), for a record the reader made at `read`. */
|
||||
function bind(repo: FixtureRepo, read: string, head: string) {
|
||||
Object.assign(process.env, repo.env, ENV);
|
||||
delete process.env.GSTACK_APPROVALS_DIR;
|
||||
const productOf = (c: string) => spawnSync('git', ['patch-id', '--verbatim'], { input: spawnSync('git', ['diff', 'main', c, '--', '.', ':(exclude)VERSION', ':(exclude)CHANGELOG.md'], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).stdout, cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).stdout.split(' ')[0];
|
||||
const record = { classes: ['money'], rules: 'r', brief_sha: 'a'.repeat(64), status: 'done', findings: 0, raised_by: 'targeted', head: read };
|
||||
return parseReviewTargeted(record, productOf(head)!, productOf, from => targetedClassesSince(repo.work, from, head, 'main'), from => plainDocsSince(repo.work, from, head, 'main'), undefined, from => ruledChangeSince(repo.work, from, head, 'main'));
|
||||
}
|
||||
|
||||
describe('a Captain-ruled edit after the read-only final review (HARN-1)', () => {
|
||||
// Value: protects=a ruled edit outside every targeted class ships on the record the final review's targeted reader made, with
|
||||
// the rulings recorded; fails_when=the plan stops on the release stamps in the fix range, or the receipt refuses the record
|
||||
// read before the ruled edit (RECEIPT_INVALID), forcing a whole new read-only full review; seam=bin/gstack-review-plan
|
||||
// --range-base and parseReviewTargeted with ruledChangeSince
|
||||
test('a ruled edit with no targeted class: the plan is done and the receipt carries the record, naming the ruling', () => {
|
||||
const { repo, passHead, head } = shipped({ 'src/util.ts': UTIL.replace('trim()', 'trim().toLowerCase()') });
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(next(plan(repo, ['--range-base', passHead, '--targeted-ran', ran]).stdout)).toStartWith('NEXT: stop (');
|
||||
expect(bind(repo, passHead, head).ok).toBe(false);
|
||||
expect(rule(repo, 'src/util.ts', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(p.status, p.stderr).toBe(0);
|
||||
expect(p.stdout).toContain(`FIX_RANGE: runtime_lines=0 base=${passHead} ruled=1`);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: done (every edit since --range-base is ruled a note (RULED_EDIT)');
|
||||
expect(dispatches(p.stdout)).toEqual([]);
|
||||
expect(p.stdout).toContain(`SKIP: targeted-only read (every edit since --range-base is ruled a note and none carries a targeted class, so the record read at ${passHead.slice(0, 12)} carries`);
|
||||
const b = bind(repo, passHead, head);
|
||||
expect(b).toMatchObject({ ok: true, targeted: { classes: ['money'], read: passHead, ruled_edits: [{ path: 'src/util.ts', approval: expect.stringMatching(/^a-[0-9a-f]{12}$/), by: 'GStack Minder (GSTA-36)' }] } });
|
||||
const unread = plan(repo, ['--range-base', passHead]);
|
||||
expect(next(unread.stdout)).toStartWith('NEXT: targeted (');
|
||||
expect(dispatches(unread.stdout)).toEqual(['DISPATCH: targeted targeted effort=full classes=money']);
|
||||
});
|
||||
|
||||
// Value: protects=a ruled edit that changes money code gets exactly one targeted reader on HEAD (not a round, not a full review)
|
||||
// and the old record never carries it; fails_when=the plan stops for a new full review, or the receipt binds the record read
|
||||
// before the money edit; seam=bin/gstack-review-plan and parseReviewTargeted
|
||||
test('a ruled edit in money code: one targeted reader on HEAD, and the earlier record does not carry', () => {
|
||||
const { repo, passHead, head } = shipped({ 'src/billing.ts': MONEY_CODE.replace('25', '30') });
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(rule(repo, 'src/billing.ts', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(p.status, p.stderr).toBe(0);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: targeted (the loop is done and every edit since --range-base is ruled a note');
|
||||
expect(dispatches(p.stdout)).toEqual(['DISPATCH: targeted targeted effort=full classes=money']);
|
||||
expect(bind(repo, passHead, head)).toMatchObject({ ok: false, message: expect.stringContaining('the product changed after the read') });
|
||||
expect(bind(repo, head, head).ok).toBe(true);
|
||||
});
|
||||
|
||||
// Value: protects=the fail-closed negative controls; fails_when=an unruled edit, or a ruling that misses one changed path,
|
||||
// plans no reader or carries the record; seam=bin/gstack-review-plan and parseReviewTargeted
|
||||
test('an unruled path, or a ruling that misses one of the edited paths, still stops and still refuses the record', () => {
|
||||
const { repo, passHead, head } = shipped({ 'src/util.ts': UTIL.replace('trim()', 'trim().toLowerCase()'), 'src/other.ts': 'export const o = 1;\n' });
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(rule(repo, 'src/util.ts', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: stop (');
|
||||
expect(p.stdout).toContain(`--finding 'edit:src/other.ts' --head ${head}`);
|
||||
expect(p.stdout).not.toContain("--finding 'edit:VERSION'");
|
||||
expect(bind(repo, passHead, head).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=the targeted-only read (one targeted reader on HEAD after a ruled edit, not a review round) counts as bound;
|
||||
// fails_when=review-scope prints REVIEW_SCOPE_UNBOUND: pass 3 (ledger p3) for it (GSTA-876 on #4853), or a real pass 3 with
|
||||
// no review row stops being named; seam=lib/review-scope.ts ledgerPass and summarizeReviewLoop
|
||||
describe('a targeted-only read has no review row and is not unbound (GSTA-876)', () => {
|
||||
const since = '2026-11-26T19:00:00Z';
|
||||
const rows = [1, 2].map(pass => ({ skill: 'review', via: 'ship', pass, timestamp: `2026-11-26T19:0${pass}:00Z`, commit_full: String(pass).repeat(40), findings: [] }));
|
||||
function ledger(reader: string, more: Record<string, unknown>[] = []): string {
|
||||
const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'targeted-only-')), 'p3');
|
||||
fs.mkdirSync(dir);
|
||||
dirs.push(path.dirname(dir));
|
||||
const file = path.join(dir, 'review-ledger.jsonl');
|
||||
fs.writeFileSync(file, [{ event: 'rendered', reader, at: '2026-11-26T19:10:00Z' }, ...more, { event: 'output', reader, ids: [] }].map(e => JSON.stringify(e)).join('\n') + '\n');
|
||||
return file;
|
||||
}
|
||||
test('p3 with only the targeted reader is bound; p3 with any other reader is still unbound', () => {
|
||||
const only = ledgerPass(ledger('targeted'));
|
||||
expect(only.targetedOnly).toBe(true);
|
||||
expect(summarizeReviewLoop(rows, since, [[]], [only]).unbound).toBeUndefined();
|
||||
const other = ledgerPass(ledger('red-team'));
|
||||
expect(other.targetedOnly).toBeUndefined();
|
||||
expect(summarizeReviewLoop(rows, since, [[]], [other]).unbound).toEqual(['pass 3 (ledger p3): no review-log row, so its fixes and dispositions cannot be counted']);
|
||||
const silent = ledgerPass(ledger('targeted', [{ event: 'rendered', reader: 'red-team' }, { event: 'sent', reader: 'red-team' }]));
|
||||
expect(silent.targetedOnly).toBeUndefined();
|
||||
expect(summarizeReviewLoop(rows, since, [[]], [silent]).unbound).toEqual(['pass 3 (ledger p3): no review-log row, so its fixes and dispositions cannot be counted']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user