mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 14:14:37 +01:00
train S1: merge #3852 at 61803d99bc v1.93.33.0
This commit is contained in:
commit
68bef52f1e
119 files changed
+3616
-493
No files matched your search
@@ -211,9 +211,9 @@ describe('content-binding template drift', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('greptile triage reads bodies through the guard (metadata/body split)', () => {
|
||||
test('review bot triage reads bodies through the guard (metadata/body split)', () => {
|
||||
const triage = rendered('review/greptile-triage.md');
|
||||
expect(triage).toContain('gstack-issue-guard --stdin --source greptile-line');
|
||||
expect(triage).toContain('gstack-issue-guard --stdin --source review-bot');
|
||||
expect(triage).toContain('gstack-issue-guard --stdin --source greptile-replies');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
* GST-774: a Capy machine checked out at a PR branch has refs/remotes/origin/HEAD naming that branch and
|
||||
* no local main. The default base must not be the checked-out branch (lib/default-base.ts, the GST-511
|
||||
* rule), and every base-relative step refuses a base that is HEAD or already contains it while the
|
||||
* branch has commits its real base lacks (BASE_CONTAINS_HEAD) instead of reporting no changes. The
|
||||
* control is a normal clone on the same feature branch with origin/HEAD naming main and a local main.
|
||||
*/
|
||||
import { afterAll, beforeAll, 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 { baseContainsHead, defaultBaseBranch } from '../lib/default-base';
|
||||
import { buildContext } from '../lib/pregate/context';
|
||||
import { runScriptSync } from '../lib/script-invocation';
|
||||
import { extractReceipt } from '../lib/ship-receipt';
|
||||
import { bindShippedReceipt } from '../lib/ship-receipt-depth';
|
||||
import { resolveBaseBranch } from '../lib/ship-policy';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const BIN = (name: string) => path.join(ROOT, 'bin', name);
|
||||
const big = Array.from({ length: 80 }, (_, i) => `exports.f${i} = () => ${i};`).join('\n') + '\n';
|
||||
|
||||
interface Fx { root: string; origin: string; clone: string; control: string; noMain: string; alias: string; trunk: string; develop: string; home: string; failGh: string; releaseGh: string; env: Record<string, string> }
|
||||
let fx: Fx;
|
||||
|
||||
function run(cmd: string, args: string[], cwd: string, env: Record<string, string> = fx.env) {
|
||||
const r = spawnSync(cmd, args, { cwd, encoding: 'utf8', timeout: 60_000, env: { ...process.env, ...env } });
|
||||
if (r.status !== 0) throw new Error(`${cmd} ${args.join(' ')} failed in ${cwd}: ${r.stderr}`);
|
||||
return (r.stdout ?? '').trim();
|
||||
}
|
||||
const git = (cwd: string, ...args: string[]) => run('git', args, cwd);
|
||||
function bin(name: string, args: string[], cwd: string, extra: Record<string, string> = {}) {
|
||||
const r = runScriptSync(BIN(name), args, { cwd, encoding: 'utf8', timeout: 120_000, maxBuffer: 64 * 1024 * 1024, env: { ...process.env, ...fx.env, ...extra } });
|
||||
return { status: r.status, out: r.stdout ?? '', err: r.stderr ?? '' };
|
||||
}
|
||||
function withEnv<T>(env: Record<string, string>, fn: () => T): T {
|
||||
const saved = Object.fromEntries(Object.keys(env).map(k => [k, process.env[k]]));
|
||||
Object.assign(process.env, env);
|
||||
try { return fn(); } finally { for (const [k, v] of Object.entries(saved)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } }
|
||||
}
|
||||
const stub = (dir: string, body: string) => { fs.mkdirSync(dir, { recursive: true }); fs.writeFileSync(path.join(dir, 'gh'), `#!/bin/sh\n${body}\n`, { mode: 0o755 }); return dir; };
|
||||
|
||||
beforeAll(() => {
|
||||
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gst774-')));
|
||||
expect(spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd: root, encoding: 'utf8', timeout: 10_000 }).status).not.toBe(0);
|
||||
const home = path.join(root, 'home');
|
||||
fs.mkdirSync(home);
|
||||
const gitconfig = path.join(root, 'gitconfig');
|
||||
fs.writeFileSync(gitconfig, '[user]\n\tname = fixture\n\temail = fixture@test\n[commit]\n\tgpgsign = false\n[init]\n\tdefaultBranch = main\n');
|
||||
const failGh = stub(path.join(root, 'gh-fail'), 'exit 1');
|
||||
const releaseGh = stub(path.join(root, 'gh-release'), 'echo release');
|
||||
const env = { HOME: home, GSTACK_STATE_ROOT: home, GSTACK_HOME: home, GIT_CONFIG_GLOBAL: gitconfig, GIT_CONFIG_NOSYSTEM: '1', PATH: `${failGh}${path.delimiter}${process.env.PATH}` };
|
||||
fx = { root, origin: path.join(root, 'origin.git'), clone: path.join(root, 'clone'), control: path.join(root, 'control'), noMain: path.join(root, 'nomain'), alias: path.join(root, 'alias'), trunk: path.join(root, 'trunk'), develop: path.join(root, 'develop'), home, failGh, releaseGh, env };
|
||||
const seed = path.join(root, 'seed');
|
||||
run('git', ['init', '-q', '--bare', '-b', 'main', fx.origin], root);
|
||||
run('git', ['init', '-q', '-b', 'main', seed], root);
|
||||
fs.mkdirSync(path.join(seed, 'lib'));
|
||||
fs.writeFileSync(path.join(seed, 'README.md'), '# fixture\n');
|
||||
fs.writeFileSync(path.join(seed, 'lib', 'app.js'), 'exports.app = () => 1;\n');
|
||||
git(seed, 'add', '-A');
|
||||
git(seed, 'commit', '-qm', 'seed');
|
||||
expect(git(seed, 'log', '-1', '--format=%an <%ae>')).toBe('fixture <fixture@test>');
|
||||
git(seed, 'remote', 'add', 'origin', fx.origin);
|
||||
git(seed, 'push', '-q', 'origin', 'main', 'main:release');
|
||||
git(seed, 'checkout', '-q', '-b', 'pr-branch');
|
||||
fs.writeFileSync(path.join(seed, 'lib', 'big.js'), big);
|
||||
git(seed, 'add', '-A');
|
||||
git(seed, 'commit', '-qm', 'pr change');
|
||||
git(seed, 'push', '-q', 'origin', 'pr-branch');
|
||||
|
||||
run('git', ['clone', '-q', '--branch', 'pr-branch', fx.origin, fx.clone], root);
|
||||
git(fx.clone, 'symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/pr-branch');
|
||||
run('git', ['clone', '-q', fx.origin, fx.control], root);
|
||||
git(fx.control, 'checkout', '-q', '-b', 'pr-branch', 'origin/pr-branch');
|
||||
|
||||
const nomainOrigin = path.join(root, 'nomain.git');
|
||||
run('git', ['clone', '-q', '--bare', fx.origin, nomainOrigin], root);
|
||||
git(nomainOrigin, 'branch', '-m', 'main', 'trunk');
|
||||
git(nomainOrigin, 'symbolic-ref', 'HEAD', 'refs/heads/trunk');
|
||||
run('git', ['clone', '-q', '--branch', 'pr-branch', nomainOrigin, fx.noMain], root);
|
||||
git(fx.noMain, 'symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/pr-branch');
|
||||
git(fx.noMain, 'remote', 'set-url', 'origin', path.join(root, 'offline.git'));
|
||||
run('git', ['clone', '-q', nomainOrigin, fx.trunk], root);
|
||||
|
||||
run('git', ['clone', '-q', fx.origin, fx.alias], root);
|
||||
git(fx.alias, 'checkout', '-q', '-b', 'work', '--track', 'origin/pr-branch');
|
||||
git(fx.alias, 'symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/pr-branch');
|
||||
|
||||
const developOrigin = path.join(root, 'develop.git');
|
||||
run('git', ['clone', '-q', '--bare', fx.origin, developOrigin], root);
|
||||
git(developOrigin, 'branch', 'develop', 'pr-branch');
|
||||
git(developOrigin, 'symbolic-ref', 'HEAD', 'refs/heads/develop');
|
||||
run('git', ['clone', '-q', developOrigin, fx.develop], root);
|
||||
});
|
||||
afterAll(() => { if (fx) fs.rmSync(fx.root, { recursive: true, force: true }); });
|
||||
|
||||
describe('the fixture is the reported checkout', () => {
|
||||
// Value: protects=every case below reads the GST-774 shape, outside any checkout and with its own state root; fails_when=the
|
||||
// clone has a local main or origin/HEAD names main, or state resolves into the operator's root; seam=none
|
||||
test('the clone is on the PR branch, origin/HEAD names it, there is no local main, and state resolves into the fixture', () => {
|
||||
expect(git(fx.clone, 'symbolic-ref', '--short', 'HEAD')).toBe('pr-branch');
|
||||
expect(git(fx.clone, 'symbolic-ref', 'refs/remotes/origin/HEAD')).toBe('refs/remotes/origin/pr-branch');
|
||||
expect(spawnSync('git', ['rev-parse', '--verify', '--quiet', 'refs/heads/main'], { cwd: fx.clone, timeout: 10_000 }).status).not.toBe(0);
|
||||
expect(git(fx.clone, 'rev-parse', 'origin/main')).toBe(git(fx.control, 'rev-parse', 'main'));
|
||||
expect(git(fx.control, 'symbolic-ref', 'refs/remotes/origin/HEAD')).toBe('refs/remotes/origin/main');
|
||||
expect(git(fx.clone, 'rev-parse', '--show-toplevel')).toBe(fx.clone);
|
||||
expect(bin('gstack-paths', ['--get', 'GSTACK_STATE_ROOT'], fx.clone).out.trim()).toBe(fx.home);
|
||||
const slug = bin('gstack-slug', ['--get', 'SLUG'], fx.clone);
|
||||
expect(slug.status).toBe(0);
|
||||
expect(slug.out.trim()).not.toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveBaseBranch skips an origin/HEAD that names the checked-out branch', () => {
|
||||
// Value: protects=ship-queue, pregate and the receipt writer default to the PR's real base, never the branch itself; fails_when=
|
||||
// origin/HEAD naming the PR branch is taken as the base; seam=lib/default-base.ts
|
||||
test('origin/main on the bug checkout, the PR base when gh names one, explicit --base as given; the control is unchanged', () => {
|
||||
withEnv(fx.env, () => {
|
||||
expect(resolveBaseBranch(fx.clone)).toBe('main');
|
||||
expect(resolveBaseBranch(fx.clone, 'pr-branch')).toBe('pr-branch');
|
||||
expect(resolveBaseBranch(fx.control)).toBe('main');
|
||||
git(fx.control, 'checkout', '-q', 'main');
|
||||
try { expect(resolveBaseBranch(fx.control)).toBe('main'); } finally { git(fx.control, 'checkout', '-q', 'pr-branch'); }
|
||||
});
|
||||
withEnv({ ...fx.env, PATH: `${fx.releaseGh}${path.delimiter}${process.env.PATH}` }, () => expect(resolveBaseBranch(fx.clone)).toBe('release'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('the review depth ship-queue ready binds', () => {
|
||||
// Value: protects=a READY on the bug checkout binds the 80-line diff's real depth inputs (light under R51, runtime_lines=80);
|
||||
// fails_when=the queue compares the PR head with itself and reports runtime_lines=0; seam=bindShippedReceipt
|
||||
test('origin/<PR branch> refuses BASE_CONTAINS_HEAD; the resolved default base binds runtime_lines=80; the control binds the same', () => {
|
||||
const body = path.join(fx.root, 'body.md');
|
||||
const w = bin('gstack-ship-receipt', ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body], fx.clone);
|
||||
expect(w.status, w.err).toBe(0);
|
||||
const text = fs.readFileSync(body, 'utf8');
|
||||
expect(extractReceipt(text).receipt!.review_depth).toMatchObject({ depth: 'light', runtime_lines: 80 });
|
||||
const head = git(fx.clone, 'rev-parse', 'HEAD');
|
||||
withEnv(fx.env, () => {
|
||||
const self = bindShippedReceipt(fx.clone, 'origin/pr-branch', text, '7', [head]);
|
||||
expect(self.ok).toBe(false);
|
||||
if (self.ok) return;
|
||||
expect(self.code as string).toBe('BASE_CONTAINS_HEAD');
|
||||
expect(self.message).toContain(head.slice(0, 12));
|
||||
const real = bindShippedReceipt(fx.clone, `origin/${resolveBaseBranch(fx.clone)}`, text, '7', [head]);
|
||||
expect(real.ok && real.depthLine).toContain('receipt=light required=light runtime_lines=80 class=code');
|
||||
const control = bindShippedReceipt(fx.control, `origin/${resolveBaseBranch(fx.control)}`, text, '7', [head]);
|
||||
expect(control.ok && control.depthLine).toContain('receipt=light required=light runtime_lines=80 class=code');
|
||||
});
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('gstack-review-plan', () => {
|
||||
// Value: protects=/ship's review plan never plans light for a diff it compared with itself; fails_when=--base <PR branch> plans
|
||||
// REVIEW_DEPTH light runtime_lines=0; seam=bin/gstack-review-plan
|
||||
test('--base <PR branch> refuses; --base main plans the same depth on the bug checkout and the control; main itself plans an empty diff', () => {
|
||||
const self = bin('gstack-review-plan', ['--base', 'pr-branch'], fx.clone);
|
||||
expect(self.status).toBe(1);
|
||||
expect(self.err).toContain('(BASE_CONTAINS_HEAD)');
|
||||
const depth = (out: string) => /^REVIEW_DEPTH: .*$/m.exec(out)?.[0];
|
||||
const real = bin('gstack-review-plan', ['--base', 'main'], fx.clone);
|
||||
expect(real.status, real.err).toBe(0);
|
||||
expect(depth(real.out)).toContain('REVIEW_DEPTH: light runtime_lines=80');
|
||||
const control = bin('gstack-review-plan', ['--base', 'main'], fx.control);
|
||||
expect(depth(control.out)).toBe(depth(real.out));
|
||||
git(fx.control, 'checkout', '-q', 'main');
|
||||
try {
|
||||
const onMain = bin('gstack-review-plan', ['--base', 'main'], fx.control);
|
||||
expect(onMain.status, onMain.err).toBe(0);
|
||||
expect(depth(onMain.out)).toContain('runtime_lines=0');
|
||||
} finally { git(fx.control, 'checkout', '-q', 'pr-branch'); }
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('the pregate base and the sealed policy base', () => {
|
||||
// Value: protects=the pregate selects the PR's files and reads the base branch's policy, never the PR branch's; fails_when=the
|
||||
// default base is the PR branch, so 0 files are touched and the policy is the PR's own; seam=buildContext, cmdSealed
|
||||
const load = (cwd: string, base: string) => buildContext({ repoRoot: cwd, base, policyFrom: 'base', allowRepoCommands: false, cores: 64, testBackend: 'local', env: { ...process.env, ...fx.env }, progress: () => {} });
|
||||
test('the default base is main with the PR file touched; an explicit PR-branch base refuses; the control and main itself are unchanged', () => {
|
||||
withEnv(fx.env, () => {
|
||||
const bug = load(fx.clone, resolveBaseBranch(fx.clone));
|
||||
expect('ctx' in bug && { base: bug.ctx.base, touched: bug.ctx.touched.map(t => t.path) }).toEqual({ base: 'main', touched: ['lib/big.js'] });
|
||||
const self = load(fx.clone, 'pr-branch');
|
||||
expect('refused' in self && (self.refused.code as string)).toBe('BASE_CONTAINS_HEAD');
|
||||
const control = load(fx.control, resolveBaseBranch(fx.control));
|
||||
expect('ctx' in control && { base: control.ctx.base, touched: control.ctx.touched.map(t => t.path) }).toEqual({ base: 'main', touched: ['lib/big.js'] });
|
||||
git(fx.control, 'checkout', '-q', 'main');
|
||||
try {
|
||||
const onMain = load(fx.control, resolveBaseBranch(fx.control));
|
||||
expect('ctx' in onMain && onMain.ctx.touched).toEqual([]);
|
||||
} finally { git(fx.control, 'checkout', '-q', 'pr-branch'); }
|
||||
});
|
||||
}, 120_000);
|
||||
|
||||
test('sealed reads the policy from origin/main by default and refuses an explicit PR-branch base', () => {
|
||||
const bug = bin('gstack-pregate', ['sealed'], fx.clone);
|
||||
expect(bug.status, bug.err).toBe(0);
|
||||
expect(bug.out).toContain('policy=no sealed key on refs/remotes/origin/main or HEAD');
|
||||
const self = bin('gstack-pregate', ['sealed', '--base', 'pr-branch'], fx.clone);
|
||||
expect(self.status).not.toBe(0);
|
||||
expect(self.err).toContain('(BASE_CONTAINS_HEAD)');
|
||||
const control = bin('gstack-pregate', ['sealed'], fx.control);
|
||||
expect(control.out).toBe(bug.out);
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('gstack-gate-diff and gstack-diff-scope defaults', () => {
|
||||
// Value: protects=the gate scan and the scope flags read the PR's diff on the bug checkout; fails_when=the default base is the
|
||||
// PR branch, so the scan lists nothing and every scope flag is false with exit 0; seam=lib/gate-diff/git.ts, bin/gstack-diff-scope
|
||||
test('gate-diff: the default diffs against origin/main like the control; the PR branch refuses; no resolvable default fails closed', () => {
|
||||
const summary = (out: string) => /^GATE_SUMMARY: .*$/m.exec(out)?.[0];
|
||||
const bug = bin('gstack-gate-diff', [], fx.clone);
|
||||
expect(bug.status, bug.out + bug.err).toBe(0);
|
||||
const control = bin('gstack-gate-diff', [], fx.control);
|
||||
expect(control.status, control.out + control.err).toBe(0);
|
||||
expect(summary(bug.out)).toBe(summary(control.out));
|
||||
expect(summary(bug.out)).toContain('unmatched=1');
|
||||
const self = bin('gstack-gate-diff', ['pr-branch'], fx.clone);
|
||||
expect(self.status).toBe(2);
|
||||
expect(self.out).toStartWith('GATE_ERROR=base_contains_head ref=pr-branch');
|
||||
const none = bin('gstack-gate-diff', [], fx.noMain);
|
||||
expect(none.status).toBe(2);
|
||||
expect(none.out).toStartWith('GATE_ERROR=no_base ref=origin/HEAD target=origin/pr-branch');
|
||||
}, 120_000);
|
||||
|
||||
test('diff-scope: the default reads the PR file like the control; the PR branch refuses; main and a fresh branch keep today\'s output', () => {
|
||||
const bug = bin('gstack-diff-scope', [], fx.clone);
|
||||
expect(bug.status, bug.out + bug.err).toBe(0);
|
||||
expect(bug.out).toContain('SCOPE_BACKEND=true');
|
||||
const control = bin('gstack-diff-scope', [], fx.control);
|
||||
expect(control.out).toBe(bug.out);
|
||||
const self = bin('gstack-diff-scope', ['pr-branch'], fx.clone);
|
||||
expect(self.status).toBe(2);
|
||||
expect(self.out).toContain('SCOPE_ERROR=base_contains_head');
|
||||
const none = bin('gstack-diff-scope', [], fx.noMain);
|
||||
expect(none.status).toBe(2);
|
||||
expect(none.out).toContain('SCOPE_ERROR=no_base');
|
||||
git(fx.control, 'checkout', '-q', 'main');
|
||||
try {
|
||||
const onMain = bin('gstack-diff-scope', [], fx.control);
|
||||
expect(onMain.status).toBe(0);
|
||||
expect(onMain.out).not.toContain('=true');
|
||||
git(fx.control, 'checkout', '-q', '-b', 'fresh');
|
||||
fs.writeFileSync(path.join(fx.control, 'lib', 'app.js'), 'exports.app = () => 2;\n');
|
||||
const fresh = bin('gstack-diff-scope', ['main'], fx.control);
|
||||
expect(fresh.status, fresh.out).toBe(0);
|
||||
expect(fresh.out).toContain('SCOPE_BACKEND=true');
|
||||
} finally { git(fx.control, 'checkout', '-q', '--', 'lib/app.js'); git(fx.control, 'checkout', '-q', 'pr-branch'); }
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('the docs-audit base', () => {
|
||||
// Value: protects=/ship's documentation audit selects the PR's files; fails_when=the snapshot's base is the PR head, so it
|
||||
// selects nothing and every later freshness check passes; seam=bin/gstack-docs-candidate snapshot
|
||||
test('snapshot refuses a base that is HEAD; the merge base with origin/main selects the PR file like the control', () => {
|
||||
const snap = (cwd: string, base: string, name: string) => bin('gstack-docs-candidate', ['snapshot', '--out', path.join(fx.root, `${name}.json`), '--audit-id', name, '--mode', 'read-only', '--base', base], cwd);
|
||||
const self = snap(fx.clone, git(fx.clone, 'rev-parse', 'origin/pr-branch'), 'self');
|
||||
expect(self.status).not.toBe(0);
|
||||
expect(self.err).toContain('(BASE_CONTAINS_HEAD)');
|
||||
const real = snap(fx.clone, git(fx.clone, 'merge-base', 'origin/main', 'HEAD'), 'real');
|
||||
expect(real.status, real.err).toBe(0);
|
||||
expect(real.out).toContain('committed: "lib/big.js"');
|
||||
const control = snap(fx.control, git(fx.control, 'merge-base', 'origin/main', 'HEAD'), 'control');
|
||||
expect(control.out.split('\n').slice(2).join('\n')).toBe(real.out.split('\n').slice(2).join('\n'));
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('baseContainsHead keeps today\'s result where the branch is not compared with itself', () => {
|
||||
// Value: protects=the guard refuses only a self-comparison and never the base branch, a detached checkout or a fresh branch;
|
||||
// fails_when=the refusal fires on main, on a CI-style detached HEAD or on a branch with only uncommitted work; seam=lib/default-base.ts
|
||||
test('null on main, detached at the PR head and on a fresh branch; a PR head the base contains refuses; no default resolves past a skipped origin/HEAD', () => {
|
||||
withEnv(fx.env, () => {
|
||||
const head = git(fx.clone, 'rev-parse', 'HEAD');
|
||||
expect(baseContainsHead(fx.clone, 'origin/pr-branch')).toContain('on pr-branch, whose commits origin/main lacks; the real base is main');
|
||||
expect(baseContainsHead(fx.clone, 'origin/main')).toBeNull();
|
||||
expect(baseContainsHead(fx.clone, 'origin/pr-branch', head)).toContain(`the head ${head.slice(0, 12)}`);
|
||||
expect(baseContainsHead(fx.clone, 'origin/main', head)).toBeNull();
|
||||
git(fx.clone, 'checkout', '-q', '--detach', head);
|
||||
try { expect(baseContainsHead(fx.clone, 'origin/pr-branch')).toBeNull(); } finally { git(fx.clone, 'checkout', '-q', 'pr-branch'); }
|
||||
git(fx.control, 'checkout', '-q', 'main');
|
||||
try {
|
||||
expect(baseContainsHead(fx.control, 'origin/main')).toBeNull();
|
||||
git(fx.control, 'checkout', '-q', '-b', 'fresh-2');
|
||||
expect(baseContainsHead(fx.control, 'origin/main')).toBeNull();
|
||||
expect(bin('gstack-review-plan', ['--base', 'main'], fx.control).status).toBe(0);
|
||||
} finally { git(fx.control, 'checkout', '-q', 'pr-branch'); }
|
||||
expect(defaultBaseBranch(fx.noMain)).toEqual({ branch: null, skipped: { remote: 'origin', branch: 'pr-branch' } });
|
||||
expect(defaultBaseBranch(fx.control)).toEqual({ branch: 'main', remote: 'origin' });
|
||||
});
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('a remote HEAD naming the branch under another name is skipped; a real default branch is kept', () => {
|
||||
// Value: protects=a local branch tracking the PR branch, one cut from its tip, and a detached checkout of it never take the PR
|
||||
// branch as their base, while a repository whose default is develop or trunk keeps it; fails_when=the skip compares names only,
|
||||
// so a differently named checkout reads the PR against itself (an empty diff with exit 0), or the skip falls through to a
|
||||
// stale main or to no base on the default branch itself; why_new=the outside voice and the adversarial pass reproduced both;
|
||||
// seam=lib/default-base.ts
|
||||
test('upstream, same commit and detached checkouts resolve main; develop and trunk resolve from the remote\'s live HEAD', () => {
|
||||
withEnv(fx.env, () => {
|
||||
expect(defaultBaseBranch(fx.alias).branch).toBe('main');
|
||||
expect(baseContainsHead(fx.alias, 'origin/pr-branch')).toContain('on work, whose commits origin/main lacks; the real base is main');
|
||||
const aliased = bin('gstack-diff-scope', [], fx.alias);
|
||||
expect(aliased.status, aliased.out).toBe(0);
|
||||
expect(aliased.out).toContain('SCOPE_BACKEND=true');
|
||||
git(fx.alias, 'checkout', '-q', '--no-track', '-b', 'work-2', 'origin/pr-branch');
|
||||
try { expect(defaultBaseBranch(fx.alias).branch).toBe('main'); } finally { git(fx.alias, 'checkout', '-q', 'work'); }
|
||||
git(fx.alias, 'checkout', '-q', '--detach', 'origin/pr-branch');
|
||||
try { expect(defaultBaseBranch(fx.alias).branch).toBe('main'); } finally { git(fx.alias, 'checkout', '-q', 'work'); }
|
||||
expect(defaultBaseBranch(fx.trunk)).toEqual({ branch: 'trunk', remote: 'origin', skipped: { remote: 'origin', branch: 'trunk' } });
|
||||
expect(defaultBaseBranch(fx.develop).branch).toBe('develop');
|
||||
for (const cwd of [fx.trunk, fx.develop]) {
|
||||
const onDefault = bin('gstack-diff-scope', [], cwd);
|
||||
expect(onDefault.status, onDefault.out).toBe(0);
|
||||
expect(onDefault.out).not.toContain('=true');
|
||||
}
|
||||
});
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { DEFENSIVE_REVIEW_FRAMING, FIXTURE_SUMMARY_MODE } from '../scripts/resolvers/defensive-review';
|
||||
import { DEFENSIVE_REVIEW_FRAMING, FIXTURE_SUMMARY_MODE, fixtureSummaryMode } from '../scripts/resolvers/defensive-review';
|
||||
import { generateReviewArmy } from '../scripts/resolvers/review-army';
|
||||
import { HOST_PATHS } from '../scripts/resolvers/types';
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('defensive-security framing reaches every adversarial dispatch', () =>
|
||||
test(`${skill}: adversarial subagent keeps the framing and fixture summary mode`, () => {
|
||||
const prompt = between(adversarial, 'Subagent prompt:', 'Think like an attacker');
|
||||
expect(prompt).toContain(DEFENSIVE_REVIEW_FRAMING);
|
||||
expect(prompt).toContain(FIXTURE_SUMMARY_MODE);
|
||||
expect(prompt).toContain(fixtureSummaryMode(skill === 'ship'));
|
||||
});
|
||||
|
||||
test(`${skill}: Red Team prompt starts from the framing and fixture summary mode`, () => {
|
||||
@@ -41,7 +41,7 @@ describe('defensive-security framing reaches every adversarial dispatch', () =>
|
||||
const dispatch = between(army, '### Dispatch specialists in parallel', '**Subagent configuration:**');
|
||||
const securityOnly = between(dispatch, '4. **Defensive framing (Security specialist and the Red Team below only).**', 'Instructions:');
|
||||
expect(securityOnly).toContain(DEFENSIVE_REVIEW_FRAMING);
|
||||
expect(securityOnly).toContain(FIXTURE_SUMMARY_MODE);
|
||||
expect(securityOnly).toContain(fixtureSummaryMode(skill === 'ship'));
|
||||
expect(securityOnly).toContain('including Testing, reads the full diff with fixtures');
|
||||
const sharedInstructions = dispatch.slice(dispatch.indexOf('Instructions:'));
|
||||
expect(sharedInstructions).not.toContain(FRAMING_SENTENCE);
|
||||
|
||||
@@ -67,6 +67,66 @@ afterAll(() => {
|
||||
describe('gstack-diff-scope', () => {
|
||||
// --- Existing scope signals ---
|
||||
|
||||
// Value: protects=a stale local base branch does not stand in for the base: a docs-only branch that merged a newer
|
||||
// origin/main is docs, not the backend change origin/main already has (GST-462, GBRA-218); fails_when=the script
|
||||
// diffs against the local branch whenever it resolves (with the name given, or the default it detects); seam=a
|
||||
// tracking ref moved with update-ref, as a fetch would; no_claim=nothing about remotes other than origin.
|
||||
test('a stale local main yields to origin/main, named or defaulted; a tag, a qualified ref or a pinned sha is never redirected', () => {
|
||||
const dir = createRepo([]);
|
||||
const git = (...a: string[]) => spawnSync('git', a, { cwd: dir, stdio: 'pipe', timeout: 5000 });
|
||||
git('checkout', '-q', 'main');
|
||||
mkdirSync(join(dir, 'lib'), { recursive: true });
|
||||
writeFileSync(join(dir, 'lib', 'server.ts'), 'export const port = 1;\n');
|
||||
git('add', '.'); git('commit', '-qm', 'upstream backend');
|
||||
git('update-ref', 'refs/remotes/origin/main', 'HEAD');
|
||||
git('reset', '-q', '--hard', 'HEAD~1');
|
||||
git('checkout', '-q', '-b', 'topic', 'origin/main');
|
||||
mkdirSync(join(dir, 'docs'), { recursive: true });
|
||||
writeFileSync(join(dir, 'docs', 'howto.md'), '# How to\n');
|
||||
git('add', '.'); git('commit', '-qm', 'docs');
|
||||
for (const args of [['main'], []]) {
|
||||
const out = spawnSync(SCRIPT, args, { cwd: dir, stdio: 'pipe', timeout: 5000 }).stdout.toString();
|
||||
expect(out).toContain('SCOPE_DOCS=true');
|
||||
expect(out).toContain('SCOPE_BACKEND=false');
|
||||
}
|
||||
const scopeOf = (args: string[]) => spawnSync(SCRIPT, args, { cwd: dir, stdio: 'pipe', timeout: 5000 }).stdout.toString();
|
||||
git('tag', 'origin/main', 'HEAD');
|
||||
expect(scopeOf(['main'])).toContain('SCOPE_DOCS=true');
|
||||
git('tag', '-d', 'origin/main');
|
||||
git('update-ref', 'refs/remotes/origin/origin/main', 'HEAD');
|
||||
expect(scopeOf(['origin/main'])).toContain('SCOPE_DOCS=true');
|
||||
git('tag', 'origin/main', 'HEAD');
|
||||
expect(scopeOf(['origin/main'])).toContain('SCOPE_DOCS=true');
|
||||
git('tag', '-d', 'origin/main');
|
||||
const pinned = git('rev-parse', 'origin/main').stdout.toString().trim();
|
||||
git('update-ref', `refs/remotes/origin/${pinned}`, 'HEAD');
|
||||
expect(scopeOf([pinned])).toContain('SCOPE_DOCS=true');
|
||||
git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/main');
|
||||
expect(spawnSync(SCRIPT, ['HEAD'], { cwd: dir, stdio: 'pipe', timeout: 5000 }).stdout.toString()).toContain('SCOPE_DOCS=false');
|
||||
git('update-ref', 'refs/remotes/origin/main', git('commit-tree', git('rev-parse', 'HEAD^{tree}').stdout.toString().trim(), '-m', 'unrelated').stdout.toString().trim());
|
||||
const unrelated = spawnSync(SCRIPT, ['main'], { cwd: dir, stdio: 'pipe', timeout: 5000 }).stdout.toString();
|
||||
expect(unrelated).toContain('SCOPE_BACKEND=true');
|
||||
});
|
||||
|
||||
// Value: protects=diff-scope reads the base gstack-review-plan's path list reads (origin/<base>), so a test file a local
|
||||
// main carries but origin lacks counts when the branch includes it; fails_when=a related local main ahead of origin/main
|
||||
// stays the base (fix-check, pass 2: SCOPE_TESTS=false beside a path list naming the test); seam=a tracking ref set with
|
||||
// update-ref; no_claim=remotes other than origin
|
||||
test('a local main ahead of origin/main yields to it, so its unpushed test file is in scope', () => {
|
||||
const dir = createRepo([]);
|
||||
const git = (...a: string[]) => spawnSync('git', a, { cwd: dir, stdio: 'pipe', timeout: 5000 });
|
||||
git('checkout', '-q', 'main');
|
||||
git('update-ref', 'refs/remotes/origin/main', 'HEAD');
|
||||
mkdirSync(join(dir, 'test'), { recursive: true });
|
||||
writeFileSync(join(dir, 'test', 'a.test.ts'), "test.skip('b', () => {});\n");
|
||||
git('add', '.'); git('commit', '-qm', 'unpushed test');
|
||||
git('checkout', '-q', '-b', 'topic', 'main');
|
||||
mkdirSync(join(dir, 'docs'), { recursive: true });
|
||||
writeFileSync(join(dir, 'docs', 'x.md'), '# x\n');
|
||||
git('add', '.'); git('commit', '-qm', 'docs');
|
||||
expect(spawnSync(SCRIPT, ['main'], { cwd: dir, stdio: 'pipe', timeout: 5000 }).stdout.toString()).toContain('SCOPE_TESTS=true');
|
||||
});
|
||||
|
||||
test('detects frontend files', () => {
|
||||
const dir = createRepo(['styles.css', 'component.tsx']);
|
||||
const scope = runScope(dir);
|
||||
|
||||
@@ -159,6 +159,8 @@ const SCANNER_EXEMPT: Record<string, string> = {
|
||||
'git fetch appears only in an error-message string',
|
||||
'bin/gstack-worktree-audit':
|
||||
'read-only audit: best-effort fetch of the user\'s own repo\'s base branch so the MERGED column is current (skipped with --no-fetch) — a user-repo dev-workflow op like gstack-next-version\'s, not gstack-state egress',
|
||||
'lib/default-base.ts':
|
||||
'read-only `git ls-remote --symref <remote> HEAD` of the user\'s own repo (5 s timeout, prompts off) to learn its live default branch, run only when the cached origin/HEAD names the checked-out branch (GST-774) — a user-repo dev-workflow op like gstack-next-version\'s, not gstack-state egress',
|
||||
'bin/gstack-state-matrix':
|
||||
'git fetch appears only in an error-message string (the fix the user runs when origin/<base> has no merge base)',
|
||||
'bin/gstack-redact-prepush':
|
||||
|
||||
@@ -329,6 +329,7 @@ describe('parity with the measured prototype', () => {
|
||||
'lib/bun-isolation.ts': 'GSTA-56: every bun launcher (script-invocation, restamp, qa-deadline, the hooks) imports it, so it reaches every consumer of those launchers',
|
||||
'lib/ship-receipt-docs.ts': 'bin/gstack-ship-receipt imports it (the docs audit record and doc caps), so it reaches every consumer of the receipt binary',
|
||||
'lib/ship-receipt-prose.ts': 'bin/gstack-ship-receipt imports it (read --check-prose), so it reaches every consumer of the receipt binary',
|
||||
'lib/default-base.ts': 'GST-511/GST-774: lib/ship-policy.ts (resolveBaseBranch), lib/gate-diff/git.ts, lib/pregate/context.ts, lib/ship-receipt-depth.ts and the review-plan, gate-diff, pregate, docs-candidate and diff-scope bins import or run it, so it reaches every consumer of those readers',
|
||||
};
|
||||
|
||||
test('the shipped map equals or is a reviewed superset of the prototype map on this checkout', () => {
|
||||
|
||||
+2
-2
@@ -256,7 +256,7 @@ sections. Read a section in full before doing its step; do not work from memory.
|
||||
| the pre-landing review and specialist dispatch (Step 9) | `sections/review-army.md` |
|
||||
| exploratory QA before Fix-First (Step 9.2.1) | Use the QA Read directive in `sections/review-army.md` |
|
||||
| reusing explicitly skipped shared-code advice (Step 9.3) | `sections/shared-code-reuse.md` |
|
||||
| addressing Greptile review comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| addressing review bot comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| the adversarial review and learnings capture (Step 11) | `sections/adversarial.md` |
|
||||
| writing the CHANGELOG entry (Step 13) | `sections/changelog.md` |
|
||||
| auditing docs before final commit/verification (Step 14.5), on every ship | `sections/documentation.md` |
|
||||
@@ -485,7 +485,7 @@ repeat Step 2 (decisions included) on the merged content, then Step 4.
|
||||
> **STOP.** Before the pre-landing review and specialist dispatch (Step 9), Read `sections/review-army.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before addressing Greptile review comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> **STOP.** Before addressing review bot comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before the adversarial review and learnings capture (Step 11), Read `sections/adversarial.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
|
||||
+2
-2
@@ -255,7 +255,7 @@ sections. Read a section in full before doing its step; do not work from memory.
|
||||
| the pre-landing review and specialist dispatch (Step 9) | `sections/review-army.md` |
|
||||
| exploratory QA before Fix-First (Step 9.2.1) | Use the QA Read directive in `sections/review-army.md` |
|
||||
| reusing explicitly skipped shared-code advice (Step 9.3) | `sections/shared-code-reuse.md` |
|
||||
| addressing Greptile review comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| addressing review bot comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| the adversarial review and learnings capture (Step 11) | `sections/adversarial.md` |
|
||||
| writing the CHANGELOG entry (Step 13) | `sections/changelog.md` |
|
||||
| auditing docs before final commit/verification (Step 14.5), on every ship | `sections/documentation.md` |
|
||||
@@ -484,7 +484,7 @@ repeat Step 2 (decisions included) on the merged content, then Step 4.
|
||||
> **STOP.** Before the pre-landing review and specialist dispatch (Step 9), Read `~/.claude/skills/gstack/ship/sections/review-army.md` and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before addressing Greptile review comments when a PR exists (Step 10), Read `~/.claude/skills/gstack/ship/sections/greptile.md` and execute it
|
||||
> **STOP.** Before addressing review bot comments when a PR exists (Step 10), Read `~/.claude/skills/gstack/ship/sections/greptile.md` and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before the adversarial review and learnings capture (Step 11), Read `~/.claude/skills/gstack/ship/sections/adversarial.md` and execute it
|
||||
|
||||
+2
-2
@@ -254,7 +254,7 @@ sections. Read a section in full before doing its step; do not work from memory.
|
||||
| the pre-landing review and specialist dispatch (Step 9) | `sections/review-army.md` |
|
||||
| exploratory QA before Fix-First (Step 9.2.1) | Use the QA Read directive in `sections/review-army.md` |
|
||||
| reusing explicitly skipped shared-code advice (Step 9.3) | `sections/shared-code-reuse.md` |
|
||||
| addressing Greptile review comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| addressing review bot comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| the adversarial review and learnings capture (Step 11) | `sections/adversarial.md` |
|
||||
| writing the CHANGELOG entry (Step 13) | `sections/changelog.md` |
|
||||
| auditing docs before final commit/verification (Step 14.5), on every ship | `sections/documentation.md` |
|
||||
@@ -484,7 +484,7 @@ repeat Step 2 (decisions included) on the merged content, then Step 4.
|
||||
> **STOP.** Before the pre-landing review and specialist dispatch (Step 9), Read `sections/review-army.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before addressing Greptile review comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> **STOP.** Before addressing review bot comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before the adversarial review and learnings capture (Step 11), Read `sections/adversarial.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
|
||||
+2
-2
@@ -256,7 +256,7 @@ sections. Read a section in full before doing its step; do not work from memory.
|
||||
| the pre-landing review and specialist dispatch (Step 9) | `sections/review-army.md` |
|
||||
| exploratory QA before Fix-First (Step 9.2.1) | Use the QA Read directive in `sections/review-army.md` |
|
||||
| reusing explicitly skipped shared-code advice (Step 9.3) | `sections/shared-code-reuse.md` |
|
||||
| addressing Greptile review comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| addressing review bot comments when a PR exists (Step 10) | `sections/greptile.md` |
|
||||
| the adversarial review and learnings capture (Step 11) | `sections/adversarial.md` |
|
||||
| writing the CHANGELOG entry (Step 13) | `sections/changelog.md` |
|
||||
| auditing docs before final commit/verification (Step 14.5), on every ship | `sections/documentation.md` |
|
||||
@@ -486,7 +486,7 @@ repeat Step 2 (decisions included) on the merged content, then Step 4.
|
||||
> **STOP.** Before the pre-landing review and specialist dispatch (Step 9), Read `sections/review-army.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before addressing Greptile review comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> **STOP.** Before addressing review bot comments when a PR exists (Step 10), Read `sections/greptile.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
> in full. Do not work from memory — that section is the source of truth for this step.
|
||||
|
||||
> **STOP.** Before the adversarial review and learnings capture (Step 11), Read `sections/adversarial.md` relative to the installed `gstack-ship` SKILL.md directory and execute it
|
||||
|
||||
+9
-9
@@ -6,52 +6,52 @@
|
||||
"agy/gstack-plan-design-review": 109107,
|
||||
"agy/gstack-plan-devex-review": 114948,
|
||||
"agy/gstack-plan-eng-review": 143581,
|
||||
"agy/gstack-review": 104267,
|
||||
"agy/gstack-review": 104182,
|
||||
"codex/gstack-autoplan": 108400,
|
||||
"codex/gstack-plan-design-review": 110464,
|
||||
"codex/gstack-plan-devex-review": 116456,
|
||||
"codex/gstack-plan-eng-review": 144746,
|
||||
"codex/gstack-review": 103790,
|
||||
"codex/gstack-review": 103705,
|
||||
"copilot/gstack-autoplan": 109100,
|
||||
"copilot/gstack-plan-design-review": 109373,
|
||||
"copilot/gstack-plan-devex-review": 114410,
|
||||
"copilot/gstack-plan-eng-review": 143746,
|
||||
"copilot/gstack-review": 103848,
|
||||
"copilot/gstack-review": 103763,
|
||||
"cursor/gstack-autoplan": 108332,
|
||||
"cursor/gstack-plan-design-review": 107915,
|
||||
"cursor/gstack-plan-devex-review": 113680,
|
||||
"cursor/gstack-plan-eng-review": 142336,
|
||||
"cursor/gstack-review": 122138,
|
||||
"cursor/gstack-review": 122053,
|
||||
"factory/gstack-autoplan": 110610,
|
||||
"factory/gstack-plan-design-review": 111013,
|
||||
"factory/gstack-plan-devex-review": 117043,
|
||||
"factory/gstack-plan-eng-review": 145444,
|
||||
"factory/gstack-review": 125911,
|
||||
"factory/gstack-review": 125826,
|
||||
"gbrain/gstack-autoplan": 108739,
|
||||
"gbrain/gstack-plan-eng-review": 124963,
|
||||
"gemini/gstack-autoplan": 108890,
|
||||
"gemini/gstack-plan-design-review": 109201,
|
||||
"gemini/gstack-plan-devex-review": 114238,
|
||||
"gemini/gstack-plan-eng-review": 143579,
|
||||
"gemini/gstack-review": 103670,
|
||||
"gemini/gstack-review": 103585,
|
||||
"hermes/gstack-autoplan": 108742,
|
||||
"hermes/gstack-plan-eng-review": 124999,
|
||||
"kiro/gstack-autoplan": 108106,
|
||||
"kiro/gstack-plan-design-review": 107761,
|
||||
"kiro/gstack-plan-devex-review": 113532,
|
||||
"kiro/gstack-plan-eng-review": 142198,
|
||||
"kiro/gstack-review": 121962,
|
||||
"kiro/gstack-review": 121877,
|
||||
"openclaw/gstack-autoplan": 108562,
|
||||
"openclaw/gstack-plan-eng-review": 123478,
|
||||
"opencode/gstack-autoplan": 109081,
|
||||
"opencode/gstack-plan-design-review": 109229,
|
||||
"opencode/gstack-plan-devex-review": 114288,
|
||||
"opencode/gstack-plan-eng-review": 143605,
|
||||
"opencode/gstack-review": 122760,
|
||||
"opencode/gstack-review": 122675,
|
||||
"slate/gstack-autoplan": 108219,
|
||||
"slate/gstack-plan-design-review": 107838,
|
||||
"slate/gstack-plan-devex-review": 113606,
|
||||
"slate/gstack-plan-eng-review": 142267,
|
||||
"slate/gstack-review": 122050
|
||||
"slate/gstack-review": 121965
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -65,7 +65,7 @@
|
||||
"## Step 1: Check branch",
|
||||
"## Step 1.5: Scope Drift Detection",
|
||||
"## Step 2: Read the checklist",
|
||||
"## Step 2.5: Check for Greptile review comments",
|
||||
"## Step 2.5: Check for review bot comments",
|
||||
"## Step 3: Get the diff",
|
||||
"## Step 3.4: Workspace-aware queue status (advisory)",
|
||||
"## Step 3.5: Diff scans",
|
||||
@@ -132,7 +132,7 @@
|
||||
"## Step 6.5: Early Greptile PR (after the free tests pass)"
|
||||
],
|
||||
"sections/greptile.md": [
|
||||
"## Step 10: Address Greptile review comments (if PR exists)"
|
||||
"## Step 10: Address review bot comments (if PR exists)"
|
||||
],
|
||||
"sections/plan-completion.md": [
|
||||
"## Step 8: Plan Completion Audit",
|
||||
|
||||
@@ -149,6 +149,94 @@ describe('gstack-gate-diff arguments and exit contract', () => {
|
||||
expect(odd.stdout.trim()).toBe("GATE_ERROR=no_base ref=rel;echo pwned fix=git fetch origin '+rel;echo pwned:refs/remotes/origin/rel;echo pwned'");
|
||||
});
|
||||
|
||||
// Value: protects=a local base branch that is related to HEAD but behind its remote-tracking twin yields to the twin, so
|
||||
// commits the base already has (merged into the branch from origin) do not count as the branch's change (GST-462,
|
||||
// GBRA-218); fails_when=resolveBase returns the local ref whenever it resolves and shares history with HEAD; seam=a
|
||||
// tracking ref moved with update-ref, as a fetch would; no_claim=nothing about remotes other than origin.
|
||||
test('a local main behind, ahead of or diverged from origin/main yields to it and says so; beside an unrelated origin/main it stays the base', () => {
|
||||
const src = repo({ fixture: 'rh1-skip', commit: true });
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-gate-diff-behind-'));
|
||||
repos.push(dir);
|
||||
gitIn(dir, ['clone', '-q', `file://${src}`, '.']);
|
||||
gitIn(dir, ['checkout', '-q', 'main']);
|
||||
gitIn(dir, ['update-ref', 'refs/remotes/origin/main', 'refs/remotes/origin/feature']);
|
||||
gitIn(dir, ['checkout', '-q', '-b', 'topic', 'origin/main']);
|
||||
fs.writeFileSync(path.join(dir, 'NOTES.md'), 'topic note\n');
|
||||
gitIn(dir, ['add', 'NOTES.md']);
|
||||
gitIn(dir, ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'topic']);
|
||||
expect(spawnSync('git', ['merge-base', '--is-ancestor', 'main', 'origin/main'], { cwd: dir, timeout: 30_000 }).status).toBe(0);
|
||||
|
||||
const r = run(dir, ['main']);
|
||||
expect(r.status).toBe(0);
|
||||
expect(summary(r.stdout).tagged).toBe('');
|
||||
expect(r.stderr).toContain('gstack-gate-diff: local main is behind origin/main; base is origin/main');
|
||||
gitIn(dir, ['update-ref', 'refs/heads/main', 'refs/remotes/origin/main']);
|
||||
const current = run(dir, ['main']);
|
||||
expect(summary(current.stdout).tagged).toBe('');
|
||||
expect(current.stderr).not.toContain('base is origin/main');
|
||||
const commitOn = (ref: string, name: string) => {
|
||||
const tree = gitIn(dir, ['rev-parse', `${ref}^{tree}`]).trim();
|
||||
const sha = gitIn(dir, ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit-tree', tree, '-p', ref, '-m', name]).trim();
|
||||
gitIn(dir, ['update-ref', ref, sha]);
|
||||
};
|
||||
commitOn('refs/heads/main', 'unpushed');
|
||||
const ahead = run(dir, ['main']);
|
||||
expect(ahead.status).toBe(0);
|
||||
expect(ahead.stderr).toContain('gstack-gate-diff: local main is ahead of origin/main; base is origin/main');
|
||||
commitOn('refs/remotes/origin/main', 'upstream moved');
|
||||
const diverged = run(dir, ['main']);
|
||||
expect(diverged.status).toBe(0);
|
||||
expect(diverged.stderr).toContain('gstack-gate-diff: local main has diverged from origin/main; base is origin/main');
|
||||
const orphan = gitIn(dir, ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit-tree', gitIn(dir, ['rev-parse', 'HEAD^{tree}']).trim(), '-m', 'unrelated']).trim();
|
||||
gitIn(dir, ['update-ref', 'refs/remotes/origin/main', orphan]);
|
||||
const unrelated = run(dir, ['main']);
|
||||
expect(unrelated.status).toBe(0);
|
||||
expect(summary(unrelated.stdout).tagged).toBe('');
|
||||
expect(unrelated.stderr).not.toContain('base is origin/main');
|
||||
});
|
||||
|
||||
// Value: protects=the gate scan reads the same base as gstack-review-plan's path list (origin/<base>), so commits a local
|
||||
// main carries but origin lacks are scanned when the branch includes them; fails_when=a related local main that is ahead
|
||||
// of origin/main stays the base (fix-check, pass 2: an unpushed test.skip listed in paths, gate_tagged=0); seam=a local
|
||||
// branch moved with update-ref; no_claim=a fork whose origin is not the PR's base repository (ship preflight's prSized)
|
||||
test('a local main ahead of origin/main yields to it, so its unpushed test.skip is scanned', () => {
|
||||
const src = repo({ fixture: 'rh1-skip', commit: true });
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-gate-diff-ahead-'));
|
||||
repos.push(dir);
|
||||
gitIn(dir, ['clone', '-q', `file://${src}`, '.']);
|
||||
gitIn(dir, ['branch', '-q', '--no-track', 'main', 'origin/feature']);
|
||||
gitIn(dir, ['checkout', '-q', '-b', 'topic', 'main']);
|
||||
fs.writeFileSync(path.join(dir, 'NOTES.md'), 'topic note\n');
|
||||
gitIn(dir, ['add', 'NOTES.md']);
|
||||
gitIn(dir, ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'topic']);
|
||||
const r = run(dir, ['main']);
|
||||
expect(r.status).toBe(0);
|
||||
expect(summary(r.stdout).tagged).toBe('RH-1:1');
|
||||
expect(r.stderr).toContain('gstack-gate-diff: local main is ahead of origin/main; base is origin/main');
|
||||
});
|
||||
|
||||
// Value: protects=the base cannot be redirected to the candidate by a ref the contributor controls: a tag named
|
||||
// origin/main, or a fetched branch named origin/main (refs/remotes/origin/origin/main), never replaces origin's tracking
|
||||
// branch, and an explicit origin/main is never re-qualified; fails_when=resolveBase resolves the twin by its short name or
|
||||
// tries a twin for a remote-qualified ref (outside voice, pass 2: both emptied the gate scan of a test.skip); seam=refs a
|
||||
// fetch would create; no_claim=a tag shadowing a local branch name, which predates this change
|
||||
test('a tag or a fetched branch named origin/main cannot empty the gate scan, named bare, qualified or defaulted', () => {
|
||||
const src = repo({ fixture: 'rh1-skip', commit: true });
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-gate-diff-shadow-'));
|
||||
repos.push(dir);
|
||||
gitIn(dir, ['clone', '-q', `file://${src}`, '.']);
|
||||
gitIn(dir, ['checkout', '-q', '-b', 'topic', 'origin/feature']);
|
||||
expect(gitIn(dir, ['branch', '--list', 'main']).trim()).toBe('');
|
||||
gitIn(dir, ['tag', 'origin/main', 'HEAD']);
|
||||
expect(summary(run(dir, ['main']).stdout).tagged).toBe('RH-1:1');
|
||||
expect(summary(run(dir, ['origin/main']).stdout).tagged).toBe('RH-1:1');
|
||||
gitIn(dir, ['symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/main']);
|
||||
expect(summary(run(dir, []).stdout).tagged).toBe('RH-1:1');
|
||||
gitIn(dir, ['tag', '-d', 'origin/main']);
|
||||
gitIn(dir, ['update-ref', 'refs/remotes/origin/origin/main', 'HEAD']);
|
||||
expect(summary(run(dir, ['origin/main']).stdout).tagged).toBe('RH-1:1');
|
||||
});
|
||||
|
||||
// Value: protects=a clone whose only remote is not called origin resolves the base through that remote and the fix line
|
||||
// fetches from it; fails_when=remoteNames or resolveBase hard-code origin, or noBaseFix falls back to the literal 'origin'
|
||||
// while a real remote exists; why_new=every existing fixture has either an origin remote or none; seam=none;
|
||||
@@ -176,7 +264,7 @@ describe('gstack-gate-diff arguments and exit contract', () => {
|
||||
expect([bare.status, remote.status]).toEqual([0, 0]);
|
||||
expect(summary(bare.stdout).candidate).toBe(summary(remote.stdout).candidate);
|
||||
expect(bare.stdout).toBe(remote.stdout);
|
||||
expect(bare.stderr).toContain('gstack-gate-diff: local main is not origin/main; base is origin/main');
|
||||
expect(bare.stderr).toContain('gstack-gate-diff: local main is behind origin/main; base is origin/main');
|
||||
});
|
||||
|
||||
// Value: protects=a ref a contributor controls (a fork's origin/upstream/main branch, a tag named origin/main, another
|
||||
|
||||
@@ -171,9 +171,9 @@ describe('Greptile replies through the real review/greptile-triage.md blocks', (
|
||||
expect(createBlock).toBe(freeTextFileBash([{ variable: 'REPLY_FILE', stem: 'reply' }]));
|
||||
});
|
||||
|
||||
test('the fetched JSON goes to a mktemp directory, not fixed /tmp paths', () => {
|
||||
test('the fetched JSON goes to the helper\'s private directory, not fixed /tmp paths', () => {
|
||||
expect(doc).not.toMatch(/\/tmp\/greptile_/);
|
||||
expect(fence(doc, 'GREPTILE_DIR=$(mktemp -d')).toContain('"$GREPTILE_DIR/line.json"');
|
||||
expect(fence(doc, 'gstack-review-bots fetch')).toContain('~/.claude/skills/gstack/bin/gstack-review-bots fetch');
|
||||
});
|
||||
|
||||
for (const [kind, block, args] of [['line-level', lineBlock, ['api', '--method=POST', 'repos/{owner}/{repo}/pulls/7/comments/123/replies', '--field=body=@-']], ['top-level', topBlock, ['pr', 'comment', '7', '--body-file=-']]] as const) {
|
||||
|
||||
@@ -21,7 +21,7 @@ interface Call { cmd: string; args: string[]; file?: string }
|
||||
function fixture(opts: {
|
||||
files?: Record<string, string>;
|
||||
visibility?: string;
|
||||
comments?: Array<{ login: string; created: string }>;
|
||||
comments?: Array<{ login: string; type?: string; created: string }>;
|
||||
openPrs?: Array<{ number: number; url: string }>;
|
||||
checks?: Array<{ name: string; status: string; app: string }>;
|
||||
reviews?: Array<{ login: string; commit: string }>;
|
||||
@@ -103,14 +103,26 @@ describe("detection (CEO-8, DX-10)", () => {
|
||||
});
|
||||
|
||||
test("a Greptile comment counts only within 90 days", () => {
|
||||
const recent = fixture({ comments: [{ login: "greptile-apps[bot]", created: new Date(NOW - 10 * DAY).toISOString() }] });
|
||||
const recent = fixture({ comments: [{ login: "greptile-apps[bot]", type: "Bot", created: new Date(NOW - 10 * DAY).toISOString() }] });
|
||||
expect(value(recent.run("detect").out, "GREPTILE_SIGNAL")).toBe("comment");
|
||||
const old = fixture({ comments: [{ login: "greptile-apps[bot]", created: new Date(NOW - 120 * DAY).toISOString() }, { login: "octocat", created: new Date(NOW - DAY).toISOString() }] });
|
||||
const old = fixture({ comments: [{ login: "greptile-apps[bot]", type: "Bot", created: new Date(NOW - 120 * DAY).toISOString() }, { login: "octocat", type: "User", created: new Date(NOW - DAY).toISOString() }] });
|
||||
const r = old.run("detect");
|
||||
expect(value(r.out, "GREPTILE_SIGNAL")).toBe("none");
|
||||
expect(value(r.out, "GREPTILE_EARLY")).toBe("off");
|
||||
});
|
||||
|
||||
test("a human account named like Greptile is no signal (#3122)", () => {
|
||||
const f = fixture({ comments: [{ login: "greptile-ci", type: "User", created: new Date(NOW - DAY).toISOString() }, { login: "notgreptile[bot]", type: "Bot", created: new Date(NOW - DAY).toISOString() }] });
|
||||
expect(value(f.run("detect").out, "GREPTILE_SIGNAL")).toBe("none");
|
||||
});
|
||||
|
||||
test("early review is off when greptile is in neither review-bot list (#3122)", () => {
|
||||
const f = fixture({ files: { ".greptile/config.json": "{}" }, config: "pr_wait_gating_bots: coderabbit\npr_wait_advisory_bots: none\n" });
|
||||
const r = f.run("detect");
|
||||
expect(value(r.out, "GREPTILE_EARLY")).toBe("off");
|
||||
expect(value(r.out, "GREPTILE_EARLY_REASON")).toBe("greptile is not in pr_wait_gating_bots or pr_wait_advisory_bots");
|
||||
});
|
||||
|
||||
test("without Greptile nothing changes", () => {
|
||||
const r = fixture().run("detect");
|
||||
expect(value(r.out, "GREPTILE_EARLY")).toBe("off");
|
||||
|
||||
@@ -153,6 +153,7 @@ const REQUIRED_KEYS = [
|
||||
'USER_STREAK',
|
||||
'RETRO_CONTEXT',
|
||||
'GREPTILE_HISTORY',
|
||||
'REVIEW_BOT_HISTORY',
|
||||
'TODOS_FILE',
|
||||
'SKILL_USAGE_LOG',
|
||||
'EUREKA_LOG',
|
||||
@@ -250,16 +251,19 @@ describe('gstack-retro-metrics behavior', () => {
|
||||
|
||||
test('aux inputs report present when the files exist under GSTACK_HOME', () => {
|
||||
fs.writeFileSync(path.join(tmpGstackHome, 'greptile-history.md'), '# history\n');
|
||||
fs.writeFileSync(path.join(tmpGstackHome, 'review-bot-history.md'), '# history\n');
|
||||
fs.mkdirSync(path.join(tmpGstackHome, 'analytics'), { recursive: true });
|
||||
fs.writeFileSync(path.join(tmpGstackHome, 'analytics', 'skill-usage.jsonl'), '{}\n');
|
||||
try {
|
||||
const out = runMetrics(['--base', 'main', '--since', '2026-03-09T00:00:00']);
|
||||
expect(out).toMatch(/^GREPTILE_HISTORY: present /m);
|
||||
expect(out).toMatch(/^REVIEW_BOT_HISTORY: present /m);
|
||||
expect(out).toMatch(/^SKILL_USAGE_LOG: present /m);
|
||||
expect(out).toMatch(/^RETRO_CONTEXT: absent$/m);
|
||||
expect(out).toMatch(/^EUREKA_LOG: absent$/m);
|
||||
} finally {
|
||||
fs.rmSync(path.join(tmpGstackHome, 'greptile-history.md'), { force: true });
|
||||
fs.rmSync(path.join(tmpGstackHome, 'review-bot-history.md'), { force: true });
|
||||
fs.rmSync(path.join(tmpGstackHome, 'analytics'), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -751,7 +751,7 @@ export function buildCrossSkillConsistencyJudgePrompt(collected: string): string
|
||||
return `You are evaluating whether multiple skill configuration files implement the same data architecture consistently.
|
||||
|
||||
INTENDED ARCHITECTURE:
|
||||
- greptile-history has TWO paths: per-project (~/.gstack/projects/{slug}/greptile-history.md) and global (~/.gstack/greptile-history.md)
|
||||
- the review-bot history has TWO paths: per-project (~/.gstack/projects/{slug}/review-bot-history.md) and global (~/.gstack/review-bot-history.md); older installs name the same files greptile-history.md, whose rows count as Greptile's
|
||||
- /review and /ship WRITE to BOTH paths (per-project for suppressions, global for retro aggregation)
|
||||
- /review and /ship delegate write mechanics to greptile-triage.md
|
||||
- /retro READS from the GLOBAL path only (it aggregates across all projects)
|
||||
|
||||
@@ -41,6 +41,8 @@ export const IDENTIFIER_PLACEHOLDERS: Record<string, IdentifierGrammar> = {
|
||||
'<clean|flagged>': { grammar: oneOf('clean', 'flagged'), what: 'semantic review outcome' },
|
||||
'<N|null>': { grammar: /^(?:[0-9]+(?:\.[0-9]+)?|null)$/, what: 'health score or null' },
|
||||
'<platform>': { grammar: oneOf('github', 'gitlab', 'unknown'), what: 'detected git platform' },
|
||||
'<fix|fp|already-fixed>': { grammar: oneOf('fix', 'fp', 'already-fixed'), what: 'review-bot triage outcome' },
|
||||
'<category>': { grammar: oneOf('race-condition', 'null-check', 'error-handling', 'style', 'type-safety', 'security', 'performance', 'correctness', 'other'), what: 'review-bot finding category (CATEGORIES in lib/review-bots.ts)' },
|
||||
'<effort-level>': { grammar: /^[a-z]*$/, what: "the request's /codex --effort level, or empty for none (the probe validates the level)", quoted: true },
|
||||
|
||||
// Ids, keys and numbers.
|
||||
@@ -116,7 +118,7 @@ export const IDENTIFIER_PLACEHOLDERS: Record<string, IdentifierGrammar> = {
|
||||
'<reply-file-name>': { grammar: ID, what: 'basename of the mktemp reply file printed by the previous block' },
|
||||
'<redact-file-name>': { grammar: ID, what: 'basename of the mktemp draft file printed by the free-text block' },
|
||||
'<approach-file-name>': { grammar: ID, what: 'basename of the mktemp approach file printed by the free-text block' },
|
||||
'<greptile-dir>': { grammar: PATH, what: 'mktemp directory printed by the Greptile fetch block' },
|
||||
'<bot-dir>': { grammar: PATH, what: 'REVIEW_BOTS_DIR printed by gstack-review-bots fetch' },
|
||||
'<SNAPSHOT_TOOL>': { grammar: QUOTED, what: 'snapshot tool path printed by autoplan', quoted: true },
|
||||
'<SOURCE_PLAN>': { grammar: QUOTED, what: 'plan path', quoted: true },
|
||||
'<ACTIVE_PLAN>': { grammar: QUOTED, what: 'plan path', quoted: true },
|
||||
|
||||
@@ -36,7 +36,7 @@ export function qaCallerInstructions(caller: QaCaller, root = QA_CALLER_ROOT): s
|
||||
? callerExcerpt(source, '## Step 4: Critical pass (core review)', '## Step 5.8: Persist Eng Review result')
|
||||
: callerExcerpt(source,
|
||||
'> **STOP.** Before auditing plan completion, verification, and scope drift (Step 8),',
|
||||
'> **STOP.** Before addressing Greptile review comments');
|
||||
'> **STOP.** Before addressing review bot comments');
|
||||
const review = caller === 'review' ? excerpt : read('ship/sections/review-army.md');
|
||||
if (!review.includes(`### Step ${caller === 'review' ? '4.7' : '9.2.1'}: Exploratory QA (before Fix-First)`) || !review.includes('sections/exploratory.md')) {
|
||||
throw new Error(`Generated /${caller} parent is missing the exploratory QA integration`);
|
||||
|
||||
@@ -44,7 +44,7 @@ export const REVIEW_E2E_SECTIONS = [
|
||||
'Step 0: Detect platform and base branch',
|
||||
'Step 1: Check branch',
|
||||
'Step 2: Read the checklist',
|
||||
'Step 2.5: Check for Greptile review comments',
|
||||
'Step 2.5: Check for review bot comments',
|
||||
'Step 3: Get the diff',
|
||||
'Step 4: Critical pass (core review)',
|
||||
'Confidence Calibration',
|
||||
@@ -59,7 +59,7 @@ export const REVIEW_ARMY_E2E_SECTIONS = [
|
||||
'Step 1: Check branch',
|
||||
'Step 1.5: Scope Drift Detection',
|
||||
'Step 2: Read the checklist',
|
||||
'Step 2.5: Check for Greptile review comments',
|
||||
'Step 2.5: Check for review bot comments',
|
||||
'Step 3: Get the diff',
|
||||
'Step 4: Critical pass (core review)',
|
||||
'Confidence Calibration',
|
||||
|
||||
@@ -45,7 +45,7 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
|
||||
'scripts/resolvers/review-scope.ts', 'scripts/resolvers/review-army.ts', 'scripts/resolvers/sections.ts', 'scripts/resolvers/index.ts',
|
||||
'scripts/resolvers/types.ts', 'scripts/gen-skill-docs.ts', 'scripts/host-config.ts', 'scripts/discover-skills.ts', 'hosts/claude.ts', 'hosts/index.ts', 'hosts/define-host.ts',
|
||||
'ship/sections/review-army.md*', 'ship/sections/manifest.json', 'review/checklist.md',
|
||||
'bin/gstack-review-scope', 'lib/review-scope.ts', 'lib/ship-policy.ts', 'lib/result-codes-release.ts',
|
||||
'bin/gstack-review-scope', 'lib/review-scope.ts', 'lib/ship-policy.ts', 'lib/default-base.ts', 'lib/result-codes-release.ts',
|
||||
'bin/gstack-review-log', 'bin/gstack-review-read', 'bin/gstack-wtree', 'bin/gstack-slug', 'bin/gstack-remote-identity.sh',
|
||||
'lib/review-evidence.ts', 'lib/claude-bin.ts', 'lib/eval-model.ts',
|
||||
'test/helpers/ship-frozen-scope-actor.ts', 'test/helpers/scratch-repo.ts',
|
||||
@@ -140,7 +140,7 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
|
||||
'review-enum-completeness': [ 'review/**', 'test/fixtures/review-eval-enum*.rb', 'test/skill-e2e-review.test.ts',
|
||||
'test/fixtures/fake-impeccable.ts', 'test/helpers/fake-impeccable.ts'],
|
||||
'review-base-branch': [ 'review/**', 'test/skill-e2e-review-attribution.test.ts'],
|
||||
'review-gate-integrity': [ 'review/**', 'lib/gate-diff/**', 'bin/gstack-gate-diff', 'scripts/resolvers/gate-scan.ts',
|
||||
'review-gate-integrity': [ 'review/**', 'lib/gate-diff/**', 'lib/default-base.ts', 'bin/gstack-gate-diff', 'scripts/resolvers/gate-scan.ts',
|
||||
'scripts/gate-diff-calibrate.ts', 'test/fixtures/gate-diff/**', 'test/helpers/gate-diff-repo.ts',
|
||||
'scripts/question-registry.ts', 'test/skill-e2e-gate-integrity.test.ts', 'test/helpers/skill-fixture.ts', 'test/helpers/gate-disposition.ts'],
|
||||
'review-design-lite': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'review/**', 'test/fixtures/review-eval-design-slop.*', 'test/helpers/fake-impeccable.ts', 'test/fixtures/fake-impeccable.ts', 'test/fixtures/impeccable-detect-sample.json', 'lib/design-catalog.ts', 'lib/design-detect-contract.ts', 'bin/gstack-design-detect.ts', 'scripts/resolvers/design-checklist.ts', 'scripts/resolvers/review-army.ts', 'test/skill-e2e-review.test.ts'
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* gstack-review-bots (#3122): /review and /ship triage every configured review bot, not only
|
||||
* Greptile. Drives lib/review-bots.ts in process with a fake gh, so it runs in the Windows lane too.
|
||||
*/
|
||||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { botOwning } from "../lib/pr-wait";
|
||||
import { parseHistory, patternMatches, runReviewBots, type BotComment, type ReviewBotsEnv } from "../lib/review-bots";
|
||||
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "review-bots-"));
|
||||
afterAll(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
||||
const NOW = Date.parse("2026-10-31T12:00:00Z");
|
||||
const bot = (login: string) => ({ login, type: "Bot" });
|
||||
const human = (login: string) => ({ login, type: "User" });
|
||||
|
||||
interface Fixture {
|
||||
config?: string;
|
||||
/** Each endpoint's pages; a string fails that call with the string as stderr. */
|
||||
line?: unknown[][] | string;
|
||||
top?: unknown[][] | string;
|
||||
reviews?: unknown[][] | string;
|
||||
history?: Record<string, string>;
|
||||
prView?: { status: number; stdout?: string; stderr?: string };
|
||||
authFails?: boolean;
|
||||
/** Raw stdout for the reviews call, as gh would print it. */
|
||||
rawReviews?: string;
|
||||
repoFails?: boolean;
|
||||
/** stderr for a repo lookup that fails for another reason (network, rate limit). */
|
||||
repoError?: string;
|
||||
}
|
||||
|
||||
function run(opts: Fixture, ...argv: string[]) {
|
||||
const state = fs.mkdtempSync(path.join(tmp, "state-"));
|
||||
if (opts.config) fs.writeFileSync(path.join(state, "config.yaml"), opts.config);
|
||||
for (const [name, text] of Object.entries(opts.history ?? {})) {
|
||||
fs.mkdirSync(path.dirname(path.join(state, name)), { recursive: true });
|
||||
fs.writeFileSync(path.join(state, name), text);
|
||||
}
|
||||
const out: string[] = [];
|
||||
const calls: string[][] = [];
|
||||
const ok = (stdout: string) => ({ status: 0, stdout, stderr: "" });
|
||||
const page = (p: unknown[][] | string | undefined) => typeof p === "string" ? { status: 1, stdout: "", stderr: p + "\n" } : ok((p ?? [[]]).flat().map(i => JSON.stringify(i) + "\n").join(""));
|
||||
const env: ReviewBotsEnv = {
|
||||
vars: { GSTACK_HOME: state },
|
||||
binDir: "/opt/gstack/bin",
|
||||
tmpDir: tmp,
|
||||
now: () => NOW,
|
||||
out: t => { out.push(t); },
|
||||
err: t => { out.push(t); },
|
||||
run(cmd, args) {
|
||||
calls.push([cmd, ...args]);
|
||||
const joined = args.join(" ");
|
||||
if (cmd.endsWith("gstack-slug")) return ok("acme-widget\n");
|
||||
if (cmd === "gh" && args.includes("--slurp")) return { status: 1, stdout: "", stderr: "unknown flag: --slurp (gh 2.45)\n" };
|
||||
if (cmd === "gh" && args[0] === "auth" && opts.authFails) return { status: 1, stdout: "", stderr: "not logged in\n" };
|
||||
if (cmd === "gh" && args[0] === "repo" && opts.repoFails) return { status: 1, stdout: "", stderr: "no git remotes found\n" };
|
||||
if (cmd === "gh" && args[0] === "repo" && opts.repoError) return { status: 1, stdout: "", stderr: opts.repoError + "\n" };
|
||||
if (cmd === "gh" && (args[0] === "--version" || args[0] === "auth")) return ok("");
|
||||
if (cmd === "gh" && args[0] === "repo") return ok("acme/widget\n");
|
||||
if (cmd === "gh" && args[0] === "pr") return { stdout: "", stderr: "", ...(opts.prView ?? { status: 0, stdout: "12\n" }) };
|
||||
if (cmd === "gh" && joined.includes("/pulls/12/comments")) return page(opts.line);
|
||||
if (cmd === "gh" && joined.includes("/issues/12/comments")) return page(opts.top);
|
||||
if (cmd === "gh" && joined.includes("/pulls/12/reviews")) return opts.rawReviews !== undefined ? ok(opts.rawReviews) : page(opts.reviews);
|
||||
return { status: 1, stdout: "", stderr: `unexpected ${cmd} ${joined}` };
|
||||
},
|
||||
};
|
||||
const code = runReviewBots(argv, env);
|
||||
const text = out.join("");
|
||||
const dir = /^REVIEW_BOTS_DIR: (.+)$/m.exec(text)?.[1];
|
||||
const records: BotComment[] = dir ? fs.readFileSync(path.join(dir, "comments.jsonl"), "utf8").split("\n").filter(Boolean).map(l => JSON.parse(l)) : [];
|
||||
return { code, text, records, calls, state };
|
||||
}
|
||||
|
||||
describe("botOwning", () => {
|
||||
test("a bot owns the logins that start with its name, nothing else", () => {
|
||||
expect(botOwning("greptile-apps[bot]", ["greptile", "coderabbit"])).toBe("greptile");
|
||||
expect(botOwning("CodeRabbitAI[bot]", ["greptile", "coderabbit"])).toBe("coderabbit");
|
||||
expect(botOwning("notgreptile", ["greptile"])).toBeNull();
|
||||
expect(botOwning(null, ["greptile"])).toBeNull();
|
||||
expect(botOwning("", ["greptile"])).toBeNull();
|
||||
expect(botOwning("copilot-swe[bot]", ["copilot", "copilot-swe"])).toBe("copilot-swe");
|
||||
expect(botOwning("coderabbitai[bot]", ["code", "coderabbit"])).toBe("coderabbit");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetch", () => {
|
||||
test("reads every configured bot across pages, root comments only, newest review body per bot", () => {
|
||||
const r = run({
|
||||
line: [
|
||||
[{ id: 1, user: bot("greptile-apps[bot]"), path: "a.ts", line: 3, position: 3, html_url: "u1", body: "race" }],
|
||||
[
|
||||
{ id: 2, user: bot("coderabbitai[bot]"), path: "b.ts", line: 9, position: 9, html_url: "u2", body: "null" },
|
||||
{ id: 3, user: bot("coderabbitai[bot]"), path: "b.ts", line: 9, position: 9, in_reply_to_id: 2, html_url: "u3", body: "still null" },
|
||||
{ id: 4, user: bot("greptile-apps[bot]"), path: "c.ts", line: 1, position: null, html_url: "u4", body: "outdated" },
|
||||
],
|
||||
],
|
||||
top: [[{ id: 5, user: bot("greptile-apps[bot]"), html_url: "u5", body: "summary" }, { id: 6, user: human("alice"), html_url: "u6", body: "lgtm" }]],
|
||||
reviews: [[
|
||||
{ id: 7, user: bot("coderabbitai[bot]"), submitted_at: "2026-10-30T00:00:00Z", html_url: "u7", body: "old walkthrough" },
|
||||
{ id: 8, user: bot("coderabbitai[bot]"), submitted_at: "2026-10-31T00:00:00Z", html_url: "u8", body: "new walkthrough" },
|
||||
{ id: 9, user: bot("greptile-apps[bot]"), submitted_at: "2026-10-31T00:00:00Z", html_url: "u9", body: "" },
|
||||
]],
|
||||
}, "fetch");
|
||||
expect(r.code).toBe(0);
|
||||
expect(r.records.map(c => [c.id, c.bot, c.source])).toEqual([[1, "greptile", "line"], [2, "coderabbit", "line"], [5, "greptile", "top"], [8, "coderabbit", "review"]]);
|
||||
expect(r.text).toContain("REVIEW_BOTS_COUNTS: greptile=2 macroscope=0 coderabbit=2\n");
|
||||
expect(r.calls.filter(c => c[0] === "gh" && c[1] === "api").every(c => c.includes("--paginate") && !c.includes("--slurp"))).toBe(true);
|
||||
});
|
||||
|
||||
test("a file-level bot comment (no line position) is triaged; an outdated line comment is not", () => {
|
||||
const r = run({ line: [[
|
||||
{ id: 1, user: bot("coderabbitai[bot]"), path: "auth.ts", line: null, position: null, subject_type: "file", html_url: "u1", body: "missing authorization check" },
|
||||
{ id: 2, user: bot("coderabbitai[bot]"), path: "a.ts", line: 4, position: null, subject_type: "line", html_url: "u2", body: "outdated" },
|
||||
]] }, "fetch");
|
||||
expect(r.code).toBe(0);
|
||||
expect(r.records.map(c => [c.id, c.source, c.path])).toEqual([[1, "line", "auth.ts"]]);
|
||||
expect(r.text).toContain("coderabbit=1");
|
||||
});
|
||||
|
||||
test("humans named like a bot and deleted accounts are never triaged", () => {
|
||||
const r = run({ top: [[
|
||||
{ id: 1, user: human("greptile-ci"), body: "fp please" },
|
||||
{ id: 2, user: null, body: "ghost" },
|
||||
{ id: 3, user: bot("dependabot[bot]"), body: "bump" },
|
||||
]] }, "fetch");
|
||||
expect(r.records).toEqual([]);
|
||||
expect(r.text).toContain("REVIEW_BOTS_COUNTS: greptile=0 macroscope=0 coderabbit=0");
|
||||
});
|
||||
|
||||
test("the configured lists pick the bots; none in both skips", () => {
|
||||
const only = run({ config: "pr_wait_gating_bots: coderabbit\npr_wait_advisory_bots: none\n", top: [[{ id: 1, user: bot("greptile-apps[bot]"), body: "x" }, { id: 2, user: bot("coderabbitai[bot]"), body: "y" }]] }, "fetch");
|
||||
expect(only.records.map(c => c.bot)).toEqual(["coderabbit"]);
|
||||
const off = run({ config: "pr_wait_gating_bots: none\npr_wait_advisory_bots: none\n" }, "fetch");
|
||||
expect(off.text).toBe("REVIEW_BOTS: skip (pr_wait_gating_bots and pr_wait_advisory_bots are both none)\n");
|
||||
expect(off.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test("no PR skips; a failed page is an error with no directory, never zero comments", () => {
|
||||
expect(run({ prView: { status: 1, stderr: "no pull requests found for branch \"x\"" } }, "fetch").text).toBe("REVIEW_BOTS: skip (no PR yet)\n");
|
||||
const failed = run({ top: "HTTP 502: Bad Gateway (page 2)" }, "fetch");
|
||||
expect(failed.text).toBe("REVIEW_BOTS: error (repos/acme/widget/issues/12/comments: HTTP 502: Bad Gateway (page 2))\n");
|
||||
expect(failed.records).toEqual([]);
|
||||
expect(run({ rawReviews: "{\"id\":1}\nnot json\n" }, "fetch").text).toBe("REVIEW_BOTS: error (repos/acme/widget/pulls/12/reviews: invalid JSON)\n");
|
||||
expect(run({ rawReviews: "[1,2]\n" }, "fetch").text).toBe("REVIEW_BOTS: error (repos/acme/widget/pulls/12/reviews: not a list of objects)\n");
|
||||
});
|
||||
|
||||
test("pages are read without --slurp, so gh before 2.48 still fetches", () => {
|
||||
const r = run({ line: [[{ id: 1, user: bot("coderabbitai[bot]"), path: "a.ts", line: 1, position: 1, body: "x" }]] }, "fetch");
|
||||
expect(r.records.map(c => c.id)).toEqual([1]);
|
||||
const apiCalls = r.calls.filter(c => c[1] === "api");
|
||||
expect(apiCalls).toHaveLength(3);
|
||||
for (const c of apiCalls) expect(c).toEqual(["gh", "api", "--paginate", expect.stringMatching(/\?per_page=100$/), "--jq", ".[] | tojson"]);
|
||||
});
|
||||
|
||||
test("gh not logged in or no GitHub remote skips; a non-numeric --pr is an error", () => {
|
||||
expect(run({ authFails: true }, "fetch").text).toBe("REVIEW_BOTS: skip (gh not logged in)\n");
|
||||
expect(run({ repoFails: true }, "fetch").text).toBe("REVIEW_BOTS: skip (not a GitHub remote: no git remotes found)\n");
|
||||
expect(run({ repoError: "HTTP 502: Bad Gateway" }, "fetch").text).toBe("REVIEW_BOTS: error (repository lookup failed: HTTP 502: Bad Gateway)\n");
|
||||
expect(run({ prView: { status: 1, stderr: "API rate limit exceeded" } }, "fetch").text).toBe("REVIEW_BOTS: error (PR lookup failed: API rate limit exceeded)\n");
|
||||
const bad = run({}, "fetch", "--pr", "12;rm");
|
||||
expect(bad.text).toBe("REVIEW_BOTS: error ('12;rm' is not a PR number)\n");
|
||||
expect(bad.calls.some(c => c[1] === "api")).toBe(false);
|
||||
});
|
||||
|
||||
test("an empty PR is a complete fetch with zero counts", () => {
|
||||
const r = run({}, "fetch");
|
||||
expect(r.text).toContain("REVIEW_BOTS_DIR: ");
|
||||
expect(r.text).toContain("REVIEW_BOTS_COUNTS: greptile=0 macroscope=0 coderabbit=0");
|
||||
});
|
||||
|
||||
test("a false positive suppresses only the same bot; old greptile-history rows are Greptile's", () => {
|
||||
const r = run({
|
||||
history: {
|
||||
"projects/acme-widget/review-bot-history.md": "2026-10-01 | acme/widget | fp | src/*.ts | race-condition | coderabbit\n2026-10-01 | other/repo | fp | src/a.ts | style | greptile\n",
|
||||
"projects/acme-widget/greptile-history.md": "2026-09-01 | acme/widget | fp | src/a.ts | null-check\n2026-09-01 | acme/widget | fix | src/a.ts | security\n",
|
||||
},
|
||||
line: [[
|
||||
{ id: 1, user: bot("greptile-apps[bot]"), path: "src/a.ts", line: 1, position: 1, body: "x" },
|
||||
{ id: 2, user: bot("coderabbitai[bot]"), path: "src/a.ts", line: 1, position: 1, body: "y" },
|
||||
{ id: 3, user: bot("coderabbitai[bot]"), path: "src/deep/b.ts", line: 1, position: 1, body: "z" },
|
||||
]],
|
||||
}, "fetch");
|
||||
expect(r.records.map(c => [c.id, c.suppress_candidates])).toEqual([[1, ["null-check"]], [2, ["race-condition"]], [3, []]]);
|
||||
expect(r.text).toContain("REVIEW_BOTS_SUPPRESSION_CANDIDATES: 2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("record and history", () => {
|
||||
test("record takes the bot and path from the fetched comment, so a contributor-named file never reaches a shell", () => {
|
||||
const fetched = run({
|
||||
line: [[{ id: 7, user: bot("coderabbitai[bot]"), path: "src/$(printf X).ts", line: 1, position: 1, body: "x" }, { id: 8, user: bot("coderabbitai[bot]"), path: "a | b.ts", line: 1, position: 1, body: "x" }, { id: 6, user: bot("coderabbitai[bot]"), path: "**", line: 1, position: 1, body: "x" }]],
|
||||
top: [[{ id: 9, user: bot("greptile-apps[bot]"), body: "y" }]],
|
||||
}, "fetch");
|
||||
const dir = /^REVIEW_BOTS_DIR: (.+)$/m.exec(fetched.text)![1]!;
|
||||
const r = run({}, "record", "--dir", dir, "--id", "7", "--type", "fp", "--category", "style");
|
||||
expect(r.code).toBe(0);
|
||||
const row = "2026-10-31 | acme/widget | fp | src/$(printf X).ts | style | coderabbit\n";
|
||||
expect(fs.readFileSync(path.join(r.state, "projects/acme-widget/review-bot-history.md"), "utf8")).toBe(row);
|
||||
expect(fs.readFileSync(path.join(r.state, "review-bot-history.md"), "utf8")).toBe(row);
|
||||
expect(parseHistory(row)).toEqual([{ repo: "acme/widget", type: "fp", pattern: "src/$(printf X).ts", category: "style", bot: "coderabbit" }]);
|
||||
const top = run({}, "record", "--dir", dir, "--id", "9", "--type", "already-fixed", "--category", "correctness");
|
||||
expect(fs.readFileSync(path.join(top.state, "review-bot-history.md"), "utf8")).toBe("2026-10-31 | acme/widget | already-fixed | top-level | correctness | greptile\n");
|
||||
for (const bad of ["8", "6"]) {
|
||||
const refused = run({}, "record", "--dir", dir, "--id", bad, "--type", "fp", "--category", "security");
|
||||
expect(refused.code).toBe(1);
|
||||
expect(fs.existsSync(path.join(refused.state, "review-bot-history.md"))).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
test("record refuses an id two comment kinds share", () => {
|
||||
const fetched = run({ line: [[{ id: 9, user: bot("coderabbitai[bot]"), path: "a.ts", line: 1, position: 1, body: "x" }]], top: [[{ id: 9, user: bot("greptile-apps[bot]"), body: "y" }]] }, "fetch");
|
||||
const dir = /^REVIEW_BOTS_DIR: (.+)$/m.exec(fetched.text)![1]!;
|
||||
const r = run({}, "record", "--dir", dir, "--id", "9", "--type", "fp", "--category", "style");
|
||||
expect(r.code).toBe(1);
|
||||
expect(r.text).toContain("more than one comment 9");
|
||||
});
|
||||
|
||||
test("record refuses anything but a known id, type and category", () => {
|
||||
const fetched = run({ top: [[{ id: 9, user: bot("greptile-apps[bot]"), body: "y" }]] }, "fetch");
|
||||
const dir = /^REVIEW_BOTS_DIR: (.+)$/m.exec(fetched.text)![1]!;
|
||||
const rec = (extra: Fixture, ...a: string[]) => run(extra, "record", "--dir", dir, ...a);
|
||||
expect(rec({}, "--id", "9", "--type", "maybe", "--category", "style").code).toBe(64);
|
||||
expect(rec({}, "--id", "9", "--type", "fp", "--category", "$(id)").code).toBe(64);
|
||||
expect(rec({}, "--id", "9;rm", "--type", "fp", "--category", "style").code).toBe(64);
|
||||
expect(rec({}, "--id", "9", "--type", "fp").code).toBe(64);
|
||||
expect(rec({}, "--id", "10", "--type", "fp", "--category", "style").code).toBe(1);
|
||||
expect(run({}, "record", "--dir", path.join(dir, "gone"), "--id", "9", "--type", "fp", "--category", "style").text).toContain("is gone; run fetch again");
|
||||
const noRepo = rec({ repoFails: true }, "--id", "9", "--type", "fp", "--category", "style");
|
||||
expect(noRepo.code).toBe(1);
|
||||
expect(fs.existsSync(path.join(noRepo.state, "review-bot-history.md"))).toBe(false);
|
||||
});
|
||||
|
||||
test("patterns: exact, * within a directory, ** across", () => {
|
||||
expect(patternMatches("src/a.ts", "src/a.ts")).toBe(true);
|
||||
expect(patternMatches("src/*.ts", "src/deep/b.ts")).toBe(false);
|
||||
expect(patternMatches("src/**.ts", "src/deep/b.ts")).toBe(true);
|
||||
expect(patternMatches("a.(ts)", "a.ts")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* /review's PR-type step (GSTA-224 H1, issue #356). The checklist names the PR type from the changed paths, keeps every
|
||||
* category on application and mixed diffs, always runs five categories on CI/infra, scripts/tooling and docs-only diffs,
|
||||
* and reports the rest in one not-applicable line. The classifier below is built from the patterns the checklist itself
|
||||
* lists (its backticked globs, plus the compose, Terraform and README/CHANGELOG phrases the classifier hardcodes), so a
|
||||
* reworded rule that drops one fails here before a reviewer reads it.
|
||||
*/
|
||||
import { describe, test, expect } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const checklist = fs.readFileSync(path.join(import.meta.dir, '..', 'review', 'checklist.md'), 'utf8').replace(/\r\n/g, '\n');
|
||||
|
||||
function between(text: string, start: string, end: string): string {
|
||||
const i = text.indexOf(start);
|
||||
expect(i).toBeGreaterThanOrEqual(0);
|
||||
const j = text.indexOf(end, i + start.length);
|
||||
expect(j).toBeGreaterThan(i);
|
||||
return text.slice(i, j);
|
||||
}
|
||||
|
||||
const block = () => between(checklist, '**PR type', '**Two-pass review:**');
|
||||
const TYPES = ['docs-only', 'CI/infra', 'scripts/tooling', 'application', 'mixed'] as const;
|
||||
type PrType = typeof TYPES[number];
|
||||
|
||||
function rule(type: PrType): string {
|
||||
const line = block().split('\n').find(l => l.startsWith('- **' + type + ':**'));
|
||||
expect(line).toBeDefined();
|
||||
return line!;
|
||||
}
|
||||
const ticks = (line: string) => [...line.matchAll(/\x60([^\x60]+)\x60/g)].map(m => m[1]!);
|
||||
const globRe = (glob: string) => new RegExp('^' + glob.replace(/[.+^\${}()|[\]\\]/g, '\\$&').replace(/\*\*/g, '\u0000').replace(/\*/g, '[^/]*').replace(/\u0000/g, '.*') + '$');
|
||||
const base = (p: string) => p.slice(p.lastIndexOf('/') + 1);
|
||||
|
||||
const MANIFESTS = ['package.json', 'bun.lock', 'bun.lockb', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'Cargo.toml', 'Cargo.lock', 'go.mod', 'go.sum', 'Gemfile', 'Gemfile.lock', 'pyproject.toml', 'uv.lock'];
|
||||
const LINT_CONFIG = /^(\.eslintrc.*|eslint\.config\..*|\.prettierrc.*|prettier\.config\..*|biome\.json|\.shellcheckrc|\.editorconfig)$/;
|
||||
|
||||
function classifier() {
|
||||
const ci = ticks(rule('CI/infra')).map(globRe);
|
||||
const scriptRes = ticks(rule('scripts/tooling')).map(globRe);
|
||||
const app = rule('application');
|
||||
const appDirs = ticks(app).filter(t => t.endsWith('/'));
|
||||
const appGlobs = ticks(app).filter(t => t.startsWith('*')).map(globRe);
|
||||
expect(appDirs).toEqual(['bin/', 'scripts/', 'tools/']);
|
||||
expect(app).toContain('package manifests and lockfiles');
|
||||
expect(app).toContain('skill Markdown');
|
||||
expect(rule('docs-only')).toContain('\x60docs/\x60');
|
||||
expect(rule('docs-only')).toContain('README/CHANGELOG');
|
||||
expect(rule('CI/infra')).toContain('compose files');
|
||||
expect(rule('CI/infra')).toContain('Terraform');
|
||||
const isScript = (p: string) => scriptRes.some(r => r.test(base(p)));
|
||||
return (p: string): Exclude<PrType, 'mixed'> => {
|
||||
if (appDirs.some(d => p.startsWith(d)) && !isScript(p)) return 'application';
|
||||
if (MANIFESTS.includes(base(p)) || appGlobs.some(r => r.test(base(p))) || base(p) === 'SKILL.md') return 'application';
|
||||
if (/\.(md|txt)$/.test(p) && (p.startsWith('docs/') || /^(README|CHANGELOG)/.test(base(p)))) return 'docs-only';
|
||||
if (ci.some(r => r.test(p) || r.test(base(p))) || /(^|\/)(docker-)?compose\.ya?ml$|\.tf$/.test(p)) return 'CI/infra';
|
||||
if (isScript(p) || LINT_CONFIG.test(base(p))) return 'scripts/tooling';
|
||||
return 'application';
|
||||
};
|
||||
}
|
||||
|
||||
function prType(paths: string[]): PrType {
|
||||
const one = classifier();
|
||||
const types = new Set(paths.map(one));
|
||||
return types.size > 1 ? 'mixed' : [...types][0]!;
|
||||
}
|
||||
|
||||
describe('review checklist PR type (GSTA-224 H1)', () => {
|
||||
test('the PR type is decided first and names the five types in order', () => {
|
||||
const b = block();
|
||||
expect(checklist.indexOf('**PR type')).toBeLessThan(checklist.indexOf('## Review Categories'));
|
||||
expect(b).toContain('\x60PR type: <type>\x60');
|
||||
let at = -1;
|
||||
for (const type of TYPES) {
|
||||
const i = b.indexOf('- **' + type + ':**');
|
||||
expect(i).toBeGreaterThan(at);
|
||||
at = i;
|
||||
}
|
||||
expect(rule('application')).toContain('When in doubt, application.');
|
||||
});
|
||||
|
||||
test.each(([
|
||||
['a .tmpl change', ['review/SKILL.md.tmpl', 'review/SKILL.md'], 'application'],
|
||||
['a bin/ TypeScript change', ['bin/gstack-design-detect.ts'], 'application'],
|
||||
['an extensionless bin/ executable', ['bin/gstack-approval-classes'], 'application'],
|
||||
['scripts/ TypeScript', ['scripts/skill-bin-drift.ts'], 'application'],
|
||||
['package.json + bun.lock', ['package.json', 'bun.lock'], 'application'],
|
||||
['a workflow-only change', ['.github/workflows/free-tests.yml'], 'CI/infra'],
|
||||
['a Dockerfile', ['Dockerfile.ci'], 'CI/infra'],
|
||||
['a .bat add at the root', ['build.bat'], 'scripts/tooling'],
|
||||
['a .bat add under scripts/', ['scripts/build.bat'], 'scripts/tooling'],
|
||||
['a shell script and the Makefile', ['scripts/release.sh', 'Makefile'], 'scripts/tooling'],
|
||||
['docs only', ['docs/skills.md', 'README.md'], 'docs-only'],
|
||||
['docs plus a checklist prompt', ['docs/skills.md', 'review/checklist.md'], 'mixed'],
|
||||
['a workflow plus application code', ['.github/workflows/ci.yml', 'lib/review-brief.ts'], 'mixed'],
|
||||
['a workflow plus a .bat script', ['.github/workflows/ci.yml', 'build.bat'], 'mixed'],
|
||||
['an unplaceable path', ['assets/logo.svg'], 'application'],
|
||||
] as Array<[string, string[], PrType]>).map(([name, paths, expected]) => [name + ' is ' + expected, paths, expected] as const))('%s', (_name, paths, expected) => {
|
||||
expect(prType(paths)).toBe(expected);
|
||||
});
|
||||
|
||||
test('application and mixed diffs run everything; other types always run five categories and report the rest in one line', () => {
|
||||
const scope = block().slice(block().indexOf('On application and mixed diffs'));
|
||||
expect(scope).toContain('On application and mixed diffs, run every category below exactly as written; nothing is skipped.');
|
||||
const always = /always run (.+?), and report/.exec(scope);
|
||||
expect(always).not.toBeNull();
|
||||
const names = always![1]!.split(/, | and (?=Repo)/);
|
||||
expect(names).toEqual(['Gate Integrity', 'Shell Injection', 'Completeness Gaps', 'Distribution & CI/CD Pipeline', 'Repo Conventions & Platform Fit']);
|
||||
const headings = checklist.split('\n').filter(l => l.startsWith('#### ')).map(l => l.slice(5));
|
||||
for (const name of names) expect(headings.some(h => h.startsWith(name))).toBe(true);
|
||||
expect(scope).toContain('once, in one line: \x60Not applicable (PR type: <type>): <categories>\x60');
|
||||
expect(scope).toContain('never counts as passed');
|
||||
});
|
||||
|
||||
test('Repo Conventions & Platform Fit needs a concrete consequence and Distribution gains the script checks', () => {
|
||||
const conventions = between(checklist, '#### Repo Conventions & Platform Fit', '\n---');
|
||||
expect(conventions).toContain('concrete consequence');
|
||||
expect(conventions).toContain('a \x60.bat\x60 script in a repo whose scripts are bash plus a Makefile is a finding');
|
||||
expect(conventions).toContain('platforms the CI runners and docs target');
|
||||
expect(conventions).toContain('repeats no existing tool');
|
||||
const distribution = between(checklist, '#### Distribution & CI/CD Pipeline', '#### Repo Conventions');
|
||||
for (const token of ['\x60set -euo pipefail\x60', 'quoted variables', "CI runners' OS", 'release tag or commit SHA', 'pinned version']) expect(distribution).toContain(token);
|
||||
expect(distribution).toContain('except for the script and pinning checks above');
|
||||
expect(between(checklist, '## Severity Classification', '## Fix-First Heuristic')).toContain('└─ Repo Conventions & Platform Fit');
|
||||
});
|
||||
|
||||
test('the addition stays near 25 lines', () => {
|
||||
const conventions = between(checklist, '#### Repo Conventions & Platform Fit', '\n---');
|
||||
const scriptChecks = checklist.split('\n').filter(l => l.startsWith('- Scripts CI or a build relies on:') || l.startsWith('- Pinned versions:'));
|
||||
expect(scriptChecks).toHaveLength(2);
|
||||
const lines = (block() + conventions).trimEnd().split('\n').length + scriptChecks.length + 1;
|
||||
expect(lines).toBeLessThanOrEqual(25);
|
||||
});
|
||||
});
|
||||
+121
-1
@@ -3,7 +3,7 @@ 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 { collectCommit, collectLive, CONSUMER_SCAN_CAP, loadRegistryAt } from '../lib/review-collect';
|
||||
import { collectCommit, collectLive, CONSUMER_SCAN_CAP, CONSUMER_SCAN_TIMEOUT_MS, consumerScanTimeoutMs, grepConsumers, loadRegistryAt, scanConsumers } from '../lib/review-collect';
|
||||
import { depthOfCommitInput } from '../lib/review-depth';
|
||||
|
||||
const dirs: string[] = [];
|
||||
@@ -112,6 +112,18 @@ describe('collectLive: the working tree', () => {
|
||||
expect(c.paths).toEqual(['docs/a.md', 'src/a.ts', 'src/new.ts']);
|
||||
expect(depthOfCommitInput({ ...c, gateTagged: 0 })).toMatchObject({ depth: 'light', runtimeLines: 20 + 10 });
|
||||
});
|
||||
// Value: protects=a remote-qualified base reads that remote's tracking branch by its full name, so a fetched branch called
|
||||
// origin/main cannot become the merge base (an empty diff) or the registry and policy source; fails_when=collectLive tries
|
||||
// refs/remotes/origin/<base> first for origin/main (/ship review of #3852, outside-voice#1); why_new=every other case names a
|
||||
// bare base; seam=none; no_claim=remotes other than origin
|
||||
test('a fetched branch named origin/main never stands in for origin/main', () => {
|
||||
const r = repo({});
|
||||
r.git('update-ref', 'refs/remotes/origin/main', r.baseSha);
|
||||
const head = r.commit({ 'src/a.ts': lines(3) });
|
||||
r.git('update-ref', 'refs/remotes/origin/origin/main', head);
|
||||
const c = collectLive(r.dir, 'origin/main');
|
||||
expect([c.mergeBase, c.registry.sha, c.paths]).toEqual([r.baseSha, r.baseSha, ['src/a.ts']]);
|
||||
});
|
||||
test('no merge base is a collector error the CLI refuses on', () => {
|
||||
const r = repo({});
|
||||
expect(collectLive(r.dir, 'no-such-branch').errors.map(e => e.code)).toEqual(['numstat_failed']);
|
||||
@@ -177,3 +189,111 @@ describe('GSTA-167 part 4a: which data files code names (scanConsumers)', () =>
|
||||
expect(depthOfCommitInput({ ...c, gateTagged: 0 }).class).toBe('code');
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
describe('GST-544: the consumer scan reads only files that can match, under one overall deadline', () => {
|
||||
const rows = Array.from({ length: 40 }, (_, i) => `{"i":${i}}`).join('\n') + '\n';
|
||||
const blob = Buffer.concat([Buffer.from([0, 1, 2]), Buffer.from(' rows.json post.json\n')]);
|
||||
const mixed = () => {
|
||||
const r = repo({ 'src/old.ts': "read('rules.json')\n", 'src/manifest.ts': "load('index.json')\n", 'docs/wiki.md': 'see orphan.json and rows.json\n', 'bench/blob.bin': blob, 'bench/notes.ts': 'no data names here, only .json and .csv\n' });
|
||||
const head = r.commit({ 'src/old.ts': null, 'src/load.ts': "require('./data/rows.json'); require('my rows.json')\n", 'data/rows.json': rows, 'data/my rows.json': rows, 'assets/rules.json': rows, 'assets/index.json': '["post.json"]\n', 'assets/post.json': rows, 'wiki/orphan.json': rows, 'wiki/live.csv': 'a\n', 'bench/overlap.ts': "'xrows.jsonl' 'ab.csv' 'b.csv'\n" });
|
||||
r.write({ 'src/untracked.ts': "read('live.csv')\n" });
|
||||
return { ...r, head };
|
||||
};
|
||||
const patterns = ['rows.json', 'my rows.json', 'rules.json', 'index.json', 'post.json', 'orphan.json', 'live.csv', 'b.csv'];
|
||||
const wholeTree = (dir: string, at: string) => {
|
||||
const r = spawnSync('git', ['-c', 'core.quotePath=false', 'grep', '-I', '-F', '-o', '--null', '--no-line-number', '--no-column', '--no-color', ...patterns.flatMap(b => ['-e', b]), ...(at ? [at, '--'] : ['--untracked', '--'])], { cwd: dir, encoding: 'utf8', timeout: 10_000 });
|
||||
expect([0, 1]).toContain(r.status ?? -1);
|
||||
return r.stdout.split('\n').filter(Boolean).sort();
|
||||
};
|
||||
// Value: protects=the narrowed scan prints exactly the lines one whole-tree git grep prints, at a commit, at the merge base
|
||||
// and in the working tree with untracked files; fails_when=the extension pre-pass or the pathspecs drop a consumer;
|
||||
// seam=git grep output, compared with the single grep the scan ran before GST-544
|
||||
test('grepConsumers prints the same lines as one whole-tree git grep at each rev and in the working tree', () => {
|
||||
const r = mixed();
|
||||
for (const at of [r.baseSha, r.head, '']) {
|
||||
const got = grepConsumers(r.dir, patterns, at, () => true, Date.now() + 10_000);
|
||||
expect(Array.isArray(got)).toBe(true);
|
||||
expect((got as string[]).filter(Boolean).sort()).toEqual(wholeTree(r.dir, at));
|
||||
}
|
||||
expect(wholeTree(r.dir, '').length).toBeGreaterThan(5);
|
||||
});
|
||||
test('the pathspec chunks give the same lines when every file is its own git grep call', () => {
|
||||
const r = mixed();
|
||||
const got = grepConsumers(r.dir, patterns, '', () => true, Date.now() + 10_000, 1);
|
||||
expect((got as string[]).filter(Boolean).sort()).toEqual(wholeTree(r.dir, ''));
|
||||
expect(new Set(wholeTree(r.dir, '').map(l => l.split('\0')[0])).size).toBeGreaterThan(3);
|
||||
});
|
||||
test('consumed sets on the mixed fixture: chains through a data manifest, a live untracked consumer, docs ignored', () => {
|
||||
const r = mixed();
|
||||
const commit = collectCommit(r.dir, r.baseSha, r.head);
|
||||
expect([commit.consumed, commit.errors]).toEqual([['assets/index.json', 'assets/post.json', 'assets/rules.json', 'data/my rows.json', 'data/rows.json'], []]);
|
||||
const live = collectLive(r.dir, 'main');
|
||||
expect([live.consumed, live.errors]).toEqual([['assets/index.json', 'assets/post.json', 'assets/rules.json', 'data/my rows.json', 'data/rows.json', 'wiki/live.csv'], []]);
|
||||
});
|
||||
// Value: protects=a scan that runs out of time keeps every data file code and says it timed out, with the deadline;
|
||||
// fails_when=a slow grep drops data to docs or reads as a git error; seam=the spawnSync timeout
|
||||
test('a scan past its deadline fails closed with consumer_scan_failed naming the timeout and the deadline', () => {
|
||||
const r = mixed();
|
||||
const errors: Parameters<typeof scanConsumers>[5] = [];
|
||||
expect(scanConsumers(r.dir, ['data/rows.json', 'wiki/orphan.json'], [r.head], true, r.dir, errors, 1)).toBe('all');
|
||||
expect(errors).toEqual([expect.objectContaining({ code: 'consumer_scan_failed', detail: expect.stringMatching(/timed out.*0\.001 s deadline.*GSTACK_CONSUMER_SCAN_TIMEOUT_MS/) })]);
|
||||
const saved = process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS;
|
||||
process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS = '1';
|
||||
try {
|
||||
const c = collectCommit(r.dir, r.baseSha, r.head);
|
||||
expect(c.consumed).toBe('all');
|
||||
expect(c.errors.map(e => [e.code, /timed out/.test(e.detail)])).toEqual([['consumer_scan_failed', true]]);
|
||||
} finally {
|
||||
if (saved === undefined) delete process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS; else process.env.GSTACK_CONSUMER_SCAN_TIMEOUT_MS = saved;
|
||||
}
|
||||
r.git('config', 'grep.lineNumber', 'not-a-bool');
|
||||
const failed: Parameters<typeof scanConsumers>[5] = [];
|
||||
expect(scanConsumers(r.dir, ['data/rows.json'], [r.head], false, r.dir, failed, CONSUMER_SCAN_TIMEOUT_MS)).toBe('all');
|
||||
expect(failed[0]!.detail).toMatch(new RegExp(`^git grep exited \\d+: .*\\(deadline ${CONSUMER_SCAN_TIMEOUT_MS / 1000} s\\)$`));
|
||||
});
|
||||
const withEnv = (name: string, value: string, fn: () => void) => {
|
||||
const saved = process.env[name];
|
||||
process.env[name] = value;
|
||||
try { fn(); } finally { if (saved === undefined) delete process.env[name]; else process.env[name] = saved; }
|
||||
};
|
||||
// Value: protects=an inherited GIT_LITERAL_PATHSPECS (git --literal-pathspecs exports it to children) cannot empty the narrowed
|
||||
// search and drop data to docs; a fractional override cannot crash spawnSync; fails_when=the pathspecs use magic the variable
|
||||
// turns off, or the timeout is not an integer; seam=the process environment
|
||||
test('an inherited GIT_LITERAL_PATHSPECS keeps the same lines; a fractional timeout is whole milliseconds; a spawn error is named', () => {
|
||||
const r = mixed();
|
||||
withEnv('GIT_LITERAL_PATHSPECS', '1', () => {
|
||||
for (const at of [r.head, '']) expect((grepConsumers(r.dir, patterns, at, () => true, Date.now() + 10_000) as string[]).filter(Boolean).sort()).toEqual(wholeTree(r.dir, at));
|
||||
});
|
||||
withEnv('GSTACK_CONSUMER_SCAN_TIMEOUT_MS', '1500.5', () => expect(consumerScanTimeoutMs()).toBe(1500));
|
||||
const errors: Parameters<typeof scanConsumers>[5] = [];
|
||||
withEnv('PATH', path.join(r.dir, 'no-bin'), () => expect(scanConsumers(r.dir, ['data/rows.json'], [r.head], false, r.dir, errors, 10_000)).toBe('all'));
|
||||
expect(errors[0]!.detail).toMatch(/^git grep exited null: .*ENOENT/);
|
||||
});
|
||||
// Value: protects=a consumer whose name is not valid UTF-8 still counts, and a file with a million references does not crash the
|
||||
// planner; fails_when=the -l pass hands back a mangled name as a pathspec, or the matches are spread into one call;
|
||||
// seam=git tree objects and git grep output size
|
||||
test('a consumer named with invalid UTF-8 bytes still counts; output past the byte cap fails closed; a million matches are all returned', () => {
|
||||
const r = repo({ 'src/keep.ts': 'x\n' });
|
||||
const head = r.commit({ 'data/results.json': rows });
|
||||
const run = (args: string[], input?: Buffer) => { const x = spawnSync('git', args, { cwd: r.dir, input, timeout: 10_000 }); if (x.status !== 0) throw new Error(`git ${args.join(' ')}: ${x.stderr}`); return x.stdout as Buffer; };
|
||||
const sha = run(['hash-object', '-w', '--stdin'], Buffer.from("read('results.json')\n")).toString().trim();
|
||||
const entry = Buffer.concat([Buffer.from(`100644 blob ${sha}\tloader`), Buffer.from([0xff]), Buffer.from('.py\0')]);
|
||||
const tree = run(['mktree', '-z'], Buffer.concat([run(['ls-tree', '-z', head]), entry])).toString().trim();
|
||||
const named = run(['commit-tree', tree, '-p', head, '-m', 'consumer'], Buffer.alloc(0)).toString().trim();
|
||||
expect(collectCommit(r.dir, r.baseSha, named).consumed).toEqual(['data/results.json']);
|
||||
const small = mixed();
|
||||
const capped = grepConsumers(small.dir, patterns, '', () => true, Date.now() + 10_000, 1, 50);
|
||||
expect(capped).toEqual({ status: null, err: 'ENOBUFS', timedOut: false });
|
||||
r.write({ 'src/many.ts': 'rows.json\n'.repeat(1_100_000) });
|
||||
const got = grepConsumers(r.dir, ['rows.json'], '', () => true, Date.now() + 30_000);
|
||||
expect(Array.isArray(got) && got.filter(Boolean).length).toBe(1_100_000);
|
||||
}, 30_000);
|
||||
// Value: protects=a slow scan ends in its own fail-closed consumer_scan_failed, not in the parent killing gstack-review-plan;
|
||||
// fails_when=the scan deadline reaches the timeout the dispatch and preflight callers give the whole plan; seam=caller source
|
||||
test('the default scan deadline leaves a minute of the plan timeout its callers set', () => {
|
||||
const callers = ['bin/gstack-review-dispatch', 'lib/ship-preflight.ts'].map(f => fs.readFileSync(path.join(import.meta.dir, '..', f), 'utf8'));
|
||||
const limits = callers.flatMap(src => [...src.matchAll(/gstack-review-plan'[^\n]*?(?:timeout: |\], )(\d[\d_]+)/g)].map(m => Number(m[1]!.replace(/_/g, ''))));
|
||||
expect(limits.length).toBeGreaterThanOrEqual(2);
|
||||
expect(CONSUMER_SCAN_TIMEOUT_MS).toBeLessThanOrEqual(Math.min(...limits) - 60_000);
|
||||
});
|
||||
});
|
||||
@@ -154,10 +154,11 @@ describe('GST-967 invariant: no gate-class owner exit before Step 11\'s voices;
|
||||
* the four fix flags; Step 11 run or not), main's planReview at 1022f4f (v1.92.81.0) hashes to MAIN_PLANS. The branch's plan,
|
||||
* with each voices step read back as main's stop (its reason is the parenthesised tail, no dispatch), hashes to the same value,
|
||||
* and every voices step is a gate-class stop before Step 11 that adds exactly Step 11's three voices. No grant is passed (main
|
||||
* takes none). The brief bodies lib/review-brief.ts cuts from the ship sections hash to MAIN_SECTIONS, main's value.
|
||||
* takes none). The brief bodies lib/review-brief.ts cuts from the ship sections hash to MAIN_SECTIONS: main's bodies plus
|
||||
* GST-508's exclude-pathspec placeholders (replay 'GST-508+GST-464+GST-967': the merged bodies minus main's are the wave's minus fc292e22f).
|
||||
*/
|
||||
const MAIN_PLANS = '9d13d6bae86bfc9207ce7e0cec8da5b33db2518c1653e8e009160a98b0f04c89';
|
||||
const MAIN_SECTIONS = 'a2b999aa2de2c4cdbb953aeb0a4fac6a67e01a2c5d74121e191b95781e68e345';
|
||||
const MAIN_SECTIONS = 'cec8872ff5a4aacb610133294706e452952b172fbe9c4891039679e98d895f62';
|
||||
describe('GST-967 dispatch-superset no-loss check', () => {
|
||||
// Value: protects=the no-loss rule for review-depth changes: GST-967 drops, renames and re-efforts no reviewer main dispatches on any grid case, and changes no brief body; fails_when=a non-stop plan changes, a voices step appears off gate class or after Step 11, it dispatches anything but the three voices, or a brief body moves;
|
||||
// why_new=GST-967; seam=planReview, sectionTexts; no_claim=what the added voices find (they only add coverage)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { afterAll, 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';
|
||||
@@ -11,6 +11,16 @@ const BIN = path.join(ROOT, 'bin', 'gstack-review-dispatch');
|
||||
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(), 'review-dispatch-')); dirs.push(d); return d; };
|
||||
/** A clean checkout of HEAD: the outside voice embeds the diff against its base, and a build that rewrites tracked files in ROOT can push that past the reviewer diff ceiling. */
|
||||
let clean = '';
|
||||
const cleanCheckout = () => {
|
||||
if (clean) return clean;
|
||||
const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'review-dispatch-clean-')), 'wt');
|
||||
const r = spawnSync('git', ['-C', ROOT, 'worktree', 'add', '--detach', dir, 'HEAD'], { encoding: 'utf8', timeout: 120_000 });
|
||||
if (r.status !== 0) throw new Error(`git worktree add failed: ${r.stderr}`);
|
||||
return (clean = dir);
|
||||
};
|
||||
afterAll(() => { if (clean) spawnSync('git', ['-C', ROOT, 'worktree', 'remove', '--force', clean], { encoding: 'utf8', timeout: 60_000 }); });
|
||||
/** A reader that follows its brief's workspace paragraph starts its reply with the REVIEWED_TREE line of that checkout (GST-482). */
|
||||
function treeLineOf(cwd: string): string {
|
||||
const git = (a: string[]) => spawnSync('git', ['-C', cwd, ...a], { encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
@@ -207,10 +217,11 @@ describe('gstack-review-dispatch sent, collect, judge and verify: nothing change
|
||||
const spec = p.w('spec.out', '{"severity":"CRITICAL","path":"a.ts","line":3,"category":"logic","summary":"off by one","specialist":"testing"}\n{"severity":"INFORMATIONAL","path":"a.ts","line":9,"category":"style","summary":"name","specialist":"testing"}\n');
|
||||
const outside = p.w('outside.out', 'Findings:\n1. **High**: retry loop never backs off (q.ts:78)\n2. Low - log line is noisy\nRecommendation: Fix the retry because it DoSes the pool\n');
|
||||
const c1 = run(['collect', '--ledger', p.ledger, '--role', 'specialist', '--name', 'testing', '--output', spec, '--merged', p.merged]);
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const ov = field(run(['render', '--role', 'outside-voice', '--out', p.out, '--diff-base', head]).stdout, 'file');
|
||||
const wt = cleanCheckout();
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: wt, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const ov = field(run(['render', '--role', 'outside-voice', '--out', p.out, '--diff-base', head], wt).stdout, 'file');
|
||||
run(['sent', '--ledger', p.ledger, '--role', 'outside-voice', '--sent', ov]);
|
||||
const c2 = run(['collect', '--ledger', p.ledger, '--role', 'outside-voice', '--output', outside, '--merged', p.merged]);
|
||||
const c2 = run(['collect', '--ledger', p.ledger, '--role', 'outside-voice', '--output', outside, '--merged', p.merged], wt);
|
||||
expect([c1.stdout.includes('findings=2'), c2.stdout.includes('findings=2')]).toEqual([true, true]);
|
||||
const merged = fs.readFileSync(p.merged, 'utf8').trim().split('\n').map(l => JSON.parse(l) as MergedLine);
|
||||
expect(merged.map(m => [m.id, m.label])).toEqual([['specialist/testing#1', 'CRITICAL'], ['specialist/testing#2', 'INFORMATIONAL'], ['outside-voice#1', 'High'], ['outside-voice#2', 'Low']]);
|
||||
@@ -720,9 +731,10 @@ describe('gstack-review-dispatch sent, collect, judge and verify: nothing change
|
||||
run(['judge', '--ledger', p.ledger, '--merged', p.merged, '--judged', path.join(p.out, 'judged.jsonl')]);
|
||||
const v = run(['verify', '--ledger', p.ledger]);
|
||||
expect([v.status, v.stdout.includes('replaced_by_a_review'), v.stdout.includes('VERIFY: clean briefs=1 outputs=2 voided=1')]).toEqual([0, true, true]);
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const wt = cleanCheckout();
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: wt, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const o = tmp();
|
||||
const ov = field(run(['render', '--role', 'outside-voice', '--out', o, '--diff-base', head]).stdout, 'file');
|
||||
const ov = field(run(['render', '--role', 'outside-voice', '--out', o, '--diff-base', head], wt).stdout, 'file');
|
||||
const ledger = path.join(o, 'review-ledger.jsonl'), merged = path.join(o, 'merged.jsonl');
|
||||
run(['sent', '--ledger', ledger, '--role', 'outside-voice', '--sent', ov]);
|
||||
const fail = path.join(o, 'timeout.out');
|
||||
@@ -831,16 +843,17 @@ describe('gstack-review-dispatch sent, collect, judge and verify: nothing change
|
||||
// later review voids it, or an output with no recorded file passes on its review field (fix-checks at 721539c, 56ed6e3 and 50dc73c: VERIFY: clean); why_new=the GST-482 count exemption trusted collect's
|
||||
// fields; seam=verify; no_claim=that a deleted output event is caught (#3719)
|
||||
test('an output event edited to look refused, or a refused one edited to look accepted, is dirty; a real wrong-tree reply is NOT_REVIEWED, then voided by a review', () => {
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const wt = cleanCheckout();
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: wt, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const findings = '1. **CRITICAL**: auth.ts:3 leaks a token\nBlocks: yes\n\nRecommendation: request changes\n';
|
||||
const voice = (reply: string) => {
|
||||
const out = tmp();
|
||||
const ledger = path.join(out, 'review-ledger.jsonl');
|
||||
const merged = path.join(out, 'merged.jsonl');
|
||||
const brief = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head]).stdout, 'file');
|
||||
const send = () => run(['sent', '--ledger', ledger, '--role', 'outside-voice', '--sent', brief]);
|
||||
const brief = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head], wt).stdout, 'file');
|
||||
const send = () => run(['sent', '--ledger', ledger, '--role', 'outside-voice', '--sent', brief], wt);
|
||||
let n = 0;
|
||||
const take = (text: string) => { const f = path.join(out, `ov${++n}.out`); fs.writeFileSync(f, text); return run(['collect', '--ledger', ledger, '--role', 'outside-voice', '--output', f, '--merged', merged]); };
|
||||
const take = (text: string) => { const f = path.join(out, `ov${++n}.out`); fs.writeFileSync(f, text); return run(['collect', '--ledger', ledger, '--role', 'outside-voice', '--output', f, '--merged', merged], wt); };
|
||||
send();
|
||||
const c = take(reply);
|
||||
const forge = (edit: Record<string, unknown>) => {
|
||||
@@ -849,8 +862,8 @@ describe('gstack-review-dispatch sent, collect, judge and verify: nothing change
|
||||
};
|
||||
const verify = () => {
|
||||
fs.writeFileSync(path.join(out, 'judged.jsonl'), '');
|
||||
expect(run(['judge', '--ledger', ledger, '--merged', merged, '--judged', path.join(out, 'judged.jsonl')]).status).toBe(0);
|
||||
return run(['verify', '--ledger', ledger]);
|
||||
expect(run(['judge', '--ledger', ledger, '--merged', merged, '--judged', path.join(out, 'judged.jsonl')], wt).status).toBe(0);
|
||||
return run(['verify', '--ledger', ledger], wt);
|
||||
};
|
||||
return { c, send, take, forge, verify };
|
||||
};
|
||||
@@ -952,8 +965,9 @@ describe('reading the REVIEWED_TREE line (GST-482 review fixes)', () => {
|
||||
const out = tmp();
|
||||
const ledger = path.join(out, 'review-ledger.jsonl');
|
||||
const merged = path.join(out, 'merged.jsonl');
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const file = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head]).stdout, 'file');
|
||||
const wt = cleanCheckout();
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: wt, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const file = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head], wt).stdout, 'file');
|
||||
run(['sent', '--ledger', ledger, '--role', 'outside-voice', '--sent', file]);
|
||||
const reply = path.join(out, 'r.out');
|
||||
fs.writeFileSync(reply, '1. **CRITICAL**: auth bypass in a.ts:3\nBlocks: yes\n\nRecommendation: request changes\n');
|
||||
@@ -973,16 +987,18 @@ describe('reading the REVIEWED_TREE line (GST-482 review fixes)', () => {
|
||||
test('the fingerprint step opens the brief and its command prints a line collect accepts; GST-850 gpt-6.1-sol replies stay refused (GST-897)', () => {
|
||||
const out = tmp();
|
||||
const ledger = path.join(out, 'review-ledger.jsonl');
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const file = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head]).stdout, 'file');
|
||||
const wt = cleanCheckout();
|
||||
const wtTop = fs.realpathSync(wt);
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: wt, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const file = field(run(['render', '--role', 'outside-voice', '--out', out, '--diff-base', head], wt).stdout, 'file');
|
||||
const brief = fs.readFileSync(file, 'utf8');
|
||||
const first = brief.split('\n')[0]!;
|
||||
expect(first).toStartWith(`First step, before anything else: run \`cd '${top}' && echo "REVIEWED_TREE: `);
|
||||
expect(first).toStartWith(`First step, before anything else: run \`cd '${wtTop}' && echo "REVIEWED_TREE: `);
|
||||
expect(first).toContain('Copy that output line, not the command, as the first line of your final reply');
|
||||
expect(brief.slice(brief.lastIndexOf('\n\n') + 2)).toContain('(the output, not the command)');
|
||||
const command = /run `([^`]+)`/.exec(first)![1]!;
|
||||
const printed = spawnSync('bash', ['-c', command], { cwd: os.tmpdir(), encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
expect(checkReviewedTree(printed + '\nNO FINDINGS', expected).ok).toBe(true);
|
||||
expect(checkReviewedTree(printed + '\nNO FINDINGS', `${tree} ${wtTop}`).ok).toBe(true);
|
||||
run(['sent', '--ledger', ledger, '--role', 'outside-voice', '--sent', file]);
|
||||
for (const p of ['p1', 'p2']) {
|
||||
const reply = path.join(ROOT, `test/fixtures/review-wrong-tree/gpt-6.1-sol-gst850-${p}.out`);
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
/**
|
||||
* review_exclude_paths and the reviewer diff ceiling (GST-508, docs/ship-policy.md#review-exclude-paths): what the base
|
||||
* policy excludes and keeps, what every brief's diff commands read, the receipt binding, the base-policy read, the
|
||||
* argument-byte bound and the REVIEW_DIFF_TOO_LARGE / REVIEW_DIFF_UNREADABLE lines.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { KEEP_ARG_MAX_BYTES, readSelection, reviewExclude, tooLargeLine, unreadableLine } from '../lib/review-exclude';
|
||||
import { collectCommit, collectLive } from '../lib/review-collect';
|
||||
import { extractReceipt } from '../lib/ship-receipt';
|
||||
import { bindShippedReceipt, receiptReviewAtHead } from '../lib/ship-receipt-depth';
|
||||
import { REVIEW_EXCLUDE_KEY_VERSION, isUnavailable } from '../lib/ship-policy';
|
||||
import { loadPolicyAt } from '../lib/ship-policy-at';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, write, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
const policyText = (patterns: string[]) => JSON.stringify({ review_exclude_paths: patterns, min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION }) + '\n';
|
||||
const GZ = Buffer.from([0x1f, 0x8b, 0, 1, 2, 3, 0, 0]);
|
||||
const EXCLUDED = ['receipts/a/result.json', 'receipts/a/trial.gz', 'receipts/config/blob.bin', 'receipts/c/result.json', 'receipts/e/result.json', 'receipts/notes.md'];
|
||||
const KEPT = ['receipts/b/result.json', 'receipts/d/fixture.json', 'receipts/run.sh'];
|
||||
|
||||
/** A results branch: receipts/** on the base policy, receipts of every kind on the branch. */
|
||||
function census(patterns: string[] | null = ['receipts/**']): FixtureRepo {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: patterns ? { '.gstack/ship-policy.json': policyText(patterns) } : {} });
|
||||
repos.push(repo);
|
||||
for (const [rel, bytes] of [['receipts/a/trial.gz', GZ], ['receipts/config/blob.bin', GZ]] as const) {
|
||||
fs.mkdirSync(path.dirname(path.join(repo.work, rel)), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, rel), bytes);
|
||||
}
|
||||
write(repo.work, 'receipts/run.sh', '#!/bin/sh\necho run\n');
|
||||
fs.chmodSync(path.join(repo.work, 'receipts/run.sh'), 0o755);
|
||||
repo.git('add', 'receipts/run.sh');
|
||||
repo.git('update-index', '--chmod=+x', 'receipts/run.sh');
|
||||
commit(repo, {
|
||||
'receipts/a/result.json': '{"cost_usd": 12.5, "pass_rate": "97%"}\n',
|
||||
'receipts/b/result.json': '{"ok": true}\n',
|
||||
'receipts/c/result.json': '{"ok": true}\n',
|
||||
'receipts/d/fixture.json': '{"ok": true}\n',
|
||||
'receipts/e/result.json': '{"ok": true}\n',
|
||||
'receipts/notes.md': '# notes\n',
|
||||
'docs/receipts-manifest.json': JSON.stringify(['receipts/c/result.json', 'receipts/a/trial.gz']) + '\n',
|
||||
'lib/reader.js': "exports.p = 'receipts/b/result.json';\nexports.q = 'result.json';\n",
|
||||
'test/d.test.js': "const f = 'receipts/d/fixture.json';\n",
|
||||
});
|
||||
return repo;
|
||||
}
|
||||
const plan = (repo: FixtureRepo, extra: string[] = []) => runBin(repo, 'gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', ...extra]);
|
||||
const mergeBase = (repo: FixtureRepo) => repo.git('merge-base', 'origin/main', 'HEAD');
|
||||
/** The paths one diff command from a plan line or a brief reads (run as --name-only in the fixture). */
|
||||
function pathsRead(repo: FixtureRepo, cmd: string, diffBase: string): string[] {
|
||||
const named = cmd.replace(/^git diff( --stat| --name-status)?/, 'git diff --name-only').replace('<diff-base>', '"$DIFF_BASE"');
|
||||
const r = spawnSync('bash', ['-c', named], { cwd: repo.work, encoding: 'utf8', timeout: 30_000, env: { ...process.env, ...repo.env, DIFF_BASE: diffBase } });
|
||||
expect({ cmd: named, status: r.status, err: r.stderr }).toMatchObject({ cmd: named, status: 0 });
|
||||
return r.stdout.split('\n').filter(Boolean);
|
||||
}
|
||||
/** Rewrite the base: commit on main, push, and merge it into the feature branch. */
|
||||
function onBase(repo: FixtureRepo, files: Record<string, string>) {
|
||||
repo.git('checkout', '-q', 'main');
|
||||
commit(repo, files, 'base change');
|
||||
repo.git('push', '-q', 'origin', 'main');
|
||||
repo.git('checkout', '-q', 'feature');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
||||
}
|
||||
|
||||
describe('what review_exclude_paths excludes and keeps', () => {
|
||||
// Value: protects=a results PR's receipts leave the reviewers' diff while code, executables and files a program names stay;
|
||||
// fails_when=a binary file under config/ is kept, a file named only by a data manifest or by its basename is kept, or a
|
||||
// file a test names by full path is excluded; why_new=GST-508 adds the selection; seam=bin/gstack-review-plan on a real
|
||||
// repository and git running the printed commands; no_claim=references by relative path or directory (REVIEW_EXCLUDE_REFERENCE)
|
||||
test('binary, data and docs files are excluded; only a code or test file naming the full path keeps one', () => {
|
||||
const repo = census();
|
||||
const p = JSON.parse(plan(repo, ['--json']).out);
|
||||
expect(p.review_exclude.kept_files).toEqual([
|
||||
{ path: 'receipts/b/result.json', reason: 'named-by-code' },
|
||||
{ path: 'receipts/d/fixture.json', reason: 'named-by-code' },
|
||||
{ path: 'receipts/run.sh', reason: 'executable' },
|
||||
]);
|
||||
expect(p.review_exclude).toMatchObject({ state: 'active', excluded: EXCLUDED.length, content: { binary: 2, data: 3, docs: 1, log: 0 } });
|
||||
const text = plan(repo).out;
|
||||
expect(text).toContain(`REVIEW_EXCLUDE: patterns=1/1 excluded=${EXCLUDED.length} `);
|
||||
expect(text).toContain(' content=binary:2,data:3,docs:1 ');
|
||||
const mb = mergeBase(repo);
|
||||
const cmds = text.split('\n').filter(l => /^DIFF_(CMD|KEEP): /.test(l)).map(l => l.replace(/^DIFF_(CMD|KEEP): \S+ /, ''));
|
||||
expect(cmds.length).toBeGreaterThan(2);
|
||||
const read = new Set(cmds.flatMap(c => pathsRead(repo, c, mb)));
|
||||
for (const f of EXCLUDED) expect(read.has(f)).toBe(false);
|
||||
for (const f of KEPT) expect(read.has(f)).toBe(true);
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the Red Team, the security specialist, the adversarial pass and the outside voice read the same selection
|
||||
// as the plan, including through the fixture-handling command; fails_when=any brief's git diff command (or the embedded
|
||||
// outside-voice diff) shows an excluded file, or a kept file is unreachable from a brief; why_new=task 8 (the fixture
|
||||
// command had no exclude slot); seam=gstack-review-dispatch pass/stage/render and git; no_claim=what a model does with the brief
|
||||
test('every brief\'s git diff commands leave excluded files out and reach the kept ones', () => {
|
||||
const repo = census();
|
||||
const out = path.join(repo.root, 'pass');
|
||||
expect(runBin(repo, 'gstack-review-dispatch', ['pass', '--base', 'main', '--out', out, '--pass', 'p1', '--', '--gate-tagged', '0']).status).toBe(EXIT.ok);
|
||||
expect(runBin(repo, 'gstack-review-dispatch', ['stage', '--manifest', path.join(out, 'pass-manifest.json'), '--stage', 'voices']).status).toBe(EXIT.ok);
|
||||
const m = JSON.parse(fs.readFileSync(path.join(out, 'pass-manifest.json'), 'utf8'));
|
||||
const reader = m.readers.find((r: any) => r.role === 'adversarial-native');
|
||||
const mb = mergeBase(repo);
|
||||
const slots = ['--base', 'main', '--diff-base', mb, '--exclude', reader.exclude, '--keep', ['--', ...reader.keep.map((k: string) => `'${k}'`)].join(' '), '--disclosure', m.disclosure];
|
||||
for (const role of [['specialist', '--name', 'security'], ['red-team', '--specialists', '1'], ['outside-voice']]) {
|
||||
const r = runBin(repo, 'gstack-review-dispatch', ['render', '--role', ...role, '--out', path.join(out, 'briefs'), ...slots]);
|
||||
expect(r.status).toBe(EXIT.ok);
|
||||
}
|
||||
const briefs = fs.readdirSync(path.join(out, 'briefs')).filter(f => f.endsWith('.md')).map(f => fs.readFileSync(path.join(out, 'briefs', f), 'utf8'));
|
||||
expect(briefs.length).toBe(5);
|
||||
const cmds = [...new Set(briefs.flatMap(b => [...b.matchAll(/`[^`\n]*?(git diff [^`\n]*)`/g)].map(x => x[1]!)))];
|
||||
expect(cmds.some(c => c.includes("'*fixture*'"))).toBe(true);
|
||||
const read = new Set(cmds.flatMap(c => pathsRead(repo, c, mb)));
|
||||
for (const f of EXCLUDED) expect(read.has(f)).toBe(false);
|
||||
for (const f of KEPT) expect(read.has(f)).toBe(true);
|
||||
const outside = briefs.find(b => b.includes('## Branch diff'))!;
|
||||
expect(outside).toContain(`git diff "$DIFF_BASE" -- . ${m.readers[0].policy_exclude} and git diff "$DIFF_BASE" -- '${reader.keep[0]}'`);
|
||||
for (const f of EXCLUDED) expect(outside).not.toContain(`diff --git a/${f}`);
|
||||
expect(outside).toContain('diff --git a/receipts/b/result.json');
|
||||
for (const b of briefs) expect(b).toContain(`(selection ${m.review_exclude.digest})`);
|
||||
}, 180_000);
|
||||
|
||||
// Value: protects=Step 11's standalone targeted render cannot record a brief with no selection beside the pass's briefs;
|
||||
// fails_when=render --role targeted without --disclosure writes a rendered event with no exclude digest, so verify sees
|
||||
// mixed digests and never prints VERIFY: clean; why_new=/ship review of the GST-508 wave (Red Team); seam=gstack-review-dispatch render
|
||||
test('a standalone targeted render under an active exclusion refuses and leaves the ledger as the pass wrote it', () => {
|
||||
const repo = census();
|
||||
const out = path.join(repo.root, 'pass');
|
||||
expect(runBin(repo, 'gstack-review-dispatch', ['pass', '--base', 'main', '--out', out, '--pass', 'p1', '--', '--gate-tagged', '0']).status).toBe(EXIT.ok);
|
||||
const ledger = path.join(out, 'review-ledger.jsonl');
|
||||
const before = fs.readFileSync(ledger, 'utf8');
|
||||
const r = runBin(repo, 'gstack-review-dispatch', ['render', '--role', 'targeted', '--classes', 'money', '--base', 'main', '--diff-base', mergeBase(repo), '--out', out]);
|
||||
expect(r.status).not.toBe(EXIT.ok);
|
||||
expect(r.err).toContain("review_exclude_paths is active, so the targeted reader renders in the pass manifest's voices stage");
|
||||
expect(fs.readFileSync(ledger, 'utf8')).toBe(before);
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=excluded receipts cannot dispatch the outside voice or the targeted money reader on lines no reader sees,
|
||||
// and a credential line inside a matched file keeps it; fails_when=scanNumbers or targetedClasses read excluded lines, or
|
||||
// a secret-bearing data file is excluded; why_new=task 9; seam=bin/gstack-review-plan; no_claim=pregate's credential scan
|
||||
test('excluded lines feed neither the numeric scan nor the targeted classes; a credential line keeps its file', () => {
|
||||
const files = { 'receipts/r.json': '{"cost_usd": 12.5, "price_usd": 3, "pass_rate": "97%", "latency_ms": 180}\n', 'docs/bench.md': '# bench\n', 'receipts/s.json': '{"cmd": "curl -H $OPENAI_API_KEY"}\n' };
|
||||
const control = makeFixtureRepo({ prefix: 'gstack-exclude-' }); repos.push(control);
|
||||
commit(control, files);
|
||||
const with_ = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['receipts/**']) } }); repos.push(with_);
|
||||
commit(with_, files);
|
||||
const c = JSON.parse(plan(control, ['--json']).out);
|
||||
const w = JSON.parse(plan(with_, ['--json']).out);
|
||||
expect(c.numbers.publishes).toBe(true);
|
||||
expect(c.targeted.classes).toEqual(['money', 'secret']);
|
||||
expect(w.review_exclude.kept_files).toEqual([{ path: 'receipts/s.json', reason: 'secret-line' }]);
|
||||
expect(w.numbers.publishes).toBe(false);
|
||||
expect(w.targeted.classes).toEqual(['secret']);
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('the base policy read', () => {
|
||||
// Value: protects=a base the plan cannot read never turns exclusion off quietly; fails_when=a missing blob or a bad commit
|
||||
// reads as no policy, or an invalid base key plans without exclusion; why_new=task 6; seam=loadPolicyAt and the plan CLI;
|
||||
// no_claim=the head copy's validation (gstack-ship-policy validate)
|
||||
test('no file reads as defaults; an unreadable object or commit is unavailable; an invalid base key refuses the plan', () => {
|
||||
const none = census(null);
|
||||
const sha = none.git('rev-parse', 'origin/main');
|
||||
const absent = loadPolicyAt(none.work, sha, 'origin/main');
|
||||
expect(isUnavailable(absent)).toBe(false);
|
||||
expect(!isUnavailable(absent) && absent.policy.review_exclude_paths).toEqual([]);
|
||||
expect(isUnavailable(loadPolicyAt(none.work, 'f'.repeat(40), 'origin/main'))).toBe(true);
|
||||
|
||||
const gone = census();
|
||||
const blob = gone.git('rev-parse', 'origin/main:.gstack/ship-policy.json');
|
||||
fs.rmSync(path.join(gone.work, '.git/objects', blob.slice(0, 2), blob.slice(2)));
|
||||
const unread = loadPolicyAt(gone.work, gone.git('rev-parse', 'origin/main'), 'origin/main');
|
||||
expect(isUnavailable(unread)).toBe(true);
|
||||
const r = plan(gone);
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toContain('POLICY_SOURCE_UNAVAILABLE');
|
||||
|
||||
const bad = census([':(icase)receipts/**']);
|
||||
const b = plan(bad);
|
||||
expect(b.status).toBe(EXIT.refused);
|
||||
expect(b.err).toContain('review_exclude_paths[0]');
|
||||
expect(b.err).toContain('(POLICY_INVALID)');
|
||||
expect(b.out).not.toContain('DISPATCH:');
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('the kept-file command is bounded by argument bytes', () => {
|
||||
// Value: protects=the DIFF_KEEP command stays under the Windows command line however many kept files a pattern has, and a
|
||||
// disjoint small pattern still applies; fails_when=a pattern whose kept files pass KEEP_ARG_MAX_BYTES is applied, or the plan
|
||||
// does not say why it was not; why_new=task 10; seam=bin/gstack-review-plan; no_claim=a real Windows launch
|
||||
test('a pattern whose kept files pass the bound is not applied and the plan says why; a disjoint small pattern applies', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['big/**', 'small/**']) } }); repos.push(repo);
|
||||
const long = 'x'.repeat(180);
|
||||
for (let k = 0; k < 140; k++) {
|
||||
write(repo.work, `big/${long}-${k}.sh`, '#!/bin/sh\n');
|
||||
fs.chmodSync(path.join(repo.work, `big/${long}-${k}.sh`), 0o755);
|
||||
}
|
||||
commit(repo, { 'big/data.json': '{}\n', 'small/data.json': '{}\n', 'lib/a.js': 'exports.a = 1;\n' });
|
||||
const text = plan(repo).out;
|
||||
expect(text).toMatch(new RegExp(`REVIEW_EXCLUDE: patterns=1/2 .* skipped=big/\\*\\*:kept=140:bytes=\\d+ \\(kept files over ${KEEP_ARG_MAX_BYTES} argument bytes: pattern not applied\\)`));
|
||||
const cmd = text.split('\n').find(l => l.startsWith('DIFF_CMD: '))!;
|
||||
expect(cmd).toContain("':(top,exclude,glob)small/**'");
|
||||
expect(cmd).not.toContain('big/**');
|
||||
expect(text).not.toContain('DIFF_KEEP:');
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('the review ceiling lines', () => {
|
||||
const d = { bytes: 3_500_000, byDir: [['results', 3_000_000], ['src', 500_000]] as Array<[string, number]> };
|
||||
// Value: protects=a REVIEW_DIFF_TOO_LARGE stop names the one fix that applies, with JSON a person can paste; fails_when=the
|
||||
// fix ignores where the policy stands or prints a placeholder version; why_new=task 4; seam=tooLargeLine; no_claim=the bytes git reports
|
||||
test('the fix branches on no key, head-only, a skipped pattern and still over, with pasteable JSON at the key version', () => {
|
||||
const json = (line: string) => JSON.parse(line.match(/land (\{.*?\}) in /)![1]!);
|
||||
const none = tooLargeLine('ctx', 'batched', d, { state: 'none', base: 'main', source: 'origin/main@abc' }).line;
|
||||
expect(json(none)).toEqual({ review_exclude_paths: ['results/**'], min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION });
|
||||
expect(none).toContain('then bring main into this branch and rerun once; if it is still over, split the PR');
|
||||
const head = tooLargeLine('ctx', 'batched', d, { state: 'head-only', base: 'main', source: 'origin/main@abc', headPatterns: ['results/**'] }).line;
|
||||
expect(head).toContain('this branch declares review_exclude_paths, but only the copy on main applies');
|
||||
const skipped = tooLargeLine('ctx', 'batched', d, { state: 'active', base: 'main', source: 'origin/main@abc', record: { patterns: ['results/**'], skipped: [{ pattern: 'results/**', kept: 900, bytes: 40_000 }], excluded: 0 } }).line;
|
||||
expect(skipped).toContain('pattern results/** was not applied: its 900 kept files need 40000 argument bytes');
|
||||
const over = tooLargeLine('ctx', 'batched', d, { state: 'active', base: 'main', source: 'origin/main@abc', floor: '1.300.0.0', record: { patterns: ['receipts/**'], skipped: [], excluded: 12 } }).line;
|
||||
expect(over).toContain('still over after excluding 12 files');
|
||||
expect(json(over)).toEqual({ review_exclude_paths: ['receipts/**', 'results/**'], min_gstack_version: '1.300.0.0' });
|
||||
expect(over).toEndWith('nothing was written (REVIEW_DIFF_TOO_LARGE)');
|
||||
});
|
||||
|
||||
// Value: protects=a REVIEW_DIFF_UNREADABLE stop says timeout or git exit, the timeout, and keeps full stderr in a file with
|
||||
// remote URLs redacted; fails_when=a credential-bearing remote URL reaches the line or the log, or the fix ignores the
|
||||
// reason; why_new=task 5; seam=readSelection and unreadableLine; no_claim=a real 120-second timeout
|
||||
test('a git exit and a timeout name their reason, the timeout and a redacted log file', () => {
|
||||
const repo = census();
|
||||
const r = readSelection(repo.work, 'f'.repeat(40), []);
|
||||
expect(r).toMatchObject({ ok: false, reason: 'git-exit', exit: 128 });
|
||||
if (r.ok) return;
|
||||
const logDir = path.join(repo.root, 'run');
|
||||
const line = unreadableLine('ctx', 'specialist/security', { ...r, stderr: `fatal: unable to access ${['https://bot', 'tok_fixture'].join(':')}${'@'}example.invalid/o/r.git/\nmore\n` }, 'f'.repeat(40), 'main', logDir);
|
||||
expect(line).toContain('reason=git-exit exit=128 timeout_ms=120000');
|
||||
expect(line).toContain('fix: git fetch origin main, then rerun once');
|
||||
expect(line).not.toContain('tok_fixture');
|
||||
const log = fs.readFileSync(path.join(logDir, 'diff-specialist_security.stderr'), 'utf8');
|
||||
expect(log).toContain('<url>');
|
||||
expect(log).not.toContain('tok_fixture');
|
||||
const slow = unreadableLine('ctx', 'batched', { ok: false, reason: 'timeout', exit: null, stderr: '', timeoutMs: 120_000 }, 'f'.repeat(40), 'main', logDir);
|
||||
expect(slow).toContain('reason=timeout exit=none timeout_ms=120000');
|
||||
expect(slow).toContain('rerun once unchanged; if it times out again, split the PR');
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
describe('the receipt binds the selection the reviewers read', () => {
|
||||
const receiptIn = (body: string) => extractReceipt(fs.readFileSync(body, 'utf8')).receipt!;
|
||||
const writeReceipt = (repo: FixtureRepo, body: string, extra: string[]) =>
|
||||
runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body, ...extra]);
|
||||
const targetedAtHead = (repo: FixtureRepo) => ['--review-targeted', JSON.stringify({ classes: ['money', 'gate', 'auth', 'secret'], rules: 'r', brief_sha: 'a'.repeat(64), status: 'done', findings: 0, raised_by: 'targeted', head: repo.git('rev-parse', 'HEAD') })];
|
||||
// Value: protects=a docs-only range whose only file sits under a base pattern and carries a gate tag binds the same selection at
|
||||
// plan and receipt write, so the receipt can be written; fails_when=receiptReviewAtHead skips the gate scan when the paths are
|
||||
// docs-class and excludes the file the plan kept as gate-tagged (/ship review of #3852, red-team#1: digests 652d0aa8 vs
|
||||
// 6f33bd56, RECEIPT_INVALID with no fix); why_new=every other receipt case has a code path in its range; seam=gstack-review-plan
|
||||
// --json and receiptReviewAtHead on one head; no_claim=the gate scan's own tag rules
|
||||
test('a docs-only range with a gate-tagged file under a pattern binds the plan\'s digest at receipt write', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-docs-', baseFiles: { '.gstack/ship-policy.json': policyText(['testdata/**']) } });
|
||||
repos.push(repo);
|
||||
const head = commit(repo, { 'testdata/expected.txt': 'expected output\n' });
|
||||
const planned = JSON.parse(runBin(repo, 'gstack-review-plan', ['--base', 'main', '--json']).out).review_exclude;
|
||||
expect(planned.kept_files).toEqual([{ path: 'testdata/expected.txt', reason: 'gate-tagged' }]);
|
||||
const prior = process.env.GSTACK_STATE_ROOT;
|
||||
process.env.GSTACK_STATE_ROOT = path.join(repo.root, 'receipt-state');
|
||||
let review: ReturnType<typeof receiptReviewAtHead>;
|
||||
try { review = receiptReviewAtHead(repo.work, 'main', path.join(import.meta.dir, '..', 'bin'), head); }
|
||||
finally { if (prior === undefined) delete process.env.GSTACK_STATE_ROOT; else process.env.GSTACK_STATE_ROOT = prior; }
|
||||
const { exclude } = review;
|
||||
expect(exclude.state === 'active' ? exclude.record.digest : exclude.state).toBe(planned.digest);
|
||||
});
|
||||
// Value: protects=a receipt names the selection the rendered briefs read, a base merge that leaves the policy alone still
|
||||
// carries, and a policy change on the base (adding or removing a pattern) needs a new review, not a write; fails_when=write
|
||||
// records a digest the briefs never named, carry compares the base sha, or a removed exclusion clears by writing the old
|
||||
// digest; why_new=tasks 2 and 7; seam=gstack-review-dispatch verify, gstack-ship-receipt write/carry, bindShippedReceipt;
|
||||
// no_claim=the merge train's own refusal wording
|
||||
test('verify names the briefs\' digest; write binds it; a neutral base merge carries; a policy edit refuses write and carry', () => {
|
||||
const repo = census();
|
||||
const out = path.join(repo.root, 'pass');
|
||||
expect(runBin(repo, 'gstack-review-dispatch', ['pass', '--base', 'main', '--out', out, '--pass', 'p1', '--', '--gate-tagged', '0']).status).toBe(EXIT.ok);
|
||||
expect(runBin(repo, 'gstack-review-dispatch', ['stage', '--manifest', path.join(out, 'pass-manifest.json'), '--stage', 'voices']).status).toBe(EXIT.ok);
|
||||
const v = runBin(repo, 'gstack-review-dispatch', ['verify', '--ledger', path.join(out, 'review-ledger.jsonl')]);
|
||||
const digest = v.out.match(/^REVIEW_EXCLUDE_RECORD: digest=([0-9a-f]{64}) /m)?.[1];
|
||||
expect(digest).toBe(JSON.parse(plan(repo, ['--json']).out).review_exclude.digest);
|
||||
const body = path.join(repo.root, 'body.md');
|
||||
const missing = writeReceipt(repo, body, []);
|
||||
expect(missing.status).toBe(EXIT.fail);
|
||||
expect(missing.err).toContain(`field=review_exclude expected=${digest} recorded=none source=origin/main@`);
|
||||
expect(missing.err).toContain('gstack-review-dispatch verify --ledger <ledger>');
|
||||
expect(fs.existsSync(body)).toBe(false);
|
||||
expect(writeReceipt(repo, body, ['--review-exclude', digest!, ...targetedAtHead(repo)]).status).toBe(EXIT.ok);
|
||||
expect(receiptIn(body).review_exclude).toMatchObject({ digest, excluded: EXCLUDED.length, kept: KEPT.length });
|
||||
|
||||
onBase(repo, { 'docs/other.md': '# other\n' });
|
||||
const carried = runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
|
||||
expect(carried.status).toBe(EXIT.ok);
|
||||
expect(receiptIn(body).review_exclude!.digest).toBe(digest!);
|
||||
|
||||
onBase(repo, { '.gstack/ship-policy.json': policyText(['receipts/**', 'results/**']) });
|
||||
const refused = runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
|
||||
expect(refused.status).toBe(EXIT.refused);
|
||||
expect(refused.err).toContain(`review_exclude changed: recorded=${digest}`);
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const queue = bindShippedReceipt(repo.work, 'origin/main', fs.readFileSync(body, 'utf8').replace(/head: \S+/, `head: ${head}`), undefined, [head]);
|
||||
expect(queue.ok).toBe(false);
|
||||
|
||||
onBase(repo, { '.gstack/ship-policy.json': JSON.stringify({}) + '\n' });
|
||||
const removed = writeReceipt(repo, path.join(repo.root, 'body2.md'), ['--review-exclude', digest!]);
|
||||
expect(removed.status).toBe(EXIT.fail);
|
||||
expect(removed.err).toContain(`field=review_exclude expected=none recorded=${digest}`);
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
describe('a branch cannot hide code under a base pattern', () => {
|
||||
// Value: protects=a branch cannot hide code or a link under a base-declared pattern, and untracked files never move the
|
||||
// selection away from the committed head the receipt reads; fails_when=the branch's .gitattributes makes a code file
|
||||
// binary content, a NUL-bearing code file is excluded as binary, a symlink is excluded as data, or an untracked file under a pattern changes the plan's digest;
|
||||
// why_new=/ship pass-1 security and Red Team findings on GST-508, each reproduced before the fix; seam=bin/gstack-review-plan;
|
||||
// no_claim=gitlinks (the same mode rule, no fixture)
|
||||
test('a branch .gitattributes cannot make code binary, a symlink is kept, and an untracked file leaves the digest alone', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['receipts/**']) } }); repos.push(repo);
|
||||
fs.mkdirSync(path.join(repo.work, 'receipts'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, 'receipts/real.gz'), GZ);
|
||||
fs.symlinkSync('../.env', path.join(repo.work, 'receipts/config.json'));
|
||||
commit(repo, { '.gitattributes': 'receipts/** binary\n', 'receipts/evil.ts': 'export const run = () => 1;\n', 'receipts/a.json': '{}\n' });
|
||||
const p = JSON.parse(plan(repo, ['--json']).out);
|
||||
expect(p.review_exclude.kept_files).toEqual([
|
||||
{ path: 'receipts/config.json', reason: 'link' },
|
||||
{ path: 'receipts/evil.ts', reason: 'code' },
|
||||
]);
|
||||
expect(p.review_exclude.content).toMatchObject({ binary: 1, data: 1 });
|
||||
write(repo.work, 'receipts/stray/result.json', '{"ok": true}\n');
|
||||
expect(JSON.parse(plan(repo, ['--json']).out).review_exclude.digest).toBe(p.review_exclude.digest);
|
||||
}, 120_000);
|
||||
test('a binary file at a code path stays kept and still forces full depth; a .gz stays binary content', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['assets/**']) } }); repos.push(repo);
|
||||
fs.mkdirSync(path.join(repo.work, 'assets'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, 'assets/loader.js'), '/* \0 */ require("child_process").exec("id");\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'assets/real.gz'), GZ);
|
||||
commit(repo, {});
|
||||
const p = JSON.parse(plan(repo, ['--json']).out);
|
||||
expect(p.review_exclude.kept_files).toEqual([{ path: 'assets/loader.js', reason: 'code' }]);
|
||||
expect(p.review_exclude.content).toMatchObject({ binary: 1 });
|
||||
expect(p).toMatchObject({ depth: 'full', errors: expect.arrayContaining([expect.objectContaining({ code: 'binary_code_path', input: 'assets/loader.js' })]) });
|
||||
}, 120_000);
|
||||
|
||||
test('an unavailable gate scan keeps every candidate instead of excluding it', () => {
|
||||
const repo = census();
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const baseSha = repo.git('rev-parse', 'origin/main');
|
||||
const c = collectCommit(repo.work, baseSha, head);
|
||||
const at = (gateTagged: ReadonlySet<string> | null) => reviewExclude({ root: repo.work, baseSha, ref: 'origin/main', mergeBase: c.mergeBase!, head, perPath: c.perPath, added: c.added, classRoot: c.root ?? [], gateTagged, context: 'test' });
|
||||
const scanned = at(new Set());
|
||||
expect(scanned.state === 'active' && [...scanned.excluded].sort()).toEqual([...EXCLUDED].sort());
|
||||
const blind = at(null);
|
||||
expect(blind.state).toBe('active');
|
||||
if (blind.state !== 'active') return;
|
||||
expect(blind.excluded.size).toBe(0);
|
||||
expect(blind.kept.filter(k => k.reason === 'gate-scan-unavailable').map(k => k.path).sort()).toEqual([...EXCLUDED, 'receipts/b/result.json', 'receipts/d/fixture.json'].sort());
|
||||
}, 120_000);
|
||||
|
||||
test.skipIf(process.platform === 'win32' || process.getuid?.() === 0)('a live binary file whose bytes cannot be read is kept, not excluded', () => {
|
||||
const repo = census();
|
||||
const gz = path.join(repo.work, 'receipts/a/shot.png');
|
||||
fs.writeFileSync(gz, Buffer.from([0x89, 0x50, 0, 1]));
|
||||
commit(repo, {});
|
||||
fs.writeFileSync(gz, Buffer.from([0x89, 0x50, 0, 2]));
|
||||
fs.chmodSync(gz, 0o000);
|
||||
try {
|
||||
const c = collectLive(repo.work, 'origin/main');
|
||||
const x = reviewExclude({ root: repo.work, baseSha: repo.git('rev-parse', 'origin/main'), ref: 'origin/main', mergeBase: c.mergeBase!, perPath: [...c.perPath, { path: 'receipts/a/shot.png', lines: 0, binary: true }], added: c.added, classRoot: repo.work, gateTagged: new Set(), context: 'test' });
|
||||
expect(x.state).toBe('active');
|
||||
if (x.state !== 'active') return;
|
||||
expect(x.excluded.has('receipts/a/shot.png')).toBe(false);
|
||||
expect(x.kept).toContainEqual({ path: 'receipts/a/shot.png', reason: 'consumer-scan-unavailable' });
|
||||
} finally { fs.chmodSync(gz, 0o644); }
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the receipt (head blobs) and the plan (live files) agree on binary content past 256 MB of blobs; fails_when=
|
||||
// one git cat-file --batch read stops at its buffer and later blobs fall through to kept code, so the digests differ and
|
||||
// receipt write refuses on every rerun; why_new=/ship review of the GST-508 wave (Red Team, reproduced at 280 MB); seam=binaryContent
|
||||
test('head mode reads each blob\'s first 8,000 bytes, so blobs after 256 MB of others are still binary', () => {
|
||||
const repo = census();
|
||||
fs.mkdirSync(path.join(repo.work, 'receipts/big'), { recursive: true });
|
||||
const big = Buffer.alloc(270 * 1024 * 1024);
|
||||
fs.writeFileSync(path.join(repo.work, 'receipts/big/a.dat'), big);
|
||||
big[big.length - 1] = 1;
|
||||
fs.writeFileSync(path.join(repo.work, 'receipts/big/c.dat'), big);
|
||||
fs.writeFileSync(path.join(repo.work, 'receipts/big/b.dat'), GZ);
|
||||
commit(repo, {});
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const baseSha = repo.git('rev-parse', 'origin/main');
|
||||
const c = collectCommit(repo.work, baseSha, head);
|
||||
const atHead = reviewExclude({ root: repo.work, baseSha, ref: 'origin/main', mergeBase: c.mergeBase!, head, perPath: c.perPath, added: c.added, classRoot: c.root ?? [], gateTagged: new Set(), context: 'test' });
|
||||
const l = collectLive(repo.work, 'origin/main');
|
||||
const live = reviewExclude({ root: repo.work, baseSha, ref: 'origin/main', mergeBase: l.mergeBase!, perPath: l.perPath, added: l.added, classRoot: repo.work, gateTagged: new Set(), context: 'test' });
|
||||
expect(atHead.state === 'active' && [...atHead.excluded].filter(p => p.startsWith('receipts/big/')).sort()).toEqual(['receipts/big/a.dat', 'receipts/big/b.dat', 'receipts/big/c.dat']);
|
||||
expect(atHead.state === 'active' && live.state === 'active' && atHead.record.digest).toBe(live.state === 'active' ? live.record.digest : 'none');
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
@@ -57,22 +57,30 @@ const NO_LOSS_REPLAYS = {
|
||||
'PR-a': "GSTA-167 variant G Arm 4: structural plan identity at the 14 cohort heads and the free exact re-score of saved C, D and A' findings (parts 4a and 4b)",
|
||||
'G1': "GSTA-167 variant G Arm G1: live no-loss replay of both prose voices with part 1's prompts, 2 passes, normalizer v2, paired rule against pooled C' (parts 1 and 3; specialists at medium as in C and C2)",
|
||||
'L': "GSTA-167 variant G Arm L: live no-loss replay of one batched reader (testing and security plus scoped checklists) and the Red Team on its findings, 2 passes, scored L∘G1 against G1 on the paired rule (part 2)",
|
||||
'GST-508': "GST-508 (#3744, GSTA-202) preregistered no-loss replay of review_exclude_paths at ef2760f: Arm V found 33 of 41 blockers vs R 33 of 41, exact sign flip with delta 4, p_NI 0.0279 (pass); Arm P identical depth, dispatch and reader sets on 26 of 26 units (GStack Minder drive handoffs/GSTA-202/noloss-results.md)",
|
||||
'GST-257': "GST-257 PR 1 dispatch-superset no-loss check (test/review-targeted.test.ts): on every fixture diff the branch dispatches main's reviewers at 8be7f21 unchanged plus only the targeted reader, and over the last 100 non-release commits on main it lost none; adds the targeted role and brief to the G1 and L bytes, whose existing reviewer text is unchanged",
|
||||
'GST-464': "GST-464 brief-identity no-loss check (the brief-body test below): every reviewer brief lib/review-brief.ts cuts from ship/sections/review-army.md and adversarial.md is byte-identical to the bodies at the L and GST-257 pins; only lead instructions outside the cut spans changed",
|
||||
'GST-850': "GST-850 dispatch-superset no-loss check: on the 26 GSTA-167 no-loss units the branch plan (wider security and money classes, write-up text in the batched diff) drops no reviewer role main dispatches, so no saved blocker can be lost, and over the last 100 main commits no commit with a gate or risk class drops depth (test/review-risk-routing.test.ts, test/review-risk-linear.test.ts); reviewer text is unchanged",
|
||||
'GSTA-224 H1': 'GSTA-224 H1 preregistered no-loss run: the PR-type checklist against main\'s checklist and a no-gstack arm (Opus 5.5, 81 calls), 5 behavior cases, 10 Round 7 application blockers and 2 clean controls; every bar passed (handoffs/GSTA-224/h1-noloss-results.md)',
|
||||
'R51': "R51 risk-tier routing no-loss re-score (GSTA-167): the saved panel findings (349 records over 24 of the 26 no-loss units) re-scored against the branch's plan lose no blocker whose only finders are roles it drops, and every gate, security, user-data and money fixture keeps main's reviewers plus the full panel (test/review-targeted.test.ts, test/review-risk-routing.test.ts); reviewer text is unchanged",
|
||||
'GST-508+R51': "wave review-53cfb5bfe011 merge of #3744 into main: lib/review-depth.ts keeps both admitted changes, the GST-508 no-loss replay of review_exclude_paths (Arm V 33 of 41 blockers vs R 33 of 41, p_NI 0.0279; GStack Minder drive handoffs/GSTA-202/noloss-results.md) and the R51 risk-tier re-score with GST-850's dispatch-superset no-loss check: excluded paths sit beside the added and removed line maps, and the exclusion filter keeps the publishes-docs rule",
|
||||
'GST-508+GST-464': "wave review-53cfb5bfe011 merge of #3744 into main: ship/sections/review-army.md and adversarial.md carry the GST-508 no-loss-replayed exclude pathspec placeholders inside the brief bodies (handoffs/GSTA-202/noloss-results.md) and the GST-464 lead-instruction edits outside the cut spans, which its brief-identity no-loss check admitted",
|
||||
'GST-986': "GST-986 brief-identity no-loss check (the brief-body test below): every reviewer brief lib/review-brief.ts cuts from ship/sections/adversarial.md is byte-identical to the bodies at the GST-257 pin; only the lead's Step 11 instruction naming the targeted record's path changed, outside the cut spans",
|
||||
'GST-911-redos': "GST-911 ReDoS fix verdict-identity no-loss check (wave review-e7b551ebd865): SVG_REFUSED's url() entry, rewritten to run in linear time, refuses exactly the strings #3838's pattern refused (test/review-risk-redos.test.ts: 60,000 seeded strings and the hand-picked edges, and every SVG blob in the repository's history, with zero differences); SVG_MARKUP now refuses a DOCTYPE naming any document but W3C's SVG DTD (test/review-planner-misreads.test.ts), which only keeps more SVGs code and so drops no reviewer; GST-911's no-loss replay holds unchanged; reviewer text is unchanged",
|
||||
'GST-911': "GST-911 no-loss replay (GSTA-249/13): the planner over the last 100 first-parent main commits to f5cb6ec1e, origin/main's code against this branch, gate scan fixed at 0, changes no commit's depth, class, risk classes, targeted classes or SCOPE_AUTH; the three misreads (a drawing-only SVG, a session-named data file, a bare base) are proven on fixtures (test/review-planner-misreads.test.ts), where every SVG that can run script stays code with the security class; reviewer text is unchanged",
|
||||
'R51': "R51 risk-tier routing no-loss re-score (GSTA-167): the saved panel findings (349 records over 24 of the 26 no-loss units) re-scored against the branch's plan lose no blocker whose only finders are roles it drops, and every gate, security, user-data and money fixture keeps main's reviewers plus the full panel (test/review-targeted.test.ts, test/review-risk-routing.test.ts); reviewer text is unchanged",
|
||||
'GST-508+R51+GST-911': "wave review-53cfb5bfe011 merge of main 3d99c2249 (#3848) into #3852: lib/review-depth.ts keeps GST-508's review_exclude_paths (no-loss replay, GStack Minder drive handoffs/GSTA-202/noloss-results.md), R51 with GST-850's dispatch-superset no-loss check, and GST-911's SVG drawings with GST-911-redos (no-loss replay: 0 of 100 main commits changed, reports/GSTA-249-911-decisions.tsv; test/review-planner-misreads.test.ts, test/review-risk-redos.test.ts); lib/review-risk.ts is main's GST-911 bytes. Merged-head checks (handoffs/GSTA-202/merge-3d99c22-checks.md): Arm P on unit 3593 differs only in the exclude pathspec and the disclosure line, the same brief diff as before the merge, and GST-911 panel unit f5cb6ec1e plans, dispatches and renders byte-identical briefs under 3d99c2249 and the merged head",
|
||||
'GST-898': "GST-898 verdict-identity no-loss check: the linear rm rule, and the rmSync rule (which also raises security on any call with more than 500 characters before its closing parenthesis), give the same verdict as R51's on every changed line of the last 100 main commits (69,023 lines, a563f47 back 100 first-parent commits) and on 60,000 seeded lines per rule (test/review-risk-redos.test.ts), and no commit changes depth, class or risk class, so every diff dispatches main's reviewers unchanged; reviewer text is unchanged",
|
||||
'GST-967': "GST-967 dispatch-superset no-loss check (test/review-depth.test.ts, 'GST-967 dispatch-superset no-loss check'): over 1,440 planReview cases the branch plans exactly what main planned at 1022f4f except the 71 gate-class stops before Step 11, which add only Step 11's adversarial, outside and targeted voices, so no reviewer main dispatches is dropped or re-efforted; the brief bodies lib/review-brief.ts cuts from the ship sections hash to main's; only the lead's repeat-decision and Step 11 instructions changed; reviewer text is unchanged",
|
||||
'GST-508+GST-464+GST-967': "wave review-53cfb5bfe011 merge of main 68410828f into #3852: ship/sections/review-army.md and adversarial.md are main's GST-967 bytes plus exactly the GST-508+GST-464 lines (the merged file minus main equals the wave minus fc292e22f, line for line), so GST-967's dispatch-superset no-loss check and GST-508's no-loss replay both hold; merged-head checks in GStack Minder drive handoffs/GSTA-202/merge-6841-checks.md",
|
||||
'GST-508+R51+GST-911+GST-967': "wave review-53cfb5bfe011 merge of main 68410828f into #3852: lib/review-depth.ts is main's GST-967 bytes plus exactly the GST-508+R51+GST-911 lines (the merged file minus main equals the wave minus fc292e22f, line for line); GST-967's dispatch-superset no-loss check (test/review-depth.test.ts) passes on the merged file, and the GST-508+R51+GST-911 checks are rerun at the merged head (GStack Minder drive handoffs/GSTA-202/merge-6841-checks.md)",
|
||||
} as const;
|
||||
type Replay = keyof typeof NO_LOSS_REPLAYS;
|
||||
const REVIEWER_BRIEFS: Record<string, { sha: string; replay: Replay }> = {
|
||||
'ship/sections/review-army.md': { sha: '7c58dfd1bf1f16f967186a4872191cb16ebff3be81a50ebbf19067020af3ec53', replay: 'GST-967' },
|
||||
'ship/sections/adversarial.md': { sha: 'f492e2c1663b81f503872543e1ba616ff092ffeed23e7d993bd2f4d1bfcd5d9e', replay: 'GST-986' },
|
||||
'ship/sections/review-army.md': { sha: 'de3e0d35f2af56492c42fd287b6868fbe19bce96b86321e74a4947ba909b74eb', replay: 'GST-508+GST-464+GST-967' },
|
||||
'ship/sections/adversarial.md': { sha: '0142d6bc3f2a5bceb9f8b2adef1d3a206e5836c99a0667fe995568da2e80a5a6', replay: 'GST-508+GST-464+GST-967' },
|
||||
'review/sections/review-army.md': { sha: '78329b64640260cd8831ca81a9189f3f8dcade9c406431631d3f2cd798cd3967', replay: '#3638' },
|
||||
'review/sections/adversarial.md': { sha: 'e6962fa25b78f362654f2954f79683e524d2ebd452d1494f8a2b099888e8e255', replay: 'G1' },
|
||||
'review/checklist.md': { sha: '607788afeb2c83f2dff1dccd58d212616ec72393d28cda2fa18690c1a83df699', replay: '#3638' },
|
||||
'review/checklist.md': { sha: 'a32963ef38d9d3613c58c805e8517cd2e593c63769b30dd7d40e2592fa48fc78', replay: 'GSTA-224 H1' },
|
||||
'review/design-checklist.md': { sha: 'b9205f88313cc64902c0b13e9685722ab8138d3dcc58916154f47274abda7d83', replay: '#3638' },
|
||||
'review/gate-integrity.md': { sha: 'f570db344c9a01df633bcaa281d6017f4f12420fd3e0aa3078c1ce06e0df8332', replay: '#3638' },
|
||||
'review/specialists/api-contract.md': { sha: '263d23ac119dd601d315c191dbdbd503d47c00264c9c0ca81959559ca11d4e95', replay: '#3638' },
|
||||
@@ -86,17 +94,22 @@ const REVIEWER_BRIEFS: Record<string, { sha: string; replay: Replay }> = {
|
||||
'review/specialists/testing.md': { sha: 'd6cc2bef7be562387d0c0a22fefe646dff9c295f1d34d8453a6cb496584150e4', replay: '#3638' },
|
||||
'review/specialists/targeted.md': { sha: '7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5', replay: 'GST-257' },
|
||||
'scripts/resolvers/fix-check.ts': { sha: '712bf5b0c439e96bac32f19cbe25394dabb4c94aa66600100bfde9b100e15a08', replay: '#3638' },
|
||||
'lib/review-depth.ts': { sha: 'c5fd958b6c9a1116be9fc3418844239c01168476abb72c1db85bc26ab0adf4b4', replay: 'GST-967' },
|
||||
'lib/review-risk.ts': { sha: '126eff0f1de6982e03dc24d8017c67e6807c91dfa518b18d2db3aa910aac911f', replay: 'GST-911' },
|
||||
'lib/review-depth.ts': { sha: 'd76a9afcfadfe0a95b15428c04e6f7a88c6b0fa75591201c45f023fec2bb90db', replay: 'GST-508+R51+GST-911+GST-967' },
|
||||
'lib/review-risk.ts': { sha: '126eff0f1de6982e03dc24d8017c67e6807c91dfa518b18d2db3aa910aac911f', replay: 'GST-508+R51+GST-911' },
|
||||
};
|
||||
|
||||
/** The reviewer brief bodies lib/review-brief.ts cuts out of the ship sections, at the bytes replays L and GST-257 admitted. */
|
||||
/**
|
||||
* The reviewer brief bodies lib/review-brief.ts cuts out of the ship sections, at the bytes replays L and GST-257
|
||||
* admitted, except fixtures, redTeam and native, which carry the exclude pathspec placeholders the GST-508 replay
|
||||
* admitted (byte-identical to #3744 at 995e442). A section repin under GST-464 or GST-986 is valid only while every
|
||||
* body still hashes here: the section may change outside the cut spans, never inside them.
|
||||
*/
|
||||
const BRIEF_BODIES: Record<string, string> = {
|
||||
specialist: '1ebe47ddb3291a9e4fe90b5a260eb57e328144959549bc95c119b68d23652cb5',
|
||||
framing: 'aad667b5ea4c6d23d930dafffa38178c04be388cd4364fb73759fc92af17bb63',
|
||||
fixtures: '9517c86befe773e76acbf30a0642ed828e211b8ecb524325702072b26429ef16',
|
||||
redTeam: '1cca7957d13f9da08434870290b92958f37750207047b92c9aa52a802da789e8',
|
||||
native: 'ddb1041ec1e4dd373c3e4ab9017e49316e78c230055c1ef3db1bbba518b143a2',
|
||||
fixtures: 'fbe52f3a9e0f4442eb755f1747a95944b373b439bd05c61f3eb68345d1061a5b',
|
||||
redTeam: '6dd670ea040535ca6cceab81c29a395bb67ce5a2ab8fa2b81e51bc4711e4aada',
|
||||
native: 'a7cc08fb31b6ca65932a316d589f0b09677426d193d63f88ec74fee6d93ce053',
|
||||
outside: 'bd96406da28b03742384560425a333b6d6d7ed2be95bd2026c90e0039632cee2',
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,29 @@ describe('gstack-review-plan', () => {
|
||||
expect(r.stdout).toContain('REVIEW_PLAN: class=docs pass=1 next=full dispatches=0 numbers=no');
|
||||
expect(r.stdout).toContain('SKIP: outside-voice (docs class, no numeric claims)');
|
||||
});
|
||||
// Value: protects=a stale local main does not stand in for the base: a docs-only branch that merged a newer origin/main
|
||||
// plans as docs, not as the gate change origin/main already has (GST-462: #3597 was labeled gate code at full depth
|
||||
// until --base origin/main); fails_when=gstack-gate-diff or gstack-diff-scope diff against the local branch;
|
||||
// seam=a tracking ref moved with update-ref, as a fetch would; no_claim=nothing about a local main ahead of origin/main.
|
||||
test('a stale local main yields to origin/main: a docs-only branch that merged the newer origin/main plans as docs', () => {
|
||||
const r = repo({ 'docs/howto.md': '# How to\nStep one.\n' });
|
||||
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
||||
const testFile = (skip: boolean) => `import { test, expect } from 'bun:test';\ntest${skip ? '.skip' : ''}('adds', () => {\n expect(1 + 1).toBe(2);\n});\n`;
|
||||
git('checkout', '-q', 'main');
|
||||
fs.mkdirSync(path.join(r.dir, 'test'), { recursive: true });
|
||||
fs.writeFileSync(path.join(r.dir, 'test', 'add.test.ts'), testFile(false));
|
||||
git('add', '.'); git('commit', '-qm', 'tests');
|
||||
git('checkout', '-q', 'feat'); git('merge', '-q', '--no-edit', 'main'); git('checkout', '-q', 'main');
|
||||
fs.writeFileSync(path.join(r.dir, 'test', 'add.test.ts'), testFile(true));
|
||||
git('commit', '-qam', 'upstream skip');
|
||||
git('remote', 'add', 'origin', 'https://example.invalid/x.git');
|
||||
git('update-ref', 'refs/remotes/origin/main', 'HEAD');
|
||||
git('reset', '-q', '--hard', 'HEAD~1');
|
||||
git('checkout', '-q', 'feat'); git('merge', '-q', '--no-edit', 'origin/main');
|
||||
const plan = spawnSync(BIN, ['--base', 'main'], { cwd: r.dir, encoding: 'utf8', timeout: 60_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
||||
expect(plan.status).toBe(0);
|
||||
expect(plan.stdout).toContain('REVIEW_PLAN: class=docs pass=1 next=full dispatches=0 numbers=no');
|
||||
});
|
||||
test('a docs diff that publishes numbers keeps the outside voice', () => {
|
||||
const r = run(repo({ 'docs/bench.md': 'Median latency fell 42% to 180 ms.\n' }), []);
|
||||
expect(r.stdout).toContain('DISPATCH: outside-voice outside-voice effort=host');
|
||||
|
||||
@@ -339,6 +339,54 @@ describe('the targeted role end to end on a fixture repository', () => {
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('the /ship commands carry the targeted record to the receipt (GST-464)', () => {
|
||||
// Value: protects=when the targeted reader ran, the receipt /ship writes carries its record, so ready prints verdict=ok instead
|
||||
// of receipt=legacy (gstack-evals#95, #3682, #3612); fails_when=Step 11's verify writes the record nowhere Step 19 reads, the
|
||||
// Step 19 or handoff write command omits --review-targeted, or a record from an earlier run survives Step 9; seam=the generated
|
||||
// sections' own command text, expanded by bash and passed to gstack-ship-receipt write; no_claim=enforcement (report-only)
|
||||
test('Step 11 verify writes the record where Step 19 write reads it, a run without the reader writes none, and Step 9 clears it', () => {
|
||||
const section = (name: string) => fs.readFileSync(path.join(ROOT, 'ship', 'sections', `${name}.md`), 'utf8');
|
||||
const recordPath = /verify --targeted-out (\S+?)`/.exec(section('adversarial'))?.[1];
|
||||
expect(recordPath).toBe('.gstack/tmp/targeted.json');
|
||||
const writeLine = section('pr-body').split('\n').find(l => l.includes('gstack-ship-receipt write --pr'))!;
|
||||
const optional = /\$\(\[ -s (\S+) \] && echo (--review-targeted @\S+)\)/.exec(writeLine);
|
||||
expect(optional?.slice(1)).toEqual([recordPath!, `--review-targeted @${recordPath}`]);
|
||||
expect(section('handoff')).toContain(`When Step 11 saved \`${recordPath}\`, add \`--review-targeted @${recordPath}\` to that write.`);
|
||||
expect(fs.readFileSync(path.join(ROOT, 'ship', 'DRIVER.md'), 'utf8')).toContain('[--review-targeted @<f>] --body <body>');
|
||||
const entry = /Every entry also runs\n`([^`]+)`/.exec(section('review-army'))?.[1];
|
||||
expect(entry).toContain(`rm -f ${recordPath}`);
|
||||
|
||||
const repo = makeFixtureRepo({ prefix: 'targeted-wire-' });
|
||||
repos.push(repo);
|
||||
repo.git('checkout', '-q', '-b', 'feat');
|
||||
fs.mkdirSync(path.join(repo.work, 'src'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, 'src', 'charge.ts'), 'export const spend_cap_usd = 5;\n');
|
||||
repo.git('add', '-A'); repo.git('commit', '-q', '-m', 'charge');
|
||||
const expand = () => spawnSync('bash', ['-c', `printf '%s\\n' ${optional![0]}`], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).stdout.split('\n').filter(Boolean);
|
||||
expect(expand()).toEqual([]);
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack', 'tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, recordPath!), '{}\n');
|
||||
expect(spawnSync('bash', ['-c', entry!], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).status).toBe(0);
|
||||
expect(fs.existsSync(path.join(repo.work, recordPath!))).toBe(false);
|
||||
fs.rmSync(path.join(repo.work, '.gstack'), { recursive: true });
|
||||
expect(spawnSync('bash', ['-c', entry!], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).status).toBe(0);
|
||||
const exclude = path.join(repo.work, '.git', 'info', 'exclude');
|
||||
fs.rmSync(path.dirname(exclude), { recursive: true, force: true });
|
||||
expect(spawnSync('bash', ['-c', entry!], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).status).toBe(0);
|
||||
fs.writeFileSync(exclude, '*.log');
|
||||
expect(spawnSync('bash', ['-c', entry!], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).status).toBe(0);
|
||||
expect(fs.readFileSync(exclude, 'utf8').split('\n')).toEqual(expect.arrayContaining(['*.log', '/.gstack/tmp/']));
|
||||
fs.writeFileSync(path.join(repo.work, recordPath!), JSON.stringify({ classes: ['money'], rules: TARGETED_RULES, brief_sha: targetedBriefSha(), status: 'done', findings: 0, raised_by: 'targeted', head: repo.git('rev-parse', 'HEAD') }) + '\n');
|
||||
const args = expand();
|
||||
expect(args).toEqual(['--review-targeted', `@${recordPath}`]);
|
||||
expect(repo.git('ls-files', '--others', '--exclude-standard')).toBe('');
|
||||
const write = runBin(repo, 'gstack-ship-receipt', ['write', '--base', 'main', '--session-kind', 'unattended', ...args, '--json']);
|
||||
expect(write.status, write.err).toBe(0);
|
||||
const receipt = JSON.parse(write.out) as ShipReceipt;
|
||||
expect(receiptTargetedVerdict(['money'], receipt).line).toBe('REVIEW_TARGETED: required=money receipt=money verdict=ok');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the receipt record and the queue line', () => {
|
||||
const record = { classes: ['gate', 'money'], rules: TARGETED_RULES, brief_sha: 'a'.repeat(64), status: 'done', findings: 0, raised_by: 'targeted' };
|
||||
test('parseReviewTargeted binds the receipt\'s product patch, orders the classes and refuses a malformed record', () => {
|
||||
|
||||
@@ -546,10 +546,10 @@ test('review clarity: settlement gates edits separately from incomplete required
|
||||
expectMentions(fix, [['stop', 'without', 'edits']], 'fix');
|
||||
});
|
||||
|
||||
test('review clarity: Greptile reply choices never substitute for Fix-First approval', () => {
|
||||
test('review clarity: review bot reply choices never substitute for Fix-First approval', () => {
|
||||
const fix = skill.slice(skill.indexOf('## Step 5: Fix-First Review'), skill.indexOf('{{CROSS_REVIEW_DEDUP}}'));
|
||||
expect(fix).toContain('VALID & ACTIONABLE Greptile findings');
|
||||
const greptile = skill.slice(skill.indexOf('### Greptile comment resolution'), skill.indexOf('## Step 5.8:'));
|
||||
expect(fix).toContain('VALID & ACTIONABLE review bot findings');
|
||||
const greptile = skill.slice(skill.indexOf('### Review bot comment resolution'), skill.indexOf('## Step 5.8:'));
|
||||
const flat = greptile.replace(/\s+/g, ' ');
|
||||
expectMentions(flat, [['not', 'decisions', 'approval']], 'flat');
|
||||
expect(flat).toContain('B) Propose a code change');
|
||||
|
||||
@@ -261,6 +261,14 @@ describe('variant G: the call plan, observe budget, waits and audit readers (GST
|
||||
});
|
||||
});
|
||||
|
||||
describe('review bots (#3122)', () => {
|
||||
test('only Step 6.5 waits on Greptile detection; Step 10 routes to the bot triage section for any configured bot', () => {
|
||||
expect(doc).toContain('Step 6.5 runs only if `gstack-greptile-early detect` finds');
|
||||
expect(doc).not.toContain('Steps 6.5 and 10 run only if');
|
||||
expect(doc).toContain('- Step 10 with a PR: `sections/greptile.md#step-10-address-review-bot-comments-if-pr-exists`');
|
||||
});
|
||||
});
|
||||
|
||||
describe('STOP anchors', () => {
|
||||
test('every STOP row is rendered and its anchor names a heading that exists', () => {
|
||||
for (const s of SHIP_DRIVER_STOPS) {
|
||||
|
||||
@@ -64,6 +64,20 @@ describe("/ship Step 10 waits for the early review", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("/ship Step 10 triages every configured review bot (#3122)", () => {
|
||||
test("Step 10 runs the bot-agnostic fetch with a bot on every record; only Step 6.5 waits on Greptile detection", () => {
|
||||
const s = flat(step10);
|
||||
expect(s).toContain("`REVIEW_BOTS: skip` is `no_pr`; `REVIEW_BOTS: error` is `unavailable`");
|
||||
expect(s).toContain("a `bot` and integer `id` on every comment");
|
||||
expect(flat(read("review/greptile-triage.md"))).toContain("~/.claude/skills/gstack/bin/gstack-review-bots fetch");
|
||||
const driver = flat(read("ship/DRIVER.md.tmpl"));
|
||||
expect(driver).toContain("Step 6.5 runs only if `gstack-greptile-early detect` finds Greptile.");
|
||||
expect(driver).not.toMatch(/Steps 6\.5 and 10 run only if/);
|
||||
expect(prBody).toContain("## Review bot comments");
|
||||
expect(prBody).not.toContain("## Greptile Review");
|
||||
});
|
||||
});
|
||||
|
||||
describe("/ship Steps 18-19 finish the early PR", () => {
|
||||
test("the provisional title is replaced and the draft is marked ready unless a draft was asked for", () => {
|
||||
expect(flat(prBody)).toContain("For an existing open PR/MR (not Step 6.5's early PR, which takes item 2)");
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('/ship Step 10 Greptile PR check', () => {
|
||||
expect(dispatchIdx).toBeGreaterThan(checkIdx);
|
||||
const between = SECTION.slice(checkIdx, dispatchIdx);
|
||||
expect(between).toContain('Only `PR: exists` dispatches.');
|
||||
expect(between).toContain('"Greptile: not run (<reason>); runs on the PR once it exists"');
|
||||
expect(between).toContain('"Review bots: not run (<reason>); runs on the PR once it exists"');
|
||||
expect(SECTION).not.toContain('PR: unknown');
|
||||
});
|
||||
|
||||
|
||||
@@ -83,13 +83,13 @@ describe('gstack-ship-parts next under loss and odd inputs (PR #3670 review)', (
|
||||
// why_new=Step 11 findings on #3670 (outside voice 1-3, adversarial 5, QA); seam=none; no_claim=the host noticing that a return was lost
|
||||
test('a lost return is sent again with --resend, and a plain next promotes it to returned', () => {
|
||||
const dir = tmp();
|
||||
const first = run(['next', '--run', dir, '--phase', '3', '--room', '4000']);
|
||||
const first = run(['next', '--run', dir, '--phase', '3', '--room', '6000']);
|
||||
const ids = [...first.stdout.matchAll(/^PART: (\S+) /gm)].map(m => m[1]!);
|
||||
expect(ids.length).toBeGreaterThan(0);
|
||||
const again = run(['next', '--run', dir, '--phase', '3', '--room', '4000', '--resend']);
|
||||
const again = run(['next', '--run', dir, '--phase', '3', '--room', '6000', '--resend']);
|
||||
expect(again.status, again.stderr).toBe(0);
|
||||
expect([...again.stdout.matchAll(/^PART: (\S+) /gm)].map(m => m[1]!)).toEqual(ids);
|
||||
const later = run(['next', '--run', dir, '--phase', '3', '--room', '4000']);
|
||||
const later = run(['next', '--run', dir, '--phase', '3', '--room', '6000']);
|
||||
expect([...later.stdout.matchAll(/^PART: (\S+) /gm)].map(m => m[1]!).filter(id => ids.includes(id))).toEqual([]);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(dir, 'parts', 'state.json'), 'utf8')).returned).toEqual(expect.arrayContaining(ids));
|
||||
});
|
||||
|
||||
@@ -86,6 +86,52 @@ describe('gstack-ship-preflight', () => {
|
||||
expect(lineOf(r.stdout, 'POLICY')).toContain('queue_mode=stamp-at-merge');
|
||||
});
|
||||
|
||||
// Value: protects=Step 1 refreshes origin/<base> itself, so a clone whose fetch refspec leaves out the base (a single-branch
|
||||
// clone) still diffs against the current base tip (GST-462, HARN-15); fails_when=preflight runs `git fetch origin <base>`,
|
||||
// which then updates only FETCH_HEAD; seam=remote.origin.fetch; no_claim=remotes other than origin
|
||||
test('a single-branch clone: the fetch refreshes origin/<base>, so DIFF is the branch alone', () => {
|
||||
const f = fx({ '.gstack/ship-policy.json': '{"queue_mode":"stamp-at-merge"}\n' });
|
||||
f.git('config', 'remote.origin.fetch', '+refs/heads/feat:refs/remotes/origin/feat');
|
||||
f.advanceBase({ 'docs/new.md': '# new\n' });
|
||||
f.git('fetch', '-q', f.origin, 'main');
|
||||
f.git('merge', '-q', '--no-edit', 'FETCH_HEAD');
|
||||
const stale = f.git('rev-parse', 'origin/main').stdout.trim();
|
||||
const r = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(r.status).toBe(0);
|
||||
expect(f.git('rev-parse', 'origin/main').stdout.trim()).not.toBe(stale);
|
||||
expect(lineOf(r.stdout, 'DIFF')).toMatch(/^DIFF: 1 file changed, 1 insertion\(\+\); commits=2$/);
|
||||
});
|
||||
|
||||
// Value: protects=a diff far larger than the PR's own (a stale or wrong base: HARN-15 reviewed 17,000 files of main's history)
|
||||
// stops before any reader runs, naming the PR's base; fails_when=preflight never compares the diff with the PR's changed
|
||||
// files; seam=gh pr view (changedFiles, headRefOid, baseRefName); no_claim=GitHub's own count
|
||||
test('a diff far beyond or short of the PR\'s changed files stops at the pushed head; another head or a matching size goes on', () => {
|
||||
const files = Object.fromEntries(Array.from({ length: 60 }, (_, i) => [`src/f${i}.ts`, `export const f${i} = ${i};\n`]));
|
||||
const f = fx({}, files);
|
||||
const head = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const stub = (changed: number, prHead: string, prBase = 'release') => f.gh(`case "$*" in *"pr list"*) echo 7 ;; *changedFiles*) echo "${changed} ${prHead} ${prBase}" ;; esac`);
|
||||
stub(3, head);
|
||||
const r = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(r.status).toBe(3);
|
||||
expect(r.stdout).toContain('STOP: the diff against origin/main lists 60 files but PR #7 changes 3 (its base is release): origin/main is not the PR\'s base; rerun with --base release after git fetch origin +refs/heads/release:refs/remotes/origin/release');
|
||||
stub(3, head, 'main');
|
||||
const fork = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(fork.stdout).toContain('(its base is main): origin is not the PR\'s base repository (a fork) or its main has moved');
|
||||
expect(fork.stdout).not.toContain('rerun with --base');
|
||||
stub(3, head, 'x;rm');
|
||||
expect(f.run(PREFLIGHT, ['--base', 'main']).stdout).toContain("rerun with --base 'x;rm' after git fetch origin +refs/heads/'x;rm':refs/remotes/origin/'x;rm'");
|
||||
stub(61, head, 'main');
|
||||
const fewer = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(fewer.status).toBe(3);
|
||||
expect(fewer.stdout).toContain('STOP: the diff against origin/main lists 60 files but PR #7 changes 61 (its base is main): origin is not the PR\'s base repository (a fork) or its main has moved');
|
||||
for (const [changed, prHead] of [[3, 'f'.repeat(40)], [61, 'f'.repeat(40)], [60, head], [0, head]] as const) {
|
||||
stub(changed, prHead);
|
||||
const go = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(go.stdout).not.toContain('lists 60 files');
|
||||
expect(lineOf(go.stdout, 'PR')).toBe('PR: #7');
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=Step 1's scope check reads the fetched origin/<base>, so a clone without a local base branch still sees frontend files; fails_when=the preflight reports frontend=false because gstack-diff-scope could not resolve a local <base>;
|
||||
// why_new=GSTA-167 dogfood on #3633: a Capy checkout has no local main and SCOPE printed false; seam=gstack-diff-scope; no_claim=design review itself
|
||||
test('no local base branch: SCOPE still reads the fetched base', () => {
|
||||
|
||||
@@ -242,8 +242,8 @@ test('publication composes the saved documentation section unchanged and refuses
|
||||
});
|
||||
|
||||
test('publication reports unavailable triage separately from an empty successful fetch', () => {
|
||||
const section = template.slice(template.indexOf('## Greptile Review'), template.indexOf('## Scope Drift'));
|
||||
expect(section).toContain('Greptile triage: UNAVAILABLE (dispatch failed)');
|
||||
const section = template.slice(template.indexOf('## Review bot comments'), template.indexOf('## Scope Drift'));
|
||||
expect(section).toContain('Review bot triage: UNAVAILABLE (dispatch failed)');
|
||||
expect(section).toContain('actual reason');
|
||||
expect(section).toContain('complete');
|
||||
expect(section).toContain('no_pr');
|
||||
|
||||
@@ -14,9 +14,11 @@ import { EXIT } from '../lib/headless-artifacts';
|
||||
import { BASE_POLICY, cleanup, makeFixtureRepo, readFile, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
import { shippedBody } from './helpers/ship-queue-train-fixture';
|
||||
import { resolveReleaseConflicts } from '../lib/ship-queue-land';
|
||||
import { mergePolicy } from '../lib/ship-policy';
|
||||
import { receiptDepthAtHead, receiptExclude, receiptReviewAtHead } from '../lib/ship-receipt-depth';
|
||||
import { mergePolicy, REVIEW_EXCLUDE_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { persist, repoIdentity } from '../lib/ship-queue-train-record';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const POLICY = { ...BASE_POLICY, release_tool: null, release_outputs: [], changelog_fragments: { dir: 'changelog.d' }, min_gstack_version: '1.91.336.0' };
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
@@ -47,7 +49,7 @@ function setup(policy: Record<string, unknown> = POLICY): Fx {
|
||||
" if(head!==want){console.error('Head branch was modified');process.exit(1)}",
|
||||
" if(d.mergeRefuse){console.error('Pull request is not mergeable: the base branch policy prohibits the merge');process.exit(1)}",
|
||||
" if(d.driftOnMerge){const m=g('rev-parse','refs/heads/main');const t=g('rev-parse',m+'^{tree}');g('update-ref','refs/heads/main',g('commit-tree',t,'-p',m,'-m','outside merge'));d.driftOnMerge=false}",
|
||||
" const main=g('rev-parse','refs/heads/main');const sq=g('commit-tree',g('rev-parse',want+'^{tree}'),'-p',main,'-m','squash #'+a[2]);g('update-ref','refs/heads/main',sq);if(d.outsideAfter){g('update-ref','refs/heads/main',g('commit-tree',g('rev-parse',sq+'^{tree}'),'-p',sq,'-m','outside after'));d.outsideAfter=false}d.mergeArgs=a.slice(3);p.state='MERGED';save();if(d.mergeErrorAfter){d.mergeErrorAfter=false;save();console.error('HTTP 502: Bad Gateway');process.exit(1)}process.exit(0)}",
|
||||
" const main=g('rev-parse','refs/heads/main');const sq=g('commit-tree',g('rev-parse',want+'^{tree}'),'-p',main,...(d.trueMerge&&a.includes('--merge')?['-p',want]:[]),'-m','squash #'+a[2]);g('update-ref','refs/heads/main',sq);if(d.outsideAfter){g('update-ref','refs/heads/main',g('commit-tree',g('rev-parse',sq+'^{tree}'),'-p',sq,'-m','outside after'));d.outsideAfter=false}d.mergeArgs=a.slice(3);p.state='MERGED';save();if(d.mergeErrorAfter){d.mergeErrorAfter=false;save();console.error('HTTP 502: Bad Gateway');process.exit(1)}process.exit(0)}",
|
||||
"if(a[0]==='pr'&&a[1]==='create'&&d.createFail){d.createFail=false;save();console.error('timeout');process.exit(1)}",
|
||||
"if(a[0]==='pr'&&a[1]==='create'){const h=a[a.indexOf('--head')+1];const had=Object.entries(d.prs).find(([,p])=>p.headRefName===h&&p.state==='OPEN');if(had){console.error('a pull request for branch \"'+h+'\" into branch \"main\" already exists:\\nhttps://github.com/o/r/pull/'+had[0]);process.exit(1)}}",
|
||||
"if(a[0]==='pr'&&a[1]==='create'){const n=String(Math.max(0,...Object.keys(d.prs).map(Number))+1);d.prs[n]={state:'OPEN',headRefName:a[a.indexOf('--head')+1],isCrossRepository:false,title:a[a.indexOf('--title')+1],body:''};save();console.log('https://github.com/o/r/pull/'+n);process.exit(0)}",
|
||||
@@ -562,6 +564,50 @@ describe('land: one pass, base, lock and history', () => {
|
||||
expect(r.out).toContain('LANDED: ');
|
||||
expect(JSON.parse(fs.readFileSync(fx.data, 'utf8')).mergeArgs).toContain('--merge');
|
||||
}, 90_000);
|
||||
|
||||
// Value: protects=a merge-only land interrupted after GitHub merged resumes to LANDED, though a true merge puts the pin inside
|
||||
// the base; fails_when=the receipt check refuses the merged pin as BASE_CONTAINS_HEAD, or its depth check reads the empty
|
||||
// range as a scope error and raises the depth, and the lock is never released; why_new=GST-774's base guard, and the shim
|
||||
// only squashed; seam=none; no_claim=GitHub's merge-commit shape beyond two parents
|
||||
test('merge-only: a true merge that errored after GitHub merged resumes to LANDED with a depth-bearing receipt', () => {
|
||||
const fx = setup({ ...POLICY, history: 'merge-only' });
|
||||
const head = openPr(fx, '14');
|
||||
const depth = receiptDepthAtHead(fx.repo.work, 'main', path.join(ROOT, 'bin'), head);
|
||||
expect(depth.depth).toBe('light');
|
||||
fx.write(d => { d.prs['14'].body = shippedBody('14', head, { gstack_version: '1.91.400.0', review_depth: depth }); });
|
||||
land(fx, ['--pr', '14']);
|
||||
fx.write(d => { d.trueMerge = true; d.mergeErrorAfter = true; });
|
||||
expect(land(fx, ['--pr', '14']).err).toContain('HTTP 502');
|
||||
const again = land(fx, ['--pr', '14']);
|
||||
expect(again.out + again.err).not.toMatch(/BASE_CONTAINS_HEAD|QUEUE_RECEIPT_DEPTH_RAISED/);
|
||||
expect(again.out).toMatch(/^REVIEW_DEPTH: receipt=light required=light /m);
|
||||
expect(again.out).toContain('LANDED: ');
|
||||
}, 90_000);
|
||||
|
||||
// Value: protects=the same merged resume when review_exclude_paths excluded files from the PR's range; fails_when=the queue
|
||||
// recomputes the exclusion over the merged (empty) range and refuses the receipt's digest as RECEIPT_INVALID; why_new=the
|
||||
// case above has no review_exclude_paths; seam=none; no_claim=GitHub's merge-commit shape beyond two parents
|
||||
test('merge-only: a merged resume lands when review_exclude_paths excluded files from the range', () => {
|
||||
const fx = setup({ ...POLICY, history: 'merge-only', review_exclude_paths: ['data/**'], min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION });
|
||||
const head = openPr(fx, '15', { edit: work => { fs.mkdirSync(path.join(work, 'data', 'a'), { recursive: true }); fs.writeFileSync(path.join(work, 'data', 'a', 'result.json'), '{"ok": true}\n'); } });
|
||||
fx.repo.git('checkout', '-q', '--detach', head);
|
||||
const prior = process.env.GSTACK_STATE_ROOT;
|
||||
process.env.GSTACK_STATE_ROOT = path.join(fx.repo.root, 'ready-state');
|
||||
let review: ReturnType<typeof receiptReviewAtHead>;
|
||||
try { review = receiptReviewAtHead(fx.repo.work, 'main', path.join(ROOT, 'bin'), head); }
|
||||
finally { if (prior === undefined) delete process.env.GSTACK_STATE_ROOT; else process.env.GSTACK_STATE_ROOT = prior; }
|
||||
const { depth, exclude } = review;
|
||||
fx.repo.git('checkout', '-q', '--detach', 'origin/main');
|
||||
const recorded = receiptExclude(exclude);
|
||||
expect(recorded?.excluded).toBe(1);
|
||||
fx.write(d => { d.prs['15'].body = shippedBody('15', head, { gstack_version: REVIEW_EXCLUDE_KEY_VERSION, review_depth: depth, review_exclude: recorded }); });
|
||||
land(fx, ['--pr', '15']);
|
||||
fx.write(d => { d.trueMerge = true; d.mergeErrorAfter = true; });
|
||||
expect(land(fx, ['--pr', '15']).err).toContain('HTTP 502');
|
||||
const again = land(fx, ['--pr', '15']);
|
||||
expect(again.out + again.err).not.toMatch(/RECEIPT_INVALID|BASE_CONTAINS_HEAD|QUEUE_RECEIPT_DEPTH_RAISED/);
|
||||
expect(again.out).toContain('LANDED: ');
|
||||
}, 90_000);
|
||||
});
|
||||
|
||||
// /ship adversarial (Claude) and outside-voice (Codex) findings (GSTA-154 PR A): each case failed or was unreachable before its fix.
|
||||
|
||||
@@ -194,7 +194,7 @@ test('linked spec discovery reads frontmatter fields and claims closure only for
|
||||
test('comment triage reports one of three statuses with fixed result strings', () => {
|
||||
const section = compact(readTemplate('ship/sections/greptile.md.tmpl'));
|
||||
expectTokens(section, ['"status":"complete|no_pr|unavailable"', '`complete`', '`no_pr`', '`unavailable`',
|
||||
'"Greptile: no PR exists"', '"Greptile: fetched, zero comments"', '`Greptile triage: UNAVAILABLE (dispatch failed)`'], 'ship greptile section');
|
||||
'"Review bots: not run (no PR, or both bot lists are none)"', '"Review bots: fetched, zero comments"', '`Review bot triage: UNAVAILABLE (dispatch failed)`'], 'ship greptile section');
|
||||
expectAbsent(section, ['If no PR exists, `gh` fails, the API errors, or there are zero comments'], 'ship greptile section');
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 591,
|
||||
"why": "GST-464: Step 9 creates .gstack/tmp, excludes it and clears the targeted record on every entry"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 486,
|
||||
"why": "GST-508: review_exclude_paths slots on the fixture and name-status commands, and the --review-exclude receipt step"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": -232,
|
||||
"why": "wave review-53cfb5bfe011 merge of main e85005482: ship/DRIVER.md takes main's shorter Step 19 line ([--review-targeted @<f>], host PR tool) over the wave's, and the wave's own trims overlap main's"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 96,
|
||||
"why": "GSTA-224 B2 (#3122): Step 10 triages every bot in pr_wait_gating_bots/pr_wait_advisory_bots through gstack-review-bots; records by comment id (subagent JSON carries id and dir, parent requires both); Greptile-only prose trimmed"
|
||||
}
|
||||
@@ -430,7 +430,7 @@ describe('Update check preamble', () => {
|
||||
// --- Part 7: Cross-skill path consistency (A1) ---
|
||||
|
||||
describe('Cross-skill path consistency', () => {
|
||||
test('REMOTE_SLUG derivation pattern is identical across files that use it', () => {
|
||||
test('no qa or review skill file hand-rolls a REMOTE_SLUG derivation (gstack-slug and gstack-review-bots own it)', () => {
|
||||
const patterns = extractRemoteSlugPatterns(ROOT, ['qa', 'review']);
|
||||
const allPatterns: string[] = [];
|
||||
|
||||
@@ -438,50 +438,30 @@ describe('Cross-skill path consistency', () => {
|
||||
allPatterns.push(...filePatterns);
|
||||
}
|
||||
|
||||
// Should find at least 2 occurrences (qa/SKILL.md + review/greptile-triage.md)
|
||||
expect(allPatterns.length).toBeGreaterThanOrEqual(2);
|
||||
// review/greptile-triage.md held the last prose copy until #3122 moved it into lib/review-bots.ts.
|
||||
expect(allPatterns).toEqual([]);
|
||||
});
|
||||
|
||||
// All occurrences must be character-for-character identical
|
||||
const unique = new Set(allPatterns);
|
||||
if (unique.size > 1) {
|
||||
const variants = Array.from(unique);
|
||||
throw new Error(
|
||||
`REMOTE_SLUG pattern differs across files:\n` +
|
||||
variants.map((v, i) => ` ${i + 1}: ${v}`).join('\n')
|
||||
);
|
||||
test('every review-bot history write goes through the one writer (project and global rows: test/review-bots.test.ts)', () => {
|
||||
// ship's bot handling moved into sections/greptile.md (T9 carve).
|
||||
for (const content of [fs.readFileSync(path.join(ROOT, 'review', 'SKILL.md'), 'utf-8'), readShipUnion()]) {
|
||||
expect(content).toContain('History File Writes');
|
||||
expect(content).not.toContain('greptile-history (type:');
|
||||
}
|
||||
});
|
||||
|
||||
test('all greptile-history write references specify both per-project and global paths', () => {
|
||||
const filesToCheck = [
|
||||
'review/SKILL.md',
|
||||
'ship/SKILL.md',
|
||||
'review/greptile-triage.md',
|
||||
];
|
||||
|
||||
for (const file of filesToCheck) {
|
||||
const filePath = path.join(ROOT, file);
|
||||
if (!fs.existsSync(filePath)) continue;
|
||||
// ship's greptile handling moved into sections/greptile.md (T9 carve).
|
||||
const content = file === 'ship/SKILL.md' ? readShipUnion() : fs.readFileSync(filePath, 'utf-8');
|
||||
|
||||
const hasBoth = (content.includes('per-project') && content.includes('global')) ||
|
||||
(content.includes('$REMOTE_SLUG/greptile-history') && content.includes('~/.gstack/greptile-history'));
|
||||
|
||||
expect(hasBoth).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('greptile-triage.md contains both project and global history paths', () => {
|
||||
test('greptile-triage.md records through gstack-review-bots into review-bot-history.md', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'review', 'greptile-triage.md'), 'utf-8');
|
||||
expect(content).toContain('$REMOTE_SLUG/greptile-history.md');
|
||||
expect(content).toContain('~/.gstack/greptile-history.md');
|
||||
expect(content).toContain('gstack-review-bots record --dir <bot-dir> --id <comment-id>');
|
||||
expect(content).toContain('review-bot-history.md');
|
||||
});
|
||||
|
||||
test('retro/SKILL.md reads global greptile-history (not per-project)', () => {
|
||||
test('retro/SKILL.md reads the global review-bot and greptile histories (not per-project)', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'retro', 'SKILL.md'), 'utf-8');
|
||||
expect(content).toContain('the path `GREPTILE_HISTORY` printed');
|
||||
expect(fs.readFileSync(path.join(ROOT, 'bin', 'gstack-retro-metrics'), 'utf-8')).toContain('$_GH/greptile-history.md');
|
||||
expect(content).toContain('`REVIEW_BOT_HISTORY` / `GREPTILE_HISTORY: present`');
|
||||
const metrics = fs.readFileSync(path.join(ROOT, 'bin', 'gstack-retro-metrics'), 'utf-8');
|
||||
expect(metrics).toContain('$_GH/greptile-history.md');
|
||||
expect(metrics).toContain('$_GH/review-bot-history.md');
|
||||
// Should NOT reference per-project path for reads
|
||||
expect(content).not.toContain('$REMOTE_SLUG/greptile-history.md');
|
||||
});
|
||||
|
||||
@@ -47,12 +47,6 @@ const SCANNER_EXEMPT: { file: string; pattern: string; reason: string }[] = [
|
||||
reason:
|
||||
'F1 plan binding: only the first `Plan: <path>` token survives (one whitespace-free path, CR and backticks stripped); the body never reaches model context, and the path is then read as a file the parent confirms',
|
||||
},
|
||||
{
|
||||
file: 'review/greptile-triage.md',
|
||||
pattern: 'gh comment-body api read',
|
||||
reason:
|
||||
'raw fetch lands in /tmp json FILES (metadata/body split); body text is read into context only via the gstack-issue-guard --stdin pipes documented in the same file',
|
||||
},
|
||||
{
|
||||
file: 'document-release/sections/release-body.md.tmpl',
|
||||
pattern: 'gh pr body read',
|
||||
|
||||
Reference in new issue
Block a user