diff --git a/rust/contracts/application-boundary.md b/rust/contracts/application-boundary.md index 0018e46d..2d621ce3 100644 --- a/rust/contracts/application-boundary.md +++ b/rust/contracts/application-boundary.md @@ -556,3 +556,16 @@ the prefix does not confer authority. Core deduplicates only the generated count of the effective saved selector and validates it before use. Prepared team/local Run layers can be resolved without filesystem publication; native adapters own cancellation, source checks, metadata-preserving conditional writes, rollback and readback. + + +### Machine-wide SDK catalog ownership + +Shared `toolchains.catalogState` / `toolchains.editCatalog` own the bounded global +registration document and its merge semantics. Desktop adapters read it from the +platform user-preference root, retain native source identity, publish only after +explicit Save, and reread the result. No workspace is needed; opening settings +creates no source. Registered homes and defaults become inert resolver inputs, +never cached authority about an executable. A project may override the global +default, while running processes retain their launch environment. Native SDK +probing, cancellation and filesystem permissions remain adapter responsibilities; +neither these commands nor runtime consumers write into SDKs or installed bundles. diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index a767f102..344a0877 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -485,6 +485,8 @@ or removing a command fails until the table changes in the same commit. | `toolchains.failureReply` | Build the JSON-RPC error reply for a query that missed its deadline or found no backend, so the host passes it to `toolchains.decodeReply` like a provider's own error; cancellation has none | | `toolchains.resolvePins` | Validate a captured local document and find the nearest ancestor directory pin, retaining dormant and legacy entries without probing or writing | | `toolchains.editPins` | Apply one bounded batch of directory pin edits to a captured local document without writing native files | +| `toolchains.catalogState` | Validate machine-wide SDK registrations without a project | +| `toolchains.editCatalog` | Merge confirmed machine-wide SDK registrations and defaults | | `toolchains.pinStoragePlan` | Declare bounded workspace-native pin and ignore sources | | `toolchains.decodePinDocument` | Validate a complete native source or supply the absent-source default | | `toolchains.editPinSources` | Plan deterministic pin and Git ignore source edits without native I/O | @@ -6509,3 +6511,43 @@ and executable exports, then resolves/probes the main build tool in that same environment. User-configured invocation environment retains its existing precedence. Host-managed runtime candidates are explicit `runtime` plans; hosts must not infer executable names from opaque runtime IDs. + + +### Global SDK registrations without an open project + +`toolchains.catalogState` accepts `{document:string|null,platform,filesystemCaseSensitive?}` +and returns `{status:"ok",state:{document,storage:{relativePath:"toolchains/global.json",maximumBytes:262144}}}`. +Native clients resolve the relative path below their platform user-preference directory, +never below a workspace, SDK, installed package or application bundle. Reading an absent +source returns `{version:1,tools:{}}` and must not create a directory or file. + +`toolchains.editCatalog` accepts the same source fields and a nonempty `edits` array of +`{tool,homes:[absoluteHome],defaultHome:string|null}`. Each edit replaces only that tool's +registrations and default; other tools, including dormant plugins, remain intact. At most +64 tools and 32 distinct homes per tool are accepted. Native platform path normalization +and case identity apply before deduplication. A selected default is registered if needed; +null clears only the default. Empty registrations plus null remove the tool entry. +The result is `{status:"ok",edit:{changed,document:string|null,catalog}}`; unchanged edits +return a null replacement and must not create a source. Invalid shapes, duplicate JSON keys, +unknown fields, relative homes, aliases and oversized documents reject with +`plugin.toolchain.invalidDocument`. The schema is +[`toolchain-global-v1.schema.json`](toolchain-global-v1.schema.json); cross-client vectors +are in `rust/fixtures/toolchain-global-catalog.json`. + +Native clients retain the exact bytes and filesystem identity privately, verify them before +atomic publication, and reread after Save. Core owns the merge and bounds; the native client +owns read/write permissions, conflict detection and installation probing. Registrations +contain no cached version authority and never modify SDK directories. This user-settings +resource does not affect code signatures or update deltas. + +`toolchains.candidates` and `toolchains.resolve` accept optional `global:true` with +`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 +`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 +removing manual registrations. Each new consumer resolves fresh facts and probes; already +running processes retain their launch-time environment. diff --git a/rust/contracts/toolchain-global-v1.schema.json b/rust/contracts/toolchain-global-v1.schema.json new file mode 100644 index 00000000..9e57ab4b --- /dev/null +++ b/rust/contracts/toolchain-global-v1.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://lithe.dev/contracts/toolchain-global-v1.schema.json", + "title": "Machine-wide SDK catalog v1", + "type": "object", + "additionalProperties": false, + "required": [ + "version", + "tools" + ], + "properties": { + "version": { + "const": 1 + }, + "tools": { + "type": "object", + "maxProperties": 64, + "additionalProperties": { + "type": "object", + "additionalProperties": false, + "required": [ + "homes" + ], + "properties": { + "homes": { + "type": "array", + "maxItems": 32, + "uniqueItems": true, + "items": { + "type": "string", + "minLength": 1 + } + }, + "defaultHome": { + "type": "string", + "minLength": 1 + } + } + } + } + } +} diff --git a/rust/crates/core/src/protocol/command.rs b/rust/crates/core/src/protocol/command.rs index eb5bbc2a..5ca28863 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -389,6 +389,10 @@ pub enum KeymapCommand { #[derive(Debug, Clone)] /// The `toolchains.*` commands; their names live in [`CoreCommand::parse`]. pub enum ToolchainsCommand { + /// Reads global SDK registrations and their native source plan. + CatalogState, + /// Plans a source-bound global SDK registration/default edit. + EditCatalog, /// Registers plugin-owned tools with verified package provenance. Registry, /// Validates provider answers using native evidence supplied by the host. @@ -1084,6 +1088,8 @@ impl CoreCommand { "keymap.planImportSources" => Some(Self::Keymap(KeymapCommand::PlanImportSources)), "keymap.planImportBindings" => Some(Self::Keymap(KeymapCommand::PlanImportBindings)), "debug.startOrContinue" => Some(Self::Debug(DebugCommand::StartOrContinue)), + "toolchains.catalogState" => Some(Self::Toolchains(ToolchainsCommand::CatalogState)), + "toolchains.editCatalog" => Some(Self::Toolchains(ToolchainsCommand::EditCatalog)), "toolchains.registry" => Some(Self::Toolchains(ToolchainsCommand::Registry)), "toolchains.decodeReply" => Some(Self::Toolchains(ToolchainsCommand::DecodeReply)), "toolchains.failureReply" => Some(Self::Toolchains(ToolchainsCommand::FailureReply)), diff --git a/rust/crates/core/src/runtime/dispatcher/toolchains.rs b/rust/crates/core/src/runtime/dispatcher/toolchains.rs index d9baefd6..694e7571 100644 --- a/rust/crates/core/src/runtime/dispatcher/toolchains.rs +++ b/rust/crates/core/src/runtime/dispatcher/toolchains.rs @@ -33,6 +33,12 @@ pub(super) fn dispatch( ToolchainsCommand::EditPins => { plugin_response(id, payload, crate::toolchain::edit_pins_command) } + ToolchainsCommand::CatalogState => { + plugin_response(id, payload, crate::toolchain::catalog_state_command) + } + ToolchainsCommand::EditCatalog => { + plugin_response(id, payload, crate::toolchain::edit_catalog_command) + } ToolchainsCommand::PinStoragePlan => { plugin_response(id, payload, crate::toolchain::pin_storage_plan_command) } diff --git a/rust/crates/core/src/tests/toolchain_pins.rs b/rust/crates/core/src/tests/toolchain_pins.rs index 27275a7e..34e57399 100644 --- a/rust/crates/core/src/tests/toolchain_pins.rs +++ b/rust/crates/core/src/tests/toolchain_pins.rs @@ -397,3 +397,25 @@ fn source_edits_match_shared_fixture() { } } } +#[test] +fn global_catalog_commands_match_shared_fixture() { + let fixture: Value = serde_json::from_str(include_str!( + "../../../../fixtures/toolchain-global-catalog.json" + )) + .unwrap(); + for case in fixture["cases"].as_array().unwrap() { + let response: Value = serde_json::from_str(&crate::execute_json( + &json!({"command": case["command"], "payload": case["input"]}).to_string(), + )) + .unwrap(); + if let Some(code) = case.get("error") { + assert_eq!(response["data"]["status"], "rejected", "{case}: {response}"); + assert_eq!( + &response["data"]["error"]["code"], code, + "{case}: {response}" + ); + } else { + assert_eq!(response["data"], case["expected"], "{case}: {response}"); + } + } +} diff --git a/rust/crates/core/src/tests/toolchain_resolution.rs b/rust/crates/core/src/tests/toolchain_resolution.rs index 2e8d5aba..3df263a7 100644 --- a/rust/crates/core/src/tests/toolchain_resolution.rs +++ b/rust/crates/core/src/tests/toolchain_resolution.rs @@ -1074,3 +1074,46 @@ fn consumer_preferences_json_dispatcher_preserves_the_value_boundary() { json!({"home":"/fixture/sdk-one"}) ); } + +#[test] +fn global_toolchain_discovery_and_defaults_need_no_project_directory() { + let mut value = input(); + value["global"] = json!(true); + value["workspaceRoot"] = json!(""); + value["filesystem"] = json!([]); + installation(&mut value, HOME, "21.0.4"); + value["systemInstallations"] = json!([{"tool":"java","home":HOME}]); + value["globalDefault"] = json!({"home":HOME}); + let result = resolve_command(value.clone(), validated_manifest_json).unwrap(); + assert_eq!(result["status"], "ok", "{result}"); + assert_eq!(result["resolution"]["outcome"]["selection"]["home"], HOME); + let mut listing = value_for_candidates(&value); + listing["global"] = json!(true); + let candidates = candidates_command(listing, validated_manifest_json).unwrap(); + assert_eq!(candidates["status"], "ok", "{candidates}"); + assert_eq!(candidates["candidates"]["installations"][0]["home"], HOME); +} + +#[test] +fn global_toolchain_mode_refuses_project_pins_and_ignores_project_executables() { + let mut value = input(); + value["global"] = json!(true); + value["workspaceRoot"] = json!(""); + value["filesystem"] = json!([]); + installation(&mut value, HOME, "21.0.4"); + value["systemInstallations"] = json!([{"tool":"java","home":HOME}]); + value["globalDefault"] = json!({"home":HOME}); + value["registry"]["plugins"][0]["manifest"]["toolDefinitions"][0]["executables"].as_array_mut().unwrap().insert(1, + json!({"id":"project-env","kind":"projectFile","projectKind":"environment","home":".venv","path":".venv/bin/java","platforms":["macos","linux"]})); + value["projectCodeAllowed"] = json!(true); + let result = resolve(&value); + assert_eq!(result["outcome"]["selection"]["home"], HOME); + assert!(!result["trace"] + .as_array() + .unwrap() + .iter() + .any(|row| row["candidate"] == "project-env")); + value["local"] = local_pins(); + let rejected = resolve_command(value, validated_manifest_json).unwrap(); + assert_eq!(rejected["status"], "rejected", "{rejected}"); +} diff --git a/rust/crates/toolchain/src/catalog.rs b/rust/crates/toolchain/src/catalog.rs new file mode 100644 index 00000000..a12b3e53 --- /dev/null +++ b/rust/crates/toolchain/src/catalog.rs @@ -0,0 +1,242 @@ +//! Machine-wide SDK registrations and defaults, independent of project pins. +//! +//! Native adapters validate installations, preserve source identity and publish +//! edits atomically. This module owns bounds, path identity and document merges. + +use super::paths; +use lithe_plugin_model::{is_tool_id, PluginRejection, Validation}; +use lithe_protocol::json_document::parse_unique_json; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use std::collections::{BTreeMap, BTreeSet}; + +const MAX_BYTES: usize = 256 * 1024; + +#[derive(Clone, Default, Deserialize, PartialEq, Serialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Entry { + homes: Vec, + #[serde(default, skip_serializing_if = "Option::is_none")] + default_home: Option, +} + +#[derive(Clone, Deserialize, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +struct Catalog { + version: u32, + tools: BTreeMap, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Request { + document: Option, + platform: String, + #[serde(default)] + filesystem_case_sensitive: Option, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Edit { + tool: String, + homes: Vec, + default_home: Option, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct EditRequest { + document: Option, + platform: String, + #[serde(default)] + filesystem_case_sensitive: Option, + edits: Vec, +} + +fn invalid(field: &str) -> PluginRejection { + PluginRejection::at( + "plugin.toolchain.invalidDocument", + field, + "Expected bounded global toolchain registrations with unique native homes.", + ) +} + +impl Request { + fn case_sensitive(&self) -> Validation { + if !matches!(self.platform.as_str(), "macos" | "windows" | "linux") { + return Err(invalid("platform")); + } + Ok(self + .filesystem_case_sensitive + .unwrap_or(self.platform != "windows")) + } + + fn entry(&self, homes: &[String], default: &Option) -> Validation { + let case_sensitive = self.case_sensitive()?; + if homes.len() > 32 { + return Err(invalid("homes")); + } + let mut identities = BTreeSet::new(); + let mut normalized = Vec::new(); + for home in homes { + let path = + paths::normalize(home, &self.platform, true).ok_or_else(|| invalid("homes"))?; + let key = paths::normalize(&path, &self.platform, case_sensitive) + .ok_or_else(|| invalid("homes"))?; + if !identities.insert(key) { + return Err(invalid("homes")); + } + normalized.push(path); + } + let default_home = default + .as_ref() + .map(|home| { + paths::normalize(home, &self.platform, true).ok_or_else(|| invalid("defaultHome")) + }) + .transpose()?; + if let Some(default) = &default_home { + let key = paths::normalize(default, &self.platform, case_sensitive) + .ok_or_else(|| invalid("defaultHome"))?; + if identities.insert(key) { + normalized.push(default.clone()); + } + } + if normalized.len() > 32 { + return Err(invalid("homes")); + } + Ok(Entry { + homes: normalized, + default_home, + }) + } + + fn read(&self) -> Validation { + self.case_sensitive()?; + let mut catalog = if let Some(text) = &self.document { + if text.len() > MAX_BYTES { + return Err(invalid("document")); + } + serde_json::from_value(parse_unique_json(text).map_err(|_| invalid("document"))?) + .map_err(|_| invalid("document"))? + } else { + Catalog { + version: 1, + tools: BTreeMap::new(), + } + }; + if catalog.version != 1 || catalog.tools.len() > 64 { + return Err(invalid("document")); + } + for (tool, entry) in &mut catalog.tools { + if !is_tool_id(tool) { + return Err(invalid("tool")); + } + *entry = self.entry(&entry.homes, &entry.default_home)?; + } + Ok(catalog) + } +} + +/// Returns the complete validated catalog and the native read plan. +pub(crate) fn state(input: &Value) -> Validation { + let request: Request = serde_json::from_value(input.clone()).map_err(|_| invalid("input"))?; + Ok( + json!({"document":request.read()?,"storage":{"relativePath":"toolchains/global.json","maximumBytes":MAX_BYTES}}), + ) +} + +/// Merges only the confirmed tools, preserving all dormant registrations. +pub(crate) fn edit(input: &Value) -> Validation { + let request: EditRequest = + serde_json::from_value(input.clone()).map_err(|_| invalid("input"))?; + if request.edits.is_empty() || request.edits.len() > 64 { + return Err(invalid("edits")); + } + let source = Request { + document: request.document, + platform: request.platform, + filesystem_case_sensitive: request.filesystem_case_sensitive, + }; + let mut catalog = source.read()?; + let original = catalog.clone(); + let mut tools = BTreeSet::new(); + for edit in request.edits { + if !is_tool_id(&edit.tool) || !tools.insert(edit.tool.clone()) { + return Err(invalid("tool")); + } + let entry = source.entry(&edit.homes, &edit.default_home)?; + if entry.homes.is_empty() && entry.default_home.is_none() { + catalog.tools.remove(&edit.tool); + } else { + catalog.tools.insert(edit.tool, entry); + } + } + if catalog.tools.len() > 64 { + return Err(invalid("tools")); + } + let changed = catalog != original; + let document = if changed { + let text = serde_json::to_string_pretty(&catalog).map_err(|_| invalid("document"))? + "\n"; + if text.len() > MAX_BYTES { + return Err(invalid("document")); + } + Some(text) + } else { + None + }; + Ok(json!({"changed":changed,"document":document,"catalog":catalog})) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn registrations_and_defaults_are_independent_of_projects() { + let initial = json!({"document":null,"platform":"macos"}); + assert_eq!(state(&initial).unwrap()["document"]["tools"], json!({})); + let result = edit(&json!({"document":null,"platform":"macos","edits":[{"tool":"vm","homes":["/sdk/8","/sdk/17"],"defaultHome":"/sdk/17"}]})).unwrap(); + assert_eq!( + result["catalog"]["tools"]["vm"]["homes"], + json!(["/sdk/8", "/sdk/17"]) + ); + let reset = edit(&json!({"document":result["document"],"platform":"macos","edits":[{"tool":"vm","homes":["/sdk/8","/sdk/17"],"defaultHome":null}]})).unwrap(); + assert!(reset["catalog"]["tools"]["vm"].get("defaultHome").is_none()); + assert_eq!( + reset["catalog"]["tools"]["vm"]["homes"] + .as_array() + .unwrap() + .len(), + 2 + ); + } + + #[test] + fn unchanged_automatic_state_creates_no_document_and_preserves_other_tools() { + let result = edit(&json!({"document":null,"platform":"linux","edits":[{"tool":"vm","homes":[],"defaultHome":null}]})).unwrap(); + assert_eq!(result["changed"], false); + assert_eq!(result["document"], Value::Null); + let result = edit(&json!({"document":"{\"version\":1,\"tools\":{\"other\":{\"homes\":[\"/sdk/other\"]}}}","platform":"linux","edits":[{"tool":"vm","homes":[],"defaultHome":"/sdk/chosen"}]})).unwrap(); + assert_eq!( + result["catalog"]["tools"]["other"]["homes"], + json!(["/sdk/other"]) + ); + assert_eq!( + result["catalog"]["tools"]["vm"]["homes"], + json!(["/sdk/chosen"]) + ); + } + + #[test] + fn windows_aliases_unknown_fields_and_duplicate_keys_are_rejected() { + for document in [ + r#"{"version":1,"version":1,"tools":{}}"#, + r#"{"version":1,"tools":{},"private":true}"#, + r#"{"version":1,"tools":{"vm":{"homes":["C:/SDK","c:\\sdk"]}}}"#, + ] { + assert!(state(&json!({"document":document,"platform":"windows"})).is_err()); + } + assert!(edit(&json!({"document":null,"platform":"macos","edits":[{"tool":"vm","homes":["../sdk"],"defaultHome":null}]})).is_err()); + } +} diff --git a/rust/crates/toolchain/src/lib.rs b/rust/crates/toolchain/src/lib.rs index a49f86b5..45d9118d 100644 --- a/rust/crates/toolchain/src/lib.rs +++ b/rust/crates/toolchain/src/lib.rs @@ -2,6 +2,7 @@ //! //! No manager configuration, native scanning or process lifecycle belongs here. +mod catalog; pub mod definitions; pub mod fixed; pub mod paths; @@ -166,3 +167,13 @@ pub fn candidates_command( "candidates", ) } + +/// Reads bounded machine-wide SDK registrations without project context or native I/O. +pub fn catalog_state_command(input: Value) -> Result { + command(input, catalog::state, "state") +} + +/// Plans a complete conditional edit of the machine-wide SDK registry. +pub fn edit_catalog_command(input: Value) -> Result { + command(input, catalog::edit, "edit") +} diff --git a/rust/crates/toolchain/src/resolution.rs b/rust/crates/toolchain/src/resolution.rs index 65b21d9f..8d3b25a5 100644 --- a/rust/crates/toolchain/src/resolution.rs +++ b/rust/crates/toolchain/src/resolution.rs @@ -37,6 +37,7 @@ pub(crate) fn resolve(input: &Value, validate_manifest: ManifestValidator) -> Va "platform", "filesystemCaseSensitive", "workspaceRoot", + "global", "workspaceRoots", "filesystem", "minimumVersion", @@ -69,6 +70,15 @@ pub(crate) fn resolve(input: &Value, validate_manifest: ManifestValidator) -> Va .get("local") .cloned() .unwrap_or(json!({"version":1,"toolchains":{}})); + if input["global"] == true + && ["toolchains", "pins"].iter().any(|key| { + document[*key] + .as_object() + .is_some_and(|value| !value.is_empty()) + }) + { + return Err(reject("local")); + } let pin = pins::resolve(&json!({"document":document,"directory":directory,"tool":tool}))?; let fixed = input .get("fixed") @@ -270,6 +280,13 @@ pub(crate) fn resolve(input: &Value, validate_manifest: ManifestValidator) -> Va let mut default_checked = !default_preflight; for candidate in &candidates { let kind = candidate["kind"].as_str().unwrap_or(""); + if input["global"] == true + && (kind == "projectFile" + || (kind == "setting" && candidate["layer"] == "project") + || (kind == "toolchain" && candidate["scope"] == "project")) + { + continue; + } let id = candidate["id"].as_str().unwrap_or(kind); let layer = match kind { "setting" if candidate["layer"] == "project" => "pinned", diff --git a/rust/crates/toolchain/src/resolution/automatic.rs b/rust/crates/toolchain/src/resolution/automatic.rs index 28fe9b71..2b2ed459 100644 --- a/rust/crates/toolchain/src/resolution/automatic.rs +++ b/rust/crates/toolchain/src/resolution/automatic.rs @@ -125,6 +125,7 @@ pub(crate) fn candidates(input: &Value, validate_manifest: ManifestValidator) -> "platform", "filesystemCaseSensitive", "workspaceRoot", + "global", "workspaceRoots", "filesystem", "minimumVersion", diff --git a/rust/crates/toolchain/src/resolution/project.rs b/rust/crates/toolchain/src/resolution/project.rs index 54cd60c7..30bb419c 100644 --- a/rust/crates/toolchain/src/resolution/project.rs +++ b/rust/crates/toolchain/src/resolution/project.rs @@ -120,11 +120,27 @@ pub(crate) fn prepare<'a>( }) .transpose()? .unwrap_or(platform != "windows"); - let root = input["workspaceRoot"] - .as_str() - .and_then(|root| paths::normalize(root, platform, true)) - .ok_or_else(|| reject("workspaceRoot"))?; - let mut roots = vec![root.clone()]; + let global = input + .get("global") + .map(|value| value.as_bool().ok_or_else(|| reject("global"))) + .transpose()? + .unwrap_or(false); + let root = if global { + if input["workspaceRoot"] != "" { + return Err(reject("workspaceRoot")); + } + String::new() + } else { + input["workspaceRoot"] + .as_str() + .and_then(|root| paths::normalize(root, platform, true)) + .ok_or_else(|| reject("workspaceRoot"))? + }; + let mut roots = if global { + Vec::new() + } else { + vec![root.clone()] + }; for value in array(input, "workspaceRoots", 64)? { roots.push( value @@ -169,11 +185,12 @@ pub(crate) fn prepare<'a>( snapshot.validate_facts()?; snapshot.targets = query::implied_targets(facts, platform, case_sensitive) .map_err(|_| reject("filesystem"))?; - if snapshot.key( - snapshot.fact(&root, "directory")?["canonicalPath"] - .as_str() - .ok_or_else(|| reject("workspaceRoot"))?, - )? != snapshot.key(&root)? + if !global + && snapshot.key( + snapshot.fact(&root, "directory")?["canonicalPath"] + .as_str() + .ok_or_else(|| reject("workspaceRoot"))?, + )? != snapshot.key(&root)? { return Err(reject("workspaceRoot")); } diff --git a/rust/fixtures/toolchain-global-catalog.json b/rust/fixtures/toolchain-global-catalog.json new file mode 100644 index 00000000..628581c4 --- /dev/null +++ b/rust/fixtures/toolchain-global-catalog.json @@ -0,0 +1,61 @@ +{ + "schemaVersion": 1, + "cases": [ + { + "name": "missing-global-source-is-read-only", + "command": "toolchains.catalogState", + "input": { + "document": null, + "platform": "macos" + }, + "expected": { + "status": "ok", + "state": { + "document": { + "version": 1, + "tools": {} + }, + "storage": { + "relativePath": "toolchains/global.json", + "maximumBytes": 262144 + } + } + } + }, + { + "name": "automatic-without-registrations-creates-no-file", + "command": "toolchains.editCatalog", + "input": { + "document": null, + "platform": "linux", + "edits": [ + { + "tool": "vm", + "homes": [], + "defaultHome": null + } + ] + }, + "expected": { + "status": "ok", + "edit": { + "changed": false, + "document": null, + "catalog": { + "version": 1, + "tools": {} + } + } + } + }, + { + "name": "windows-aliases-refused", + "command": "toolchains.catalogState", + "input": { + "document": "{\"version\":1,\"tools\":{\"vm\":{\"homes\":[\"C:/SDK\",\"c:\\\\sdk\"]}}}", + "platform": "windows" + }, + "error": "plugin.toolchain.invalidDocument" + } + ] +}