Skip to content

Commit bbf9ee4

Browse files
author
agentcore-bot
committed
fix: fix issue #984
1 parent 2c34489 commit bbf9ee4

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/cli/commands/status/__tests__/action.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/__exit: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(/__exit:1/);
858+
expect(exitSpy).toHaveBeenCalledWith(1);
859+
} finally {
860+
exitSpy.mockRestore();
861+
}
862+
});
863+
});

src/cli/commands/status/command.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const registerStatus = (program: Command) => {
7676
Invalid resource type &apos;{cliOptions.type}&apos;. Valid types: {VALID_RESOURCE_TYPES.join(', ')}
7777
</Text>
7878
);
79-
return;
79+
process.exit(1);
8080
}
8181

8282
// Validate --state
@@ -86,7 +86,7 @@ export const registerStatus = (program: Command) => {
8686
Invalid state &apos;{cliOptions.state}&apos;. Valid states: {VALID_STATES.join(', ')}
8787
</Text>
8888
);
89-
return;
89+
process.exit(1);
9090
}
9191

9292
try {

0 commit comments

Comments
 (0)