Keep scope regression fixtures faithful to explicit references

This commit is contained in:
yoriswind committed 2026-11-04 10:24:48 -08:00
1 parent 012342d87e
commit 503c043a51
2 files changed
+28 -9

No files matched your search

+10 -1
View File
@@ -1920,7 +1920,16 @@ fn batch_refuses_ambiguous_nested_atn_calls_before_output() {
let bytes = atn_cmds::export(name, &[action], &[], false).unwrap().0;
groups.push(atn::parse(&bytes).unwrap());
}
std::fs::write(&file, atn::write_sets(&groups).unwrap()).unwrap();
// Portable export supplies the caller's set by default; remove it for this unscoped fixture.
let descriptor = groups.last_mut().unwrap().actions[0].items[0].descriptor.as_mut().unwrap();
for (_, value) in &mut descriptor.items {
if let photocraft_psd::descriptor::Value::Reference(reference) = value {
reference.retain(|item| !matches!(item, photocraft_psd::descriptor::ReferenceItem::Name { class, .. } if class.class_id.is("ASet")));
}
}
let bytes = atn::write_sets(&groups).unwrap();
assert!(atn_cmds::import(&bytes).unwrap().actions[2].steps[0].1.get("set").is_none());
std::fs::write(&file, bytes).unwrap();
let output = directory.join("out");
let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
let args = [
+18 -8
View File
@@ -35,12 +35,12 @@ fn finish(marker: &str) -> Action {
Action::new("Finish", vec![("layer.new.layer".into(), json!({"name":marker}))])
}
/// Play and Conditional use the first named physical set, retaining legacy fallback rules.
/// Explicit scopes never fall through; unscoped calls retain caller-local resolution.
#[test]
fn imported_named_set_calls_keep_their_target_through_duplicate_action_renaming() {
for conditional in [false, true] {
for local in [false, true] {
for scope in [Some("B"), None, Some("Missing"), Some("Empty")] {
for scope in [Some("A"), Some("B"), None, Some("Missing"), Some("Empty")] {
let mut params = if conditional { json!({"if":"always","then":"Finish"}) } else { json!({"action":"Finish"}) };
if let Some(scope) = scope {
params["set"] = json!(scope);
@@ -68,11 +68,16 @@ fn imported_named_set_calls_keep_their_target_through_duplicate_action_renaming(
session.execute("file.new", json!({"width":8,"height":8})).unwrap();
let before = session.actions.clone();
let result = session.execute("actions.load", json!({"data":photocraft_engine::paint::tile::b64_encode(&bytes),"replace":false}));
let expected = if scope == Some("B") {
Some("From B first")
} else if scope == Some("Empty") {
None
} else if local {
if scope == Some("Missing") {
result.unwrap();
let caller = session.actions.list.iter().find(|action| action.name == "Caller").unwrap();
assert_eq!(caller.steps[0].1[if conditional { "then" } else { "action" }], "Finish");
assert_eq!(caller.steps[0].1["set"], "Missing", "deferred external reference stays unrewritten");
continue;
}
let expected = if scope == Some("A") {
Some("From A")
} else if scope.is_none() && local {
Some("From C")
} else {
None
@@ -88,7 +93,12 @@ fn imported_named_set_calls_keep_their_target_through_duplicate_action_renaming(
assert_eq!(session.active().unwrap().doc.layers.last().unwrap().name, expected);
} else {
let error = result.unwrap_err().to_string();
assert!(error.contains("ambiguous cross-set"), "{error}");
let expected = match scope {
Some("B") => "ambiguous action call set",
Some("Empty") => "missing from set",
_ => "ambiguous cross-set",
};
assert!(error.contains(expected), "{error}");
assert_eq!(session.actions, before, "refusal retains the original definitions");
}
}