Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

test(engine): a job applied during a later recording is not recorded there (#7289)

Korg1chb287a884f4ed
diff --git a/crates/engine/src/jobs_tests.rs b/crates/engine/src/jobs_tests.rs
index 2bcdda76f..f7e041ed9 100644
--- a/crates/engine/src/jobs_tests.rs
+++ b/crates/engine/src/jobs_tests.rs
@@ -605,3 +605,45 @@ fn an_inline_job_ctx_lets_another_thread_cancel_inline_work() {
s.set_inline_job_ctx(None);
s.execute("filter.blur.gaussianBlur", json!({"radius": 2})).unwrap();
}
+
+/// The command ids an action holds.
+fn action_steps(s: &mut Session, name: &str) -> Vec<String> {
+ let a = s.execute("actions.get", json!({"action": name})).unwrap();
+ a["steps"].as_array().unwrap().iter().map(|step| step[0].as_str().unwrap().to_string()).collect()
+}
+
+/// A job's result is recorded only by the recording it was started in: one started later keeps
+/// its own steps around it but doesn't pick up the older edit (#7289).
+#[test]
+fn a_job_lands_in_the_recording_it_was_started_in_only() {
+ // Started while recording A, applied after A stopped and B started.
+ let mut s = session(40, 30);
+ s.execute("actions.record", json!({"name": "A"})).unwrap();
+ let id = job(s.start("filter.blur.gaussianBlur", json!({"radius": 1})).unwrap());
+ s.execute("actions.stop", json!({})).unwrap();
+ s.execute("actions.record", json!({"name": "B"})).unwrap();
+ // B's own steps before and after the result lands stay in B (a new document, so the job's
+ // document is unchanged and its result applies).
+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
+ s.wait_job(id).unwrap();
+ s.execute("image.adjustments.desaturate", json!({})).unwrap();
+ s.execute("actions.stop", json!({})).unwrap();
+ assert!(action_steps(&mut s, "A").is_empty());
+ assert_eq!(action_steps(&mut s, "B"), ["file.new", "image.adjustments.desaturate"]);
+
+ // Started before any recording, applied while B records.
+ let mut s = session(40, 30);
+ let id = job(s.start("filter.blur.gaussianBlur", json!({"radius": 1})).unwrap());
+ s.execute("actions.record", json!({"name": "B"})).unwrap();
+ s.wait_job(id).unwrap();
+ s.execute("actions.stop", json!({})).unwrap();
+ assert!(action_steps(&mut s, "B").is_empty());
+
+ // Started and applied while A records: A has it, as before.
+ let mut s = session(40, 30);
+ s.execute("actions.record", json!({"name": "A"})).unwrap();
+ let id = job(s.start("filter.blur.gaussianBlur", json!({"radius": 1})).unwrap());
+ s.wait_job(id).unwrap();
+ s.execute("actions.stop", json!({})).unwrap();
+ assert_eq!(action_steps(&mut s, "A"), ["filter.blur.gaussianBlur"]);
+}