From 48a39ca7aa1c75c2adef3eb4b2e5cb032a87739a Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 29 Oct 2026 11:32:49 +0700 Subject: [PATCH] #1409: test that a continued batch reports only the live events of the steps that stayed --- .../engine/src/batch_continue_events_tests.rs | 33 +++++++++++++++++++ crates/engine/src/lib.rs | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 crates/engine/src/batch_continue_events_tests.rs diff --git a/crates/engine/src/batch_continue_events_tests.rs b/crates/engine/src/batch_continue_events_tests.rs new file mode 100644 index 000000000..280f9a696 --- /dev/null +++ b/crates/engine/src/batch_continue_events_tests.rs @@ -0,0 +1,33 @@ +//! A batch that goes on after a failed step (`onError: "continue"`) reports the live events of the +//! steps that stayed, not of the ones rolled back. + +use std::time::Duration; + +use serde_json::json; + +use crate::Session; + +#[test] +fn a_continued_batch_reports_only_the_events_of_steps_that_stayed() { + let mut s = Session::new(); + let before = s.events.latest(); + let r = s + .execute( + "command.batch", + &json!({"onError": "continue", "commands": [ + {"command": "comment.add", "params": {"x": 10, "y": 10, "text": "Stays"}}, + {"command": "command.batch", "params": {"commands": [ + {"command": "comment.add", "params": {"x": 20, "y": 20, "text": "Rolled back"}}, + {"command": "node.set", "params": {"ids": [999_999], "props": {"name": "x"}}} + ]}}, + {"command": "comment.add", "params": {"x": 30, "y": 30, "text": "Stays too"}} + ]}), + ) + .unwrap(); + let ok: Vec = r.as_array().unwrap().iter().map(|o| o["ok"].as_bool().unwrap()).collect(); + assert_eq!(ok, [true, false, true]); + let texts: Vec = s.doc().unwrap().comments.iter().map(|c| c.first.text.clone()).collect(); + assert_eq!(texts, ["Stays", "Stays too"]); + let events = s.events.poll(before, &["comments".into()], 10, Duration::ZERO).events; + assert_eq!(events.iter().map(|e| e.kind.as_str()).collect::>(), ["comment.added", "comment.added"]); +} diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 0db81fd1e..3797f904d 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -179,6 +179,8 @@ mod arc_handles_tests; #[cfg(test)] mod autosave_tests; #[cfg(test)] +mod batch_continue_events_tests; +#[cfg(test)] mod batch_rollback_tests; #[cfg(test)] mod batch_step_ref_tests;