diff --git a/test/autoplan-token-efficiency.test.ts b/test/autoplan-token-efficiency.test.ts index 69c8172d4..1e39c6011 100644 --- a/test/autoplan-token-efficiency.test.ts +++ b/test/autoplan-token-efficiency.test.ts @@ -64,10 +64,10 @@ describe('round budget', () => { test('a resumed run keeps the max_rounds it persisted', () => { const s = start(); - fs.writeFileSync(path.join(s.out, 'run.json'), JSON.stringify({ ...readRunJson(s.out), max_rounds: 3 }, null, 2) + '\n'); + fs.writeFileSync(path.join(s.out, 'run.json'), JSON.stringify({ ...readRunJson(s.out), max_rounds: 1 }, null, 2) + '\n'); expect(r.ap(['resume', '--out', s.out]).status).toBe(0); - expect(readRunJson(s.out).max_rounds).toBe(3); - expect(r.ap(['status', '--out', s.out]).stdout).toMatch(/^ROUNDS: ceo=1\/3 eng=1\/3 max_rounds=3 /m); + expect(readRunJson(s.out).max_rounds).toBe(1); + expect(r.ap(['status', '--out', s.out]).stdout).toMatch(/^ROUNDS: ceo=1\/1 eng=1\/1 max_rounds=1 /m); }); }); diff --git a/test/helpers/free-fixtures-data.ts b/test/helpers/free-fixtures-data.ts index 8cdfaeaf4..ccb6df282 100644 --- a/test/helpers/free-fixtures-data.ts +++ b/test/helpers/free-fixtures-data.ts @@ -189,6 +189,7 @@ export const FREE_FIXTURES: Readonly> = { 'test/fixtures/pty-idle-turn-end.json': ['test/helpers/claude-pty-runner.runners.unit.test.ts', 'test/helpers/claude-pty-runner.screen.unit.test.ts'], 'test/fixtures/redact-diagram/**': ['test/redact-context-exemptions.test.ts'], 'test/fixtures/remote-identity-vectors.json': ['test/bin-context-windows-slug.test.ts', 'test/gstack-slug-parity.test.ts', 'test/remote-identity-vectors.test.ts'], + 'test/fixtures/review-depth/**': ['test/review-dispatch-compare.test.ts'], 'test/fixtures/review-design-lite-reports-ci-36633323521.json': ['test/review-finalization-budget.test.ts'], 'test/fixtures/review-gate-integrity-opus-reports.json': ['test/gate-integrity-templates.test.ts'], 'test/fixtures/session-update-heartbeat.sh': ['test/session-update-heartbeat.test.ts'], diff --git a/test/review-dispatch-compare.test.ts b/test/review-dispatch-compare.test.ts new file mode 100644 index 000000000..24ba518a2 --- /dev/null +++ b/test/review-dispatch-compare.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, test } from 'bun:test'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; +import { runScriptSync } from '../lib/script-invocation'; + +const ROOT = path.join(import.meta.dir, '..'); +const SCRIPT = path.join(ROOT, 'scripts', 'review-dispatch-compare.ts'); +const FIXTURES = ['test/fixtures/review-depth/docs-only.json', 'test/fixtures/review-depth/code.json'].map(f => path.join(ROOT, f)); +const run = (args: string[]) => { + const r = runScriptSync(SCRIPT, [...FIXTURES.flatMap(f => ['--fixture', f]), ...args], { cwd: ROOT, encoding: 'utf8', timeout: 120_000 }); + expect(r.status).toBe(0); + return r.stdout as string; +}; + +describe('scripts/review-dispatch-compare.ts', () => { + test('the new policy never dispatches more reviewers than the legacy one, and a docs diff costs under a third', () => { + const out = JSON.parse(run(['--json'])); + expect(out.tokens_source).toBe('DEFAULT'); + expect(out.ship.length).toBe(10); + for (const row of out.ship) { + expect(row.new_dispatches).toBeLessThanOrEqual(row.legacy_dispatches); + expect(row.new_tokens).toBeLessThanOrEqual(row.legacy_tokens); + } + for (const row of out.ship.filter((r: any) => r.class === 'docs')) expect(row.ratio).toBeLessThan(0.34); + for (const f of out.autoplan) for (const r of f.runs) expect(r.next).toBeLessThanOrEqual(r.legacy); + }); + + test('--tokens replaces the default output estimates and the table says which it used', () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dispatch-compare-')); + try { + const tok = path.join(dir, 'measured.json'); + fs.writeFileSync(tok, JSON.stringify({ specialist: { full: 6929, light: 5446 } })); + const table = run(['--tokens', tok]); + expect(table).toContain(`TOKENS: measured (${tok})`); + expect(table).toMatch(/^SHIP_TOKEN_RATIO: median=0\.\d+ min=0\.\d+ max=\d\.\d+ \(n=10\)$/m); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } + }); +});