Skip to content

fix(QUAL-008): pin the pre-commit ruff hook to the version CI installs - #117

Open
DoRmAmMu1997 wants to merge 2 commits into
mainfrom
fix/qual-008-precommit-ruff-pin
Open

fix(QUAL-008): pin the pre-commit ruff hook to the version CI installs#117
DoRmAmMu1997 wants to merge 2 commits into
mainfrom
fix/qual-008-precommit-ruff-pin

Conversation

@DoRmAmMu1997

Copy link
Copy Markdown
Owner

The drift

.pre-commit-config.yaml pinned ruff-pre-commit at v0.15.1 while constraints.txt pinned ruff==0.16.3 — a full minor version apart, with real rule differences.

The config file asked for these to stay aligned, in a comment on the line directly above the rev:

  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Keep this rev aligned with the ruff pin in constraints.txt.
    rev: v0.15.1

Nothing enforced it, so it drifted. A commit-time hook that lints with different rules than CI can pass code CI then rejects — which defeats the purpose of having the hook at all.

Why the existing guard missed it

tests/test_supply_chain_policy.py is exactly the right place for this — it already asserts the verbatim CI command strings and the constraints.txt pin list. But it checked:

  • the hook ids, the files regex, and the no---fix policy (:145)
  • separately, that a ruff== pin exists in constraints.txt (:191)

...and never compared the two values. The one cross-file invariant the config explicitly asked for was the one nobody guarded.

The fix

  • Bump the hook to v0.16.3 (tag confirmed upstream at 65dbdb5).
  • Add test_pre_commit_ruff_rev_matches_the_constraints_pin: parses the ruff-pre-commit rev, parses the ruff== pin, requires equality.
  • Add a companion test_pre_commit_ruff_rev_guard_rejects_a_drifted_pin, matching the file's existing pattern of proving each guard actually bites (same shape as the QUAL-007 ignore_errors pair).

Verification

Note: pre-commit run --all-files cannot execute on the development machine — it fails to clone its hook environments (InvalidManifestError) on untouched main too, so it is a pre-existing local environment issue rather than anything this PR introduces. CI runs only validate-config, which passes. Lint was verified directly with python -m ruff check, which is what the hook shells out to anyway.

🤖 Generated with Claude Code

DoRmAmMu1997 and others added 2 commits September 4, 2026 19:12
`.pre-commit-config.yaml` pinned `ruff-pre-commit` at v0.15.1 while
`constraints.txt` pinned `ruff==0.16.3`. The config file asked for these to stay
aligned in a comment on the line above the rev, but nothing enforced it, so they
drifted a full minor version apart. A commit-time hook that lints with different
rules than CI can pass code CI then rejects, which defeats the purpose of having
the hook.

`tests/test_supply_chain_policy.py` was the natural place to catch this - it
already asserts the exact CI command strings and the `constraints.txt` pin list -
but it only checked the hook's ids, file regex and no-`--fix` policy, and
separately that a `ruff==` pin exists. It never compared the two values.

Bump the hook to v0.16.3 and add the missing guard: parse the ruff-pre-commit
rev, parse the `ruff==` pin, and require equality, with a companion test proving
the guard fails on a drifted rev. Verified by re-drifting the rev to v0.15.1 and
watching the assertion fail with `- 0.16.3 / + 0.15.1`.

`python -m ruff check` over the full gated path set passes under 0.16.3, so the
bump surfaces no new findings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant