Skip to content

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

Closed
JohnnyXu (xubenqiang) wants to merge 6 commits into
microsoft:mainfrom
xubenqiang:fix/registry-prerelease-selection
Closed

JohnnyXu (xubenqiang) wants to merge 6 commits into
microsoft:mainfrom
xubenqiang:fix/registry-prerelease-selection

Conversation

@xubenqiang

Copy link
Copy Markdown
Contributor

Fixes #3466

Problem

deps/registry/semver.pick_best() filtered only by satisfies_range(), so pre-release versions stayed in the candidate set:

pick_best("^1.2.3", ["1.2.3", "1.3.0-beta.1"])        # -> "1.3.0-beta.1"
pick_best(">=1.2.0 <2.0.0", ["1.9.0", "2.0.0-rc.1"])  # -> "2.0.0-rc.1"
pick_best("~1.2.0", ["1.2.4", "1.2.5-alpha.1"])       # -> "1.2.5-alpha.1"

deps/git_semver_resolver.py discards pre-releases unless include_prerelease=True, and marketplace/version_resolver.py skips them, so the same range resolved to a different version depending on the source. OpenAPM v0.1 §7.3.1 requires pre-release candidates to be discarded unless the range names a pre-release on the same tuple or the entry opts in.

Fix

def pick_best(spec: str, versions: list[str], *, include_prerelease: bool = False) -> str | None:
    ...
    allow_prerelease = include_prerelease or _range_mentions_prerelease(spec)
    ...
        if v.is_prerelease and not allow_prerelease:
            continue

_range_mentions_prerelease() parses each space-separated comparator (after stripping >=, <=, ^, ~, =), so ranges such as >=1.3.0-beta.1 <2.0.0 still allow pre-releases. The default is opt-out, matching the git and marketplace resolvers.

Verification

After the change, the issue's three examples and the pre-release range:

'^1.2.3'                ['1.2.3', '1.3.0-beta.1']         -> '1.2.3'    OK
'>=1.2.0 <2.0.0'        ['1.9.0', '2.0.0-rc.1']          -> '1.9.0'    OK
'~1.2.0'                ['1.2.4', '1.2.5-alpha.1']       -> '1.2.4'    OK
'>=1.3.0-beta.1 <2.0.0' ['1.3.0', '1.3.0-beta.2']        -> '1.3.0'    OK
include_prerelease=True -> 1.3.0-beta.1

Before the change, the same first three calls returned 1.3.0-beta.1, 2.0.0-rc.1 and 1.2.5-alpha.1 (the reported behaviour).

Five tests are added to tests/unit/registry/test_semver.py (TestPickBestPrereleasePolicy), covering the three reported cases, the pre-release-range allowance, and the explicit opt-in. ruff check and ruff format --check pass on both changed files.

Notes

  • The dependency-entry prerelease: true opt-in named by the spec is not implemented anywhere in the parser today; include_prerelease is the resolver-level hook for whoever wires it up.
  • The registry resolver call site (deps/registry/resolver.py) needs no change: the default now drops pre-releases.

`pick_best()` kept every version that satisfied the range, including
pre-releases, so a stable range selected `1.3.0-beta.1` over `1.2.3` whenever
the registry listed a pre-release above the highest release. The git and
marketplace resolvers already discard pre-releases, so the same range resolved
differently depending on the source.

Drop pre-release candidates unless the range itself names a pre-release or the
caller opts in, per OpenAPM v0.1 §7.3.1.

Fixes microsoft#3466

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

OpenAPM v0.1 section 7.3.1 permits a pre-release candidate only when the
range names a pre-release on the same major.minor.patch; the previous
check admitted any pre-release once the range mentioned one, so
">=1.2.0-alpha <2.0.0" could select 1.5.0-beta. Also order equal
precedence candidates by full version string (req-rs-014) so the
registry picker agrees with the semver-dialect conformance oracle.

Addresses the approved apm-scope:v1 tighten on microsoft#3466 and its Done-when
oracle clause; tests cover both sides of the rule.

Co-authored-by: Copilot App <[email protected]>
Document that a registry semver range selects a pre-release only when it
names one on the same major.minor.patch, and add the CHANGELOG entry
crediting the contributor.

Co-authored-by: Copilot App <[email protected]>
Move the semver-dialect oracle check into tests/spec_conformance so the
registry picker is a marked conformance binding for the requirements it
implements (satisfies the Mode B silent-extension gate), regenerate
CONFORMANCE.{json,md}, and add pre-release regression traps on the two
registry consumers of pick_best: install resolution and outdated Wanted.
Document the req-rs-014 tiebreak at the sort site.

Addresses panel follow-ups from test-coverage-expert and python-architect.

Co-authored-by: Copilot App <[email protected]>
Note that stable git ref ranges never pick a pre-release tag, explain
when registry outdated Wanted can be a pre-release, and word the
CHANGELOG entry in user terms.

Addresses panel follow-ups from doc-writer.

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

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_with_followups

Community fix tightens registry pre-release filtering to the same-tuple rule (OpenAPM 7.3.1), binds the conformance oracle, and covers the in-scope consumer sites with mutation-proven regression traps.

panel-mode=lean; personas=python-architect (ad hoc: pick_best is shared by registry install, outdated and git tag range resolution),test-coverage-expert,doc-writer,apm-ceo

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

All three panelists agreed. The original change admitted any pre-release once the range named one. It now admits a pre-release only when the range names one on the same major.minor.patch, as required by the apm-scope:v1 record on #3466. The req-rs-014 build-metadata tiebreak is added and commented at the sort site. Every in-scope follow-up from the panel was folded: regression traps for outdated Wanted and registry install resolution, the outdated.md Wanted clause, a git ref range note, user-facing CHANGELOG wording, and a @pytest.mark.req conformance binding. Mutation-break proof: going back to any-pre-release semantics fails 2 tests, removing the filter fails 5, and removing the tiebreak fails the oracle case. Two items are deferred because they cross the scope boundary: match_version also drives lockfile drift detection, which the scope excludes, and the oracle's ~0.2, comma and || ranges need a grammar extension that is not part of pre-release selection.

Aligned with: Secure by default: stable ranges exclude unfinished versions without opt-in. Portable by manifest: matches OpenAPM v0.1 section 7.3.1, so conformant resolvers pick the same candidates. Community driven: authorship is preserved and the CHANGELOG credits JohnnyXu (@xubenqiang).

Panel summary

Persona B R N Takeaway
Python Architect 0 2 0 Same-tuple pre-release rule and req-rs-014 tiebreak are correct; one consistency gap in match_version is pre-existing but now visible.
Test Coverage Expert 0 2 0 Core pick_best policy is well covered; two consumer call sites (outdated Wanted, registry resolver) lacked pre-release regression traps.
Doc Writer 0 2 0 New doc sentences and CHANGELOG entry match pick_best and OpenAPM 7.3.1; outdated Wanted docs and the git-tag claim needed follow-up.

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

Top 2 follow-ups

  1. [Python Architect] Align match_version with the same-tuple pre-release rule, so outdated outside_constraint and drift detection treat pre-releases the same way -- it is a separate path that admits pre-releases unconditionally; fixing it touches lockfile drift detection, which is out of scope here.
  2. [Python Architect] Extend the registry range grammar to accept ~0.2, comma AND and || OR ranges, then cover the remaining oracle cases -- these forms fail validation before pick_best runs; this is a separate grammar feature, not pre-release selection.

Recommendation

The fix stays within the scope record, follows the spec, and is mutation-proven, and all in-scope panel findings are folded. CI on head a0840bf is green. One precondition remains before merge: JohnnyXu (@xubenqiang) must sign the Microsoft CLA (license/cla is still pending), and the contribution cannot be accepted until it clears. After that, merging is at the maintainer's discretion.

Folded in this run

  • (panel) Pre-release admitted only when the range names one on the same major.minor.patch (scope tighten); tests for both sides -- resolved in 055de49.
  • (panel) req-rs-014 build-metadata tiebreak so the prerelease_optin=false oracle cases pass -- resolved in 055de49.
  • (panel) CHANGELOG Fixed entry crediting JohnnyXu (@xubenqiang); registry range sentence in manifest-schema.md and apm-guide dependencies.md -- resolved in 301fe2f.
  • (panel) Oracle check bound under tests/spec_conformance with req-rs-007 / req-rs-014 markers, CONFORMANCE regenerated (clears the Mode B gate) -- resolved in 281d04a.
  • (panel) Tiebreak invariant comment at the sort site -- resolved in 281d04a.
  • (panel) Regression traps: outdated Wanted and registry install skip a published pre-release for a stable range -- resolved in 281d04a.
  • (panel) outdated.md Wanted clause; git ref range note; CHANGELOG reworded in user terms -- resolved in a0840bf.

Copilot signals reviewed

  • review 5768931976 -- NOT-LEGIT: no review content (reviewer quota error); zero inline comments across 2 fetch rounds.

Deferred (out-of-scope follow-ups)

  • (panel) Apply the same-tuple rule in registry match_version -- scope boundary: match_version also drives drift.py lockfile drift detection, and the scope record excludes lockfile changes.
  • (panel) Registry picker does not parse oracle ranges ~0.2, comma AND and || OR -- scope boundary: needs a range-grammar extension in the marketplace.semver grammar shared with the marketplace resolver, which is outside pre-release scope.

Regression-trap evidence (mutation-break gate)

  • test_semver.py::TestPickBestPrereleasePolicy::test_prerelease_range_rejects_other_tuple_prerelease -- deleted same-tuple check; test FAILED as expected; guard restored.
  • test_semver.py::TestPickBestPrereleasePolicy::test_stable_range_skips_prerelease_above_it -- deleted pre-release filter; test FAILED as expected; guard restored.
  • test_resolver.py::TestHappyPath::test_stable_range_skips_published_prerelease -- deleted pre-release filter; test FAILED as expected; guard restored.
  • test_outdated.py::TestCheckRegistryLockedDep::test_wanted_excludes_prerelease_from_stable_range -- deleted pre-release filter; test FAILED as expected; guard restored.
  • test_resolution_reqs.py::test_registry_picker_matches_semver_dialect_oracle[build-metadata-tiebreak-ascii-highest] -- deleted (SemVer, raw) tiebreak; test FAILED as expected; guard restored.

Lint contract

ruff check and ruff format --check were silent, pylint R0801 rated 10.00/10, and lint-auth-signals.sh and lint-architecture-boundaries.sh passed. The run was on the head merged with current main. The owner-touch gate found no canonical owner touched.

CI

All CI checks on a0840bf passed (SUCCESS, NEUTRAL or SKIPPED). One fix iteration was needed: the Spec conformance Mode B detector failed on 301fe2f and was fixed in 281d04a. license/cla is still pending.

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3469 a0840bf ship_with_followups 2 9 2 2 yellow MERGEABLE BLOCKED CLA unsigned; awaiting maintainer review
Full per-persona findings

Python Architect

  • [recommended] match_version does not apply the pre-release opt-in rule, which splits authority with pick_best at src/apm_cli/deps/registry/semver.py:48
    outdated.py uses match_version for outside_constraint. A pre-release Latest on another tuple is therefore not flagged as outside the constraint. This gap existed before the PR and the new filtering makes it visible; it is cosmetic for outdated only. Deferred (lockfile drift boundary).
  • [recommended] The (SemVer, raw) sort tiebreak contract is implicit at src/apm_cli/deps/registry/semver.py:95
    Suggested: comment the req-rs-014 invariant. Folded in 281d04a.

Doc Writer

  • [recommended] The apm outdated reference did not say that Wanted skips pre-releases while Latest includes them, at docs/src/content/docs/reference/cli/outdated.md
    Folded in a0840bf.
  • [recommended] The CHANGELOG git-tag claim had no supporting docs and used internal wording, at CHANGELOG.md:21
    Verified that git_reference_resolver.py:541 previously selected pre-releases. Folded in a0840bf.

Test Coverage Expert

  • [recommended] Outdated Wanted had no pre-release regression trap, at tests/unit/registry/test_outdated.py
    Proof (missing at): tests/unit/registry/test_outdated.py -- proves: Wanted is never a pre-release for a stable range. Folded in 281d04a.
  • [recommended] Registry install resolution had no pre-release regression trap, at tests/unit/registry/test_resolver.py
    Proof (missing at): tests/unit/registry/test_resolver.py -- proves: a stable range never installs a pre-release. Folded in 281d04a.

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.

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Thank you for this fix, JohnnyXu (@xubenqiang) -- the change itself is useful and matches the approved scope on #3466.

We can only merge contributions once the Microsoft Contributor License Agreement (CLA) is signed, and this PR has been waiting on it for more than 7 days. Per our maintainer policy we are closing it for now so the queue reflects what can actually land.

This is not a rejection. As soon as the CLA is signed (follow the license/cla check link above), comment here and we will reopen it. Your branch and authorship are preserved.


Posted with AI assistance on behalf of Daniel Meppiel (@danielmeppiel) (APM maintainer backlog policy).

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
* fix(registry): keep pre-releases out of stable semver ranges

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]>

* docs(changelog): note registry pre-release range fix (#3601)

Refs #3466

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

* test(registry): integration-tier trap for stable-range pre-release skip

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]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
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.

[BUG] Registry resolver selects pre-releases for stable ranges, against OpenAPM §7.3.1

3 participants