mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 14:06:50 +01:00
* feat(review): variant G part 4: data files no code names are docs in classifyDiff, untested state-matrix cells map below the floor per cell (GSTA-167 PR-a)
Part 4a: lib/review-depth.ts owns DATA_PATH (JSON, JSONL, NDJSON, CSV, TSV, raster
images; YAML, TOML and SVG stay code) and applies the data rule only in classifyDiff,
to candidates lib/review-collect.ts finds no non-docs consumer for (git grep of
basenames at head, merge base and, live, the working tree; data-to-data chains four
deep; over 2,000 candidates keeps all code; a grep failure fails closed). classifyPath
and every path-only caller are unchanged; the receipt gate scan decides through
gateScanNeeded (path-only), so it cannot be skipped. gstack-ship-preflight computes
RUNTIME_LINES with classifyDiff over gstack-review-plan --json (now with consumed).
Part 4b: lib/review-scope.ts mapStateMatrixOutput maps an "untested cell" finding to
INFORMATIONAL when its cell has test null in the same output's matrix and it is the
only finding on that cell; gstack-state-matrix findings prints it for Step 9.2 before
the merge. state-machines.md is byte-identical; check still reads the raw output.
Reviewer-brief pins repinned under no-loss replay PR-a (Arm 4: plan identity at the 14
cohort heads; free exact re-score of saved C, D and A' findings).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(review): variant G parts 1 and 3: blocking floor in both prose voices, specialists at medium (GSTA-167)
Part 1: the native adversarial and outside-voice prompts end with the blocking
floor ("would fail a test, break production, or lose data or secrets") and ask
each finding for Severity and Blocks: yes|no. Additive rule: a finding is
CRITICAL when its label rule says so or it says Blocks: yes; Blocks: no never
lowers one (proseVoiceSeverity, BLOCKING_FLOOR in lib/review-scope.ts).
Part 3: ROLE_EFFORT puts specialists at medium; Red Team, native adversarial
and fix-check stay full; light's batched specialist (carries the Red Team
prompt) stays full; --no-tiers sends specialists to host.
Repinned reviewer briefs with no-loss replay G1 (live Arm G1, not yet run):
ship/sections/review-army.md, ship/sections/adversarial.md,
review/sections/adversarial.md, lib/review-depth.ts. Merge only on G1's pass.
Review-skill parity ratio 1.3136 -> 1.3180 and the gstack-review size pins
+537 for the approved +0.3k tokens per voice.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(review): variant G part 2: lean ensemble, one batched specialist at every depth (GSTA-167)
planReview dispatches one 'specialist batched' at standard and full depth (and
light, which adds the Red Team checklist): Testing and Security always on code
and gate class, plus State-machines, Data-migration, API-contract and Design
when scope asks; a forced checklist always joins. Maintainability, Performance
and Simplification are read only when forced (SKIP names them). LIGHT_FIXED is
[testing, security]; BATCH_SCOPED joins DEPTH_RULES so old receipts re-plan.
The Red Team rule and prompt are unchanged; it reads the batched reader's
merged findings. specialistsFor stays as the legacy selection the dispatch
compare script models.
Repinned reviewer briefs with no-loss replay L (live Arm L, scored L∘G1 vs G1;
not yet run): ship/sections/review-army.md, lib/review-depth.ts. Merge only on
L's pass.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(review): variant G on #3648's dispatch: Blocks: yes collects as CRITICAL, batched checklists by name (GSTA-167)
Integrates parts 1 and 2 with gstack-review-dispatch (#3648):
- lib/review-ledger.ts parseFindings: a prose voice's "Blocks: yes" makes its
own line, or the finding on the line just before it, CRITICAL in
merged.jsonl (normalizer v2, certified by round 5's G1), so judge refuses a
lead that keeps it below the floor; with no finding before it the Blocks
line is its own CRITICAL finding. "Blocks: no" never lowers a label.
- lib/review-brief.ts: the outside-voice brief no longer appends "Give each
finding a severity"; the section's prompt now asks for Severity and Blocks,
so the brief is the certified section prompt plus the branch diff.
- bin/gstack-review-dispatch render --checklists takes the plan's
checklists= names (review/specialists/<name>.md) as well as paths and
refuses an unknown one, since the batched reader is now every depth's
specialist dispatch.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* chore(changelog): GSTA-167 variant G reviewer stack fragment
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(review): consumer scan survives grep.lineNumber/grep.column; collect reads separate-line Severity/Blocks
/ship pass 1 (PR #3660): the Red Team CRITICAL at lib/review-collect.ts:120 and the
informational findings in the same batch. proseVoiceSeverity had no caller and is
removed; the normalizer v2 table now runs through parseFindings, the path collect uses.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(review): collect keeps every prose blocker and one id per finding
/ship pass 2 (PR #3660): an unlabeled line carrying an inline Blocks: yes collects as
CRITICAL again; Severity/Blocks continuation needs a colon, stops at a list item, heading,
bold paragraph opener or a repeated field, and never swallows a top-level bullet or its
section label; the native voice's FIXABLE collects as CRITICAL under its role with or
without a dispatch name; the consumer scan adds --no-color.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(review): a later finding's fields never land on the one before it; explicit Severity wins its line
/ship pass 2 Red Team (PR #3660): prose after a finding's Severity/Blocks field, a
post-blank paragraph or a line in an indented block starts the next finding, and a
line's explicit Severity: label decides it over other label words on the line.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(review): FIXABLE outranks a Severity label on its line; a blocker keeps its own id and subject
/ship fix-check (PR #3660): labels are named before the strongest is taken, so a one-line
native FIXABLE ... Severity: Medium collects as CRITICAL; a later finding starts at a
file:line after the open finding's fields, field bullets stay on their finding, a field
line may omit the colon, and continuation prose never replaces a list item's subject.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs(changelog): GSTA-167 fragment adds round 6 and the collect and consumer-scan fixes
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
261 lines
20 KiB
TypeScript
261 lines
20 KiB
TypeScript
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import { spawnSync } from 'node:child_process';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
|
|
const BIN = path.join(import.meta.dir, '..', 'bin', 'gstack-review-plan');
|
|
const dirs: string[] = [];
|
|
afterEach(() => { while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
|
|
|
|
function repo(files: Record<string, string>): { dir: string; state: string } {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'review-plan-'));
|
|
const state = fs.mkdtempSync(path.join(os.tmpdir(), 'review-plan-state-'));
|
|
dirs.push(dir, state);
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: dir, encoding: 'utf8', timeout: 10_000 });
|
|
git('init', '-q', '-b', 'main'); git('config', 'user.email', 't@t'); git('config', 'user.name', 't'); git('config', 'commit.gpgsign', 'false');
|
|
fs.writeFileSync(path.join(dir, 'README.md'), '# x\n'); git('add', '.'); git('commit', '-qm', 'base');
|
|
git('checkout', '-qb', 'feat');
|
|
for (const [p, text] of Object.entries(files)) { fs.mkdirSync(path.dirname(path.join(dir, p)), { recursive: true }); fs.writeFileSync(path.join(dir, p), text); }
|
|
git('add', '.'); git('commit', '-qm', 'feat');
|
|
return { dir, state };
|
|
}
|
|
const run = (r: { dir: string; state: string }, args: string[]) => spawnSync(BIN, ['--base', 'main', '--gate-tagged', '0', ...args], { cwd: r.dir, encoding: 'utf8', timeout: 60_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
|
|
describe('gstack-review-plan', () => {
|
|
test('a docs-only diff plans no dispatch and says why', () => {
|
|
const r = run(repo({ 'docs/howto.md': '# How to\nStep one.\n' }), []);
|
|
expect(r.status).toBe(0);
|
|
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)');
|
|
});
|
|
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');
|
|
});
|
|
test('--json carries the class, the next step, every dispatch with its effort and the audit effort; --no-tiers renders specialists and audits at host effort', () => {
|
|
const r = repo({ 'src/a.ts': Array.from({ length: 80 }, (_, i) => `export const v${i} = ${i};`).join('\n') + '\n' });
|
|
const plan = JSON.parse(run(r, ['--json']).stdout);
|
|
expect(plan).toMatchObject({ class: 'code', next: { step: 'full' }, pass: 0 });
|
|
expect(plan.dispatches.filter((d: any) => d.role === 'specialist').map((d: any) => d.effort)).toEqual(expect.arrayContaining(['medium']));
|
|
expect(plan.dispatches.filter((d: any) => d.role === 'specialist').every((d: any) => d.effort === 'medium')).toBe(true);
|
|
expect(plan.dispatches.find((d: any) => d.role === 'adversarial-native').effort).toBe('full');
|
|
expect(plan.audit_effort).toBe('light');
|
|
expect(run(r, []).stdout).toContain('DISPATCH: specialist batched effort=medium checklists=testing,security,state-machines');
|
|
const host = JSON.parse(run(r, ['--json', '--no-tiers']).stdout);
|
|
expect(host.audit_effort).toBe('host');
|
|
expect(host.dispatches.filter((d: any) => d.role === 'specialist').every((d: any) => d.effort === 'host')).toBe(true);
|
|
expect(host.dispatches.find((d: any) => d.role === 'adversarial-native').effort).toBe('full');
|
|
expect(run(r, ['--no-tiers']).stdout).toContain('DISPATCH: specialist batched effort=host checklists=testing,security,state-machines');
|
|
});
|
|
test('a below-floor fix after pass 1 plans one fix-check', () => {
|
|
const r = run(repo({ 'src/a.ts': 'export const a = 1;\n' }), ['--pass', '1', '--last', 'full', '--fixed-below']);
|
|
expect(r.stdout).toContain('next=fix-check dispatches=1');
|
|
expect(r.stdout).toContain('DISPATCH: fix-check fix-check effort=full');
|
|
});
|
|
// Value: protects=the CLI the ship loop calls after a fix-check prints NEXT: done when the fix-check was clean and only below-floor fixes came before it; fails_when=`--last fix-check --fixed-below` prints NEXT: stop with a blocking-finding reason (GSTA-167 replay 8G on #34);
|
|
// why_new=no CLI case covered --last fix-check; seam=bin/gstack-review-plan (lib/review-depth.ts stays at its no-loss pin); no_claim=the fix-check reviewer's verdict
|
|
test('a clean fix-check after below-floor fixes prints NEXT: done', () => {
|
|
const r = run(repo({ 'src/a.ts': 'export const a = 1;\n' }), ['--pass', '1', '--last', 'fix-check', '--fixed-below']);
|
|
expect(r.status).toBe(0);
|
|
expect(r.stdout).toContain('NEXT: done');
|
|
expect(r.stdout).not.toContain('NEXT: stop');
|
|
expect(run(repo({ 'src/a.ts': 'export const a = 1;\n' }), ['--pass', '1', '--last', 'fix-check', '--fixed-below', '--blocking-open']).stdout).toContain('NEXT: stop');
|
|
});
|
|
test('--fix-check-prompt renders the fix-check reviewer prompt from the parent\'s files and refuses a missing one', () => {
|
|
const r = repo({ 'docs/howto.md': '# x\n' });
|
|
const w = (n: string, t: string) => { const f = path.join(r.state, n); fs.writeFileSync(f, t); return f; };
|
|
const files = ['--fix-list', w('fix.txt', 'lib/a.ts:3 guard now refuses unknown'), '--hunks', w('hunks.diff', '+if (s !== "MERGED") return false;'), '--tests', w('tests.txt', '12 pass 0 fail')];
|
|
const ok = spawnSync(BIN, ['--fix-check-prompt', ...files], { cwd: r.dir, encoding: 'utf8', timeout: 60_000 });
|
|
expect(ok.status).toBe(0);
|
|
expect(ok.stdout).toContain('You are the fix-check reviewer');
|
|
expect(ok.stdout).toContain('lib/a.ts:3 guard now refuses unknown');
|
|
expect(ok.stdout).toContain('(none found)');
|
|
const missing = spawnSync(BIN, ['--fix-check-prompt', '--fix-list', path.join(r.state, 'nope.txt'), '--hunks', files[3]!, '--tests', files[5]!], { cwd: r.dir, encoding: 'utf8', timeout: 60_000 });
|
|
expect(missing.status).toBe(2);
|
|
});
|
|
test('untracked files count, a version-only package.json bump stays docs, and review_effort_tiers off renders audits at host effort', () => {
|
|
const r = repo({ 'docs/a.md': '# a\n' });
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
|
git('checkout', '-q', 'main');
|
|
fs.writeFileSync(path.join(r.dir, 'package.json'), '{\n "name": "x",\n "version": "1.0.0"\n}\n');
|
|
git('add', '.'); git('commit', '-qm', 'package');
|
|
git('checkout', '-q', 'feat'); git('reset', '-q', '--hard', 'main');
|
|
fs.writeFileSync(path.join(r.dir, 'package.json'), '{\n "name": "x",\n "version": "1.0.1"\n}\n');
|
|
git('commit', '-qam', 'stamp');
|
|
const stamp = JSON.parse(run(r, ['--json']).stdout);
|
|
expect(stamp.stamp_only).toContain('package.json');
|
|
expect(stamp.class).toBe('docs');
|
|
fs.mkdirSync(path.join(r.dir, 'lib'), { recursive: true });
|
|
fs.writeFileSync(path.join(r.dir, 'lib', 'new.ts'), 'export const a = 1;\n');
|
|
const withUntracked = JSON.parse(run(r, ['--json']).stdout);
|
|
expect(withUntracked.paths).toContain('lib/new.ts');
|
|
expect(withUntracked.class).toBe('code');
|
|
const cfg = spawnSync(path.join(import.meta.dir, '..', 'bin', 'gstack-config'), ['set', 'review_effort_tiers', 'off'], { cwd: r.dir, encoding: 'utf8', timeout: 30_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
expect(cfg.status).toBe(0);
|
|
expect(JSON.parse(run(r, ['--json']).stdout).audit_effort).toBe('host');
|
|
const bad = spawnSync(path.join(import.meta.dir, '..', 'bin', 'gstack-config'), ['set', 'review_effort_tiers', 'maybe'], { cwd: r.dir, encoding: 'utf8', timeout: 30_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
expect(bad.status).not.toBe(0);
|
|
expect(bad.stderr).toContain("review_effort_tiers 'maybe' not recognized");
|
|
});
|
|
test('without --gate-tagged the plan runs the gate scan itself', () => {
|
|
const r = repo({ 'lib/a.ts': 'export const a = 1;\n' });
|
|
const res = spawnSync(BIN, ['--base', 'main', '--json'], { cwd: r.dir, encoding: 'utf8', timeout: 120_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
expect(res.status, res.stderr).toBe(0);
|
|
expect(typeof JSON.parse(res.stdout).gate_tagged).toBe('number');
|
|
});
|
|
test('usage errors exit 2', () => {
|
|
expect(spawnSync(BIN, [], { encoding: 'utf8', timeout: 10_000 }).status).toBe(2);
|
|
expect(run(repo({ 'a.md': 'x' }), ['--last', 'later']).status).toBe(2);
|
|
});
|
|
test('scratch under .gstack/tmp/ is ignored, a subdirectory run plans the whole repository, and --adversarial-ran drops the repeat adversarial pass', () => {
|
|
const r = repo({ 'docs/a.md': '# a\n' });
|
|
fs.mkdirSync(path.join(r.dir, '.gstack', 'tmp'), { recursive: true });
|
|
fs.writeFileSync(path.join(r.dir, '.gstack', 'tmp', 'fix-check-list.ts'), 'export const x = 1;\n');
|
|
const plan = JSON.parse(run(r, ['--json']).stdout);
|
|
expect(plan.class).toBe('docs');
|
|
expect(plan.paths).toEqual(['docs/a.md']);
|
|
const sub = spawnSync(BIN, ['--base', 'main', '--gate-tagged', '0', '--json'], { cwd: path.join(r.dir, 'docs'), encoding: 'utf8', timeout: 60_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
expect(JSON.parse(sub.stdout).paths).toEqual(['docs/a.md']);
|
|
const code = repo({ 'src/a.ts': Array.from({ length: 80 }, (_, i) => `export const v${i} = ${i};`).join('\n') + '\n' });
|
|
const repeat = ['--pass', '1', '--last', 'full', '--fixed-blocking'];
|
|
expect(run(code, repeat).stdout).toContain('DISPATCH: adversarial-native adversarial effort=full');
|
|
const ran = run(code, [...repeat, '--adversarial-ran']).stdout;
|
|
expect(ran).not.toContain('DISPATCH: adversarial-native');
|
|
expect(ran).toContain('SKIP: adversarial-native and outside-voice (run once per invocation)');
|
|
});
|
|
});
|
|
|
|
describe('gstack-review-plan: review depth', () => {
|
|
const code = (n: number) => Array.from({ length: n }, (_, i) => `export const v${i} = ${i};`).join('\n') + '\n';
|
|
test('prints REVIEW_DEPTH with runtime lines and the rules hash, and GATE_SCAN bound to the head', () => {
|
|
const r = repo({ 'src/a.ts': code(10), 'test/a.test.ts': code(200) });
|
|
const out = run(r, []).stdout;
|
|
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: r.dir, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
|
expect(out).toMatch(/^REVIEW_DEPTH: light runtime_lines=10 rules=[0-9a-f]{16} reasons=runtime=10<=50 codes=none$/m);
|
|
expect(out).toContain(`GATE_SCAN: tagged=0 head=${head}`);
|
|
expect(out).toContain('DISPATCH: specialist batched effort=full checklists=testing,security,state-machines,red-team');
|
|
expect(out).toContain('DISPATCH: adversarial-native adversarial effort=full reason=backtest inconclusive (GSTA-147 D5)');
|
|
});
|
|
test('DIFF_CMD is shell-quoted per dispatch and excludes what the reviewer does not read; DIFF_EXCLUDE: none when empty', () => {
|
|
const r = repo({ 'src/a.ts': code(80), 'docs/my notes*.md': '# n\n', 'test/a.test.ts': code(3) });
|
|
const out = run(r, []).stdout;
|
|
expect(out).toContain("DIFF_CMD: batched git diff <diff-base> -- . ':(exclude,literal)docs/my notes*.md'\n");
|
|
expect(out).toContain('SKIP: maintainability, performance, simplification (lean ensemble: read only when forced)');
|
|
expect(out).toContain('DIFF_CMD: adversarial git diff <diff-base>\nDIFF_EXCLUDE: adversarial none');
|
|
const cmd = /^DIFF_CMD: batched (.*)$/m.exec(out)![1]!.replace('<diff-base>', 'main');
|
|
const diff = spawnSync('bash', ['-c', cmd.replace('git diff main', 'git diff --name-only main')], { cwd: r.dir, encoding: 'utf8' });
|
|
expect(diff.stdout.trim().split('\n')).toEqual(['src/a.ts', 'test/a.test.ts']);
|
|
});
|
|
test('--json carries depth, runtime_lines, rules, errors, gate_scan and every dispatch\'s exclude array', () => {
|
|
const r = repo({ 'src/a.ts': code(80), 'README.md': '# y\n' });
|
|
const plan = JSON.parse(run(r, ['--json']).stdout);
|
|
expect(plan).toMatchObject({ depth: 'standard', step_depth: 'standard', runtime_lines: 80, errors: [], codes: [], gate_scan: { tagged: 0 } });
|
|
expect(plan.rules).toMatch(/^[0-9a-f]{16}$/);
|
|
expect(plan.dispatches.find((d: any) => d.name === 'batched').exclude).toEqual([':(exclude)README.md']);
|
|
expect(plan.dispatches.find((d: any) => d.role === 'outside-voice').exclude).toEqual([]);
|
|
});
|
|
test('--depth-floor full raises a light diff, never lowers a full one, and an invalid floor is a usage error', () => {
|
|
const r = repo({ 'src/a.ts': code(5) });
|
|
expect(run(r, ['--depth-floor', 'full']).stdout).toMatch(/^REVIEW_DEPTH: full runtime_lines=5 .*reasons=runtime=5<=50,floor:full /m);
|
|
const gate = repo({ 'src/a.ts': code(5), '.github/workflows/ci.yml': 'on: push\n' });
|
|
expect(run(gate, ['--depth-floor', 'standard']).stdout).toMatch(/^REVIEW_DEPTH: full /m);
|
|
expect(run(r, ['--depth-floor', 'light']).status).toBe(2);
|
|
});
|
|
test('a conservative full plan exits 0 with its errors; a plan that cannot be built exits 1', () => {
|
|
const r = repo({ 'lib/x.wasm': '\u0000asm\u0000' });
|
|
const res = run(r, ['--json']);
|
|
expect(res.status).toBe(0);
|
|
expect(JSON.parse(res.stdout)).toMatchObject({ depth: 'full', errors: expect.arrayContaining([expect.objectContaining({ code: 'binary_code_path', input: 'lib/x.wasm' })]) });
|
|
expect(run(r, []).stdout).toContain('DEPTH_ERROR: binary_code_path input=lib/x.wasm');
|
|
const none = spawnSync(BIN, ['--base', 'no-such-branch', '--gate-tagged', '0'], { cwd: r.dir, encoding: 'utf8', timeout: 60_000, env: { ...process.env, GSTACK_STATE_ROOT: r.state } });
|
|
expect(none.status).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe('gstack-review-plan: the scoped second pass (GSTA-152 D6)', () => {
|
|
const code = (n: number, tag = 'v') => Array.from({ length: n }, (_, i) => `export const ${tag}${i} = ${i};`).join('\n') + '\n';
|
|
function fixed(lines: number): { r: { dir: string; state: string }; rangeBase: string } {
|
|
const r = repo({ 'src/a.ts': code(80) });
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
|
const rangeBase = git('rev-parse', 'HEAD').stdout.trim();
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'fix.ts'), code(lines, 'f'));
|
|
git('add', '.'); git('commit', '-qm', 'fix: pre-landing review fixes');
|
|
return { r, rangeBase };
|
|
}
|
|
const pass2 = ['--pass', '1', '--last', 'full', '--fixed-blocking', '--adversarial-ran', '--pass1-depth', 'standard'];
|
|
const full1 = ['--pass', '1', '--last', 'full', '--fixed-blocking', '--adversarial-ran', '--pass1-depth', 'full'];
|
|
test('--range-base with a small fix range plans NEXT: scoped with a fix-check and the Red Team, and counts it as pass 2', () => {
|
|
const { r, rangeBase } = fixed(24);
|
|
const out = run(r, [...pass2, '--range-base', rangeBase]).stdout;
|
|
expect(out).toMatch(/^REVIEW_PLAN: class=code pass=2 next=scoped dispatches=3 /m);
|
|
expect(out).toContain(`FIX_RANGE: runtime_lines=24 base=${rangeBase}`);
|
|
expect(out).toMatch(/^NEXT: scoped \(a blocking finding was fixed on a standard diff with 24 runtime lines in the fix range/m);
|
|
expect(out).toContain('DISPATCH: fix-check fix-check effort=full');
|
|
expect(out).toContain('DISPATCH: red-team red-team effort=full');
|
|
expect(out).toContain('DISPATCH: adversarial-native adversarial effort=full');
|
|
expect(out).not.toContain('DISPATCH: specialist');
|
|
expect(JSON.parse(run(r, [...pass2, '--range-base', rangeBase, '--json']).stdout)).toMatchObject({ next: { step: 'scoped' }, fix_range: { base: rangeBase, runtime_lines: 24 } });
|
|
});
|
|
test('a 151-line range, no --range-base, an unknown range base and uncommitted fixes keep the full pass 2', () => {
|
|
const big = fixed(151);
|
|
expect(run(big.r, [...pass2, '--range-base', big.rangeBase]).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and the fix range has 151 runtime lines \(> 150\)/m);
|
|
const { r, rangeBase } = fixed(10);
|
|
expect(run(r, [...pass2.slice(0, -2), '--range-base', rangeBase]).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and pass 1 ran at full depth/m);
|
|
expect(run(r, pass2).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and the fix range was not read/m);
|
|
const unknown = run(r, [...pass2, '--range-base', 'f'.repeat(40)]).stdout;
|
|
expect(unknown).toMatch(/^FIX_RANGE: unread \(.*\) base=f{40}$/m);
|
|
expect(unknown).toMatch(/^NEXT: full /m);
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'fix.ts'), code(12, 'g'));
|
|
const dirty = run(r, [...pass2, '--range-base', rangeBase]).stdout;
|
|
expect(dirty).toMatch(/^FIX_RANGE: unread \(uncommitted or untracked edits.*\)/m);
|
|
expect(dirty).toMatch(/^NEXT: full /m);
|
|
expect(run(r, [...pass2, '--range-base']).status).toBe(2);
|
|
});
|
|
test('a fix range that touches a gate path keeps the full pass 2 without --touched-gate, and an empty range is unread', () => {
|
|
const r = repo({ 'src/a.ts': code(80), '.github/workflows/ci.yml': 'on: push\n' });
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
|
const rangeBase = git('rev-parse', 'HEAD').stdout.trim();
|
|
expect(run(r, [...pass2, '--range-base', rangeBase]).stdout).toMatch(/^FIX_RANGE: unread \(the fix range is empty: .*\) base=/m);
|
|
git('rm', '-q', '.github/workflows/ci.yml');
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'b.ts'), code(2, 'b'));
|
|
git('add', '.'); git('commit', '-qm', 'fix: revert the workflow edit');
|
|
const out = run(r, [...pass2, '--range-base', rangeBase]).stdout;
|
|
expect(out).toMatch(/^REVIEW_DEPTH: standard /m);
|
|
expect(out).toMatch(/^NEXT: full \(a blocking finding was fixed and a fix touched a gate-class path/m);
|
|
expect(JSON.parse(run(r, [...pass2, '--range-base', rangeBase, '--json']).stdout)).toMatchObject({ next: { step: 'full' }, fix_range: { touched_gate: true } });
|
|
}, 30_000);
|
|
test.each([
|
|
['an auth revert', 'src/auth/login.ts', 'export const login = (u: string) => u.length > 0;\n'],
|
|
['a migration revert', 'db/migrate/001_a.sql', 'ALTER TABLE users ADD COLUMN email text;\n'],
|
|
])('%s on a full-depth PR plans the full pass 2', (_n, file, text) => {
|
|
const r = repo({ 'src/a.ts': code(80) });
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
|
const write = (body: string) => { fs.mkdirSync(path.dirname(path.join(r.dir, file)), { recursive: true }); fs.writeFileSync(path.join(r.dir, file), body); };
|
|
git('checkout', '-q', 'main'); write(text); git('add', '.'); git('commit', '-qm', 'base file');
|
|
git('checkout', '-q', 'feat'); git('merge', '-q', '--no-edit', 'main');
|
|
write(text + '-- edited\n'); git('add', '.'); git('commit', '-qm', 'feat edit');
|
|
const rangeBase = git('rev-parse', 'HEAD').stdout.trim();
|
|
write(text);
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'b.ts'), code(2, 'b'));
|
|
git('add', '.'); git('commit', '-qm', 'fix: revert the edit');
|
|
const out = run(r, [...full1, '--range-base', rangeBase]).stdout;
|
|
expect(out).not.toMatch(/^REVIEW_CLASS: gate/m);
|
|
expect(out).toMatch(/^NEXT: full /m);
|
|
}, 30_000);
|
|
test('a fix that un-skips a gate tag added in an earlier pass-1 commit plans the full pass 2 on a full-depth PR', () => {
|
|
const r = repo({ 'src/a.ts': code(80), 'test/a.test.ts': "test.skip('x', () => {});\n" });
|
|
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'c.ts'), code(3, 'c')); git('add', '.'); git('commit', '-qm', 'later pass-1 commit');
|
|
const rangeBase = git('rev-parse', 'HEAD').stdout.trim();
|
|
fs.writeFileSync(path.join(r.dir, 'test', 'a.test.ts'), "test('x', () => {});\n");
|
|
fs.writeFileSync(path.join(r.dir, 'src', 'y.ts'), code(1, 'y'));
|
|
git('add', '.'); git('commit', '-qm', 'fix: un-skip');
|
|
expect(run(r, [...full1, '--range-base', rangeBase]).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and pass 1 ran at full depth/m);
|
|
}, 30_000);
|
|
test('--depth-floor full opts out of the scoped pass', () => {
|
|
const { r, rangeBase } = fixed(10);
|
|
expect(run(r, [...pass2, '--range-base', rangeBase, '--depth-floor', 'full']).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and the diff is at full depth/m);
|
|
});
|
|
});
|