Skip to content

feat(cli): each command declares its dry-run class, and a ratchet test stops a new command without one #2230

Description

@dan-petty

Part of #886. This is the first sub-issue. Each later sub-issue removes its commands from the gap list that this one adds.

Problem or Motivation

The owner's dry-run rule (#412, 2026-10-04) says that a dry run makes no external request. An external request is a request to GitHub, a cluster, a model or the network, or a child process that does one of these. A dry run returns the requests that the real run would make, as devops_cli.dry_run.requests.PlannedRequest items, and a result of the same type as the real result. A command that makes no external request can run normally under a dry run.

No code records which commands obey this rule. Thus, nothing stops a new command that breaks it. The inventory for #886 (2026-10-25, commit 1bb164b) found these counts:

  • The walk from main._COMMAND_SPECS finds 456 command paths: 441 leaf commands and 15 group callbacks that run with no subcommand. It does not count the alias trees tui, format and lint. 49 of these paths are second names for the same callback (gh pr *, ai review *, ai spend *, gh rate_limit). Thus there are 407 distinct commands.
  • 234 of the 456 paths declare no --dry-run.
  • 33 paths (31 distinct) have a request-plan dry run today: all ci commands except ci fail-to-pass, roadmap intake, roadmap refine, roadmap return, pr update (and gh pr update), gh project reconcile, k8s push-secrets, k8s run-job, k8s deploy-stack, k8s doctor, k8s volume reclaim, k8s volume move and review rules fetch (and ai review rules fetch).
  • 256 distinct commands make an external request (or possibly make one) and have no request plan.
  • 12 distinct commands change local state, make no external request and have no --dry-run.
  • 108 distinct commands make no external request and need only a mark.

The present guard, tests/test_main_dry_run.py::test_invariants_all_dry_run_commands_consistent, checks only that a command that declares --dry-run has the text dry_run in its source. The parameter name alone satisfies that check. It does not check that a dry run makes no request.

Proposed Solution & Architectural Design

  1. Add one declaration in src/devops_cli/dry_run/decorator.py: a decorator that sets a dry-run class on a command callback. The class has two values:
    • request-plan: the command declares --dry-run. Its dry run makes no external request and returns a result of the real result type, marked as a dry run, that holds the ordered PlannedRequest items.
    • no-external-request: the command makes no external request. devops --dry-run <command> runs it normally. If the command changes local state, it also declares --dry-run, and that preview writes nothing.
      functools.wraps copies the attribute to the wrappers of OTelTyper.command and @dry_run_command, so the test reads it from the Click callback.
  2. Make the lazy proxy (core/cli.py:_handle_lazy_proxy_dry_run and core/command_resolver.py:resolve_proxy_dry_run) run a no-external-request command without --dry-run. A command with no class keeps the generic Would run delegated command line, as today.
  3. Add tests/test_dry_run_class_ratchet.py and the committed list tests/fixtures/dry_run_gaps.json. The test walks every command path that _COMMAND_SPECS reaches, as tests/test_main_dry_run.py and tests/test_cli_format_adoption.py do now. It fails when:
    • a path has no dry-run class and is not in the list. The message names the two classes and the list.
    • a path has a class and is still in the list. The message tells the author to remove the entry, so that the list can only become shorter (the same pattern as tests/test_swallowed_failures_ratchet.py).
    • a path in the list is no longer a command.
    • a request-plan command does not declare --dry-run.
  4. Give the request-plan class to the 31 distinct commands above that already have a request plan. Put all other paths in the list: 423 paths in the inventory, which includes the alias paths. The alias trees tui, format and lint add 3 more paths (tui, format fail-to-pass, lint fail-to-pass) if the test walks them. A class on a callback clears all of its paths.
  5. Add the one-direction MCP check that feat(cli): commands with no dry-run preview: read-only ones run, mutators gain one #886 asks for: an MCP tool in CONST_MCP_EXPOSURE_TABLE that wraps a no-external-request command has readOnlyHint: true.
  6. Replace the weak substring check in test_invariants_all_dry_run_commands_consistent with the new test, or remove it. Do not keep two tests for one rule.

The inventory data and the scripts that made it are not part of the pull request. The list in the fixture is the record.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

  • Click and Typer have no metadata for "this command makes external requests". A Click Command takes custom attributes, but a decorator on the callback is simpler and the proxy already reads the callback.
  • The repository's ratchet pattern (tests/test_swallowed_failures_ratchet.py with tests/fixtures/swallowed_failures_ceilings.json) covers the "list that can only shrink" need. This issue reuses it and adds no new tool.
  • Tests of the later sub-issues use the guards that exist: the socket guard in tests/conftest.py, core.process.set_process_runner, and the pattern of tests/test_roadmap_dry_runs.py. No new test dependency is necessary.

Acceptance Criteria

  • A command with no dry-run class that is not in tests/fixtures/dry_run_gaps.json fails the ratchet test. Verified by a test with a fixture Typer app.
  • A command with a class that is still in the list fails the test, and the message tells the author to remove the entry.
  • An entry in the list that names no command fails the test.
  • A request-plan command without --dry-run fails the test.
  • devops --dry-run <command> runs a no-external-request command normally, and still prints the generic line for a command with no class. Verified by tests with a fixture command.
  • The 31 distinct commands that have a request plan today carry the request-plan class, and are not in the list.
  • An MCP tool that wraps a no-external-request command has readOnlyHint: true. Verified by a test.
  • The new tests start no process and open no socket. They add at most 1 s to the test step (the limit that feat(cli): commands with no dry-run preview: read-only ones run, mutators gain one #886 sets). The pull request records the time.
  • uv run devops ci passes.

Source: #886

Proposed design

Problem statement

No code records which CLI commands obey the dry-run rule that a dry run makes no external request. A new command that breaks this rule is not stopped by any guard. The existing test checks only that the text 'dry_run' appears in a command's source, which the parameter name alone satisfies. This issue adds a per-command dry-run class declaration, a ratchet test that fails on any new command without a class, and a fixture list that can only shrink as later sub-issues add classes to the remaining commands.

Acceptance criteria

  • Criterion 1: A command path with no dry-run class that is not in tests/fixtures/dry_run_gaps.json fails the ratchet test.
    Verification: Run the ratchet test with a fixture Typer app that has a command lacking the class and not in the list. The test fails with a message naming the two classes and the list.
  • Criterion 2: A command path that has a dry-run class and is still in the gap list fails the test.
    Verification: Run the ratchet test with a command that carries the class and an entry in the list. The test fails with a message telling the author to remove the entry.
  • Criterion 3: An entry in the gap list that names a path that is no longer a command fails the test.
    Verification: Run the ratchet test with a list entry that does not match any reachable command path. The test fails.
  • Criterion 4: A command with the request-plan class that does not declare --dry-run fails the test.
    Verification: Run the ratchet test with a command carrying the request-plan class but no --dry-run parameter. The test fails.
  • Criterion 5: devops --dry-run runs a no-external-request command normally and still prints the generic 'Would run delegated command' line for a command with no class.
    Verification: Invoke the CLI with --dry-run and a no-external-request command. The command executes. Invoke with a command that has no class. The generic line prints and the command does not execute.
  • Criterion 6: The 31 distinct commands that have a request plan today carry the request-plan class and are not in the gap list.
    Verification: Run the ratchet test. It passes. Inspect the fixture file. The 31 command paths are absent.
  • Criterion 7: An MCP tool in CONST_MCP_EXPOSURE_TABLE that wraps a no-external-request command has readOnlyHint set to true.
    Verification: Run the MCP check test. It passes. A tool wrapping a no-external-request command without readOnlyHint: true fails.
  • Criterion 8: The new tests start no process and open no socket, and add at most 1 second to the test step.
    Verification: Run the new tests under the conftest guards. They pass. Record the test step time in the pull request description.
  • Criterion 9: uv run devops ci passes with the new code and tests.
    Verification: Run uv run devops ci. All checks pass.

Key questions

  • What attribute name does the decorator set on the command callback?: The body does not fix a name. The implementation chooses one (for example _dry_run_class) and sets it on the callback function. functools.wraps copies it to the wrappers of OTelTyper.command and @dry_run_command so the test reads it from the Click callback. (proposed) [sources: src/devops_cli/dry_run/decorator.py]
  • What is the format of tests/fixtures/dry_run_gaps.json?: A JSON list of command path strings (for example ["ai ast graph", "repos sync"]). The body says 'Put all other paths in the list: 423 paths'. The ratchet test walks every reachable path and checks membership in this list. (proposed) [sources: tests/fixtures/swallowed_failures_ceilings.json]
  • Does the implementation replace or remove test_invariants_all_dry_run_commands_consistent?: The body says 'Replace the weak substring check ... with the new test, or remove it. Do not keep two tests for one rule.' The implementation must do one of the two and not keep both. (proposed) [sources: tests/test_main_dry_run.py]
  • Where is CONST_MCP_EXPOSURE_TABLE defined?: The body references it by name but the context does not show its file. The MCP check reads this table and asserts readOnlyHint: true for tools that wrap a no-external-request command. The implementation locates it in the repository. [sources: src/devops_cli/ai/mcp/server.py]
  • How does the ratchet test walk command paths?: It walks every command path that _COMMAND_SPECS reaches, the same way tests/test_main_dry_run.py and tests/test_cli_format_adoption.py do now. It imports each module, gets the Typer app, converts to a Click command, and recurses through groups to leaf commands. [sources: tests/test_main_dry_run.py, tests/test_cli_format_adoption.py]
  • What guards ensure the new tests start no process and open no socket?: The session-scoped fixtures prevent_external_network_calls and refuse_real_programs in tests/conftest.py block all socket connects and subprocess starts. The new tests must not use @pytest.mark.live and must not start any binary. [sources: tests/conftest.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    on Oct 25, 2026
  2. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/feature. The candidate proposes a new feature to declare dry-run classes for commands.
    • Priority: P1-High. This change enforces the dry-run rule and prevents breaking changes to external requests.
    • Value: High. It improves the correctness of dry-run behavior across many commands in the CLI.
    • Effort: Medium. It requires adding new decorators, updating tests, and modifying command resolution logic.
    • Related: chore(cli): every argument-taking --dry-run command path is recorded as read-only or mutating, one candidate per offender #986, which asks for a different change. Both items relate to dry-run command handling but the candidate introduces a new class declaration while #986 concerns argument-taking commands' recording.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 520e8b8 (see proposed design in issue body).

  4. added
    priority/p1-high
    status/ready
    effort/medium
    value/high
    scope/cli
    on Oct 28, 2026
  5. removed
    status/ready
    on Oct 31, 2026
  6. added a commit that references this issue on Oct 31, 2026
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

    effort/mediumpriority/p1-highscope/clisource/agenttype/featurevalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions