@@ -2,6 +2,8 @@ import { test } from 'vitest';
22import assert from 'node:assert/strict' ;
33import { parseArgs } from '../args.ts' ;
44import { AppError } from '../../../kernel/errors.ts' ;
5+ import { listCliCommandNames } from '../../../command-catalog.ts' ;
6+ import { getCliCommandSchema } from '../../../cli-schema/command-schema.ts' ;
57
68test ( 'parseArgs rejects test retries above the supported ceiling' , ( ) => {
79 assert . throws (
@@ -130,6 +132,32 @@ test('negative numeric positionals are accepted without -- separator', () => {
130132 assert . deepEqual ( pressed . positionals , [ '-10' , '20' ] ) ;
131133} ) ;
132134
135+ test ( 'get accepts a snapshot ref with a multiword label' , ( ) => {
136+ const parsed = parseArgs ( [ 'get' , 'text' , '@e5~s3' , 'World' , 'Clock' ] , { strictFlags : true } ) ;
137+
138+ assert . equal ( parsed . command , 'get' ) ;
139+ assert . deepEqual ( parsed . positionals , [ 'text' , '@e5~s3' , 'World' , 'Clock' ] ) ;
140+ } ) ;
141+
142+ test ( 'bounded commands reject excess positionals from their CLI schema' , ( ) => {
143+ for ( const command of listCliCommandNames ( ) ) {
144+ const schema = getCliCommandSchema ( command ) ;
145+ if ( schema . allowsExtraPositionals ) continue ;
146+ const maximum = schema . positionalArgs ?. length ?? 0 ;
147+ const positionals = Array . from ( { length : maximum + 1 } , ( _ , index ) => `arg-${ index + 1 } ` ) ;
148+
149+ assert . throws (
150+ ( ) => parseArgs ( [ command , ...positionals ] , { strictFlags : true } ) ,
151+ ( error : unknown ) =>
152+ error instanceof AppError &&
153+ error . code === 'INVALID_ARGS' &&
154+ error . message ===
155+ `${ command } accepts at most ${ maximum } positional argument(s), received ${ positionals . length } : ${ positionals . join ( ' ' ) } ` ,
156+ `Expected ${ command } to reject excess positionals` ,
157+ ) ;
158+ }
159+ } ) ;
160+
133161test ( 'command-specific flags without command fail in strict mode' , ( ) => {
134162 assert . throws (
135163 ( ) => parseArgs ( [ '--depth' , '3' ] , { strictFlags : true } ) ,
0 commit comments