mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep pending library edits out of transform settlement
Use the component sync result only as a geometry proposal when settling reflections and swapped placement. Correct existing shapes without pulling pending library content, styles or structure into a transformed copy. Keep path geometry and the primary action's exact undo/redo group. Generate source transforms, letters and all twelve text style units with separate source histories and explicit consumer acceptance. Add dropped source-edit controls and portable/frontend regressions for the accidental pull. Register the new portable namespace in the JavaScript runner. The complete original program and both reductions pass unchanged. Common JVM passes 1,919 tests/31,313 assertions. Full JS passes 1,845/29,770; the newly registered source namespace adds 5/135 passing checks. Frontend passes 1,566/11,119, backend 1,610/8,104 and exporter 14/32. Lint and formatting pass; browser ShapeProxy replay passes. No golden data changes. Benchmark ratios against the unchanged baseline: mains 10/100/1000 0.57/0.65/0.61, levels 0.52, chain 0.51, library 0.52, many shapes 0.47, variant switch 0.60. No regression flag. AI-assisted-by: gpt-6
This commit is contained in:
parent
f54d1a288e
commit
a88f53874d
@ -414,11 +414,17 @@
|
||||
changes)
|
||||
changes)))
|
||||
|
||||
(def ^:private placement-geometry-attrs
|
||||
#{:x :y :width :height :selrect :points :transform :transform-inverse
|
||||
:rotation :flip-x :flip-y :content-scale})
|
||||
|
||||
(defn generate-sync-transformed-placement
|
||||
"Settle copy descendants after a reflection and untouched swapped heads
|
||||
after a parent turn, in the transform's change group. Reflection can
|
||||
leave descendant flip flags in another decomposition; swapped content
|
||||
can have a different size from its position frame."
|
||||
can have a different size from its position frame. Keep this correction
|
||||
within existing geometry: transforming a stale library copy must not
|
||||
accept pending content, style or structural changes."
|
||||
[changes file libraries page before ids]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
orientation (fn [shape]
|
||||
@ -443,11 +449,21 @@
|
||||
(let [objects (pcb/get-objects changes)
|
||||
page (assoc page :objects objects)
|
||||
file (assoc-in file [:data :pages-index (:id page) :objects] objects)
|
||||
container (ctn/make-container page :page)]
|
||||
(-> changes
|
||||
(pcb/with-container container)
|
||||
(generate-sync-shape-direct file (assoc libraries (:id file) file)
|
||||
container id false))))
|
||||
container (ctn/make-container page :page)
|
||||
changes (pcb/with-container changes container)
|
||||
proposal (generate-sync-shape-direct changes file (assoc libraries (:id file) file)
|
||||
container id false)
|
||||
placed (pcb/get-objects proposal)]
|
||||
(pcb/update-shapes
|
||||
changes (cfh/get-children-ids-with-self objects id)
|
||||
(fn [shape]
|
||||
(let [expected (get placed (:id shape))
|
||||
attrs (cond-> placement-geometry-attrs
|
||||
(= :path (:type shape)) (conj :content))]
|
||||
(if (= (:type shape) (:type expected))
|
||||
(merge shape (select-keys expected attrs))
|
||||
shape)))
|
||||
{:ignore-touched true})))
|
||||
changes roots)))
|
||||
|
||||
(defn- sync-copy-shape
|
||||
|
||||
93
common/test/common_tests/logic/source_gen_test.cljc
Normal file
93
common/test/common_tests/logic/source_gen_test.cljc
Normal file
@ -0,0 +1,93 @@
|
||||
;; 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 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))))
|
||||
@ -85,6 +85,7 @@
|
||||
[common-tests.logic.multiple-nesting-levels-test]
|
||||
[common-tests.logic.override-scan-test]
|
||||
[common-tests.logic.placement-test]
|
||||
[common-tests.logic.source-gen-test]
|
||||
[common-tests.logic.swap-and-reset-test]
|
||||
[common-tests.logic.swap-as-override-test]
|
||||
[common-tests.logic.swap-group-test]
|
||||
@ -221,6 +222,7 @@
|
||||
'common-tests.logic.multiple-nesting-levels-test
|
||||
'common-tests.logic.override-scan-test
|
||||
'common-tests.logic.placement-test
|
||||
'common-tests.logic.source-gen-test
|
||||
'common-tests.logic.swap-and-reset-test
|
||||
'common-tests.logic.swap-as-override-test
|
||||
'common-tests.logic.swap-group-test
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
[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.normalize :as thn]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.test-helpers.texts :as thtx]
|
||||
[app.common.time :as ct]
|
||||
@ -35,6 +36,7 @@
|
||||
[app.main.data.workspace.thumbnails-wasm :as dwthw]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.data.workspace.wasm-text :as dwwt]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.store :as st]
|
||||
[app.render-wasm.api :as wasm]
|
||||
[app.render-wasm.api.fonts :as wasm.fonts]
|
||||
@ -387,6 +389,75 @@
|
||||
(t/is (= red (fill (:id first-copy))))
|
||||
(t/is (= setup/labeled-fill (fill (:id other-copy))))))
|
||||
|
||||
(defn- ^:async source-acceptance-history
|
||||
[tuple transform-tuple]
|
||||
(let [initial (cg/initial-state [2 1 {:library true :stale-libraries true :library-text true}])
|
||||
situation (:situation initial)
|
||||
owner (:library-id (cg/resolve-op situation {} tuple))
|
||||
transform-tuple (when transform-tuple
|
||||
(assoc transform-tuple 1
|
||||
(first (keep-indexed
|
||||
(fn [index entry]
|
||||
(when (= (thi/id :library-text-component)
|
||||
(get-in entry [:shape :component-id])) index))
|
||||
(cg/candidates situation {} :transform 4)))))
|
||||
edited (-> initial (cg/step tuple) cg/settle-state)
|
||||
group (peek (get-in edited [:situation :library-histories owner :runner ::r/undo-stack]))
|
||||
changes (mapcat :redo-changes group)
|
||||
;; The notification envelope advances the loaded library revision.
|
||||
edited (update edited :situation
|
||||
#(tm/with-aux-files % (update (tm/aux-files %) owner assoc :revn 1)))
|
||||
_ (ftm/start-generated situation)
|
||||
current-id (:id (tm/file situation))
|
||||
before (get-in (ftm/snapshot) [:files current-id])]
|
||||
(t/is (seq changes) (str "source edit changes " tuple))
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/ext-library-changed owner (ct/now) 1 changes)]))))
|
||||
(t/is (= before (get-in (ftm/snapshot) [:files current-id])) "notification keeps consumer copies stale")
|
||||
(t/is (empty? (get-in @st/state [:workspace-undo :items])) "notification creates no consumer history")
|
||||
(when transform-tuple
|
||||
(let [before-transform (ftm/snapshot)
|
||||
resolved (cg/resolve-op situation {} transform-tuple)
|
||||
content (fn []
|
||||
(into {} (map (fn [{:keys [shape]}]
|
||||
[(:id shape) (select-keys shape [:content :name :fills :strokes :shapes :opacity])]))
|
||||
(cg/tree (ftm/refresh-generated situation))))
|
||||
before-content (content)]
|
||||
(t/is (= :settled (await (ftm/await-step (ftm/op->events (:op resolved) situation)))))
|
||||
(t/is (= before-content (content)) "a transform keeps pending source content and structure stale")
|
||||
(let [after-transform (ftm/snapshot)]
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
(t/is (uc/same-state? before-transform (ftm/snapshot)))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after-transform (ftm/snapshot))))))
|
||||
(let [edited (cond-> edited transform-tuple (cg/step transform-tuple))
|
||||
before-accept (ftm/snapshot)
|
||||
expected (-> edited (cg/step [:library-sync]) cg/settle-state)]
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/sync-file current-id owner)]))))
|
||||
(let [actual (ftm/refresh-generated (:situation expected))
|
||||
after-accept (ftm/snapshot)
|
||||
expected-design (oracle/canonical (:situation expected))
|
||||
actual-design (oracle/canonical actual)]
|
||||
(t/is (true? (oracle/equivalent? expected-design actual-design))
|
||||
(str "consumer acceptance " tuple ": " (pr-str (thn/diff expected-design actual-design))))
|
||||
(t/is (nil? (oracle/check actual (:model expected))))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
(t/is (uc/same-state? before-accept (ftm/snapshot)) "undo restores the stale consumer only")
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after-accept (ftm/snapshot)) "redo restores accepted geometry and text")))))
|
||||
|
||||
(t/deftest ^:async source-geometry-and-text-wait-for-consumer-acceptance
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(doseq [tuple (concat (map #(vector :library-transform 0 % 4 1) (range 6))
|
||||
[[:library-text 0 0 1]]
|
||||
(map #(vector :library-text-style 0 % 1) (range 12)))]
|
||||
(await (source-acceptance-history tuple nil))))))
|
||||
|
||||
(t/deftest ^:async a-transform-keeps-library-text-stale-until-acceptance
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(await (source-acceptance-history [:library-text 0 1 1] [:transform 8 3 3 4])))))
|
||||
|
||||
(t/deftest ^:async edit-step-waits-for-slow-sync
|
||||
(let [sync-file dwl/sync-file]
|
||||
(await
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user