Skip to content

Reject lockfiles whose resolved versions violate declared specifiers - #23143

Closed
GautamKumarOffical wants to merge 2 commits into
astral-sh:mainfrom
GautamKumarOffical:fix/lock-satisfies-resolution-specifiers
Closed

GautamKumarOffical wants to merge 2 commits into
astral-sh:mainfrom
GautamKumarOffical:fix/lock-satisfies-resolution-specifiers

Conversation

@GautamKumarOffical

Copy link
Copy Markdown

Summary

Closes #23073.

Previously, Lock::satisfies only checked whether declared requirements matched the lockfile's declared [package.metadata] requires-dist and that resolved package names were present in the graph. It did not verify that the versions of the resolved dependency packages actually satisfied the declared PEP 440 version specifiers.

As a result, if a lockfile experienced a conflicted merge or manual edit where declared specifiers in pyproject.toml and metadata were bumped (e.g. anyio==3.7.0) while the resolved node remained at anyio==3.6.2, uv lock --locked and uv lock --check would report that the lockfile was up-to-date and succeed.

This change adds version specifier validation to Lock::satisfies_requires_dist (and root requirements validation in Lock::satisfies):

  1. Verifies that the resolved package version satisfies the declared version specifiers across production, extra, and group contexts, accounting for markers and disjoint evaluation.
  2. Returns SatisfiesResult::MismatchedPackageDependencies when a resolved dependency violates the declared specifiers, prompting --locked/--check to error and re-resolution to trigger on uv lock.
  3. Adds is_empty checks on DependencyModifiers to bypass requirement preprocessing allocations when no overrides or excludes are configured.

Test Plan

  • Added unit test resolved_dependency_violating_specifier_fails_validation in crates/uv-lock/src/lock/mod.rs.
  • Added integration test lock_resolved_dependency_violating_specifier_fails_locked in crates/uv/tests/project/lock.rs asserting --locked and --check fail when a resolved dependency violates the declared specifier, and that uv lock updates to the matching version.
  • Verified test suite passes:
    • cargo test -p uv-lock
    • cargo test -p uv --test it lock_resolved_dependency_violating_specifier_fails_locked
    • cargo clippy -p uv-lock -p uv-configuration

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.

--locked/--check accept a lockfile whose resolution violates the declared specifiers (declaration-only validation)

1 participant