Skip to content

Commit

Permalink
fix: ensure pinning strategy is not affected by non-semver packages (p…
Browse files Browse the repository at this point in the history
…refix-dev#2580)

Fixes prefix-dev#2574.

I added a test as well, but I'm not sure if it follows the project's
standards.
  • Loading branch information
seowalex authored and jjjermiah committed Nov 30, 2024
1 parent ad06992 commit f22d354
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
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""#);
}

0 comments on commit f22d354

Please sign in to comment.