Skip to content

chore(cli): every argument-taking --dry-run command path is recorded as read-only or mutating, one candidate per offender #986

Closed

Description

@dan-petty

Problem Statement

Split off #885 on 2026-10-02 by owner decision Q3: #885 keeps the two dry-run guards in the ci.py runners and the guard around the coverage cleanup, and its task file records the 80-path recorder result already measured and names this candidate. The survey of the remaining 40 argument-taking paths changes no code in #885, cannot be verified by that pull request's checks (docs/agent/tasks/README.md:11, rule 3: verification is the PR's passing checks), and its only output is zero or more candidates for other command modules. So it is its own candidate for intake (backlog, no milestone), not a step of #885.

Paths are under src/devops_cli/; evidence checked at 9c879ae (tip of release/v0.2.25). lang/en/help.py and config/constants.py changed since #885's 8271385, but the lines cited below hold.

  • A command's own --dry-run only calls set_dry_run(True) (dry_run/state.py:18-25), which sets DEVOPS_CLI_DRY_RUN; nothing below the command refuses to run. The core runners print Would run command and then start the process anyway (core/process.py:235-236 then subprocess.run at :266; :376-377 then asyncio.create_subprocess_exec at :409). Whether a command is safe under its own --dry-run therefore depends on each command checking is_dry_run() (dry_run/state.py:38-41) itself.
  • fix(ci): devops ci checks run for real under their own --dry-run #885 found that 14 devops ci commands do not, and fixes them. For the other commands, the issue's recorder run (with subprocess.run replaced, as tests/test_ci.py:28-36 does) covered 120 command paths: 80 that run without arguments finished, and apart from ci the only processes started were read-only (git worktree list, git rev-parse, gh api rate_limit, kubectl apply -k . --dry-run=client). The 40 paths that need arguments were not run, so nobody knows whether devops <group> <cmd> <args> --dry-run runs for real in any of them.
  • At 9c879ae, at least 96 command functions across 30 modules under commands/ declare --dry-run (an AST count of decorated typer commands whose signature contains the literal "--dry-run"): 15 in ci.py and 81 elsewhere (scan.py 10, ai.py 8, docker.py 6, sandbox.py 6, devcontainer.py 5, gh.py 5, and 24 modules with 1-4 each). That count misses commands registered after definition with app.command()(func) (commands/k8s/__init__.py:98-120; for example k8s lint, commands/k8s/security_audit.py:99-106), so it is a floor. The issue's 120-path count also includes root aliases (devops lint and devops format are ci subcommands, main.py:70-71, config/constants.py:183) and group callbacks; the survey re-derives the list from the Click tree rather than from any AST count.
  • The option's help promises "Preview execution plan without mutating external state." (lang/en/help.py:25). Every command that declares it makes that promise.
  • tests/test_all_commands_help_dryrun.py:22-73 runs --dry-run on 14 entries (12 distinct paths) and asserts only exit 0 (:86). Ten of those paths use the global devops --dry-run <cmd> form, which never reaches the command: the lazy proxy prints a delegated line and stops (core/cli.py:128-135). Only two (repos sync, branches clean) pass the command's own flag, both argument-free. The test records no process and covers none of the 40 argument-taking paths.

Proposed Solution

The method, reusing what #885 established:

  1. Enumerate every command path that declares --dry-run from the Click tree (typer.main.get_command(app) over _COMMAND_SPECS, main.py:33), including the format and lint root aliases, and split it into argument-free paths (already recorded in fix(ci): devops ci checks run for real under their own --dry-run #885's task file) and argument-taking paths (the 40).
  2. For each argument-taking path, invoke it once through CliRunner with its own --dry-run and syntactically valid placeholder arguments (a tmp_path file or directory, a name such as example, a loopback URL), with subprocess.run replaced by a recorder returning rc 0 (tests/test_ci.py:31-35). The recorder also catches the async runner, which falls back to the sync runner in a thread whenever subprocess.run is patched (core/process.py:361-362). No live cluster, tunnel or repository is needed: every process is intercepted, as it was for the 80 paths. The survey runs under the session network guard (tests/conftest.py:98-112): a connect to a non-loopback host raises RuntimeError, and a loopback port this process does not listen on is refused, so a path that reaches the network fails loudly rather than silently.
  3. Record per path: exit code, every argv recorded, and whether each argv is read-only (the _QUIET_SUBPROCESS_ARGS set, core/process.py:23-25, is the existing list of such git subcommands) or mutating.
  4. For each command outside commands/ci.py whose recorder shows a mutating process, or whose code path writes files or calls a remote API under --dry-run, file one candidate. A path that only starts read-only processes is recorded, not filed.

What a resulting item looks like (the shape #885 has): title fix(<scope>): \devops ` runs for real under its own --dry-run; a problem statement citing the command's --dry-rundeclaration and the runner call it reaches; the fix placed in that command's runner or helper, printing the command withprint_dry_run_command (output/console.py:728) and returning a pass; a test that records subprocess.run, asserts zero calls and the Would run commandlines, and fails before the fix; the no-flag control; One command per item; a module with several offenders may group them when they share one runner function, asci.py` does.

Scope

  • The survey record: the list of argument-taking --dry-run paths, the placeholder arguments used, and the recorder result per path, kept in this item's task file (docs/agent/tasks/task-<issue>-dry-run-survey.md).
  • Zero or more filed candidates, one per offending command outside commands/ci.py, each named in the task file.
  • No change under src/ or tests/. The enumeration and recorder snippet is reproduced in the task file so the survey can be re-run; it is not committed as a script (AGENTS.md:97-102: scratch scripts live only in the gitignored scratch directory and are deleted before the session ends).

Key Questions

This item is born from decisions already taken; nothing is open.

  • Does the survey stay in fix(ci): devops ci checks run for real under their own --dry-run #885? No (owner decision Q3, decisions.json item 885: "Move it out as its own candidate; this PR's task file keeps the recorded 80-path result and names the candidate filed").
  • Does the survey need live arguments (a cluster, a tunnel, a repository)? No. The recorder intercepts every process and returns rc 0, so placeholder arguments that pass each command's own validation are enough; that is how the 80 argument-free paths ran. A command that validates its argument before any process (an existing path, a reachable host) gets a tmp_path or loopback placeholder; the network guard refuses the loopback connect, which is itself a recorded result.
  • Does an offender get fixed in this item? No. This item changes no code. Each offender becomes its own candidate with the shape above, and intake places it. This keeps the item a survey that one task file delivers.
  • Is a read-only process under dry-run a finding? No. Many callers rely on read-only processes under dry-run (git rev-parse in review branch; _QUIET_SUBPROCESS_ARGS, core/process.py:23-25). The runner-level decision is refactor(cli): one process runner owns execution, process groups and dry-run #775. Only a mutating process, a file write or a remote write is a finding.
  • Should the survey become a permanent test? Not here. tests/test_all_commands_help_dryrun.py already asserts exit 0 for a hand-kept list; turning it into a tree-walking recorder test with per-path placeholder arguments is a follow-up the survey can propose once it knows how many paths need bespoke arguments.

Acceptance Criteria

  • The task file lists every argument-taking command path that declares --dry-run at the surveyed commit, derived from the Click tree, one table row per path with the placeholder arguments used; the file states the counts (argument-taking, and argument-free as recorded in fix(ci): devops ci checks run for real under their own --dry-run #885's task file), reconciles their sum against the issue's 120-path figure and explains any difference. Observable: the table and the reconciliation paragraph in docs/agent/tasks/task-<issue>-dry-run-survey.md.
  • Every row records the exit code and every argv the recorder saw, each marked read-only or mutating, and names any file or remote write the code path performs under --dry-run; a row with no process says none. Observable: no row of the table has an empty result cell.
  • For every command outside commands/ci.py recorded as mutating, the task file names the candidate filed for it, in the shape described above; a survey with no offender says so in one sentence. Observable: the "Candidates filed" section of the task file.
  • The task file reproduces the enumeration and recorder snippet and states that the survey ran with subprocess.run recorded and under the tests/conftest.py network guard, with no live cluster, tunnel, repository or network; no script is added to the tree (git diff --stat main...HEAD lists only the task file and the changelog fragment).
  • uv run devops ci passes.

Out of Scope

Dependencies

Update 2026-10-08: refinement

Under #412's rule, a row is a finding when its --dry-run contacts a server, writes outside its temp directories or changes local state; a local read is not. #885's survey lists gh api rate_limit and kubectl apply -k . --dry-run=client, both findings now. The table gives #412's test its arguments.

  • Every argv is marked local read, local write or external, and every finding has a candidate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/clitype/chore

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions