Actions: keep a Select Sky step whose sampleAllLayers isn't a Boolean (CodeRabbit review on crates/engine/src/cmd/atn_cmds/steps_image.rs:486)

A wrong-typed sampleAllLayers was read as missing and the step played
with false. A shared `setting` helper now reads a present key with its
expected type and returns None otherwise, so the step stays a Photoshop
step, like settings the command can't represent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-10-31 21:22:46 -06:00
1 parent 1d22ffc1ff
commit 292f48d0cf
3 files changed
+42 -10

No files matched your search

+14 -6
View File
@@ -20,13 +20,17 @@ pub(super) fn get_num(d: &Descriptor, k: &str) -> Option<f64> {
d.get(k).and_then(num)
}
pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option<bool> {
match d.get(k) {
Some(D::Boolean(b)) => Some(*b),
pub(super) fn boolean(v: &D) -> Option<bool> {
match v {
D::Boolean(b) => Some(*b),
_ => None,
}
}
pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option<bool> {
d.get(k).and_then(boolean)
}
pub(super) fn get_text(d: &Descriptor, k: &str) -> Option<String> {
match d.get(k) {
Some(D::Text(t)) => Some(t.to_string_lossy()),
@@ -35,13 +39,17 @@ pub(super) fn get_text(d: &Descriptor, k: &str) -> Option<String> {
}
/// An enumerated value's id, trailing spaces removed (`Ordn.Trgt` → `"Trgt"`).
pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option<String> {
match d.get(k) {
Some(D::Enumerated { value, .. }) => Some(trimmed(value)),
pub(super) fn enumerated(v: &D) -> Option<String> {
match v {
D::Enumerated { value, .. } => Some(trimmed(value)),
_ => None,
}
}
pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option<String> {
d.get(k).and_then(enumerated)
}
pub(super) fn get_obj<'a>(d: &'a Descriptor, k: &str) -> Option<&'a Descriptor> {
match d.get(k) {
Some(D::Descriptor(o) | D::GlobalObject(o)) => Some(o),
+14 -4
View File
@@ -1,5 +1,5 @@
use super::descriptors::{
PX, Target, ang, class, code, desc, enm, get_bool, get_enum, get_num, get_obj, get_ref, jbool, jnum, jstr, layer_ref, layer_target, long, pct, px,
PX, Target, ang, boolean, class, code, desc, enm, get_bool, get_enum, get_num, get_obj, get_ref, jbool, jnum, jstr, layer_ref, layer_target, long, pct, px,
ref_class, target, trimmed,
};
use super::events::pixel_target;
@@ -461,6 +461,16 @@ fn only_keys(d: &Descriptor, keys: &[&str]) -> bool {
d.items.iter().all(|(k, _)| keys.contains(&trimmed(k).as_str()))
}
/// The step's `key` read by `read` (its space padding ignored, as `only_keys` admits it),
/// `default` when the step leaves it out, `None` when it holds a value `read` can't take: that
/// is still the step's setting, so the step is kept rather than played with the default.
fn setting<T>(d: &Descriptor, key: &str, read: impl Fn(&D) -> Option<T>, default: T) -> Option<T> {
match d.items.iter().find(|(k, _)| trimmed(k) == key.trim_end()) {
Some((_, v)) => read(v),
None => Some(default),
}
}
/// Whether `p` sets nothing but `allowed` (a `null` counts as unset).
fn sets_only(p: &Value, allowed: &[&str]) -> bool {
p.as_object().is_none_or(|m| m.iter().all(|(k, v)| v.is_null() || allowed.contains(&k.as_str())))
@@ -480,10 +490,10 @@ pub(super) fn bare_to(_: &str, p: &Value) -> Option<Descriptor> {
/// Select Sky (`selectSky`): `sampleAllLayers` only, false when the step leaves it out
/// (the command's own default is true).
pub(super) fn select_sky_from(d: &Descriptor) -> Mapped {
if !only_keys(d, &["sampleAllLayers"]) {
return Mapped::Unsupported { harmless: false };
match setting(d, "sampleAllLayers", boolean, false) {
Some(all) if only_keys(d, &["sampleAllLayers"]) => step("select.sky", json!({"sampleAllLayers": all})),
_ => Mapped::Unsupported { harmless: false },
}
step("select.sky", json!({"sampleAllLayers": get_bool(d, "sampleAllLayers").unwrap_or(false)}))
}
/// The event has no mode, threshold or softness: only their replay values survive.
+14
View File
@@ -3278,3 +3278,17 @@ fn newer_feature_steps_that_cannot_be_written_are_refused() {
}
assert!(export_item("select.sky", &json!({"mode": "replace", "threshold": 50, "softness": 50}), "S").is_some());
}
/// A recorded setting of the wrong type is the step's own setting, not a missing one: the
/// mapper must not play it with a default but keep the Photoshop step (#10610).
fn kept_when_wrong_typed(name: &str, settings: &[(&str, D)]) {
for (key, v) in settings {
let m = newer(name, desc("null").with(key, v.clone()));
assert!(matches!(m, Mapped::Unsupported { harmless: false }), "{name} with {key:?} = {v:?} was mapped");
}
}
#[test]
fn select_sky_with_a_wrong_typed_setting_is_kept() {
kept_when_wrong_typed("selectSky", &[("sampleAllLayers", D::Integer(1)), ("sampleAllLayers", text("true"))]);
}