From 872073a0a05b06f5bb3727879fd1f60aa90c5196 Mon Sep 17 00:00:00 2001 From: Dasemu Date: Mon, 26 Oct 2026 06:52:44 +0100 Subject: [PATCH] fix(core): clearing an undefined type's icon defines nothing Also covers that renaming a plain tag leaves an undefined (suggested) type of that name alone. Co-Authored-By: Claude Opus 5.5 --- crates/synapse-core/src/types.rs | 7 ++++--- crates/synapse-core/tests/structure.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/synapse-core/src/types.rs b/crates/synapse-core/src/types.rs index d504f65..8c6f801 100644 --- a/crates/synapse-core/src/types.rs +++ b/crates/synapse-core/src/types.rs @@ -245,8 +245,8 @@ impl Graph { Ok(name) } - /// Sets (or with `None` clears) the emoji of a type, defining the type if needed (see - /// [`normalize_icon`] for what an icon may be). + /// Sets (or with `None` clears) the emoji of a type, defining the type when setting one + /// (see [`normalize_icon`] for what an icon may be). Clearing an undefined type is a no-op. pub fn set_type_icon(&self, name: &str, icon: Option<&str>) -> Result<()> { let name = checked_type_name(name)?; let icon = match icon { @@ -255,7 +255,8 @@ impl Graph { }; let tx = self.tx()?; let current = self.type_def(&name)?.filter(|d| !d.removed); - if current.as_ref().is_some_and(|d| d.icon == icon) { + // Clearing the icon of an undefined type changes nothing (and defines nothing). + if current.as_ref().map_or(icon.is_none(), |d| d.icon == icon) { tx.commit()?; return Ok(()); } diff --git a/crates/synapse-core/tests/structure.rs b/crates/synapse-core/tests/structure.rs index 2d3b2b0..e425f70 100644 --- a/crates/synapse-core/tests/structure.rs +++ b/crates/synapse-core/tests/structure.rs @@ -1089,6 +1089,29 @@ fn renaming_a_type_keeps_its_icon_and_removing_drops_it() { assert_eq!(type_row(&g, "lugar"), Some(("lugar".into(), 1, None))); } +#[test] +fn renaming_a_tag_leaves_undefined_types_alone() { + let (_d, g) = graph(); + let a = page(&g, "A", &["x"]); + g.add_page_tag(a, "idea").unwrap(); + let seq = g.last_seq().unwrap(); + g.rename_tag("idea", "ocurrencia").unwrap(); + // "idea" is only a suggestion (no definition): it stays offered, nothing is defined. + assert_eq!(type_row(&g, "idea"), Some(("idea".into(), 0, None))); + assert!(g.type_defs().unwrap().is_empty()); + assert!( + g.ops_since(seq, 100) + .unwrap() + .iter() + .all(|r| !matches!(r.op, Op::PutTypeDef { .. })) + ); + // Clearing the icon of an undefined type is a no-op. + g.set_type_icon("idea", None).unwrap(); + g.set_type_icon("nueva", None).unwrap(); + assert!(g.type_defs().unwrap().is_empty()); + assert_eq!(type_row(&g, "nueva"), None); +} + #[test] fn tag_catalog_says_where_each_tag_comes_from() { let (_d, g) = graph();