diff --git a/crates/ui-egui/src/control_job.rs b/crates/ui-egui/src/control_job.rs index 33829820f..0d736291e 100644 --- a/crates/ui-egui/src/control_job.rs +++ b/crates/ui-egui/src/control_job.rs @@ -413,9 +413,19 @@ impl SolveApp { if let Some(level) = level { copy.param_check = level; } + // The copy has no history and no file (#9624): an inspection reports the design's own. + let s = &self.session; + let own = (id == "document.inspect").then(|| (s.undo.len(), s.redo.len(), s.path.clone())); let rx = spawn(scope, move || { let mut reply = match copy.execute(id, ¶ms) { - Ok(v) => json!({"ok": true, "result": v}), + Ok(mut v) => { + if let (Some((undo, redo, path)), Some(o)) = (own, v.as_object_mut()) { + o.insert("undo".into(), json!(undo)); + o.insert("redo".into(), json!(redo)); + o.insert("path".into(), json!(path)); + } + json!({"ok": true, "result": v}) + } Err(e) => json!({"ok": false, "error": e.to_string()}), }; if let Some(level) = level { diff --git a/crates/ui-egui/src/history_off_thread_tests.rs b/crates/ui-egui/src/history_off_thread_tests.rs index 702b72bce..14391fdb9 100644 --- a/crates/ui-egui/src/history_off_thread_tests.rs +++ b/crates/ui-egui/src/history_off_thread_tests.rs @@ -682,6 +682,42 @@ fn a_measure_reads_a_copy_off_the_window_thread_preference_or_not() { assert_eq!(h.app.session.log.len(), log, "a reading leaves no echo: {:?}", h.app.session.log); } +/// #9624: an inspection read on a copy reports the design's undo and redo counts and its file, +/// as one run here does; the copy has no history and no file, and it said undo 0, redo 0, path +/// none, so an agent could not tell how far to roll back a failed batch. +#[test] +fn an_inspection_on_a_copy_reports_the_history_and_the_file() { + let mut h = Harness::new(); + h.app.home.open = false; + h.app.apply_off_thread = Some(Duration::ZERO); + let (tx, rx) = std::sync::mpsc::channel(); + h.app.control_rx = Some(rx); + let inspect = |h: &mut Harness| { + let reply = ask(&tx, "document.inspect", json!({})); + h.frames(1); + assert_eq!(h.app.control_answering.len(), 1, "read a copy"); + let r = reply_to(h, &reply); + assert_eq!(r["ok"], true, "{r}"); + let here = h.app.run("document.inspect", json!({})).unwrap(); + for key in ["undo", "redo", "path"] { + assert_eq!(r["result"][key], here[key], "{key}: {r}"); + } + (r["result"]["undo"].clone(), r["result"]["redo"].clone(), r["result"]["path"].clone()) + }; + for corner in [[0, 0, 0], [20, 0, 0]] { + h.app.run("solid.box", json!({"corner": corner, "length": 10, "width": 10, "height": 10})).unwrap(); + } + assert_eq!(inspect(&mut h), (json!(2), json!(0), json!(null))); + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(inspect(&mut h), (json!(1), json!(1), json!(null))); + let path = h.dir.join("boxes.solidcraft"); + h.app.run("file.save_as", json!({"path": path})).unwrap(); + let (undo, redo, saved) = inspect(&mut h); + assert_eq!((undo, redo), (json!(1), json!(1))); + assert_eq!(saved, json!(h.app.session.path), "the file it was saved to"); + assert!(saved.as_str().is_some_and(|p| p.ends_with("boxes.solidcraft")), "{saved}"); +} + /// A reading on a copy keeps the request's own `param_check` (#9184), as one run here does: its /// reply says the level, and a word that is no level is refused. #[test]