fix(agent-compliance): keep the package name of a compound version specifier #4333
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4333"
general
weight: 0.35
MohammadHaroonAbuomar
Related Issue
None. I found this while reading the supply-chain checks. The sections below are filled in as the template asks.
Problem & Solution
Problem.
_parse_requirements_linesplits a requirement into a name and a version specifier. It tries the operators in a fixed order (===,==,~=,!=,>=,<=,>,<) and splits at the first one that appears anywhere in the line. That is only right when there is a single specifier. With a compound specifier, the operator tried first can come later in the line, so the split lands in the middle:| Line | name | specifier |
| --- | --- | --- |
|
requests>=2.28.0,!=2.29.0|requests>=2.28.0,|!=2.29.0||
requests<3,>=2.28.0|requests<3,|>=2.28.0||
requests >= 2.28.0, != 2.29.0|requests >= 2.28.0,|!= 2.29.0|All three callers use that name:
check_requirementsandcheck_pyprojectreport theunpinned-version/loose-constraintfinding under the wrong package name, and runcheck_typosquattingon it. With the specifier attached, a typosquatted name is no longer similar enough to be flagged.reqeusts>=2.28.0,!=2.29.0gives notyposquatfinding, whilereqeusts>=2.28.0does.scan_lockfile_driftlooks forrequests>=2.28.0,in the lockfile, so a package that is locked is reported aslockfile-drift.Compound specifiers like
>=X,!=Yand<N,>=Mare common in real requirements files andpyproject.tomldependencies.Solution. Split at the leftmost operator, using one regex over the same operators (longest first, so
===is not read as==). The name isrequests, and the specifier is the whole>=2.28.0,!=2.29.0. Single-specifier lines split the same way as before._PEP508_PINNEDstill decides pinning from the full specifier, sorequests!=2.30.0,==2.31.0counts as pinned.Impact on Your Work
A
SupplyChainGuardscan (check_requirements,check_pyproject,scan_directory,scan_lockfile_drift) of a project that uses compound specifiers reports findings under names likerequests>=2.28.0,, raises false lockfile-drift findings, and misses typosquats written that way.Timeline
None.
Alternatives Considered
packaging.requirements.Requirement. It parses PEP 508 fully, including extras, markers and URLs, but it would add a dependency to agent-compliance (its dependencies are pydantic, pyyaml and click), and it raises on lines the current parser tolerates. A one-line split fix keeps the current behavior for everything else.pkg[extra]>=1) and parenthesized specifiers (pkg (>=1)). Both still keep extra characters in the name. They are separate problems, so I left them out to keep this PR small.Type of Change
Package(s) Affected
Testing
Unit Testing
New tests in
tests/test_supply_chain.py:TestCheckRequirements::test_compound_specifier_keeps_package_name, parametrized overrequests>=2.28.0,!=2.29.0,requests<3,>=2.28.0,requests >= 2.28.0, != 2.29.0andrequests>2,<3. Each gives exactly one finding,unpinned-versionforrequestswith the full specifier.TestCheckRequirements::test_compound_specifier_with_exact_pin_passes:requests!=2.30.0,==2.31.0gives no findings.TestCheckRequirements::test_compound_specifier_typosquat_flagged:reqeusts>=2.28.0,!=2.29.0is flagged astyposquatforreqeusts.TestCheckPyproject::test_compound_specifier_keeps_package_name: oneloose-constraintfinding forrequests.TestScanLockfileDrift::test_compound_specifier_found_in_lockfile: no drift when the lockfile hasrequests==2.31.0.Six of these fail on main.
requests>2,<3and the exact-pin case already pass on main, because there the first operator tried is also the leftmost one. They are there to pin that behavior.tests/test_supply_chain.pyhas 89 passing.Manual Testing
tests/: 474 passed, 3 skipped. 13 tests intest_agt_cli.pyandtest_lint_policy.pyfail the same way without this change in my environment, becauseagent_control_specificationand the installed toolkit distribution aren't available. I skippedtest_policy_replay_metadata.pyfor the same import reason.ruff checkreports no new findings on the changed files.supply_chain.pyand the test file already have findings on main (import order,Optional), and I left those alone. cspell is clean on the added lines.Checklist
test_supply_chain.pypass; the unrelated environment failures are listed above.Attribution & Prior Art
AI Assistance
I used Claude Code (Claude Opus) to help find the bug and draft the fix and tests. I reviewed the full diff and will handle review comments myself.
IP, Patents, and Licensing
🤖 Generated with Claude Code