mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Preserve native ATN options through the durable test round-trip
This commit is contained in:
1 parent
3505982ba8
commit
f9bc661def
4 files changed
+25
-13
No files matched your search
@@ -195,7 +195,7 @@ fn malformed_unknown_and_unrepresentable_descriptors_stay_whole() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_native_targets_and_damaged_origins_are_refused() {
|
||||
fn unsupported_native_targets_and_damaged_origins_use_exact_native_fallback() {
|
||||
let loaded = imported(fixture("Lnr ", "Gcls", false));
|
||||
for (key, value) in [
|
||||
("target", json!("mask")),
|
||||
@@ -211,9 +211,7 @@ fn unsupported_native_targets_and_damaged_origins_are_refused() {
|
||||
] {
|
||||
let mut action = loaded.actions[0].clone();
|
||||
action.steps[0].1[key] = value;
|
||||
assert!(atn_cmds::export("S", &[&action], &[], false).is_err(), "{key}");
|
||||
let (_, skipped) = atn_cmds::export("S", &[&action], &[], true).unwrap();
|
||||
assert_eq!(skipped.len(), 1, "{key}");
|
||||
crate::atn_export::fallback("S", &action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,10 @@ fn load(d: Descriptor) -> Action {
|
||||
loaded.actions.into_iter().next().unwrap()
|
||||
}
|
||||
|
||||
/// Inspect only the explicit Photoshop projection; unsupported native options are omitted here.
|
||||
fn exported(p: Value) -> Option<AtnItem> {
|
||||
let a = Action::new("A", vec![(CMD.into(), p)]);
|
||||
let bytes = export("S", &[&a], &[], false).ok()?.0;
|
||||
let bytes = export("S", &[&a], &[], true).ok()?.0;
|
||||
atn::parse(&bytes).ok()?.actions.into_iter().next()?.items.into_iter().next()
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ fn caf_settings_roundtrip_seven_fields_and_boolean_choices() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Unedited source identity, order and flags survive; damaged preservation metadata is refused.
|
||||
/// Unedited wire bytes survive; damaged preservation metadata uses exact native fallback.
|
||||
#[test]
|
||||
fn caf_source_order_and_flags_survive_without_reviving_stale_settings() {
|
||||
let mut d = descriptor();
|
||||
@@ -103,11 +104,13 @@ fn caf_source_order_and_flags_survive_without_reviving_stale_settings() {
|
||||
assert_eq!(atn::parse(&bytes).unwrap().actions[0].items[0], source);
|
||||
let mut damaged = a.steps[0].1.clone();
|
||||
damaged["_atnCafDescriptor"] = json!("not base64");
|
||||
crate::atn_export::fallback("S", &Action::new("A", vec![(CMD.into(), damaged.clone())]));
|
||||
assert!(exported(damaged).is_none());
|
||||
let invalid = descriptor().with("extra", D::Boolean(true));
|
||||
let mut damaged = a.steps[0].1.clone();
|
||||
damaged["_atnCafDescriptor"] = json!(photocraft_paint::tile::b64_encode(&invalid.to_bytes()));
|
||||
assert!(exported(damaged).is_none(), "valid base64 cannot hide an unrepresented source field");
|
||||
crate::atn_export::fallback("S", &Action::new("A", vec![(CMD.into(), damaged.clone())]));
|
||||
assert!(exported(damaged).is_none(), "valid base64 cannot hide an unrepresented source field in Photoshop output");
|
||||
}
|
||||
|
||||
/// Representable edits export their new values canonically, retaining step flags without skips.
|
||||
@@ -247,9 +250,11 @@ fn caf_native_exports_preserve_effective_defaults_and_refuse_unrepresented_optio
|
||||
] {
|
||||
let mut p = params();
|
||||
p[key] = value;
|
||||
crate::atn_export::fallback("S", &Action::new("A", vec![(CMD.into(), p.clone())]));
|
||||
assert!(exported(p.clone()).is_none(), "{p}");
|
||||
}
|
||||
for p in [json!({}), json!({"output":"new"}), json!([])] {
|
||||
crate::atn_export::fallback("S", &Action::new("A", vec![(CMD.into(), p.clone())]));
|
||||
assert!(exported(p.clone()).is_none(), "unrepresented native default: {p}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,10 +173,10 @@ fn non_text_and_no_document_playback_fail_without_edits() {
|
||||
|
||||
/// Explicit native targets and corrupt wire metadata cannot export as the implicit measured form.
|
||||
#[test]
|
||||
fn native_export_refuses_explicit_targets_and_damaged_metadata() {
|
||||
fn native_export_preserves_explicit_targets_and_damaged_metadata_without_approximation() {
|
||||
for params in [json!({"layer":1}), json!({"layers":[1]}), json!({(SOURCE):"bad base64"}), json!({(SOURCE):Value::Null})] {
|
||||
let action = Action::new("Path", vec![(COMMAND.into(), params)]);
|
||||
assert!(export("Paths", &[&action], &[], false).is_err());
|
||||
crate::atn_export::fallback("Paths", &action);
|
||||
}
|
||||
let action = Action::new("Path", vec![(COMMAND.into(), json!({}))]);
|
||||
assert_eq!(saved(&action).descriptor.unwrap(), descriptor());
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
//! Assertions for the shared ATN library's native fallback and opt-in Photoshop omission.
|
||||
use photocraft_engine::{actions_cmds::Action, atn_cmds};
|
||||
use photocraft_engine::{
|
||||
Session,
|
||||
actions_cmds::Action,
|
||||
atn_cmds,
|
||||
preset_store::{self, ACTIONS_FILE, MemBackend, PresetBackend},
|
||||
};
|
||||
use photocraft_psd::{
|
||||
atn::{self, AtnItem},
|
||||
descriptor::Value as D,
|
||||
@@ -8,9 +13,13 @@ use photocraft_psd::{
|
||||
pub fn preserved(set: &str, action: &Action) -> Vec<AtnItem> {
|
||||
let (bytes, skipped) = atn_cmds::export(set, &[action], &[], false).unwrap();
|
||||
assert!(skipped.is_empty());
|
||||
let loaded = atn_cmds::import(&bytes).unwrap();
|
||||
assert!(loaded.unsupported.is_empty());
|
||||
assert_eq!(loaded.actions[0].steps, action.steps);
|
||||
// The durable library preserves every native ID and JSON value. Portable imports
|
||||
// deliberately apply the stricter recorder policy, covered by native-admission tests.
|
||||
let store = MemBackend::default();
|
||||
store.write(ACTIONS_FILE, &bytes).unwrap();
|
||||
let mut loaded = Session::new();
|
||||
assert!(loaded.attach_preset_store(preset_store::open(Box::new(store))).is_empty());
|
||||
assert_eq!(loaded.actions.list[0].steps, action.steps);
|
||||
atn::parse(&bytes).unwrap().actions[0].items.clone()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user