Skip to content

feat(cli): reachable --dry-run previews for delegated commands #412

Closed

Description

@dan-petty

Context & Rationale

Paths are under src/devops_cli/ unless they start with tests/ or docs/. Evidence was checked at ef21785.

How dry-run reaches a command today

  • Every command group is registered lazily. main.py:179-180 passes each _COMMAND_SPECS entry (main.py:32-70) to OTelTyper.add_typer as a module:app string, and that branch registers a proxy command (core/cli.py:121-151).
  • Under dry-run, the proxy prints Would run delegated command: devops <group> <args> (lang/en/messages.py:509-511). It then returns before importing the module (core/cli.py:129-134).
  • Two forms take that path: devops --dry-run …, and an exported DEVOPS_CLI_DRY_RUN (main.py:216-218; tests/test_main_dry_run.py:12-28, :44-66).
  • The trailing form devops <group> <cmd> --dry-run behaves differently:
    • entry.py:36-37 turns dry-run on;
    • the root callback turns it off again, because this process set it (main.py:216-217, dry_run/state.py:28-35);
    • the proxy delegates, and the command parses --dry-run as its own option (tests/test_main_dry_run.py:31-41).
  • MCP tools use the trailing form (ai/mcp/server.py:521-522 and others).

What is reachable
I walked typer.main.get_command for every _COMMAND_SPECS module, leaving out the tui, format and lint aliases. That gives 418 leaf command paths and 361 distinct leaf callbacks.

  • 112 declare their own --dry-run.
    • The trailing form reaches them. The global form prints only the generic line.
    • So devops repos sync --dry-run previews, and devops --dry-run repos sync does not.
    • Four group callbacks also declare it: ci, scan, ai benchmark and dashboard (alias tui). With them, 116 callbacks and 123 command paths declare --dry-run.
  • 75 have a dry-run branch in their body but no --dry-run option. The branch is an is_dry_run() check, render_dry_run_result or @dry_run_command.
    • No form reaches them. The global form short-circuits, and the trailing form fails with No such option: --dry-run (exit 2). I confirmed this for k8s configure-urls, tf apply and release sync-notes.
    • They span 24 modules: tf has 12, argo 7, release 6 and ssh 5.
    • They include tf apply and tf destroy (apply's branch is at commands/tf.py:205-211), k8s deploy-stack, k8s teardown-stack, release tag, release sync-notes, docker push, docker prune, ssh rotate and vault login.
    • I ran all 75 under DEVOPS_CLI_DRY_RUN=1 with process creation replaced by a recorder, sockets blocked and HOME isolated. 52 rendered their preview. 23 needed arguments or a repository and did not finish. None started a process.
  • 174 have neither, so they have no preview to reach. This check reads only the command's own source, so a command that handles dry-run only inside helpers counts here.

Unreachable previews go stale

  • k8s configure-urls once previewed eight hardcoded minikube NodePort URLs. v0.2.22 rewrote that preview (cb75261, commands/k8s/networking.py:559-576).
  • Its branch (networking.py:870-876) is still unreachable from the CLI.

The short-circuit is load-bearing

  • Under dry-run, run_subprocess prints Would run command and then runs the command anyway (core/process.py:235-236, then :266; the async version is at :376-377, then :409). refactor(cli): one process runner owns execution, process groups and dry-run #775 tracks this.
  • Forwarding makes devops --dry-run <cmd> do whatever devops <cmd> --dry-run does. Some commands act under their own flag:
    • With subprocess.run recorded, devops ci lint --dry-run reaches uv … run ruff check . --fix (commands/ci.py:883-893, :172-185). 12 ci subcommands reached their tool the same way, and ci run reached the async runner. The split-off fix(ci): devops ci checks run for real under their own --dry-run #885 (devops ci checks run for real under their own --dry-run) fixes these.
    • review path <file> --dry-run writes a review session. _execute_review_workflow builds ReviewPipelineOrchestrator before any dry-run check (ai/review/runner.py:2142). Its constructor creates the session directory (ai/review/pipeline.py:1415-1420). The report step writes findings.json, candidates.json and review.md (pipeline.py:3600-3627). With DEVOPS_CLI_DATA_DIR isolated, one run wrote reviews/<id>/ with three "[DRY-RUN] Simulated" findings. runner.py:1268 skips the session directory only in the persona loop.
    • ai benchmark --dry-run saves <id>-benchmark.json with "is_dry_run": true (ai/benchmark/runner.py:566, :955-961).
  • The probes so far recorded process starts only, not file writes. They ran the declaring commands without arguments, so 40 of 120 paths did not finish, and they skipped dashboard, serve and tui.
  • devops --dry-run lint and devops --dry-run review path . are safe today only because of the short-circuit.
  • tests/test_main_dry_run.py:44-51 records what a dry-run that ran costs. A sync-notes --all meant as a preview republished every release description.

Where the forwarded flag lands matters

  • 26 call sites in 6 command modules run set_dry_run(dry_run) with the command's own option, for example commands/sandbox.py:138 and commands/review.py:289. If the forwarded --dry-run does not reach the option, they turn dry-run off.
  • Click treats everything after -- as an argument. For sandbox deploy (commands/sandbox.py:101-102), deploy -- sh -c true --dry-run parses as dry_run=False, with --dry-run inside the container command. deploy --dry-run -- sh -c true parses as dry_run=True.
  • So appending the flag at the end would make devops --dry-run sandbox deploy -- sh -c true deploy for real.

The proxy also never resolves the command

  • An unknown command passes under dry-run. devops --dry-run repos status exits 0 with the generic line, while devops repos status exits 2 with No such command 'status'.
  • tests/test_all_commands_help_dryrun.py:23, 25, 28-29 and tests/test_repos.py:1035-1037 assert exit 0 for repos status, argo list and argo status. None of these commands exists.
  • --help under the global flag prints the generic line instead of the help.

Scope & Deliverables

  • Deliverable:
    • One rule: a command previews only if it declares --dry-run.
    • Proxy routing under dry-run (core/cli.py:126-139). The proxy resolves the target command and parses its arguments without invoking it. Then:
      • if the command declares --dry-run and the parsed value is already true, the proxy delegates the arguments unchanged;
      • if it declares --dry-run and the parsed value is false, the proxy inserts --dry-run directly after the command path, before any other argument, so a -- separator cannot swallow it. The global flag stays on;
      • if it does not declare it, the proxy prints the generic line, as today;
      • if the command does not resolve or its arguments do not parse, the proxy shows that usage error and exits with its code. It never delegates a command it could not resolve and parse;
      • -h/--help goes to _delegate's help fast path (main.py:90-97);
      • the format and lint aliases resolve to ci format and ci lint (main.py:86).
    • Each of the 75 branch-only commands declares dry_run: Annotated[bool, typer.Option("--dry-run", help=HELP.options.dry_run)] = False. This is the existing convention, for example commands/kustomize.py:56.
      • Its branch tests dry_run or is_dry_run(). It never calls set_dry_run(dry_run).
      • @dry_run_command already reads a dry_run argument (dry_run/decorator.py:43-44), so commands that use it only gain the option.
      • Before adding the option, the builder checks that the branch returns before any write, mutating subprocess or mutating API call.
    • An invariant test. It reuses the import walk in tests/test_all_commands_help_dryrun.py:84-104 and asserts two things:
      • every command reachable from _COMMAND_SPECS whose callback references is_dry_run, render_dry_run_result or dry_run_command declares --dry-run;
      • every callback that declares --dry-run reads its dry_run parameter, or is wrapped by @dry_run_command. All 116 declaring callbacks do at ef21785.
    • A one-off recorder sweep, outside the gate. Run every command that declares --dry-run after this change once, with valid arguments, process creation recorded, sockets blocked, and HOME and DEVOPS_CLI_DATA_DIR in a temp directory. Record the processes started and the files written in the task file.
    • Update every test that relied on the short-circuit:
      • tests/test_main_dry_run.py;
      • tests/test_all_commands_help_dryrun.py:21-31 and :57-58;
      • tests/test_repos.py:1001-1004, :1014-1018 and :1035-1037;
      • tests/test_rag_cli.py:20-33;
      • tests/test_grafana.py:36-40;
      • tests/test_ai_subcommands_rag.py:37-43, tests/test_argo.py:206 and tests/test_prometheus.py:107;
      • any other test that invokes main.app with a leading --dry-run.
    • Docs and records:
      • HELP.main.dry_run (lang/en/help.py:12-15) states the rule;
      • docs compact (commands/docs.py:279-280, option help at :337) stops reusing that string and uses HELP.options.dry_run;
      • docs/SDLC.md:145 states the rule instead of requiring @dry_run_command;
      • regenerate docs/CLI_REFERENCE.md and docs/commands/;
      • add a CHANGELOG entry;
      • rewrite the task file docs/agent/tasks/task-412-reachable-dry-run-previews-for-delegated-commands.md, which still says v0.2.24 and Backlog.
  • Acceptance criteria:
    • devops --dry-run k8s configure-urls and devops k8s configure-urls --dry-run both print the JSON preview with "command": "devops k8s configure-urls" and "action": "configure_monitoring_urls", and exit 0. Verified by a test that runs the real _delegate with save_settings and process creation patched to fail.
    • tf apply <tmp dir>, tf destroy <tmp dir>, k8s teardown-stack and docker prune exit 0, render their preview and start no process, in both the global form and the trailing form. Verified the same way, with the tf binary lookup and the Docker engine (commands/docker.py:196) also patched to fail.
    • For repos sync, branches clean and the lint alias, devops --dry-run <cmd> passes _delegate the same arguments as devops <cmd> --dry-run. devops --dry-run repos sync --dry-run passes --dry-run once. Verified with _delegate patched, in tests/test_main_dry_run.py.
    • devops --dry-run sandbox deploy -- sh -c true passes _delegate ["deploy", "--dry-run", "--", "sh", "-c", "true"]. devops --dry-run sandbox deploy -- tool --dry-run also gets --dry-run before --. Verified with _delegate patched. Both tests fail if the flag is appended at the end or if its presence is checked by searching the argument list.
    • DEVOPS_CLI_DRY_RUN=1 devops repos sync delegates the same way as devops --dry-run repos sync. This test replaces the called == False assertion at tests/test_main_dry_run.py:66.
    • devops --dry-run config set ai.provider ollama prints Would run delegated command: devops config set ai.provider ollama and exits 0, and _delegate is not called. Verified by a test.
    • devops --dry-run repos status exits 2 with No such command 'status', and devops --dry-run repos --unknown-option exits 2. Verified by tests. The cases for the non-existent commands repos status, argo list and argo status are replaced by commands that exist.
    • devops --dry-run k8s --help prints the k8s help and exits 0. Verified by a test.
    • The invariant test fails on ef21785, listing 75 callbacks, and passes after the change. A fixture callback that declares --dry-run and never reads it also fails the test.
    • The task file has one row for each command that gained --dry-run. Each row says what runs before the command's branch and gives the verdict.
    • The task file records the sweep. It shows no command that starts a mutating process, or writes outside its temp directories, under its own --dry-run. The reviewer checks this in the PR.
    • The new and changed tests add at most 1 s to the test step. Measure with pytest --durations=0 on the touched test files, before and after, and record both figures in the task file.
    • uv run devops docs check and uv run devops ci pass.
  • Key questions:
    • Should every command be classified first, and the switch flipped last, as the first draft planned? No (proposed). Route per command, and default to the generic line. Then a command the audit misses keeps printing a harmless line instead of running. Classifying the commands that have no preview is the split-off.
    • Should a marker decorator or a declared --dry-run option say that a command previews? The option (proposed). 112 commands already follow that convention. It shows in --help and in docs/CLI_REFERENCE.md, MCP can pass it, and the trailing form works too. With a marker, devops tf apply --dry-run would still fail with No such option.
    • Should the proxy clear the global flag when it forwards, so the result matches the trailing form exactly? No (proposed). If the flag stays on, helper-level guards such as k8s/logs.py:28 also apply. It does not protect a command that runs set_dry_run(dry_run), which is why the next answer matters.
    • Where does the forwarded flag go? Directly after the command path, and only when the parsed value is false (proposed). Appended at the end, it lands after a -- separator and sandbox deploy runs for real. Reading the parsed value, not searching the argument list, also stops a --dry-run inside a passed-through command from counting as the command's own.
    • How does the proxy find the command? With fix(mcp): mcp tools and resources call commands and options that exist #836's resolver, not a second copy (proposed). That resolver walks resolve_command from _COMMAND_SPECS and calls make_context on the leaf, never invoke. If fix(mcp): mcp tools and resources call commands and options that exist #836 puts it under src/devops_cli/docs/, this item moves it to core/, because the CLI entry path now calls it.
    • Group callbacks run before a forwarded command. Are they safe? Yes, at ef21785 (proposed):
      • ai, ai review/review, ai analyze and ai rag only handle --explain (commands/ai.py:144-161, review.py:134-148, analyze.py:311-325, rag.py:38-55);
      • ci, scan, ai cost (alias ai spend) and ai benchmark return when a subcommand is invoked (ci.py:704, scan.py:125, ai_cost.py:322, benchmark.py:353). Before it returns, ci resolves and prints the worktree root (ci.py:701-703), which only reads files;
      • groups used as commands: install-tools and serve declare no --dry-run, so they keep the generic line. dashboard/tui and ai benchmark declare it, so they are forwarded. dashboard --dry-run renders the static summary (commands/dashboard.py:197-198). ai benchmark --dry-run writes a report, which a dependency fixes.
    • Some of the 75 are read-only, such as ssh list, whose preview only echoes its arguments (commands/ssh.py:342-348). Add the option, or delete the branch? Add the option (proposed). One rule for all 75 keeps the review mechanical. Whether read-only commands should simply run under dry-run is the split-off's question.
    • What if a branch turns out to act before it returns? If the fix is local to the command, fix the order in this PR. Otherwise, leave that command without the option, list it in the task file and add it to the split-off (proposed).
    • Does the feat(review): per-model review quality baseline for the devops-review pool #475 extension's ordering (docs/ROADMAP.md:314, "PR 3, before Reachable --dry-run Previews") still apply? Yes (proposed). A dry-run review still writes a session directory and findings.json through the orchestrator path (ai/review/runner.py:2142, pipeline.py:1415-1420, :3600-3627). Forwarding would make devops --dry-run review path . write them. The feat(review): per-model review quality baseline for the devops-review pool #475 refinement splits this off as "a dry-run review writes no session", and this item depends on it.
  • Constraint:
    • devops --dry-run <cmd> starts no mutating process, writes no file outside a temp directory and makes no mutating API call. Today the short-circuit guarantees this. After this item, each forwarded command's own --dry-run must.
    • devops --dry-run <cmd> is never less careful than devops <cmd> --dry-run.
    • The dependencies below land first.
    • Typer 0.27.2 vendors Click (typer._click). Its exceptions do not subclass the click.ClickException that main.py:144 catches. The proxy's usage-error path catches the vendored classes.
    • Tests start no process and touch no network, cluster or real scanner. The preview tests patch process creation, settings writes and the Docker engine to fail.
    • No new dependency, and no compatibility shim for the old generic-line behaviour.
    • Cyclomatic complexity is 10 or less and nesting depth 5 or less. Tests use structural tuple assertions until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that.

Strategic Alignment

Amended 2026-10-04: a dry run makes no external request (owner's definition)

The owner (2026-10-04): a "dry run should just return the command or request that would be run and a dry run response that is the exact same type as the real return object, not run a thousand api requests as read only".

Measured the same day: devops roadmap reprioritize --dry-run read all 931 board items and spent 2,025 GraphQL points. That is the same read as a real run; only the writes were skipped.

  • No external requests. With --dry-run, no command makes any external request (GitHub, Kubernetes, the AI gateway, Docker, Vault or HTTP), reads included. A test runs every command that has --dry-run with the network, gh, kubectl and other subprocess runners replaced by fakes that fail on use, and asserts that none was called.
  • The plan of requests. A dry run returns the exact commands or requests the real run would make, in order, each with method, target and redacted parameters. Values that need a read to know are shown as named placeholders (for example <items of board 2 matching is:open>), never fetched.
  • The same return type. A dry run returns an object of the same type as the real run, marked as a dry run (for example dry_run: true plus the request plan), so CLI rendering, --json output, MCP tools and tests handle both paths with one code path. Its typed fields hold empty or placeholder values, never fabricated data.
  • Commands that must read to decide (reprioritize, intake, migrate) still make no request in a dry run. A separate, explicitly named mode (for example --plan) may read, and reports its request cost, so a read-only preview is a deliberate choice.

Update 2026-10-08: refinement

#836 and #885 (PR #1199) landed; #872 is open. ai benchmark --dry-run still saves its report (ai/benchmark/runner.py:604-607), so that folds here: a dry run saves no report. The resolver (docs/command_resolver.py:139-159) moves to core/. Lines: proxy core/cli.py:139-144, root callback main.py:242-250, entry.py:46-50. The no-request test takes its arguments from #986's table.

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/cli
    priority/p1-high
    on Sep 22, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to make room for the seven P1 items left open in the shipped v0.2.23, which were committed earlier. The roadmap-job items placed in v0.2.25 stay, and this item is among the oldest of the rest.

  4. removed this from the v0.2.26 milestone on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.26 to the backlog to keep v0.2.26 at 12 after #832 joined. Its two dependencies, #885 (devops ci checks run for real under their own --dry-run) and #872 (a dry-run review writes no session), are in the backlog, so it couldn't start in v0.2.26 anyway. It heads the P1 backlog, after those two.

  6. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Another case for this item, from #1360 (2026-10-08): devops roadmap run --dry-run, and run without --confirm, read the changes and releases, now including the pull request and GitHub Release listings #1360 adds to the poll, although the help says they make no request. A dry run should return the would-be requests with the same-typed result and make none. Folded here instead of a new issue because the agent filing quota (#1153) is spent.

  7. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #886 and #775 apply this item's 2026-10-04 dry-run rule (#886 declares which commands make requests; #775's runner refuses them), and #794 and #809 had --dry-run criteria amended to make no request. Found by the 2026-10-08 backlog review.

  8. added this to the v0.2.33 milestone on Oct 9, 2026
  9. dan-petty commented on Oct 9, 2026

    @dan-petty
    OwnerAuthor

    Note from #1515 (2026-10-09): devops roadmap run --dry-run has promised since v0.2.26 to name why each job is due, but nothing returns a reason today (_Poll.is_due returns a bool). Since this item reshapes the dry-run output, the reason line belongs here if it fits: a DueReason per job printed under the unchanged Due: line, so parse_due_tuple and the MCP tool keep working. #1515 proves its own interval through the due tuple only.

  10. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1530, merged into release/v0.2.33 as 1f91d98.

    Summary

    • Implemented reachable --dry-run previews for delegated commands across command groups.
    • Lazy proxy command routing resolves leaf commands and inspects arguments.
    • If a command declares --dry-run and parsed dry_run is false, the proxy forwards arguments with --dry-run inserted directly after the command path before any -- separator or positional arguments.
    • If a command does not declare --dry-run, the generic preview line is retained without delegating.
    • Unknown commands and option syntax errors are caught and surfaced with usage error exit codes.
    • Added --dry-run option across 24 command modules (55 functions), ensuring previews are reachable without process execution or state mutation.
    • Updated BenchmarkRunner to avoid writing benchmark reports under dry-run.
    • Added structural invariant tests ensuring all callbacks declaring --dry-run read their parameter, and callbacks referencing dry-run branches declare --dry-run.
    • Synchronized and verified all documentation via devops docs generate --sync-readme and devops docs check.

    Closes #412

    64 file(s) changed.

    How it was verified

    Check runs at 29635b0:

    • Prune PR DevContainer Images: pass
    • bandit: pass
    • devops-cli: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Changed-Test Independence: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-412-reachable-dry-run-previews-for-delegated-commands.md:

    No Acceptance Criteria section.

  11. added a commit that references this issue on Oct 10, 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

    priority/p1-highscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions