Files
temp/features/tdd_cli_incomplete_subcommand_registration.feature
freemo 6e09842731 fix(cli): raise on subcommand registration failure instead of partial silent return
- What was implemented
  - Fixed _register_subcommands in src/cleveragents/cli/main.py: replaced bare return with raise SystemExit(1) from exc in the exception handler to propagate a non-zero exit code and preserve the original traceback context.
  - Removed # pragma: no cover from the exception handler, enabling test coverage for this path.

- Why this change
  - Ensures the CLI exits with a non-zero status on subcommand registration failure and provides proper error context for debugging, aligning with the project's error-handling goals and B904 linting requirements.

- Tests and verification
  - Added Behave BDD issue-capture test features/tdd_cli_incomplete_subcommand_registration.feature with 3 scenarios to exercise and validate the failure path.
  - Added step definitions features/steps/tdd_cli_incomplete_subcommand_registration_steps.py corresponding to the new scenarios.
  - The @tdd_expected_fail scenario captures the previous buggy behavior (silent return with exit code 0) to ensure regression is addressed.
  - All nox quality gates pass (lint, typecheck).

- Key design decisions
  - Use raise SystemExit(1) from exc to exit with a clear non-zero status while preserving the original exception chain (satisfies B904).
  - Coverage ensured by removing the pragma, bringing the error path under test.
  - Behavior now explicitly signals failure to the shell and any orchestrating tooling, avoiding silent failures.

- Affected modules and artifacts
  - src/cleveragents/cli/main.py
  - features/tdd_cli_incomplete_subcommand_registration.feature
  - features/steps/tdd_cli_incomplete_subcommand_registration_steps.py

ISSUES CLOSED: #2604
2026-04-05 08:27:05 +00:00

33 lines
1.6 KiB
Gherkin

@tdd_issue @tdd_issue_2604
Feature: TDD Issue #2604 — Incomplete subcommand registration on error
As a CLI user
I want the CLI to fail loudly when subcommand registration encounters an error
So that the CLI is never left in a partially initialized state
This test captures bug #2604. The _register_subcommands() function in
src/cleveragents/cli/main.py catches all exceptions during subcommand
import and registration, prints a traceback, then silently returns.
This violates CONTRIBUTING.md error-handling standards: "Errors must
never be suppressed. Exceptions should propagate to the top-level
execution handler."
The fix replaces the bare `return` with `raise SystemExit(1)` so the
CLI exits with a non-zero exit code instead of entering a partially
initialized state.
Scenario: Bug #2604 — subcommand registration failure exits with non-zero code
Given the CLI subcommand import raises an ImportError during registration
When the CLI is invoked with any command
Then the CLI exits with a non-zero exit code
Scenario: Bug #2604 — subcommand registration failure prints error message
Given the CLI subcommand import raises an ImportError during registration
When the CLI is invoked with any command
Then the error output contains "Failed to register subcommands"
@tdd_expected_fail
Scenario: Bug #2604 — old behaviour silently returns on registration error
Given the CLI subcommand import raises an ImportError during registration
When the CLI is invoked with any command
Then the CLI exits with exit code 0