修复分离树合成根节点 ID 冲突

避免单图根节点重复进入重做计数
补充根图片构造回归测试
This commit is contained in:
2026-09-09 00:38:55 +08:00
parent 187faa607d
commit aff40f794d
2 changed files with 23 additions and 1 deletions
@@ -92,6 +92,21 @@ mod tests {
"image"
);
}
#[test]
fn construction_uses_distinct_root_id_for_root_image() {
let image = Component::Image(ImageComponent {
target_graphic: None,
image_type: ImageType::Simple {
preserve_aspect: false,
},
});
let root = node("root-image", vec![image], vec![]);
let result = construct_separation_state(&state(root));
let tree = &result.unprocessed_trees[0];
assert_ne!(tree.root.id, tree.root.children[0].id);
assert_eq!(tree.root.children[0].id.as_str(), "root-image");
}
#[test]
fn binding_validation_requires_exact_batch_coverage() {
let node = SeparationNode {
@@ -85,7 +85,14 @@ pub fn construct_separation_state(state: &State) -> SeparationState {
(!children.is_empty()).then(|| SeparationTree {
src_ui_design: tree.src_ui_design.clone(),
root: SeparationNode {
id: tree.root.id.clone(),
// The synthetic root must never share an ID with a real
// UI node. A single-image design may use the original
// tree root as an eligible separation leaf.
id: NodeId::new(format!(
"separation-root-{}",
uuid::Uuid::new_v4().simple()
))
.expect("synthetic separation root id is valid"),
global_pos_x_px: 0,
global_pos_y_px: 0,
width_px: image.pixel_size.x.max(0.0).round() as u32,