Skip to content

test(cli): root module and dry-run tests use the public interface #3901

Closed

Description

@dan-petty

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.py patches devops_cli.main._delegate 7 times. It imports the private _handle_lazy_proxy_dry_run and builds a module-level CliRunner().
  • tests/dry_run/test_fast_dispatch.py patches devops_cli.main.app 4 times and devops_cli.entry.main 1 time. It calls the private main._delegate directly. The catch-all test_main_helpers_and_entrypoint and the name test_fast_dispatch name an implementation detail, not a behavior.
  • tests/dry_run/test_consolidation_dry_run_decorator.py patches devops_cli.dry_run.decorator.render_dry_run_result 4 times. It imports the private _MAX_DRY_RUN_* constants. Its name is the name of a refactor.
  • tests/invariants/test_hermetic_floor.py names 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-run flag and of DEVOPS_CLI_DRY_RUN move to tests/commands/ and run through the cli fixture. They use real commands and process_fake. A run without the flag starts the process. A dry run starts none. They patch no devops_cli name.
  • 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 public add_typer.
  • The tests of entry.main and main_entry call them with an argv and read the exit code and the output. Version, help, shell completion, the leading devops word of the argv and the dry-run state go through the real app.
  • The test of a help flag after -- runs devops uv run -- pytest --help with process_fake answering 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 CommandDryRunResult are 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_result is 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_cli name or imports a private name.
  • git grep -n "_delegate" tests/commands tests/dry_run finds 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.py and dry_run/decorator.py makes 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 ci passes.

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.

Related

Parent: #1333. Tracker: #1307. ADR 0007.

Activity

  1. added
    source/agent
    type/test
    scope/cli
    status/new
    value/medium
    effort/medium
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/cli. The (cli) scope of the title gives the scope.
    • Priority: P2-Medium. It improves test maintainability but does not fix a defect or add user-facing behavior.
    • Value: Medium. Removing private-name patches makes tests resilient to refactors, but no user-visible change results.
    • Effort: Medium. Three files must be rewritten, renamed, and a stub module created, with mutation checks passing.
    • Related: feat(cli): each command declares its dry-run class, and a ratchet test stops a new command without one #2230, which asks for a different change. 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.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/in-progress
    and removed
    status/new
    on Nov 7, 2026
  5. added
    status/in-review
    and removed
    status/in-progress
    on Nov 7, 2026
  6. removed
    status/in-review
    on Nov 7, 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/p2-mediumscope/clisource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions