Skip to content

refactor(cli): entry.main sets a dry-run state that is set again #3910

Closed

Description

@dan-petty

Problem or Motivation

entry.main in src/devops_cli/entry.py calls set_dry_run(True) when the argv holds --dry-run. The root callback main in src/devops_cli/main.py then calls set_dry_run(requested) before any command runs. For every run that reaches a command, the root callback decides the final state, so the call in entry.main has no effect that a person or a test can see.

Found while the tests of the entry point moved off a mocked app (#3901). The old test saw the call only because it replaced the app with a mock. A mutation that removes the call survives all tests that run the real app.

The call may still serve a run that stops before the root callback, such as an eager option like --version. Check this first. If no such run needs the state, the call is dead code.

Proposed Solution & Architectural Design

Check the runs that stop before the root callback. If none needs the state, delete the call and the set_dry_run import from entry.py. If one needs it, add a test through the public interface that fails without the call.

Target Subsystem

SDLC, Git & PR Governance

Acceptance criteria

  • The call is deleted with a test that shows no behavior changes, or a test through the public interface fails when the call is removed.
  • uv run devops ci passes.

Existing Tool Considered

Not applicable: this item builds nothing.

Related

Found in #3901. Parent of the test migration: #1333.

Alternatives check of 2026-11-09: not-applicable.
Class: refactor, no search.
Tool: none found.

Proposed design

Problem statement

entry.main in src/devops_cli/entry.py calls set_dry_run(True) when the argv holds --dry-run, and the root callback main in src/devops_cli/main.py sets the dry-run state again before any command runs. The check finds that no run that stops before the root callback (--version, --help, a usage error or a no-argument run) reads the state, and that the telemetry export at exit reads in_dry_run_invocation, which mark_dry_run_invocation already sets. The entry call is not harmless in one run: with DEVOPS_CLI_DRY_RUN exported and a command's own --dry-run, it marks the request as activated here, so the root callback clears the exported variable, contrary to the recorded intent. The change deletes the call and the set_dry_run import, keeps the invocation mark, and tests the early-stop runs and the exported-env run.

Acceptance criteria

Requirement: Entry point sets no dry-run state

The function entry.main SHALL NOT call set_dry_run and src/devops_cli/entry.py SHALL NOT import it, so that an exported DEVOPS_CLI_DRY_RUN survives a command's own --dry-run.

Scenario: An exported dry-run request meets a command's own flag

  • WHEN the real entry point runs main(["devops", "uv", "sync", "--dry-run"]) with DEVOPS_CLI_DRY_RUN=1
  • THEN the run prints the devops uv sync plan, starts no program, and is_dry_run() is true

Requirement: Early stop runs keep their behavior

A run that stops before the root callback, such as --version, MUST keep its output and its exit code.

Scenario: Version flag with the dry-run flag

  • WHEN the real entry point runs main(["devops", "--dry-run", "--version"])
  • THEN the output shows the version and the exit code is 0

Requirement: Dry-run invocation mark stays

The function entry.main SHALL keep the call to mark_dry_run_invocation with the requested value.

Scenario: The mark is recorded before an early stop

  • WHEN the real entry point runs main(["devops", "--dry-run", "--version"])
  • THEN in_dry_run_invocation() is true after the run, although the root callback never ran

Requirement: Full check passes

The command uv run devops ci MUST pass after the change.

Scenario: CI run on the change

  • WHEN uv run devops ci runs on the branch
  • THEN the command exits with code 0

Existing Tool Considered

Not applicable: this item builds nothing. It deletes one call and one import and adds tests to tests/commands/test_entry_point.py. The cost is a few thousand tokens and under one hour. The alternatives check of 2026-11-09 recorded verdict not-applicable (class refactor, no search) and found no tool.

Key questions

  • Which runs stop before the root callback main and could need the dry-run state that entry.main sets?: None. The runs that stop before the root callback are --version, --help, a usage error and a run with no arguments. The --version callback prints the version and raises typer.Exit without reading the state (src/devops_cli/main.py:268-273), and Typer prints help or a usage error without reaching it. The reads of is_dry_run() before a command are in _delegate (src/devops_cli/main.py:158) and in the lazy proxy (src/devops_cli/core/cli.py:184), both after the root callback. The atexit handler prints only the elapsed time (src/devops_cli/main.py:27-35), and the telemetry export at exit asks in_dry_run_invocation() (src/devops_cli/telemetry/tracer.py:1328-1331), which mark_dry_run_invocation (src/devops_cli/entry.py:50, src/devops_cli/dry_run/state.py:49-52) sets before the app runs, so an early stop still exports nothing. A command's own --dry-run without an exported variable still ends with is_dry_run() false and in_dry_run_invocation() true, as tests/commands/test_entry_point.py:118-131 asserts. The one run whose final state the entry call changes is an exported DEVOPS_CLI_DRY_RUN with a command's own --dry-run: the call sets _ACTIVATED_HERE (src/devops_cli/dry_run/state.py:26), so dry_run_requested_by_environment() returns False (src/devops_cli/dry_run/state.py:40) and the root callback clears the exported variable (src/devops_cli/main.py:302), contrary to the comment at src/devops_cli/main.py:295-300. [sources: src/devops_cli/main.py:268, src/devops_cli/main.py:273, src/devops_cli/main.py:158, src/devops_cli/core/cli.py:184, src/devops_cli/main.py:27, src/devops_cli/telemetry/tracer.py:1328, src/devops_cli/entry.py:50, src/devops_cli/dry_run/state.py:49, src/devops_cli/dry_run/state.py:26, src/devops_cli/dry_run/state.py:40, src/devops_cli/main.py:302, src/devops_cli/main.py:295, tests/commands/test_entry_point.py:131]
  • Should the call be deleted or kept with a new test?: Delete the call and the set_dry_run import. docs/TESTING.md records that a line no public behaviour reaches is dead code and is deleted, not covered by a test that reaches past the public interface. No run that stops before the root callback reads the state, so the issue's second branch, a test through the public interface that fails without the call, has no case. The early-stop runs keep their output and exit code, and the invocation mark stays. (best practice) [sources: docs/TESTING.md:185, src/devops_cli/main.py:302, src/devops_cli/entry.py:52, src/devops_cli/dry_run/state.py:33]
    • Chosen: Delete the call and the import. No early run reads the state, the root callback sets the final state for every run that reaches a command, and docs/TESTING.md:185 says dead code is deleted.
    • Rejected: Keep the call and add a test that fails without it. No run that stops before the root callback reads the state, so no public-interface test can fail without the call.
    • Rejected: Keep the call with no test. No caller needs it, and the project's dead-code rule says such a line is deleted, not kept without a guard.
  • Does an exported DEVOPS_CLI_DRY_RUN with a command's own --dry-run need the entry call to keep the state?: No. The call sets _ACTIVATED_HERE, so dry_run_requested_by_environment() reports False and the root callback clears the exported variable, which contradicts the comment at src/devops_cli/main.py:295-302 that an exported request must survive. Deleting the call leaves the exported request on, and a test of that run fails if the call returns. (best practice) [sources: src/devops_cli/main.py:295, src/devops_cli/dry_run/state.py:33, src/devops_cli/dry_run/state.py:23, src/devops_cli/entry.py:49]
    • Chosen: Delete the call and test the exported-env run. It keeps the exported request, as the root callback's comment records, and the test fails if the call returns.
    • Rejected: Keep the call to clear the exported state. It discards a request the caller exported, contrary to src/devops_cli/main.py:295-302 and src/devops_cli/dry_run/state.py:33-40.
    • Rejected: Delete the call without a test for the exported-env run. The one state change would be unguarded, and a later re-add of the call would pass the suite.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    scope/cli
    status/new
    value/low
    effort/low
    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/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/cli. The (cli) scope of the title gives the scope.
    • Priority: P3-Low. Dead code removal with no user-visible effect and no blocking dependency.
    • Value: Low. Removes a redundant call; no user-facing behaviour changes.
    • Effort: Low. Delete one call and one import, or add one test through the public interface.
    • Related: test(cli): root module and dry-run tests use the public interface #3901, which asks for a different change. Both concern dry-run state in entry.py, but #3901 migrates tests to the public interface while this item removes a dead code call found during that work.
  3. added
    priority/p3-low
    on Nov 7, 2026
  4. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: refactor. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 9, 2026
  6. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 1b37dbc (see proposed design in issue body).

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 9, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 9, 2026
  9. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-09 23:58 UTC

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/lowpriority/p3-lowscope/clisource/agenttype/refactorvalue/low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions