alonso.torres 25281f47f2 🐛 Keep no switched swap that would nest a component in itself
A copy whose child was swapped to a variant, switched to that variant,
kept the swap. That put a copy of the new component inside a copy of
itself, so the move of the kept child was refused and the child stayed
at the page root, leaving an invalid file. A switch now keeps a swap only
when its subtree holds no copy of the new component, nor of a component
the copy is inside; the new variant's own child takes its place.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):

|                             :world | :baseline |   :now |  :mean | :ratio |
|------------------------------------+-----------+--------+--------+--------|
|  deepest-edit-through-three-levels |    35.215 |   19.0 | 20.802 |   0.54 |
| edit-through-a-chain-of-dependents |    68.931 | 36.673 | 38.166 |   0.53 |
|         library-update-into-copies |    83.083 | 44.204 | 46.142 |   0.53 |
|        main-edit-among-many-shapes |     4.837 |  2.106 |  2.224 |   0.44 |
|           main-edit-into-10-copies |      1.79 |  0.917 |  0.981 |   0.51 |
|          main-edit-into-100-copies |    15.415 |  8.858 |  9.458 |   0.57 |
|         main-edit-into-1000-copies |   153.086 | 89.013 | 93.164 |   0.58 |
|         variant-switch-into-copies |    32.052 | 19.844 | 20.613 |   0.62 |

Common suite: 2371 tests, 1 failure, the known insufficient-random-coverage
of random-stale-library-compositions (swap and library-add-variant
attempted too few times in 20 programs).

AI-assisted-by: claude-opus-5-5
2026-11-18 10:29:47 +01:00
..