From 49bda296edaa3389682a28ed98768d43a8442a37 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 05:33:31 +0100 Subject: [PATCH] :bug: Fit the cells a copy takes from its main within its own tracks A copy that authors its track lists keeps them when its main adds or removes tracks, but sync gave it its main's cells as they were: after the main added a column, a copy with two columns of its own held a cell in a third. A copy whose track counts differ from its main's now fits the main's cells within its own tracks as the contract keeps cells when tracks shrink (move, shorten or join), and the oracle expects the same. Test: a-copy-with-its-own-columns-takes-its-main-cells-within-them (the grid gate program of seed 175377838). Common suite: as the previous commit. Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured with the previous commit's change in the tree as well: | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 22.04 | 22.52 | 0.63 | | edit-through-a-chain-of-dependents | 68.931 | 43.463 | 44.28 | 0.63 | | library-update-into-copies | 83.083 | 48.024 | 50.138 | 0.58 | | main-edit-among-many-shapes | 4.837 | 2.247 | 2.418 | 0.46 | | main-edit-into-10-copies | 1.79 | 1.06 | 1.078 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.242 | 11.303 | 0.66 | | main-edit-into-1000-copies | 153.086 | 110.068 | 112.273 | 0.72 | | variant-switch-into-copies | 32.052 | 22.921 | 23.391 | 0.72 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 4 ++++ common/src/app/common/test_helpers/composable/grid.cljc | 4 ++-- .../src/app/common/test_helpers/composable/oracle.cljc | 9 ++++++++- common/test/common_tests/logic/composable_gen_test.cljc | 6 ++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index b5d8a775a5..32c7f31aa7 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2316,6 +2316,10 @@ (:shapes shape-copy))] (-> shape-copy (assoc :layout-grid-cells (-> shape-main (ctsl/remap-grid-cells ids-map) :layout-grid-cells)) + ;; a copy with its own track lists keeps its main's cells within them + (cond-> (or (not= (count (:layout-grid-rows shape-copy)) (count (:layout-grid-rows shape-main))) + (not= (count (:layout-grid-columns shape-copy)) (count (:layout-grid-columns shape-main)))) + (ctsl/fit-cells-to-tracks)) (ctsl/assign-cells objects)))) (defn grid-direction-cells diff --git a/common/src/app/common/test_helpers/composable/grid.cljc b/common/src/app/common/test_helpers/composable/grid.cljc index daaebd2979..3e6abbfd5f 100644 --- a/common/src/app/common/test_helpers/composable/grid.cljc +++ b/common/src/app/common/test_helpers/composable/grid.cljc @@ -163,10 +163,10 @@ (def ^:private default-cell {:row-span 1 :column-span 1 :position :auto :align-self :auto :justify-self :auto :shapes []}) -(defn- fit-cells +(defn fit-cells "`cells` placed within a grid of `rows` by `columns` that flows in `direction`, as the contract keeps a copy's cells when its inherited - tracks shrink: cells with children first, then authored empty ones, then + tracks shrink, or the cells it takes from a main with other tracks: cells with children first, then authored empty ones, then default ones, each where it fits, else in the first free slot, else in one track; children left without a slot join the cell where theirs would start. Free slots take default cells." diff --git a/common/src/app/common/test_helpers/composable/oracle.cljc b/common/src/app/common/test_helpers/composable/oracle.cljc index 6477c41e58..1afb2da266 100644 --- a/common/src/app/common/test_helpers/composable/oracle.cljc +++ b/common/src/app/common/test_helpers/composable/oracle.cljc @@ -661,7 +661,14 @@ (and manual (= :auto (:position cell))) (assoc :position :manual)))])) [false []] cells))) - cells (->> (grid-cells main) + rows (count (:layout-grid-rows shape)) + columns (count (:layout-grid-columns shape)) + ;; a copy with its own track lists keeps its main's cells within them + fitted (if (and (= rows (count (:layout-grid-rows main))) + (= columns (count (:layout-grid-columns main)))) + (grid-cells main) + (grid/fit-cells (grid-cells main) rows columns (or (:layout-grid-dir shape) :row))) + cells (->> fitted (sort-by flow-order) (mapv #(update % :shapes (fn [ids] (filterv participating ids)))) end-auto-prefix) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index de3a91c5c9..164b92321f 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2381,6 +2381,12 @@ :layout-copies true :text true}] :ops [[:nest 6 0 0 0] [:nest 9 0 0 0] [:style 2 29 1] [:detach 5 0 0 0]]})))) +(t/deftest a-copy-with-its-own-columns-takes-its-main-cells-within-them + (t/is (map? (cg/run {:world [1 0 {:variants false :layout :grid :layout-item-margins false :grid-square false + :rich-variants false :layout-children false :grid-empty false + :layout-copies false :text false}] + :ops [[:grid-track 10 5 0 11] [:grid-track 0 1] [:grid-cell 0 0 0 1]]})))) + (t/deftest random-shape-structure-compositions (let [coverage (atom {}) failure (atom nil)]