Repository navigation
fix(semver): parse exact versions with the SemVer 2.0.0 grammar - #3894
Conversation
parse_semver now rejects leading zeros in numeric identifiers and non-ASCII digits. The policy literal-tag check (v1.2.3) routes through parse_semver instead of its own regex, so v01.2.3 and [email protected] are no longer treated as exact releases by require_pinned_constraint. Closes #3795 Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the stricter SemVer parsing and shared policy validation changes.
No open issues 🎉
What changed in this PR
Fixes #3795 by tightening APM’s shared exact-version parser to reject leading zeros in numeric identifiers and non-ASCII digits, and routing policy literal-tag checks through that parser.
Changes:
- Enforces SemVer numeric-identifier rules while preserving valid alphanumeric prerelease identifiers and build metadata.
- Replaces the policy’s separate literal-tag regex with
parse_semver. - Adds regression tests and documents the behavior change.
| File | Description |
|---|---|
tests/unit/policy/test_pinned_constraint.py |
Verifies malformed release tags classify as bare branches. |
tests/unit/marketplace/test_semver.py |
Tests invalid numeric identifiers and valid zero-containing forms. |
src/apm_cli/policy/_constraint_pinning.py |
Delegates v-prefixed release validation to parse_semver. |
src/apm_cli/marketplace/semver.py |
Tightens numeric and prerelease identifier grammar. |
CHANGELOG.md |
Records stricter release recognition in resolution and pinning policy. |
Review effort: Balanced
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 2 | 0 | Owner routing is correct: _LITERAL_TAG_RE now delegates to parse_semver and the grammar matches SemVer 2.0.0. Remaining gaps: the dropped guard and the behavior-change wording. |
| Test Coverage Expert | 0 | 1 | 0 | Grammar and pinning repros are trapped at unit tier and pass. Resolver tag selection has no trap for leading-zero tags. No durable-state paths changed, so no lifecycle test needed. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Test Coverage Expert] In-PR: add one parametrized case to
TestIterSemverTagsintests/unit/deps/test_git_semver_resolver.pyasserting that onlyv1.0.0survives from[v01.9.0, v1.9.0-01, v1.0.0]. --_VERSION_RXstill accepts any digits, soparse_semveris the only thing stopping a leading-zero tag from being selected, and no test watches it. - [Python Architect] In-PR: reword the single Fixed line as a behavior change (leading-zero, non-ASCII or malformed-prerelease tags are skipped by resolution and reported as bare branches by
require_pinned_constraint). -- Users with tags likev1.02.0will see different resolution results; that must be visible in the CHANGELOG. - [Python Architect] Record the guard deviation on the [BUG] parse_semver accepts leading zeros and non-ASCII digits #3795 binding record (captain prune, 2026-11-19), not only in the PR body. Open a guard follow-up only if the maintainer wants one. -- The record's Done-when still lists a guard; writing the decision down keeps governance honest without adding scope.
Recommendation
Merge once the author adds the resolver regression test and the reworded single CHANGELOG line, both already planned for this PR. Neither needs a new review round. After that, the only open item is noting the guard deviation on the #3795 record, which is the maintainer's call.
Full per-persona findings
Python Architect
- [recommended] Skipping the guard is defensible under the captain prune, but the record and the architecture rule both expect one. Record the deviation. at
src/apm_cli/marketplace/semver.py:125
Routing is correct and complete within scope:_is_literal_version_tag,_is_package_literal_tagand_is_package_at_release_tagall route throughparse_semverwith consistent lazy imports, and_PARTIAL_WILDCARD_REis range syntax, correctly left alone. architecture.instructions.md says a split-authority fix is complete only with a regression test and a registered static guard; today the only protection is theparse_semverdocstring line.
Suggested: Do not add the guard in this PR. State the deviation and track it if the maintainer wants it. - [recommended] The stricter parser also changes resolution and policy results for real-world tags. Make sure the one CHANGELOG line says so. at
src/apm_cli/policy/_constraint_pinning.py:277
The grammar is correct against SemVer 2.0.0 (alphanumeric prerelease ids such as0astay valid; build metadata still allows+001; ASCII digits keepint()and_cmp_tuplesafe). Tags such asv1.02.0now drop out of git-semver selection, outdated and drift, and refs the old regex accepted (v1.2.3-01,v1.2.3--,v1.2.3-rc..1,v1.2.3+a+b) now classify asBARE_BRANCH.
Suggested: Word the CHANGELOG entry as a behavior change.
Test Coverage Expert
- [recommended] No resolver-level regression trap shows that
^1.0.0ignores av01.9.0tag. attests/unit/deps/test_git_semver_resolver.py:288
The pinning promise is trapped throughtest_classify_non_semver_literal_tag_returns_bare_branch. The resolution promise is only trapped indirectly throughparse_semverunit tests;tests/spec_conformance/test_resolution_reqs.py:714checks a private regex copy, not the resolver.TestIterSemverTags::test_skips_non_semver_tagsonly coversrelease-candidate.
Suggested: Add RemoteRef tagsrefs/tags/v01.9.0andrefs/tags/v1.9.0-01next torefs/tags/v1.0.0and assert onlyv1.0.0comes back.
Proof (missing at):tests/unit/deps/test_git_semver_resolver.py::TestIterSemverTags::test_skips_leading_zero_semver_tags-- proves: a range like ^1.0.0 never installs from a tag such as v01.9.0 or v1.9.0-01. [secure-by-default,portability-by-manifest]
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Folded in this run
- (panel) Resolver regression trap
TestIterSemverTags::test_skips_tags_outside_semver_grammarkeeps onlyv1.0.0from[v01.9.0, v1.9.0-01, v1.0.0]; fails with main's parser -- resolved in 647c2a6. - (panel) CHANGELOG line reworded as a behavior change (resolution skips non-SemVer tags;
require_pinned_constraintreports them as bare branches) -- resolved in 647c2a6.
Copilot signals reviewed
- Copilot review on b86e306: approval recommended, no inline findings.
Deferred (out-of-scope follow-ups)
- Static guard against new ad-hoc exact-version regexes -- dropped by the 0.37 captain scope prune ("No new guard is needed unless trivial"); a new rule needs a registry record, MutationCase and inventory entry. Recording it on the [BUG] parse_semver accepts leading zeros and non-ASCII digits #3795 record is the maintainer's call.
Lint
ruff 0.15.12 check + format, pylint R0801, auth-signal lint and scripts/lint-architecture-boundaries.sh all clean at 647c2a6.
CI
gh pr checks 3894 at 647c2a6: 30 pass, 2 skipping, 0 failing (CI, Merge Gate, Spec conformance, CodeQL).
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Fold panel findings on #3894: iter_semver_tags must skip v01.9.0 and v1.9.0-01, and the CHANGELOG line names the resolution and policy behavior change. Co-authored-by: Copilot App <[email protected]>
Description
TL;DR
parse_semvernow follows the SemVer 2.0.0 grammar for numeric identifiers: ASCII digits only, no leading zeros. The policy literal-tag check (v1.2.3) drops its own regex and callsparse_semver, sorequire_pinned_constraintno longer treatsv01.2.3,v1.2.3-01or[email protected]as exact releases.Problem (WHY)
_SEMVER_REinmarketplace/semver.pyused\d+, which accepts leading zeros (01.2.3,1.2.3-01) and, because Python\dis Unicode-aware, non-ASCII digits (\u0661.2.3).policy/_constraint_pinning._LITERAL_TAG_REwas a second, looser exact-version regex (^v\d+\.\d+\.\d+([-+][0-9A-Za-z.\-+]+)?$). It also acceptedv1.2.3-rc..1.Approach (WHAT)
\d+core parts and prerelease ids0|[1-9][0-9]*core parts; prerelease ids are numeric without leading zeros or alphanumeric_LITERAL_TAG_REregex in policy_is_literal_version_tag:vprefix plusparse_semver(spec[1:])[0-9A-Za-z-]+Implementation (HOW)
src/apm_cli/marketplace/semver.py_SEMVER_REis built from_NUMERIC_ID/_PRERELEASE_IDfragments; docstring names it the one exact-version parser.src/apm_cli/policy/_constraint_pinning.py_LITERAL_TAG_REremoved; classification step 5 calls_is_literal_version_tag, which routes throughparse_semver(lazy import, as the neighbouring helpers do).tests/unit/marketplace/test_semver.py1.2.3-0,1.2.3-0a,1.2.3+001valid.tests/unit/policy/test_pinned_constraint.pyv01.2.3,v1.02.3,v1.2.3-01,v1.2.3-rc..1,v\u0661.2.3,[email protected]classify asBARE_BRANCH.tests/unit/deps/test_git_semver_resolver.pyiter_semver_tagsoverv01.9.0,v1.9.0-01,v1.0.0keeps onlyv1.0.0, so^1.0.0cannot select a leading-zero tag (panel fold; fails on main)._PACKAGE_AT_TAG_REand the{name}-v...layouts already delegate the version part toparse_semver, so they pick up the stricter grammar with no edit.Trade-offs
commands/outdated.TAG_RE,marketplace/version_resolver._BARE_SEMVERandbundle/formats._VERSION_REare^\d+\.\d+\.\d+prefix probes, not exact-version parsers. Range syntax and tag-naming conventions are out of scope in the record.v1.02.0stop counting as semver candidates during range resolution, and the same refs stop passingrequire_pinned_constraint. Both are the issue's cases.$keeps its current trailing-newline behavior; no ref reaches the parser with one.Benefits
parse_semverand the policy literal-tag check (2 owners become 1).require_pinned_constraintjudgesv01.2.3/[email protected]as unbounded, matching the documented "exact release" intent.01.2.3and1.2.3as equal versions.Validation
Fail-before on main (tests added first):
15 failed, 6 passedfor the new cases. After the fix:Commands and results
Scenario evidence
apm.ymlpinsacme/lib#v01.2.3underrequire_pinned_constraint: true: reported as a bare branch, not an exact releasetests/unit/policy/test_pinned_constraint.py::test_classify_non_semver_literal_tag_returns_bare_branchv1.2.3,v1.0.0-rc.1,v1.2.3+build.42,[email protected]) stay pinnedtests/unit/policy/test_pinned_constraint.py::test_classify_pinned_specs_return_none,test_pinned_constraint_declared.py^1.0.0in a repo taggedv01.9.0andv1.0.0resolves tov1.0.0tests/unit/deps/test_git_semver_resolver.py::TestIterSemverTags::test_skips_tags_outside_semver_grammartests/integration/test_git_semver_install_e2e.py,test_git_semver_prerelease_chain_lifecycle.py,tests/unit/depsHow to test
python -c "from apm_cli.marketplace.semver import parse_semver as p; print(p('01.2.3'), p('1.2.3-01'), p('1.2.3-0a'))"printsNone None SemVer(...).tests/unit/marketplace/test_semver.pyandtests/unit/policy/test_pinned_constraint.py.Issue and approved scope
Issue: Closes #3795
Human scope-approval comment: #3795 (comment) (restated record for the pruned scope; earlier records 7000601744 and 7000058184)
Does this PR complete the issue, or what remains? It completes it. Both call paths named in the record use
parse_semver, and the fail-before tests, resolution and pinning suites and the CHANGELOG line (under [Unreleased] Fixed) are done. The guard item was dropped by the 0.37 captain's scope prune (see Trade-offs).Type of change
Testing
Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedtests/spec_conformance/test_resolution_reqs.py(which already expectsv01.2.3to be rejected) stays green.Co-authored-by: Copilot [email protected]