Fix: run the update-constraints pre-commit hook in check mode - #163
Open
AmaadMartin wants to merge 4 commits into
Open
Fix: run the update-constraints pre-commit hook in check mode#163AmaadMartin wants to merge 4 commits into
AmaadMartin wants to merge 4 commits into
Conversation
added 3 commits
August 7, 2026 16:57
Update mode re-derives --exclude-newer from the current date and exits non-zero whenever it rewrites a file, so the hook could never pass in the Pre-commit Linter job. Check mode reads the recorded date back out of each constraints file header, writes nothing, and still fails on real pin drift. Adds two guard tests: the hook entry must pass --check, and every Python version in the script's PYTHON_VERSIONS array must have a committed constraints file.
The hand-rolled walk-up returned Path | None, which forced two assert _REPO_ROOT is not None narrowing lines that the module-level skipif already makes unreachable. Match the sibling test file and index parents[3] instead, then drop both asserts.
This was referenced Aug 8, 2026
Open
…ests The skipif predicate can never be true. tests/ is never packaged (the sdist includes only src, README, pyproject and LICENSE), so .pre-commit-config.yaml is present wherever these tests run. The guard also inverted the intent it was meant to serve: a deleted .pre-commit-config.yaml is the most severe hook-config drift there is, and the skip turned that into a silent pass. Both tests still fail on their mutations, and deleting .pre-commit-config.yaml now fails instead of skipping.
This was referenced Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Prior art: google#6505 proposes the same
one-line change, bundled with four other edits that have since landed
separately.
Problem: The
Pre-commit Linterjob fails on every commit tomain, whilethe other 15 jobs pass. The
update-constraintshook runs./scripts/update_constraints.shwith no flag, which is the script's updatemode. Update mode re-derives
--exclude-newerfrom the current date, rewritesall five
constraints-*.txtheaders, and exits non-zero whenever it rewrote afile. An auto-fixer that exits 1 on success cannot pass as a gate.
Solution: Pass
--checkin the hook entry. The script's own usage blockalready designates
--checkas the CI mode. Check mode reads the recorded--exclude-newerdate back out of each file header, so it is deterministic andnever writes to a tracked file. It still fails on real pin drift, so the guard
is kept, not deleted.
Two new tests pin the contract: the hook entry must pass
--check, and everyPython version in the script's
PYTHON_VERSIONSarray must have a committedconstraints file.
Deliberately not re-shipped, because they already landed on
main: theastral-sh/setup-uvstep in the lint job (566fca3f), the fiveconstraints-*.txtfiles and the codespell skip (42f220a6). This PR touchesone YAML file and adds one test module.
Collision check against the open fork PRs. Three PRs edit the same six lines,
and none of them use
--check:guard.
stages: [manual]. Same loss of the guard. It was written before theconstraints files were committed and before the lint job had
uv, so at thetime disabling the hook was the only option. Both premises have changed.
Five more PRs (#54, #68, #77, #149, #159) edit
scripts/update_constraints.sh. This PR does not touch that script, so it doesnot conflict with them.
Testing Plan
Unit Tests:
Both tests were proved able to fail, by mutating the exact line each one pins:
--checkfrom the hook entryAssertionError: The update-constraints hook must pass --check .../assert '--check' in []constraints-3.14.txtAssertionError: No committed constraints file for Python ['3.14'] ....pre-commit-config.yamlFileNotFoundErroron the config readManual End-to-End (E2E) Tests:
Run from the repo root. Needs
uvand network access to PyPI.Both failure paths were exercised the same way:
a2a-sdkpin inconstraints-3.12.txtFailed, exit 1,constraints-3.12.txt is OUT OF DATE!plus the remedy line. The file was left as-is, so check mode wrote nothing.constraints-3.14.txtFailed, exit 1,constraints-3.14.txt is missing!All other hooks pass on the changed files:
Checklist