Skip to content

fix(registry): keep pre-releases out of stable semver ranges - #3601

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-fix-registry-prerelease-stable-ranges
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-fix-registry-prerelease-stable-ranges

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR

Registry version selection (pick_best) no longer picks a pre-release for a stable range: ^1.2.3 over [1.2.3, 1.3.0-beta.1] now resolves 1.2.3. A pre-release is eligible only when the range itself names a pre-release on the same major.minor.patch, per OpenAPM v0.1 §7.3.1. Equal-precedence builds now tie-break on the bytewise-highest version string (req-rs-014) instead of registry list order.

Important

Partial delivery of the scope record's Done when. Every pre-release clause is met, but three prerelease_optin=false oracle cases (tilde-0_x ~0.2, comma-and >=1.0.0, <1.5.0, or-union 1.x || ...) fail for range-grammar reasons, not pre-release reasons: is_semver_range rejects those forms today (and tests/unit/registry/test_semver.py::TestIsSemverRange::test_rejects_invalid_refs pins that rejection). That gate is shared with marketplace manifest validation, drift and ref classification, so widening it is outside this record (Out of scope: marketplace resolver changes). They are recorded as a strict=True xfail test so a future grammar change flips them loudly. Hence Refs, not Fixes.

Credit: approach from #3469 by JohnnyXu (@xubenqiang) (closed for CLA). This PR is an independent implementation of the narrower approved scope: #3469's original commit admitted any pre-release once the range named one; this admits only the range's own [major, minor, patch] tuple.

Problem (WHY)

  • pick_best kept pre-releases in the candidate set, so ^1.2.3 → 1.3.0-beta.1, >=1.2.0 <2.0.0 → 2.0.0-rc.1, ~1.2.0 → 1.2.5-alpha.1 (reproduced on 2cc5d809c).
  • >=1.2.0-alpha <2.0.0 selected 1.5.0-beta, a pre-release on a tuple the range never named.
  • The same range resolved differently by source: GitSemverResolver and the marketplace resolver already drop pre-releases.
  • [!] Build-metadata ties (1.2.3+zeta vs 1.2.3+build.42) resolved by registry response order, which is non-deterministic.

Why these matter: OpenAPM v0.1 §7.3.1 says pre-release candidates "MUST be discarded from the candidate set before highest-match selection" unless the range "contains a pre-release identifier on the same [major, minor, patch] tuple"; req-rs-014 requires selecting "the tag whose name compares highest under bytewise ASCII ordering" on equal precedence.

Approach (WHAT)

# Fix
1 Collect the [major, minor, patch] tuples of pre-release operands in the range; drop any pre-release candidate whose tuple is not in that set before matching.
2 Select with max((SemVer, raw)) so equal precedence falls back to the raw string (req-rs-014).
3 Bind the registry picker to the §7.3.1 oracle (semver-dialect.json, prerelease_optin=false) under req-rs-007 / req-rs-014.

Implementation (HOW)

  • src/apm_cli/deps/registry/semver.py — new _prerelease_tuples(); pick_best() filters and tie-breaks. is_semver_range, match_version and the shared marketplace matcher are untouched.
  • tests/unit/registry/test_semver.py — issue cases, same-tuple admit/reject, upper-bound and caret pre-release operands, exact pre-release, order-independent tie-break.
  • tests/unit/registry/test_resolver.py, test_outdated.py — download_package("^1.0.0") downloads 1.5.3 not 1.6.0-rc.1; apm outdated Wanted excludes the beta while Latest still reports it.
  • tests/spec_conformance/test_resolution_reqs.py — oracle-driven conformance test plus a separate strict-xfail test for the three grammar gaps (kept off the req markers so CONFORMANCE.json lists only passing evidence).
  • Docs — one sentence each in guides/registries.md, reference/manifest-schema.md, reference/cli/outdated.md and apm-usage/dependencies.md. CONFORMANCE.{json,md} regenerated.

Diagrams

Legend: candidate flow inside pick_best; the boxed step is new.

flowchart LR
    A["registry /versions"] --> B["parse_semver"]
    B --> C{"pre-release?"}
    C -->|"no"| E["satisfies_range"]
    C -->|"yes"| D["NEW: tuple named by a pre-release operand in range?"]
    D -->|"yes"| E
    D -->|"no"| X["discard"]
    E -->|"match"| F["NEW: max by SemVer then raw string"]
Loading

Trade-offs

  • Filter in pick_best, not resolver.py. The record names pick_best; apm outdated Wanted and the git_reference_resolver semver-tag fallback (git_reference_resolver.py:545) share it, so those paths now agree with GitSemverResolver (req-rs-002). No code in the git-semver or marketplace resolvers changed.
  • match_version unchanged. Drift and outdated "outside constraint" checks still treat a locked pre-release as in range, so this PR forces no re-resolution of existing lockfiles.
  • No prerelease: true opt-in. Explicitly out of scope; the prerelease_optin=true oracle case is not bound.
  • Grammar gaps deferred (see the IMPORTANT note above) rather than widening a gate shared with marketplace validation.

Benefits

  1. The three issue reproductions now return 1.2.3, 1.9.0 and 1.2.4.
  2. Registry, git-semver and marketplace resolvers agree on stable-range pre-release exclusion.
  3. 10 of 13 prerelease_optin=false oracle cases are now bound to the registry picker (req-rs-007 1 → 11 tests in CONFORMANCE.md).
  4. Equal-precedence selection is deterministic regardless of registry response order.

Issue and approved scope

Issue: Refs #3466

Partial: delivers every pre-release clause of the #3466 scope record and the req-rs-014 tie-break; remaining is the registry range grammar for oracle cases tilde-0_x (~0.2), comma-and and or-union (||), which needs a decision on the shared is_semver_range gate (out of this record's scope).

Human scope-approval comment: #3466 (comment) (apm-scope:v1, review contact Daniel Meppiel (@danielmeppiel))

Does this PR complete the issue, or what remains? It delivers the full pre-release scope and the req-rs-014 tie-break. Remaining Done when gap: the registry picker does not yet accept ~0.2, comma-AND and || ranges (oracle cases tilde-0_x, comma-and, or-union). That needs a range-grammar decision on the shared is_semver_range gate, which the record puts out of scope. The maintainer decides whether the issue stays open for the grammar follow-up.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
Validation evidence

Reproduction on HEAD 2cc5d809c before the fix:

^1.2.3 -> 1.3.0-beta.1 | >=1.2.0 <2.0.0 -> 2.0.0-rc.1 | ~1.2.0 -> 1.2.5-alpha.1 | >=1.2.0-alpha <2.0.0 -> 1.5.0-beta

TDD and mutation-break (fix reverted with git stash, then restored):

# new tests, before fix
11 failed, 22 passed, 137 deselected, 3 xfailed
# resolver + outdated tests with fix reverted
2 failed, 52 deselected
# with fix
.venv/bin/python -m pytest tests/unit/registry/ tests/spec_conformance/test_resolution_reqs.py tests/unit/policy/test_pinned_constraint.py tests/integration/test_deps_registry_coverage.py tests/unit/install/test_git_semver_wiring.py
579 passed, 6 xfailed

Spec conformance (mirrors .github/workflows/spec-conformance.yml):

python -m tests.spec_conformance.orphan_check
[+] orphan_check OK: 136 requirements aligned across anchors / manifest / Appendix C / pytest markers
pytest tests/spec_conformance -p no:randomly -q
521 passed, 3 xfailed; 35 unrelated failures in test_unmanaged_skill_preflight_reqs.py from a stale Homebrew apm 0.33.0 on PATH (same failures on pristine origin/main)
python -m tests.spec_conformance.gen_statement   # CONFORMANCE.{json,md} committed

Lint contract on the merged tree (ruff check, ruff format --check, pylint R0801, lint-auth-signals.sh, Mode B, orphan check): all clean. Targeted tests after merging origin/main: pytest tests/unit/registry/ tests/spec_conformance/test_resolution_reqs.py -> 384 passed, 5 xfailed.

Local preflight skipped by maintainer instruction (2026-11-12); CI is the gate.

Scenario Evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 owner/repo#^1.0.0 through a registry installs the newest stable release, not a published RC Governed by policy tests/unit/registry/test_resolver.py::TestHappyPath::test_stable_range_skips_published_prerelease unit
2 A range naming 1.1.0-alpha may pick 1.1.0-beta, but >=1.2.0-alpha <2.0.0 never picks 1.5.0-beta Governed by policy tests/unit/registry/test_semver.py::TestPickBestPrereleaseOptIn unit
3 apm outdated Wanted matches what apm install would pick DevX tests/unit/registry/test_outdated.py::TestCheckRegistryLockedDep::test_wanted_excludes_prerelease_from_stable_range unit
4 Registry selection conforms to the OpenAPM §7.3.1 oracle and req-rs-014 Vendor-neutral tests/spec_conformance/test_resolution_reqs.py::test_registry_picker_matches_semver_dialect_oracle conformance

How to test

  • .venv/bin/python -c "from apm_cli.deps.registry.semver import pick_best as p; print(p('^1.2.3',['1.2.3','1.3.0-beta.1']), p('>=1.2.0 <2.0.0',['1.9.0','2.0.0-rc.1']), p('~1.2.0',['1.2.4','1.2.5-alpha.1']))" → 1.2.3 1.9.0 1.2.4
  • uv run --extra dev pytest tests/unit/registry/test_semver.py tests/spec_conformance/test_resolution_reqs.py -k "PickBest or registry_picker" → passes, 3 xfailed (grammar gaps)
  • Existing test_prerelease_sorts_before_release (>=1.0.0-beta.1 <2.0.0) still selects 1.0.0.

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended. (req-rs-007, req-rs-014; implementation now conforms to existing §7.3.1 text, no spec change.)
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Co-authored-by: Copilot [email protected]

Registry version selection (deps/registry/semver.pick_best) now discards
a pre-release candidate unless the range names a pre-release on the same
[major, minor, patch] tuple, per OpenAPM v0.1 section 7.3.1 (req-rs-007).
Equal-precedence candidates tie-break on the bytewise-highest version
string (req-rs-014) instead of registry list order.

Binds the registry picker to the semver-dialect.json oracle
(prerelease_optin=false) under req-rs-007 and req-rs-014; the three
range-grammar cases the registry gate does not accept yet are a strict
xfail. CONFORMANCE.{json,md} regenerated.

Refs #3466
Credit: approach from #3469 by @xubenqiang.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the registry pre-release selection changes.

No open issues 🎉

What changed in this PR

Addresses the registry pre-release selection bug in #3466 by aligning pick_best with OpenAPM’s same-version-tuple eligibility rule, without expanding the accepted range grammar.

Changes:

  • Excludes pre-releases unless the range names one on the same major.minor.patch, and makes equal-precedence ties deterministic using bytewise version-string ordering.
  • Adds picker, install, outdated, and conformance coverage; records three deferred grammar cases as strict expected failures.
  • Updates user documentation and generated conformance records.
File Description
tests/​unit/​registry/​test_semver.py Tests pre-release eligibility and order-independent build tie-breaking.
tests/​unit/​registry/​test_resolver.py Verifies stable-range installs skip published pre-releases.
tests/​unit/​registry/​test_outdated.py Verifies stable Wanted selection while Latest can report a pre-release.
tests/​spec_conformance/​test_resolution_reqs.py Binds registry selection to oracle cases and tracks deferred grammar gaps.
src/​apm_cli/​deps/​registry/​semver.py Filters pre-releases by named version tuple and adds deterministic tie-breaking.
packages/​apm-guide/​.apm/​skills/​apm-usage/​dependencies.md Documents registry range pre-release eligibility.
docs/​src/​content/​docs/​reference/​manifest-schema.md Explains pre-release range selection and exact-version behavior.
docs/​src/​content/​docs/​reference/​cli/​outdated.md Clarifies pre-release eligibility for Wanted.
docs/​src/​content/​docs/​guides/​registries.md Updates the range-selector behavior description.
CONFORMANCE.md Updates resolution requirement test counts.
CONFORMANCE.json Records the added conformance test bindings.

Review effort: Balanced

The panel test-coverage lens found pre-release filtering exercised only
at unit tier. Add a sibling to test_best_version_selected so the
RegistryPackageResolver._pick_version path proves a stable range skips a
published pre-release. Mutation-break verified: removing the pick_best
pre-release guard fails this test.

Addresses CEO follow-up from test-coverage-expert (#3601).

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Daniel Meppiel (danielmeppiel) commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_now

Delta pass confirms the iteration-1 follow-up (test_best_version_skips_prerelease) is folded with mutation-break proof; PR body cleaned of an accidental closing reference. Ship.

panel-mode=lean (iteration 1; personas=python-architect,test-coverage-expert,doc-writer,apm-ceo) then delta (terminal; personas=test-coverage-expert,apm-ceo)

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

Iteration 1 (lean) left one follow-up: add an integration-tier regression trap proving pick_best excludes pre-releases from stable semver ranges. That follow-up is now folded: TestRegistryPackageResolverPickVersion::test_best_version_skips_prerelease, with mutation-break symmetry (removing the guard fails the test, restoring it passes). The test-coverage delta return confirms the tier-floor gap is closed with zero new findings. python-architect confirmed the same-tuple filter and the max((SemVer, raw)) tie-break encode OpenAPM v0.1 section 7.3.1 and req-rs-014 with no canonical-authority split; doc-writer found docs, CHANGELOG and the apm-usage guide consistent with the code.

The PR body was tightened: the sentence "may close" plus the issue number made GitHub list #3466 as a closing reference, contradicting the declared partial. It now keeps Refs #3466 and carries an explicit Partial: line naming the remaining grammar gap (oracle cases tilde-0_x, comma-and, or-union need a decision on the shared is_semver_range gate, outside the scope record). That boundary stays tracked on #3466 and is not a follow-up for this PR.

Aligned with: Portable by manifest: stable ranges resolve to stable releases, so apm.yml resolves the same way across registry, git-semver and marketplace sources. Pragmatic as npm: pre-releases do not satisfy a stable range unless the range opts in on the same tuple.

Panel summary

Persona B R N Takeaway
Python Architect 0 0 0 pick_best pre-release filter and max() tiebreak correctly implement OpenAPM 7.3.1 and req-rs-014; no canonical-authority split; ship.
Test Coverage Expert 0 1 -> 0 0 Iteration 1: tier-floor gap at integration level. Delta: folded with mutation-break proof; resolved.
Doc Writer 0 0 0 Docs and CHANGELOG match pick_best at head; no stale pre-release mentions.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Recommendation

All iteration-1 follow-ups are resolved. The test-coverage tier floor is met with mutation-break evidence. CI is green across every check at the exact head 988fe1a; the later merges from main were merge-only and touched no PR file. The remaining grammar gaps are explicitly out of scope and tracked on #3466. Ready for maintainer merge at their discretion.

Folded in this run

Copilot signals reviewed

  • Overview review on 90b07de -- NOT-LEGIT (no action): "Approval recommended", zero inline comments; nothing to fold.

Regression-trap evidence (mutation-break gate)

  • TestRegistryPackageResolverPickVersion::test_best_version_skips_prerelease -- deleted the if v.is_prerelease and (v.major, v.minor, v.patch) not in allowed_prerelease: continue guard in src/apm_cli/deps/registry/semver.py; test FAILED as expected (1 failed); guard restored (1 passed).

Lint contract

ruff check and ruff format --check over src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py silent; pylint R0801 10.00/10; lint-auth-signals.sh clean; lint-architecture-boundaries.sh exit 0. Owner-touch gate: no canonical owner touched.

CI

All 26 checks green (23 pass, 3 skipped) at 988fe1a (also green at 0a09e7c and 90d9be9) (Lint, Build & Test shards, Lifecycle Smoke, Spec conformance gate, Windows gates, CodeQL, license/cla) after 0 CI fix iterations. Targeted local run: pytest tests/unit/registry/test_semver.py tests/unit/registry/test_resolver.py tests/unit/registry/test_outdated.py tests/spec_conformance/test_resolution_reqs.py tests/integration/test_deps_registry_coverage.py::TestRegistryPackageResolverPickVersion -> 232 passed, 3 xfailed (strict xfail grammar gaps).

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3601 988fe1a ship_now 1 2 0 1 green MERGEABLE BLOCKED Refs-only partial; pending required review

Convergence

1 outer iteration(s); 1 Copilot round(s). Final panel stance: ship_now. Ready for maintainer review.

Full per-persona findings

Python Architect

No findings.

Test Coverage Expert

  • [recommended] (iteration 1, now folded) Tier-floor gap: pre-release filtering covered at unit tier only; install-pipeline surface needs integration-with-fixtures. at tests/integration/test_deps_registry_coverage.py:716
    Proof (missing at): tests/integration/test_deps_registry_coverage.py::TestRegistryPackageResolverPickVersion::test_best_version_skips_prerelease -- proves: A stable semver range in apm install never resolves to a pre-release tag published alongside stable versions. [governed-by-policy,devx]
    Delta: test added in 9d54fe6 with mutation-break proof; no findings.

Doc Writer

No findings.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants