Skip to content

fix(status): exit non-zero on invalid --type/--state filter#1650

Draft
aidandaly24 wants to merge 2 commits into
aws:mainfrom
aidandaly24:fix/984
Draft

fix(status): exit non-zero on invalid --type/--state filter#1650
aidandaly24 wants to merge 2 commits into
aws:mainfrom
aidandaly24:fix/984

Conversation

@aidandaly24

Copy link
Copy Markdown
Contributor

Description

#984 — status --type with invalid type prints error but exits 0

status with an invalid --type/--state prints an error but returns exit code 0, so scripts and CI cannot detect the rejected filter.

Fix

Set a non-zero exit code on both validation branches. Merge PR #1603 (process.exitCode = 1 before return, adds command.test.ts) — cleaner than a hard process.exit(1) because it lets cli.ts's finally cleanup run. Close PR #1169 (duplicate, uses process.exit(1), diff is stale against pre-#1317 file and will conflict).

This fix was produced by an automated triage+fix run and validated locally (build + unit suite + symptom reproduction). It is being opened as a draft for CI and human review.

Related Issue

Closes #984

Documentation PR

N/A — bug fix; no devguide change required.

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 — N/A, no src/assets/ changes

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.

The status command's --type and --state validation branches rendered an
error then bare-returned without setting a non-zero exit code, so scripts
and CI under set -e could not detect a rejected filter (silent success on
failure). Set process.exitCode = 1 on both branches before returning,
which still lets cli.ts's finally cleanup run.

Adds command.test.ts asserting exit code 1 for invalid --type and
--state, and unset for a valid filter.

Fixes aws#984
@github-actions github-actions Bot added the size/s PR size: S label Jun 26, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 26, 2026
@aidandaly24 aidandaly24 changed the title fix(cli): set a non-zero exit code on both validation branches (#984) fix(status): exit non-zero on invalid --type/--state filter Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.21.0.tgz

How to install

gh release download pr-1650-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.21.0.tgz

@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 26, 2026

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. Small, focused fix.

  • Using process.exitCode = 1 instead of process.exit(1) is the right call here — it lets the finally block in src/cli/cli.ts run TelemetryClientAccessor.shutdown() so the validation-failure telemetry event actually gets flushed before the process exits.
  • The new tests cover both validation branches and assert the happy path doesn't accidentally set a non-zero exit code. The mocking is at reasonable boundaries (ink render, the action module, the telemetry wrapper) and matches the pattern already used in exec/__tests__/command.test.ts.
  • Telemetry is already instrumented on the validation branches via withCommandRunTelemetry with a ValidationError outcome, so nothing missing there.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 26, 2026
@github-actions github-actions Bot added size/s PR size: S and removed size/s PR size: S labels Jun 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 26, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 26, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 26, 2026

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed independently — looks good to merge.

Verified the key points already raised in the existing review:

  • process.exitCode = 1 is the right choice: main() in src/cli/cli.ts wraps program.parseAsync in a try/finally that calls TelemetryClientAccessor.shutdown(), so the ValidationError telemetry event recorded by withCommandRunTelemetry will flush before the process exits. A hard process.exit(1) here would skip that.
  • Both validation branches (invalid --type and invalid --state) get the fix and the new unit tests cover both, plus a happy-path assertion that exit code stays unset.
  • Mocks in the new command.test.ts are at sensible boundaries (ink, ./action, telemetry/cli-command-run, tui/guards) and mirror the pattern in exec/__tests__/command.test.ts.
  • Telemetry is already instrumented on these branches (no missing instrumentation).
  • The integ-test updates correctly tighten the assertion from exitCode === 0 to exitCode === 1 while leaving the failure-telemetry assertions intact.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 26, 2026
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

2 participants