fix(endsession): parse arguments with the arg-parser so a slug with -h is no help request, and only the operator starts it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-23 14:45:25 +02:00
commit 403afe606f
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
5 changed files with 148 additions and 7 deletions

View file

@ -1,7 +1,12 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { spawnSync } from 'node:child_process';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from '../../lib/parsers/arg-parser.mjs';
const PARSER = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'lib', 'parsers', 'arg-parser.mjs');
test('trekbrief — empty args', () => {
const r = parseArgs('', 'trekbrief');
assert.equal(r.command, 'trekbrief');
@ -155,3 +160,43 @@ test('trekcontinue — .md positional accepted by parser (rejection is command-l
assert.deepEqual(r.positional, ['NEXT-SESSION-PROMPT.local.md']);
assert.deepEqual(r.errors, []);
});
// --- #15 — /trekendsession reads its arguments with the parser ---
// A slug or label holding "-h" is an argument, not a help request: only the
// exact --help flag or a lone -h as the first positional asks for help.
test('[#15] trekendsession — a slug is one positional, with no errors', () => {
const r = parseArgs('2026-05-01-hotfix', 'trekendsession');
assert.deepEqual(r.errors, []);
assert.deepEqual(r.positional, ['2026-05-01-hotfix']);
assert.equal(r.flags['--help'], undefined);
});
test('[#15] trekendsession — a path and a quoted label are two positionals, with no --help', () => {
const r = parseArgs('fix-header "Session 2"', 'trekendsession');
assert.deepEqual(r.errors, []);
assert.deepEqual(r.positional, ['fix-header', 'Session 2']);
assert.equal(r.flags['--help'], undefined);
});
test('[#15] trekendsession — --help is the boolean help flag', () => {
const r = parseArgs('--help', 'trekendsession');
assert.deepEqual(r.errors, []);
assert.equal(r.flags['--help'], true);
assert.deepEqual(r.unknown, []);
});
test('[#15] trekendsession — the CLI with --command trekendsession -- fix-header exits 0', () => {
const r = spawnSync(process.execPath, [PARSER, '--command', 'trekendsession', '--', 'fix-header'], { encoding: 'utf8' });
assert.equal(r.status, 0, `the parser CLI refused trekendsession: ${r.stdout}${r.stderr}`);
const out = JSON.parse(r.stdout);
assert.deepEqual(out.positional, ['fix-header']);
assert.equal(out.flags['--help'], undefined);
});
test('trekendsession — -h stays a positional (no alias resolution)', () => {
const r = parseArgs('-h', 'trekendsession');
assert.deepEqual(r.positional, ['-h']);
assert.deepEqual(r.errors, []);
assert.equal(r.flags['--help'], undefined);
});