📎 Align the composable model with the gate round's findings

A fresh gate round (seed 20261117) found, besides F591 to F594, gaps in
the composable harness itself:

- A swapped nested head pasted out of its copy inherits nothing from the
  slot it replaced, and the model steps through a swapped reference to
  its component's main, as the clipboard now does.
- A copy grid that grows to hold its children pads the tracks it authors
  with default ones.
- The shapes a layout places in a deleted component's stored objects
  are left out of the I6 comparison: no layout lays them out until the
  component is restored, so a sync there gives a place the layout would
  change.
- I4 compares corners within a ten-thousandth of the shape's diagonal
  when that is more than a hundredth of a pixel.
- A pasted library main is a new copy of its component, with no
  overrides of its own; stale worlds make no library pastes, since the
  model does not hold apart the versions a consumer accepted.
- Intersections are made only of shapes that overlap, and transforms
  skip shapes without area: an empty bool has no geometry to compare.

Each comes with a pinned program. The five properties that failed in
the round pass 500 programs on the same seed after the fixes.

Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-18 00:24:20 +01:00
parent 59e848ea14
commit 3da9b29671
4 changed files with 172 additions and 33 deletions

View File

@ -271,9 +271,10 @@
`objects` out of `levels` copy levels into `after-objects`, also holding
the groups the references it skips author: the clipboard keeps the values
they gave it. The pasted shape's own groups win over theirs, and a nearer
reference's over a farther one's."
[model objects source-id after-objects new-head levels]
(letfn [(ref-at [id n] (nth (iterate #(:shape-ref (get objects %)) id) n))
reference's over a farther one's. `next-ref` steps along the references
a shape shows its content from."
[model objects source-id after-objects new-head levels next-ref]
(letfn [(ref-at [id n] (nth (iterate next-ref id) n))
(walk [model source-id copy-id]
(let [source (get objects source-id)
copy (get after-objects copy-id)
@ -556,6 +557,9 @@
[situation]
(vec
(for [[library-index [library-id library]] (map-indexed vector (ordered-files (tm/aux-files situation)))
;; a stale consumer refers to the libraries as it accepted them, which
;; the model does not hold apart from those it pastes from
:when (not (:accepted-libraries situation))
:let [objects (:objects (thf/current-page library))]
entry (tree (tm/with-file situation library))
:let [shape (:shape entry)]
@ -733,6 +737,18 @@
[[:group] [:mask] [:ungroup] [:unmask] [:bool :union] [:bool :difference]
[:bool :intersection] [:bool :exclude] [:path]])
(defn- overlapping?
"Whether the shapes `ids` of `objects` share an area, by the boxes of
their corners."
[objects ids]
(let [boxes (map #(let [xs (map :x (:points (get objects %))) ys (map :y (:points (get objects %)))]
[(apply min xs) (apply min ys) (apply max xs) (apply max ys)])
ids)
[x1 y1 x2 y2] (reduce (fn [[ax1 ay1 ax2 ay2] [bx1 by1 bx2 by2]]
[(max ax1 bx1) (max ay1 by1) (min ax2 bx2) (min ay2 by2)])
boxes)]
(and (seq ids) (< (+ x1 0.5) x2) (< (+ y1 0.5) y2))))
(defn- structure-edit
"The structure edit `property` names on the shape of `entry`, and the
shapes it takes: with an odd `value`, its next sibling too when that is
@ -751,7 +767,11 @@
empties? (and (#{:group :bool} (:type parent)) (= (set pair) (set (:shapes parent))))
targets (case action
(:group :mask) (when-not empties? pair)
:bool (when (not-any? #(= :text (:type (get objects %))) pair) pair)
:bool (when (and (not-any? #(= :text (:type (get objects %))) pair)
;; an intersection of shapes that do not overlap is
;; empty: it and the bools around it have no area
(or (not= :intersection bool-type) (overlapping? objects pair)))
pair)
:ungroup (when (#{:group :bool :frame} (:type shape)) [(:id shape)])
:unmask (when (:masked-group shape) [(:id shape)])
:path (when (#{:rect :circle} (:type shape)) [(:id shape)]))]
@ -1090,7 +1110,8 @@
full-before (r/settle situation all)
full (:situation (cf/sync-world settled all))
;; an undone creation keeps its stored copies as they were when it was undone
opts {:free-head-placement false :unreferenced-deleted-components false}
opts {:free-head-placement false :unreferenced-deleted-components false
:stored-layout-placement false}
settled-design (oracle/canonical settled opts)
full-before-design (oracle/canonical full-before opts)
full-design (oracle/canonical full opts)
@ -1252,30 +1273,42 @@
(get (into {} (mapcat cf/object-trees) (vals (cf/reference-libraries after head)))
(:shape-ref head)))
(get after-objects (:shape-ref head)))
model (shadow/duplicate model objects id
(if-let [page-id (:to-page op)]
(get-in (tm/file after) [:data :pages-index page-id :objects])
(:objects (thf/current-page (tm/file after))))
new-head)
;; a library main pastes as a new copy of its component, with no
;; override of its own
model (if (and (= kind :library-paste) (ctk/main-instance? shape))
model
(shadow/duplicate model objects id
(if-let [page-id (:to-page op)]
(get-in (tm/file after) [:data :pages-index page-id :objects])
(:objects (thf/current-page (tm/file after))))
new-head))
;; a nested copy pasted out of its copies takes the overrides of the
;; references it leaves behind
page-objects (:objects (thf/current-page (tm/file before)))
;; the references it skips to reach the main of its component
main-id (get-in (cf/libraries before) [(:component-file shape) :data :components
(:component-id shape) :main-instance-id])
;; the references it skips to reach the main of its component; a
;; swapped head shows its content from the main of its own component
main-of (fn [shape] (get-in (cf/libraries before) [(:component-file shape) :data :components
(:component-id shape) :main-instance-id]))
next-ref (fn [id] (let [s (get objects id)]
(if (ctk/swapped? s) (main-of s) (:shape-ref s))))
main-id (main-of shape)
levels (if (and (= kind :paste) (get page-objects id) (ctn/has-any-copy-parent? page-objects shape))
(->> (iterate #(:shape-ref (get objects %)) (:shape-ref shape))
(->> (iterate next-ref (:shape-ref shape))
(take-while some?)
(take 16)
(take-while #(not= % main-id))
count)
0)
model (cond-> model
;; the references a swapped head skips are those of the slot it
;; replaced, not of its content: it inherits none of theirs
(and new-head (pos? levels) (not (ctk/swapped? shape)))
(inherit-skipped-groups objects id after-objects new-head levels next-ref)
;; out of every copy level, a swapped head is a plain copy of the
;; component it shows
(and new-head (pos? levels))
(-> (inherit-skipped-groups objects id after-objects new-head levels)
;; out of every copy level, a swapped head is a plain copy of
;; the component it shows
(update new-head dissoc :swap-group)))]
(update new-head dissoc :swap-group))]
;; a copy pasted on the page keeps the geometry it showed: what it
;; authored, now where it lands, and the orientation and size another
;; parent gave it, which its main's need not be

View File

@ -184,14 +184,45 @@
(and (:deleted component) (not (contains? referenced id)))))
components)))))))
(defn- without-stored-layout-placement
"The snapshot `files` with the shapes a layout places, or that move with
one it places, in the stored objects of deleted components without their
place: no layout lays them out until
the component is restored, so a sync there gives a place the layout would
change."
[files]
(let [laid-out? (fn [objects shape]
(and (ctl/any-layout-immediate-child? objects shape)
(not (ctl/position-absolute? shape))))
unplaced (fn [objects]
(update-vals objects
(fn [shape]
;; a layout places the shape, or a shape around it
(if (some #(laid-out? objects %)
(cons shape (cfh/get-parents objects (:id shape))))
(cond-> (dissoc shape :x :y :selrect :points :transform :transform-inverse)
(= :path (:type shape)) (dissoc :content))
shape))))]
(update-vals files
(fn [file]
(d/update-in-when file [:data :components]
(fn [components]
(update-vals components
#(cond-> %
(and (:deleted %) (:objects %))
(update :objects unplaced)))))))))
(defn design-snapshot
"Design inputs without derived placement, dimensions and bookkeeping.
Geometry remains unrounded; equivalent? applies its tolerance directly.
With `:unreferenced-deleted-components false`, the deleted components
nothing refers to are left out."
nothing refers to are left out; with `:stored-layout-placement false`, so
is the place of the shapes a layout places in deleted components."
([situation] (design-snapshot situation {}))
([situation {:keys [free-head-placement relative-free-head-placement unreferenced-deleted-components]
:or {free-head-placement true unreferenced-deleted-components true}}]
([situation {:keys [free-head-placement relative-free-head-placement unreferenced-deleted-components
stored-layout-placement]
:or {free-head-placement true unreferenced-deleted-components true
stored-layout-placement true}}]
(let [origins (when (and free-head-placement relative-free-head-placement)
(get-derived-reference-origins situation))]
(walk/postwalk
@ -279,7 +310,8 @@
(dissoc :x :y :width :height :points :selrect :transform :transform-inverse)))])) objects)))
value))
(cond-> (snapshot situation)
(not unreferenced-deleted-components) without-unreferenced-deleted))))))
(not unreferenced-deleted-components) without-unreferenced-deleted
(not stored-layout-placement) without-stored-layout-placement))))))
(defn canonical
"Design data with shape, component and grid-cell IDs named by tree path.
@ -602,10 +634,14 @@
group-sized (let [parent (get objects (:parent-id ownership))]
(and (#{:group :bool} (:type parent))
(some #{:width :height} (derived-attributes objects parent))))
;; corners within a hundredth of a pixel, or within a ten-thousandth of
;; the shape's diagonal, which float noise from a layout's resize of a
;; turned parent reaches on a large shape
tolerance (max 0.01 (* 1e-4 (mth/hypot (or (:width expected) 0) (or (:height expected) 0))))
width-owned (contains? derived :width)
height-owned (contains? derived :height)
;; Both flags and a half turn decompose the transform neither does.
same-corners? (gsh/close-attrs? :points (:points shape) (:points expected) 0.01)
same-corners? (gsh/close-attrs? :points (:points shape) (:points expected) tolerance)
both-flipped (and (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))
(not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))
(geom/decomposes? shape))
@ -615,7 +651,7 @@
in-group? (#{:group :bool} (:type (get objects (:parent-id ownership))))
derived (and (or (#{:group :bool} (:type shape)) in-group?)
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (:points expected)) 0.01))]
(geom/ordered-corners (:points expected)) tolerance))]
(cond-> #{}
;; Parents may store equivalent decompositions, so a rotation that
;; decomposes the shape's own transform is its expected turn too, as
@ -624,7 +660,7 @@
(same-turn? rotation exp-rotation)
(and mirrored (same-turn? rotation (- exp-rotation)))
(geom/decomposes? shape)
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :rotation)
(gsh/close-attrs? :points (:points shape) (:points expected) tolerance))) (conj :rotation)
;; ordered corners that match fix the transform, so flags that decompose
;; it store the same transform otherwise
(and (not both-flipped) (not derived) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))
@ -635,13 +671,13 @@
(and (not height-owned) (not (mth/close? (:height shape) (:height expected) 0.01))) (conj :height)
(and (not layout-child) auto-height
(not (gsh/close-attrs? :points [(first (:points shape))]
[(first (:points expected))] 0.01))) (conj :position)
[(first (:points expected))] tolerance))) (conj :position)
(and (not layout-child) (not auto-width) (not auto-height) (not group-sized)
;; a bool computes its corners from its segments, in their order
(not (if (or (= :bool (:type shape)) in-group?)
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (:points expected)) 0.01)
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01)))) (conj :points)))))
(geom/ordered-corners (:points expected)) tolerance)
(gsh/close-attrs? :points (:points shape) (:points expected) tolerance)))) (conj :points)))))
(defn check-requested-geometry
[objects actual expected]

View File

@ -764,7 +764,19 @@
ordinary? (dissoc :swap-group)
gridless? (dissoc :layout-grid-cells)
(and (:layout-grid-cells groups) (not gridless?))
(update-in [:layout-grid-cells :layout-grid-cells] grid/settle-cells shape objects context source))]
(update-in [:layout-grid-cells :layout-grid-cells] grid/settle-cells shape objects context source))
;; a grid that grows to hold its children adds default tracks, also
;; to the tracks the copy authors
grown (some-> groups :layout-grid-cells :layout-grid-cells meta ::grid/context)
pad (fn [tracks n] (into (vec tracks) (repeat (- n (count tracks)) ctl/default-track-value)))
groups (cond-> groups
(and grown (:layout-grid-columns groups)
(< (count (get-in groups [:layout-grid-columns :layout-grid-columns])) (:columns grown)))
(update-in [:layout-grid-columns :layout-grid-columns] pad (:columns grown))
(and grown (:layout-grid-rows groups)
(< (count (get-in groups [:layout-grid-rows :layout-grid-rows])) (:rows grown)))
(update-in [:layout-grid-rows :layout-grid-rows] pad (:rows grown)))]
(if (seq groups) (assoc result id groups) (dissoc result id))))
model model)))

View File

@ -4542,13 +4542,71 @@
:ops [[:style 1 1 1 0] [:add-child 0] [:structure 0 0 0] [:add-child 0]
[:structure 1 4 0] [:transform 1 1 0 1]]}))))
(t/deftest generated-a-detach-authors-no-geometry-for-float-noise
;; after a turn and a fill resize, the nested copies a detach advances sit
;; a few thousandths of a pixel from their new mains' places: no override
(t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:nest 7 2 4 2] [:rotate 6 2 4 1] [:duplicate 1 3 1 0] [:make-variant 2] [:duplicate 8 2 8 6] [:style 2 29 1] [:detach 8 6 8 2]]}))))
(t/deftest generated-a-swapped-nested-head-pasted-out-inherits-no-overrides-of-its-slot
;; the references a swapped head skips are those of the slot it replaced:
;; pasted out of its copy, it is a plain copy of the component it shows
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :rich-variants true :layout-copies true :text true}]
:ops [[:variant-property 0 0 0 0] [:switch 3] [:add-variant 15 0 0 0] [:combine 2]
[:switch 0] [:resize 0 0 0 0] [:paste 11 0 0 0]]}))))
(t/deftest generated-a-copy-grid-with-its-own-columns-grows-them-to-hold-its-children
;; a main grid that loses a row leaves a copy with its own columns too few
;; cells for its children: the copy adds a default column, also to the
;; columns it authors
(t/is (map? (cg/run {:world [2 1 {:variants true :layout :grid :grid-square true :rich-variants true
:layout-children true :layout-copies true :text true}]
:ops [[:grid-track 9 5 0 0] [:grid-direction 0 0 0 1] [:grid-cell 0 0 0 1]
[:grid-track 0 2 0 0]]}))))
(t/deftest generated-a-deleted-component-keeps-the-place-its-grid-gave-a-copy
;; a component deleted with a path its grid places keeps it where the grid
;; put it; a sync of its stored objects, which no layout lays out until it
;; is restored, is not compared with it
(t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout :grid
:layout-copies true :layout-children true}]
:ops [[:add-child 16] [:style 22 35 1] [:add-child 7] [:delete 15 18 10 19] [:add-child 7]
[:structure 7 8 4] [:delete 6 9 5 0] [:delete 7 10 18 17]]}))))
(t/deftest generated-a-pasted-library-main-is-a-new-copy-without-overrides
;; a library main pasted into the consumer is a new copy of its component:
;; its nested copies show what the main's nested copies author, without
;; overriding it
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :grid :library true :rich-variants true
:grid-empty true :layout-copies true :text true}]
:ops [[:edit 5 0 0 2] [:edit 1 0 1 1] [:update-main 1] [:library-paste 4 0 0 0]]}))))
(t/deftest generated-a-copy-grid-keeps-an-authored-empty-cell-where-it-was-when-it-grows-back
;; a copy grid with its own cells loses a row its main removes and grows it
;; back for its children: its authored empty cell keeps its place (user
;; decision)
(t/is (map? (cg/run {:world [2 1 {:variants true :layout :grid :layout-item-margins false :grid-square true :rich-variants true :layout-children true :grid-empty false :layout-copies true :text true}] :ops [[:grid-track 9 5 0 0] [:grid-direction 0 0 1 1] [:grid-cell 0 15 0 1] [:grid-track 0 2 0 0]]}))))
(t/deftest generated-an-intersection-is-made-only-of-overlapping-shapes
;; an intersection of shapes that do not overlap would be empty; the
;; programs make one only of shapes that overlap
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout :grid :layout-copies true :layout-children true}] :ops [[:add-child 0] [:structure 4 4 3] [:structure 5 6 3 0]]}))))
(t/deftest generated-a-pasted-swapped-head-takes-the-placement-of-its-new-main
;; a swapped nested head pasted out of its copy takes its new main's
;; placement where it overrides none
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :grid :layout-item-margins false :grid-square false :library true :rich-variants true :layout-children true :grid-empty true :layout-copies true :text true}] :ops [[:style 8 8 0 0] [:switch 7 0 0 0] [:delete 2 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:paste 8 0 0 0]]}))))
(t/deftest generated-a-detach-authors-no-geometry-for-float-noise
;; after a turn and a fill resize, the nested copies a detach advances sit
;; a few thousandths of a pixel from their new mains' places: no override
(t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:nest 7 2 4 2] [:rotate 6 2 4 1] [:duplicate 1 3 1 0] [:make-variant 2] [:duplicate 8 2 8 6] [:style 2 29 1] [:detach 8 6 8 2]]}))))
(t/deftest generated-a-pasted-copy-of-a-swapped-reference-inherits-nothing-of-its-slot
;; a nested copy pasted out of its copy, whose reference is a head its main
;; swapped, takes its content from the component swapped in: nothing the
;; replaced slot overrides reaches it
(t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true :stale-libraries true
:layout :flex :library-depth 2 :library true :rich-variants true
:layout-children true :library-text true :layout-copies true :text true}]
:ops [[:library-variant-property 0 0 0 0] [:library-sync] [:switch 23] [:edit 12 0 0 0]
[:delete 18 0 0 0] [:paste 12 0 0 0]]}))))