Repository navigation
Description
Context & Rationale
The nesting and complexity metric is implemented twice with the same node sets: _ComplexityVisitor._visit_with_depth in security/complexity.py:100-136 and _measure in security/structural_invariants.py:27-45. The pre-commit hook keeps its own copy because complexity.py imports ai.review_schema.Finding, which took 8.9s to import. The gate's test stage took 5m 26s on the 9p workspace mount (2026-09-30) and 1m 42s after the workspace moved to ext4 (2026-10-01), so it is within its 5-minute budget; the per-test timings below were measured on 9p. Its slowest test, tests/test_structural_invariant_hook.py::test_the_metric_matches_the_projects_own_scanner (~38s), exists only to prove the two copies agree across the whole tree, and tests/test_architectural_invariants.py::test_no_excessive_nesting_in_src (~27s) scans the whole tree a third time.
Scope & Deliverables
- Deliverable: the metric lives once, in the lightweight module. The hook (argv and stderr) and
devops scan(results turned intoFindings) are its two adapters, the parity test is removed, and the whole tree is scanned once. - Constraint: behaviour tests stay on small fixtures (
tests/test_scan_complexity.pyand the hook's fixture tests).
Strategic Alignment
- Milestone: Backlog (no release)
- Design: none
- Depends on: none
Amendment (2026-10-01 assessment)
- Context:
- The hook counts nesting depth from 0 (
security/structural_invariants.py:53); the scanner counts from 1 (security/complexity.py:81). Five nested ifs therefore pass the hook (depth 5) and fail the scanner (depth 6). - Under the scanner's metric, 5 functions in
tests/sit at depth 6, and nothing blocks them. - The complexity counts also differ: 235 from the scanner, 230 from the hook.
- The parity test (~38 s on 9p) passes only because both report 0 nesting breaches in
src. - The hook imports
devops_cli.security, which eagerly imports every scanner (__init__.py:5-30), anddevops_cli.config.defaults.
- The hook counts nesting depth from 0 (
- Deliverable:
- The shared module's complexity follows mccabe: no +1 for assert,
withor boolean operands. - Fix the depth origin, with a boundary fixture at depths 5 and 6.
- The hook imports nothing from
devops_cli.securityordevops_cli.config. Its thresholds arrive as hook args, and a test pins those args to the defaults. - Consumers:
devops scan complexity, MCPscan_complexity,ai/inspection.py,ai/benchmark/suite.py:33, and feat(review): branch and pr reviews compute their own base-vs-head symbol delta #593 PR2's content-taking entry. - Exactly one whole-tree test remains. It parses
srconce, through one helper that the planned import-graph invariant reuses. - Decide whether that test covers
tests/.
- The shared module's complexity follows mccabe: no +1 for assert,
- Acceptance criteria:
- A fresh-subprocess hook run leaves no
devops_cli.security.*module and nopydantic_aiinsys.modules. - The set of (file, function) pairs the scanner flags at 10 equals the set ruff C901 flags.
- A function with 4 asserts inside a
withblock scores 1. - The parity test is deleted.
- The task file records the test-step
--durationsdifference, which must be negative. - No new dependency.
- A fresh-subprocess hook run leaves no
- Constraint: If hand-matching mccabe proves fiddly, delegate to ruff's JSON output instead of maintaining a third visitor.
- Depends on: feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Placed in v0.2.30 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: P1 secret and sandbox-boundary fixes, the review tools lock, kube-linter finding identity and a faster gate. Position 8 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
refactor(ci): one nesting metric module shared by the pre-commit hook…
dan-petty-bot commentedon Oct 9, 2026
What changed
#1466, merged into
release/v0.2.30as ea37ebf.22 file(s) changed.
How it was verified
Check runs at a4284a1:
Acceptance Criteria of
docs/agent/tasks/task-773-one-nesting-metric-module.md:devops_cli.securityordevops_cli.security.*module, and nopydantic_ai, insys.modules(test_the_hook_loads_no_scanner_and_no_pydantic_ai). The module's own imports are stdlib only.devops_cli.config" holds for the module's own imports only.python -m devops_cli.core.code_metricsfirst runs the package inits.devops_cli/__init__.pyimportsdevops_cli.config.metadata, and with it pydantic and thedevops_cli.configbarrel (commands,constants,defaults,envandoptions).devops_cli/core/__init__.pyimportscore.cli, and with it typer and 16devops_cli.exceptionsmodules. A hook run loads 269 modules, and took 0.43 s against 0.07 s for an interpreter importing only the module's stdlib imports (medians of 5, load average about 12). refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 removes the config barrel. Makingdevops_cli/__init__.pyanddevops_cli/core/__init__.pylazy is outside this item: moved to a follow-up issue, not yet filed.C901flags: 54/54 insrc/, 0/0 intests/. Withruff check --ignore-noqa --select C901 --config lint.mccabe.max-complexity=0(ruff 0.16.8), all 18,000 functions in the trackedsrc/andtests/files on this branch get the same value from both, with no key or value difference. Without charging closures to the function that defines them,src/would give 48. The six it would miss areai/ext_langchain.py:24and, inai/harness/,agents.py:377,memory.py:629,planning.py:440,shell.py:371andworkflow.py:262.withscores 1.test_complexity_is_ruffs_c901_countholds 12 fixtures, each value read once from Ruff and hard-coded.test_the_function_body_is_depth_one). On all 18,000 functions, the new depth equals the old hook depth plus 1.tests/test_structural_invariant_hook.py. Its fixture tests now run in-process throughmain([...])intests/test_code_metrics.py.test_the_source_tree_keeps_its_structural_invariants, which parsessrc/devops_clionce through_parse_src().--durationsdifference is negative. Each pair below was run back to back with-n 0, on the exported base (edd2578) and then on this branch:test_no_excessive_nesting_in_src5.3 s.test_the_source_tree_keeps_its_structural_invariantstook 4.7 s and the import-check subprocess 0.3 s.src/. The saving comes from deleting the parity test and the three hook subprocess spawns.python -m, withoutuv run's own start-up) takes 0.58 s instead of 8.45 s, the medians of 5 interleaved runs each at a load average of about 18. At a load of about 5 it was 0.2 s against 3.0 s.pyproject.tomlanduv.lockare untouched.changelog.d/773.mdexists, andCHANGELOG.mdanddocs/ROADMAP.mdare untouched.feat(release): v0.2.30 (#1473)