fix(trekendsession): Phase 3 re-reads the arguments instead of splicing the label into the shell line

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-26 16:12:44 +01:00
commit 89975a1fd6
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
5 changed files with 223 additions and 15 deletions

View file

@ -10,6 +10,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { execFileSync, spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { childEnv } from '../helpers/child-env.mjs';
import {
validateNextSessionPromptContent,
@ -204,3 +205,37 @@ test('[#102] sibling: rb.valid counts: an invalid B makes the consistency result
rmSync(dir, { recursive: true, force: true });
}
});
// --- E16a (fix round 4.5b): --state-file without a value is refused ----------
// The CLI refuses --state-file when no value follows it, or when the next word
// is another option, with exit 2 and "needs a value". Without the refusal the
// consistency call runs on the same pair and exits 0 or 1, so each test runs
// that call and asserts the exit code and the message.
function runCliClean(args) {
return spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf-8', env: childEnv() });
}
test('[E16a] --state-file as the last argument exits 2 with needs a value', () => {
const dir = mkdtempSync(join(tmpdir(), 'nspv-cli-'));
try {
const { a, b } = stalePair(dir);
const r = runCliClean(['--json', '--consistency', a, b, '--state-file']);
assert.equal(r.status, 2, `a --state-file with no value was not refused: exit ${r.status}: ${r.stdout}${r.stderr}`);
assert.match(r.stderr, /--state-file needs a value/, `the refusal does not say the flag needs a value: ${r.stderr}`);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('[E16a] --state-file followed by another option exits 2', () => {
const dir = mkdtempSync(join(tmpdir(), 'nspv-cli-'));
try {
const { a, b } = stalePair(dir);
const r = runCliClean(['--state-file', '--json', '--consistency', a, b]);
assert.equal(r.status, 2, `--state-file took the option after it as its value: exit ${r.status}: ${r.stdout}${r.stderr}`);
assert.match(r.stderr, /--state-file needs a value/, `the refusal does not say the flag needs a value: ${r.stderr}`);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});