voyage/tests/lib/arg-parser.test.mjs
Kjell Tore Guttormsen 9fb536e2d8 feat(voyage): S11 — NW2 part B, integrate opt-in --workflow flag
Make the bake-off-validated Workflow substrate (Arm B) reachable behind an
opt-in --workflow flag for /trekreview. Default Phase 5-6 path stays prose
to preserve the lower portability floor; --workflow raises the consumer
floor to Claude Code 2.1.154+ (the Workflow tool).

- arg-parser: --workflow added to trekreview boolean flags
- commands/trekreview.md: flag row + Phase 5 substrate-routing gate +
  new section 'Phase 5-6 via the Workflow substrate' (invocation contract,
  S10 gotchas, bake-off citation, auto/bypass residual as Known limitation)
- docs/command-modes.md: --workflow row in /trekreview table
- routes to existing scripts/trekreview-armB.workflow.mjs (byte-identical to
  the S10 part-B POSITIVE build); integration is pure routing, no script change

TDD: 8 new tests (arg-parser flag recognition + combine; command/doc prose
pins for route, opt-in posture, 2.1.154+ floor, bake-off evidence).
Suite 662 -> 670 (668 pass / 2 skip / 0 fail). plugin validate clean modulo
known root-CLAUDE.md warning. Resolves W1-narrow-wins-plan.md S11.
2026-06-18 17:22:09 +02:00

157 lines
5.6 KiB
JavaScript

import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { parseArgs } from '../../lib/parsers/arg-parser.mjs';
test('trekbrief — empty args', () => {
const r = parseArgs('', 'trekbrief');
assert.equal(r.command, 'trekbrief');
assert.deepEqual(r.flags, {});
});
test('trekbrief — --quick boolean', () => {
const r = parseArgs('--quick', 'trekbrief');
assert.equal(r.flags['--quick'], true);
});
test('trekresearch — --project value capture', () => {
const r = parseArgs('--project .claude/projects/2026-04-30-foo', 'trekresearch');
assert.equal(r.flags['--project'], '.claude/projects/2026-04-30-foo');
});
test('trekresearch — --quick --local combined', () => {
const r = parseArgs('--quick --local', 'trekresearch');
assert.equal(r.flags['--quick'], true);
assert.equal(r.flags['--local'], true);
});
test('trekplan — --research multi-value', () => {
const r = parseArgs('--research a.md b.md c.md', 'trekplan');
assert.deepEqual(r.flags['--research'], ['a.md', 'b.md', 'c.md']);
});
test('trekplan — --research multi stops at next flag', () => {
const r = parseArgs('--research a.md b.md --project /x', 'trekplan');
assert.deepEqual(r.flags['--research'], ['a.md', 'b.md']);
assert.equal(r.flags['--project'], '/x');
});
test('trekplan — --brief required-value flag', () => {
const r = parseArgs('--brief brief.md', 'trekplan');
assert.equal(r.flags['--brief'], 'brief.md');
});
test('trekplan — missing value for --brief produces error', () => {
const r = parseArgs('--brief --quick', 'trekplan');
assert.ok(r.errors.find(e => e.code === 'ARG_MISSING_VALUE'));
});
test('trekplan — --decompose value flag', () => {
const r = parseArgs('--decompose plan.md', 'trekplan');
assert.equal(r.flags['--decompose'], 'plan.md');
});
test('trekexecute — --resume + --project', () => {
const r = parseArgs('--resume --project /tmp/p', 'trekexecute');
assert.equal(r.flags['--resume'], true);
assert.equal(r.flags['--project'], '/tmp/p');
});
test('trekexecute — --step N value', () => {
const r = parseArgs('--step 3', 'trekexecute');
assert.equal(r.flags['--step'], '3');
});
test('trekexecute — unknown flag goes to unknown[]', () => {
const r = parseArgs('--mystery foo', 'trekexecute');
assert.ok(r.unknown.includes('--mystery'));
});
test('quoted positional with spaces preserved', () => {
const r = parseArgs('"hello world" simple', 'trekbrief');
assert.deepEqual(r.positional, ['hello world', 'simple']);
});
test('unknown command reported as error', () => {
const r = parseArgs('--quick', 'notacommand');
assert.ok(r.errors.find(e => e.code === 'ARG_UNKNOWN_COMMAND'));
});
test('trekreview — --project value capture', () => {
const r = parseArgs('--project .claude/projects/2026-05-01-foo', 'trekreview');
assert.equal(r.flags['--project'], '.claude/projects/2026-05-01-foo');
});
test('trekreview — --since <ref> value', () => {
const r = parseArgs('--since HEAD~5', 'trekreview');
assert.equal(r.flags['--since'], 'HEAD~5');
});
test('trekreview — --quick + --validate combined', () => {
const r = parseArgs('--quick --validate', 'trekreview');
assert.equal(r.flags['--quick'], true);
assert.equal(r.flags['--validate'], true);
});
test('trekreview — unknown flag goes to unknown[]', () => {
const r = parseArgs('--mystery foo', 'trekreview');
assert.ok(r.unknown.includes('--mystery'));
});
// --- S11 (NW2 part B) — opt-in --workflow substrate flag ---
test('trekreview — --workflow boolean flag (NW2 opt-in substrate)', () => {
const r = parseArgs('--workflow', 'trekreview');
assert.equal(r.flags['--workflow'], true);
assert.ok(!r.unknown.includes('--workflow'),
'--workflow must be a recognized trekreview flag, not unknown[]');
});
test('trekreview — --workflow combines with --quick + --project', () => {
const r = parseArgs('--workflow --quick --project .claude/projects/x', 'trekreview');
assert.equal(r.flags['--workflow'], true);
assert.equal(r.flags['--quick'], true);
assert.equal(r.flags['--project'], '.claude/projects/x');
assert.deepEqual(r.unknown, []);
});
test('trekcontinue — empty args produce no flags and no positional', () => {
const r = parseArgs('', 'trekcontinue');
assert.equal(r.command, 'trekcontinue');
assert.deepEqual(r.flags, {});
assert.deepEqual(r.positional, []);
assert.deepEqual(r.errors, []);
});
test('trekcontinue — --help boolean flag', () => {
const r = parseArgs('--help', 'trekcontinue');
assert.equal(r.flags['--help'], true);
});
test('trekcontinue — -h treated as positional (no alias resolution)', () => {
const r = parseArgs('-h', 'trekcontinue');
assert.deepEqual(r.positional, ['-h']);
assert.deepEqual(r.errors, []);
assert.equal(r.flags['--help'], undefined);
});
test('trekcontinue — --cleanup boolean flag', () => {
const r = parseArgs('--cleanup', 'trekcontinue');
assert.equal(r.flags['--cleanup'], true);
});
test('trekcontinue — --cleanup --confirm both flags', () => {
const r = parseArgs('--cleanup --confirm', 'trekcontinue');
assert.equal(r.flags['--cleanup'], true);
assert.equal(r.flags['--confirm'], true);
});
test('trekcontinue — positional project dir captured', () => {
const r = parseArgs('.claude/projects/2026-05-04-foo', 'trekcontinue');
assert.deepEqual(r.positional, ['.claude/projects/2026-05-04-foo']);
});
test('trekcontinue — .md positional accepted by parser (rejection is command-level)', () => {
const r = parseArgs('NEXT-SESSION-PROMPT.local.md', 'trekcontinue');
assert.deepEqual(r.positional, ['NEXT-SESSION-PROMPT.local.md']);
assert.deepEqual(r.errors, []);
});