Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

File: a saved model whose booleans retried is taken on opening (#5286) (#5334)

dudedagger42ad8b2f91bb45
diff --git a/crates/doc/src/model_cache.rs b/crates/doc/src/model_cache.rs
index b5062aa501..9e597a1e21 100644
--- a/crates/doc/src/model_cache.rs
+++ b/crates/doc/src/model_cache.rs
@@ -25,6 +25,17 @@ const MAX_ITEMS: usize = 1_000_000;
/// Bodies and sketches all the states hold together, at most (a state is a list of clones).
const MAX_HELD: usize = 50_000_000;
+/// A feature's boolean retries as saved. The kernel leaves `rejected` out when it is empty, and
+/// the field has no default when read, so a saved model whose booleans retried was refused and
+/// the design evaluated on every open (#5286): an absent list is an empty one.
+fn saved_diagnostics(d: &Json) -> Result<kernel::BooleanDiagnostics> {
+ let mut d = d.clone();
+ if let Some(fields) = d.as_object_mut() {
+ fields.entry("rejected").or_insert_with(|| json!([]));
+ }
+ serde_json::from_value(d).map_err(|_| bad("saved model: diagnostics"))
+}
+
fn hex(v: u64) -> String {
format!("{v:016x}")
}
@@ -557,7 +568,7 @@ impl Model {
error: None,
warning: r.get("warning").map(|w| text(Some(w))).transpose()?,
boolean_diagnostics: match r.get("diagnostics") {
- Some(d) => serde_json::from_value(d.clone()).map_err(|_| bad("saved model: diagnostics"))?,
+ Some(d) => saved_diagnostics(d)?,
None => Default::default(),
},
ms,
diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs
index c8d582f26b..6321e2a3ff 100644
--- a/crates/engine/src/cmd/file.rs
+++ b/crates/engine/src/cmd/file.rs
@@ -864,6 +864,30 @@ mod tests {
std::fs::remove_file(format!("{}.bak", path.display())).unwrap();
}
+ /// #5286: a saved model whose feature records the boolean retries it took (as the kernel
+ /// writes them, with no `rejected` list when there were none) is taken on opening, not
+ /// refused and evaluated again.
+ #[test]
+ fn a_saved_model_with_boolean_retries_is_adopted() {
+ let mut session = Session::new(Document::new("Retried"));
+ session.execute("solid.box", &json!({"length":10,"width":20,"height":30})).unwrap();
+ let mut saved = saved_geometry(&session, &session.doc).unwrap();
+ // What a coplanar-face retry leaves in the file (a user's design, #5286).
+ let retry = json!({"events": [{"face_shift_mm": 0.6477, "rotation_rad": 0.0, "strategy": "coplanar_separation", "tolerance_mm": 0.0, "translation_mm": 0.0}], "truncated": false});
+ saved.records["features"][0]["diagnostics"] = retry;
+ let bytes =
+ solidcraft_io::write_design_container_with_cache(&session.doc, solidcraft_io::DesignCompression::Fast, None, Some(&saved)).unwrap();
+ let path = std::env::temp_dir().join(format!("solidcraft-saved-retries-{}.solidcraft", std::process::id()));
+ std::fs::write(&path, &bytes).unwrap();
+ let mut reopened = Session::default();
+ reopened.execute("doc.open", &json!({"path": path})).unwrap();
+ std::fs::remove_file(&path).unwrap();
+ assert!(reopened.model.results.iter().all(|r| r.ms == session.model.results[0].ms), "taken from the file, not evaluated");
+ let d = &reopened.model.results[0].boolean_diagnostics;
+ assert_eq!(d.events.len(), 1, "{d:?}");
+ assert!(d.rejected.is_empty());
+ }
+
#[test]
fn saved_model_needs_no_meshes_and_is_adopted_only_for_its_document() {
let mut session = Session::new(Document::new("Saved model"));