PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7588: fix(atn): refuse strict export of options the descriptors can't carry
aionggb66199332f97
diff --cc crates/engine/src/atn_cmds.rsindex afba79302,595b15789..4170de955--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@@ -443,15 -435,15 +443,23 @@@ fn fields_to(p: &Value, fields: &[F], mKind::Px => px(v.as_f64()?),Kind::Pct => pct(v.as_f64()?),Kind::Ang => ang(v.as_f64()?),- Kind::Long => long(v.as_f64()?),+ // A value outside the descriptor's 32-bit integer refuses the step rather than being+ // clamped to another value (an Add Noise seed above i32::MAX replayed as i32::MAX, #7287).+ Kind::Long => {+ let n = v.as_f64()?.round();+ if !(f64::from(i32::MIN)..=f64::from(i32::MAX)).contains(&n) {+ return None;+ }+ long(n)+ }+ Kind::ExactLong => {+ let number = v.as_f64()?;+ let integer = number as i32;+ if f64::from(integer) != number {+ return None;+ }+ D::Integer(integer)+ }Kind::Dbl => D::Double(v.as_f64()?),Kind::Bool => D::Boolean(v.as_bool()?),Kind::Enum(ty, table) => enm(ty, lookup_back(table, v.as_str()?)?),diff --cc crates/engine/src/atn_cmds/tests.rsindex bbec1def4,09d90027e..715fabb8e--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@@ -1558,28 -1267,78 +1558,99 @@@ fn save_while_recording_includes_pendinassert_eq!(action["steps"].as_array().unwrap().len(), 2, "both steps must be present without duplication");}+/// #7233: the Minimum / Maximum descriptor carries the radius only, so a step with Preserve:+/// Roundness is refused by strict export (and left out, reported, otherwise) instead of replaying+/// as the default Squareness. Squareness, explicit or by default, still round-trips.+#[test]+fn minimum_and_maximum_with_roundness_are_not_exported_as_squareness() {+ for id in ["filter.other.minimum", "filter.other.maximum"] {+ let round = Action { name: "Round".into(), steps: vec![(id.into(), json!({"radius": 2, "preserve": "roundness"}))], ..Default::default() };+ assert!(export("Audit", &[&round], &[], false).is_err(), "{id}: strict export refuses it");+ let (_, skipped) = export("Audit", &[&round], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Round".into(), step: 0, id: id.into() }], "{id}");+ for p in [json!({"radius": 2}), json!({"radius": 2, "preserve": "squareness"})] {+ let square = Action { name: "Square".into(), steps: vec![(id.into(), p.clone())], ..Default::default() };+ let (bytes, skipped) = export("Audit", &[&square], &[], false).unwrap();+ assert!(skipped.is_empty(), "{id} {p}");+ let imported = import(&bytes).unwrap();+ let (got, params) = &imported.actions[0].steps[0];+ assert_eq!((got.as_str(), params["radius"].as_f64()), (id, Some(2.0)), "{id} {p}");+ assert!(params.get("preserve").is_none_or(|v| v == "squareness"), "{id} {p}: {params}");+ }+ }+}++ /// #7502, #7512, #7513, #7514: a New Layer step that clips to the layer below, has a colour+ /// label, fills with the neutral colour or goes below the active layer isn't exported, since the+ /// descriptor carries only its name, opacity and mode. Those options at their defaults still+ /// export, and the step round-trips.+ #[test]+ fn new_layer_options_the_descriptor_cannot_carry_refuse_strict_export() {+ let new_layer = |p: Value| Action { name: "Probe".into(), steps: vec![("layer.new.layer".into(), p)], ..Default::default() };+ for p in [+ json!({"name": "New", "clipToPrevious": true}),+ json!({"name": "New", "color": "red"}),+ json!({"name": "New", "mode": "Overlay", "fillNeutral": true}),+ json!({"name": "New", "position": "below"}),+ json!({"name": "New", "clipToPrevious": 1}),+ ] {+ assert!(export("Audit7", &[&new_layer(p.clone())], &[], false).is_err(), "{p}");+ let (_, skipped) = export("Audit7", &[&new_layer(p.clone())], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "layer.new.layer".into() }], "{p}");+ }+ let defaults =+ json!({"name": "New", "mode": "Multiply", "opacity": 0.6, "clipToPrevious": false, "color": "none", "fillNeutral": false, "position": "above"});+ let (bytes, skipped) = export("Audit7", &[&new_layer(defaults)], &[], false).unwrap();+ assert!(skipped.is_empty());+ let imported = import(&bytes).unwrap();+ assert_eq!(imported.actions[0].steps, vec![("layer.new.layer".to_string(), json!({"name": "New", "mode": "Multiply", "opacity": 0.6}))]);+ }++ /// Options the exported descriptors can't carry refuse strict export (and a partial export skips+ /// the step) instead of exporting a step that replays differently; the forms they can carry still-/// export (#7196, #7236, #7246, #7287, #7503, #7506, #7507).++/// export (#7196, #7246, #7287, #7503, #7506, #7507).+ #[test]+ fn options_the_descriptors_cannot_carry_refuse_strict_export() {+ let one = |id: &str, p: Value| Action { name: "Probe".into(), steps: vec![(id.into(), p)], ..Default::default() };+ let refused = [- ("layer.groupLayers", json!({"layer": 3, "name": "Group"})),+ ("layer.newFillLayer.solidColor", json!({"color": "#c0603080"})),+ ("layer.newFillLayer.solidColor", json!({"color": "teal"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "black"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "#ab2233"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "backgroundColor", "backgroundColor": [0.2, 0.4, 0.6]})),+ ("select.loadSelection", json!({"channel": "Alpha 1", "invert": true})),+ ("select.loadSelection", json!({"channel": "Alpha 1", "operation": "subtract"})),+ ("layer.setProps", json!({"opacity": 0.5, "locked": true})),+ ("layer.setProps", json!({"opacity": 0.5, "clipped": true})),+ ("layer.setProps", json!({"layers": [2, 3], "opacity": 0.5})),+ ("filter.noise.addNoise", json!({"amount": 30, "seed": 2147483648_u64})),+ ("filter.noise.addNoise", json!({"amount": 30, "seed": 4294967295_u64})),+ ];+ for (id, p) in refused {+ let err = export("Audit7", &[&one(id, p.clone())], &[], false).unwrap_err();+ assert!(err.contains(&format!("`{id}`")), "{id} {p}: the error names the step: {err}");+ let (_, skipped) = export("Audit7", &[&one(id, p.clone())], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: id.into() }], "{id} {p}");+ }+ let carried = [+ ("layer.groupLayers", json!({"name": "Group"})),+ ("layer.newFillLayer.solidColor", json!({"color": "#c06030"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "white"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "transparent"})),+ ("file.new", json!({"width": 24, "height": 18, "background": "backgroundColor"})),+ ("select.loadSelection", json!({"channel": "Alpha 1", "invert": false, "operation": "new"})),+ // A named target (a numeric one is #7248, #7262).+ ("layer.setProps", json!({"layer": "Pixels", "opacity": 0.5, "visible": true})),+ ("filter.noise.addNoise", json!({"amount": 30, "seed": 2147483647})),+ ];+ for (id, p) in carried {+ let (bytes, skipped) = export("Audit7", &[&one(id, p.clone())], &[], false).unwrap_or_else(|e| panic!("{id} {p}: {e}"));+ assert!(skipped.is_empty(), "{id} {p}");+ let imported = import(&bytes).unwrap();+ assert_eq!(imported.actions[0].steps.first().map(|(i, _)| i.as_str()), Some(id), "{p}");+ }+ }+/// Photoshop's Close has no document target: a Close of a specific document must not be/// exported as a plain Close, which would close the active document on playback.#[test]