🐛 Restore migration and test compatibility after rebase

Keep the container root helper used by the main-instance name migration.
Adapt imported-file ids and component swap tests to the current APIs, and
check copied swaps through their position refs and swap groups.

AI-assisted-by: gpt-6
This commit is contained in:
alonso.torres 2026-10-27 15:22:28 +01:00
parent 2e542dc8cf
commit 11d7a630dc
4 changed files with 24 additions and 27 deletions

View File

@ -13,11 +13,11 @@
[app.common.data :as d]
[app.common.features :as cfeat]
[app.common.files.changes-builder :as pcb]
[app.common.files.tokens :as cfo]
[app.common.files.validate :as cfv]
[app.common.files.comp-processors :as cfcp]
[app.common.files.migrations :as fmg]
[app.common.files.swap-slots :as cfss]
[app.common.files.tokens :as cfo]
[app.common.files.validate :as cfv]
[app.common.pprint :as pp]
[app.common.test-helpers.components :as cthc]
[app.common.test-helpers.compositions :as ctho]
@ -2960,7 +2960,7 @@
(assoc ::bfc/team-id (:default-team-id profile))
(assoc ::bfc/input input))]
(case version
1 (vec (v1/import-files! cfg))
1 (:file-ids (v1/import-files! cfg))
3 (:file-ids (v3/import-files! cfg)))))
(defn- import-error

View File

@ -94,6 +94,10 @@
[container shape-id f]
(update-in container [:objects shape-id] f))
(defn get-container-root
[container]
(d/seek #(or (nil? (:parent-id %)) (= (:parent-id %) uuid/zero)) (shapes-seq container)))
(defn get-direct-children
[container shape]
(map #(get-shape container %) (:shapes shape)))

View File

@ -11,6 +11,7 @@
[app.common.geom.shapes :as gsh]
[app.common.logic.libraries :as cll]
[app.common.logic.shapes :as cls]
[app.common.logic.variants :as clv]
[app.common.math :as mth]
[app.common.test-helpers.components :as thc]
[app.common.test-helpers.compositions :as tho]
@ -160,22 +161,12 @@
[file library shape-label new-component-label]
(let [shape (ths/get-shape file shape-label)
page (thf/current-page file)
keep-props-values (select-keys shape ctk/swap-keep-attrs)
libraries {(:id library) library
(:id file) file}
id-new (:id (thc/get-component library new-component-label))
[_ _ changes] (cll/generate-component-swap
[_ changes _] (clv/generate-component-swap-in-place
(pcb/empty-changes nil (:id page))
(:objects page)
shape
(:data library)
page
libraries
id-new
0
nil
keep-props-values
false)]
page libraries (:data library) shape id-new false)]
(thf/apply-changes file changes)))
(defn- setup-library-with-absolute-nested-icon
@ -211,13 +202,13 @@
;; ==== Check
(t/is (true? (:layout-item-absolute swapped)))
(t/is (some? (ctk/get-swap-slot swapped)))
(t/is (ctk/swapped? swapped))
(t/is (= (thi/id :icon-b) (:component-id swapped)))
(t/is (some? (ctk/get-swap-slot swapped')))
(t/is (ctk/swapped? swapped'))
(t/is (= (thi/id :icon-b) (:component-id swapped')))
(t/is (true? (:layout-item-absolute swapped')))))
(t/deftest test-sync-library-propagates-slot-absolute-to-swapped-nested
(t/deftest test-sync-library-propagates-position-absolute-to-swapped-nested
(let [;; ==== Setup
library (setup-library-with-absolute-nested-icon)
file (-> (thf/sample-file :file)
@ -234,7 +225,7 @@
swapped' (ths/get-shape file' :copy-nested-head)]
;; ==== Check
(t/is (some? (ctk/get-swap-slot swapped')))
(t/is (ctk/swapped? swapped'))
(t/is (= (thi/id :icon-b) (:component-id swapped')))
(t/is (not (true? (:layout-item-absolute swapped'))))))
@ -268,4 +259,4 @@
;; ==== Check
(t/is (= margin (:layout-item-margin sibling')))
(t/is (true? (:layout-item-absolute swapped')))
(t/is (some? (ctk/get-swap-slot swapped')))))
(t/is (ctk/swapped? swapped'))))

View File

@ -872,7 +872,7 @@
(t/is (not (ctk/swapped? copied-blue1')))))))))
(t/deftest test-keep-inherited-swap-slot-copy-paste-nested-copy-to-root
(t/deftest test-keep-inherited-swap-group-copy-paste-nested-copy-to-root
(t/async
done
(let [;; ==== Setup
@ -934,12 +934,13 @@
;; ==== Check
;; the copied icon now refers to the icon main, where blue
;; does not exist, so the copied blue must keep the swap slot
;; inherited from :blue-copy-title
;; does not exist, so the copied blue must keep the position
;; reference inherited from :blue-copy-title and its swap group.
(t/is (some? copied-icon'))
(t/is (= (:shape-ref copied-icon') (cthi/id :frame-icon)))
(t/is (some? copied-blue'))
(t/is (= (ctk/get-swap-slot copied-blue') (cthi/id :red-copy-icon)))
(t/is (= (:shape-ref copied-blue') (cthi/id :red-copy-icon)))
(t/is (ctk/swapped? copied-blue'))
;; the file must be valid after the paste
(t/is (nil? errors))))))))
@ -985,7 +986,7 @@
(t/is (contains? (:touched copied-red') :fill-group))
(t/is (= (:touched red') (:touched copied-red')))))))))
(t/deftest test-remove-swap-slot-copy-paste-nested-swapped-copy-to-root
(t/deftest test-remove-swap-group-copy-paste-nested-swapped-copy-to-root
(t/async
done
(let [;; ==== Setup (sample file as is)
@ -1014,6 +1015,7 @@
copied-blue' (find-copied-shape blue' page' uuid/zero)]
;; ==== Check
;; the copied blue has no swap-id
;; The copied blue refers to its own main and has no swap override.
(t/is (some? copied-blue'))
(t/is (nil? (ctk/get-swap-slot copied-blue')))))))))
(t/is (not (ctk/swapped? copied-blue')))
(t/is (= (:shape-ref copied-blue') (cthi/id :frame-blue)))))))))