Skip to content

test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313

Closed

Description

@dan-petty

Problem

  • The suite is flat. All 447 test files sit directly in tests/; its only subdirectories are tests/fixtures/ and tests/golden/ [measured: find at 5c45b1e]. AGENTS.md already asks for tests organised by submodule, mirroring src/devops_cli/, and allows tests/<submodule>/test_<feature>.py [code: AGENTS.md:159], but nothing checks it. The owner ranks findability second among the suite's problems (Q1).
  • Where a file belongs needs a rule. 146 of the 447 files have under 60% of their devops_cli references in one package directory (93 after discounting config, lang, exceptions, output, models and dry_run), and 9 reference no devops_cli module. The census groups proposed different directories for 23 files and claimed none for 16 [measured: census of 2026-10-07]. File names mislead: tests/test_agent_invariants.py tests the pinned invariants of PydanticAgent, not a committed file [code: tests/test_agent_invariants.py:1, :9], and tests/test_k8s_argocd_overrides.py, new with fix(k8s): argo cd takes homelab values from deploy-time overrides, and the repository holds no private or placeholder config #1290, tests k8s/argocd_overrides.py although it also reads committed manifests [code: tests/test_k8s_argocd_overrides.py:15, :24].
  • One conftest serves every package. tests/conftest.py has 917 lines and 33 fixtures, 17 of them autouse [measured: grep at 5c45b1e]. Beside the isolation every test needs, it holds domain fixtures: the roadmap store (github_roadmap_factory :380, roadmap_store :408, unreadable_github_roadmap :430), git repositories (git :554, nested_worktree :580, symbol_removal_repo :600), review sessions (write_review_session :614, review_history :657), mock_keyring :710, mock_settings :719, docker_engine :744 with reset_docker_engine_singleton :750, public_dns :173, stub_web :204, register_test_mock_provider :59 and guard_live_rag_data :480. tmp_ssh_dir :696 and tmp_repos_dir :703 have no user [code: tests/conftest.py].
  • Moving files today would break them. 48 files find the repo root through __file__ depth and 7 find tests/fixtures or tests/golden relative to themselves [measured: grep at 5c45b1e]; 3 import tests.conftest; tests/test_roadmap_dry_runs.py:47 imports from another test file; and devops test globs tests/ non-recursively [code: src/devops_cli/commands/test_cmd.py:72]. test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312 removes all of these first, so the move edits no test module.
  • One hook names test files by path. detect-private-key excludes tests/test_review_prompt_guardrails.py and tests/test_security_gitleaks.py [code: .pre-commit-config.yaml:26]; moved without an update, both fail the hook.

Acceptance criteria

The move

  • Every tests/test_*.py keeps its file name and moves into the directory mirroring the src/devops_cli package that owns most of what it tests, at full depth (src/devops_cli/ai/review/* -> tests/ai/review/). Ownership counts the devops_cli modules a file imports and the targets it patches, ignoring config, lang, exceptions, output, models and dry_run unless nothing else is referenced. A file whose tests mostly drive a devops command goes under tests/commands/ with that command's module. Cross-package behaviour files (*_hardening.py, test_subprocess_env_boundary.py) go to the package that owns the behaviour.
  • The placement agrees with the phase E file lists: a file that an E item names lands in a directory that item covers, and no file is named by two E items. Where the ownership rule and a list disagree, the task file records the choice and the list is corrected before this PR merges. A name does not decide the directory: test_agent_invariants.py goes to tests/ai/agents/, test_otel_command_coverage.py, which checks the spans and metrics every command emits, to tests/telemetry/, and test_k8s_argocd_overrides.py to tests/k8s/.
  • Invariant tests, whose subject is a committed repo file, move to tests/invariants/ under their current names, for example test_architectural_invariants.py, test_workflow_contracts.py, test_agent_task_files.py, test_agents_md_claims.py and the test_k8s_* files whose subject is the YAML under k8s/ (such as test_k8s_argocd_apps.py).
  • Each new directory has an empty __init__.py, so modules import as tests.<dirs>.<name> and later behaviour-named files may share a base name across packages.
  • The task file lists every move (old path, new directory). For each file whose top package holds under 60% of its references, or whose directory the census disputed, it names the runner-up and why the chosen directory won. It also holds the commands that regenerate the move from that table.

Proof that the move is rename-only

  • git diff --name-status -M100% <merge-base>...HEAD -- tests/ shows an R100 line for every moved test file, and otherwise only M tests/conftest.py, added conftest.py files, added empty __init__.py files, added or modified files under tests/support/ that receive moved fixtures, the layout ratchet in tests/invariants/test_source_tree.py, and, if test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceiling table re-keyed as below. git diff -M --stat shows 0 changed lines for every rename.
  • The test IDs from pytest --collect-only -q at the merge base and at HEAD are the same set once the directory part of each path is dropped, and the full run passes, skips and xfails the same numbers of tests. Both comparisons are recorded in the task file.

The conftest split

The layout ratchet

Landing

  • The detect-private-key exclusion (.pre-commit-config.yaml:26) names the two files' new paths.
  • (person-run) The PR merges into main at a quiet point, when few open PRs change tests/. If another PR changes tests/ first, the move is regenerated from the task file's table rather than rebased.
  • uv run devops ci passes.

Key questions

Strategic alignment

Proposed design

Problem statement

The test suite is flat with 447 files in tests/ directory. Files are not in directories mirroring the source package structure. The root conftest.py holds many fixtures that should be isolated.

Acceptance criteria

  • Criterion 1: Every test file moves to a directory that mirrors its main devops_cli package
    Verification: Files like tests/test_agent_invariants.py move to tests/ai/agents/ and tests/test_k8s_argocd_overrides.py to tests/k8s/
  • Criterion 2: Invariant test files go to tests/invariants/ directory with their current names
    Verification: Files such as test_architectural_invariants.py, test_workflow_contracts.py move to tests/invariants/ directory
  • Criterion 3: Each new directory has an empty init.py file
    Verification: New directories like tests/ai/agents/init.py exist and are empty
  • Criterion 4: Root conftest.py holds only hermetic floor fixtures
    Verification: Root tests/conftest.py contains only network block, isolation and workspace tripwire fixtures
  • Criterion 5: All moved test files are recognized as renames by git
    Verification: git diff --name-status -M100% shows R100 lines for all moved files

Key questions

  • One move, or one per package?: One mechanical move PR at a quiet point on main (proposed)
  • Rename or edit files while moving?: No. Pure git mv of whole files plus the conftest split (proposed)
  • Where does a file that tests several packages go?: To the package owning most of what it tests (proposed)
  • Which directories may hold tests outside the mirror?: Only tests/invariants/ for tests whose subject is a committed repo file (proposed)
  • Do invariant files take their subject names here?: No. The move renames nothing (proposed)
  • Where do shared fixtures go?: tests/support/ registered once from the root conftest (proposed)
  • What about paths to moved files cited outside tests/?: Live docs, comments and strings that cite a moved file get path-only substitutions in a separate commit of this PR (proposed)

Open questions

Fit

Needs splitting into 3 items:

  1. Split the root conftest.py into package-specific conftest.py files
  2. Move test files to their mirrored package directories
  3. Update layout ratchet in tests/invariants/test_source_tree.py

Suspected block

None.

Dependencies

None.

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

Activity

  1. added
    type/test
    scope/cli
    priority/p2-medium
    scope/ci
    on Oct 7, 2026
  2. 9 remaining items

  3. added a commit that references this issue on Oct 20, 2026
  4. 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: P1-High. Improving test organization and infrastructure is critical for maintainability and developer experience.
    • Value: High. Better organized tests improve findability, reduce confusion, and make refactoring easier for developers.
    • Effort: High. Moving 447 files and restructuring the conftest requires significant coordination and testing.
    • Related: test(cli): tests double only process edges and mirror the source tree #1307, which asks for a different change. Both items aim to reorganize tests but #1307 focuses on mirroring the source tree and using edge fakes, while this candidate focuses on directory placement and conftest cleanup.
  5. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at 48c78ca until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

  6. added
    priority/p1-high
    status/new
    effort/high
    value/high
    and removed
    priority/p2-medium
    on Oct 28, 2026
  7. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Tool: none found

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

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

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions