🐛 Reject imported components v1 files that have graphics

A library in the components v1 format with graphics and no components
imported, but its graphics were lost: only the removed v1 to v2
migration turned them into components, and v2 has no graphics section,
so the file showed no assets at all.

`check-components-v2` now rejects a components v1 file with graphics
(`:media`) as it rejects one with components, with
`:file-in-components-v1`.

Found by the components Qase run (PENPOT-1598).

Test: `check-components-v2-looks-at-components-and-component-shapes`
(binfile-test).

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-19 09:57:53 +01:00
parent 61d3313fbb
commit 5808c873f6
2 changed files with 14 additions and 4 deletions

View File

@ -454,17 +454,21 @@
(true? (:main-instance shape))))
(defn- has-component-data?
[{:keys [components pages-index]}]
"Whether a components v1 file holds library data that only the removed
v1 to v2 migration could convert: components, shapes linked to them, or
graphics (`:media`), which v2 turns into components."
[{:keys [components media pages-index]}]
(or (seq components)
(seq media)
(some (fn [page] (some component-shape? (vals (:objects page))))
(vals pages-index))))
(defn check-components-v2
"Check that an imported file can be stored as a components v2 file.
A file without the `components/v2` feature is in the deprecated
components v1 format: it is rejected when it has components or shapes
linked to them, and otherwise takes the feature as it is. Returns the
file."
components v1 format: it is rejected when it has components, shapes
linked to them or graphics, and otherwise takes the feature as it is.
Returns the file."
[{:keys [features data] :as file}]
(cond
(contains? features "components/v2")

View File

@ -3813,6 +3813,12 @@
(t/is (rejected? (file #{} {:shape-ref (uuid/custom 2 2)} nil)))
(t/is (rejected? (file #{} {:main-instance true} nil))))
(t/testing "a file without components/v2 is rejected when it has graphics"
(let [media-id (uuid/custom 6 1)]
(t/is (rejected? (assoc-in (file #{} {} nil) [:data :media]
{media-id {:id media-id :name "icon" :width 24 :height 24
:mtype "image/svg+xml" :media-id (uuid/custom 6 2)}})))))
(t/testing "a file without components/v2 and without component data takes the feature"
(t/is (= #{"components/v2"}
(:features (bfc/check-components-v2 (file #{} {} nil))))))