fix: keep grouped object IDs unique

This commit is contained in:
Formsmith
2026-08-03 18:54:15 +03:00
parent 9d2ec76103
commit decf33521a
5 changed files with 130 additions and 14 deletions
+29
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import type { WorkplaneShape } from "@/types/sketchforge";
import {
canonicalizeShape,
cloneWorkplaneShapeTreeWithFreshIds,
cleanNearZero,
cleanRotationDegrees,
fallbackSolidColor,
@@ -98,6 +99,34 @@ describe("workplane shape helpers", () => {
expect(canonical.groupedShapes?.[0].mirrorZ).toBeUndefined();
});
it("assigns fresh object IDs throughout duplicated group trees", () => {
const original = shape({
id: "outer-group",
kind: "mesh",
groupedShapes: [
shape({ id: "round-roof-child", kind: "roundRoof" }),
shape({
id: "nested-group",
kind: "mesh",
groupedShapes: [shape({ id: "nested-box" })],
}),
],
});
const duplicate = cloneWorkplaneShapeTreeWithFreshIds(original, "copy");
const collectIds = (entry: WorkplaneShape): string[] => [
entry.id,
...(entry.groupedShapes ?? []).flatMap(collectIds),
];
const originalIds = collectIds(original);
const duplicateIds = collectIds(duplicate);
expect(new Set(duplicateIds).size).toBe(duplicateIds.length);
expect(duplicateIds.every((id) => !originalIds.includes(id))).toBe(true);
expect(original.groupedShapes?.[0].id).toBe("round-roof-child");
expect(duplicate.groupedShapes?.[0].kind).toBe("roundRoof");
});
it("keeps shallow equality strict for shape payload references", () => {
const importedMesh = { positions: [0, 0, 0], baseWidth: 1, baseDepth: 1, baseHeight: 1, triangleCount: 0, sourceFormat: "json" as const };
const first = shape({ importedMesh });