/** * The two report bins must DISTINGUISH operator-verified rows from * unverified ones (act:5335d1e2): report-last tags every non-operator * row and says the run is PARTIAL; report-status never lets an * unverified scenario read clean/stale, and gives it its own label. * * Runs the built bins as child processes against a fixture reports dir. */ import { test } from 'node:test'; import assert from 'node:assert/strict'; 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 { fileURLToPath } from 'node:url'; const here = path.dirname(fileURLToPath(import.meta.url)); const BIN = (name: string) => path.resolve(here, '..', 'src', 'cli', `${name}.js`); function row(over: Record): Record { return { runId: 'run-2026-08-27T00-00-00-000Z', runStartedAt: '2026-08-27T00:00:00.000Z', gitSha: 'abcdef0123456789', scenarioFile: 'features/01-thing.feature', scenarioTitle: 'Thing', stepText: 'x', checkId: '1.01', pathHash: 'aaaa', acItemId: null, screenshotPath: null, notes: null, durationMs: 1, role: 'user', costUsd: null, ...over, }; } function fixture(rows: Record[], totals: Record): string { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cabinet-verify-report-')); fs.mkdirSync(path.join(dir, 'reports')); fs.mkdirSync(path.join(dir, 'features')); fs.writeFileSync(path.join(dir, 'features', '01-thing.feature'), 'Feature: Thing\n'); fs.writeFileSync( path.join(dir, 'reports', 'run-2026-08-27T00-00-00-000Z.summary.json'), JSON.stringify({ runId: 'run-2026-08-27T00-00-00-000Z', runStartedAt: '2026-08-27T00:00:00.000Z', ...totals, rows }, null, 2), ); return dir; } function run(bin: string, cwd: string): string { const r = spawnSync(process.execPath, [BIN(bin)], { cwd, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0' } }); assert.equal(r.status, 0, r.stderr); return r.stdout + r.stderr; } test('report-last: unverified rows are tagged and the run is called PARTIAL', () => { const dir = fixture( [ row({ checkId: '1.01', verdict: 'human:P', source: 'human', stepText: 'human-verdict: looks right?' }), row({ checkId: '1.02', verdict: 'unverified:P', source: 'unverified', stepText: 'unverified-verdict: nav ok?', notes: '[unverified — non-TTY stdin; responder claimed source=human] fine' }), row({ checkId: '1.03', verdict: 'claude:I', source: 'claude', stepText: 'claude-verdict: button?', notes: '[claude-auto, confidence:low] clipped' }), ], { total: 3, passed: 1, failed: 0, humanVerdicts: 1, unverified: 2 }, ); try { const out = run('report-last', dir); assert.match(out, /unverified 2/); assert.match(out, /PARTIAL/); assert.match(out, /1\.02.*\[unverified\]/); assert.match(out, /1\.03.*\[unverified·low-confidence\]/); assert.doesNotMatch(out, /1\.01.*\[unverified/); // the legacy claude I still surfaces under ISSUES so it can be spot-checked assert.match(out, /I = ISSUES[\s\S]*1\.03/); } finally { fs.rmSync(dir, { recursive: true, force: true }); } }); test('report-status: a scenario whose only subjective rows are unverified is labelled unverified, never clean', () => { const dir = fixture( [ row({ checkId: '1.01', verdict: 'auto:pass', source: 'auto' }), row({ checkId: '1.02', verdict: 'unverified:P', source: 'unverified' }), row({ checkId: '1.03', verdict: 'claude:P', source: 'claude' }), ], { total: 3, passed: 1, failed: 0, humanVerdicts: 0, unverified: 2 }, ); try { const out = run('report-status', dir); assert.match(out, /01-thing\.feature\s+unverified/); assert.doesNotMatch(out, /01-thing\.feature\s+clean/); assert.match(out, /unverified:2/); assert.match(out, /1 unverified/); } finally { fs.rmSync(dir, { recursive: true, force: true }); } }); test('report-status: an operator-verified scenario with one unverified row is still not clean', () => { const dir = fixture( [ row({ checkId: '1.01', verdict: 'human:P', source: 'human' }), row({ checkId: '1.02', verdict: 'unverified:P', source: 'unverified' }), ], { total: 2, passed: 1, failed: 0, humanVerdicts: 1, unverified: 1 }, ); try { const out = run('report-status', dir); assert.match(out, /01-thing\.feature\s+unverified/); assert.match(out, /P:1/); assert.match(out, /unverified:1/); } finally { fs.rmSync(dir, { recursive: true, force: true }); } }); test('report-status: operator verdicts alone read clean (the label is earned, not withheld)', () => { const dir = fixture( [row({ checkId: '1.01', verdict: 'human:P', source: 'human' }), row({ checkId: '1.02', verdict: 'human:N', source: 'human' })], { total: 2, passed: 2, failed: 0, humanVerdicts: 2, unverified: 0 }, ); try { const out = run('report-status', dir); // no git repo in the fixture → commitsAhead null → clean assert.match(out, /01-thing\.feature\s+clean/); } finally { fs.rmSync(dir, { recursive: true, force: true }); } });