Fix APK resolver for version constraints on provided packages #1860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical bug in the APK resolver that was causing numpy and pytorch packages to fail building in Wolfi/Chainguard. The resolver wasn't correctly handling version constraints when packages were found via their
providesentries.The Problem
When migrating from
py3-numpyto versioned packages likepy3.12-numpy, we hit an issue:Package structure:
py3.12-numpy(version 2.1.0) providespy3-numpy=2.1.0py3.12-numpy(version 1.26.4) providespy3-numpy=1.26.4py3-numpy<2.0The bug:
py3-numpy<2.0, APK would find packages providingpy3-numpypy3.12-numpyversion 2.1.0) against the constraintpy3-numpy=2.1.0)py3-numpy<2.0, even thoughpy3.12-numpy-1.26.4providespy3-numpy=1.26.4The Solution
This PR adds context awareness to the package filtering logic:
queryNameto track which name was used to find packagespy3-numpy<2.0, only checks versions relevant topy3-numpyWhy This Matters
This fix is critical for:
py3-*topy3.XX-*versioned packagesTesting
TestNumpyVersionConstraintWithProvidesthat reproduces the exact scenarioImpact
This fixes the current build failures in:
And enables the planned migration away from
py3-*packages as discussed in the incident.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com