mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Enhance audit documentation and address critical Ref property issues
- Updated the audit guide to clarify the workflow and prerequisites for conducting a production-grade sync feature audit. - Introduced a new plan file detailing fixes for critical issues identified in the two-way sync audit, including missing instance maps and stale paths after renames. - Enhanced `ServeSession.lua` to correctly pass the instance map in patch updates, ensuring accurate handling of unresolved Ref properties. - Implemented various fixes in `change_processor.rs` and `rojo_ref.rs` to address critical bugs related to Ref path handling and instance renaming. - Added tests to verify the correct behavior of Ref properties and ensure robustness against edge cases. These changes improve the reliability of the synchronization system and enhance the clarity of the audit process.
This commit is contained in:
parent
8f0df692d3
commit
ca2a938902
8 changed files with 811 additions and 90 deletions
|
|
@ -288,25 +288,33 @@ fn compute_ref_properties(
|
|||
};
|
||||
|
||||
for (attr_name, attr_value) in attributes.iter() {
|
||||
// Handle legacy ID-based refs (Rojo_Target_) FIRST -- lower priority.
|
||||
// If a Rojo_Ref_* attribute also exists for the same property, it will
|
||||
// overwrite this entry below (path-based system has priority).
|
||||
// Handle legacy ID-based refs (Rojo_Target_) -- lower priority.
|
||||
// BTreeMap iterates alphabetically, so Rojo_Ref_* ('R') is visited
|
||||
// BEFORE Rojo_Target_* ('T'). Without the contains_key guard,
|
||||
// Rojo_Target_* would silently overwrite Rojo_Ref_*. The guard
|
||||
// ensures path-based refs always win when both exist.
|
||||
if let Some(prop_name) = attr_name.strip_prefix(REF_POINTER_ATTRIBUTE_PREFIX) {
|
||||
let key = ustr(prop_name);
|
||||
// Skip if Rojo_Ref_* already set a value for this property
|
||||
if map.contains_key(&key) {
|
||||
continue;
|
||||
}
|
||||
let Some(id_str) = crate::variant_as_str(attr_value, attr_name) else {
|
||||
continue;
|
||||
};
|
||||
let rojo_ref = RojoRef::new(id_str.to_string());
|
||||
if let Some(target_id) = tree.get_specified_id(&rojo_ref) {
|
||||
map.insert(ustr(prop_name), Some(Variant::Ref(target_id)));
|
||||
map.insert(key, Some(Variant::Ref(target_id)));
|
||||
} else {
|
||||
map.insert(ustr(prop_name), None);
|
||||
map.insert(key, None);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle path-based refs (Rojo_Ref_) SECOND -- higher priority.
|
||||
// Overwrites any Rojo_Target_* entry for the same property since
|
||||
// path-based is the preferred system.
|
||||
// Handle path-based refs (Rojo_Ref_) -- higher priority.
|
||||
// Always inserted unconditionally; if a Rojo_Target_* for the same
|
||||
// property was already visited (shouldn't happen due to BTreeMap
|
||||
// ordering, but defensive), this overwrites it.
|
||||
if let Some(prop_name) = attr_name.strip_prefix(REF_PATH_ATTRIBUTE_PREFIX) {
|
||||
let Some(path) = crate::variant_as_str(attr_value, attr_name) else {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ fn ref_attr_resolves_primary_part() {
|
|||
let has_primary_part_ref = patch_set.updated_instances.iter().any(|u| {
|
||||
u.changed_properties
|
||||
.get(&ustr("PrimaryPart"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
});
|
||||
assert!(
|
||||
has_primary_part_ref,
|
||||
|
|
@ -280,7 +280,7 @@ fn ref_attr_resolves_value() {
|
|||
let has_value_ref = patch_set.updated_instances.iter().any(|u| {
|
||||
u.changed_properties
|
||||
.get(&ustr("Value"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
});
|
||||
assert!(
|
||||
has_value_ref,
|
||||
|
|
@ -343,11 +343,11 @@ fn ref_attr_multiple_on_same_instance() {
|
|||
let has_pp = update
|
||||
.changed_properties
|
||||
.get(&ustr("PrimaryPart"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(r)) if r.is_some()));
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(r)) if r.is_some()));
|
||||
let has_custom = update
|
||||
.changed_properties
|
||||
.get(&ustr("CustomRef"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(r)) if r.is_some()));
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(r)) if r.is_some()));
|
||||
|
||||
assert!(has_pp, "PrimaryPart ref should resolve");
|
||||
assert!(has_custom, "CustomRef ref should resolve");
|
||||
|
|
@ -393,7 +393,7 @@ fn ref_attr_nonexistent_path_does_not_produce_valid_ref() {
|
|||
let has_valid_ref = patch_set.updated_instances.iter().any(|u| {
|
||||
u.changed_properties
|
||||
.get(&ustr("PrimaryPart"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(r)) if r.is_some()))
|
||||
});
|
||||
assert!(
|
||||
!has_valid_ref,
|
||||
|
|
@ -448,7 +448,7 @@ fn ref_attr_with_regular_attributes_mixed() {
|
|||
let has_pp = patch_set.updated_instances.iter().any(|u| {
|
||||
u.changed_properties
|
||||
.get(&ustr("PrimaryPart"))
|
||||
.map_or(false, |v| matches!(v, Some(Variant::Ref(_))))
|
||||
.is_some_and(|v| matches!(v, Some(Variant::Ref(_))))
|
||||
});
|
||||
assert!(has_pp, "PrimaryPart should be resolved from Rojo_Ref_*");
|
||||
}
|
||||
|
|
@ -486,10 +486,108 @@ fn ref_attr_empty_path_resolves_to_root() {
|
|||
|
||||
// Empty path should resolve to root (RojoTree.get_instance_by_path("") returns root)
|
||||
let has_ref = patch_set.updated_instances.iter().any(|u| {
|
||||
u.changed_properties.get(&ustr("PrimaryPart")).map_or(
|
||||
false,
|
||||
u.changed_properties.get(&ustr("PrimaryPart")).is_some_and(
|
||||
|v| matches!(v, Some(Variant::Ref(r)) if *r == root_id),
|
||||
)
|
||||
});
|
||||
assert!(has_ref, "Empty path should resolve to root instance");
|
||||
}
|
||||
|
||||
/// When both Rojo_Ref_PrimaryPart and Rojo_Target_PrimaryPart exist for the
|
||||
/// same property, Rojo_Ref_* (path-based) must win because it is the preferred
|
||||
/// system. BTreeMap iterates alphabetically ('R' < 'T'), so Rojo_Ref_* is
|
||||
/// visited first. The Rojo_Target_* branch must skip insertion if Rojo_Ref_*
|
||||
/// already set the property.
|
||||
#[test]
|
||||
fn ref_attr_priority_path_wins_over_target() {
|
||||
// Build tree: ROOT > Workspace > Model > Target, OtherPart
|
||||
let snapshot = InstanceSnapshot::new()
|
||||
.name("ROOT")
|
||||
.class_name("DataModel")
|
||||
.children(vec![InstanceSnapshot::new()
|
||||
.name("Workspace")
|
||||
.class_name("Workspace")
|
||||
.children(vec![InstanceSnapshot::new()
|
||||
.name("Model")
|
||||
.class_name("Model")
|
||||
.children(vec![
|
||||
InstanceSnapshot::new().name("Target").class_name("Part"),
|
||||
InstanceSnapshot::new().name("OtherPart").class_name("Part"),
|
||||
])])]);
|
||||
let mut tree = RojoTree::new(snapshot);
|
||||
|
||||
let root_id = tree.get_root_id();
|
||||
let workspace_id = tree
|
||||
.get_instance(root_id)
|
||||
.unwrap()
|
||||
.children()
|
||||
.first()
|
||||
.copied()
|
||||
.unwrap();
|
||||
let model_id = tree
|
||||
.get_instance(workspace_id)
|
||||
.unwrap()
|
||||
.children()
|
||||
.first()
|
||||
.copied()
|
||||
.unwrap();
|
||||
let model_children: Vec<_> = tree
|
||||
.get_instance(model_id)
|
||||
.unwrap()
|
||||
.children()
|
||||
.to_vec();
|
||||
let target_id = model_children[0]; // Target
|
||||
let other_id = model_children[1]; // OtherPart
|
||||
|
||||
// Give OtherPart a specified ID so Rojo_Target_* can resolve it
|
||||
let other_rojo_id = crate::RojoRef::new("other-rojo-id".to_string());
|
||||
tree.set_specified_id(other_id, other_rojo_id);
|
||||
|
||||
// Create snapshot with BOTH attributes for the same property.
|
||||
// Rojo_Ref_PrimaryPart points to Target (via path).
|
||||
// Rojo_Target_PrimaryPart points to OtherPart (via ID).
|
||||
// Rojo_Ref_* should win.
|
||||
let mut attrs = Attributes::new();
|
||||
attrs.insert(
|
||||
"Rojo_Ref_PrimaryPart".into(),
|
||||
Variant::String("Workspace/Model/Target".into()),
|
||||
);
|
||||
attrs.insert(
|
||||
"Rojo_Target_PrimaryPart".into(),
|
||||
Variant::String("other-rojo-id".into()),
|
||||
);
|
||||
|
||||
let snap = InstanceSnapshot::new()
|
||||
.name("Model")
|
||||
.class_name("Model")
|
||||
.properties(UstrMap::from_iter([(
|
||||
ustr("Attributes"),
|
||||
Variant::Attributes(attrs),
|
||||
)]))
|
||||
.children(vec![
|
||||
InstanceSnapshot::new().name("Target").class_name("Part"),
|
||||
InstanceSnapshot::new().name("OtherPart").class_name("Part"),
|
||||
]);
|
||||
|
||||
let patch_set = compute_patch_set(Some(snap), &tree, model_id);
|
||||
|
||||
// PrimaryPart should point to Target (from Rojo_Ref_*), NOT OtherPart (from Rojo_Target_*)
|
||||
let pp_ref = patch_set
|
||||
.updated_instances
|
||||
.iter()
|
||||
.find_map(|u| u.changed_properties.get(&ustr("PrimaryPart")))
|
||||
.expect("PrimaryPart should be in the patch");
|
||||
|
||||
match pp_ref {
|
||||
Some(Variant::Ref(r)) => {
|
||||
assert_eq!(
|
||||
*r, target_id,
|
||||
"Rojo_Ref_* should win over Rojo_Target_* -- PrimaryPart should point to Target, not OtherPart"
|
||||
);
|
||||
}
|
||||
other => panic!(
|
||||
"PrimaryPart should be Some(Variant::Ref), got {:?}",
|
||||
other
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue