|
1 | 1 | use lithe_plugin_manifest::{ |
2 | | - discover_tests_command, language_server_launch_plan_command, resolve_settings_command, |
3 | | - run_plan_command, test_plan_command, validate_command, workspace_configuration_command, |
| 2 | + command_installer_default_directory_command, command_installer_plan_command, |
| 3 | + command_installer_requirements_command, discover_tests_command, |
| 4 | + language_server_launch_plan_command, resolve_settings_command, run_plan_command, |
| 5 | + test_plan_command, validate_command, workspace_configuration_command, |
4 | 6 | }; |
5 | 7 | use serde_json::{json, Value}; |
6 | 8 |
|
@@ -63,6 +65,10 @@ const PROJECT_GENERATOR_FIXTURE: &str = |
63 | 65 | contract_file!("fixtures/project-generators/project-generator.plugin.json"); |
64 | 66 | const PROJECT_GENERATOR_TOOL_FIXTURE: &str = |
65 | 67 | contract_file!("fixtures/project-generators/project-generator-tool-field.plugin.json"); |
| 68 | +const COMMAND_INSTALLER_FIXTURE: &str = |
| 69 | + contract_file!("fixtures/command-installers/command-installer.plugin.json"); |
| 70 | +const COMMAND_INSTALLER_PLANS: &str = |
| 71 | + contract_file!("fixtures/command-installers/command-installer-plans.json"); |
66 | 72 | const INVALID_MANIFESTS: &str = contract_file!("fixtures/manifest/invalid-manifests.json"); |
67 | 73 | const COMMAND_PLANS: &str = contract_file!("fixtures/languages/command-plans.json"); |
68 | 74 |
|
@@ -95,6 +101,7 @@ fn fixture(name: &str) -> Value { |
95 | 101 | "editor-providers.plugin.json" => EDITOR_PROVIDERS_FIXTURE, |
96 | 102 | "project-generator.plugin.json" => PROJECT_GENERATOR_FIXTURE, |
97 | 103 | "project-generator-tool-field.plugin.json" => PROJECT_GENERATOR_TOOL_FIXTURE, |
| 104 | + "command-installer.plugin.json" => COMMAND_INSTALLER_FIXTURE, |
98 | 105 | other => panic!("unknown fixture {other}"), |
99 | 106 | }; |
100 | 107 | serde_json::from_str(source).expect("fixture manifest is JSON") |
@@ -126,6 +133,7 @@ fn contract_fixtures_and_official_plugins_validate() { |
126 | 133 | LANGUAGE_SERVER_BACKEND_FIXTURE, |
127 | 134 | EDITOR_PROVIDERS_FIXTURE, |
128 | 135 | PROJECT_GENERATOR_TOOL_FIXTURE, |
| 136 | + COMMAND_INSTALLER_FIXTURE, |
129 | 137 | ] { |
130 | 138 | let outcome = validate(serde_json::from_str(source).unwrap()); |
131 | 139 | assert_eq!(outcome["status"], "ok", "{outcome}"); |
@@ -253,6 +261,93 @@ fn invalid_manifest_fixtures_report_their_stable_codes() { |
253 | 261 | } |
254 | 262 | } |
255 | 263 |
|
| 264 | +/// The command-installer commands answer the golden cases for this host's |
| 265 | +/// platform; `lithe-plugin-manifest` checks the same cases for every |
| 266 | +/// platform. |
| 267 | +#[test] |
| 268 | +fn command_installer_fixtures_match_on_this_host() { |
| 269 | + let plans: Value = serde_json::from_str(COMMAND_INSTALLER_PLANS).unwrap(); |
| 270 | + let platform = if cfg!(windows) { "windows" } else { "unix" }; |
| 271 | + for case in plans["cases"].as_array().unwrap() { |
| 272 | + let name = case["name"].as_str().unwrap(); |
| 273 | + let specific = &case["platforms"][platform]; |
| 274 | + let mut payload = json!({ "manifest": fixture("command-installer.plugin.json") }); |
| 275 | + for source in [&case["payload"], &specific["payload"]] { |
| 276 | + for (field, value) in source.as_object().into_iter().flatten() { |
| 277 | + payload[field] = value.clone(); |
| 278 | + } |
| 279 | + } |
| 280 | + for edit in case["manifestEdits"].as_array().into_iter().flatten() { |
| 281 | + let pointer = edit["path"].as_str().unwrap(); |
| 282 | + *payload["manifest"].pointer_mut(pointer).unwrap() = edit["value"].clone(); |
| 283 | + } |
| 284 | + let outcome = match case["operation"].as_str().unwrap() { |
| 285 | + "requirements" => command_installer_requirements_command(payload), |
| 286 | + "plan" => command_installer_plan_command(payload), |
| 287 | + "defaultDirectory" => command_installer_default_directory_command(payload), |
| 288 | + other => panic!("unknown operation {other}"), |
| 289 | + } |
| 290 | + .expect("payload is well formed"); |
| 291 | + let expected = if specific.get("expected").is_some() { |
| 292 | + &specific["expected"] |
| 293 | + } else { |
| 294 | + &case["expected"] |
| 295 | + }; |
| 296 | + if expected["status"] == "rejected" { |
| 297 | + assert_eq!(outcome["status"], "rejected", "{name}: {outcome}"); |
| 298 | + assert_eq!( |
| 299 | + outcome["error"]["code"], expected["code"], |
| 300 | + "{name}: {outcome}" |
| 301 | + ); |
| 302 | + assert_eq!( |
| 303 | + outcome["error"]["field"], expected["field"], |
| 304 | + "{name}: {outcome}" |
| 305 | + ); |
| 306 | + } else { |
| 307 | + assert_eq!(&outcome, expected, "{name}"); |
| 308 | + } |
| 309 | + } |
| 310 | +} |
| 311 | + |
| 312 | +/// The install review shows everything an installer runs, so changing its |
| 313 | +/// arguments or targets is a new program the user approves again. |
| 314 | +#[test] |
| 315 | +fn command_installers_are_reviewed_programs() { |
| 316 | + let programs = |manifest: Value| { |
| 317 | + let outcome = lithe_plugin_marketplace::install_review_command(json!({ |
| 318 | + "manifest": manifest, |
| 319 | + })) |
| 320 | + .expect("payload is well formed"); |
| 321 | + outcome["review"]["programs"].as_array().unwrap().clone() |
| 322 | + }; |
| 323 | + let manifest = fixture("command-installer.plugin.json"); |
| 324 | + let before = programs(manifest.clone()); |
| 325 | + let installers: Vec<&Value> = before |
| 326 | + .iter() |
| 327 | + .filter(|program| program["kind"] == "commandInstaller") |
| 328 | + .collect(); |
| 329 | + assert_eq!(installers.len(), 2); |
| 330 | + assert_eq!(installers[0]["installer"], "sample-dap"); |
| 331 | + assert_eq!(installers[1]["timeoutSeconds"], 300); |
| 332 | + let mut changed = manifest; |
| 333 | + changed["commandInstallers"][0]["arguments"] = json!(["install", "example.org/other@latest"]); |
| 334 | + assert_ne!(programs(changed), before); |
| 335 | +} |
| 336 | + |
| 337 | +/// A malformed request is a Core failure, not a rejection. |
| 338 | +#[test] |
| 339 | +fn command_installer_requests_decode_strictly() { |
| 340 | + let manifest = fixture("command-installer.plugin.json"); |
| 341 | + assert!(command_installer_plan_command( |
| 342 | + json!({ "manifest": manifest, "installerID": "sample-ls", "target": "elsewhere" }) |
| 343 | + ) |
| 344 | + .is_err()); |
| 345 | + assert!(command_installer_default_directory_command( |
| 346 | + json!({ "manifest": manifest, "installerID": "sample-ls" }) |
| 347 | + ) |
| 348 | + .is_err()); |
| 349 | +} |
| 350 | + |
256 | 351 | #[test] |
257 | 352 | fn command_plan_fixtures_match_golden_expansions() { |
258 | 353 | let fixtures: Value = serde_json::from_str(COMMAND_PLANS).unwrap(); |
|
0 commit comments