fix(validators): brief-validator CLI no-flag invocation bailed to Usage
The documented `brief-validator.mjs <brief.md>` invocation (no flags) always bailed to Usage/exit 2. Root cause: when --min-version is absent, minIdx is -1, so the skip index minIdx+1 was 0 — excluding argv index 0, exactly where the file positional sits in the no-flag case. Any leading flag (--soft, --json) pushed the file to index >=1 and masked the bug, so the function-level tests never caught it. Guard the skip index to -1 when --min-version is absent. Add two CLI regression tests (execFileSync, matching the next-session-prompt-validator pattern): no-flag invocation reaches validation, and --min-version still skips its value token to find the file. Suite 822 -> 824 (822/0/2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WH1krHamUehZh6JqVqs85t
This commit is contained in:
parent
0c634b6636
commit
926b768543
2 changed files with 44 additions and 1 deletions
|
|
@ -252,7 +252,11 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|||
const minIdx = args.indexOf('--min-version');
|
||||
const minBriefVersion = minIdx >= 0 ? args[minIdx + 1] : undefined;
|
||||
// filePath is the first positional, skipping the --min-version value token.
|
||||
const filePath = args.find((a, i) => !a.startsWith('--') && i !== minIdx + 1);
|
||||
// Guard: when --min-version is absent (minIdx === -1) the skip index must be -1,
|
||||
// not 0 — otherwise the no-flag invocation `brief-validator.mjs <brief.md>` drops
|
||||
// the file (which sits at index 0) and bails to Usage.
|
||||
const skipIdx = minIdx >= 0 ? minIdx + 1 : -1;
|
||||
const filePath = args.find((a, i) => !a.startsWith('--') && i !== skipIdx);
|
||||
if (!filePath) {
|
||||
process.stderr.write('Usage: brief-validator.mjs [--soft] [--min-version <x.y>] <brief.md>\n');
|
||||
process.exit(2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue