🔧 Validate shapes after removing them from a variant

generate-make-shapes-no-variant now validates the main instances it
takes out of the variant. Only those main instances change. The old
container is not validated, as callers such as generate-relocate call
this function before they move the shapes out of it.

Check with thf/validates-shapes-last? that the function validates the
expected page and shapes.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Eva Marco 2026-09-30 16:51:43 +02:00 committed by Andrés Moya
parent ae1b541208
commit c16b439af9
2 changed files with 27 additions and 2 deletions

View File

@ -235,7 +235,14 @@
"Extract some components from a variant, removing the variant-id and variant-name from the
main instances and the variant-id and variant-properties from the components."
[changes shapes]
(reduce generate-make-shape-no-variant changes shapes))
(if (empty? shapes)
changes
;; Only the extracted main instances change. The container is not
;; validated, as the caller may not have moved the shapes out of it yet
(-> (reduce generate-make-shape-no-variant changes shapes)
(pcb/validate-shapes (pcb/get-page-id changes)
(mapv :id shapes)
(str "generate-make-shapes-no-variant: " (mapv :id shapes))))))
(defn- create-new-properties-from-variant
[shape min-props data container-name base-properties]

View File

@ -655,7 +655,25 @@
(t/is (nil? (:variant-id comp01')))
(t/is (nil? (:variant-properties comp01')))
(t/is (nil? (:variant-id main01')))
(t/is (nil? (:variant-name main01')))))
(t/is (nil? (:variant-name main01')))
(t/is (thf/validates-shapes-last? changes (:id page) [(:id main01)]))))
(t/deftest test-make-shapes-no-variant-validates-shapes
(let [file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
page (thf/current-page file)
main01 (ths/get-shape file :m01)
main02 (ths/get-shape file :m02)
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clvp/generate-make-shapes-no-variant [main01 main02]))]
;; Only the extracted main instances change. The container is not
;; validated, as the caller may not have moved the shapes out of it yet
(t/is (thf/validates-shapes-last? changes (:id page) [(:id main01) (:id main02)]))))
;; =============================================================================
;; generate-make-shapes-variant tests