mirror of
https://github.com/penpot/penpot.git
synced 2026-11-23 02:40:32 +00:00
Count repeated processing of each component instead of total graph width. A valid dependency graph with 102 outer components now settles and updates every copy (F108). The non-settling cascade guard remains bounded. The regression failed at 100 passes before the fix, then passed with 103 components. Common JVM/JS, frontend, backend and exporter suites pass. Benchmark vs Phase 1e (lower quantile, ms): world baseline now ratio main-10 1.790 0.993 0.55 main-100 15.415 9.038 0.59 main-1000 153.086 90.145 0.59 three-levels 35.215 18.989 0.54 chain 68.931 35.045 0.51 library-500 83.083 85.830 1.03 many-shapes 4.837 3.344 0.69 variant-100 32.052 33.586 1.05 All worlds pass the 10% regression threshold. AI-assisted-by: GPT-6
168 lines
7.7 KiB
Clojure
168 lines
7.7 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
;;
|
||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||
|
||
(ns common-tests.logic.chained-propagation-test
|
||
(:require
|
||
[app.common.files.changes-builder :as pcb]
|
||
[app.common.logic.instances :as cli]
|
||
[app.common.logic.libraries :as cll]
|
||
[app.common.logic.shapes :as cls]
|
||
[app.common.test-helpers.components :as thc]
|
||
[app.common.test-helpers.compositions :as tho]
|
||
[app.common.test-helpers.files :as thf]
|
||
[app.common.test-helpers.ids-map :as thi]
|
||
[app.common.test-helpers.shapes :as ths]
|
||
[app.common.types.container :as ctn]
|
||
[clojure.test :as t]))
|
||
|
||
(t/use-fixtures :each thi/test-fixture)
|
||
|
||
(t/deftest a-wide-component-cascade-settles
|
||
(let [labels (mapv #(keyword (str "outer-" %)) (range 102))
|
||
file (reduce (fn [file label]
|
||
(let [root (keyword (str (name label) "-main"))
|
||
head (keyword (str (name label) "-nested"))
|
||
copy (keyword (str (name label) "-copy"))]
|
||
(-> file
|
||
(tho/add-frame root)
|
||
(thc/instantiate-component :inner head :parent-label root)
|
||
(thc/make-component label root)
|
||
(thc/instantiate-component label copy))))
|
||
(-> (thf/sample-file :file1)
|
||
(tho/add-simple-component :inner :inner-main :inner-child))
|
||
labels)
|
||
file (ths/update-shape file :inner-child :fills
|
||
(ths/sample-fills-color :fill-color "#FF0000"))
|
||
result (cll/generate-sync-components-cascade
|
||
(pcb/empty-changes) (:id file) #{(thi/id :inner)}
|
||
{(:id file) file} (:id file))
|
||
synced (thf/apply-changes file (:changes result))]
|
||
(t/is (= 103 (count (:component-ids result))))
|
||
(doseq [label labels]
|
||
(t/is (= "#FF0000" (tho/bottom-fill-color synced (keyword (str (name label) "-copy"))))))))
|
||
|
||
(defn- first-fill-color [file tag]
|
||
(-> (ths/get-shape file tag)
|
||
(:fills)
|
||
first
|
||
:fill-color))
|
||
|
||
(defn- first-child-fill-color [file tag]
|
||
(let [shape (ths/get-shape file tag)]
|
||
(-> (ths/get-shape-by-id file (first (:shapes shape)))
|
||
(:fills)
|
||
first
|
||
:fill-color)))
|
||
|
||
;; Related .penpot file: common/test/cases/chained-components-changes-propagation.penpot
|
||
(t/deftest test-propagation-with-anidated-components
|
||
(letfn [(setup []
|
||
(-> (thf/sample-file :file1)
|
||
(tho/add-frame :frame-comp-1)
|
||
(ths/add-sample-shape :rectangle :parent-label :frame-comp-1 :fills (ths/sample-fills-color :fill-color "#2653d8"))
|
||
(thc/make-component :comp-1 :frame-comp-1)
|
||
|
||
(tho/add-frame :frame-comp-2)
|
||
(thc/instantiate-component :comp-1 :copy-comp-1 :parent-label :frame-comp-2 :children-labels [:rect-comp-2])
|
||
(thc/make-component :comp-2 :frame-comp-2)
|
||
|
||
(tho/add-frame :frame-comp-3)
|
||
(thc/instantiate-component :comp-2 :copy-comp-2 :parent-label :frame-comp-3 :children-labels [:comp-1-comp-2])
|
||
(thc/make-component :comp-3 :frame-comp-3)))
|
||
|
||
(propagate-all-component-changes [file]
|
||
(-> file
|
||
(tho/propagate-component-changes :comp-1)
|
||
(tho/propagate-component-changes :comp-2)))
|
||
|
||
(fill-colors [file]
|
||
[(tho/bottom-fill-color file :frame-comp-1)
|
||
(tho/bottom-fill-color file :frame-comp-2)
|
||
(tho/bottom-fill-color file :frame-comp-3)])
|
||
|
||
(validate [file validator]
|
||
(validator file)
|
||
file)]
|
||
|
||
(-> (setup)
|
||
;; Change the color of Comp1 inside Comp2 to red. It will propagate to Comp1 inside Comp3
|
||
(tho/update-bottom-color :frame-comp-2 "#FF0000" :propagate-fn propagate-all-component-changes)
|
||
(validate #(t/is (= (fill-colors %) ["#2653d8" "#FF0000" "#FF0000"])))
|
||
|
||
;; Change the color of Comp1 inside Comp3 to green.
|
||
(tho/update-bottom-color :frame-comp-3 "#00FF00" :propagate-fn propagate-all-component-changes)
|
||
(validate #(t/is (= (fill-colors %) ["#2653d8" "#FF0000" "#00FF00"])))
|
||
|
||
;; Select Comp1 inside Comp3, and do a ‘Reset override’
|
||
;; Desired result: Comp1 inside Comp3 change its color to red, like Comp1 inside Comp2.
|
||
(tho/reset-overrides-in-first-child :copy-comp-2)
|
||
(validate #(t/is (= (fill-colors %) ["#2653d8" "#FF0000" "#FF0000"]))))))
|
||
|
||
(t/deftest test-propagation-with-deleted-component
|
||
(letfn [(setup []
|
||
(-> (thf/sample-file :file1)
|
||
(tho/add-frame :frame-comp-4)
|
||
(ths/add-sample-shape :rectangle :parent-label :frame-comp-4 :fills (ths/sample-fills-color :fill-color "#b1b2b5"))
|
||
(thc/make-component :comp-4 :frame-comp-4)
|
||
|
||
(tho/add-frame :frame-comp-5)
|
||
(thc/instantiate-component :comp-4 :copy-comp-4 :parent-label :frame-comp-5 :children-labels [:rect-comp-5])
|
||
(thc/make-component :comp-5 :frame-comp-5)
|
||
|
||
(tho/add-frame :frame-comp-6)
|
||
(thc/instantiate-component :comp-5 :copy-comp-5 :parent-label :frame-comp-6 :children-labels [:comp-4-comp-5])
|
||
(thc/make-component :comp-6 :frame-comp-6)
|
||
|
||
(thc/instantiate-component :comp-5 :loose-copy-comp-5)))
|
||
|
||
(propagate-all-component-changes [file]
|
||
(-> file
|
||
(tho/propagate-component-changes :comp-4)
|
||
(tho/propagate-component-changes :comp-5)))
|
||
|
||
(stored-fill-color [file]
|
||
(let [component (thc/get-component file :comp-5 :include-deleted? true)]
|
||
(when (:deleted component)
|
||
(->> (vals (:objects component))
|
||
(some #(when (= :rect (:type %))
|
||
(-> % :fills first :fill-color)))))))
|
||
|
||
(fill-colors [file]
|
||
[(tho/bottom-fill-color file :frame-comp-4)
|
||
(tho/bottom-fill-color file :frame-comp-5)
|
||
(tho/bottom-fill-color file :frame-comp-6)
|
||
(tho/bottom-fill-color file :loose-copy-comp-5)])
|
||
|
||
(restore-comp-5 [file]
|
||
(let [page (thf/current-page file)]
|
||
(thf/apply-changes file
|
||
(cli/generate-restore-component (pcb/empty-changes)
|
||
(:data file)
|
||
(thi/id :comp-5)
|
||
(:id file)
|
||
page
|
||
(:objects page)))))
|
||
|
||
(validate [file validator]
|
||
(validator file)
|
||
file)]
|
||
|
||
(-> (setup)
|
||
;; Delete Comp5.
|
||
(tho/delete-shape :frame-comp-5)
|
||
(validate #(t/is (= (fill-colors %) ["#b1b2b5" nil "#b1b2b5" "#b1b2b5"])))
|
||
|
||
;; Change the color of Comp4
|
||
;; Desired result: the deleted Comp5 keeps passing the change on, to
|
||
;; its stored main, its copy and Comp6
|
||
(tho/update-bottom-color :frame-comp-4 "#FF0000" :propagate-fn propagate-all-component-changes)
|
||
(validate #(t/is (= (fill-colors %) ["#FF0000" nil "#FF0000" "#FF0000"])))
|
||
(validate #(t/is (= (stored-fill-color %) "#FF0000")))
|
||
|
||
;; Restore Comp5: its main comes back up to date
|
||
(restore-comp-5)
|
||
(validate #(t/is (= (fill-colors %) ["#FF0000" "#FF0000" "#FF0000" "#FF0000"]))))))
|