Integration: a failed script rolls back instead of leaving an undo step

main rolls a half-run script back (#709); next's #406 test expected the
successful prefix to stay as an undo step. Both keep a partial edit from being
stranded; the script keeps main's rollback, and the test checks that. The
generic partial-failure undo step stays covered by the fillWithPlaceholder test.
This commit is contained in:
aiongg
2026-10-16 03:31:05 +00:00
parent 0209b6781b
commit fa3d13ae5a
+7 -7
View File
@@ -128,19 +128,19 @@ fn a_command_that_runs_another_is_one_undo_step() {
one_step(&mut s, "script.run", json!({"text": script}), "Run Script");
}
/// What a command did before it failed is an undo step too: a script that stopped at a bad
/// step left its earlier steps in the document with nothing to undo.
/// A command that fails partway strands no edits without an undo step: a script that stops at
/// a bad step rolls its earlier steps back (#709). A command that leaves its partial edit in the
/// document records an undo step for it (next test).
#[test]
fn a_command_that_fails_partway_can_be_undone() {
fn a_command_that_fails_partway_strands_no_edits() {
let mut s = session();
let before = s.doc().unwrap().doc.clone();
let script = "frame.create {\"rect\": [36, 36, 136, 136]}\nnope.command";
assert!(s.execute("script.run", &json!({"text": script})).is_err());
let st = s.doc().unwrap();
assert_eq!(st.doc.spreads[0].items.len(), 1, "the first step ran");
assert_eq!(st.history.undo.len(), 1);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc, before);
assert_eq!(st.doc, before, "the first step was rolled back");
assert!(st.history.undo.is_empty());
assert!(s.execute("edit.undo", &json!({})).is_err(), "nothing was left to undo");
// The next command records its step as usual.
s.execute("frame.create", &json!({"rect": [36, 36, 136, 136]})).unwrap();
assert_eq!(s.doc().unwrap().history.undo.len(), 1);