diff --git a/changelog.d/+pin-hierarchy-error.bugfix.md b/changelog.d/+pin-hierarchy-error.bugfix.md new file mode 100644 index 00000000..60d45956 --- /dev/null +++ b/changelog.d/+pin-hierarchy-error.bugfix.md @@ -0,0 +1 @@ +A pin on a package the trees have only outside the solve's toolchain hierarchy, in a `stack solve` policy or a `package plan` / `package bump` stack policy, now fails with the hierarchy searched and the toolchains the trees have the package on, instead of "unknown package" and "names a package with no candidate at all". A stack-policy exclusion gets the same message. diff --git a/docs/orgmode/howto/new-package.org b/docs/orgmode/howto/new-package.org index 664fb2ca..8b08a5ba 100644 --- a/docs/orgmode/howto/new-package.org +++ b/docs/orgmode/howto/new-package.org @@ -238,7 +238,9 @@ A preferred pin is favored when jointly feasible. Resolvo may choose another compatible candidate and records the requested version, toolchain, versionsuffix, selected identity, and fallback. A locked pin cannot fall back. Omitting ~toolchain~ leaves the pin unconstrained within the target hierarchy; -cross-generation admission requires an explicit toolchain. Omitting +cross-generation admission requires an explicit toolchain. A pin without one, +or an exclusion, on a package the trees have only outside the target +hierarchy fails, and the message names the toolchains the trees have it on. Omitting ~versionsuffix~ leaves that part of the artifact identity unconstrained. Candidate exclusions record known target/build evidence and stay visible in the profile lock. diff --git a/docs/orgmode/reference/policy.org b/docs/orgmode/reference/policy.org index e59dcb7f..e04d2ffa 100644 --- a/docs/orgmode/reference/policy.org +++ b/docs/orgmode/reference/policy.org @@ -47,7 +47,9 @@ noted below. Restricts a package to candidates whose version matches the requirement string (grammar below). A pin on a package with no matching candidate fails the solve at policy-construction time, before any Boolean satisfiability (SAT) solving - happens. + happens. A pin on a package the trees have only outside the policy + toolchain's hierarchy fails the same way, and the message names the + toolchains the trees have it on. - ~forbid~ :: Optional array of strings. Each entry matches either a full ~easyconfig_path~ or a bare package ~name~; matching candidates are excluded from the universe entirely before solving. diff --git a/llms-full.txt b/llms-full.txt index 5591be69..a5459abc 100644 --- a/llms-full.txt +++ b/llms-full.txt @@ -959,7 +959,9 @@ A preferred pin is favored when jointly feasible. Resolvo may choose another compatible candidate and records the requested version, toolchain, versionsuffix, selected identity, and fallback. A locked pin cannot fall back. Omitting `toolchain` leaves the pin unconstrained within the target hierarchy; -cross-generation admission requires an explicit toolchain. Omitting +cross-generation admission requires an explicit toolchain. A pin without one, +or an exclusion, on a package the trees have only outside the target +hierarchy fails, and the message names the toolchains the trees have it on. Omitting `versionsuffix` leaves that part of the artifact identity unconstrained. Candidate exclusions record known target/build evidence and stay visible in the profile lock. @@ -10272,7 +10274,9 @@ noted below. Restricts a package to candidates whose version matches the requirement string (grammar below). A pin on a package with no matching candidate fails the solve at policy-construction time, before any Boolean satisfiability (SAT) solving - happens. + happens. A pin on a package the trees have only outside the policy + toolchain's hierarchy fails the same way, and the message names the + toolchains the trees have it on. - `forbid` :: Optional array of strings. Each entry matches either a full `easyconfig_path` or a bare package `name`; matching candidates are excluded from the universe entirely before solving. diff --git a/src/hierarchy.rs b/src/hierarchy.rs index 558ab7dd..821f164c 100644 --- a/src/hierarchy.rs +++ b/src/hierarchy.rs @@ -253,6 +253,47 @@ pub fn root_missing_from_generation( Some(render_missing_root(name, toolchain, all)) } +/// Where the trees carry a name the searched hierarchy does not. +/// +/// `searched` is the universe a solve reads and `all` every candidate the +/// trees parsed. A name that `searched` has, or that no tree has, is `None`: +/// the solver's own message is then the accurate one. +pub fn name_outside_hierarchy( + name: &str, + hierarchy: &ToolchainHierarchy, + searched: &[Candidate], + all: &[Candidate], +) -> Option { + const SHOWN: usize = 6; + if searched.iter().any(|candidate| candidate.name == name) { + return None; + } + let mut toolchains: Vec = all + .iter() + .filter(|candidate| candidate.name == name) + .map(|candidate| candidate.toolchain.identity_label()) + .collect(); + if toolchains.is_empty() { + return None; + } + toolchains.sort(); + toolchains.dedup(); + let more = toolchains.len().saturating_sub(SHOWN); + toolchains.truncate(SHOWN); + let mut found = toolchains.join(", "); + if more > 0 { + found.push_str(&format!(", and {more} more")); + } + let parent = hierarchy.parent.identity_label(); + let levels = match hierarchy.member_labels() { + labels if labels.is_empty() => parent.clone(), + labels => labels.join(", "), + }; + Some(format!( + "{name} has no easyconfig in the {parent} hierarchy ({levels}); the trees have it on {found}" + )) +} + fn version_and_suffix(candidate: &Candidate) -> String { format!( "{}{}", diff --git a/src/lib.rs b/src/lib.rs index f96d67d0..84caaaa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -801,6 +801,20 @@ pub fn solve_with_baseline_source( roots_disp ); } + let hierarchy = crate::hierarchy::ToolchainHierarchy { + parent: policy.toolchain.clone(), + members: hierarchy_members.clone(), + }; + for pin in &policy.pins { + if let Some(found) = crate::hierarchy::name_outside_hierarchy( + &pin.name, + &hierarchy, + &universe_cands, + &expanded_all, + ) { + bail!("pin {} {}: {found}", pin.name, pin.version_req); + } + } let universe = Universe { toolchain: policy.toolchain.clone(), generation_label: Some(format!( diff --git a/src/package_solve.rs b/src/package_solve.rs index fa3990f2..6b938375 100644 --- a/src/package_solve.rs +++ b/src/package_solve.rs @@ -2,8 +2,8 @@ use crate::domain::{Candidate, DepReq, Policy, Toolchain}; use crate::hierarchy::{ - filter_candidates_in_hierarchy, hierarchy_for_with_tree, is_system_toolchain, toolchains_match, - ToolchainHierarchy, + filter_candidates_in_hierarchy, hierarchy_for_with_tree, is_system_toolchain, + name_outside_hierarchy, toolchains_match, ToolchainHierarchy, }; use crate::package::{ materialize_profile, DependencyRole, LockedDependency, PackagePlan, ProfileEnvironment, @@ -363,6 +363,11 @@ pub fn solve_package_profile_with_hierarchy( require_upgrade: Vec::new(), criteria: Vec::new(), }; + if let Some(message) = + stack_policy_name_outside_hierarchy(stack_policy, &universe, candidates, &hierarchy) + { + return Err(ProfileSolveError::Resolve(message)); + } let result = solve_curated_with_stack_policy(&universe, &policy, None, stack_policy) .map_err(ProfileSolveError::Resolve)?; @@ -509,6 +514,43 @@ fn admit_named_dependency_toolchains( } } +/// A stack-policy pin or exclusion on a name the solve's hierarchy does not +/// carry, and where the trees have it. The solver can only call such a name +/// unknown. +fn stack_policy_name_outside_hierarchy( + stack_policy: &StackPolicy, + universe: &[Candidate], + candidates: &[Candidate], + hierarchy: &ToolchainHierarchy, +) -> Option { + let pins = stack_policy + .pins + .iter() + .map(|pin| ("pin", &pin.name, &pin.version_requirement)); + let exclusions = stack_policy + .exclusions + .iter() + .map(|exclusion| ("exclusion", &exclusion.name, &exclusion.version_requirement)); + let mut everywhere = None; + for (kind, name, requirement) in pins.chain(exclusions) { + if universe.iter().any(|candidate| &candidate.name == name) { + continue; + } + let everywhere = everywhere.get_or_insert_with(|| expand_extension_provides(candidates)); + if let Some(found) = name_outside_hierarchy(name, hierarchy, universe, everywhere) { + let advice = if kind == "pin" { + ". A pin without a toolchain applies inside that hierarchy" + } else { + "" + }; + return Some(format!( + "stack policy {kind} {name} {requirement}: {found}{advice}" + )); + } + } + None +} + fn admit_stack_pin_closures( candidates: &[Candidate], admitted: &mut Vec, diff --git a/tests/bump_workflow.rs b/tests/bump_workflow.rs index 95d662a7..3a8d9a64 100644 --- a/tests/bump_workflow.rs +++ b/tests/bump_workflow.rs @@ -319,6 +319,72 @@ fn easybuild_bump_makes_cross_generation_stack_selection_explicit() { ); } +#[test] +fn a_version_only_pin_outside_the_hierarchy_says_where_the_package_is() { + let temp = tempfile::tempdir().expect("tempdir"); + let source = temp.path().join("Alpha-1.0-foss-2025b.eb"); + let robot = temp.path().join("robot"); + fs::create_dir_all(&robot).expect("robot directory"); + fs::write( + &source, + "easyblock = 'ConfigureMake'\nname = 'Alpha'\nversion = '1.0'\n\ + homepage = 'https://example.invalid/'\ndescription = 'Synthetic package'\n\ + toolchain = {'name': 'foss', 'version': '2025b'}\n\ + sources = ['alpha-1.0.tar.gz']\n\ + checksums = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']\n\ + moduleclass = 'tools'\n", + ) + .expect("source recipe"); + fs::write( + robot.join("PinnedLib-1.2-gfbf-2024a.eb"), + "easyblock = 'ConfigureMake'\nname = 'PinnedLib'\nversion = '1.2'\n\ + homepage = 'https://example.invalid/'\ndescription = 'Pinned candidate'\n\ + toolchain = {'name': 'gfbf', 'version': '2024a'}\n\ + sources = []\nchecksums = []\nmoduleclass = 'lib'\n", + ) + .expect("pinned candidate"); + let toolchain = Toolchain { + name: "foss".into(), + version: "2026.1".into(), + }; + + let error = plan_package_bump(&BumpPackageRequest { + source, + toolchain: toolchain.clone(), + version: None, + source_checksum: None, + easyconfig_roots: vec![robot], + hierarchy_fixture: None, + overrides: HashMap::new(), + stack_policy: StackPolicy { + schema_version: STACK_POLICY_SCHEMA_VERSION, + name: "site".into(), + toolchain, + pins: vec![StackPin { + name: "PinnedLib".into(), + version_requirement: "==1.2".into(), + toolchain: None, + versionsuffix: None, + mode: StackPinMode::Locked, + source: Some("site stack".into()), + }], + exclusions: Vec::new(), + }, + strict_patches: false, + package_layers: Vec::new(), + foreign_sources: Vec::new(), + }) + .expect_err("a version-only pin stays inside the hierarchy"); + let message = format!("{error:#}"); + assert!(!message.contains("unknown package"), "{message}"); + assert!( + message.contains("stack policy pin PinnedLib ==1.2") + && message.contains("foss-2026.1 hierarchy") + && message.contains("on gfbf-2024a"), + "name the pin, the hierarchy, and where the tree has it: {message}" + ); +} + #[test] fn version_bump_adopts_the_same_version_siblings_patch_block() { let temp = tempfile::tempdir().expect("tempdir"); diff --git a/tests/hierarchy_universe.rs b/tests/hierarchy_universe.rs index 2921e4f9..b324d229 100644 --- a/tests/hierarchy_universe.rs +++ b/tests/hierarchy_universe.rs @@ -352,6 +352,41 @@ fn a_pin_that_admits_nothing_is_named_ahead_of_the_pins_that_are_fine() { assert!(eb_stack::select::policy_constraints_report(&bare, &all).is_empty()); } +/// A pin on a package the tree has above the policy toolchain is not a pin on +/// an unknown package. Calling it unknown sends the reader looking for a typo +/// when the fix is the solve toolchain or the pin. +#[test] +fn a_pin_outside_the_hierarchy_says_where_the_package_is() { + let dir = tempfile::tempdir().unwrap(); + tree(dir.path()); + let policy_path = dir.path().join("policy.json"); + fs::write( + &policy_path, + r#"{"toolchain": {"name": "GCCcore", "version": "15.2.0"}, + "roots": ["CMake"], "objective": "prefer_newer", + "pins": [{"name": "FlexiBLAS", "version_req": "==3.5.0"}]}"#, + ) + .unwrap(); + let error = eb_stack::solve_from_easyconfigs_with_extras( + &[dir.path()], + &policy_path, + None, + &dir.path().join("stack.lock.json"), + None, + eb_stack::SolveExtraOut::default(), + ) + .expect_err("a pin outside the hierarchy cannot be applied"); + let message = format!("{error:#}"); + assert!(!message.contains("unknown package"), "{message}"); + assert!(!message.contains("no candidate at all"), "{message}"); + assert!( + message.contains("pin FlexiBLAS ==3.5.0") + && message.contains("GCCcore-15.2.0 hierarchy") + && message.contains("on GCC-15.2.0"), + "name the pin, the hierarchy, and where the tree has it: {message}" + ); +} + /// Identity became (name, toolchain level) in the provider and in the lock. /// ebstack-fqh7 names two things that read those keys and so move with it: the /// build list ordering and the SBOM dependency graph. Nothing asserted either,