Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure pinning strategy is not affected by non-semver packages #2580

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lock_file/satisfiability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ mod tests {
Ok(())
}

#[rstest::rstest]
#[rstest]
#[tokio::test]
async fn test_good_satisfiability(
#[files("tests/data/satisfiability/*/pixi.toml")] manifest_path: PathBuf,
Expand Down
3 changes: 2 additions & 1 deletion src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,10 @@ impl Project {
.flatten()
.collect_vec();

let mut pinning_strategy = self.config().pinning_strategy;
let channel_config = self.channel_config();
for (name, (spec_type, spec)) in conda_specs_to_add_constraints_for {
let mut pinning_strategy = self.config().pinning_strategy;

// Edge case: some packages are a special case where we want to pin the minor
// version by default. This is done to avoid early user confusion
// when the minor version changes and environments magically start breaking.
Expand Down
68 changes: 66 additions & 2 deletions tests/integration_rust/add_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,8 @@ async fn add_sdist_functionality() {
.unwrap();
}

#[rstest::rstest]
#[tokio::test]
async fn add_unconstrainted_dependency() {
async fn add_unconstrained_dependency() {
// Create a channel with a single package
let mut package_database = PackageDatabase::default();
package_database.add_package(Package::build("foobar", "1").finish());
Expand Down Expand Up @@ -582,3 +581,68 @@ async fn pinning_dependency() {
.to_string();
assert_eq!(python_spec, r#""==3.13""#);
}

#[tokio::test]
async fn add_dependency_pinning_strategy() {
// Create a channel with two packages
let mut package_database = PackageDatabase::default();
package_database.add_package(Package::build("foo", "1").finish());
package_database.add_package(Package::build("bar", "1").finish());
package_database.add_package(Package::build("python", "3.13").finish());

let local_channel = package_database.into_channel().await.unwrap();

// Initialize a new pixi project using the above channel
let pixi = PixiControl::new().unwrap();
pixi.init().with_channel(local_channel.url()).await.unwrap();

// Add the `packages` to the project
pixi.add_multiple(vec!["foo", "python", "bar"])
.await
.unwrap();

let project = pixi.project().unwrap();

// Get the specs for the `foo` package
let foo_spec = project
.manifest()
.default_feature()
.dependencies(SpecType::Run, None)
.unwrap_or_default()
.get("foo")
.cloned()
.unwrap()
.to_toml_value()
.to_string();
assert_eq!(foo_spec, r#"">=1,<2""#);

// Get the specs for the `python` package
let python_spec = project
.manifest()
.default_feature()
.dependencies(SpecType::Run, None)
.unwrap_or_default()
.get("python")
.cloned()
.unwrap()
.to_toml_value()
.to_string();
// Testing to see if edge cases are handled correctly
// Python shouldn't be automatically pinned to a major version.
assert_eq!(python_spec, r#"">=3.13,<3.14""#);

// Get the specs for the `bar` package
let bar_spec = project
.manifest()
.default_feature()
.dependencies(SpecType::Run, None)
.unwrap_or_default()
.get("bar")
.cloned()
.unwrap()
.to_toml_value()
.to_string();
// Testing to make sure bugfix did not regress
// Package should be automatically pinned to a major version
assert_eq!(bar_spec, r#"">=1,<2""#);
}
Loading