From 9d92cc020281fa787fd320baa91375239dacdca8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 9 Nov 2026 18:22:24 +0100 Subject: [PATCH] :paperclip: Model a pushed swap whose near main converged on update main A copy's child authored a swap, and a later swap in the main gave the child's near main the same component. Update-main clones the copy's swapped parent into the main, and the clone of the child keeps its swap against the same near main, as an authored swap stays when its near main converges. The model dropped the swap from every pushed main shape whose component equals its ref's; it now keeps it on a main shape that refers to the same shape as the copy shape. Harness only; the benchmark is not run. Also in this commit: - Turn an authored child by the sign of its own mirror decomposition. A mirrored shape can store its turn either way: rotation 45 with the flip after the turn, or 315 with the turn after the flip, for one transform. When a flipped copy turned, the model turned a child's authored rotation with the sign of the decomposition the shape stores, while the model may hold the other one, and expected 270 where production gives 0. AI-assisted-by: claude-opus-5-5 --- .../common/test_helpers/composable/shadow.cljc | 11 ++++++++--- .../logic/composable_gen_test.cljc | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 54af0bb30f..dfa6d29e65 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -498,8 +498,10 @@ (and (:shape-ref ref) (seq groups)) (update (:id ref) merge (cond-> (grid/remap-groups groups (grid/get-child-map after shape ref)) - (= (:component-id ref) - (:component-id (get after (:shape-ref ref)))) + ;; a clone of the copy shape keeps the swap it authored against the same main + (and (= (:component-id ref) + (:component-id (get after (:shape-ref ref)))) + (not= (:shape-ref ref) (:shape-ref shape))) (dissoc :swap-group))))] (reduce #(push %1 %2 content?) result (:shapes shape))))] (push model root-id false))) @@ -534,7 +536,10 @@ (if-let [expected (authored-placement (:geometry-group groups) new-parent)] (assoc-in result [id :geometry-group] (with-meta (values expected :geometry-group) (meta (:geometry-group groups)))) - (update-in result [id :geometry-group] in-orientation parent new-parent (geom/turn-sign old))) + (let [geometry (:geometry-group groups) + ;; the way the authored rotation, not the one `old` stores, decomposes its transform + sign (geom/turn-sign (merge old (select-keys geometry [:rotation :flip-x :flip-y])))] + (update-in result [id :geometry-group] in-orientation parent new-parent sign))) result))) model model)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index cf1c2f98e7..7fe97f46b0 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1964,6 +1964,24 @@ [:nest 19 0 0 0] [:grid-direction 9 0 3 0] [:nest 8 0 0 0] [:add-variant 0] [:switch 12] [:make-variant 2] [:switch 14]]})))) +(t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:swap 5 0 0 0] [:delete 8 0 0 0] [:delete 5 0 0 0] [:combine 7 0 0 0] + [:restore 0 0 0 0] [:add-variant 5] [:switch 0] [:combine 0] [:switch 3] + [:make-variant 14] [:switch 2] [:duplicate 0 0 0 0] [:delete 4 0 0 0] + [:add-variant 7 0 0 0] [:transform 15 1 0 2] [:combine 0] [:switch 1] + [:duplicate 1 0 0 0] [:transform 1 4 0 4] [:variant-property 0 0 0 0] + [:switch 6] [:rotate 10 0 0 0] [:rotate 1 0 0 0]]})))) + +(t/deftest updating-a-main-keeps-a-pushed-swap-its-main-converged-to + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:make-variant 1] [:switch 11] [:make-variant 2] [:switch 10] [:swap 1 0 0 0] + [:update-main 0 0 0 0]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)]