Delete in a rolled-back history warns about the features after the marker (#3471) (#3698)

* claim: #3471

* Delete in a rolled-back history warns about the features after the marker (#3471)

With the timeline rolled back, the checks a delete runs first (the
confirmation's "these features will fail", timeline.dependents and
selection.delete's would_fail) compared models evaluated only up to the
marker. Features after it, broken by the delete, were not listed, so their
error marks turned up only once the timeline moved to the end.

newly_broken_in_history evaluates both sides over the whole history when
either has a marker (on copies; the model and document are unchanged) and is
used by the delete's report and by timeline.dependents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HiroKenEz
2026-10-23 14:22:52 +00:00
committed by GitHub
parent 426f8ddd18
commit efb45d7411
2 changed files with 59 additions and 8 deletions
+34 -7
View File
@@ -61,6 +61,7 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
}
}
let before = s.model.clone();
let before_doc = s.doc.clone();
let mut joints = p
.get("joints")
.and_then(Value::as_array)
@@ -182,13 +183,9 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
}
s.refresh();
let deleted: Vec<&String> = features_before.iter().filter(|(id, _)| s.doc.feature(*id).is_none()).map(|(_, n)| n).collect();
let would_fail: Vec<String> = s
.model
.results
.iter()
.filter(|r| r.error.is_some() && before.result(r.id).is_some_and(|b| b.error.is_none() && !b.skipped))
.map(|r| r.name.clone())
.collect();
// Features after a rolled-back marker count too (#3471).
let would_fail: Vec<String> =
super::edit::newly_broken_in_history(&before_doc, &before, &s.doc, &s.model).into_iter().map(|(name, _)| name).collect();
Ok(json!({ "deleted": deleted, "deleted_joints": joints, "bodies": bodies, "would_fail": would_fail, "skipped": skipped }))
}
@@ -235,6 +232,36 @@ mod tests {
assert_eq!(bodies(&s), 2);
}
/// With the history rolled back, the checks before a delete look past the marker too (#3471):
/// deleting the plate (or its extrude) there breaks the hole cut after the marker, and the
/// confirmation must say so instead of the hole's error mark turning up only at the end.
#[test]
fn the_checks_before_a_delete_in_a_rolled_back_history_see_the_features_after_the_marker() {
let mut s = Session::default();
run(&mut s, "sketch.create", json!({"plane": "XY"}));
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 20]}));
run(&mut s, "sketch.finish", json!({}));
run(&mut s, "solid.extrude", json!({"distance": 5, "name": "Plate"}));
run(&mut s, "solid.cylinder", json!({"base": [20, 10, -1], "radius": 2, "height": 10, "operation": "cut", "name": "Hole"}));
let body = s.model.state().bodies[0].name.clone();
let plate = s.doc.find_feature("Plate").unwrap().id;
for marker in [None, Some(2)] {
run(&mut s, "timeline.roll_to", marker.map_or(json!({}), |m| json!({"position": m})));
let doc = s.doc.clone();
let dry = run(&mut s, "selection.delete", json!({"items": [{"type": "body", "name": body}], "dry_run": true}));
// At the end the plate's Remove goes after the hole; rolled back, before it.
let breaks = if marker.is_some() { json!(["Hole"]) } else { json!([]) };
assert_eq!(dry["would_fail"], breaks, "marker {marker:?}: {dry}");
let deps = run(&mut s, "timeline.dependents", json!({"feature": plate}));
assert_eq!(deps["would_fail"], json!(["Hole"]), "marker {marker:?}: {deps}");
assert_eq!(*s.doc, *doc, "the checks change nothing");
assert!(s.model.result(s.doc.find_feature("Hole").unwrap().id).is_some_and(|r| r.skipped == marker.is_some() && r.error.is_none()));
}
// Deleting anyway (rolled back) still reports what it broke.
let done = run(&mut s, "selection.delete", json!({"items": [{"type": "body", "name": body}]}));
assert_eq!(done["would_fail"], json!(["Hole"]), "{done}");
}
#[test]
fn mixed_selection_is_one_undo_step() {
let (mut s, _) = part();
+25 -1
View File
@@ -1077,6 +1077,30 @@ fn newly_broken(before: &solidcraft_doc::Model, after: &solidcraft_doc::Model) -
.collect()
}
/// [`newly_broken`] over the whole history, from `before` (the model of `before_doc`) to `after`
/// (the model of `after_doc`). With the history rolled back, the features after the marker are
/// evaluated too, on copies of the models (which share their cache): a delete made in the
/// rolled-back history that breaks them says so before it is made, rather than leaving error marks
/// that only show at the end of the timeline (#3471).
pub(super) fn newly_broken_in_history(
before_doc: &solidcraft_doc::Document,
before: &solidcraft_doc::Model,
after_doc: &solidcraft_doc::Document,
after: &solidcraft_doc::Model,
) -> Vec<(String, String)> {
if before_doc.marker.is_none() && after_doc.marker.is_none() {
return newly_broken(before, after);
}
let whole = |doc: &solidcraft_doc::Document, model: &solidcraft_doc::Model| {
let mut doc = doc.clone();
doc.marker = None;
let mut model = model.clone();
model.evaluate(&doc);
model
};
newly_broken(&whole(before_doc, before), &whole(after_doc, after))
}
fn reorder(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "timeline.reorder";
let id = feature_id(s, p.get("feature"), cmd)?;
@@ -1406,7 +1430,7 @@ fn dependents(s: &mut Session, p: &Value) -> Result<Value> {
let mut after = s.model.clone();
after.evaluate(&next);
let names = |ids: &[u64]| -> Vec<String> { ids.iter().filter(|x| **x != id).filter_map(|x| s.doc.feature(*x).map(|f| f.name.clone())).collect() };
let broken: Vec<String> = newly_broken(&s.model, &after).into_iter().map(|(n, _)| n).collect();
let broken: Vec<String> = newly_broken_in_history(&s.doc, &s.model, &next, &after).into_iter().map(|(n, _)| n).collect();
Ok(json!({"deleted_with_it": names(&gone), "would_fail": broken}))
}