Repository navigation
Closed
Labels
priority/p2-mediumPriority P2: standard workscope/cliCore CLI framework, Typer subcommands, options, and tablestype/testType test: a new or changed test
Milestone
Description
Context & Rationale
test_no_circular_imports_in_decoupled_subsystems (tests/test_architectural_invariants.py:282-347) runs a hand-written Tarjan algorithm over 4 roots. Its ast.walk (:275) counts function-local and TYPE_CHECKING imports as edges.
Findings from a stdlib probe:
- With module-level, non-TYPE_CHECKING imports and submodule-only resolution, the tree has no cycle.
- Counting every import gives a strongly connected component of 105 modules.
- Naive package-plus-submodule edges report a false
ai.client<->ai.client.unifiedcycle (ai/client/unified.py:16).
The interface layering is prose only (ARCHITECTURE.md:11-50, AGENTS.md:377). ai/mcp/server.py:2844 already imports the private _load_local_contracts from commands/ai_ingest.py:114; that function has 3 callers.
docs/ROADMAP.md:1040 part (2) plans this. :1043 rejects import-linter and pylint R0401.
Scope & Deliverables
- Deliverable:
src/devops_cli/core/import_graph.py(stdlibastonly) builds module-level, non-TYPE_CHECKING edges.from pkg import nameresolves to the submodule whennameis a submodule, and to the package otherwise.- A cycle rule built on
graphlib.TopologicalSorter(graph).prepare(). TheCycleErrormessage names the cycle. - An interface-layer rule: no module outside
devops_cli.commands.*anddevops_cli.mainimportsdevops_cli.commands, at any scope. - Both rules run inside the one whole-tree test that refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773 leaves, which parses
srconce. Delete the Tarjan test and its helper. - Move
_load_local_contractsbelow the command layer, not intomodels/, and update its 3 callers. - Failure messages give file:line, the rule and the fix. The docstring states that string-based lazy imports are invisible to the graph.
- Acceptance criteria:
- Both rules pass on the tree.
- Fixtures:
- a package
__init__doingfrom . import sub, wheresubdoesfrom pkg import name, reports no cycle; - top-level mutual imports fail, naming both modules;
- mutual imports only inside function bodies or under TYPE_CHECKING add no cycle;
- a function-local import of
devops_cli.commands.xoutside commands fails with file:line.
- a package
- No change to
pyproject.tomloruv.lock. - In
--durations, the combined whole-tree test is no slower than the Tarjan test and refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773's remaining scan were together, recorded in the task file.
- Key questions:
- Does
core/cli.py:136, which importsdevops_cli.main, count as a violation? (proposed) No. Only the commands rule is stated. - What happens to the vulture step in
ROADMAP.md:1040? (proposed) It is dropped, and the task file records that.
- Does
- Constraint: Add a layer rule only when an ADR or ARCHITECTURE.md states it.
Strategic Alignment
- Milestone: Backlog
- Depends on: refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773
Metadata
Metadata
Assignees
Labels
priority/p2-mediumPriority P2: standard workscope/cliCore CLI framework, Typer subcommands, options, and tablestype/testType test: a new or changed test
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 14, 2026
Moved to v0.2.36: v0.2.36 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
test(cli): whole-tree import-cycle and interface-layer invariants (#848…
dan-petty commentedon Oct 16, 2026
What changed
#1592, merged into
release/v0.2.36as df9efa3.15 file(s) changed.
How it was verified
Check runs at 2b4e2f5:
Acceptance Criteria of
docs/agent/tasks/task-848-whole-tree-import-cycle-invariants.md:No Acceptance Criteria section.
feat(release): v0.2.36 (#1615)