Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

## Decisions

- **Build each PlannedRequest from the same argument builder the real run uses**: The issue states the plan cannot drift from the run. Using the same builder guarantees the plan matches the real requests.
- **Remove echo-only previews with no shim**: The issue says 'with no shim' and the pre-1.0 policy in the repository deletes rather than keeps behind flags.
- **Group commands by family and work type (mark-only vs request-plan)**: Each group fits the 40000-token budget. A group of 2-5 commands in one file keeps the step small and focused.
- **Use the existing PlannedRequest and render_request_plan**: They exist in the repository (#741) and are the established pattern. Building new rendering would duplicate code.
1. **One argv builder serves the plan and the run.** The issue asks that a plan cannot drift from the run. Today no builder exists: each command builds its argv inline. Each request-plan group splits the argv into a pure function that returns the command, and the real run calls it. The plan module calls the same function.
- `src/devops_cli/git/operations.py`: `fetch_all` and `pull_tracking` call functions that return the git commands (they read the remotes, the current branch and the tracking remote with `local_read`). `clone_repo` calls a function that returns the clone command. The calls, their arguments and their order do not change, because recorded git transcripts and `tests/git/test_git_operations.py` pin them.
- `src/devops_cli/github/client.py`: `get_org_repos` calls two functions that return the listing path of an organization and the fallback path of the own account.
- `src/devops_cli/github/ssh.py` and `src/devops_cli/crypto/ssh_keys.py`: `register_key_on_github` and `configure_git_signing` call functions that return the key request bodies and the `git config` commands.
- `src/devops_cli/crypto/tls_plans.py` (new): `enable_k8s_cmd` gets its four kubectl commands from functions of this module. The command still calls `run_subprocess` itself, because `tests/commands/test_tls_cmd.py` patches that name.
2. **Local reads run in a dry run. External reads are listed, not made.** The runner lets a `local_read` call run in a dry run, and `_remotes`, `current_branch` and `_tracking_remote` already use it. So the plan of `branches sync` and `repos sync` holds the exact `git fetch` and `git pull` commands. A read that goes to GitHub is a planned request with a condition or a repeat. These are the organization listing of `repos clone-org` (with its fallback to the own account), the follow-up listing of a key that GitHub refuses with HTTP 422, and the pull request read of `repos worktrees prune`. A value that only the real run knows is a named placeholder, such as `<repo>` or `<output of the previous request>`.
3. **`repos worktrees prune` is a request plan.** The run without `--confirm` reads GitHub. Its `--dry-run` already lists these reads. The group adds the class and the entry in the gap list, and no code.
4. **A command that writes local state keeps a local preview.** The issue table marks `branches jira`, `ssh generate`, `tls ca`, `tls cert` and `tls homelab` as "mark only", so that `devops --dry-run <command>` runs them normally. The evidence in Feasibility shows that this is wrong for these five. A normal run under the dry-run state writes the private key of `ssh generate`, and the key and certificate files of the three `tls` commands. For `branches jira` it prints a false success: the runner turns `git checkout -b` into a plan result. The merged base spec already sets the rule for such commands: `workspace-no-external-request` and `devcontainer-no-external-request` say that a `no-external-request` command which writes local state provides a local preview under `--dry-run` without modifying paths. Change `2260` follows the same rule. So these five commands carry the `no-external-request` class, keep or get a `--dry-run`, and print one `Would ...` line with `print_info`. They write nothing. The line is not an echo of the arguments, and `render_dry_run_result` is not used. The eight commands that only read have no `--dry-run` option and run normally under `devops --dry-run`. `branches clean` keeps its own `--dry-run`: it is a real preview of `delete_merged_branches`.
5. **Tests use the fakes of `docs/TESTING.md`, not a patch.** `git_fake` answers the local reads, `process_fake` records the other process starts, and `github_api` records the GitHub requests. A dry-run test asserts that no call has `local_read` false and that `github_api.sent` is empty. A plan test runs the real command on the same fakes, and compares the argv of its calls that are not local reads, in order, with the numbered lines of the dry run. A request that has a `condition` is left out of the comparison when the scenario does not trigger it. The new tests join the existing test files of the commands (`tests/commands/test_branches.py`, `tests/commands/test_repos.py`, `tests/git/test_repos_worktrees.py`, `tests/crypto/test_ssh.py`, `tests/commands/test_tls_cmd.py`). These files hold the helpers and fixtures that the tests need, and a test file may not import another test file.
6. **No `--format` or `--json` for the new plans.** None of the nine commands that get a new plan has such an option, and no consumer asks for one. The issue criterion applies to a command that already has one. Only `repos worktrees prune` has, and it already returns its report with the requests.
7. **`tls ca` and `tls cert` leave the MCP exposure table.** `CONST_MCP_EXPOSURE_TABLE` (`src/devops_cli/config/constants.py`) lists both with `read_only=False`, and `generator.py` sends that value as `readOnlyHint`. The invariant `test_mcp_exposure_table_no_external_request_read_only` fails for a `no-external-request` command with `read_only=False`. The class is right for both commands (decision 4), so the table must change. `readOnlyHint=True` would be false: both commands write a private key and a certificate, and a client may skip its confirmation for a read-only tool. So the two entries go. Each command moves to `mcp_command_exclusions` in `tests/ai/mcp/test_mcp.py`, which `test_all_cli_commands_are_either_exposed_or_excluded` reads. `tls_ca` and `tls_cert` leave the list of expected tools in `tests/ai/mcp/test_fastmcp_contracts.py`. `docs/MCP_TOOLS.md` is generated and loses the two tools in group 8. `tls_inspect` stays. Both commands stay in the CLI.

## Rejected alternatives

- **Build a new dry-run rendering module for these commands**: render_request_plan and PlannedRequest already exist (#741, #885 in CHANGELOG.md). Building a new one duplicates code and diverges from the established pattern.
- **Keep echo-only previews as a fallback behind a flag**: The issue says 'with no shim'. The pre-1.0 policy in the repository (ADR 0005, CONTEXT.md) deletes rather than keeps behind flags.
- **Add a new dependency for dry-run planning**: The issue states 'No new dependency is necessary.' The repository already has the full dry-run infrastructure.
- **Patch GitPython in the tests, as the first plan said.** The library is gone: `grep -c -i gitpython pyproject.toml` prints 0, and every git call goes through `run_subprocess`. A patch of GitPython would pass for the wrong reason.
- **Collect the `PlannedProcessResult` values that the runner returns in a dry run.** The runner returns one for each call that is not a `local_read` (`src/devops_cli/core/process.py`: the guard at line 624, the return at line 631), so the real code path would make the plan. But no collector exists, `_git` runs with `quiet=True` and drops the result, and the GitHub session does not use the runner. A collector is a new mechanism in a 1,200-line core module for four commands. It also hides the plan inside the run, which is the coupling that the issue wants to avoid. Rejected for cost and size.
- **Run the five local writers normally under `devops --dry-run`, as the issue table says.** Rejected, with the evidence of decision 4.
- **Reuse `plan_k8s_enable_tls` and `plan_k8s_create_tls_secret` for `tls enable-k8s`.** They plan no render and no `apply`, they take a stack instead of a namespace list, and `k8s enable-tls` (#2239) owns them. A change of them would change the plan of another command.
- **Give the new request plans a `--format json` option.** No consumer needs it (decision 6).
- **Remove `--dry-run` from `branches clean`.** The first plan did. The option is a real preview, not an echo. `tests/commands/test_branches.py::test_branches_commands` runs it.
- **Set `read_only=True` for `tls ca` and `tls cert`.** This would pass the invariant with a false hint (decision 7).
- **Test every group by an invented ratchet change.** The ratchet test already fails when a classified command stays in the gap list and when a request-plan command has no `--dry-run`. It needs no change.
Loading
Loading