Skip to content

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

Tests: the autosave scenario crashes once its autosave has landed (#10690) (#10694)

austin62jake75c46dad7be5
diff --git a/crates/engine/src/recovery.rs b/crates/engine/src/recovery.rs
index 59b349935d..e05c079fb3 100644
--- a/crates/engine/src/recovery.rs
+++ b/crates/engine/src/recovery.rs
@@ -283,6 +283,14 @@ impl Autosaver {
Ok(true)
}
+ /// Whether the last autosave holds `s` as it is now, with no write still running: what a
+ /// crash now would leave for the next launch to offer. A finished write counts once a
+ /// [`Self::tick`] has taken its outcome.
+ pub fn caught_up(&self, s: &Session) -> bool {
+ self.writing.is_none()
+ && self.last.as_ref().is_some_and(|(doc, visibility)| (Arc::ptr_eq(doc, &s.doc) || **doc == *s.doc) && *visibility == s.visibility)
+ }
+
/// Autosave when the interval has passed, or right away after a big operation. The design
/// is written on a worker thread; true when this call started a write.
pub fn tick(&mut self, s: &Session, big: bool) -> Result<bool> {
diff --git a/crates/ui-egui/src/scenario.rs b/crates/ui-egui/src/scenario.rs
index e8c9c333a4..277466f1ca 100644
--- a/crates/ui-egui/src/scenario.rs
+++ b/crates/ui-egui/src/scenario.rs
@@ -595,6 +595,20 @@ impl Harness {
} else if let Some(how) = s.get("restart").and_then(Value::as_str) {
// "crash": the app dies (its autosave lock goes with it, the entry stays);
// "close": it closes normally. Then a new app starts on the same folders.
+ if how == "crash" {
+ // The work so far is autosaved before the crash: the write runs on a worker
+ // thread, which a loaded machine had not finished (#10690). The autosave's
+ // own ticks write it; a bounded wait, so an autosave that stopped writing
+ // still fails the recovery that follows.
+ for _ in 0..600 {
+ let caught_up = self.app.autosave.as_ref().and_then(|a| a.active.as_ref()).is_none_or(|a| a.caught_up(&self.app.session));
+ if caught_up {
+ break;
+ }
+ std::thread::sleep(std::time::Duration::from_millis(5));
+ self.frames(1);
+ }
+ }
let mut old = std::mem::replace(&mut self.app, SolveApp::new(Session::default(), Services::default()));
if how == "close" {
crate::recovery_ui::close(&mut old);