Skip to content

Commit 7f5a7c2

Browse files
committed
test(contract): compare dependency ranges structurally instead of hardcoding upper bounds
The upper-bound check asserted literal strings such as '<13.0.0', so every Dependabot range bump (e.g. #11, Pillow <14.0.0) failed CI although requirements.txt, pyproject.toml and the lockfile moved together. The test now checks that each bounded package has identical ranges in requirements.txt and pyproject.toml and that the locked version is below the upper bound. Vulnerability floors are still checked separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01THB2F227hR8eAmXPnAe4bZ
1 parent 550e90f commit 7f5a7c2

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎tests/test_security_license_contract.py‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@ def test_dependency_lockfile_and_upper_bounds_parity() -> None:
7474
assert re.search(rf"^{pkg}==[\d.]+", lock_text, re.MULTILINE), f"{pkg} must be pinned in requirements-lock.txt"
7575

7676
# Verify requirements.txt defines upper bounds matching pyproject.toml
77+
# (compared structurally so that Dependabot range bumps stay green when both files move together)
7778
req_file = ROOT / "requirements.txt"
7879
req_text = req_file.read_text(encoding="utf-8")
79-
assert "<7.0.0" in req_text, "requirements.txt must specify PySide6 / pyinstaller upper bounds"
80-
assert "<13.0.0" in req_text, "requirements.txt must specify Pillow upper bound"
81-
assert "<26.0.0" in req_text, "requirements.txt must specify keyring upper bound"
80+
pyproject_text = (ROOT / "pyproject.toml").read_text(encoding="utf-8")
81+
spec_re = r"^\s*\"?{pkg}(>=[\d.]+,<[\d.]+)\"?,?\s*$"
82+
for pkg in ("PySide6", "pyinstaller", "Pillow", "keyring"):
83+
req_match = re.search(spec_re.format(pkg=pkg), req_text, re.MULTILINE)
84+
pyproject_match = re.search(spec_re.format(pkg=pkg), pyproject_text, re.MULTILINE)
85+
assert req_match, f"requirements.txt must specify a lower and upper bound for {pkg}"
86+
assert pyproject_match, f"pyproject.toml must specify a lower and upper bound for {pkg}"
87+
assert req_match.group(1) == pyproject_match.group(1), (
88+
f"{pkg} range differs: requirements.txt {req_match.group(1)} vs pyproject.toml {pyproject_match.group(1)}"
89+
)
90+
lock_match = re.search(rf"^{pkg}==([\d.]+)", lock_text, re.MULTILINE)
91+
upper = req_match.group(1).split(",<")[1]
92+
lock_version = tuple(int(p) for p in lock_match.group(1).split("."))
93+
assert lock_version < tuple(int(p) for p in upper.split(".")), (
94+
f"{pkg}=={lock_match.group(1)} in requirements-lock.txt violates upper bound <{upper}"
95+
)
8296

8397

8498
def test_third_party_licenses_complete_and_accurate() -> None:

0 commit comments

Comments
 (0)