Skip to content

feat(cli): extend the ruff rule set to the correctness families #420

Closed

Description

@dan-petty

Problem Statement

[tool.ruff.lint] select (pyproject.toml:93) is E, F, I, N, W, UP plus four single codes: B017, RUF022, RUF043 and RUF068. The comment at pyproject.toml:88-92 leaves the rest of RUF to this item. The families that catch defects rather than style are not selected.

Measured at 9da1309 (release/v0.2.25) with the pinned ruff 0.16.8: uv run ruff check --no-cache --exit-zero --extend-select B,SIM,RUF,BLE,ASYNC,PT011,PT015,PT017,PGH003,B011,B015,B018 --statistics src tests reports 1,028 hits.

  • 541 are BLE001. feat(cli): blind exception handling policy #423 owns them and requires triage before enforcement.
  • 229 are SIM rewrites, 105 of them nested with blocks (SIM117). These are readability preferences. The exception is SIM115 (a file opened without a context manager), with 1 hit.
  • 9 are stale noqa codes (RUF100) under the project config: ai/gateway_bench.py:69,97,100 (S310), ai/gateway_tune.py:432 (S603), tests/test_ai_gateway_tune.py:338 (S102), tests/test_exceptions.py:172-173 (F401), tests/test_sandbox_metrics.py:229 and tests/test_sandbox_probe.py:133 (N802). feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586 plans to remove them; at 9da1309 it has not merged and they are all still present. commands/ci.py:160 (noqa: UP036) is not one of them: it is a live suppression that only a narrowed --select reports.
  • 21 are RUF001 confusable glyphs: 15 en dashes, 3 × and 3 ℹ, all deliberate. One example is the line-range regex at ai/review_schema.py:380.
  • 33 B009 and 7 B010, 35 RUF005 and 8 ASYNC109 are style or deliberate (see the ignores below).
  • The rest, 146 sites in 73 files, include real defect classes:
    • 38 raise statements inside except without from (B904), all in src. The original cause drops out of the traceback.
    • 11 zip() calls without strict= (B905): ai/review/defects.py:159,519,561, ai/review/pipeline.py:2570,2686,2845, ai/review/runner.py:1060,1080,1092, tests/test_review_page_line_numbers.py:113,131 (the two test sites are also the two RUF007 hits, and itertools.pairwise clears both rules at once). pipeline.py:2686 copies each verified finding back onto its original. Every path in _validate_segment_findings (ai/review/verification.py:2078) returns one finding per input today. If that ever changed, the zip would silently leave the remaining findings unverified.
    • 12 mutable class attributes (RUF012). WorkloadSandboxEngine._prior_samples (sandbox/engine.py:171) is one dict shared by every engine, read at :504 and written through self at :533; commands/sandbox.py builds a fresh engine at eight sites (:139,207,239,281,428,638,755,960).
    • A create_task result that is never stored (RUF006, ai/mcp/server.py:2983). The task can be garbage-collected before it finishes.
    • A Path.home() option default evaluated at import time (B008, commands/mcp.py:96), and a shared list default (B006, commands/ai.py:862, = list(_AGENT_FILES)).
    • A conditional whose two arms are identical (RUF034, github/pr_monitor.py:44).
    • 19 closures that read a loop variable (B023): 18 in the Tarjan cycle test (tests/test_architectural_invariants.py:308-375, test_no_circular_imports_in_decoupled_subsystems; the nested strongconnect starts at :343 and the hits are at :351-367) and 1 at tests/test_network_security_and_trace_correlation.py:34. Each closure runs inside its own iteration, so none misbehaves today.
    • An itertools.batched() without strict= (B911, ai/cache/valkey_cache.py:156).
    • One RUF019 (security/vault_broker.py:204) and one RUF023 (security/reference_extractor.py:336), both safe fixes.
  • The 23 duplicate __all__ entries an earlier version of this item counted are gone. RUF068 is selected now and reports 0.

Weak test assertions. PT011 finds 10 pytest.raises(ValueError) calls with no match=: tests/test_security_sandbox_and_protection.py:212,218,227,235,246, tests/test_http.py:67, tests/test_argo_fleet.py:467, tests/test_command_decorator.py:53, tests/test_consolidation_serialization.py:47, tests/test_harness.py:129. B011, B015, B018, PT015 and PT017 find 0. CONST_TEST_ASSERTION_LINT_RULES (config/constants.py:2603 at 9da1309; :2693 at 9c879ae, two commits later) pins only B017 and RUF043. The pin works through _ruff_enforces (tests/test_architectural_invariants.py:471) and test_no_test_certifies_a_failure_without_checking_it (:512-531), which reads pyproject.toml with tomllib at :523.

Blanket ignores. The Type Escape-Hatch Ratchet entry (docs/ROADMAP.md:1043, no issue) assigns its step (1) to this item: select PGH003 and turn on mypy's ignore-without-code (:1045). Both report 0 today. ruff --select PGH003 finds nothing, and uv run mypy --python-version 3.14 --strict --enable-error-code ignore-without-code src reports "Success: no issues found in 500 source files". Locking in this clean state costs nothing now.

Cost. Over three runs each at 9da1309, uv run ruff check --no-cache . took 1.50-1.64 s with today's selection and 1.54-1.89 s with the proposed one (uv start-up dominates both). Lint runs in devops ci (commands/ci.py:392-398), in the pre-commit hook (.pre-commit-config.yaml:36-41, ruff v0.16.8 with --fix) and in CI (.github/workflows/ci.yml:51). mypy reads [tool.mypy] both in devops ci (commands/ci.py:406-419) and in CI (ci.yml:57).

Drift. The knowledge-base page that agents retrieve still gives the selection as ["E", "F", "I", "N", "W", "UP"] (src/devops_cli/ai/knowledge_base/devops_cli/libraries/ruff_mypy_pytest.md:39). The only other places the string appears are quotes of this item's old description (docs/ROADMAP.md:1118, which is generated, and the task file), neither of which agents retrieve as library guidance. In the terminal, an unselected rule and a deliberately disabled rule look the same. ignore = ["E501", "N818"] (pyproject.toml:94) gives no reason for either entry.

Proposed Solution

pyproject.toml [tool.ruff.lint]

[tool.mypy]: enable_error_code = ["ignore-without-code"].

Fix the 146 remaining sites in 73 files. These are the counts at 9da1309; re-measure at start. The sites are B904 38, RUF059 31, B023 19, RUF012 12, B905 11, PT011 10, B007 7, RUF010 4, RUF015 4, RUF007 2, and one each of RUF006, B911, B008, B006, SIM115, RUF019, RUF023 and RUF034 (138 + 8 = 146; the B020 an earlier count listed has no hit at 9da1309). Fix each PT011 site against its contract, as #421 did: either a narrower exception type or an escaped match=. B911 at valkey_cache.py:156 batches keys into chunks of 500 whose last chunk is normally short, so strict=False is the contract there, with the reason in the call.

Pins in tests/test_architectural_invariants.py

Docs

  • In ruff_mypy_pytest.md:36-40, name the selected families and point to pyproject.toml as the source.
  • In the delivering commit, correct docs/agent/tasks/task-420-extend-the-ruff-rule-set-to-the-correctness-families.md (it says v0.2.25 and Backlog), record the measurements and mark it Done (tests/test_agent_task_files.py:12 accepts Backlog, Ready, In Progress, Done; :36-55 rejects a PR field and any unchecked box outside a fence).
  • Add changelog.d/420.md. Do not edit CHANGELOG.md or docs/ROADMAP.md: docs/ROADMAP.md is generated by devops roadmap render since feat(github): github-sourced roadmap, migration and generated roadmap view (devops roadmap migrate, render) #739 (banner at docs/ROADMAP.md:4), and devops pr check-readiness blocks a PR into a release branch that changes either (commands/pr.py:1648-1660, docs/agent/tasks/README.md point 5).

Constraints

Scope

One pull request: the pyproject.toml lint and mypy settings, the 146 site fixes plus the one SIM115 noqa, the 9 stale noqa removals if still present, the three pins and their tests, the knowledge-base page line, the task file and changelog.d/420.md.

Key Questions

Acceptance Criteria

Out of Scope

Dependencies

No item must be delivered before this one. The numbers below are sequencing and file overlaps.

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/cli
    priority/p1-high
    on Sep 22, 2026
  3. modified the milestones: v0.2.23, v0.2.25 on Sep 24, 2026
  4. modified the milestones: v0.2.25, v0.2.26 on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to make room for the seven P1 items left open in the shipped v0.2.23, which were committed earlier. The roadmap-job items placed in v0.2.25 stay, and this item is among the oldest of the rest.

  6. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Owner's order of 2026-10-03: #753 and #741 merge before this item (and #742 may, starting first), so the sweep covers their code. The first-merge criterion is reworded to match.

  7. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Lines cited at dcafadf.
    At 132ecc5, config/constants.py:3003-3012 is :3037-3046.

    #1107 also edits [tool.ruff.lint] select and the [tool.ruff.lint] key allowlist CONST_RUFF_LINT_KEYS (config/constants.py:3003-3012), and it lands after this item.

  8. added
    status/in-review
    on Oct 4, 2026
  9. added a commit that references this issue on Oct 4, 2026
  10. removed
    status/in-review
    on Oct 30, 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

    priority/p1-highscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions