mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-24 09:01:28 +01:00
/ship keeps its review count and grant claims honest, and a symlinked harness pin needs a fresh review (GST-3463) (#4703)
/ship now keeps a PR's earlier runs when it rewrites the PR description, so later runs count review rounds correctly, and it refuses to start reviewers when it could not save a granted round's claim. Why: both slips let a PR get more review rounds than the two-round limit allows, without anyone seeing it. Nothing to do: the fixes apply on the next /ship run. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/red-team#3 reader=red-team
This commit is contained in:
1 parent
f528f5bacc
commit
45e33b5e7b
15 files changed
+195
-23
No files matched your search
@@ -234,7 +234,7 @@ describe('gstack-docs-candidate', () => {
|
||||
// ci-37198445662 gate-census-2: ship-docsync-completion/-store parents spent 45-78 s of model time
|
||||
// retyping hash maps, child output and records into several artifacts after the child returned.
|
||||
const gate = fs.readFileSync(path.resolve(import.meta.dir, '..', 'ship/sections/documentation.md.tmpl'), 'utf8').replace(/\s+/g, ' ');
|
||||
expect(gate).toContain('post-child hashes (rerun the Prepare `snapshot` with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added, plus `--carry <this run\'s earlier audit\'s -post.json>` on a re-audit so receipt write resets both audits\' files; Step 16 `compare`s it; never type hashes)');
|
||||
expect(gate).toContain('post-child hashes (rerun the Prepare `snapshot` with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added, plus, on a re-audit, `--carry <its -post.json>` for each earlier audit of this run that saved one and `--carry-stopped <its Prepare snapshot>` for each that stopped before its post snapshot, so receipt write resets every audit\'s files; Step 16 `compare`s it; never type hashes)');
|
||||
expect(gate).toContain('Save records once; cite files by path, never copying their content.');
|
||||
const { dir, root, record } = repo();
|
||||
const args = ['--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'handbook'];
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('gstack-ship-receipt write', () => {
|
||||
const ok = runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '42', '--base', 'main', '--receipt', treeReceipt,
|
||||
'--gate', '{"tests":{"pass":1,"fail":0,"skip":0}}', '--ci', '@' + path.join(repo.root, 'ci.json'), '--spend-usd', '0.42',
|
||||
'--session-kind', 'unattended', '--artifacts-consumed', '2/3', '--run', 'run-1', '--thread', 'jam_1', '--queue-mode', 'stamp-at-merge',
|
||||
'--preregistration', 'none (no preregistration_shas)', '--history', 'squash-ok', '--body', body, '--out', path.join(repo.root, 'receipt.md')]);
|
||||
'--preregistration', 'none (no preregistration_shas)', '--history', 'squash-ok', '--body', body, '--out', path.join(repo.root, 'receipt.md')], ghShim(repo, { 42: { body: '' } }));
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.err.trim()).toBe(`SHIP_RECEIPT: pr=42 head=${head.slice(0, 12)} version=1.2.4.0 base=main gated_tree=${repo.git('rev-parse', 'HEAD^{tree}').slice(0, 12)} tree=same-modulo-stamps gate-reuse=eligible (reusable: tests; rerun: -) predecessor=${'b'.repeat(12)} session_kind=unattended artifacts_consumed=2/3 depth=light`);
|
||||
const parsed = extractReceipt(ok.out);
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
* 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.
|
||||
* helper (which carries as a test change on its own) and a pin turned into a symlink still refuse.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, write, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
@@ -22,7 +23,7 @@ const pin = (blob: string, reason: string, since = 7) => `${JSON.stringify({ blo
|
||||
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 } {
|
||||
function repinned(resolve: (merged: string) => Record<string, string>, linkPin = false): { body: string; repo: FixtureRepo } {
|
||||
const repo = makeFixtureRepo(); repos.push(repo);
|
||||
const blob = () => repo.git('rev-parse', `HEAD:${FILE}`);
|
||||
repo.git('checkout', '-q', 'main');
|
||||
@@ -41,7 +42,11 @@ function repinned(resolve: (merged: string) => Record<string, string>): { body:
|
||||
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);
|
||||
for (const [rel, text] of Object.entries(resolve(repo.git('hash-object', FILE)))) {
|
||||
if (!linkPin || rel !== PIN) { write(repo.work, rel, text); continue; }
|
||||
fs.rmSync(path.join(repo.work, rel), { force: true });
|
||||
fs.symlinkSync(text.trim(), path.join(repo.work, rel));
|
||||
}
|
||||
repo.git('add', '-A');
|
||||
repo.git('commit', '-q', '--no-edit');
|
||||
return { body, repo };
|
||||
@@ -106,6 +111,18 @@ describe('carry across a harness pin a base merge re-recorded (GSTA-749)', () =>
|
||||
expect(out.err).toContain(pinPath);
|
||||
}, 90_000);
|
||||
|
||||
// Value: protects=the harness reads the pin git shows: a symlink's link text can spell the reviewed pin while the harness
|
||||
// follows it elsewhere (second-model review of #4669); fails_when=a pin is read without its tree mode; seam=productSpec;
|
||||
// no_claim=gh pr edit
|
||||
test.skipIf(process.platform === 'win32')('a pin turned into a symlink whose link text is the pin still refuses', () => {
|
||||
const { repo, body } = repinned(merged => ({ [PIN]: pin(merged, BRANCH_REASON) }), true);
|
||||
expect(repo.git('ls-tree', 'HEAD', '--', PIN)).toStartWith('120000 ');
|
||||
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=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) }));
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* gstack-ship-receipt claim fails closed when it cannot record the claim in the run record (#4654 review note): the run
|
||||
* record's claim is what limits a stopped run to one self-granted fix round, so a claim the record never took must not
|
||||
* read as GRANT_CLAIMED with exit 0, or the run could stop and grant itself again.
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { PREFLIGHT, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(120_000);
|
||||
const BIN = path.join(import.meta.dir, '..', 'bin');
|
||||
const CHECKOUT = { GSTACK_LEASE_DIR: '', GSTACK_APPROVALS_MIRROR: '0' };
|
||||
const fixtures: ShipFx[] = [];
|
||||
afterEach(() => { while (fixtures.length) fixtures.pop()!.cleanup(); });
|
||||
|
||||
const run = (f: ShipFx, bin: string, args: string[]) => f.run(path.join(BIN, bin), args, CHECKOUT);
|
||||
const gitPath = (f: ShipFx, name: string) => path.resolve(f.work, f.git('rev-parse', '--git-path', name).stdout.trim());
|
||||
const record = (f: ShipFx) => JSON.parse(fs.readFileSync(gitPath(f, 'gstack-ship-run'), 'utf8'));
|
||||
|
||||
/** A run ro that stopped on one blocker and granted itself the fix-check for its own stop: returns the grant id and the body file. */
|
||||
function stoppedWithOwnGrant(f: ShipFx): { grant: string; body: string } {
|
||||
expect(f.run(PREFLIGHT, ['--base', 'main', '--run', 'ro'], CHECKOUT).status).toBe(0);
|
||||
const start = run(f, 'gstack-review-log', ['--start', 'review']);
|
||||
expect(start.status, start.stderr).toBe(0);
|
||||
const row = { skill: 'review', timestamp: new Date().toISOString(), via: 'ship', pass: 1, review_scope: 'frozen', completed: true, converged: false, status: 'issues_found', issues_found: 1, critical: 1, informational: 0, findings: [{ fingerprint: 'src/x.ts:1:outside-voice', severity: 'CRITICAL', action: 'open', blocking: true, ledger_id: 'p1/outside-voice#1', raised_by: 'outside-voice' }] };
|
||||
expect(run(f, 'gstack-review-log', [JSON.stringify(row), '--finish', start.stdout.trim()]).status).toBe(0);
|
||||
const body = path.join(f.root, 'body.md');
|
||||
fs.writeFileSync(body, 'Fixes a thing.\n');
|
||||
expect(run(f, 'gstack-ship-receipt', ['stop', '--body', body, '--pr', '7', '--run', 'ro', '--since', '2000-01-01T00:00:00Z']).status).toBe(0);
|
||||
const head = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const granted = run(f, 'gstack-approvals', ['round-grant', '--pr', '7', '--head', head, '--kind', 'fix-check', '--stop-run', 'ro', '--findings', 'p1/outside-voice#1', '--reason', 'fixable blocker', '--by', 'Captain GStack Minder (GSTA-36)']);
|
||||
const grant = /APPROVAL_RECORDED: (a-[0-9a-f]{12})/.exec(granted.stdout)?.[1];
|
||||
expect(grant, granted.stderr).toBeDefined();
|
||||
return { grant: grant!, body };
|
||||
}
|
||||
|
||||
describe('claim fails closed when the run record cannot take it (#4654)', () => {
|
||||
// Value: protects=the once-per-run self-grant limit, which reads the run record's claim; fails_when=claim prints
|
||||
// GRANT_CLAIMED and exits 0 after the record write failed; seam=gstack-ship-receipt claim; no_claim=gh pr edit
|
||||
test('a claim whose run-record write fails exits non-zero and says not to dispatch', () => {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
fixtures.push(f);
|
||||
const { grant, body } = stoppedWithOwnGrant(f);
|
||||
fs.mkdirSync(gitPath(f, 'gstack-gate-disposition.lock'));
|
||||
const claim = run(f, 'gstack-ship-receipt', ['claim', '--body', body, '--run', 'ro', '--grant', grant]);
|
||||
expect(claim.status).not.toBe(0);
|
||||
expect(claim.stdout).not.toContain('GRANT_CLAIMED');
|
||||
expect(claim.stderr).toContain('do not dispatch');
|
||||
expect(record(f).claim).toBeUndefined();
|
||||
});
|
||||
|
||||
// Value: protects=a claim retried after the failure clears records the claim once (positive control); fails_when=the
|
||||
// failed attempt's body marker blocks its own retry; seam=gstack-ship-receipt claim; no_claim=gh pr edit
|
||||
test('the same claim retried once the record is writable records it', () => {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
fixtures.push(f);
|
||||
const { grant, body } = stoppedWithOwnGrant(f);
|
||||
const lock = gitPath(f, 'gstack-gate-disposition.lock');
|
||||
fs.mkdirSync(lock);
|
||||
expect(run(f, 'gstack-ship-receipt', ['claim', '--body', body, '--run', 'ro', '--grant', grant]).status).not.toBe(0);
|
||||
fs.rmSync(lock, { recursive: true, force: true });
|
||||
const again = run(f, 'gstack-ship-receipt', ['claim', '--body', body, '--run', 'ro', '--grant', grant]);
|
||||
expect(again.status, again.stderr).toBe(0);
|
||||
expect(again.stdout).toContain('GRANT_CLAIMED: grant=' + grant);
|
||||
expect(record(f)).toMatchObject({ run: 'ro', state: 'open', claim: { grant } });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* gstack-ship-receipt write keeps the PR's earlier /ship runs when Step 19 hands it a freshly composed body (GST-3463 item 4):
|
||||
* Step 19 builds the body file from parts, so it holds no receipt and no runs block, and write placed only the new receipt
|
||||
* there; publishing it dropped every earlier run from the PR, so the next run's history counted fewer review rounds than the
|
||||
* PR had. With --pr, write now reads the live body's receipt and runs into a fresh body before placing the new receipt.
|
||||
* Control: an unreadable live body keeps today's output and says the earlier runs were not read.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { extractReceipt, receiptRuns } from '../lib/ship-receipt';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
|
||||
/** A feature branch with one /ship receipt already on the PR; the second head's write gets a fresh body file. */
|
||||
function secondRun(live: (firstBody: string) => string | null): { repo: FixtureRepo; first: string; out: ReturnType<typeof runBin>; body: string } {
|
||||
const repo = makeFixtureRepo(); repos.push(repo);
|
||||
repo.git('checkout', '-q', 'feature');
|
||||
const write = (body: string, env: Record<string, string> = {}) => runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '4700', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body], env);
|
||||
const firstBody = path.join(repo.root, 'first.md');
|
||||
expect(write(firstBody).status).toBe(EXIT.ok);
|
||||
const first = repo.git('rev-parse', 'HEAD');
|
||||
commit(repo, { 'src/second.js': 'module.exports = 2;\n' }, 'feat: second head');
|
||||
const stub = path.join(repo.root, 'stub');
|
||||
fs.mkdirSync(stub);
|
||||
const text = live(fs.readFileSync(firstBody, 'utf8'));
|
||||
const json = path.join(repo.root, 'live.json');
|
||||
if (text !== null) fs.writeFileSync(json, JSON.stringify({ body: text }));
|
||||
fs.writeFileSync(path.join(stub, 'gh'), text === null ? '#!/bin/sh\necho "gh: not authenticated" >&2\nexit 1\n' : `#!/bin/sh\ncat '${json}'\n`, { mode: 0o755 });
|
||||
const body = path.join(repo.root, 'second.md');
|
||||
fs.writeFileSync(body, 'The second head fixes the rest.\n');
|
||||
const out = write(body, { PATH: `${stub}${path.delimiter}${process.env.PATH}` });
|
||||
return { repo, first, out, body };
|
||||
}
|
||||
|
||||
describe('receipt write keeps the PR\'s earlier runs in a freshly composed body (GST-3463 item 4)', () => {
|
||||
// Value: protects=R51's per-PR round count, which reads the runs the PR body records; fails_when=a Step 19 body rewrite
|
||||
// publishes only the newest receipt; seam=gstack-ship-receipt write --pr --body; no_claim=gh pr edit
|
||||
test('a fresh body gets the live body\'s receipt as an earlier run', () => {
|
||||
const { repo, first, out, body } = secondRun(t => t);
|
||||
expect(out.status, out.err).toBe(EXIT.ok);
|
||||
const text = fs.readFileSync(body, 'utf8');
|
||||
expect(text).toContain('The second head fixes the rest.');
|
||||
expect(extractReceipt(text).receipt?.head).toBe(repo.git('rev-parse', 'HEAD'));
|
||||
expect(receiptRuns(text).map(r => r.head)).toEqual([first]);
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=a failed read is visible instead of a silent undercount (negative control); fails_when=write hides that it
|
||||
// could not read the earlier runs; seam=gstack-ship-receipt write --pr; no_claim=gh pr edit
|
||||
test('an unreadable live body leaves only this run and says why', () => {
|
||||
const { out, body } = secondRun(() => null);
|
||||
expect(out.status, out.err).toBe(EXIT.ok);
|
||||
expect(out.err).toContain("RECEIPT_RUNS: PR #4700's earlier runs were not read");
|
||||
expect(receiptRuns(fs.readFileSync(body, 'utf8'))).toEqual([]);
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 180,
|
||||
"why": "The docs audit steps say a re-audit carries each earlier audit by its post snapshot, or by its Prepare snapshot with --carry-stopped when it stopped before one"
|
||||
}
|
||||
Reference in new issue
Block a user