mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 09:42:01 +00:00
Reflecting a shape re-decomposes the flip flags of the copy heads under it by placing them through a sync proposal from their mains. Its docstring promises to stay within existing geometry, but the proposal also carries a pending size of the copy's library main. A dependent library main nesting a copy of an upstream main whose width changed took that width when the dependent main was flipped, before the update was accepted. Settle reflected heads only on the shapes whose footprint the proposal keeps. Untouched swapped heads after a parent turn still take the proposal whole, since their content may differ in size from their position. A fresh JVM library-dependency run (seed 20261101) found this: a 0.01 px nested frame became 160 px wide (I4). The program regression fails before the fix and passes after it. The source, oracle, expected-geometry, reset, sync, swap-group and composable namespaces pass at seed 712: 330 tests / 3729 assertions. Compare lower-quantile milliseconds with the saved baseline; keep that baseline unchanged. The machine/JVM warning makes ratios rough. No world is flagged. World Baseline Now Ratio Main into 10 copies 1.790 0.944 0.53 Main into 100 copies 15.415 9.742 0.63 Main into 1000 copies 153.086 91.886 0.60 Three nesting levels 35.215 18.344 0.52 Dependency chain 68.931 36.790 0.53 Library update 83.083 45.517 0.55 Many plain shapes 4.837 2.256 0.47 Variant switch 32.052 20.228 0.63 AI-assisted-by: claude-opus-5-5
101 lines
4.9 KiB
Clojure
101 lines
4.9 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.source-gen-test
|
|
(:require
|
|
[app.common.test-helpers.composable.comp.runner :as r]
|
|
[app.common.test-helpers.composable.core :as tm]
|
|
[app.common.test-helpers.composable.gen :as cg]
|
|
[app.common.test-helpers.composable.oracle :as oracle]
|
|
[app.common.test-helpers.ids-map :as thi]
|
|
[clojure.test :as t]))
|
|
|
|
(t/use-fixtures :each thi/test-fixture)
|
|
|
|
(def source-world
|
|
[2 1 {:library true :stale-libraries true :library-text true :text true :text-styles true}])
|
|
|
|
(t/deftest a-transform-does-not-accept-pending-library-content-or-structure
|
|
(doseq [[edit index] [[[:library-text 0 1 1] 8]
|
|
[[:library-text 0 0 1] 8]
|
|
[[:library-edit 0 0 1] 4]
|
|
[[:library-add-child 0] 4]]]
|
|
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true :library-text true}]
|
|
:ops [edit [:transform index 3 3 4] [:undo] [:redo]
|
|
[:library-sync]]}))
|
|
(str edit))))
|
|
|
|
(t/deftest a-reflection-does-not-accept-a-pending-library-size
|
|
;; The dependent main nests a copy of a source main whose width is pending.
|
|
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
|
|
:library-dependency true :library-text true}]
|
|
:ops [[:library-transform 3 1 4 0] [:library-transform 0 4 4 0]
|
|
[:library-undo] [:library-redo]]}))))
|
|
|
|
(t/deftest source-transforms-keep-consumers-stale-until-acceptance
|
|
(doseq [action (range 6) scope [0 1]]
|
|
(let [initial (cg/initial-state source-world)
|
|
situation (:situation initial)
|
|
tuple [:library-transform 0 action 4 scope]
|
|
resolved (cg/resolve-op situation {} tuple)
|
|
owner (:library-id resolved)]
|
|
(t/is (some? (:op resolved)) (str "source transform " action ", scope " scope))
|
|
(when (:op resolved)
|
|
(let [edited (-> initial (cg/step tuple) cg/settle-state)
|
|
source (get (oracle/snapshot (:situation edited)) owner)]
|
|
(t/is (not= (get (oracle/snapshot situation) owner) source))
|
|
(t/is (= (dissoc (oracle/snapshot situation) owner)
|
|
(dissoc (oracle/snapshot (:situation edited)) owner)))
|
|
(t/is (zero? (r/undo-depth (:situation edited))))
|
|
(t/is (map? (cg/run {:world source-world
|
|
:ops [tuple [:library-sync] [:undo] [:redo]
|
|
[:library-undo] [:library-redo] [:library-sync]]}))))))))
|
|
|
|
(t/deftest source-text-edits-cover-letters-and-every-style-unit
|
|
(doseq [tuple (into [[:library-text 0 0 1]]
|
|
(map #(vector :library-text-style 0 % 1) (range 12)))]
|
|
(let [initial (cg/initial-state source-world)
|
|
situation (:situation initial)
|
|
resolved (cg/resolve-op situation {} tuple)
|
|
owner (:library-id resolved)]
|
|
(t/is (some? (:op resolved)) (str tuple))
|
|
(when (:op resolved)
|
|
(let [edited (-> initial (cg/step tuple) cg/settle-state)]
|
|
(t/is (not= (get (oracle/snapshot situation) owner)
|
|
(get (oracle/snapshot (:situation edited)) owner)))
|
|
(t/is (= (dissoc (oracle/snapshot situation) owner)
|
|
(dissoc (oracle/snapshot (:situation edited)) owner)))
|
|
(t/is (zero? (r/undo-depth (:situation edited))))
|
|
(t/is (map? (cg/run {:world source-world
|
|
:ops [tuple [:library-sync] [:undo] [:redo]
|
|
[:library-undo] [:library-redo] [:library-sync]]}))))))))
|
|
|
|
(t/deftest source-intent-checks-reject-a-dropped-primary-edit
|
|
(doseq [tuple [[:library-transform 0 1 4 0]
|
|
[:library-transform 0 3 1 1]
|
|
[:library-text 0 0 1]
|
|
[:library-text-style 0 2 1]]]
|
|
(let [initial (cg/initial-state source-world)]
|
|
(t/is (= :I9
|
|
(try
|
|
(with-redefs [r/step (fn [situation _] situation)]
|
|
(cg/step initial tuple))
|
|
nil
|
|
(catch #?(:clj Exception :cljs js/Error) error
|
|
(:invariant (ex-data error)))))
|
|
(str "dropped source intent " tuple)))))
|
|
|
|
(t/deftest source-text-fixture-does-not-reuse-consumer-shape-ids
|
|
(let [situation (cg/world source-world)
|
|
entries (cg/forest situation)
|
|
ids (map (comp :id :shape) entries)
|
|
source-texts (for [[_ library] (tm/aux-files situation)
|
|
entry (cg/tree (tm/with-file situation library))
|
|
:when (= :text (get-in entry [:shape :type]))]
|
|
entry)]
|
|
(t/is (= (count ids) (count (set ids))))
|
|
(t/is (seq source-texts))))
|