Repository navigation
Closed as not planned
Labels
effort/mediumEffort Mediumpriority/p1-highPriority P1: high-impact work for the next planned milestonescope/cliCore CLI framework, Typer subcommands, options, and tablestype/testType test: a new or changed testvalue/highValue High: the delivery of the item matters much
Description
Problem
Nothing stops new tests from adding the coupling that #1307 retires. Counted at 36cfbbb by a static AST pass over every .py under tests/: test modules, conftest.py and the helper modules [measured: 2026-10-07; two independent passes gave 2,777 and 2,771 internal patch sites].
- Internal patch sites: about 2,770.
- Nearly all of them, in about 260 files, are patch calls (
patch,patch.object,patch.dict,patch.multiple,mocker.patch,monkeypatch.setattr/setitem/delattr) whose target resolves to an object defined in devops-cli. - Eight or nine, in three or four files, are direct assignments to devops-cli attributes, such as the console singletons [code: tests/conftest.py:268-269],
QdrantClient.__init__[code: tests/conftest.py:519] andALLOW_MODEL_REQUESTS[code: tests/test_ai_agent_capabilities.py:660, :663]. - The floor's own patches are included, for example
_own_source_dir[code: tests/conftest.py:321],_github_token[code: :357] andCONFIG_PATH[code: :473]. So are the shared fake's patches of privateLLMClientmethods [code: tests/llm_stream_fakes.py:120, :123]. - The census, matching names in test modules only, counted 2,770.
- Nearly all of them, in about 260 files, are patch calls (
- Private-name imports: 937 in 210 files. About 90 more private names are read as attributes of imported devops-cli modules or classes, in some 35 files.
- Test accommodations in src: 9 sites.
unittest.mockimports [code: security/base.py:17; ai/review/pipeline.py:711];PYTEST_CURRENT_TEST[code: commands/ci.py:253, :257; core/process.py:93];- mock attributes probed by name:
assert_called[code: ai/mcp/server.py:88] and_mock_return_value[code: sandbox/host.py:93]; - patch detection by comparing
__module__with"subprocess"[code: core/process.py:545; sandbox/host.py:91].
- A precedent exists.
test_c901_suppressions_stay_under_the_ceiling[code: tests/test_architectural_invariants.py:1327] holds the C901 markers under one ceiling. When it fails, it names files, not lines.
Acceptance criteria
What is counted. AST only; no test module is imported.
- Internal patch sites in every
.pyundertests/. A site is a patch call whose target resolves statically to an object defined in devops-cli, or an assignment to or deletion of an attribute of a devops-cli module or class. These are not counted:- a stdlib or third-party object reached through a devops-cli module, such as
patch("devops_cli.core.process.subprocess.run"), which is an edge patch; - a patch of a local object;
patch.dict(os.environ, ...).
- a stdlib or third-party object reached through a devops-cli module, such as
- Private-name imports in every
.pyundertests/: a name with one leading underscore imported from devops-cli. - Test accommodations in
src/devops_cli, of four kinds:- an import of
unittestorunittest.mock; - the string
PYTEST_CURRENT_TEST; - an attribute, or an attribute-name string, from
unittest.mock.NonCallableMockthat starts withassert_or_mock_, taken from the class rather than a hand-kept list; - a comparison of a
__module__value, read as an attribute or throughgetattr(..., "__module__"), with a name insys.stdlib_module_names.
- an import of
Ceilings
- Each ratchet's ceiling is today's count, stored per file. The PR records the totals its check measures at its base; the counts above give about 2,770, 937 and 9 at 36cfbbb.
- A file over its ceiling fails. The message lists every counted site in that file as
path:linewith its target, and says to remove the new site rather than raise the ceiling. - A file under its ceiling fails until the ceiling is lowered to its count, so a removed site cannot come back later. The message names the command that lowers the file's rows to the measured counts, so a PR outside test(cli): tests double only process edges and mirror the source tree #1307 that removes a site knows what to run. That command lowers and deletes rows but never raises or adds one.
- A file without an entry has a ceiling of 0.
Tests of the checks. Fixture trees under tmp_path, each test under 1 s.
- One fixture per counted form is counted, with its
path:line: a string target,patch.objectthrough an imported module, a direct assignment, and a private import. - An edge patch through a devops-cli module,
patch.objecton a local object,patch.dict(os.environ, ...)and a public import are not counted. - Each accommodation kind is counted in a fixture
src/tree, thegetattr(..., "__module__")form included. A__module__read that is not compared with a stdlib name, as inai/library/introspector.py:74, is not counted. - The three ratchets parse each file once per run and add at most 3 s to the summed test time, as recorded by
--durations. - The layout ratchet is not added here; it lands with the move (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).
-
uv run devops cipasses.
Key questions
- Which ratchets? Decided 2026-10-07: patches aimed at devops-cli internals and imports of private names from devops-cli. Also an invariant that bans
unittest.mock,PYTEST_CURRENT_TESTand mock-attribute checks in src, as a ratchet at today's count that reaches zero. The layout ratchet comes with the move. - Do the floor's own patches count? Decided 2026-10-07: yes. Conftest's
_github_token,_own_source_dirand_CONSOLEcount toward the ratchet. - Where do the checks live? Decided 2026-10-07: invariant tests live in
tests/invariants/, in files named by subject, and the source tree's file istest_source_tree.py. (proposed) This item createstests/invariants/test_source_tree.pynow, so 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 does not move it. It finds the repository root through pytest's rootdir rather than__file__depth, so 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 has nothing to change in it. The source-tree invariant files that 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 moves intotests/invariants/under their current names,tests/test_architectural_invariants.pyamong them, are merged into this file by test(cli): Convert ratchets to bans and merge invariant tests #1336, which owns that consolidation; this item does not move them. - Per-file or total ceilings? (proposed) Per file, in one table next to the test, sorted by path. The failure can then name the file and its lines, and items working in parallel edit different rows. A PR that moves a counted file moves its row with it; 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 re-keys the whole table as a mechanical rewrite from its move list.
- How are rows lowered? (proposed) By one command beside the table that recounts and rewrites it. It writes only rows whose count fell, deletes rows that reach 0, and exits non-zero without writing when any count rose. The under-ceiling message prints that command in full.
- Private names read as
module._name? (proposed) Count them in the private-import ratchet as well; that adds about 90 reads. Otherwise a test evades the ratchet by importing the module instead of the name. - Structural accommodations:
_K8sModuleforwarding,_LAZY_OBJECT_MAPPING,# noqa: F401patch-target re-imports, the settings cache keyed onCONFIG_PATH? (proposed) Not counted, because no single syntactic form covers them. Each package item deletes its own, and they have no reason to come back once the patches they serve are gone.
Strategic alignment
- Depends on: none. Blocks: test(cli): Convert ratchets to bans and merge invariant tests #1336. Related: test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 and fix(ci): tests touch no state outside their temporary directories #1311 (they remove some of the floor's counted patches), 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 (moves helper modules, whose rows move with them), 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 (the layout ratchet and the table re-key), refactor(cli): Unify HTTP and DNS seams with shared fakes #1314–refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320, refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(github): the github session owns transport, ledger, error classes and link pagination #983, refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001, feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 and test(github): github/ is tested through its public interface over the gh process and session fakes, with no internal patches or private imports #1321–test(infra): infrastructure tests run on edge fakes #1335 (each lowers the ceilings for the sites it removes once this item has landed), test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 (the AST check for opaque tuple asserts), test(cli): suppression comments may not grow unnoticed #849 (suppression comments may not grow).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase A).
Proposed design
Problem statement
Tests add internal patch sites, private imports and test accommodations that break test isolation. A ratchet prevents new ones from being added.
Acceptance criteria
- Criterion 1: Internal patch sites in test modules are counted by static AST analysis.
Verification: Run AST check on test files. Count patch calls to devops-cli objects and direct assignments to devops-cli attributes. - Criterion 2: Private-name imports from devops-cli are counted in test modules.
Verification: Run AST check on test files. Count names with leading underscore imported from devops-cli. - Criterion 3: Test accommodations in src code are counted by static AST analysis.
Verification: Run AST check on source files. Count unittest.mock imports, PYTEST_CURRENT_TEST strings, mock attribute checks and module comparisons. - Criterion 4: Each ratchet's ceiling is set to today's count for that file.
Verification: Check test results show file-specific ceilings. Command records current counts at PR base commit. - Criterion 5: A file over its ceiling fails with list of counted sites.
Verification: Run tests on a file with new patch site. Fail and show path:line for each counted site. - Criterion 6: A file under its ceiling fails until ceiling is lowered to count.
Verification: Run tests on a file that removes a site. Show command to lower the file's rows to measured counts.
Key questions
- Which ratchets?: Patches aimed at devops-cli internals, imports of private names from devops-cli, and invariant that bans unittest.mock, PYTEST_CURRENT_TEST and mock-attribute checks in src. (proposed)
- Do the floor's own patches count?: Yes. Conftest's _github_token, _own_source_dir and _CONSOLE count toward the ratchet. (proposed)
- Where do the checks live?: Invariant tests live in tests/invariants/, in files named by subject, and the source tree's file is test_source_tree.py. (proposed)
- Per-file or total ceilings?: Per file, in one table next to the test, sorted by path. (proposed)
- How are rows lowered?: By one command beside the table that recounts and rewrites it. It writes only rows whose count fell, deletes rows that reach 0, and exits non-zero without writing when any count rose. (proposed)
- Private names read as module._name?: Count them in the private-import ratchet as well; that adds about 90 reads. (proposed)
- Structural accommodations: _K8sModule forwarding, _LAZY_OBJECT_MAPPING, # noqa: F401 patch-target re-imports, the settings cache keyed on CONFIG_PATH?: Not counted, because no single syntactic form covers them. Each package item deletes its own, and they have no reason to come back once the patches they serve are gone. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
effort/mediumEffort Mediumpriority/p1-highPriority P1: high-impact work for the next planned milestonescope/cliCore CLI framework, Typer subcommands, options, and tablestype/testType test: a new or changed testvalue/highValue High: the delivery of the item matters much
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 8, 2026
Linked: #1347. Both add per-file ceiling tables with a lowering command, so they share one mechanism. Found by the 2026-10-08 backlog review.
dan-petty-bot commentedon Oct 8, 2026
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.
It is a guardrail preventing regression of the coupling #1307 retires, but it does not block a user-facing feature or fix a defect.Without the ratchets, new tests can silently re-introduce the internal coupling that the #1307 work stream is eliminating.Requires a static AST pass over all test files, per-file ceiling storage, failure messages naming each site, and a lowering command, but no runtime behaviour change.dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The change addresses test isolation and prevents regressions in the test suite.This change improves test reliability and maintainability for the project.Implementing ratchets requires significant development effort in both the tooling and test checks.ratchets that hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise oneas the change that both ask for.Both items ask for ratchets to track internal patches, private imports and test accommodations in src at today's counts.A person closes one of the two if that is so.dan-petty commentedon Oct 26, 2026
Status set to Ready at 48c78ca (see proposed design in issue body).
dan-petty commentedon Oct 28, 2026
Closed as not planned. The item conflicts with a more recent project direction. No code was written.
This item builds three new ratchets, each with a per-file ceiling table, a lowering command and an AST counter. Its first comment says it shares one mechanism with #1347, the swallowed-failures ratchet. Three owner decisions that are newer than this item go against that mechanism:
The per-file tables of this item are edited by every child of #1307 that removes a site (#1310 to #1335, #2167). That is the concurrent-rebase friction that decision 3 names.
docs/TESTING.mdstill lists these ratchets as a target, because the item that was to reword it (#423) was cancelled.Measured on origin/main (2026-10-28), the counts are still large, so a ban at zero is not possible for two of the three checks:
tests/: about 2,770 sites at 36cfbbb (the item's count). The children of test(cli): tests double only process edges and mirror the source tree #1307 remove them package by package.tests/: 937 at 36cfbbb. Ruff hasPLC2701(import-private-name), but in Ruff 0.16.8 it is a preview rule.src/devops_cli: 9 sites, the same total as the item, at different lines:unittest.mockimports:security/base.py:18,ai/review/pipeline.py:657;PYTEST_CURRENT_TEST:commands/ci.py:418,:422,core/process.py:109;sandbox/host.py:101(_mock_return_value);__module__compared with"subprocess":core/process.py:670,:1080,sandbox/host.py:99.The third check fits the newer direction: with only 9 sites, the sites can be removed and a tool can ban the forms at zero, with no baseline. Ruff's
banned-api(TID251) is already configured inpyproject.toml, and the repository already runs ast-grep rules with rule tests. A new item carries that part.#1336 ("the test ratchets become bans") names this item as its input. A person decides its scope.
dan-petty commentedon Oct 28, 2026
The part that fits the newer direction is now #2512: the 9 test accommodations in
src/are removed, and Ruffbanned-apiand ast-grep rules ban them at zero, with no baseline.docs(openspec): plan #2166 Remove dead imports and add F401 ratchet (#…