✨ Generate component histories in deeper and wider worlds

The random histories ran in worlds of two or three components nested at
most two levels, each with two copies, where ordering and propagation
bugs that need deeper nesting or many copies of one main cannot show.
The scale programs build three or four components nested three or four
levels, with three to six copies of each, a larger shape budget, and
every variant operation. A world takes its number of copies per main
(two by default). Scale programs run several times longer than the
others, so the suite draws twelve; the gates draw more.

Test: random-scale-compositions.
Common suite: 2444 tests, 0 failures.

Harness only; the benchmark is not run.

Also in this commit:

- Model a head size as authored only when a sync resizes its copy. The model
  took any resized copy parent of an untouched swapped head as a sync resize and
  expected the head to author the size it was given. A user resize of a nested
  copy authors that copy's geometry and scales a swapped head under it through
  constraints, which production leaves untouched. The model now finds the
  topmost ancestor the step resized and authors the head's size only when that
  ancestor is a copy shape without authored geometry, the only shape a sync
  resizes.
- Keep the layout item overrides of a swapped head in the model. A swap restores
  the swap-keep-attrs of the old head on the new one with the touched groups
  they belong to, on every swap. The model kept the old head's layout item
  groups only on a variant switch, so after a plain swap of a head that authors
  a margin it expected the new head without that override. It now keeps them on
  every swap.
- Align the arguments of the combine test fixtures. The same-name combine
  fixtures in the variant workspace tests call their helper through the `ctho`
  alias, one character longer than develop's `tho`, so their continuation lines
  sat one column left of the first argument and the frontend format check
  failed.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 21:46:11 +01:00
parent 230dc0b4c2
commit a871ea42a0
4 changed files with 80 additions and 21 deletions

View File

@ -296,7 +296,8 @@
(cond-> (and (zero? index) (pos? depth) (:layout opts)
(:layout-copies opts) (:layout-children opts))
(with-settled-layout name))
(as-> s (reduce #(tm/apply-to %2 %1) s [(n/instantiate-copy name) (n/instantiate-copy name)])))))
(as-> s (reduce #(tm/apply-to %2 %1) s
(repeatedly (:copies opts 2) #(n/instantiate-copy name)))))))
(let [s (setup/empty-situation)
s (if (:variants opts)
(let [s (reduce #(tm/apply-to %2 %1) s
@ -332,7 +333,8 @@
(:layout opts) (r/settle-layout)
(:library opts) (with-library opts)
(:stale-libraries opts) (cf/freeze-libraries)
(:rich-variants opts) (as-> s (assoc s :shape-budget (+ 80 (count (tree s)))))))
(:rich-variants opts) (as-> s (assoc s :shape-budget (+ 80 (count (tree s)))))
(:scale opts) (as-> s (assoc s :shape-budget (+ 120 (count (tree s)))))))
(defn candidates
[situation model kind scope]
@ -1398,6 +1400,28 @@
:grid-square (= grid :square) :grid-empty (= grid :empty)}]
:ops ops}))
(def scale-coverage-kinds
"The kinds the scale programs must cover: the steps that walk every copy
and every nesting level."
[:edit :reset :update-main :sync :swap :switch :undo :redo])
(def scale-program-gen
"Worlds deeper and wider than the other properties draw: up to four
components nested three or four levels, with up to six copies each."
(gen/let [components (gen/choose 3 4)
depth (gen/choose 3 4)
copies (gen/choose 3 6)
differ? gen/boolean
layout (gen/elements [nil :flex :grid])
layout-children gen/boolean
grid (gen/elements [nil :square :empty])
ops (operation-gen variant-kinds)]
{:world [components depth {:scale true :copies copies :variants true :variant-diff differ?
:rich-variants true :text true :text-styles true :layout layout
:layout-copies true :layout-children layout-children
:grid-square (= grid :square) :grid-empty (= grid :empty)}]
:ops ops}))
(def library-kinds
(into structure-kinds [:swap :switch :library-sync]))

View File

@ -573,25 +573,35 @@
model model))
(defn sync-scaled-heads
"A copy parent that a sync resizes sizes its untouched swapped heads
through their constraints. A head it gives another size authors that
size, placed in the parent."
"A copy shape that a sync resizes sizes its subtree through constraints.
An untouched swapped head in it that the resize gives another size
authors that size, placed in its parent. The resize starts at the
topmost resized ancestor of the head: a sync resizes only a copy shape
without authored geometry."
[model before after]
(let [sized-alike? #(and (mth/close? (:width %1) (:width %2))
(mth/close? (:height %1) (:height %2)))]
(mth/close? (:height %1) (:height %2)))
;; whether `id` keeps its parent and has another size in `after`
resized? (fn [id]
(let [old (get before id) shape (get after id)]
(and old shape (= (:parent-id old) (:parent-id shape))
(not (sized-alike? old shape)))))]
(reduce-kv
(fn [result id groups]
(let [old (get before id)
shape (get after id)
old-parent (get before (:parent-id old))
parent (get after (:parent-id shape))]
(let [shape (get after id)
parent (get after (:parent-id shape))
origin (when (and parent (resized? (:id parent)))
(loop [current parent]
(let [above (get after (:parent-id current))]
(if (and above (not= (:id above) (:id current)) (resized? (:id above)))
(recur above)
current))))]
(if (and (contains? groups :swap-group)
(not (contains? groups :geometry-group))
old shape old-parent parent
(= (:parent-id old) (:parent-id shape))
(:shape-ref parent)
(not (sized-alike? old-parent parent))
(not (sized-alike? old shape)))
(resized? id)
(some? origin)
(:shape-ref origin)
(not (contains? (get model (:id origin)) :geometry-group)))
(assoc-in result [id :geometry-group] (author-geometry shape parent))
result)))
model model)))
@ -891,9 +901,8 @@
retained-orientation? (or (not (mth/close? (mod (or (:rotation old-root) 0) 360) rotation 0.01))
(not= (boolean (:flip-x old-root)) (flip :flip-x))
(not= (boolean (:flip-y old-root)) (flip :flip-y)))
;; a switch keeps the old head's layout item values, and their overrides
layout-items (when keep?
(into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id)))
;; a swap keeps the old head's layout item values, and their overrides
layout-items (into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id))
;; a swap in a copy keeps an authored place its position does not give,
;; unless a layout places the head
kept-place? (and (:shape-ref parent) position

View File

@ -2289,6 +2289,19 @@
:ops [[:add-variant 15] [:duplicate 10] [:make-variant 8] [:switch 15] [:style 21 9 1]
[:update-main] [:duplicate 16] [:resize 16]]}))))
(t/deftest resizing-a-copy-parent-leaves-unauthored-the-size-it-gives-a-swapped-head
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout nil :variant-diff false
:layout-item-margins false :grid-square false :rich-variants false
:layout-children false :grid-empty false :layout-copies false :text false}]
:ops [[:make-variant 17] [:style 16 9 1] [:switch 7] [:detach 15] [:resize 15]]}))))
(t/deftest swapping-a-copy-head-keeps-the-margin-it-authors
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :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 [[:combine 10] [:make-variant 12] [:make-variant 4] [:make-variant 1] [:swap 8]
[:style 0 10] [:swap 25]]}))))
(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square true :rich-variants false
@ -2340,6 +2353,19 @@
(t/is (empty? (cg/coverage-errors @coverage cg/variant-coverage-kinds))
(pr-str (cg/coverage-errors @coverage cg/variant-coverage-kinds)))))
(t/deftest random-scale-compositions
;; scale programs run several times longer than the others; the gates draw more
(let [coverage (atom {})
failure (atom nil)]
(smt/check!
(smt/for [program cg/scale-program-gen]
(cg/check-program program coverage failure))
:max-size 30
:default-num 12)
(println "Scale operation coverage:" (pr-str @coverage))
(t/is (empty? (cg/coverage-errors @coverage cg/scale-coverage-kinds))
(pr-str (cg/coverage-errors @coverage cg/scale-coverage-kinds)))))
(t/deftest random-renames-leave-variant-management-to-its-own-operations
(let [situation (cg/world [2 2 {:variants true}])
file (tm/file situation)]

View File

@ -204,11 +204,11 @@
[]
(-> (cthf/sample-file :file1)
(ctho/add-simple-component :c01 :m01 :r01
:root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80})
:root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80})
(ctho/add-simple-component :c02 :m02 :r02
:root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80})
:root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80})
(ctho/add-simple-component :c03 :m03 :r03
:root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80})))
:root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80})))
(defn- path-named-main-file
[]