From bbf9ee4413874bc95a5656a6ea825574ad045db5 Mon Sep 17 00:00:00 2001 From: agentcore-bot Date: Thu, 7 May 2026 19:28:41 +0000 Subject: [PATCH] fix: fix issue #984 --- .../commands/status/__tests__/action.test.ts | 56 +++++++++++++++++++ src/cli/commands/status/command.tsx | 4 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/status/__tests__/action.test.ts b/src/cli/commands/status/__tests__/action.test.ts index 1c3a089dc..062814942 100644 --- a/src/cli/commands/status/__tests__/action.test.ts +++ b/src/cli/commands/status/__tests__/action.test.ts @@ -805,3 +805,59 @@ describe('handleProjectStatus — invocation URL enrichment', () => { expect(agentEntry!.invocationUrl).toBeUndefined(); }); }); + +describe('registerStatus --type / --state validation exit code', () => { + const renderMock = vi.fn(); + vi.doMock('ink', () => ({ + Box: ({ children }: { children?: unknown }) => children, + Text: ({ children }: { children?: unknown }) => children, + render: (...args: unknown[]) => renderMock(...args), + })); + vi.doMock('../../../tui/guards', () => ({ + requireProject: vi.fn(), + })); + + beforeEach(() => { + renderMock.mockReset(); + }); + + it('exits with non-zero code when --type is invalid', async () => { + const { Command } = await import('@commander-js/extra-typings'); + const { registerStatus } = await import('../command.js'); + + const program = new Command(); + program.exitOverride(); + registerStatus(program as unknown as Parameters[0]); + + const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => { + throw new Error(`__exit:${code ?? 0}`); + }) as never); + + try { + await expect(program.parseAsync(['node', 'agentcore', 'status', '--type', 'bogus'])).rejects.toThrow(/__exit:1/); + expect(exitSpy).toHaveBeenCalledWith(1); + } finally { + exitSpy.mockRestore(); + } + }); + + it('exits with non-zero code when --state is invalid', async () => { + const { Command } = await import('@commander-js/extra-typings'); + const { registerStatus } = await import('../command.js'); + + const program = new Command(); + program.exitOverride(); + registerStatus(program as unknown as Parameters[0]); + + const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => { + throw new Error(`__exit:${code ?? 0}`); + }) as never); + + try { + await expect(program.parseAsync(['node', 'agentcore', 'status', '--state', 'bogus'])).rejects.toThrow(/__exit:1/); + expect(exitSpy).toHaveBeenCalledWith(1); + } finally { + exitSpy.mockRestore(); + } + }); +}); diff --git a/src/cli/commands/status/command.tsx b/src/cli/commands/status/command.tsx index 506ad10ec..ff0ec9c8a 100644 --- a/src/cli/commands/status/command.tsx +++ b/src/cli/commands/status/command.tsx @@ -76,7 +76,7 @@ export const registerStatus = (program: Command) => { Invalid resource type '{cliOptions.type}'. Valid types: {VALID_RESOURCE_TYPES.join(', ')} ); - return; + process.exit(1); } // Validate --state @@ -86,7 +86,7 @@ export const registerStatus = (program: Command) => { Invalid state '{cliOptions.state}'. Valid states: {VALID_STATES.join(', ')} ); - return; + process.exit(1); } try {