Skip to content

refactor(ci): record keep-port decision #2600

Closed

Description

@dan-petty

Problem or Motivation

Decision 4 on #1876 (owner, 2026-10-22): a separate item covers the hand-written McCabe port mccabe_complexity in src/devops_cli/core/code_metrics.py. After #1876 the module measures complexity only (119 lines). Ruff's C901 already enforces the same count in ruff check at 10 (#586), and tests/test_code_metrics.py keeps the port equal to Ruff on 12 samples. Two product paths still read the port: devops scan complexity (security/complexity.py) and the inspection hotspots (ai/inspection.py).

Proposed Solution & Architectural Design

  • Decide whether the two readers take the complexity figure from Ruff, or whether the port stays with a stated reason.
  • Ruff is a dev dependency only (pyproject.toml), and C901 reports only the functions above max-complexity. A figure for every function needs ruff check --select C901 --config 'lint.mccabe.max-complexity=0' --output-format json, run as a subprocess from product code, or Ruff as a runtime dependency.
  • Record the cost of each option (a runtime dependency, a subprocess per scan, or keeping about 90 lines and their 12-sample test) and the choice.

Target Subsystem

core/code_metrics.py, security/complexity.py, ai/inspection.py.

Existing Tool Considered

Ruff C901 (standard McCabe, the same count). The item decides whether devops-cli reads it at run time.

Acceptance criteria

  • The two readers get their complexity from one source that matches ruff check --select C901, and a test holds it.
  • If the port goes, core/code_metrics.py and its samples go with it.

Proposed design

Problem statement

The two product paths that report function complexity, devops scan complexity and the inspection hotspots, read a hand-written McCabe port in core/code_metrics.py. Ruff's C901 enforces the same count in CI. This item decides whether the two readers take the figure from Ruff at run time, or whether the port stays with a stated reason.

Acceptance criteria

Requirement: single-source complexity

The two readers SHALL get their complexity figure from one source that matches ruff check --select C901, and a test SHALL hold that match.

Scenario: port matches ruff

  • WHEN the 12 parametrized samples in tests/test_code_metrics.py run
  • THEN each measured value equals the value that ruff check --select C901 with max-complexity = 0 reports for the same function

Requirement: port removal is complete

If the port is removed, core/code_metrics.py and its test samples SHALL be removed with it.

Scenario: port removed

  • WHEN the decision is to read from Ruff at run time
  • THEN src/devops_cli/core/code_metrics.py and tests/test_code_metrics.py do not exist

Existing Tool Considered

Ruff C901 computes the same standard McCabe count. It lacks a structured field for the complexity number in its JSON output. The number is in the diagnostic message string. Ruff is a dev dependency, not a runtime dependency. The port costs about 90 lines of Python and 12 test samples to build, keep and fix.

Key questions

  • Should the two readers read complexity from Ruff at run time, or keep the hand-written port?: Keep the port. Ruff is a dev dependency, not a runtime dependency. Its JSON output has no structured field for the complexity number. The port is 90 lines of pure Python with no external dependencies, tested to match Ruff's C901 on 12 samples. (best practice) [sources: pyproject.toml, src/devops_cli/core/code_metrics.py, tests/test_code_metrics.py]
    • Chosen: Keep the port. Ruff is a dev dependency. Its JSON output has no structured complexity field. The port is 90 lines of pure Python, no external dependencies, tested to match Ruff.
    • Rejected: Ruff as subprocess. Ruff is not a runtime dependency. Its JSON output embeds the number in a message string. A subprocess per scan adds latency and a binary dependency.
    • Rejected: Ruff as runtime dependency. Adding a Rust binary as a runtime dependency of a CLI tool is a supply-chain and size cost for a metric that 90 lines of pure Python already compute.
  • What is the written cost of keeping the port?: About 90 lines of Python in src/devops_cli/core/code_metrics.py and 12 parametrized test samples in tests/test_code_metrics.py. [sources: src/devops_cli/core/code_metrics.py, tests/test_code_metrics.py]
  • Is Ruff a runtime dependency of devops-cli?: No. Ruff is in the [dependency-groups] dev list in pyproject.toml, not in [project] dependencies. [sources: pyproject.toml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    status/new
    value/medium
    effort/medium
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/refactor. The candidate refactors how two product paths obtain their complexity figure, either replacing or retaining a hand-written port.
    • Priority: P2-Medium. It is a maintainability decision with no user-facing urgency or blocking impact.
    • Value: Medium. It removes or justifies a 90-line duplicate of Ruff C901 logic in product code.
    • Effort: Medium. The decision is small, but switching to Ruff requires a subprocess call or a runtime dependency change.
    • Related: refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773, which asks for a different change. Both touch security/complexity.py and the complexity metric, but #773 unifies the nesting metric implementation while the candidate decides whether to replace the McCabe port with Ruff C901 as the runtime source.
  3. added
    priority/p2-medium
    on Oct 29, 2026
  4. added
    scope/ci
    on Oct 30, 2026
  5. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

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

  7. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch refactor/2600-devops-scan-complexity-and-the-inspection, draft pull request #3070. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Record the keep-port decision and verify the test: 2403 tokens
  8. added 3 commits that reference this issue on Nov 1, 2026
  9. added
    status/planned
    and removed
    status/ready
    on Nov 1, 2026
  10. changed the title [-]refactor(ci): devops scan complexity and the inspection hotspots read Ruff's C901 count, or keep the McCabe port with a stated reason[/-] [+]refactor(ci): record keep-port decision[/+] on Nov 6, 2026
  11. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

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

    • Before: refactor(ci): devops scan complexity and the inspection hotspots read Ruff's C901 count, or keep the McCabe port with a stated reason
    • After: refactor(ci): record keep-port decision
    • Source of the summary: the title of plan pull request docs(openspec): plan #2600 record keep-port decision #3070
  12. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 6, 2026
  13. removed
    status/in-review
    owner/agent
    on Nov 6, 2026
  14. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 19:47 UTC

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/cisource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions