@@ -5,8 +5,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55import { cliCommandCatalog } from "../command-catalog.js" ;
66import { isReservedNonPluginCommandRoot } from "../command-registration-policy.js" ;
77import { collectShellCompletionCommandTree } from "../completion-command-tree.js" ;
8- import { formatCliJsonFailure } from "../failure-output.js" ;
9- import { runCliWithExitFinalization } from "../one-shot-exit.js" ;
108import { getCoreCliCommandNames , registerCoreCliByName } from "./command-registry-core.js" ;
119import { createProgramContext } from "./context.js" ;
1210import { getCoreCliCommandDescriptors } from "./core-command-descriptors.js" ;
@@ -253,7 +251,7 @@ function requiredCommandArgs(command: Command): string[] {
253251 if ( ! argument . required ) {
254252 return [ ] ;
255253 }
256- return argument . variadic ? [ "guard-value" ] : [ "guard-value" ] ;
254+ return [ "guard-value" ] ;
257255 } ) ;
258256 for ( const option of command . options ) {
259257 if ( ! option . mandatory ) {
@@ -427,38 +425,23 @@ describe("root command descriptions", () => {
427425 ) . toEqual ( [ ] ) ;
428426 } ) ;
429427
430- it ( "routes every registered JSON command failure through the canonical envelope " , async ( ) => {
428+ it ( "accepts declared JSON output options through the registered command parsers " , async ( ) => {
431429 const program = await registerAllBuiltInCommands ( ) ;
432430 const contexts = collectShellCompletionCommandTree ( program ) . descendants . filter ( ( context ) => {
433431 const path = context . pathVariants [ 0 ] ?. join ( " " ) ?? "" ;
434- return supportsJsonOutput ( path , context . command ) ;
432+ return supportsJsonOutput ( path , context . command ) && hasOwnJsonOption ( context . command ) ;
435433 } ) ;
436- const runtime = { log : vi . fn ( ) , error : vi . fn ( ) , exit : vi . fn ( ) } ;
437434
438435 expect ( contexts . length ) . toBeGreaterThan ( 0 ) ;
439436 for ( const context of contexts ) {
440437 const path = context . pathVariants [ 0 ] ?. join ( " " ) ?? "" ;
441438 const failure = new Error ( `synthetic failure for ${ path } ` ) ;
442- const payloads : unknown [ ] = [ ] ;
443439 context . command . action ( async ( ) => {
444440 throw failure ;
445441 } ) ;
446- const args = requiredCommandArgs ( context . command ) ;
447- if ( hasOwnJsonOption ( context . command ) ) {
448- args . push ( "--json" ) ;
449- }
450-
451- await runCliWithExitFinalization ( {
452- runtime,
453- run : async ( ) => {
454- await context . command . parseAsync ( args , { from : "user" } ) ;
455- } ,
456- onError : ( error ) => {
457- payloads . push ( formatCliJsonFailure ( error ) ) ;
458- } ,
459- } ) ;
442+ const args = [ ...requiredCommandArgs ( context . command ) , "--json" ] ;
460443
461- expect ( payloads , path ) . toEqual ( [ formatCliJsonFailure ( failure ) ] ) ;
444+ await expect ( context . command . parseAsync ( args , { from : "user" } ) , path ) . rejects . toBe ( failure ) ;
462445 }
463446 } ) ;
464447} ) ;
0 commit comments