From 5edc81e54873b0dfab9fce13c1d01ab234d5a7a7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 12:31:42 -0800 Subject: [PATCH] Plug-ins: a null translations map is refused A manifest that gives `null` for `translations` or for one of its maps (`params`, `groups`, `commands`, `options`) is refused with an error instead of being read as empty. The palette test of translated plug-in commands uses names no other test's plug-in has. --- crates/plugins/src/translations.rs | 9 ++++++--- crates/ui-egui/src/palette.rs | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/plugins/src/translations.rs b/crates/plugins/src/translations.rs index 76c8f65046..849b6b2905 100644 --- a/crates/plugins/src/translations.rs +++ b/crates/plugins/src/translations.rs @@ -64,9 +64,6 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Entries { fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.write_str("an object") } - fn visit_unit(self) -> std::result::Result { - Ok(Entries::default()) - } fn visit_map>(self, mut map: A) -> std::result::Result { let mut seen = HashSet::new(); let mut out = Vec::new(); @@ -516,6 +513,12 @@ mod tests { (r#"{"de":{"name":7}}"#, "manifest"), (r#"["de"]"#, "manifest"), (r#""de""#, "manifest"), + ("null", "expected an object"), + (r#"{"de":null}"#, "manifest"), + (r#"{"de":{"params":null}}"#, "expected an object"), + (r#"{"de":{"groups":null}}"#, "expected an object"), + (r#"{"de":{"commands":null}}"#, "expected an object"), + (r#"{"de":{"params":{"mode":{"options":null}}}}"#, "expected an object"), ] { let e = Manifest::parse(with(translations).as_bytes()).unwrap_err().to_string(); assert!(e.contains(says), "{translations}: {e}"); diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 852c0ddeb3..c38ba36e0f 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -3319,9 +3319,10 @@ mod tests { fn a_plugin_command_result_shows_the_plugins_translation() { use vectorcraft_plugins::wat as tpl; let id = "test.UI.palette_translated"; + // Names no other test's plug-in has, since tests running beside this one share the registry. let manifest = format!( - r#"{{"id":"{id}","name":"Tidy","version":"1","kind":"filter","commands":[{{"id":"grow","label":"Grow"}}], - "translations":{{"de":{{"name":"Aufräumen","commands":{{"grow":{{"label":"Wachsen"}}}}}}}}}}"# + r#"{{"id":"{id}","name":"Groom","version":"1","kind":"filter","commands":[{{"id":"grow","label":"Expand Rim"}}], + "translations":{{"de":{{"name":"Pflegen","commands":{{"grow":{{"label":"Erweitern"}}}}}}}}}}"# ); vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap(); let key = format!("plugin.{id}.grow"); @@ -3332,9 +3333,9 @@ mod tests { let (de, fr) = (shown("de"), shown("fr")); vectorcraft_plugins::registry::remove(id); let (de, object, plugins) = de.expect("the command is a result"); - assert_eq!(de, format!("{object} › {plugins} › Aufräumen › Wachsen")); + assert_eq!(de, format!("{object} › {plugins} › Pflegen › Erweitern")); let (fr, object, plugins) = fr.expect("the command is a result"); - assert_eq!(fr, format!("{object} › {plugins} › Tidy › Grow")); + assert_eq!(fr, format!("{object} › {plugins} › Groom › Expand Rim")); } /// A plug-in command whose plug-in translates its name and label into English shows the