@@ -805,3 +805,59 @@ describe('handleProjectStatus — invocation URL enrichment', () => {
805805 expect ( agentEntry ! . invocationUrl ) . toBeUndefined ( ) ;
806806 } ) ;
807807} ) ;
808+
809+ describe ( 'registerStatus --type / --state validation exit code' , ( ) => {
810+ const renderMock = vi . fn ( ) ;
811+ vi . doMock ( 'ink' , ( ) => ( {
812+ Box : ( { children } : { children ?: unknown } ) => children ,
813+ Text : ( { children } : { children ?: unknown } ) => children ,
814+ render : ( ...args : unknown [ ] ) => renderMock ( ...args ) ,
815+ } ) ) ;
816+ vi . doMock ( '../../../tui/guards' , ( ) => ( {
817+ requireProject : vi . fn ( ) ,
818+ } ) ) ;
819+
820+ beforeEach ( ( ) => {
821+ renderMock . mockReset ( ) ;
822+ } ) ;
823+
824+ it ( 'exits with non-zero code when --type is invalid' , async ( ) => {
825+ const { Command } = await import ( '@commander-js/extra-typings' ) ;
826+ const { registerStatus } = await import ( '../command.js' ) ;
827+
828+ const program = new Command ( ) ;
829+ program . exitOverride ( ) ;
830+ registerStatus ( program as unknown as Parameters < typeof registerStatus > [ 0 ] ) ;
831+
832+ const exitSpy = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ( code ?: number ) => {
833+ throw new Error ( `__exit:${ code ?? 0 } ` ) ;
834+ } ) as never ) ;
835+
836+ try {
837+ await expect ( program . parseAsync ( [ 'node' , 'agentcore' , 'status' , '--type' , 'bogus' ] ) ) . rejects . toThrow ( / _ _ e x i t : 1 / ) ;
838+ expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
839+ } finally {
840+ exitSpy . mockRestore ( ) ;
841+ }
842+ } ) ;
843+
844+ it ( 'exits with non-zero code when --state is invalid' , async ( ) => {
845+ const { Command } = await import ( '@commander-js/extra-typings' ) ;
846+ const { registerStatus } = await import ( '../command.js' ) ;
847+
848+ const program = new Command ( ) ;
849+ program . exitOverride ( ) ;
850+ registerStatus ( program as unknown as Parameters < typeof registerStatus > [ 0 ] ) ;
851+
852+ const exitSpy = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ( code ?: number ) => {
853+ throw new Error ( `__exit:${ code ?? 0 } ` ) ;
854+ } ) as never ) ;
855+
856+ try {
857+ await expect ( program . parseAsync ( [ 'node' , 'agentcore' , 'status' , '--state' , 'bogus' ] ) ) . rejects . toThrow ( / _ _ e x i t : 1 / ) ;
858+ expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
859+ } finally {
860+ exitSpy . mockRestore ( ) ;
861+ }
862+ } ) ;
863+ } ) ;
0 commit comments