Skip to content

Commit

Permalink
test: root constraint shouldnt crash (#916)
Browse files Browse the repository at this point in the history
This test is triggered by work in `conda-rattler-solver`. For some
reason the constraints seem to run into a problem in resolvo where the
unsat message runs in to a "unreachable" code path.

---------

Co-authored-by: Bas Zalmstra <[email protected]>
  • Loading branch information
wolfv and baszalmstra authored Nov 4, 2024
1 parent 1e84316 commit ce3ed53
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ regex = "1.11.1"
reqwest = { version = "0.12.9", default-features = false }
reqwest-middleware = "0.3.3"
reqwest-retry = "0.6.1"
resolvo = { version = "0.8.2" }
resolvo = { version = "0.8.3" }
retry-policies = { version = "0.4.0", default-features = false }
rmp-serde = { version = "1.3.0" }
rstest = { version = "0.23.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/match_spec/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn parse_bracket_vec_into_components(
let mut seen = HashSet::new();
for (key, _) in &bracket {
if seen.contains(key) {
return Err(ParseMatchSpecError::MultipleValueForKey(key.to_string()));
return Err(ParseMatchSpecError::MultipleValueForKey((*key).to_string()));
}
seen.insert(key);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 594
expression: file_urls
---
- channels/dummy/linux-64/xbar-1-xxx.tar.bz2
- channels/dummy/linux-64/issue_717-2.1-bla_1.tar.bz2
- channels/dummy/linux-64/bar-1.0-unix_py36h1af98f8_2.tar.bz2
- channels/dummy/linux-64/foobar-2.0-bla_1.tar.bz2
- channels/dummy/linux-64/foo-3.0.2-py36h1af98f8_1.conda
- channels/dummy/linux-64/foo-3.0.2-py36h1af98f8_1.tar.bz2
- channels/dummy/linux-64/xfoo-2-xxx.tar.bz2
- channels/dummy/linux-64/foo-4.0.2-py36h1af98f8_2.tar.bz2
- channels/dummy/linux-64/foo-3.0.2-py36h1af98f8_3.conda
- channels/dummy/linux-64/bors-1.2.1-bla_1.tar.bz2
Expand All @@ -18,5 +19,6 @@ expression: file_urls
- channels/dummy/linux-64/bors-1.1-bla_1.tar.bz2
- channels/dummy/linux-64/baz-2.0-unix_py36h1af98f8_2.tar.bz2
- channels/dummy/linux-64/foobar-2.1-bla_1.tar.bz2
- channels/dummy/linux-64/xfoo-1-xxx.tar.bz2
- channels/dummy/linux-64/bors-2.0-bla_1.tar.bz2
- channels/dummy/linux-64/cuda-version-12.5-hd4f0392_3.conda
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 497
expression: json
---
{
Expand Down Expand Up @@ -263,6 +262,50 @@ expression: json
"subdir": "linux-64",
"timestamp": 1715610974,
"version": "2.1"
},
"xbar-1-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [
"xfoo >=2"
],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xbar",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974,
"version": "1"
},
"xfoo-1-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xfoo",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974,
"version": "1"
},
"xfoo-2-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xfoo",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974,
"version": "2"
}
},
"packages.conda": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 493
expression: repodata
---
info:
Expand Down Expand Up @@ -238,5 +237,45 @@ packages:
subdir: linux-64
timestamp: 1715610974
version: "2.1"
xbar-1-xxx.tar.bz2:
build: xxx
build_number: 0
depends:
- xfoo >=2
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: xbar
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1715610974
version: "1"
xfoo-1-xxx.tar.bz2:
build: xxx
build_number: 0
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: xfoo
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1715610974
version: "1"
xfoo-2-xxx.tar.bz2:
build: xxx
build_number: 0
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: xfoo
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1715610974
version: "2"
packages.conda: {}
repodata_version: 2
2 changes: 1 addition & 1 deletion crates/rattler_networking/src/gcs_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn authenticate_with_google_cloud(mut req: Request) -> MiddlewareResult<Re
match DefaultTokenSourceProvider::new(config).await {
Ok(provider) => match provider.token_source().token().await {
Ok(token) => {
let bearer_auth = format!("Bearer {}", token);
let bearer_auth = format!("Bearer {token}");
let header_value = reqwest::header::HeaderValue::from_str(&bearer_auth)
.map_err(reqwest_middleware::Error::middleware)?;
req.headers_mut()
Expand Down
71 changes: 48 additions & 23 deletions crates/rattler_solve/tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_favored() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bors"],
installed_packages: vec![installed_package(
Expand All @@ -267,7 +267,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_with_error() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar >=2", "bors >= 2"],
..SimpleSolveTask::default()
Expand All @@ -283,7 +283,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_install_non_existent() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["asdfasdf", "foo<4"],
..SimpleSolveTask::default()
Expand All @@ -299,7 +299,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_missing_virtual_package() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bar"],
..SimpleSolveTask::default()
Expand All @@ -312,7 +312,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_with_virtual_package() {
let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bar"],
virtual_packages: vec![GenericVirtualPackage {
Expand All @@ -335,7 +335,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_install_new() {
let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
..SimpleSolveTask::default()
Expand Down Expand Up @@ -381,7 +381,7 @@ macro_rules! solver_backend_tests {
let match_spec = "foo=3.0.2=py36h1af98f8_1";

let operations = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &[match_spec],
..SimpleSolveTask::default()
Expand All @@ -406,7 +406,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
installed_packages: already_installed,
Expand Down Expand Up @@ -435,7 +435,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo>=4"],
installed_packages: already_installed,
Expand All @@ -462,7 +462,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
installed_packages: already_installed,
Expand Down Expand Up @@ -491,7 +491,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
installed_packages: already_installed,
..SimpleSolveTask::default()
Expand All @@ -508,7 +508,7 @@ macro_rules! solver_backend_tests {
let date = "2021-12-12T12:12:12Z".parse::<DateTime<Utc>>().unwrap();

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo"],
exclude_newer: Some(date),
Expand Down Expand Up @@ -546,7 +546,7 @@ macro_rules! solver_backend_tests {
fn test_constraints() {
// There following package is provided as .tar.bz and as .conda in repodata.json
let mut operations = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
constraints: vec!["bors <=1", "nonexisting"],
Expand All @@ -568,7 +568,7 @@ macro_rules! solver_backend_tests {
// This tests that a package that has a constrains on a virtual package is
// properly restricted.
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["cuda-version"],
virtual_packages: vec![GenericVirtualPackage {
Expand Down Expand Up @@ -713,7 +713,7 @@ mod resolvo {
#[test]
fn test_solve_locked() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bors >=2"],
pinned_packages: vec![installed_package(
Expand All @@ -735,7 +735,7 @@ mod resolvo {
#[test]
fn test_issue_717() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["issue_717"],
..SimpleSolveTask::default()
Expand All @@ -751,7 +751,7 @@ mod resolvo {
let date = "2021-12-12T12:12:12Z".parse::<DateTime<Utc>>().unwrap();

let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo>=4"],
exclude_newer: Some(date),
Expand All @@ -766,7 +766,7 @@ mod resolvo {
#[test]
fn test_lowest_version_strategy_highest_build_number() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo"],
strategy: rattler_solve::SolveStrategy::LowestVersion,
Expand All @@ -789,7 +789,7 @@ mod resolvo {
#[test]
fn test_lowest_version_strategy_all() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
strategy: rattler_solve::SolveStrategy::LowestVersion,
Expand Down Expand Up @@ -817,7 +817,7 @@ mod resolvo {
#[test]
fn test_lowest_direct_version_strategy() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
strategy: rattler_solve::SolveStrategy::LowestVersionDirect,
Expand Down Expand Up @@ -918,6 +918,28 @@ mod resolvo {

assert!(matches!(solve_error, SolveError::Unsolvable(_)));
}

#[test]
fn test_panic_on_constraint() {
let result = solve::<rattler_solve::resolvo::Solver>(
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["xbar"],
constraints: vec!["xfoo==1"],
pinned_packages: vec![installed_package(
"conda-forge",
"linux-64",
"xfoo",
"1",
"xxx",
1,
)],
..SimpleSolveTask::default()
},
);

insta::assert_snapshot!(result.unwrap_err());
}
}

#[derive(Default)]
Expand All @@ -932,10 +954,13 @@ struct SimpleSolveTask<'a> {
}

fn solve<T: SolverImpl + Default>(
repo_path: String,
repo_path: &[String],
task: SimpleSolveTask<'_>,
) -> Result<Vec<RepoDataRecord>, SolveError> {
let repo_data = read_repodata(&repo_path);
let repo_data = repo_path
.iter()
.map(|path| read_repodata(path))
.collect::<Vec<_>>();

let specs: Vec<_> = task
.specs
Expand All @@ -957,7 +982,7 @@ fn solve<T: SolverImpl + Default>(
pinned_packages: task.pinned_packages,
exclude_newer: task.exclude_newer,
strategy: task.strategy,
..SolverTask::from_iter([&repo_data])
..SolverTask::from_iter(&repo_data)
};

let pkgs = T::default().solve(task)?;
Expand Down
Loading

0 comments on commit ce3ed53

Please sign in to comment.