11import test from 'node:test' ;
22import assert from 'node:assert/strict' ;
33import { parseArgs , usage } from '../args.ts' ;
4+ import { AppError } from '../errors.ts' ;
5+ import { getCliCommandNames } from '../command-schema.ts' ;
6+ import { listCapabilityCommands } from '../../core/capabilities.ts' ;
47
58test ( 'parseArgs recognizes --relaunch' , ( ) => {
69 const parsed = parseArgs ( [ 'open' , 'settings' , '--relaunch' ] ) ;
@@ -11,4 +14,69 @@ test('parseArgs recognizes --relaunch', () => {
1114
1215test ( 'usage includes --relaunch flag' , ( ) => {
1316 assert . match ( usage ( ) , / - - r e l a u n c h / ) ;
17+ assert . match ( usage ( ) , / p i n c h < s c a l e > \[ x \] \[ y \] / ) ;
18+ assert . match ( usage ( ) , / - - m e t a d a t a / ) ;
19+ } ) ;
20+
21+ test ( 'every capability command has a parser schema entry' , ( ) => {
22+ const schemaCommands = new Set ( getCliCommandNames ( ) ) ;
23+ for ( const command of listCapabilityCommands ( ) ) {
24+ assert . equal ( schemaCommands . has ( command ) , true , `Missing schema for command: ${ command } ` ) ;
25+ }
26+ } ) ;
27+
28+ test ( 'compat mode warns and strips unsupported pilot-command flags' , ( ) => {
29+ const parsed = parseArgs ( [ 'press' , '10' , '20' , '--depth' , '2' ] , { strictFlags : false } ) ;
30+ assert . equal ( parsed . command , 'press' ) ;
31+ assert . equal ( parsed . flags . snapshotDepth , undefined ) ;
32+ assert . equal ( parsed . warnings . length , 1 ) ;
33+ assert . match ( parsed . warnings [ 0 ] , / n o t s u p p o r t e d f o r c o m m a n d p r e s s / ) ;
34+ } ) ;
35+
36+ test ( 'strict mode rejects unsupported pilot-command flags' , ( ) => {
37+ assert . throws (
38+ ( ) => parseArgs ( [ 'press' , '10' , '20' , '--depth' , '2' ] , { strictFlags : true } ) ,
39+ ( error ) =>
40+ error instanceof AppError &&
41+ error . code === 'INVALID_ARGS' &&
42+ error . message . includes ( 'not supported for command press' ) ,
43+ ) ;
44+ } ) ;
45+
46+ test ( 'snapshot command accepts command-specific flags' , ( ) => {
47+ const parsed = parseArgs ( [ 'snapshot' , '-i' , '-c' , '--depth' , '3' , '-s' , 'Login' ] , { strictFlags : true } ) ;
48+ assert . equal ( parsed . command , 'snapshot' ) ;
49+ assert . equal ( parsed . flags . snapshotInteractiveOnly , true ) ;
50+ assert . equal ( parsed . flags . snapshotCompact , true ) ;
51+ assert . equal ( parsed . flags . snapshotDepth , 3 ) ;
52+ assert . equal ( parsed . flags . snapshotScope , 'Login' ) ;
53+ } ) ;
54+
55+ test ( 'unknown short flags are rejected' , ( ) => {
56+ assert . throws (
57+ ( ) => parseArgs ( [ 'press' , '10' , '20' , '-x' ] , { strictFlags : true } ) ,
58+ ( error ) => error instanceof AppError && error . code === 'INVALID_ARGS' && error . message === 'Unknown flag: -x' ,
59+ ) ;
60+ } ) ;
61+
62+ test ( 'all commands participate in strict command-flag validation' , ( ) => {
63+ assert . throws (
64+ ( ) => parseArgs ( [ 'open' , 'Settings' , '--depth' , '1' ] , { strictFlags : true } ) ,
65+ ( error ) =>
66+ error instanceof AppError &&
67+ error . code === 'INVALID_ARGS' &&
68+ error . message . includes ( 'not supported for command open' ) ,
69+ ) ;
70+ } ) ;
71+
72+ test ( 'invalid enum/range errors are deterministic' , ( ) => {
73+ assert . throws (
74+ ( ) => parseArgs ( [ 'snapshot' , '--backend' , 'foo' ] , { strictFlags : true } ) ,
75+ ( error ) =>
76+ error instanceof AppError && error . code === 'INVALID_ARGS' && error . message === 'Invalid backend: foo' ,
77+ ) ;
78+ assert . throws (
79+ ( ) => parseArgs ( [ 'snapshot' , '--depth' , '-1' ] , { strictFlags : true } ) ,
80+ ( error ) => error instanceof AppError && error . code === 'INVALID_ARGS' && error . message === 'Invalid depth: -1' ,
81+ ) ;
1482} ) ;
0 commit comments