mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
/gstack-ship no longer lets anyone buy an extra review round or a narrow re-check. After two review rounds, a blocking finding ships only as an owner's recorded ruling, or the PR waits. Why: these paths were switched off last release and kept breaking; four PRs in one day tried to repair them. This is part 4 of the approved /gstack-ship simplification. Nothing to do: each removed flag now refuses with a message that names what replaced it. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p2/outside-voice#3 reader=outside-voice Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p2/adversarial-native#3 reader=adversarial-native Review-Finding: p2/adversarial-native#6 reader=adversarial-native
105 lines
6.7 KiB
TypeScript
105 lines
6.7 KiB
TypeScript
/**
|
|
* GST-2673 CLI seams: gstack-review-plan --prior-rounds / --round-grant, gstack-approvals round-grant, and
|
|
* gstack-ship-receipt history / stub over a PR body file.
|
|
*/
|
|
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';
|
|
|
|
const BIN = (n: string) => path.join(import.meta.dir, '..', 'bin', n);
|
|
const dirs: string[] = [];
|
|
afterEach(() => { while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
|
|
const tmp = (p: string) => { const d = fs.mkdtempSync(path.join(os.tmpdir(), p)); dirs.push(d); return d; };
|
|
|
|
function repo() {
|
|
const dir = tmp('pr-rounds-'), state = tmp('pr-rounds-state-');
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: dir, encoding: 'utf8', timeout: 10_000 });
|
|
git('init', '-q', '-b', 'main'); git('config', 'user.email', 't@t'); git('config', 'user.name', 't'); git('config', 'commit.gpgsign', 'false');
|
|
fs.writeFileSync(path.join(dir, 'README.md'), '# x\n'); git('add', '.'); git('commit', '-qm', 'base');
|
|
git('checkout', '-qb', 'feat');
|
|
fs.mkdirSync(path.join(dir, 'src')); fs.writeFileSync(path.join(dir, 'src', 'a.ts'), 'export const a = 1;\n'); git('add', '.'); git('commit', '-qm', 'feat');
|
|
const env = { ...process.env, GSTACK_STATE_ROOT: state, GSTACK_APPROVALS_MIRROR: '0', GSTACK_CAPY: '' };
|
|
const run = (bin: string, args: string[]) => spawnSync(BIN(bin), args, { cwd: dir, encoding: 'utf8', timeout: 60_000, env });
|
|
return { dir, head: git('rev-parse', 'HEAD').stdout.trim(), run };
|
|
}
|
|
|
|
describe('gstack-review-plan with the PR round count', () => {
|
|
test('two prior full rounds plan one read-only full review of HEAD; --round-grant is refused (GST-3562 part 4)', () => {
|
|
const r = repo();
|
|
const ro = r.run('gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', '--prior-rounds', '2', '--prior-full', '2', '--pr', '5']);
|
|
expect(ro.status).toBe(0);
|
|
expect(ro.stdout).toMatch(/REVIEW_PLAN: class=\S+ pass=1 pr_rounds=2 next=full /);
|
|
expect(ro.stdout).toContain('read-only final review (R51)');
|
|
expect(ro.stdout).not.toContain('for the owner');
|
|
expect(r.run('gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', '--prior-rounds', '2', '--prior-full', '2', '--pr', '5', '--round-grant', 'a-0123456789ab']).status).toBe(2);
|
|
expect(r.run('gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', '--prior-full', 'x']).status).toBe(2);
|
|
});
|
|
|
|
});
|
|
|
|
describe('round grants are gone (GST-3562 part 4)', () => {
|
|
test('round-grant is refused for every caller, and add refuses the scope', () => {
|
|
const r = repo();
|
|
expect(r.run('gstack-approvals', ['round-grant', '--pr', '5', '--head', r.head, '--kind', 'extra-round', '--reason', 'x', '--by', 'gstack']).status).toBe(2);
|
|
expect(r.run('gstack-approvals', ['round-grant', '--pr', '5', '--head', r.head, '--kind', 'more', '--reason', 'x', '--by', 'lane']).status).toBe(2);
|
|
expect(r.run('gstack-approvals', ['add', '--ask', 'a', '--words', 'w', '--by', 'b', '--scope', `review_round_grant ${r.head} pr=5 kind=extra-round`]).status).toBe(2);
|
|
});
|
|
});
|
|
|
|
// Value: protects=gstack's own names stay refused while a GStack-named crew rules; fails_when=rule refuses
|
|
// --by "GStack Minder (GSTA-36)" or takes gstack's own name; seam=bin/gstack-approvals rule|rulings, lib/approval-record.ts buildRow, lib/ruled-notes.ts
|
|
describe('GST-3246: GStack-named crews', () => {
|
|
test('rule takes --by "GStack Minder (GSTA-36)" and rulings lists it, while gstack\'s own names stay refused', () => {
|
|
const r = repo();
|
|
const rule = (by: string) => r.run('gstack-approvals', ['rule', '--finding', 'src/a.ts:1:correctness', '--head', r.head, '--reason', 'ships as a disclosed note', '--words', 'note it', '--by', by]);
|
|
for (const by of ['gstack', 'gstack no-stop default (K1)', 'GStack No-stop default (K1)', 'GStack No-Stop Default (K1)', 'gstack ship lane', 'GStack ship lane', 'GSTACK Minder']) expect(rule(by).status).toBe(2);
|
|
const ok = rule('GStack Minder (GSTA-36)');
|
|
expect([ok.status, ok.stderr]).toEqual([0, '']);
|
|
expect(r.run('gstack-approvals', ['rulings']).stdout).toContain('ruled by GStack Minder (GSTA-36) at ');
|
|
});
|
|
});
|
|
|
|
describe('gstack-ship-receipt history and stub', () => {
|
|
test('history prints the rounds, the flags Step 9 passes and the route; a stub counts until the run writes its receipt', () => {
|
|
const r = repo();
|
|
const loop = { passes: 1, blocking_found: 0, deferred: 0, rounds: 1 };
|
|
const body = path.join(r.dir, 'body.md');
|
|
fs.writeFileSync(body, '## Summary\nprose\n\n```gstack-ship-receipt\n' + JSON.stringify({ schema_version: 1, head: 'a'.repeat(40), run: 'r1', review_loop: loop }) + '\n```\n');
|
|
const h = r.run('gstack-ship-receipt', ['history', '--body', body, '--pr', '5']);
|
|
expect(h.status).toBe(0);
|
|
expect(h.stdout).toMatch(/^PR_REVIEW_HISTORY: pr=#5 rounds=1 cap=2 full=1 /m);
|
|
expect(h.stdout).toContain('PR_REVIEW_FLAGS: --prior-rounds 1 --prior-full 1\n');
|
|
expect(h.stdout).toMatch(/^PR_REVIEW_ROUTE: final \(the PR had 1 full review round; this head gets a fresh full review/m);
|
|
expect(h.stdout).not.toMatch(/drift|recheck_blocked/);
|
|
const s = r.run('gstack-ship-receipt', ['stub', '--body', body, '--run', 'r2', '--review-loop', JSON.stringify({ ...loop, fix_checks: 1, rounds: 2 })]);
|
|
expect(s.stdout).toContain('RUN_STUB: run=r2 status=started rounds=1');
|
|
const after = r.run('gstack-ship-receipt', ['history', '--body', body, '--pr', '5']).stdout;
|
|
expect(after).toContain('PR_REVIEW_FLAGS: --prior-rounds 2 --prior-full 2\n');
|
|
expect(after).toMatch(/^PR_REVIEW_ROUTE: read-only \(.*no fix round/m);
|
|
expect(fs.readFileSync(body, 'utf8').startsWith('## Summary\nprose\n')).toBe(true);
|
|
expect(r.run('gstack-ship-receipt', ['stub', '--body', body]).status).toBe(2);
|
|
});
|
|
|
|
test('an unreadable PR body prints source=unavailable and its fix', () => {
|
|
const r = repo();
|
|
const h = r.run('gstack-ship-receipt', ['history', '--body', path.join(r.dir, 'missing.md')]);
|
|
expect(h.status).toBe(1);
|
|
expect(h.stdout).toContain('source=unavailable');
|
|
expect(h.stderr).toContain('fix:');
|
|
});
|
|
});
|
|
|
|
describe('a scoped re-check is advice only (G1)', () => {
|
|
test('carry refuses --recheck: no re-check record carries a receipt', () => {
|
|
const r = repo();
|
|
const body = path.join(r.dir, 'body.md');
|
|
fs.writeFileSync(body, '## Summary\n');
|
|
const c = r.run('gstack-ship-receipt', ['carry', '--body', body, '--recheck', path.join(r.dir, 'r.json')]);
|
|
expect(c.status).toBe(3);
|
|
expect(c.stderr).toContain('--recheck is gone: a scoped re-check is advice only and never carries a receipt');
|
|
expect(fs.readFileSync(body, 'utf8')).toBe('## Summary\n');
|
|
});
|
|
});
|