Skip to content

test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325

Closed

Description

@dan-petty

Problem

Counts come from one AST pass over tests/test_*.py at 5c45b1e, the head of release/v0.2.28, and [code: …] lines are at the same commit. A file belongs to the package it references most, as in the census.

  • Files. 12 test files, 6,037 lines, 246 tests [measured: AST pass at 5c45b1e]: test_ci, test_ci_build_index, test_ci_dry_run, test_ci_maintain, test_test_selection, test_test_runner, test_load_and_pipeline, test_devcontainer, test_workspace, test_install_tools, test_uv and test_branches.
    • No other item names commands/pipeline.py (devops pipeline run). Its tests share test_load_and_pipeline.py with devops test load, so this item takes it (see Key questions).
  • Coupling. All 12 files hold internal patch sites, 213 in total, and 6 of them hold the 76 private imports [measured]. Most of the private imports are in test_devcontainer.py (37), test_ci.py (17) and test_install_tools.py (17).
    • Most-patched internals: ci._get_project_root 22, devcontainer.run_subprocess 21, ci._run 18, install_tools._download 12, ci.run_subprocess 11, test_cmd.run_subprocess 9, ci.cache.compute_worktree_blob_hashes 8, devcontainer._keyring_is_locked 7, workspace._PROJECT_ROOT 6.
    • Another 57 sites patch shutil.which (34), subprocess.run (20) or subprocess.Popen (3) directly.
    • 11 of the files build a module-level runner = CliRunner().
  • Product code shaped for tests (Q27).
  • Edges outside a seam.
    • commands/devcontainer.py:
      • 15 shutil.which calls [code: commands/devcontainer.py:524-1523];
      • a subprocess.Popen [code: commands/devcontainer.py:1042];
      • gh calls made outside run_gh [code: commands/devcontainer.py:1461, :1466];
      • a D-Bus socket [code: commands/devcontainer.py:1283] and secretstorage [code: commands/devcontainer.py:1396];
      • a TCP probe of the local git daemon [code: commands/devcontainer.py:1221];
      • SIGALRM [code: commands/devcontainer.py:1440];
      • a time.sleep poll [code: commands/devcontainer.py:946].
    • commands/install_tools.py builds httpx2 clients [code: commands/install_tools.py:84, :100, :190] and calls shutil.which [code: commands/install_tools.py:495].
    • commands/test_cmd.py calls shutil.which [code: commands/test_cmd.py:235].
    • devops test sandbox runs through the Docker engine [code: commands/test_cmd.py:398].
  • Logic living in commands/ (Q19). commands/ci.py (1,765 lines) holds:
    • check specs and selection [code: commands/ci.py:398-612];
    • the gate cache [code: commands/ci.py:888-993];
    • result assembly [code: commands/ci.py:683, :1016];
    • coverage-artifact cleanup [code: commands/ci.py:219-273];
    • test-target selection [code: commands/ci.py:1131-1358], which imports private core.coverage_index names [code: commands/ci.py:1174].
  • Files and names.
    • test_devcontainer.py: 2,042 lines, 89 tests in one class.
    • test_ci.py: 1,878 lines, 64 tests. Ten of its tests take a committed workflow or action file as their subject (:575, :598, :637, :670, :697, :749, :1031, :1056, :1836, :1846); the two at :1031 and :1056 run the workflow's image-change step in a temporary repository.
    • Catch-alls: test_ci.py:318, :342, :383, :463; test_devcontainer.py:823, :939, :1020; test_install_tools.py:167; test_uv.py:46; test_workspace.py:109; test_branches.py:63.

Acceptance criteria

Key questions

Strategic alignment

Proposed design

Problem statement

Twelve test files (6,037 lines, 246 tests) for devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline use 213 internal patch sites and 76 private imports. Product code holds test accommodations: lazy patch targets in four command modules and PYTEST_CURRENT_TEST checks in ci.py and process.py. Domain logic (check specs, gate cache, result assembly, coverage cleanup, test-target selection) lives in commands/ci.py instead of its package. This item removes all accommodations, moves logic to its package, and rewrites the tests over edge fakes with behaviour-based naming.

Acceptance criteria

  • Criterion 1: The 12 test files under tests/commands/ have zero patch sites aimed at devops_cli internals and zero private imports.
    Verification: Run rg -n 'patch\(|from devops_cli.* import _' tests/commands/test_ci*.py tests/commands/test_test_*.py tests/commands/test_load_and_pipeline.py tests/commands/test_devcontainer.py tests/commands/test_workspace.py tests/commands/test_install_tools.py tests/commands/test_uv.py tests/commands/test_branches.py and confirm no output.
  • Criterion 2: No _LAZY_OBJECT_MAPPING or PYTEST_CURRENT_TEST references remain in the four command modules or core/process.py.
    Verification: Run rg -n '_LAZY_OBJECT_MAPPING|PYTEST_CURRENT_TEST' src/devops_cli/commands/ci.py src/devops_cli/commands/uv.py src/devops_cli/commands/workspace.py src/devops_cli/commands/branches.py src/devops_cli/core/process.py and confirm no output.
  • Criterion 3: No test patches subprocess, shutil.which, run_subprocess, _run, _get_project_root or _PROJECT_ROOT. Tests run inside a temporary repository.
    Verification: Run rg -n 'subprocess|shutil\.which|run_subprocess|_run\(|_get_project_root|_PROJECT_ROOT' tests/commands/test_ci*.py tests/commands/test_test_*.py tests/commands/test_load_and_pipeline.py tests/commands/test_devcontainer.py tests/commands/test_workspace.py tests/commands/test_install_tools.py tests/commands/test_uv.py tests/commands/test_branches.py and confirm no patch targets remain.
  • Criterion 4: Check specs, gate cache, result assembly and coverage cleanup are public functions in ci/. Test-target selection is in core/test_selection.py. commands/ci.py is a thin adapter.
    Verification: Run rg -n '^def ' src/devops_cli/ci/ and confirm the functions exist. Run rg -n '^def ' src/devops_cli/core/test_selection.py and confirm test-target selection is there. Confirm commands/ci.py contains no logic beyond CLI argument parsing and delegation.
  • Criterion 5: The 10 workflow tests live in tests/invariants/test_workflows.py. No second workflow file exists beside it.
    Verification: Run ls tests/invariants/test_workflows.py and confirm it exists. Run rg -l 'workflow' tests/ and confirm only test_workflows.py holds workflow tests.
  • Criterion 6: test_devcontainer.py and test_ci.py are deleted. Their tests live in behaviour files. Catch-alls are dissolved. Test names state behaviour.
    Verification: Run ls tests/commands/test_devcontainer.py tests/commands/test_ci.py 2>&1 and confirm both report No such file. Run rg -n 'def test_' tests/ci/ tests/commands/ and confirm test names state behaviour.
  • Criterion 7: The 90% coverage gate passes and uv run devops ci exits with code 0.
    Verification: Run uv run devops ci and confirm exit code 0.

Key questions

  • Which files belong to this item?: The 12 files named in the body: test_ci, test_ci_build_index, test_ci_dry_run, test_ci_maintain, test_test_selection, test_test_runner, test_load_and_pipeline, test_devcontainer, test_workspace, test_install_tools, test_uv and test_branches. commands/pipeline.py joins this item. (proposed)
  • Where does the devcontainer logic go?: It stays in commands/devcontainer.py and is tested through the CLI with edge fakes. Creating a package for it is a separate item. (proposed) [sources: src/devops_cli/commands/devcontainer.py]
  • Does the CI logic move in this item?: Yes, into ci/, tested in tests/ci/. If the move is too big for one PR, it gets its own split and this item tests that logic through the CLI with edge fakes until then. (proposed) [sources: src/devops_cli/commands/ci.py]
  • How does devops workspace find its root?: It resolves the current worktree root, as commands/ci.py:95 does, so tests run in a temporary repository. (proposed) [sources: src/devops_cli/commands/workspace.py:62, src/devops_cli/commands/ci.py:95]
  • Is this one pull request?: No. The scope (6,037 lines of test code, 246 tests, moving 1,765 lines of product code, creating new packages) exceeds one PR. It splits into multiple items. (proposed) [sources: src/devops_cli/commands/ci.py]

Fit

Needs splitting into 6 items:

  1. Move CI logic (check specs, gate cache, result assembly, coverage cleanup) into ci/ package, tested in tests/ci/
  2. Move test-target selection into core/test_selection.py and stop importing private names
  3. Remove lazy patch targets and PYTEST_CURRENT_TEST accommodations from product code
  4. Refactor test files for ci, test, load_and_pipeline to use edge fakes; create behaviour files in tests/ci/
  5. Refactor test files for devcontainer, workspace, install-tools, uv, branches to use edge fakes; create behaviour files
  6. Move 10 workflow tests to tests/invariants/test_workflows.py and fix workspace root resolution

Suspected block

None.

Dependencies

#1313, #1314, #1316, #1318

Alternatives check of 2026-10-30: not-applicable.
Tool: none found.

Activity

  1. added
    type/test
    scope/cli
    priority/p2-medium
    scope/ci
    on Oct 7, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. It is a planned maintainability refactor within an existing epic, not a defect or security gap, so it is important but not urgent.
    • Value: High. Removing 213 internal patch sites and 76 private imports across 246 tests will make the suite resilient to refactoring and easier to maintain.
    • Effort: High. Twelve test files totalling 6,037 lines and 246 tests must be rewritten, plus product-code test hooks (lazy mappings, PYTEST_CURRENT_TEST checks) must be removed.
  3. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

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

    • Priority: P2-Medium. This item improves test quality and maintainability but does not address a critical issue.
    • Value: High. Improving test coverage and reducing coupling benefits the overall project health.
    • Effort: Medium. The effort involves refactoring tests and ensuring no lazy patch targets or PYTEST_CURRENT_TEST checks exist.
    • Related: test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, which asks for a different change. Both items test CLI commands with edge fakes but the candidate focuses on CI-related tests while item 1327 covers infra commands.
  4. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    The proposal at 69636b6 needs splitting into 6 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. Move CI logic (check specs, gate cache, result assembly, coverage cleanup) into ci/ package, tested in tests/ci/
    2. Move test-target selection into core/test_selection.py and stop importing private names
    3. Remove lazy patch targets and PYTEST_CURRENT_TEST accommodations from product code
    4. Refactor test files for ci, test, load_and_pipeline to use edge fakes; create behaviour files in tests/ci/
    5. Refactor test files for devcontainer, workspace, install-tools, uv, branches to use edge fakes; create behaviour files
    6. Move 10 workflow tests to tests/invariants/test_workflows.py and fix workspace root resolution
  5. added
    status/new
    effort/medium
    value/high
    on Oct 28, 2026
  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Tool: none found

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

  7. added
    status/in-progress
    and removed
    status/new
    on Oct 31, 2026
  8. removed
    status/in-progress
    on Oct 31, 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/ciscope/clitype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions