From 7f5a7c24d41b7a0b3a881210ab694ddeb7dda9ec Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 08:37:37 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01THB2F227hR8eAmXPnAe4bZ --- tests/test_security_license_contract.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_security_license_contract.py b/tests/test_security_license_contract.py index 35099c4..11b9736 100644 --- a/tests/test_security_license_contract.py +++ b/tests/test_security_license_contract.py @@ -74,11 +74,25 @@ def test_dependency_lockfile_and_upper_bounds_parity() -> None: assert re.search(rf"^{pkg}==[\d.]+", lock_text, re.MULTILINE), f"{pkg} must be pinned in requirements-lock.txt" # Verify requirements.txt defines upper bounds matching pyproject.toml + # (compared structurally so that Dependabot range bumps stay green when both files move together) req_file = ROOT / "requirements.txt" req_text = req_file.read_text(encoding="utf-8") - assert "<7.0.0" in req_text, "requirements.txt must specify PySide6 / pyinstaller upper bounds" - assert "<13.0.0" in req_text, "requirements.txt must specify Pillow upper bound" - assert "<26.0.0" in req_text, "requirements.txt must specify keyring upper bound" + pyproject_text = (ROOT / "pyproject.toml").read_text(encoding="utf-8") + spec_re = r"^\s*\"?{pkg}(>=[\d.]+,<[\d.]+)\"?,?\s*$" + for pkg in ("PySide6", "pyinstaller", "Pillow", "keyring"): + req_match = re.search(spec_re.format(pkg=pkg), req_text, re.MULTILINE) + pyproject_match = re.search(spec_re.format(pkg=pkg), pyproject_text, re.MULTILINE) + assert req_match, f"requirements.txt must specify a lower and upper bound for {pkg}" + assert pyproject_match, f"pyproject.toml must specify a lower and upper bound for {pkg}" + assert req_match.group(1) == pyproject_match.group(1), ( + f"{pkg} range differs: requirements.txt {req_match.group(1)} vs pyproject.toml {pyproject_match.group(1)}" + ) + lock_match = re.search(rf"^{pkg}==([\d.]+)", lock_text, re.MULTILINE) + upper = req_match.group(1).split(",<")[1] + lock_version = tuple(int(p) for p in lock_match.group(1).split(".")) + assert lock_version < tuple(int(p) for p in upper.split(".")), ( + f"{pkg}=={lock_match.group(1)} in requirements-lock.txt violates upper bound <{upper}" + ) def test_third_party_licenses_complete_and_accurate() -> None: