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
6 changes: 4 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7455,8 +7455,10 @@ resource does not affect code signatures or update deltas.
`workspaceRoot:""`, allowing discovery and inspection before a project is open. Global mode
requires an empty local pin document, never selects project wrappers, project environments,
project settings or project provider statements, and does not require a fictitious workspace
filesystem fact. Additional `workspaceRoots` remain exclusion roots. Normal requests still
require the real project root. Native callers supply registered homes as ordinary
filesystem fact. Global resolution can consume `queries` with `directory:"."`, outer
`context:null`, and explicit `workspace:null, context:null` in each query's params.
Additional `workspaceRoots` remain exclusion roots. Normal requests still require
queries bound to the real project root and directory. Native callers supply registered homes as ordinary
`systemInstallations` and the current catalog default as `globalDefault:{home}`; the
existing precedence remains fixed consumer choice, project override, global default, then
automatic discovery. Clearing the global default exposes live automatic selection without
Expand Down
45 changes: 45 additions & 0 deletions rust/crates/core/src/tests/toolchain_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,51 @@ fn global_toolchain_discovery_and_defaults_need_no_project_directory() {
assert_eq!(candidates["candidates"]["installations"][0]["home"], HOME);
}

#[test]
fn global_toolchain_resolution_binds_provider_replies_to_their_scope() {
let scope: Value = serde_json::from_str(include_str!(
"../../../../fixtures/toolchains/global-query-resolution.json"
))
.unwrap();
let mut value = input();
self_provided(&mut value);
for field in ["directory", "global", "workspaceRoot", "context"] {
value[field] = scope[field].clone();
}
value["filesystem"] = json!([]);
installation(&mut value, HOME, "21.0.4");
let mut backend = installs_query(&value, &[(HOME, "21.0.4")]);
let workspace_scope = backend["request"]["params"]["workspace"].take();
let workspace_context = backend["request"]["params"]["context"].take();
for field in ["context", "workspace"] {
backend["request"]["params"][field] = scope["queryScope"][field].clone();
}
value["queries"] = json!([backend]);
let selection = &resolve(&value)["outcome"]["selection"];
assert_eq!(selection["home"], HOME);
assert_eq!(selection["layer"], scope["expectedLayer"]);
assert_eq!(selection["provider"], scope["expectedProvider"]);

let mut with_context = value.clone();
with_context["context"] = workspace_context.clone();
with_context["queries"][0]["request"]["params"]["context"] = workspace_context;
let mut with_workspace = value.clone();
with_workspace["queries"][0]["request"]["params"]["workspace"] = workspace_scope;
let mut in_workspace = value.clone();
in_workspace["global"] = json!(false);
in_workspace["workspaceRoot"] = json!(WORKSPACE);
in_workspace["filesystem"]
.as_array_mut()
.unwrap()
.push(fact(WORKSPACE, "directory", false));
in_workspace["queries"][0]["filesystem"] = in_workspace["filesystem"].clone();
for rejected in [with_context, with_workspace, in_workspace] {
let result = resolve_command(rejected, validated_manifest_json).unwrap();
assert_eq!(result["status"], "rejected", "{result}");
assert_eq!(result["error"]["code"], "plugin.toolchain.invalidParams");
}
}

#[test]
fn global_toolchain_mode_refuses_project_pins_and_ignores_project_executables() {
let mut value = input();
Expand Down
37 changes: 24 additions & 13 deletions rust/crates/toolchain/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,29 @@ pub(crate) fn resolve(input: &Value, validate_manifest: ManifestValidator) -> Va
if value["platform"] != platform {
return Err(reject("queries.platform"));
}
if value["request"]["params"]["workspace"]["root"]
.as_str()
.and_then(|path| snapshot.key(path).ok())
!= Some(snapshot.key(&root)?)
{
return Err(reject("queries.workspace"));
}
let requested_directory = value["request"]["params"]["workspace"]["directory"]
.as_str()
.unwrap_or("");
if requested_directory != directory {
return Err(reject("queries.directory"));
let params = &value["request"]["params"];
let workspace = &params["workspace"];
if input["global"] == true {
if !workspace.is_null() {
return Err(reject("queries.workspace"));
}
if !params["context"].is_null() {
return Err(reject("queries.context"));
}
if directory != "." {
return Err(reject("queries.directory"));
}
} else {
if workspace["root"]
.as_str()
.and_then(|path| snapshot.key(path).ok())
!= Some(snapshot.key(&root)?)
{
return Err(reject("queries.workspace"));
}
if workspace["directory"].as_str() != Some(directory) {
return Err(reject("queries.directory"));
}
}
if value["filesystem"] != input["filesystem"] {
return Err(reject("queries.filesystem"));
Expand All @@ -217,7 +228,7 @@ pub(crate) fn resolve(input: &Value, validate_manifest: ManifestValidator) -> Va
if value["currentGeneration"].as_u64() != Some(generation) {
return Err(reject("queries.generation"));
}
if value["request"]["params"]["context"] != input["context"] {
if params["context"] != input["context"] {
return Err(reject("queries.context"));
}
if !query_providers.insert((
Expand Down
12 changes: 12 additions & 0 deletions rust/fixtures/toolchains/global-query-resolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"directory": ".",
"global": true,
"workspaceRoot": "",
"context": null,
"queryScope": {
"workspace": null,
"context": null
},
"expectedLayer": "automatic",
"expectedProvider": "dev.lithe.fixture.java-support:installs"
}
10 changes: 7 additions & 3 deletions shared/plugins/contract/v1/toolchains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,13 @@ its declared `path` layout.

Each query is a complete `decodeReply` input, bound to the resolver's registry,
generation/context, root/directory, case policy, roots and filesystem snapshot.
The resolver accepts local workspace queries here; global-only decoder inputs
are not a substitute for the workspace-bound query round. `providerChoices`
records explicit project/global provider or automatic-installation choices; it
Workspace resolution only accepts queries bound to the same workspace and
directory. With `global:true` and `workspaceRoot:""`, the resolver accepts
global-only queries with explicit `workspace:null` and `context:null` in the
request. The resolution has `directory:"."` and `context:null`. Any additional
`workspaceRoots` still exclude installations inside an open workspace.
`providerChoices` records explicit project/global provider or
automatic-installation choices; it
does not activate providers or bypass their evidence checks.
Its shape is `{project?:"pluginID:providerID",global?:"pluginID:providerID",
automatic?:"absolute-installation-home"}`; choices not present in the current
Expand Down
Loading