Skip to content

refactor(ci): Ruff's own flags protect the complexity cap, and the configuration-escape tests and key allowlists are deleted #1870

Closed

Description

@dan-petty

Friction

Because the policy is that a ceiling only falls and nothing may be suppressed, the complexity cap is guarded by a test suite that re-implements Ruff's configuration semantics: key allowlists, nested-config discovery, ignore files and suppression comment spellings. About 520 lines of tests and 66 lines of constants exist only to prove a ten-line configuration cannot be weakened, and a new Ruff setting is reported as a failure until a reviewed change admits it.

Evidence

  • tests/test_architectural_invariants.py: of the 990 lines from 1131 to 2120, 522 belong to the Ruff cap and the C901 ceiling (the table _COMPLEXITY_CAP_ESCAPES alone is 38 cases and 279 lines) and 396 to the ast-grep network gate. src/devops_cli/config/constants.py:4135-4200 holds the key sets and patterns, used only by those tests (13 references in constants.py, 33 in the test, none elsewhere in src/).
  • The review proposed CODEOWNERS lines as the replacement control. The verification pass found it protects nothing here: the main ruleset has require_code_owner_review: false and required_approving_review_count: 0, .github/CODEOWNERS is * @dan-petty, and a sole owner could not approve their own pull request if it were switched on. This item therefore moves the control into the tool's flags.
  • A resolved-settings assertion alone is not enough: in a scratch trial a nested ruff.toml with ignore = ["C901"] silenced a 13-complexity function while ruff check --show-settings on the top-level file still listed C901 enabled. --config pyproject.toml is reported to close that and --no-respect-gitignore closes the ignore-file escape (verification pass; the item re-runs both).
  • Ruff has native counterparts for much of this and the pre-commit ast-grep-scan hook already passes --error=unused-suppression --error=no-suppress-all.

Proposed remedy

  • Run ruff check with --config pyproject.toml in commands/ci.py:661, in the pre-commit hook and in CI; add --no-respect-gitignore in CI only, where the checkout is clean (locally it would lint the gitignored scratch under .data/).
  • One test reads ruff check --show-settings and asserts C901 enabled at max-complexity 10, the item 3 nesting rule, and the TID251 banned-API table; one test asserts no workflow, hook or ci.py row passes --select, --ignore, --extend-*, --isolated or another --config.
  • Keep the ast-grep half (396 lines, 18 cases): ast-grep has no settings dump, so it stays until a separate trial.
  • Reword AGENTS.md line 14, CONTRIBUTING.md, docs/SDLC.md and docs/TESTING.md as pairs A15 (interim), O02, O10 and O31 give.

What it deletes

  • 522 lines of tests (about 70 added) and about 66 lines of constants.py.

Tests

  • Negative controls in tmp_path repositories: a nested ruff.toml that ignores C901, a .gitignore entry for a source directory, a --select added to a hook. The first two fail the invocation test or the lint run; the third fails the invocation test.
  • File-level # ruff: noqa: C901 is not seen by the settings test and stays covered by the file-level directive counter (item 4).

Dependencies

  • docs(agents): a convention yields to an open tool, and instructions with no check or with a contradiction are pruned

Acceptance criteria

  • The 38 escape cases no longer exist and the tree still cannot silence C901 through configuration, nested files, ignore files or flags, shown by the negative controls.
  • uv run devops ci passes.

Size: M.

Proposed design

Problem statement

The current implementation of the complexity cap in Ruff relies on a complex set of tests and configuration constants to enforce that C901 complexity rules cannot be bypassed. This approach is brittle and requires maintaining numerous test cases and constants that only serve to prove the configuration is correctly enforced.

Acceptance criteria

  • Criterion 1: The Ruff configuration enforces the C901 complexity cap without allowing any escape mechanisms through nested configurations, ignore files, or suppression comments.
    Verification: Run ruff check with --config pyproject.toml and --no-respect-gitignore in CI and verify that C901 complexity rules are enforced.
  • Criterion 2: The negative controls for nested configurations, ignore files, and command-line flags properly fail the invocation test or lint run.
    Verification: Create temporary repositories with nested ruff.toml files that ignore C901, .gitignore entries for source directories, and hooks with added --select flags, and verify they fail the tests.
  • Criterion 3: The uv run devops ci command passes successfully.
    Verification: Execute uv run devops ci and confirm it completes without errors.

Key questions

  • What are the key files that currently implement the complexity cap enforcement?: The key files are tests/test_architectural_invariants.py which contains 522 lines of tests and src/devops_cli/config/constants.py which holds the key sets and patterns used only by those tests. [sources: tests/test_architectural_invariants.py:1131, src/devops_cli/config/constants.py:4135]
  • How does the current implementation protect against configuration escapes?: The current implementation uses a test suite that re-implements Ruff's configuration semantics, including key allowlists, nested-config discovery, ignore files and suppression comment spellings. [sources: tests/test_architectural_invariants.py]
  • What changes are proposed to enforce the complexity cap using native Ruff flags?: The proposed change is to run ruff check with --config pyproject.toml in both pre-commit hooks and CI, and add --no-respect-gitignore in CI only. (proposed)
  • What is the purpose of the --no-respect-gitignore flag?: The --no-respect-gitignore flag ensures that ignore files are not respected during linting, preventing escape mechanisms through .gitignore entries. [sources: tests/test_architectural_invariants.py:1450]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 22, 2026
  2. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/refactor. The candidate describes a refactor of CI configuration and test suite to simplify complexity cap enforcement using Ruff's native flags.
    • Priority: P2-Medium. This is a refactor that improves tooling and reduces code complexity, but does not address an urgent issue or bug.
    • Value: Medium. Improves developer experience and tooling consistency by removing redundant tests and configuration logic.
    • Effort: Low. The changes involve updating CI scripts and removing a moderate amount of test code, with no new functionality added.
  3. added this to the v0.2.39 milestone on Oct 22, 2026
  4. added
    status/in-progress
    on Oct 22, 2026
  5. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

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

  6. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1892, merged into release/v0.2.39 as aba8206.

    Cause: The complexity cap of 10 is one Ruff setting. A test file of 2,999 lines guarded that setting with tests that re-implemented Ruff's configuration rules. They held key allowlists, scans for nested configuration files, scans for ignore files and a table of 38 escape cases. A new Ruff setting failed the build until a person admitted it. The tests and the constants behind them existed only to prove that a short configuration cannot be weakened.

    Change: The lint row of devops ci (cmd and fix_cmd) and the ruff-check pre-commit hook now run ruff check --config pyproject.toml. This file is the only Ruff configuration, so no nested ruff.toml can outrank it. The new tests/test_ruff_complexity_cap.py holds three checks with their negative controls, 30 tests in 474 lines. The settings test reads ruff check --show-settings and asserts that C901, PGH004, RUF100 and TID251 are enabled, that the cap is 10, that no per-file waiver and no lint exclusion exist, and that the four banned socket APIs are listed. The walk test asks git for the tracked Python sources and asks ruff check --show-files for the files the gate walks, and it fails for each source that the walk skips. The invocation test asserts that every ruff check in a devops ci row, in the pre-commit configuration and in a .github script passes --config pyproject.toml and no flag other than --fix. tests/test_architectural_invariants.py loses 529 lines and gains 94: the key allowlists, the scans for…

    14 file(s) changed.

    How it was verified

    Check runs at 916a1b4:

    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1870-ruff-owns-the-complexity-cap.md:

    • The 38 escape cases no longer exist. The tree still cannot silence C901 through configuration, nested files, ignore files or flags. The negative controls of tests/test_ruff_complexity_cap.py show this.
    • No deleted symbol has a reference left in src, tests or the docs. The exceptions are docs/agent/tasks, docs/agent/archive and CHANGELOG.md. uv run devops docs check reports every file up to date.
    • ruff check, ruff format --check, mypy over src, deptry and the targeted tests pass. The targeted tests include tests/test_architectural_invariants.py, tests/test_ruff_complexity_cap.py, tests/test_swallowed_failures_ratchet.py, tests/test_ci.py, tests/test_ci_dry_run.py, tests/test_workflow_contracts.py and the tests of AGENTS.md claims and task files.
    • Pending a person: uv run devops ci passes on the delivering tree. This change ran the targeted tests and not the gate.
  7. added a commit that references this issue on Oct 23, 2026
  8. removed
    status/in-progress
    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

    source/agenttype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions