diff --git a/crates/engine/src/crash_tests.rs b/crates/engine/src/crash_tests.rs index b7a9b5f00..4eafc050a 100644 --- a/crates/engine/src/crash_tests.rs +++ b/crates/engine/src/crash_tests.rs @@ -75,6 +75,15 @@ fn child() { "abort" => { let _ = s.execute("diagnostics.crash_test", &json!({"mode": "abort"})); } + // Back to the root between two components: only the session's active component changes. + "components" => { + s.execute("component.create", &json!({"name": "Tray"})).unwrap(); + s.execute("solid.box", &json!({"length": 5, "width": 5, "height": 5})).unwrap(); + s.execute("component.activate", &json!({"component": "root"})).unwrap(); + s.execute("component.create", &json!({"name": "Bracket"})).unwrap(); + s.execute("solid.box", &json!({"length": 4, "width": 4, "height": 4})).unwrap(); + let _ = s.execute("diagnostics.crash_test", &json!({"mode": "abort"})); + } _ => {} } end_session(); @@ -205,6 +214,27 @@ fn render_settings_survive_unclean_exit_and_journal_replay() { let _ = fs::remove_dir_all(&d); } +#[test] +fn activating_a_component_is_journaled_so_the_replay_builds_in_the_same_component() { + let d = fresh_dir("components"); + assert!(!run_child(&d, "components").1); + assert!(run_child(&d, "none").1); + let (_, report) = only_report(&d); + let replay: Value = serde_json::from_slice(&fs::read(report["replay_path"].as_str().unwrap()).unwrap()).unwrap(); + let commands = replay["commands"].as_array().unwrap(); + assert_eq!(commands.iter().filter(|c| c["command"] == "component.activate").count(), 1, "{replay}"); + let mut recovered = Session::default(); + for command in commands { + let id = command["command"].as_str().unwrap(); + if id != "diagnostics.crash_test" { + recovered.execute(id, &command["params"]).unwrap(); + } + } + let bracket = recovered.doc.components.iter().find(|c| c.name == "Bracket").unwrap(); + assert_eq!(bracket.parent, 0, "the Bracket was made under the root"); + let _ = fs::remove_dir_all(&d); +} + #[test] fn a_crash_while_starting_up_names_the_step_and_the_renderer() { let d = fresh_dir("startup"); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index d17776a45..0f4e14ddd 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -860,6 +860,8 @@ impl Session { active_sketch: self.active_sketch, pending_moves: self.pending_moves.clone(), }; + // Where new geometry goes: not in the design, but a replay needs it (component.activate). + let active_before = (self.active_component, self.active_occurrence_path.clone()); let null = Value::Object(Default::default()); let params = if params.is_null() { &null } else { params }; let given = params; @@ -898,6 +900,8 @@ impl Session { let changed = !Arc::ptr_eq(&self.doc, &before.doc) || self.active_sketch != before.active_sketch || self.pending_moves != before.pending_moves + || self.active_component != active_before.0 + || self.active_occurrence_path != active_before.1 || spec.id.starts_with("select."); crash::command_done(self.crash_journal, changed, &before.doc, after, spec.id, given, failed.map_or(Ok(()), Err)); }