Skip to content

test(cli): Convert ratchets to bans and merge invariant tests #1336

Closed

Description

@dan-petty

Problem

Phase F of #1307. #1309 and #1313 add ratchets: counts held under a ceiling that may only go down, in the style of test_c901_suppressions_stay_under_the_ceiling [code: tests/test_architectural_invariants.py:1327], whose ceiling is a constant [code: config/defaults.py:712]. The ratcheted counts and their values:

#1321–#1335 bring each count to zero. A ratchet at zero still has a ceiling that a later PR can raise. ADR 0005 rejected exceptions with a stated reason, so these rules become bans.

Two rules have no check yet:

  • test(cli): tests double only process edges and mirror the source tree #1307's exit requires a contract suite for every fake under tests/support/fakes/ (Q26), but no test fails when a fake lacks one.
  • The layout rule counts only test_*.py. Nine helper modules sit at the top of tests/ today beside conftest.py and __init__.py, among them cluster_secret_fakes.py, llm_stream_fakes.py and web_fakes.py [measured: file survey at 5c45b1e], and a dead one could outlive the move.

tests/invariants/ has no other owner. Q13 names the files there by subject: test_source_tree.py, test_agents_md.py, test_task_files.py, test_workflows.py, test_k8s_manifests.py and test_grafana_dashboards.py. #1313 moves the invariant files there under their current names, and no E item merges them. At today's names the invariant files are test_architectural_invariants.py, test_codebase_hygiene_and_shims.py, test_public_export_surface.py, test_cli_startup_imports.py, test_agents_md_claims.py, test_agent_task_files.py, test_workflow_contracts.py, test_docs_routine_tasks.py, test_docs_review_loop.py, test_isolation_tripwire.py, test_third_party_telemetry.py, test_all_commands_help_dryrun.py, test_grafana_dashboards.py, test_stack_dashboards.py and the test_k8s_* files whose subject is the YAML under k8s/ [measured: file survey at 5c45b1e]. #1322, #1323 and #1325 append their committed-file cases to the subject files, and #1324 adds test_pull_request_template.py for .github/pull_request_template.md.

  • They hold no patch site, but four of them import a private name: _MANIFESTS_BY_STACK [code: tests/test_architectural_invariants.py:1379], _is_indexable_file [code: tests/test_codebase_hygiene_and_shims.py:16] and _COMMAND_SPECS [code: tests/test_all_commands_help_dryrun.py:95; tests/test_grafana_dashboards.py:677]. test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323 removes the private imports of the four k8s/ manifest files it names.
  • Two keep a module-level runner = CliRunner() [code: tests/test_all_commands_help_dryrun.py:76; tests/test_grafana_dashboards.py:26].
  • Not every case in them is about a committed file. test_all_commands_help_dryrun.py runs every command with --help and --dry-run, test_grafana_dashboards.py also tests the grafana/ builders and the devops grafana command, and test_codebase_hygiene_and_shims.py also tests the RAG indexer, the harness shell and the review's hallucination catalog.

AGENTS.md also carries test rules of its own:

  • the tuple-assert mandate [code: AGENTS.md:15-16];
  • "structural tuple equality assertions" [code: AGENTS.md:103];
  • the flat tests/test_<submodule>.py layout [code: AGENTS.md:158-161];
  • isolation "using mocks (unittest.mock, pytest-mock)" [code: AGENTS.md:434];
  • mock provider protocols [code: AGENTS.md:444];
  • __test__ = False helper classes in src [code: AGENTS.md:446].

#1308 replaces them with a pointer to docs/TESTING.md, but nothing stops them coming back.

Acceptance criteria

Bans

tests/invariants/ holds subject files only (Q13)

Test rules live in one place (Q5)

  • AGENTS.md states no test rule of its own. Its testing guidance is a link to docs/TESTING.md and ADR 0005.
  • tests/invariants/test_agents_md.py fails if AGENTS.md again carries a retired rule. It checks, ignoring case, for these phrases:
    • "tuple equality";
    • "using mocks (unittest.mock, pytest-mock)";
    • tests/test_<submodule>.py;
    • BaseLLMProvider;
    • __test__ = False.
  • docs/TESTING.md describes these rules as bans and lists the subject files of tests/invariants/. Its Ratchet entry remains for counts still being retired elsewhere, such as C901 suppressions.

Close-out

  • uv run devops ci passes.

Key questions

Strategic alignment

Alternatives check of 2026-11-01: not-applicable.
Tool: none found.

Proposed design

Problem statement

Phase F of #1307 turns the ratchets of #1309 and #1313 into bans. A ratchet holds a count under a ceiling that a later pull request can raise, and ADR 0005 rejects exceptions. The invariant files also sit under their old names in tests/invariants/, and AGENTS.md can again carry test rules that docs/TESTING.md owns. This item makes each retired count a ban with no ceiling, merges the invariant files into subject files, and leaves the test rules in one document. The contract-suite ban is deferred, because the Valkey fake has no contract suite. The item cannot merge while a dependency leaves a count above zero.

Acceptance criteria

Requirement: Patch ban on devops_cli internals

An invariant test in tests/invariants/test_source_tree.py SHALL assert that no test module patches a module, class, function or attribute of devops_cli.

Scenario: A patch of a devops_cli name fails the ban

  • WHEN A test module under tmp_path patches a name of devops_cli
  • THEN The ban fails and names the path:line of the patch

Requirement: Private import ban

The invariant test SHALL assert that no module under tests/ imports a name that starts with an underscore from devops_cli.

Scenario: A private import fails the ban

  • WHEN A module under tmp_path imports a private name from devops_cli
  • THEN The ban fails and names the path:line of the import

Requirement: Test accommodation ban in src

The invariant test MUST assert that src/ holds no unittest.mock import, no PYTEST_CURRENT_TEST check, no probe of a mock attribute by name and no patch detection through module.

Scenario: Each of the four kinds fails the ban

  • WHEN A module under tmp_path in src/ holds one of the four kinds
  • THEN The ban fails and names the path:line and the kind

Requirement: Test layout ban

The invariant test SHALL assert that every test_*.py file sits in a directory that mirrors a package of src/devops_cli or in tests/invariants/, with no layout ceiling constant.

Scenario: A test file outside the layout fails the ban

  • WHEN A test_*.py file sits in a directory that mirrors no package of src/devops_cli
  • THEN The ban fails and names the path

Requirement: Module-level CliRunner ban

The invariant test SHALL assert that no test module binds a CliRunner(...) at module level.

Scenario: A module-level CliRunner fails the ban

  • WHEN A test module under tmp_path binds runner = CliRunner() at module level
  • THEN The ban fails and names the path:line

Requirement: Unreachable marker ban

The invariant test MUST assert that src/ holds no call of the interim unreachable( marker, if #1310 added one.

Scenario: A remaining unreachable call fails the ban

  • WHEN A module under tmp_path in src/ calls unreachable(
  • THEN The ban fails and names the path:line

Requirement: Ceilings deleted

The change SHALL delete every ceiling constant of the converted counts from tests/ and src/, among them CONST_ROOT_TESTS_CEILING and CONST_NON_MIRROR_TEST_CEILING.

Scenario: No ceiling remains for a converted count

  • WHEN A search runs over src/ and tests/ for the ceiling constants of the converted counts
  • THEN The search finds no match

Requirement: Ban message names the rule

A ban failure SHALL name each offending path:line and the section of docs/TESTING.md that states the rule.

Scenario: A seeded violation reports its section

  • WHEN A seeded violation makes a ban fail
  • THEN The message holds the path:line and the heading of the docs/TESTING.md section

Requirement: Each ban proves that it fires

Each ban SHALL have a test that seeds one violation under tmp_path and asserts that the ban fails.

Scenario: A seeded violation fires its ban

  • WHEN The seed test of a ban places one violation under tmp_path
  • THEN The ban returns a failure that names the seeded path

Requirement: Stdlib patch and seam install stay allowed

The bans MUST pass a test that patches a stdlib edge object and a test that installs a fake through a seam fixture or a constructor.

Scenario: A stdlib patch and a seam install pass the bans

  • WHEN One test patches subprocess.run and another installs git_fake through its fixture
  • THEN No ban fails

Requirement: Reset and cache invariant becomes a ban

The change SHALL turn each reset or cache invariant that #1310 introduced with a ceiling into a ban with no ceiling.

Scenario: The reset invariant reads no ceiling

  • WHEN The invariant test for module-level caches and globals runs
  • THEN It asserts zero sites without a public reset and reads no ceiling constant

Requirement: Files directly in tests/ are banned

The invariant test SHALL fail on any .py file directly in tests/ other than conftest.py and init.py, and each helper that a test imports SHALL live in tests/support/.

Scenario: A helper directly in tests/ fails the ban

  • WHEN A file tests/helper.py exists
  • THEN The ban fails and names tests/helper.py

Requirement: Moved invariant files merge into subject files

The change SHALL merge each file that #1313 moved into tests/invariants/ into the subject file for what it checks, and SHALL remove the old file name.

Scenario: The old names are gone and the test names stay

  • WHEN The files of tests/invariants/ are listed and the merged cases are collected
  • THEN Only the subject files that docs/TESTING.md lists remain and each merged test keeps its name

Requirement: Cases about behaviour move to their package

The change SHALL move each case whose subject is not a committed file to the test package that owns the behaviour, and SHALL test it through the public interface of that package.

Scenario: The command, builder and indexer cases move to their packages

  • WHEN The suite is collected after the move
  • THEN tests/commands/ holds the --help and --dry-run cases, tests/grafana/ and tests/commands/ hold the Grafana cases, and tests/ai/rag/ holds the indexer case

Requirement: Invariant files import only public names

No file in tests/invariants/ SHALL import a private devops_cli name or bind a CliRunner(...) at module level.

Scenario: A search finds no private import in tests/invariants

  • WHEN A search runs over tests/invariants/ for private imports from devops_cli and for module-level CliRunner(
  • THEN The search finds no match

Requirement: Unlisted invariant file name fails the ban

The invariant test SHALL fail on any test_*.py in tests/invariants/ whose name is not in the subject file list of docs/TESTING.md.

Scenario: An unlisted name fails the ban

  • WHEN A file tests/invariants/test_misc.py exists
  • THEN The ban fails and names tests/invariants/test_misc.py

Requirement: AGENTS.md holds no test rule

AGENTS.md SHALL state no test rule of its own and SHALL link docs/TESTING.md and ADR 0005 for testing guidance.

Scenario: AGENTS.md links the testing documents

  • WHEN AGENTS.md is read
  • THEN It holds no test rule, and its testing row links docs/TESTING.md and docs/adr/0005-review-findings-come-from-tools-not-models.md

Requirement: A retired rule in AGENTS.md fails the ban

tests/invariants/test_agents_md.py SHALL fail, ignoring case, when AGENTS.md holds one of the retired phrases: tuple equality, using mocks (unittest.mock, pytest-mock), tests/test_<submodule>.py, BaseLLMProvider or test = False.

Scenario: A retired phrase fails the ban

  • WHEN AGENTS.md holds the phrase tuple equality
  • THEN The ban fails and names the phrase and the line

Requirement: docs/TESTING.md states the rules as bans

docs/TESTING.md SHALL state each converted rule as a ban and SHALL list every subject file of tests/invariants/.

Scenario: The testing document names the bans and the subject files

  • WHEN docs/TESTING.md is read
  • THEN It names each converted rule as a ban, lists each subject file, and keeps the Ratchet entry for the counts still retired

Requirement: The gate passes

The change MUST pass uv run devops ci.

Scenario: The full gate passes

  • WHEN uv run devops ci runs on the branch
  • THEN It exits 0

Existing Tool Considered

The alternatives check of 2026-11-01 is not-applicable and names no tool. No open, maintained tool or library covers this need, because the bans check the own test tree, import graph and committed documents of the repository. The change builds its own invariant tests with the ast module and pytest, as the existing ratchets do. Cost: about 80,000 tokens to build them, about 10,000 tokens a month to keep and fix them, and about 2 days of elapsed work.

Key questions

  • Which rules become bans, and do the bans forbid all patching?: Each retired count becomes a ban. The bans forbid patches aimed at devops_cli internals and imports of private devops_cli names. Patching a stdlib or SDK object stays the fallback for a stdlib edge, and a fake installed through a seam is no patch. (best practice) [sources: docs/TESTING.md, docs/adr/0005-review-findings-come-from-tools-not-models.md]
    • Rejected: Ban all patching. docs/TESTING.md keeps the stdlib patch as the fallback for stdlib edges, and contract suites use it.
    • Chosen: Ban internal patches and private imports only. This matches the counts that the ratchets held, and ADR 0005 rejects an exception list.
  • Where do the bans live?: In tests/invariants/, in the subject file of what each ban checks: test_source_tree.py for src and tests, test_agents_md.py for AGENTS.md. (best practice) [sources: docs/TESTING.md, tests/invariants/test_source_tree.py]
    • Chosen: Subject files in tests/invariants/. docs/TESTING.md names tests/invariants/ as the only place outside the mirror.
    • Rejected: A flat file in tests/. The layout ban forbids a .py file directly in tests/.
  • How does the ban know the allowed file names of tests/invariants/?: It reads the subject file list from docs/TESTING.md. Adding a subject means adding one line there. (best practice) [sources: docs/TESTING.md]
    • Chosen: Read the list from docs/TESTING.md. The document is the one owner of the rule and of the list.
    • Rejected: A second list in the ban test. Two lists drift apart.
  • How does an invariant file read the stack manifest table?: Through the public MANIFESTS_BY_STACK. The rename from the private name is done in stack_lifecycle.py, and the invariant files use the public name. [sources: src/devops_cli/commands/k8s/stack_lifecycle.py, k8s/README.md:21]
  • How does an invariant file get the list of commands?: From the public Click app through list_commands of devops_cli.main.app. No test imports _COMMAND_SPECS. (best practice) [sources: src/devops_cli/main.py]
    • Chosen: Read the commands from the public app. It needs no new public name and kee

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/test
    scope/cli
    priority/p2-medium
    scope/docs
    on Oct 7, 2026
  2. marked this as blocked by 11 issues on Oct 7, 2026
  3. 19 remaining items

  4. changed the title [-]test(cli): the test ratchets become bans, invariant tests merge into subject files, and AGENTS.md defers to TESTING.md[/-] [+]test(cli): Convert ratchets to bans and merge invariant tests[/+] on Nov 6, 2026
  5. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 107 characters, and the limit is 60. The type and the scope stay.

    • Before: test(cli): the test ratchets become bans, invariant tests merge into subject files, and AGENTS.md defers to TESTING.md
    • After: test(cli): Convert ratchets to bans and merge invariant tests
    • Source of the summary: the background model
  6. dan-petty commented on Nov 9, 2026

    @dan-petty
    OwnerAuthor

    The item cannot be built as written. Five dependencies remain open: #1329, #1330, #1333, #1335, and #3769. The test suite contains 606 internal patches of devops_cli and 434 private imports. The acceptance criteria require bans that assert zero and forbid exception lists. The item must wait until the open dependencies bring each count to zero.

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

    @devops-cli-service
    Contributor

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

  9. added
    status/in-progress
    and removed
    status/ready
    on Nov 9, 2026
  10. added a commit that references this issue on Nov 10, 2026
    69260e4
  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 10, 2026
  12. removed
    status/in-review
    on Nov 10, 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/cliscope/docstype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions