fix(gates): the shim reads a bare --gates and closed as on, and never swallows the next flag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-22 15:20:17 +02:00
commit e2fcf4060c
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 68 additions and 5 deletions

View file

@ -145,3 +145,49 @@ test('CLI shim missing required args returns usage error (exit 1)', () => {
assert.equal(parsed.ok, false);
assert.match(parsed.error, /usage:/);
});
// ---- --gates value rule (fix round 4.5a, #1) ---------------------------------
// The shim is tested only through its CLI; the exit code is asserted before
// any JSON.parse, so a crash or a usage error never reads as a wrong value.
function shimState(args) {
const r = runShim(args);
assert.equal(r.code, 0, `expected exit 0 for ${JSON.stringify(args)}, got ${r.code}: ${r.out}`);
const parsed = JSON.parse(r.out.trim());
assert.equal(parsed.ok, true);
return parsed.next_state;
}
test('[#1] bare --gates as the last argument → gates_on', () => {
assert.equal(shimState(['--state', 'idle', '--event', 'start', '--gates']), 'gates_on');
});
test('[#1] bare --gates before other flags swallows none of them → exit 0, gates_on', () => {
assert.equal(shimState(['--gates', '--state', 'idle', '--event', 'start']), 'gates_on');
});
test('[#1] --gates closed → gates_on', () => {
assert.equal(shimState(['--state', 'idle', '--event', 'start', '--gates', 'closed']), 'gates_on');
});
for (const bad of ['TRUE', 'yes', 'adaptive']) {
test(`[#1] --gates ${bad} → usage error (exit 1)`, () => {
const r = runShim(['--state', 'idle', '--event', 'start', '--gates', bad]);
assert.equal(r.code, 1, `expected exit 1 for --gates ${bad}, got ${r.code}: ${r.out}`);
const parsed = JSON.parse(r.out.trim());
assert.equal(parsed.ok, false);
assert.match(parsed.error, /usage/);
});
}
test('--gates true → gates_on', () => {
assert.equal(shimState(['--state', 'idle', '--event', 'start', '--gates', 'true']), 'gates_on');
});
test('--gates false → auto_running', () => {
assert.equal(shimState(['--state', 'idle', '--event', 'start', '--gates', 'false']), 'auto_running');
});
test('--gates open → auto_running', () => {
assert.equal(shimState(['--state', 'idle', '--event', 'start', '--gates', 'open']), 'auto_running');
});