diff --git a/crates/doc/src/lineage.rs b/crates/doc/src/lineage.rs index 770deffe3..dcec64f0e 100644 --- a/crates/doc/src/lineage.rs +++ b/crates/doc/src/lineage.rs @@ -587,10 +587,14 @@ pub(crate) fn order_lumps(bodies: &mut [crate::ModelBody], origin: &Arc> = members.iter().map(|i| bodies.get(*i).and_then(least).map(|k| (k, *i))).collect(); let Some(mut keys) = keys else { continue }; keys.sort(); - let names: Vec = members.iter().filter_map(|i| bodies.get(*i).map(|b| b.name.clone())).collect(); - for (name, (_, i)) in names.into_iter().zip(keys) { + // A name moves with the feature it belongs to: in a cut's family the first name is the + // cut body's own feature's and the rest are the cut's, and `body.rename` stores a name in + // the `body_names` of the feature a body says made it (#10438). + let names: Vec<(String, u64)> = members.iter().filter_map(|i| bodies.get(*i).map(|b| (b.name.clone(), b.feature))).collect(); + for ((name, feature), (_, i)) in names.into_iter().zip(keys) { if let Some(b) = bodies.get_mut(i) { b.name = name; + b.feature = feature; } } } diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rs index 62f35bf28..c1a64c2dc 100644 --- a/crates/engine/src/cmd/browser.rs +++ b/crates/engine/src/cmd/browser.rs @@ -1588,10 +1588,18 @@ mod tests { assert_eq!(sorted(names(&s)), ["A", "B", "B (1)", "Cutter"]); run(&mut s, "body.rename", json!({"body": "B (1)", "name": "B2"})); assert_eq!(sorted(names(&s)), ["A", "B", "B2", "Cutter"]); + // The new name is the cut's second piece's, stored by the cut, not in the members' slots. + let stored = |id: u64| s.doc.features.iter().find(|f| f.id == id).map(|f| f.body_names.clone()).unwrap_or_default(); + assert!(!stored(2).contains(&"B2".to_string()), "members: {:?}", stored(2)); + assert_eq!(stored(4), ["B2"], "the cut stores its piece's name"); run(&mut s, "file.save_as", json!({"path": saved.to_string_lossy()})); let mut reopened = Session::default(); run(&mut reopened, "doc.open", json!({"path": saved.to_string_lossy()})); assert_eq!(sorted(names(&reopened)), ["A", "B", "B2", "Cutter"], "the rename must not move to member A on rebuild"); + // `solidcraft-cli eval` of the saved file rebuilds it from its features alone, with no + // saved model to take the names from (#10438). + let rebuilt = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap()); + assert_eq!(sorted(names(&rebuilt)), ["A", "B", "B2", "Cutter"], "a rebuild from the features alone keeps the rename too"); let _ = std::fs::remove_dir_all(&dir); }