Skip to content

fix(cli): devops --dry-run on a command group given only its own options previews it instead of crashing with IndexError #1549

Closed

Description

@dan-petty

Requested by the owner, 2026-10-10 ("file the issues"). The defect turned up while the v0.2.33 changelog was consolidated (#1547). #412 (#1530) introduced it.

Problem

Checked at main (69c99cf, v0.2.33).

  • devops --dry-run ci --check and devops --dry-run install-tools --tool kubectl exit 1 with IndexError: list index out of range and a traceback. At v0.2.32 (b5ea6ff), both printed Would run delegated command: devops … and exited 0.
  • _descend_subcommand (src/devops_cli/core/command_resolver.py:271-275) passes its tokens list to make_context. The parser behind it (Click 8.5.0) removes each option it parses from that same list. After the group has parsed its own options, tokens holds only what is left, which is [] for ci --check. resolve_command(ctx, []) then fails at typer's args[0] (typer/core.py:1155).
  • The same mutation shortens the list that consumed is computed from.
    • With a group option before a subcommand, the forwarded --dry-run lands before the subcommand. resolve_proxy_dry_run("devops_cli.commands.ci", "ci", ["--check", "lint"]) returns ["--check", "--dry-run", "lint"]. feat(cli): reachable --dry-run previews for delegated commands #412 places it after the command path, as ["--check", "lint", "--dry-run"].
    • ci reads its own --dry-run, so its preview still comes out right. A group that declares no --dry-run would not.
  • tests/test_main_dry_run.py has no case that gives a group one of its own options.

Proposed remedy

  • _descend_subcommand parses a copy of tokens and descends with the arguments the parse left. When none are left, the group itself is the leaf:
    • devops --dry-run ci --check runs ci --check --dry-run, because ci declares --dry-run.
    • devops --dry-run install-tools --tool kubectl prints the generic line, because install-tools declares none.
  • consumed counts the group's own options, so the forwarded --dry-run follows the whole command path.

Acceptance criteria

  • devops --dry-run ci --check exits 0 with ci's own preview.
  • devops --dry-run install-tools --tool kubectl exits 0 with Would run delegated command: devops install-tools --tool kubectl (tests/test_main_dry_run.py).
  • When a group option comes before a subcommand, the forwarded --dry-run follows the subcommand: ["--check", "lint", "--dry-run"].

Feasibility

Reproduced at 69c99cf with the CLI, and by calling resolve_proxy_dry_run directly. The parse that empties the list was shown by comparing tokens before and after make_context. The fix fits one pull request: one function in src/devops_cli/core/command_resolver.py and its tests.

Activity

  1. added
    type/bug
    on Oct 10, 2026
  2. dan-petty-bot commented on Oct 10, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/bug. A crash (IndexError) that regressed from v0.2.32 to v0.2.33 when a command group is given its own options under --dry-run.
    • Priority: P2-Medium. It is a regression that breaks a previously working command with a traceback, but it affects a specific usage pattern rather than all dry-run invocations.
    • Value: Medium. Users who combine a group-level option with --dry-run hit an unhandled crash instead of a preview, undermining trust in the dry-run feature.
    • Effort: Low. The candidate states the fix is one function in command_resolver.py plus its tests, fitting a single pull request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions