Skip to content

Commit 799e700

Browse files
authoredFeb 20, 2025··
Bugfix: host options were being left out of the solver's initial requests (#1180)
Fixes a bug where host options were being left out of the initial solver requests, and adds test case for "--no-host" mode Add assertion to verify the host options aren't empty. Signed-off-by: J Robert Ray <[email protected]> Signed-off-by: David Gilligan-Cook <[email protected]>
1 parent fae99a0 commit 799e700

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
 

‎crates/spk-cli/common/src/flags.rs

+4
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ impl Solver {
278278
self.check_impossible_builds || self.check_impossible_all,
279279
);
280280

281+
for r in options.get_var_requests()? {
282+
solver.add_request(r.into());
283+
}
284+
281285
Ok(solver)
282286
}
283287
}

‎crates/spk-cli/common/src/flags_test.rs

+49
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use rstest::rstest;
66
use spk_schema::foundation::name::OptName;
77
use spk_schema::foundation::option_map::OptionMap;
8+
use spk_schema::ident::VarRequest;
9+
use spk_schema::option_map::HOST_OPTIONS;
810

911
#[rstest]
1012
#[case(&["hello:world"], &[("hello", "world")])]
@@ -33,3 +35,50 @@ fn test_option_flags_parsing(#[case] args: &[&str], #[case] expected: &[(&str, &
3335
.collect();
3436
assert_eq!(actual, expected);
3537
}
38+
39+
#[rstest]
40+
#[case::no_host_true(true)]
41+
#[case::no_host_false(false)]
42+
#[tokio::test]
43+
async fn test_get_solver_with_host_options(#[case] no_host: bool) {
44+
// Test the get_solver() method adds the host options to the solver
45+
// correctly.
46+
47+
let options_flags = crate::flags::Options {
48+
options: Vec::new(),
49+
no_host,
50+
};
51+
52+
let solver_flags = crate::flags::Solver {
53+
repos: crate::flags::Repositories {
54+
local_repo_only: false,
55+
no_local_repo: false,
56+
enable_repo: Default::default(),
57+
disable_repo: Default::default(),
58+
when: None,
59+
legacy_spk_version_tags: false,
60+
},
61+
allow_builds: false,
62+
check_impossible_initial: false,
63+
check_impossible_validation: false,
64+
check_impossible_builds: false,
65+
check_impossible_all: false,
66+
};
67+
68+
let solver = solver_flags.get_solver(&options_flags).await.unwrap();
69+
let initial_state = solver.get_initial_state();
70+
71+
assert!(
72+
!HOST_OPTIONS.get().unwrap().is_empty(),
73+
"HOST_OPTIONS must not be empty for this test to be meaningful"
74+
);
75+
76+
for (name, value) in HOST_OPTIONS.get().unwrap() {
77+
let var_request = VarRequest::new_with_value(name, value);
78+
if no_host {
79+
assert!(!initial_state.contains_var_request(&var_request));
80+
} else {
81+
assert!(initial_state.contains_var_request(&var_request));
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)
Please sign in to comment.