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
2 changes: 1 addition & 1 deletion rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ or removing a command fails until the table changes in the same commit.
| `toolchains.resolve` | Resolve the fixed/project/global/automatic layers from one generation-bound snapshot, retaining unmet requirements, unavailable providers with their cause, conflicts and terminal fixed-value failures |
| `toolchains.checkVersion` | Match captured output with an enabled plugin definition's version expression and compare generic numeric components with an optional minimum; never starts a probe |
| `toolchains.discoveryPlan` | Return platform-filtered definition-owned scan declarations, layouts, probes, PATH entries, login-shell home variables and budgets; never scans native directories |
| `toolchains.candidates` | List one tool's login-shell homes and host-scanned installations with checked executables, versions or skip reasons, and the automatic-layer choice; never starts a probe |
| `toolchains.candidates` | List one tool's login-shell homes (declared `environment` variables and, from the optional `commandHomes`, declared commands found on the PATH) and host-scanned installations with checked executables, versions or skip reasons, and the automatic-layer choice; never starts a probe. A shell home that checks out is also an `installations` entry with provider `host:shell`, once per canonical home, so a picker can offer every home the resolver may run; `selected` remains the automatic layer's own choice |
| `toolchains.instantiateLaunch` | Expand an enabled tool definition's `launch` template for a selected executable, entry, runtime arguments and arguments; a part the template cannot carry is `plugin.toolchain.launchMismatch`; performs no I/O |
| `run.decodeStart` | Validate a plugin backend's `lithe/host/run/start` params against its manifest and the workspace, and return the normalized start with temporary-file paths substituted |
| `debug.decodeBackendConfiguration` | Validate a plugin backend's `lithe/host/debug/start` params against its manifest and return the qualified adapter, request, label and configuration |
Expand Down
57 changes: 57 additions & 0 deletions rust/crates/core/src/tests/toolchain_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,63 @@ fn toolchain_candidates_list_versions_and_share_the_resolver_choice() {
assert_eq!(resolve(&value)["outcome"]["selection"]["home"], HOME);
}

#[test]
fn toolchain_candidates_offer_shell_homes_that_no_discovery_scan_covers() {
// A JDK reached only through JAVA_HOME or the PATH is still one the resolver runs.
let mut value = input();
installation(&mut value, HOME, "21.0.4");
installation(&mut value, OLD, "17.0.12");
value["environment"]["JAVA_HOME"] = json!(OLD);
let mut listing = listing(&value);
listing["commandHomes"] = json!({"java":HOME});
let result = candidates_command(listing.clone(), validated_manifest_json).unwrap();
assert_eq!(result["status"], "ok", "{result}");
let listed = &result["candidates"];
assert_eq!(
listed["installations"],
json!([
{"home":HOME,"executable":format!("{HOME}/bin/java"),"version":"21.0.4","provider":"host:shell"},
{"home":OLD,"executable":format!("{OLD}/bin/java"),"version":"17.0.12","provider":"host:shell"}
])
);
assert_eq!(
listed["shell"],
json!([
{"candidateID":"home","variable":"JAVA_HOME","home":OLD,
"executable":format!("{OLD}/bin/java"),"version":"17.0.12"},
{"candidateID":"shell","command":"java","home":HOME,
"executable":format!("{HOME}/bin/java"),"version":"21.0.4"}
])
);
// Shell homes are choices, not the automatic layer's own installations.
assert_eq!(listed["selected"], Value::Null);

// One home reached through both routes, or also scanned, is listed once and keeps
// the scan's attribution.
listing["commandHomes"] = json!({"java":OLD});
listing["systemInstallations"] = json!([{"tool":"java","home":OLD}]);
let listed =
candidates_command(listing.clone(), validated_manifest_json).unwrap()["candidates"].clone();
assert_eq!(
listed["installations"],
json!([{"home":OLD,"executable":format!("{OLD}/bin/java"),"version":"17.0.12","provider":"host:system"}])
);

// A shell home that fails its check is reported but never offered.
listing["systemInstallations"] = json!([]);
listing["minimumVersion"] = json!("21");
let listed =
candidates_command(listing.clone(), validated_manifest_json).unwrap()["candidates"].clone();
assert_eq!(listed["installations"], json!([]));
assert_eq!(listed["shell"][0]["reason"], "versionUnsatisfied");

listing["commandHomes"] = json!({"java":7});
assert_eq!(
candidates_command(listing, validated_manifest_json).unwrap()["status"],
"rejected"
);
}

#[test]
fn toolchain_candidates_keep_provider_attribution_and_count_one_home_once() {
let mut value = input();
Expand Down
59 changes: 46 additions & 13 deletions rust/crates/toolchain/src/resolution/automatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ pub(crate) fn automatic_choice(
/// resolving a directory: login-shell homes and the discovered installations with their
/// checked executables, versions or skip reasons, and Core's automatic choice. Hosts
/// probe only the executables returned here, then call again with `probes`.
///
/// `shell` reports each declared `environment` variable and `command` the host found
/// (`environment`, `commandHomes`). A shell home that checks out is also an entry of
/// `installations` under the `host:shell` provider, once per canonical home: it is a
/// home the resolver would run, so a picker must be able to offer it even where no
/// discovery scan covers it. `selected` stays the automatic layer's own choice.
pub(crate) fn candidates(input: &Value, validate_manifest: ManifestValidator) -> Validation<Value> {
fields(
input,
Expand All @@ -135,6 +141,7 @@ pub(crate) fn candidates(input: &Value, validate_manifest: ManifestValidator) ->
"fixed",
"projectCodeAllowed",
"environment",
"commandHomes",
],
)?;
let registry = definitions::registry(&input["registry"], validate_manifest)?;
Expand All @@ -150,40 +157,66 @@ pub(crate) fn candidates(input: &Value, validate_manifest: ManifestValidator) ->
{
return Err(reject("projectCodeAllowed"));
}
string_maps(input, &["environment"])?;
string_maps(input, &["environment", "commandHomes"])?;
let mut shell = Vec::new();
let mut shell_selections = Vec::new();
for candidate in definition["executables"]
.as_array()
.into_iter()
.flatten()
.filter(|value| value["kind"] == "environment" && applicable(value, snapshot.platform))
.filter(|value| applicable(value, snapshot.platform))
{
let Some(variable) = candidate["variable"].as_str() else {
continue;
// The same lookups the resolver's environment and command layers make.
let (source, home, layout) = match candidate["kind"].as_str() {
Some("environment") => {
let Some(variable) = candidate["variable"].as_str() else {
continue;
};
let home = input["environment"][variable].as_str();
(
json!({"variable":variable}),
home,
candidate["path"].as_str(),
)
}
Some("command") => {
let Some(command) = candidate["command"].as_str() else {
continue;
};
let home = input["commandHomes"][command].as_str();
(json!({"command":command}), home, None)
}
_ => continue,
};
let Some(home) = input["environment"][variable]
.as_str()
.filter(|value| !value.is_empty())
else {
let Some(home) = home.filter(|value| !value.is_empty()) else {
continue;
};
let layout = candidate["path"].as_str();
let mut row = json!({"candidateID":candidate["id"],"variable":variable,"home":home});
let mut row = json!({"candidateID":candidate["id"],"home":home});
for (key, value) in source.as_object().into_iter().flatten() {
row[key] = value.clone();
}
if let Ok(checked) = snapshot.checked(home, layout) {
row["home"] = checked["home"].clone();
row["executable"] = checked["executable"].clone();
}
match snapshot.layout_selection(home, layout, "host:shell", "global") {
Ok(value) => row["version"] = value["version"].clone(),
Ok(value) => {
row["version"] = value["version"].clone();
shell_selections.push(value);
}
Err(code) => row["reason"] = json!(code),
}
shell.push(row);
}
let mut reported = provider_installations(input, tool, &registry)?;
reported.extend(system_installations(input, tool)?);
let set = automatic_set(&snapshot, &reported)?;
let mut installations: Vec<_> = set
.eligible
let mut listed = set.eligible.clone();
for selection in shell_selections {
let key = snapshot.key(selection["home"].as_str().unwrap_or(""))?;
listed.entry(key).or_insert(selection);
}
let mut installations: Vec<_> = listed
.values()
.map(|value| {
json!({"home":value["home"],"executable":value["executable"],
Expand Down
Loading