Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/+pin-hierarchy-error.bugfix.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion docs/orgmode/howto/new-package.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion docs/orgmode/reference/policy.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
41 changes: 41 additions & 0 deletions src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
const SHOWN: usize = 6;
if searched.iter().any(|candidate| candidate.name == name) {
return None;
}
let mut toolchains: Vec<String> = 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!(
"{}{}",
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
46 changes: 44 additions & 2 deletions src/package_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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<String> {
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<Candidate>,
Expand Down
66 changes: 66 additions & 0 deletions tests/bump_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
35 changes: 35 additions & 0 deletions tests/hierarchy_universe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading