fix(verdict-gate): read --repo=<dir> and refuse unknown options

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-26 13:44:11 +01:00
commit 703c508433
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 85 additions and 5 deletions

View file

@ -625,3 +625,68 @@ test('[M11] a 64-hex name of a branch in a SHA-1 repository is stale with the re
assert.ok(r.stdout.includes(name), `the reason names the id as written: ${r.stdout}`);
} finally { fx.cleanup(); }
});
// ---- M6: --repo=<dir> is read, and an unknown option is refused ----
/** An ALLOW review in a throwaway directory; `fn(path)` gets its path. */
function withAllowReview(fn) {
const dir = mkdtempSync(join(tmpdir(), 'verdict-gate-m6-'));
try {
const p = join(dir, 'review.md');
writeFileSync(p, review({ verdict: 'ALLOW', severities: ['MINOR'] }));
return fn(p);
} finally {
rmSync(dir, { recursive: true, force: true });
}
}
function gateArgs(...argv) {
return spawnSync(process.execPath, [GATE, ...argv], { encoding: 'utf-8', env: childEnv() });
}
test('[M6] --repo=<dir> runs the stale check', () => {
const fx = gateRepo();
try {
fx.commit('fix: more work', { 'a.mjs': 'export const a = 2;\n' });
const p = join(fx.base, 'review.md');
writeFileSync(p, review({ verdict: 'ALLOW', severities: ['MINOR'], scopeShaEnd: fx.reviewed }));
assertStale(gateArgs('--json', p, `--repo=${fx.dir}`), /a\.mjs/);
} finally { fx.cleanup(); }
});
test('[M6] --repo= with no value exits 2', () => {
withAllowReview((p) => {
const r = gateArgs('--json', p, '--repo=');
assert.equal(r.status, 2, r.stdout + r.stderr);
assert.match(r.stderr, /--repo= needs a value/);
});
});
test('[M6] an unknown option exits 2', () => {
withAllowReview((p) => {
const r = gateArgs('--bogus', p);
assert.equal(r.status, 2, r.stdout + r.stderr);
assert.match(r.stderr, /unknown option --bogus/);
assert.match(r.stderr, /Usage: verdict-gate\.mjs/);
});
});
test('[M6] an unknown --x=value option exits 2', () => {
withAllowReview((p) => {
const r = gateArgs(p, '--x=value');
assert.equal(r.status, 2, r.stdout + r.stderr);
assert.match(r.stderr, /unknown option --x=value/);
assert.match(r.stderr, /Usage: verdict-gate\.mjs/);
});
});
test('[M6] --json is accepted while --jsonx is refused', () => {
withAllowReview((p) => {
const ok = gateArgs('--json', p);
assert.equal(ok.status, 0, ok.stdout + ok.stderr);
assert.equal(JSON.parse(ok.stdout).verdict, 'ALLOW');
const bad = gateArgs('--jsonx', p);
assert.equal(bad.status, 2, bad.stdout + bad.stderr);
assert.match(bad.stderr, /unknown option --jsonx/);
});
});