Repository navigation
Description
Problem or Motivation
Part of #1333, item 3 of its Fit note (item 4 in the earlier numbering): "Dry-run and root module tests: 3 files, remove main._delegate and render_dry_run_result patches". The tests of main.py, entry.py and dry_run/ reach into the code under test. They do not use the public interface.
Counts on origin/main (6d105c2), read again because the tree has moved since #1333 was written:
tests/core/test_main_dry_run.pypatchesdevops_cli.main._delegate7 times. It imports the private_handle_lazy_proxy_dry_runand builds a module-levelCliRunner().tests/dry_run/test_fast_dispatch.pypatchesdevops_cli.main.app4 times anddevops_cli.entry.main1 time. It calls the privatemain._delegatedirectly. The catch-alltest_main_helpers_and_entrypointand the nametest_fast_dispatchname an implementation detail, not a behavior.tests/dry_run/test_consolidation_dry_run_decorator.pypatchesdevops_cli.dry_run.decorator.render_dry_run_result4 times. It imports the private_MAX_DRY_RUN_*constants. Its name is the name of a refactor.tests/invariants/test_hermetic_floor.pynames the decorator test file in a list of floor-reset fixtures.
The claim of #1333 holds in the current tree, with these counts: 11 patches of main names and 4 of render_dry_run_result, in 3 files.
The shared cli fixture, process_fake and the hermetic floor already exist. Real commands such as tf apply, uv sync and uv run start a process only through the process runner, so process_fake shows whether a dry run started anything.
Proposed Solution & Architectural Design
- The tests of the global
--dry-runflag and ofDEVOPS_CLI_DRY_RUNmove totests/commands/and run through theclifixture. They use real commands andprocess_fake. A run without the flag starts the process. A dry run starts none. They patch nodevops_cliname. - The generic preview of a command with no dry-run class uses the stub command module
tests/support/dry_run_stub.py, registered on the root app for the test through Typer's publicadd_typer. - The tests of
entry.mainandmain_entrycall them with an argv and read the exit code and the output. Version, help, shell completion, the leadingdevopsword of the argv and the dry-run state go through the real app. - The test of a help flag after
--runsdevops uv run -- pytest --helpwithprocess_fakeanswering exit code 3. It no longer calls_delegate. - The decorator tests read what the decorator prints. A detail that cannot be serialized makes the render fail, which shows the state is restored on an error. No test patches
render_dry_run_result. - The bounds of
CommandDryRunResultare written as literal numbers in the test. The test imports no private constant. - The files are renamed after their behavior: the global dry-run flag, the entry point, the dry-run state and the dry-run command decorator. The catch-alls dissolve. The plan rendering of
render_dry_run_resultis a syrupy snapshot.
Out of scope (other items of #1333): core, config, http, exceptions/lang/models, the accommodations in src/, dead code, the split of test_data_dir_worktrees.py, and tests/invariants/test_dry_run_class_ratchet.py. The git item of the Fit note is stale: ADR 0007 fakes git.
Target Subsystem
SDLC, Git & PR Governance
Acceptance criteria
- No test in the 3 files, or in the files that replace them, patches a
devops_cliname or imports a private name. -
git grep -n "_delegate" tests/commands tests/dry_runfinds nothing. - Each replaced behavior keeps a test that fails when the product code changes: a mutated copy of
main.py,entry.py,dry_run/state.pyanddry_run/decorator.pymakes the new tests fail. - No file in the scope is named after a refactor, and the catch-all test names are gone.
-
uv run devops cipasses.
Existing Tool Considered
pytest, syrupy, Typer's CliRunner and the shared fakes of tests/support/fakes/ cover the need. This item builds nothing new except a small registration fixture for the existing stub command module.
Activity
dan-petty commentedon Nov 7, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
testprefix of the title gives the type.(cli)scope of the title gives the scope.It improves test maintainability but does not fix a defect or add user-facing behavior.Removing private-name patches makes tests resilient to refactors, but no user-visible change results.Three files must be rewritten, renamed, and a stub module created, with mutation checks passing.Both work on dry-run test infrastructure, but #2230 adds a new ratchet test while this candidate refactors existing tests to use the public interface.test(cli): root module and dry-run tests use the public interface
refactor(cli): entry.main sets a dry-run state that is set again (#4286)