Skip to content

refactor(cli): source modules keep no accommodation for tests #4021

Closed

Description

@dan-petty

Problem

Product code under src/devops_cli still holds hooks that only tests use, and some tests still rebind module state to reach them. This is item 6 of the Fit note of #1333. It was measured at origin/main 734e060.

  • The async runner (run_subprocess_async and DefaultProcessRunner.run_async in core/process.py) starts the sync path when subprocess.run is not the stdlib function. The module function is also a second copy of the runner: it does not go through the process runner seam, so process_fake cannot answer it.
  • The child-process environment allow-list passes PYTEST_CURRENT_TEST through.
  • The settings cache key holds str(CONFIG_PATH), because tests rebind it. Ten test sites in nine files rebind settings.CONFIG_PATH. One more test reads it.
  • get_repo_origin_name.cache_clear is attached by hand (core/repo.py). tests/commands/test_repos.py calls it.
  • The floor and three tests in tests/review/test_review_untrusted_tree.py patch the private core.repo._own_source_dir.
  • test_ensure_known_host patches pathlib.Path.home.

Expected

  • Both async runners go through the active process runner. The reroute is gone.
  • The child environment passes no PYTEST_CURRENT_TEST.
  • The settings cache key holds no config path. Every test uses the config or global_config fixture.
  • reset_repo_caches is the public reset of the origin cache. No hand-attached cache_clear remains.
  • A public seam, install_own_source_dir, replaces the patch of _own_source_dir. The floor installs it and the floor reset removes it.
  • test_ensure_known_host sets the home through the environment.
  • A check fails if a source module tells a replaced subprocess.run from the stdlib one, or if the count of PYTEST_CURRENT_TEST reads in src/ rises.

Acceptance criteria

  • core/process.py holds no __module__ check of subprocess.run, and run_subprocess_async calls get_process_runner().run_async.
  • PYTEST_CURRENT_TEST is not in the allow-list of core/process.py.
  • _config_layers builds its cache key from no config path, and no test assigns CONFIG_PATH.
  • No test calls get_repo_origin_name.cache_clear.
  • No test or fixture patches _own_source_dir.
  • A new invariant test fails on the two source patterns above.
  • Not in this item (left for other items of test(cli): Use edge fakes and real git; drop test rebind hooks #1333): the two reads of PYTEST_CURRENT_TEST in commands/ci.py, which need the devops ci tests to move to a root seam first, and the GitHub token privates (_github_token, _lookup_github_token) that the floor assigns.

Existing tool considered

No outside tool fits. The seams follow the pattern that the process runner, the keyring and the DNS lookup already use: a public install function, a fake in tests/support/fakes/, and a reset in the floor. process_fake, the config fixture and global_config already exist.

Related

#1333 (parent), #1307, #3769 (command tests patch no devops_cli names), #1336 (ratchets become bans).

Activity

  1. added
    source/agent
    type/refactor
    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/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/cli. The (cli) scope of the title gives the scope.
    • Priority: P2-Medium. Code-quality cleanup that reduces brittleness but blocks no user-facing work.
    • Value: Medium. Removes hidden coupling so future refactors do not break tests, improving long-term maintainability.
    • Effort: Medium. Six distinct seams across multiple files need public install functions, fixture updates, and a new invariant test.
    • Related: test(cli): tests double only process edges and mirror the source tree #1307, which asks for a different change. Both work under the test-architecture umbrella #1307, but the candidate removes specific source-module test hooks while #1307 defines the overall seam-and-fake model.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/in-review
    and removed
    status/new
    on Nov 7, 2026
  5. removed
    status/in-review
    on Nov 7, 2026
  6. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-07 22:00 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/mediumpriority/p2-mediumscope/clisource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions