Skip to content

test(cli): command tests patch no devops_cli names #3769

Closed
6 of 6 issues completed
Closed

Description

@dan-petty

Problem or Motivation

Issue #1327 is closed as completed. Its goal was that the command tests double only edges. At origin/main cfee381 (2026-11-06), the command tests still patch names inside devops_cli.

Measured with git grep on tests/commands:

  • 869 string patches of a devops_cli name (monkeypatch.setattr, mock.patch and patch).
  • 740 of them target a name inside devops_cli.commands, such as commands.valkey._resolve_client (24 references in test_valkey.py) and commands.cloudflare.load_settings (20 in test_cloudflare_commands.py).
  • 64 of the 129 test files of tests/commands hold at least one of these patches.
  • The largest files: k8s/test_k8s.py (134), test_pr_cmd.py (47), test_repos.py (41), test_ci.py (40), test_test_selection.py (39), test_gh_cmd.py (37), test_cloudflare_commands.py (36) and k8s/test_k8s_bootstrap.py (29).

Issue #1336 turns the ratchets of #1309 into bans. It will fail on these patches. So this work blocks #1336.

Proposed Solution & Architectural Design

Replace each internal patch with a double of the edge that the command reaches: the process fake, the HTTP fake, the GitHub fake, the Kubernetes fake or the settings fixture of tests/support/config.py. Follow the rules of docs/TESTING.md and the pattern that #1323, #1325 and the adapters of #1327 used.

The work is too large for one pull request. Split it by command group, one pull request for each group, and keep the order of the largest files first:

  1. k8s/ command tests.
  2. pr, gh and repos command tests.
  3. ci and test_selection command tests.
  4. cloudflare, valkey and the remaining command tests.

Each pull request states its count of patches before and after. The ceiling of the ratchet then goes down with each pull request.

Acceptance criteria for the whole item:

Target Subsystem

SDLC, Git & PR Governance.

Existing Tool Considered

No new tool is needed. The fakes of tests/support/fakes/, the config fixture and pytest already cover this. The cost of building the fakes is already paid by #1313, #1315 to #1320 and #1323 to #1325.

Proposed design

Problem statement

The command tests double names inside devops_cli instead of the edges that the commands reach. At cfee381, tests/commands holds 869 string patches of a devops_cli name, and 64 of its 129 test files hold at least one. The patches break the rule of docs/TESTING.md and stop #1336 from turning its ratchet into a ban.

Acceptance criteria

Requirement: The command tests patch no devops_cli name

The test files under tests/commands SHALL hold no string patch of a devops_cli name.

Scenario: The command tests are searched for a patch of a devops_cli name

  • WHEN a run searches tests/commands for monkeypatch.setattr, mock.patch and patch calls that name a devops_cli module
  • THEN the search finds no match and exits with status 0

Requirement: A command keeps its tests

Each command test file SHALL keep every test that it held before the change.

Scenario: The collected tests of the command tests before and after the change

  • WHEN a run collects the tests of tests/commands on the base commit and on the changed commit
  • THEN the changed commit collects every test identifier that the base commit collected, and each one passes

Requirement: A test sets configuration through the config fixture

A command test SHALL set configuration through the config fixture and SHALL NOT patch load_settings or a config path.

Scenario: A command test needs a setting that differs from the default

  • WHEN a converted test needs a setting that differs from its default
  • THEN the test writes the setting through the config fixture and patches no settings name

Requirement: A test reaches an edge through its fake

A command test SHALL reach each edge through the fake of that edge and SHALL install no patch of a devops_cli name.

Scenario: A converted test reaches the process edge

  • WHEN a converted test runs a command that starts a program
  • THEN the fake records the call, and the test installs no patch of a devops_cli name

Requirement: Each pull request states its patch count

Each pull request of the split SHALL state the count of string patches of a devops_cli name in its command group before and after the change.

Scenario: The patch count of a command group after its pull request

  • WHEN a run counts the string patches of a devops_cli name in the group's test files after the change
  • THEN the count is lower than the count on the base commit and equals the number that the pull request body states

Existing Tool Considered

No alternatives check has run. No new tool is needed, and the change writes no code of its own. pytest, with the fakes of tests/support/fakes/ (process, HTTP, GitHub, Kubernetes, Valkey), the config fixture of tests/support/config.py and the cli fixture, covers the need. They lack a double for logic that sits in commands/ and is no edge: that logic moves into its domain package.

Key questions

  • Which double replaces a patch of a devops_cli name in a command test?: Install the fake of the edge that the command reaches through its fixture: process_fake, web, github_api, cluster, valkey or the config fixture. The test asserts on what the fake recorded, and it patches no devops_cli name. (best practice) [sources: docs/TESTING.md, docs/adr/0007-tests-double-only-process-edges.md, tests/support/config.py]
    • Chosen: The fake of the edge, through its fixture. docs/TESTING.md gives one fake for each edge and forbids a patch of a devops_cli name.
    • Rejected: A patch of the stdlib or of the SDK object. docs/TESTING.md allows it only for an edge that no seam reaches, and never at a devops_cli name.
    • Rejected: Keep the patch under a ceiling. The goal is a ban, and a ceiling keeps the patch.
  • What does a test do when the patched name is command-layer logic and not an edge?: Move the logic into its domain package behind a public function and test it there. The command becomes a thin adapter, and the CLI test reaches only the edge. (best practice) [sources: docs/TESTING.md]
    • Chosen: Move the logic into its domain package. docs/TESTING.md requires that logic behind a private helper in commands/ moves to its domain package.
    • Rejected: Keep the patch with a marker. A marked patch still fails the ban of test(cli): Convert ratchets to bans and merge invariant tests #1336.
    • Rejected: Delete the test. The command would lose the behavior that the test checks.
  • Which fixture replaces a patch of load_settings or of a config path?: The config fixture in tests/support/config.py. It writes the overrides into the test's own config.yaml and resets the settings cache. [sources: tests/support/config.py, docs/TESTING.md]
  • Which double does a test use when no fake reaches its edge?: Use a parameter that the code already takes, a shared double already in tests/, or the stdlib fallback. If none reaches the edge, patch the SDK object at the SDK's own module, never a devops_cli name. A new fake goes to tests/support/fakes/<edge>.py and comes with its contract suite. (best practice) [sources: docs/TESTING.md]
    • Chosen: A parameter the code takes, a shared double, or the stdlib fallback. docs/TESTING.md names these in this order and forbids a patch of devops-cli.
    • Rejected: The SDK object at the SDK's own module. It is the last fallback, for an edge that none of the three reaches.
    • Rejected: The devops_cli name, with a comment. It is the patch that this item removes.
  • How is the work split, and in which order?: Four pull requests, one for each command group, largest files first: k8s, then pr/gh/repos, then ci/test_selection, then cloudflare/valkey and the rest. Each pull request states its count of patches before and after. (best practice) [sources: docs/TESTING.md]
    • Chosen: One pull request for each command group. 869 patches in 64 files exceed one pull request, and the ratchet ceiling goes down once per pull request.
    • Rejected: One pull request for the whole directory. The change is too large for one review.
    • Rejected: One pull request for each test file. 64 pull requests cost more review time than four.
  • How does a run count the patches of a command group?: With the git grep form that docs/TESTING.md fixes: -n -I -F and a plain literal, or -e literals before -- and the relative paths. The count of monkeypatch.setattr, mock.patch and patch calls that name devops_cli gives the number. [sources: docs/TESTING.md]

Fit

Needs splitting into 4 items:

  1. k8s command tests: the files of tests/commands/k8s/, with test_k8s.py (134 patches) and test_k8s_bootstrap.py (29) first.
  2. pr, gh and repos command tests: test_pr_cmd.py (47 patches), test_repos.py (41) and test_gh_cmd.py (37).
  3. ci and test_selection command tests: test_ci.py (40 patches) and test_test_selection.py (39).
  4. cloudflare, valkey and the remaining command tests: test_cloudflare_commands.py (36 patches), test_valkey.py (24) and the rest.

Suspected block

None.

Dependencies

None.

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

Sub-issues

Sub-issues

6 of 6 Issues completed
Loading 6 sub-issues

Activity

  1. added
    source/agent
    type/test
    scope/cli
    status/new
    value/medium
    effort/high
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 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 blocks #1336 but is a test refactoring, not a production defect.
    • Value: Medium. It improves test maintainability and unblocks #1336 but does not change user-facing behavior.
    • Effort: High. 869 patches across 64 files split into four pull requests.
    • Related: test(cli): tests double only process edges and mirror the source tree #1307, which asks for a different change. Both target removing internal patches from command tests; #1307 is the umbrella that defines the edge-fake rule, while the candidate is the specific remaining work in tests/commands.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    The proposal at 72c52c6 needs splitting into 4 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. k8s command tests: the files of tests/commands/k8s/, with test_k8s.py (134 patches) and test_k8s_bootstrap.py (29) first.
    2. pr, gh and repos command tests: test_pr_cmd.py (47 patches), test_repos.py (41) and test_gh_cmd.py (37).
    3. ci and test_selection command tests: test_ci.py (40 patches) and test_test_selection.py (39).
    4. cloudflare, valkey and the remaining command tests: test_cloudflare_commands.py (36 patches), test_valkey.py (24) and the rest.
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

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

    Tool: none found

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

  6. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 9, 2026
  7. removed
    status/in-review
    on Nov 9, 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/highpriority/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