Repository navigation
Intersect hashes from repeated constraints - #21956
charliermarsh wants to merge 4 commits into
Conversation
uv test inventory changesThis PR changes the tests when compared with the
|
cee9ebf to
1db9344
Compare
1db9344 to
2050ea8
Compare
| #[error("Conflicting hashes for `{0}`: no hash is allowed by all requirements and constraints")] | ||
| NoIntersection(String), |
There was a problem hiding this comment.
[P2] Update the remaining NoIntersection snapshots
require_hashes_repeated_requirements_constraint still contains four snapshots expecting the old diagnostic in pip_install.rs at lines 9867, 9879, 9896, and 9908. Those scenarios still reach NoIntersection, so this message change makes their assertions fail. Update those expectations alongside require_hashes_constraint.
|
|
||
| Computed: | ||
| sha256:[BUILD_HASH] | ||
| cause: Conflicting hashes for `build-dependency @ file://[TEMP_DIR]/wheels/build_dependency-1.0.0-py3-none-any.whl`: no hash is allowed by all requirements and constraints |
There was a problem hiding this comment.
[P2] Expect the direct-reference conflict diagnostic
These file URL constraints produce VersionId::Path, so the new combination step calls merge_digests and returns ConflictingArchiveUrlHashes, including both conflicting SHA-256 digests. NoIntersection is only returned for registry identities. This snapshot therefore cannot match the implementation; update it to expect the direct-reference diagnostic.
| context | ||
| .temp_dir | ||
| .child("backend-executed") | ||
| .assert(predicate::path::exists()); | ||
| .assert(predicate::path::missing()); |
There was a problem hiding this comment.
[P2] Reset conflicting constraints before later build scenarios
After this assertion, the command-line constraint still contains incorrect_hash while the workspace contains build_hash. The subsequent isolation and dynamic-requirement scenarios reuse that conflicting pair. build_package constructs the hash strategy before handling isolation, so they now stop at NoIntersection instead of reaching their expected behavior. Explicitly reset the constraint inputs between scenarios, using a valid common build-dependency hash before the dynamic-requirement checks.
| if let Some(existing) = constraint_hashes.get(&id) { | ||
| digests = combine_constraint_hashes(&id, digests, existing, requirement)?; |
There was a problem hiding this comment.
[P2] Allow corrected constraints to regenerate older lockfiles
An older lockfile can contain repeated build constraints with disjoint hashes because those previously used the last list. After correcting those constraints in pyproject.toml, uv lock, including --upgrade, still fails: do_lock constructs a strategy from the old manifest at uv-lock-operations/src/lock.rs:663 before checking whether the lock is stale. This new error therefore prevents regeneration without manually editing or deleting the lockfile. Handle obsolete constraint conflicts through recoverable lock validation, while continuing to reject conflicting current constraints.
| let hash_checking = match (build_isolation, build_hash_checking) { | ||
| (BuildIsolation::Shared, _) => None, | ||
| (_, HashCheckingMode::Require) => Some(HashCheckingMode::Require), | ||
| (_, HashCheckingMode::Verify) => hash_checking, |
There was a problem hiding this comment.
[P2] Honor package-specific disabled isolation
With disjoint hashes on repeated build constraints, uv build --wheel --no-build-isolation-package project still falls through these arms and fails during hash-strategy construction. For a project named project, the build frontend selects a shared environment and skips installing build dependencies, just as with global --no-build-isolation. This makes a previously working non-isolated build fail on unused hashes. Base the exemption on effective isolation for the package being built, retaining validation for isolated builds.
| // The same conflict is rejected for ordinary constraints in require-hashes mode. | ||
| context.temp_dir.child("constraints.txt").write_str(&formatdoc! {" | ||
| build-dependency==1.0.0 --hash=sha256:0000000000000000000000000000000000000000000000000000000000000000 | ||
| build-dependency==1.0.0 --hash=sha256:{hash} | ||
| "})?; | ||
| uv_snapshot!(context.filters(), context.pip_install().args([ |
There was a problem hiding this comment.
[P3] Give the ordinary constraint regression its own pip-install test
This ordinary pip install scenario is independent of the surrounding project lock checks, but inherits their backend and three generated wheels and is omitted when running the targeted pip-install suite. Move it into a separately named test in pip_install/pip_install.rs, beside require_hashes_repeated_requirements_constraint. That nearby test provides the explicit requirements-file and local ok wheel pattern needed for a smaller fixture.
|
Codex found these things which seem concerning on the surface but I haven't had time to look into them and understand in any depth. Capturing them here for future Zsolt Codex reproduced the following with builds of base
One compatibility detail seems worth documenting. The correct SHA-256 and SHA-512 of the same wheel each work alone. Put them in separate registry constraints and the head rejects the pair in either order. Intersecting literal digests means both files need to share an identical algorithm and digest. Registry intersection |
When constraints repeat the same registry pin with different hash lists, we currently keep the last list. Reordering constraints, including sorting them when writing a lockfile, can therefore change which artifact hashes we accept.
Intersect those lists using the same rules as requirement/constraint pairs. For example,
{A, B}and{B, C}allow onlyB; disjoint lists report a conflict. Hashless constraints add no restriction, and archive URL hashes retain their existing validation rules.This applies to ordinary and build constraints and makes their hash restrictions independent of declaration order.
Related to #21951.