Skip to content

fix(status): exit non-zero when --type/--state filter value is invalid#1169

Open
aidandaly24 wants to merge 1 commit intomainfrom
fix/984-27071612
Open

fix(status): exit non-zero when --type/--state filter value is invalid#1169
aidandaly24 wants to merge 1 commit intomainfrom
fix/984-27071612

Conversation

@aidandaly24
Copy link
Copy Markdown
Contributor

@aidandaly24 aidandaly24 commented May 7, 2026

Description

agentcore status --type <invalid> (and --state <invalid>) printed an error message but returned exit code 0. Non-interactive callers — scripts, CI pipelines, automation — had no way to detect the rejection and would happily continue as if nothing was wrong.

The fix is minimal: in src/cli/commands/status/command.tsx, after rendering the validation error for an invalid --type or --state, replace the bare return; with process.exit(1);. This matches the convention already used in this same file's catch handler (line 297). Two lines changed in production code.

Reviewer findings round 1: 1 finding, all approved.

Before

$ agentcore status --type bogus
Invalid resource type 'bogus'. Valid types: agent, runtime-endpoint, memory, credential, gateway, evaluator, online-eval, policy-engine, policy
$ echo $?
0

After

$ agentcore status --type bogus
Invalid resource type 'bogus'. Valid types: agent, runtime-endpoint, memory, credential, gateway, evaluator, online-eval, policy-engine, policy, config-bundle, ab-test
$ echo $?
1

Related Issue

Closes #984

Documentation PR

N/A — no user-facing documentation changes.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Added two unit tests in src/cli/commands/status/__tests__/action.test.ts that register the status command on a Commander program, parse it with --type bogus / --state bogus, and assert process.exit is called with 1. All 36 tests in this file pass; full CI (format, lint, typecheck, unit-test 1/3 + 2/3 + 3/3, build, CodeQL, security, secrets, ai-review) is green.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

@aidandaly24 aidandaly24 requested a review from a team May 7, 2026 19:30
@github-actions github-actions Bot added size/s PR size: S agentcore-harness-reviewing AgentCore Harness review in progress labels May 7, 2026
Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The fix correctly replaces return with process.exit(1) for the two validation branches, matching the existing convention used in the catch block of the same action (line 237). Tests cover both --type and --state paths and assert the exit code.

No blocking issues found. Nits I considered but did not flag:

  • When --json is set, the invalid-value branches still emit a non-JSON Ink-rendered error. This is pre-existing behavior (not introduced by this PR) and out of scope for fixing #984, but might be worth a follow-up so scripted/CI JSON consumers get a parseable error payload.
  • render(...) is async in Ink and process.exit(1) runs on the next microtask line; the same pattern is already used elsewhere in the CLI and appears to flush reliably for simple <Text> output, so I don't think it's worth changing here.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.1% 9045 / 20984
🔵 Statements 42.36% 9603 / 22669
🔵 Functions 39.75% 1560 / 3924
🔵 Branches 39.9% 5830 / 14610
Generated in workflow #2646 for commit bbf9ee4 by the Vitest Coverage Report Action

@github-actions github-actions Bot added size/s PR size: S and removed size/s PR size: S labels May 7, 2026
@aidandaly24 aidandaly24 changed the title fix: status --type/--state with invalid value should exit non-zero (#984) fix(status): exit non-zero when --type/--state filter value is invalid May 7, 2026
});

describe('registerStatus --type / --state validation exit code', () => {
const renderMock = vi.fn();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that we have to mock multiple modules to verify the validation logic feels like a code smell. I understand this fixes the bug, but I'm wondering if its worth refactoring the implementation to not only fix the bug, but also restructure it to make regressions more difficult to introduce.

Ex. extract the validation logic into a pure function and test that directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

status --type with invalid type prints error but exits 0

3 participants