mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
♻️ Name a branch's parent source in the backend and merge engine
The public names already said source for the file a branch was cut from. The internal names, docstrings, and comments of the backend and the merge engine still said main, which turns false once a branch can be cut from another branch. They now say source for a branch's parent and root for the top file of a file family. The merge policy :container-delete-over-main-edits becomes :container-delete-over-target-edits, after the engine's role names. The component sense of main (a component's main shape) and the stored file_data type "main" keep their names. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
be49abf2cf
commit
0d418cdf43
@ -64,7 +64,7 @@
|
||||
|
||||
:same-parent-reorder :merge | :refuse | :ignore
|
||||
:addition-under-deleted-parent :conflict | :refuse | :reparent-to-ancestor | :page-root
|
||||
:container-delete-over-main-edits :conflict | :expand | :cascade
|
||||
:container-delete-over-target-edits :conflict | :expand | :cascade
|
||||
|
||||
An invalid file logs a warning and the engine runs the built-in
|
||||
defaults until the file is fixed."
|
||||
@ -216,7 +216,7 @@
|
||||
:main (fn [page-id]
|
||||
[(del-obj page-id parent)])}))
|
||||
|
||||
(defn- case-delete-container-over-main-edits
|
||||
(defn- case-delete-container-over-target-edits
|
||||
"The branch deletes the frame F while main recolours F's child C and
|
||||
adds N inside F."
|
||||
[]
|
||||
@ -297,7 +297,7 @@
|
||||
[case-reorder-branch-only
|
||||
case-reorder-both-sides
|
||||
case-add-under-deleted-parent
|
||||
case-delete-container-over-main-edits
|
||||
case-delete-container-over-target-edits
|
||||
case-addition-order])]
|
||||
(println "project:" (:name project) (str (:id project)))
|
||||
(print-table [:id :name :branch-id :branch-file-id] files)
|
||||
|
||||
@ -22,26 +22,27 @@
|
||||
:same-parent-reorder :merge
|
||||
|
||||
;; --- :addition-under-deleted-parent
|
||||
;; main deleted the frame P while the branch added a shape inside P.
|
||||
;; The source deleted the frame P while the branch added a shape inside P.
|
||||
;;
|
||||
;; :conflict a :modify-delete conflict on P: :branch
|
||||
;; restores P as the branch has it, addition
|
||||
;; included; :main drops the addition.
|
||||
;; included; :source drops the addition.
|
||||
;; :refuse the merge/update refuses with :unsupported.
|
||||
;; :reparent-to-ancestor place the addition under the nearest
|
||||
;; ancestor main still has.
|
||||
;; ancestor the source still has.
|
||||
;; :page-root today's behaviour: the addition lands at
|
||||
;; the page root.
|
||||
:addition-under-deleted-parent :conflict
|
||||
|
||||
;; --- :container-delete-over-main-edits
|
||||
;; The branch deleted the container F while main modified or added
|
||||
;; anything inside F's subtree.
|
||||
;; --- :container-delete-over-target-edits
|
||||
;; One side of a merge or an update deleted the container F while the
|
||||
;; side receiving the changes modified or added anything inside F's
|
||||
;; subtree.
|
||||
;;
|
||||
;; :conflict a :delete-modify conflict on F: :branch deletes the
|
||||
;; whole subtree knowingly; :main keeps F and its subtree
|
||||
;; as main has them.
|
||||
;; :expand delete only shapes the branch deleted; main's additions
|
||||
;; whole subtree knowingly; :source keeps F and its subtree
|
||||
;; as the source has them.
|
||||
;; :expand delete only shapes the branch deleted; the source's additions
|
||||
;; move to F's parent.
|
||||
;; :cascade today's behaviour: the whole subtree goes.
|
||||
:container-delete-over-main-edits :conflict}
|
||||
:container-delete-over-target-edits :conflict}
|
||||
|
||||
@ -418,7 +418,7 @@
|
||||
(defn get-branch-change-media-maps
|
||||
"The media id maps the branch's op log rows carry, in the stored (as
|
||||
applied) direction {old-id -> new-id}: the remap a save's media fix-up
|
||||
or an update from main applied, one map per row, oldest first. A nil
|
||||
or an update from the source applied, one map per row, oldest first. A nil
|
||||
element means the row carries no stamp: either it was written before
|
||||
the column existed, or it recorded the empty map explicitly."
|
||||
[{:keys [::db/conn] :as cfg} branch-file-id]
|
||||
@ -448,10 +448,10 @@
|
||||
|
||||
(defn migrate-branch-base
|
||||
"The `:data` of a branch's merge-base snapshot at the current data
|
||||
version. The snapshot keeps the version main had when the base was
|
||||
taken, while `get-file` migrates main and the branch on every read, so
|
||||
a three-way comparison sees one version on all three sides only when
|
||||
the base migrates the same way, with main's libraries. A base already
|
||||
version. The snapshot keeps the version the source had when the base
|
||||
was taken, while `get-file` migrates the source and the branch on every
|
||||
read, so a three-way comparison sees one version on all three sides
|
||||
only when the base migrates the same way, with the source's libraries. A base already
|
||||
at the current version comes back as it is.
|
||||
|
||||
`snapshot` is a snapshot row with its data decoded: `:file-id`,
|
||||
@ -504,7 +504,7 @@
|
||||
|
||||
With `include-base-data?` true the returned file also carries the
|
||||
merge-base document under `::base-data`, migrated to the current data
|
||||
version (`migrate-branch-base`), the version `get-file` brings main and
|
||||
version (`migrate-branch-base`), the version `get-file` brings the source and
|
||||
the branch to. A caller that is about to compare the branch with its
|
||||
base reads the branch file with that flag and takes the value, and it
|
||||
never decodes the same snapshot a second time."
|
||||
@ -547,7 +547,7 @@
|
||||
base (fdata/resolve-file-data cfg base)
|
||||
base (fdata/decode-file-data cfg base)
|
||||
;; the fragment ids the base names, read before the realize
|
||||
;; drops them: a comparison skips every page main still shares
|
||||
;; drops them: a comparison skips every page the source still shares
|
||||
base-ids (fdata/get-page-pointer-ids (:data base))
|
||||
|
||||
;; the base shares the source file's fragments; past this point
|
||||
@ -593,7 +593,7 @@
|
||||
(not decode?) (blob/encode))
|
||||
|
||||
;; the comparison's `base` is the merge base before the replay,
|
||||
;; at the version main and the branch are read at. The replay
|
||||
;; at the version the source and the branch are read at. The replay
|
||||
;; returns the branch's own state in `data`, so a comparison
|
||||
;; handed `data` as its base would compare the branch with
|
||||
;; itself.
|
||||
@ -624,7 +624,7 @@
|
||||
(cond-> include-base-data?
|
||||
(assoc ::base-data base-data
|
||||
;; a migrated base no longer holds what its fragments
|
||||
;; hold, so its ids say nothing about main
|
||||
;; hold, so its ids say nothing about the source
|
||||
::base-page-pointers (when (identical? base-data (:data base))
|
||||
base-ids)))
|
||||
;; the numbers travel with the value, because the RPC audit event
|
||||
|
||||
@ -357,7 +357,7 @@
|
||||
(when is-branch
|
||||
(ex/raise :type :validation
|
||||
:code :branch-file-cant-be-restored
|
||||
:hint "branch file data is derived from the branch base and the operation log; restore the snapshot on the source file or update the branch from main instead"
|
||||
:hint "branch file data is derived from the branch base and the operation log; restore the snapshot on the source file or update the branch from its source instead"
|
||||
:file-id id)))
|
||||
|
||||
(defn restore!
|
||||
|
||||
@ -1016,8 +1016,8 @@
|
||||
|
||||
;; Absorption skips branch files. A branch stores no data payload, so an
|
||||
;; absorption written to one would land in a `file_data` row that no read
|
||||
;; consults. An open branch reaches main's absorbed copies on its next
|
||||
;; update from main. Until then an unpublished library still resolves in
|
||||
;; consults. An open branch reaches its source's absorbed copies on its
|
||||
;; next update from the source. Until then an unpublished library still resolves in
|
||||
;; the branch through the branch's own link, which `set-file-shared`
|
||||
;; keeps, and a soft-deleted library resolves nothing in the branch. A
|
||||
;; branch file keeps `is_branch` while its deletion is pending, so the
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -220,7 +220,7 @@
|
||||
;; The timer starts BEFORE `get-file`. A branch file stores no payload,
|
||||
;; so that read folds the merge-base snapshot and the op log into the
|
||||
;; derived document, and every other branch command (compare, merge,
|
||||
;; update-from-main, materialize) creates its timer ahead of its own
|
||||
;; update-from-source, materialize) creates its timer ahead of its own
|
||||
;; file reads. Starting here puts a branch save's `branch-duration-ms`
|
||||
;; on the same footing as theirs: the number covers the read, and for a
|
||||
;; branch the derive inside it, as well as the rest of the save. The
|
||||
@ -636,7 +636,7 @@
|
||||
It also records the media id map the fix-up applied, as applied
|
||||
({old-id -> new-id}, the branch's copy is the new one), filtered to
|
||||
the copies whose source row the branch's source file owns: a copy of
|
||||
media from another file is branch-own media with no main counterpart,
|
||||
media from another file is branch-own media with no source counterpart,
|
||||
and only the source's pairing is what a comparison rebuilds from the
|
||||
stamps (`files_branch.clj::branch-media-pairs`)."
|
||||
[{:keys [::db/conn ::timestamp] :as cfg} file changes media-index]
|
||||
@ -658,7 +658,7 @@
|
||||
:file-id (:id file)))
|
||||
|
||||
;; Only an open branch takes saves. A branch kept after its merge has
|
||||
;; its work in main, and no command integrates ops appended after the
|
||||
;; its work in the source, and no command integrates ops appended after the
|
||||
;; merge. An archived branch is read-only until it is restored or
|
||||
;; turned into an ordinary file. Refuse instead of stranding the ops.
|
||||
(case (:status branch)
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
|
||||
(ns backend-tests.branch-copies-follow-component-test
|
||||
"Copies follow their merged component. When a branch is merged into
|
||||
main, or main's changes are brought into the branch, the copies of a
|
||||
its source, or the source's changes are brought into the branch, the copies of a
|
||||
local component end up as Penpot's component sync leaves them after
|
||||
the integrated component: an attribute no side overrode by hand follows
|
||||
the component, an attribute one side overrode keeps that side's value,
|
||||
and only an attribute both sides overrode differently is a conflict.
|
||||
|
||||
Each test builds main with a local component (main `:mi-id`) and one
|
||||
Each test builds a source file with a local component (main `:mi-id`) and one
|
||||
copy of it (`:copy-id`), branches it, edits both sides and integrates.
|
||||
A component edit writes the main and, as the workspace's sync does,
|
||||
the untouched copy with `:ignore-touched`; an override writes the copy
|
||||
@ -98,7 +98,7 @@
|
||||
(sync-fill page-id copy-id color)])
|
||||
|
||||
(def ^:private token-colors
|
||||
"The colour tokens `setup` adds to main, by name."
|
||||
"The colour tokens `setup` adds to the source, by name."
|
||||
{"green" "#00ff00" "blue" "#0000ff" "red" "#ff0000" "yellow" "#ffff00"})
|
||||
|
||||
(defn- apply-fill-token
|
||||
@ -129,45 +129,45 @@
|
||||
(sync-fill-token page-id copy-id token-name)])
|
||||
|
||||
(defn- setup
|
||||
"Main holding a local component (main `:mi-id`) with one copy
|
||||
"A source file holding a local component (main `:mi-id`) with one copy
|
||||
(`:copy-id`) and a token set with the colour tokens `token-colors`,
|
||||
branched once. `n` numbers the profile and the file, so one test can
|
||||
build more than one. With `:override`, the copy's fill is overridden
|
||||
to that colour before branching, so the base holds the override."
|
||||
[n & {:keys [override]}]
|
||||
(let [profile (th/create-profile* n {:is-active true})
|
||||
file (th/create-file* n {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (get-file profile main-id) :data :pages first)
|
||||
comp-id (uuid/random)
|
||||
mi-id (uuid/random)
|
||||
copy-id (uuid/random)
|
||||
set-id (uuid/random)]
|
||||
(save profile main-id
|
||||
(let [profile (th/create-profile* n {:is-active true})
|
||||
file (th/create-file* n {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
source-id (:id file)
|
||||
page-id (-> (get-file profile source-id) :data :pages first)
|
||||
comp-id (uuid/random)
|
||||
mi-id (uuid/random)
|
||||
copy-id (uuid/random)
|
||||
set-id (uuid/random)]
|
||||
(save profile source-id
|
||||
[(add-root page-id mi-id (component-frame mi-id {:component-root true
|
||||
:main-instance true
|
||||
:component-id comp-id
|
||||
:component-file main-id}))
|
||||
:component-file source-id}))
|
||||
{:type :add-component :id comp-id :name "Button" :path ""
|
||||
:main-instance-id mi-id :main-instance-page page-id}
|
||||
(copy-of page-id copy-id comp-id mi-id main-id)
|
||||
(copy-of page-id copy-id comp-id mi-id source-id)
|
||||
{:type :set-token-set :id set-id :attrs {:id set-id :name "core"}}])
|
||||
(save profile main-id
|
||||
(save profile source-id
|
||||
(mapv (fn [[token-name color]]
|
||||
(let [token-id (uuid/random)]
|
||||
{:type :set-token :set-id set-id :token-id token-id
|
||||
:attrs {:id token-id :name token-name :type :color :value color}}))
|
||||
token-colors))
|
||||
(when override
|
||||
(save profile main-id [(set-fill page-id copy-id override)]))
|
||||
(save profile source-id [(set-fill page-id copy-id override)]))
|
||||
(let [branch (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id main-id
|
||||
:file-id source-id
|
||||
:name "copies"}))]
|
||||
{:profile profile
|
||||
:main-id main-id
|
||||
:source-id source-id
|
||||
:page-id page-id
|
||||
:comp-id comp-id
|
||||
:mi-id mi-id
|
||||
@ -208,29 +208,29 @@
|
||||
|
||||
;; --- a: one side edits the component, the other adds a copy
|
||||
|
||||
(t/deftest merge-syncs-a-copy-main-added-to-the-branch-component
|
||||
(t/deftest merge-syncs-a-copy-the-source-added-to-the-branch-component
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup 1)
|
||||
(let [{:keys [profile source-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup 1)
|
||||
new-copy (uuid/random)]
|
||||
(save profile branch-file-id (edit-component page-id mi-id copy-id "#00ff00"))
|
||||
(save profile main-id [(copy-of page-id new-copy comp-id mi-id main-id)])
|
||||
(save profile source-id [(copy-of page-id new-copy comp-id mi-id source-id)])
|
||||
|
||||
(let [out (merge-branch ctx)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (= "#00ff00" (fill main page-id mi-id)))
|
||||
(t/is (= "#00ff00" (fill main page-id new-copy)))
|
||||
(t/is (= "#00ff00" (fill main page-id copy-id)))
|
||||
(t/is (empty? (:touched (shape main page-id copy-id))))
|
||||
(t/is (empty? (validation-codes main)))))))
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (= "#00ff00" (fill source page-id mi-id)))
|
||||
(t/is (= "#00ff00" (fill source page-id new-copy)))
|
||||
(t/is (= "#00ff00" (fill source page-id copy-id)))
|
||||
(t/is (empty? (:touched (shape source page-id copy-id))))
|
||||
(t/is (empty? (validation-codes source)))))))
|
||||
|
||||
(t/deftest update-syncs-a-copy-the-branch-added-to-main-component
|
||||
(t/deftest update-syncs-a-copy-the-branch-added-to-the-source-component
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup 1)
|
||||
(let [{:keys [profile source-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup 1)
|
||||
new-copy (uuid/random)]
|
||||
(save profile main-id (edit-component page-id mi-id copy-id "#0000ff"))
|
||||
(save profile source-id (edit-component page-id mi-id copy-id "#0000ff"))
|
||||
(save profile branch-file-id [(copy-of page-id new-copy comp-id mi-id branch-file-id)])
|
||||
|
||||
(let [out (update-branch ctx)]
|
||||
@ -247,15 +247,15 @@
|
||||
;; --- b: both sides edit the component, each syncs its copy
|
||||
|
||||
(defn- both-edit-component
|
||||
[{:keys [profile main-id branch-file-id page-id mi-id copy-id]}]
|
||||
[{:keys [profile source-id branch-file-id page-id mi-id copy-id]}]
|
||||
(save profile branch-file-id (edit-component page-id mi-id copy-id "#00ff00"))
|
||||
(save profile main-id (edit-component page-id mi-id copy-id "#0000ff")))
|
||||
(save profile source-id (edit-component page-id mi-id copy-id "#0000ff")))
|
||||
|
||||
(t/deftest merge-of-a-component-both-sides-edited-conflicts-on-the-component-only
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[side color] [[:branch "#00ff00"] [:source "#0000ff"]]]
|
||||
(t/testing (str "resolved to " side)
|
||||
(let [{:keys [profile main-id page-id mi-id copy-id] :as ctx} (setup (if (= :branch side) 1 2))]
|
||||
(let [{:keys [profile source-id page-id mi-id copy-id] :as ctx} (setup (if (= :branch side) 1 2))]
|
||||
(both-edit-component ctx)
|
||||
|
||||
(let [out (merge-branch ctx)]
|
||||
@ -269,11 +269,11 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (= color (fill main page-id mi-id)))
|
||||
(t/is (= color (fill main page-id copy-id)))
|
||||
(t/is (empty? (:touched (shape main page-id copy-id))))
|
||||
(t/is (empty? (validation-codes main)))))))))
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (= color (fill source page-id mi-id)))
|
||||
(t/is (= color (fill source page-id copy-id)))
|
||||
(t/is (empty? (:touched (shape source page-id copy-id))))
|
||||
(t/is (empty? (validation-codes source)))))))))
|
||||
|
||||
(t/deftest update-of-a-component-both-sides-edited-conflicts-on-the-component-only
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -322,24 +322,24 @@
|
||||
|
||||
(t/deftest merge-keeps-the-branch-override-of-a-copy
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id mi-id copy-id] :as ctx} (setup 1)]
|
||||
(let [{:keys [profile source-id branch-file-id page-id mi-id copy-id] :as ctx} (setup 1)]
|
||||
(save profile branch-file-id [(set-fill page-id copy-id "#ff0000")])
|
||||
(save profile main-id (edit-component page-id mi-id copy-id "#0000ff"))
|
||||
(save profile source-id (edit-component page-id mi-id copy-id "#0000ff"))
|
||||
|
||||
(let [out (merge-branch ctx)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (= "#0000ff" (fill main page-id mi-id)))
|
||||
(t/is (= "#ff0000" (fill main page-id copy-id)))
|
||||
(t/is (contains? (:touched (shape main page-id copy-id)) :fill-group))
|
||||
(t/is (empty? (validation-codes main)))))))
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (= "#0000ff" (fill source page-id mi-id)))
|
||||
(t/is (= "#ff0000" (fill source page-id copy-id)))
|
||||
(t/is (contains? (:touched (shape source page-id copy-id)) :fill-group))
|
||||
(t/is (empty? (validation-codes source)))))))
|
||||
|
||||
(t/deftest update-keeps-main-override-of-a-copy
|
||||
(t/deftest update-keeps-the-source-override-of-a-copy
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id mi-id copy-id] :as ctx} (setup 1)]
|
||||
(save profile main-id [(set-fill page-id copy-id "#ff0000")])
|
||||
(let [{:keys [profile source-id branch-file-id page-id mi-id copy-id] :as ctx} (setup 1)]
|
||||
(save profile source-id [(set-fill page-id copy-id "#ff0000")])
|
||||
(save profile branch-file-id (edit-component page-id mi-id copy-id "#00ff00"))
|
||||
|
||||
(let [out (update-branch ctx)]
|
||||
@ -356,9 +356,9 @@
|
||||
|
||||
(t/deftest merge-of-a-copy-both-sides-overrode-is-a-conflict
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id copy-id] :as ctx} (setup 1)]
|
||||
(let [{:keys [profile source-id branch-file-id page-id copy-id] :as ctx} (setup 1)]
|
||||
(save profile branch-file-id [(set-fill page-id copy-id "#ff0000")])
|
||||
(save profile main-id [(set-fill page-id copy-id "#ffff00")])
|
||||
(save profile source-id [(set-fill page-id copy-id "#ffff00")])
|
||||
|
||||
(let [out (merge-branch ctx)]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
@ -366,9 +366,9 @@
|
||||
|
||||
(t/deftest update-of-a-copy-both-sides-overrode-is-a-conflict
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id copy-id] :as ctx} (setup 1)]
|
||||
(let [{:keys [profile source-id branch-file-id page-id copy-id] :as ctx} (setup 1)]
|
||||
(save profile branch-file-id [(set-fill page-id copy-id "#ff0000")])
|
||||
(save profile main-id [(set-fill page-id copy-id "#ffff00")])
|
||||
(save profile source-id [(set-fill page-id copy-id "#ffff00")])
|
||||
|
||||
(let [out (update-branch ctx)]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
@ -400,7 +400,7 @@
|
||||
|
||||
(t/deftest merge-keeps-a-reset-of-an-override-the-base-holds
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id comp-id mi-id copy-id] :as ctx}
|
||||
(let [{:keys [profile source-id branch-file-id page-id comp-id mi-id copy-id] :as ctx}
|
||||
(setup 1 :override "#ff0000")]
|
||||
(reset-copy profile branch-file-id page-id copy-id)
|
||||
(t/testing "the reset clears the override on the branch"
|
||||
@ -412,21 +412,21 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (not (contains? (:touched (shape main page-id copy-id)) :fill-group)))
|
||||
(t/is (= (fill main page-id mi-id) (fill main page-id copy-id)))
|
||||
(t/is (empty? (validation-codes main))))
|
||||
(t/is (follows-component? profile main-id page-id comp-id mi-id copy-id)))))
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (not (contains? (:touched (shape source page-id copy-id)) :fill-group)))
|
||||
(t/is (= (fill source page-id mi-id) (fill source page-id copy-id)))
|
||||
(t/is (empty? (validation-codes source))))
|
||||
(t/is (follows-component? profile source-id page-id comp-id mi-id copy-id)))))
|
||||
|
||||
(t/deftest update-keeps-a-reset-of-an-override-the-base-holds
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-file-id page-id comp-id mi-id copy-id] :as ctx}
|
||||
(let [{:keys [profile source-id branch-file-id page-id comp-id mi-id copy-id] :as ctx}
|
||||
(setup 1 :override "#ff0000")]
|
||||
(reset-copy profile main-id page-id copy-id)
|
||||
(t/testing "the reset clears the override on main"
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (not (contains? (:touched (shape main page-id copy-id)) :fill-group)))
|
||||
(t/is (= (fill main page-id mi-id) (fill main page-id copy-id)))))
|
||||
(reset-copy profile source-id page-id copy-id)
|
||||
(t/testing "the reset clears the override on the source"
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (not (contains? (:touched (shape source page-id copy-id)) :fill-group)))
|
||||
(t/is (= (fill source page-id mi-id) (fill source page-id copy-id)))))
|
||||
|
||||
(let [out (update-branch ctx)]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -445,11 +445,11 @@
|
||||
(get-in (shape file page-id id) [:applied-tokens :fill]))
|
||||
|
||||
(defn- integrate
|
||||
"Merge the branch (`:merge`) or update it from main (`:update`), and
|
||||
"Merge the branch (`:merge`) or update it from the source (`:update`), and
|
||||
return the result and the file the integration wrote to."
|
||||
[dir {:keys [profile main-id branch-file-id] :as ctx} & {:as params}]
|
||||
[dir {:keys [profile source-id branch-file-id] :as ctx} & {:as params}]
|
||||
(case dir
|
||||
:merge [(merge-branch ctx params) (get-file profile main-id)]
|
||||
:merge [(merge-branch ctx params) (get-file profile source-id)]
|
||||
:update [(update-branch ctx params) (get-file profile branch-file-id)]))
|
||||
|
||||
(def ^:private ok-status
|
||||
@ -460,9 +460,9 @@
|
||||
(doseq [[n dir side token] [[1 :merge :branch "green"] [2 :merge :source "blue"]
|
||||
[3 :update :branch "green"] [4 :update :source "blue"]]]
|
||||
(t/testing (str dir " resolved to " side)
|
||||
(let [{:keys [profile main-id branch-file-id page-id mi-id copy-id] :as ctx} (setup n)]
|
||||
(let [{:keys [profile source-id branch-file-id page-id mi-id copy-id] :as ctx} (setup n)]
|
||||
(save profile branch-file-id (tokenize-component page-id mi-id copy-id "green"))
|
||||
(save profile main-id (tokenize-component page-id mi-id copy-id "blue"))
|
||||
(save profile source-id (tokenize-component page-id mi-id copy-id "blue"))
|
||||
|
||||
(let [[out] (integrate dir ctx)]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
@ -481,11 +481,11 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[n dir] [[1 :merge] [2 :update]]]
|
||||
(t/testing (str dir)
|
||||
(let [{:keys [profile main-id branch-file-id page-id mi-id copy-id] :as ctx} (setup n)
|
||||
(let [{:keys [profile source-id branch-file-id page-id mi-id copy-id] :as ctx} (setup n)
|
||||
;; the source overrides the copy, the target edits the component
|
||||
[source target] (if (= :merge dir)
|
||||
[branch-file-id main-id]
|
||||
[main-id branch-file-id])]
|
||||
[branch-file-id source-id]
|
||||
[source-id branch-file-id])]
|
||||
(save profile source [(apply-fill-token page-id copy-id "red")])
|
||||
(save profile target (tokenize-component page-id mi-id copy-id "blue"))
|
||||
|
||||
@ -502,9 +502,9 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[n dir] [[1 :merge] [2 :update]]]
|
||||
(t/testing (str dir)
|
||||
(let [{:keys [profile main-id branch-file-id page-id copy-id] :as ctx} (setup n)]
|
||||
(let [{:keys [profile source-id branch-file-id page-id copy-id] :as ctx} (setup n)]
|
||||
(save profile branch-file-id [(apply-fill-token page-id copy-id "red")])
|
||||
(save profile main-id [(apply-fill-token page-id copy-id "yellow")])
|
||||
(save profile source-id [(apply-fill-token page-id copy-id "yellow")])
|
||||
|
||||
(let [[out] (integrate dir ctx)]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
@ -514,12 +514,12 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[n dir] [[1 :merge] [2 :update]]]
|
||||
(t/testing (str dir)
|
||||
(let [{:keys [profile main-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup n)
|
||||
(let [{:keys [profile source-id branch-file-id page-id comp-id mi-id copy-id] :as ctx} (setup n)
|
||||
new-copy (uuid/random)
|
||||
;; the source tokenizes the component, the target adds a copy
|
||||
[source target] (if (= :merge dir)
|
||||
[branch-file-id main-id]
|
||||
[main-id branch-file-id])]
|
||||
[branch-file-id source-id]
|
||||
[source-id branch-file-id])]
|
||||
(save profile source (tokenize-component page-id mi-id copy-id "green"))
|
||||
(save profile target [(copy-of page-id new-copy comp-id mi-id target)])
|
||||
|
||||
|
||||
@ -232,7 +232,7 @@
|
||||
(t/testing "the branch file is gone"
|
||||
(t/is (nil? (row :file branch-file-id))))
|
||||
|
||||
(t/testing "main does not list the threads the merge left behind"
|
||||
(t/testing "the source does not list the threads the merge left behind"
|
||||
(t/is (empty? (threads-of author (:id file)))))
|
||||
|
||||
(t/testing "the threads read through their review, with no file"
|
||||
@ -255,7 +255,7 @@
|
||||
(t/is (= ["wont-do"] (mapv :status (:tasks closed))))
|
||||
(t/is (nil? (:file-id (row :file-task (:id task)))))))
|
||||
|
||||
(t/testing "a thread left behind moves to main with its task, the branch file gone"
|
||||
(t/testing "a thread left behind moves to the source with its task, the branch file gone"
|
||||
(let [out (th/command! {::th/type :move-branch-review-thread
|
||||
::rpc/profile-id (:id author)
|
||||
:thread-id (:thread-id task)})
|
||||
@ -274,7 +274,7 @@
|
||||
(t/is (= "merged" (:type event)))
|
||||
(t/is (= "review-pay-button" (-> event :payload :branch-name)))))
|
||||
|
||||
(t/testing "the review reads on main with its verdict"
|
||||
(t/testing "the review reads on the source with its verdict"
|
||||
(let [result (review-of author (:id review))]
|
||||
(t/is (some? result))
|
||||
(t/is (= "Checkout redesign" (:title result)))
|
||||
@ -318,7 +318,7 @@
|
||||
;; A review thread with no open task stays on the branch at the merge.
|
||||
;; Its layer sits in a group the merge left out. Once the GC took the
|
||||
;; branch file, moving the thread lands it on the board that held the
|
||||
;; group, the nearest ancestor main has, from what the merge stored on
|
||||
;; group, the nearest ancestor the source has, from what the merge stored on
|
||||
;; the thread, and the thread keeps the name of its lost layer.
|
||||
(with-redefs [cf/flags (flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
|
||||
(ns backend-tests.branch-file-identity-test
|
||||
"A branch file is its own file: the document a branch derives from
|
||||
main's base snapshot names the branch, in `:data :id` and in every
|
||||
its source's base snapshot names the branch, in `:data :id` and in every
|
||||
reference to itself (component instances, library colours, the tokens
|
||||
source). The tests build main with a local component and a token set,
|
||||
source). The tests build a source file with a local component and a token set,
|
||||
branch it, and check each branch verb against that identity."
|
||||
(:require
|
||||
[app.binfile.common :as bfc]
|
||||
@ -93,7 +93,7 @@
|
||||
:ref-id color-id :ref-file file-id}}]))))
|
||||
|
||||
(defn- setup
|
||||
"Main holding a local component (main `:mi-id`, copy `:copy-id`), a
|
||||
"A source file holding a local component (main `:mi-id`, copy `:copy-id`), a
|
||||
library colour painted on `:swatch-id`, and a token set, branched
|
||||
once."
|
||||
[]
|
||||
@ -101,8 +101,8 @@
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (get-file profile main-id) :data :pages first)
|
||||
source-id (:id file)
|
||||
page-id (-> (get-file profile source-id) :data :pages first)
|
||||
comp-id (uuid/random)
|
||||
mi-id (uuid/random)
|
||||
copy-id (uuid/random)
|
||||
@ -110,26 +110,26 @@
|
||||
swatch-id (uuid/random)
|
||||
set-id (uuid/random)
|
||||
tok-id (uuid/random)]
|
||||
(save profile main-id
|
||||
(save profile source-id
|
||||
[(add-root page-id mi-id (component-frame mi-id {:component-root true
|
||||
:main-instance true
|
||||
:component-id comp-id
|
||||
:component-file main-id}))
|
||||
:component-file source-id}))
|
||||
{:type :add-component :id comp-id :name "Button" :path ""
|
||||
:main-instance-id mi-id :main-instance-page page-id}
|
||||
(copy-of page-id copy-id comp-id mi-id main-id)
|
||||
(copy-of page-id copy-id comp-id mi-id source-id)
|
||||
{:type :add-color
|
||||
:color {:id color-id :name "red" :color "#ff0000" :opacity 1}}
|
||||
(painted page-id swatch-id color-id main-id)
|
||||
(painted page-id swatch-id color-id source-id)
|
||||
{:type :set-token-set :id set-id :attrs {:id set-id :name "core"}}
|
||||
{:type :set-token :set-id set-id :token-id tok-id
|
||||
:attrs {:id tok-id :name "brand" :type :color :value "#ff0000"}}])
|
||||
(let [branch (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id main-id
|
||||
:file-id source-id
|
||||
:name "identity"}))]
|
||||
{:profile profile
|
||||
:main-id main-id
|
||||
:source-id source-id
|
||||
:page-id page-id
|
||||
:comp-id comp-id
|
||||
:mi-id mi-id
|
||||
@ -178,15 +178,15 @@
|
||||
(t/testing "the branch validates clean"
|
||||
(t/is (empty? (validation-codes branch)))))))
|
||||
|
||||
(t/deftest update-from-main-keeps-a-branch-copy-of-a-base-component
|
||||
(t/deftest update-from-source-keeps-a-branch-copy-of-a-base-component
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id page-id comp-id mi-id copy-id branch-id branch-file-id]} (setup)
|
||||
(let [{:keys [profile source-id page-id comp-id mi-id copy-id branch-id branch-file-id]} (setup)
|
||||
own-copy (uuid/random)]
|
||||
;; the workspace instantiates a local component with the current
|
||||
;; file, the branch, as its library
|
||||
(save profile branch-file-id [(copy-of page-id own-copy comp-id mi-id branch-file-id)])
|
||||
(save profile main-id [(set-fill page-id mi-id "#0000ff")
|
||||
(set-fill page-id copy-id "#0000ff")])
|
||||
(save profile source-id [(set-fill page-id mi-id "#0000ff")
|
||||
(set-fill page-id copy-id "#0000ff")])
|
||||
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -199,9 +199,9 @@
|
||||
(t/is (= branch-file-id (:component-file (shape branch page-id own-copy))))
|
||||
(t/is (empty? (validation-codes branch)))))))
|
||||
|
||||
(t/deftest merge-names-main-in-what-it-applies
|
||||
(t/deftest merge-names-the-source-in-what-it-applies
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id page-id comp-id mi-id color-id branch-id branch-file-id]} (setup)
|
||||
(let [{:keys [profile source-id page-id comp-id mi-id color-id branch-id branch-file-id]} (setup)
|
||||
own-copy (uuid/random)
|
||||
own-swatch (uuid/random)]
|
||||
;; the workspace paints with a local colour naming the current
|
||||
@ -216,13 +216,13 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(let [main (get-file profile main-id)]
|
||||
(t/is (= main-id (-> main :data :id)))
|
||||
(t/is (= main-id (:component-file (shape main page-id own-copy))))
|
||||
(t/is (= main-id (:component-file (shape main page-id mi-id))))
|
||||
(t/is (= "#00ff00" (-> (shape main page-id mi-id) :fills first :fill-color)))
|
||||
(t/is (= [main-id main-id] (colour-refs main page-id own-swatch)))
|
||||
(t/is (empty? (validation-codes main)))))))
|
||||
(let [source (get-file profile source-id)]
|
||||
(t/is (= source-id (-> source :data :id)))
|
||||
(t/is (= source-id (:component-file (shape source page-id own-copy))))
|
||||
(t/is (= source-id (:component-file (shape source page-id mi-id))))
|
||||
(t/is (= "#00ff00" (-> (shape source page-id mi-id) :fills first :fill-color)))
|
||||
(t/is (= [source-id source-id] (colour-refs source page-id own-swatch)))
|
||||
(t/is (empty? (validation-codes source)))))))
|
||||
|
||||
(t/deftest materialize-keeps-the-base-components
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -243,25 +243,25 @@
|
||||
|
||||
(t/deftest materialize-owns-the-images-it-inherited
|
||||
;; a materialized file outlives its source's media rows only if it owns
|
||||
;; copies: main's file-gc and main's deletion take main's rows along
|
||||
;; copies: the source's file-gc and the source's deletion take the source's rows along
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (get-file profile main-id) :data :pages first)
|
||||
source-id (:id file)
|
||||
page-id (-> (get-file profile source-id) :data :pages first)
|
||||
storage (-> (:app.storage/storage th/*system*)
|
||||
(assoc :app.storage/backend :fs))
|
||||
sobj (sto/put-object! storage {::sto/content (sto/content "photo")
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"})
|
||||
fmo (th/create-file-media-object* {:file-id main-id
|
||||
fmo (th/create-file-media-object* {:file-id source-id
|
||||
:name "photo.png"
|
||||
:mtype "image/png"
|
||||
:media-id (:id sobj)})
|
||||
photo (uuid/random)
|
||||
_ (save profile main-id
|
||||
_ (save profile source-id
|
||||
[(add-root page-id photo
|
||||
(-> (cts/setup-shape {:id photo :name "Photo" :type :rect
|
||||
:x 0 :y 0 :width 100 :height 100
|
||||
@ -271,7 +271,7 @@
|
||||
:mtype "image/png"}}])))])
|
||||
create (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id main-id
|
||||
:file-id source-id
|
||||
:name "photos"}))
|
||||
branch-file-id (:branch-file-id create)
|
||||
out (th/command! {::th/type :detach-file-branch
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
(ns backend-tests.branch-file-queries-test
|
||||
"Regression tests for the queries that count or list a team's files: a
|
||||
branch file is a hidden copy of its main file, so none of them may
|
||||
branch file is a hidden copy of its source file, so none of them may
|
||||
count it, list it, or copy it as an ordinary file."
|
||||
(:require
|
||||
[app.binfile.common :as bfc]
|
||||
@ -28,22 +28,22 @@
|
||||
library (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared true})
|
||||
main (th/create-file* 2 {:profile-id (:id profile)
|
||||
source (th/create-file* 2 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
_ (th/link-file-to-library* {:file-id (:id main) :library-id (:id library)})
|
||||
_ (th/link-file-to-library* {:file-id (:id source) :library-id (:id library)})
|
||||
out (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id main)
|
||||
:file-id (:id source)
|
||||
:name "hidden"})
|
||||
branch-id (-> out :result :branch-file-id)]
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
;; the branch copied main's link to the library
|
||||
;; the branch copied the source's link to the library
|
||||
(t/is (seq (th/db-query :file-library-rel {:file-id branch-id
|
||||
:library-file-id (:id library)})))
|
||||
|
||||
(t/testing "the project counts the library and main only"
|
||||
(t/testing "the project counts the library and the source only"
|
||||
(let [out (th/command! {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile)
|
||||
:team-id team-id})
|
||||
@ -52,20 +52,20 @@
|
||||
(t/is (= 2 (:count proj)))
|
||||
(t/is (= 2 (:total-count proj)))))
|
||||
|
||||
(t/testing "the team stats count the library and main only"
|
||||
(t/testing "the team stats count the library and the source only"
|
||||
(let [out (th/command! {::th/type :get-team-stats
|
||||
::rpc/profile-id (:id profile)
|
||||
:team-id team-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= 2 (-> out :result :files)))))
|
||||
|
||||
(t/testing "the unpublish dialog lists main only"
|
||||
(t/testing "the unpublish dialog lists the source only"
|
||||
(let [out (th/command! {::th/type :get-library-file-references
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id library)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= [(:id main)] (mapv :id (:result out))))))
|
||||
(t/is (= [(:id source)] (mapv :id (:result out))))))
|
||||
|
||||
(t/testing "a team duplication copies the library and main only"
|
||||
(t/is (= #{(:id library) (:id main)}
|
||||
(t/testing "a team duplication copies the library and the source only"
|
||||
(t/is (= #{(:id library) (:id source)}
|
||||
(db/run! th/*system* bfc/get-team-files-ids team-id)))))))
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
"Engine-level tests for the three-way comparison, with data built by hand
|
||||
rather than through a file fixture.
|
||||
|
||||
The case that matters here came from a real update-from-main: the branch
|
||||
The case that matters here came from a real update-from-source: the branch
|
||||
copy and its base disagreed only on whether a reference attribute was
|
||||
present with a `nil` value or was absent, and because main had moved the
|
||||
present with a `nil` value or was absent, and because the source had moved the
|
||||
same shapes, the engine called 368 of them `:modify-modify` conflicts."
|
||||
(:require
|
||||
[app.common.files.branch-merge :as bm]
|
||||
@ -40,13 +40,13 @@
|
||||
(def ^:private nil-ref {:typography-ref-file nil})
|
||||
|
||||
(deftest nil-ref-and-absent-ref-are-the-same-shape
|
||||
(testing "the branch's copy has the ref with nil, its base without, and main moved the shape"
|
||||
(testing "the branch's copy has the ref with nil, its base without, and the source moved the shape"
|
||||
(let [res (bm/compute-merge (file-data 0 {})
|
||||
(file-data 5 {})
|
||||
(file-data 0 nil-ref)
|
||||
:source->branch)]
|
||||
(is (zero? (count (:conflicts res))) "a nil-versus-absent reference is not a branch edit")
|
||||
(is (= 1 (count (:changes res))) "main's move still travels as a change")
|
||||
(is (= 1 (count (:changes res))) "the source's move still travels as a change")
|
||||
(is (= :modified (:status (first (:changes res)))))))
|
||||
|
||||
(testing "and the same with the sides the other way round"
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(into #{} (map :id) (:result out))))
|
||||
|
||||
(defn- update-from-main!
|
||||
(defn- update-from-source!
|
||||
[profile branch-file-id]
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -110,22 +110,22 @@
|
||||
(get-in data [:pages-index page-id :objects shape-id :fills 0 :fill-color-ref-file]))
|
||||
|
||||
(defn- setup-library-use!
|
||||
"A shared library publishing one colour, and a main file linked to it
|
||||
"A shared library publishing one colour, and a source file linked to it
|
||||
whose one shape fills with that colour."
|
||||
[profile]
|
||||
(let [library (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared true})
|
||||
main (create-file profile 2)
|
||||
source (create-file profile 2)
|
||||
color-id (uuid/random)
|
||||
shape-id (uuid/random)
|
||||
page-id (-> (file-data profile (:id main)) :pages first)]
|
||||
page-id (-> (file-data profile (:id source)) :pages first)]
|
||||
|
||||
(apply-change! profile (:id library)
|
||||
{:type :add-color
|
||||
:color {:id color-id :name "Brand" :color "#ff0000" :opacity 1}})
|
||||
(th/link-file-to-library* {:file-id (:id main) :library-id (:id library)})
|
||||
(apply-change! profile (:id main)
|
||||
(th/link-file-to-library* {:file-id (:id source) :library-id (:id library)})
|
||||
(apply-change! profile (:id source)
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -140,8 +140,8 @@
|
||||
:fill-color-ref-file (:id library)}]))})
|
||||
|
||||
{:library-id (:id library)
|
||||
:main-id (:id main)
|
||||
:main main
|
||||
:source-id (:id source)
|
||||
:source source
|
||||
:color-id color-id
|
||||
:page-id page-id
|
||||
:shape-id shape-id}))
|
||||
@ -212,12 +212,12 @@
|
||||
;; Unpublishing a library absorbs its assets into the files that use it
|
||||
;; through `bfc/update-file!`, a write a branch must never take. The
|
||||
;; branch keeps its link instead, so the unpublished library still
|
||||
;; resolves there, and its next update from main brings main's
|
||||
;; resolves there, and its next update from the source brings the source's
|
||||
;; absorbed copy.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
{:keys [library-id main-id main color-id] :as ids} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile main "absorb")
|
||||
{:keys [library-id source-id source color-id] :as ids} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile source "absorb")
|
||||
revn (:revn (th/db-get :file {:id branch-id}))
|
||||
out (th/command! {::th/type :set-file-shared
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -226,11 +226,11 @@
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
|
||||
(t/testing "main absorbs the colour and drops its link"
|
||||
(let [data (file-data profile main-id)]
|
||||
(t/testing "the source absorbs the colour and drops its link"
|
||||
(let [data (file-data profile source-id)]
|
||||
(t/is (some? (get-in data [:colors color-id])))
|
||||
(t/is (= main-id (fill-ref-file data ids))))
|
||||
(t/is (not (contains? (linked-library-ids profile main-id) library-id))))
|
||||
(t/is (= source-id (fill-ref-file data ids))))
|
||||
(t/is (not (contains? (linked-library-ids profile source-id) library-id))))
|
||||
|
||||
(t/testing "the branch writes nothing and still resolves the library"
|
||||
(t/is (empty? (payload-rows branch-id)))
|
||||
@ -240,8 +240,8 @@
|
||||
(t/is (contains? (linked-library-ids profile branch-id) library-id))
|
||||
(t/is (some? (get-in (file-data profile library-id) [:colors color-id]))))
|
||||
|
||||
(t/testing "the next update from main brings main's absorbed copy"
|
||||
(update-from-main! profile branch-id)
|
||||
(t/testing "the next update from the source brings the source's absorbed copy"
|
||||
(update-from-source! profile branch-id)
|
||||
(let [data (file-data profile branch-id)]
|
||||
(t/is (some? (get-in data [:colors color-id])))
|
||||
(t/is (not= library-id (fill-ref-file data ids))))
|
||||
@ -253,8 +253,8 @@
|
||||
;; The unpublish must not reach it.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
{:keys [library-id main-id main color-id]} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile main "deleted")]
|
||||
{:keys [library-id source-id source color-id]} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile source "deleted")]
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -272,18 +272,18 @@
|
||||
:is-shared false})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
(t/is (some? (get-in (file-data profile main-id) [:colors color-id])))
|
||||
(t/is (some? (get-in (file-data profile source-id) [:colors color-id])))
|
||||
(t/is (empty? (payload-rows branch-id))))))
|
||||
|
||||
(t/deftest delete-library-skips-branch
|
||||
;; The deletion task absorbs a shared library into the files still
|
||||
;; linked to it; a project deletion keeps those links. A branch
|
||||
;; resolves nothing through the soft-deleted library until its next
|
||||
;; update from main brings main's absorbed copy.
|
||||
;; update from the source brings the source's absorbed copy.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
{:keys [library-id main-id main color-id] :as ids} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile main "absorb")
|
||||
{:keys [library-id source-id source color-id] :as ids} (setup-library-use! profile)
|
||||
branch-id (create-branch! profile source "absorb")
|
||||
revn (:revn (th/db-get :file {:id branch-id}))]
|
||||
|
||||
(th/run-task! :delete-object {:object :file
|
||||
@ -291,10 +291,10 @@
|
||||
:id library-id})
|
||||
|
||||
;; the task logs an absorption error instead of raising it, so
|
||||
;; main's absorbed copy is what proves the absorption ran
|
||||
(let [data (file-data profile main-id)]
|
||||
;; the source's absorbed copy is what proves the absorption ran
|
||||
(let [data (file-data profile source-id)]
|
||||
(t/is (some? (get-in data [:colors color-id])))
|
||||
(t/is (= main-id (fill-ref-file data ids))))
|
||||
(t/is (= source-id (fill-ref-file data ids))))
|
||||
|
||||
(t/testing "the branch writes nothing and resolves nothing until the update"
|
||||
(t/is (empty? (payload-rows branch-id)))
|
||||
@ -303,8 +303,8 @@
|
||||
(t/is (= library-id (fill-ref-file (file-data profile branch-id) ids)))
|
||||
(t/is (not (contains? (linked-library-ids profile branch-id) library-id))))
|
||||
|
||||
(t/testing "the next update from main brings main's absorbed copy"
|
||||
(update-from-main! profile branch-id)
|
||||
(t/testing "the next update from the source brings the source's absorbed copy"
|
||||
(update-from-source! profile branch-id)
|
||||
(let [data (file-data profile branch-id)]
|
||||
(t/is (some? (get-in data [:colors color-id])))
|
||||
(t/is (not= library-id (fill-ref-file data ids))))
|
||||
|
||||
@ -131,33 +131,33 @@
|
||||
(t/deftest base-readers-realize-with-the-source-file-id
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile-id file-id]} (setup)
|
||||
branch (create-branch! profile-id file-id "readers")
|
||||
branch (create-branch! profile-id file-id "readers")
|
||||
;; whatever creation stores, pin a base that holds the source
|
||||
;; file's pointers: the readers are what this test is about
|
||||
source (bfc/get-file th/*system* file-id)
|
||||
_ (t/is (seq (page-pointer-ids (:data source))))
|
||||
snap (fsnap/create! th/*system* source
|
||||
{:label "branch-base/readers"
|
||||
:profile-id profile-id
|
||||
:created-by "system"})
|
||||
_ (th/db-update! :file-branch
|
||||
{:base-snapshot-id (:id snap)}
|
||||
{:id (:id branch)})
|
||||
main (realized-data file-id)]
|
||||
source (bfc/get-file th/*system* file-id)
|
||||
_ (t/is (seq (page-pointer-ids (:data source))))
|
||||
snap (fsnap/create! th/*system* source
|
||||
{:label "branch-base/readers"
|
||||
:profile-id profile-id
|
||||
:created-by "system"})
|
||||
_ (th/db-update! :file-branch
|
||||
{:base-snapshot-id (:id snap)}
|
||||
{:id (:id branch)})
|
||||
source-data (realized-data file-id)]
|
||||
|
||||
(t/testing "the derive reads the base"
|
||||
(let [file (bfc/get-file th/*system* (:branch-file-id branch)
|
||||
:realize? true :include-base-data? true)]
|
||||
(t/is (not (holds-pointers? (:data file))))
|
||||
(t/is (= (:pages-index main) (:pages-index (:data file))))
|
||||
(t/is (= (:pages-index source-data) (:pages-index (:data file))))
|
||||
(t/is (not (holds-pointers? (::bfc/base-data file))))
|
||||
(t/is (= (:pages-index main) (:pages-index (::bfc/base-data file))))))
|
||||
(t/is (= (:pages-index source-data) (:pages-index (::bfc/base-data file))))))
|
||||
|
||||
(t/testing "the snapshot reader reads the base"
|
||||
(let [row (th/db-get :file-branch {:id (:id branch)})
|
||||
data (db/run! th/*system* #(#'fbranch/get-base-data % row))]
|
||||
(t/is (not (holds-pointers? data)))
|
||||
(t/is (= (:pages-index main) (:pages-index data))))))))
|
||||
(t/is (= (:pages-index source-data) (:pages-index data))))))))
|
||||
|
||||
(t/deftest file-gc-keeps-the-fragments-a-base-names
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -167,13 +167,13 @@
|
||||
pinned (set (vals (page-pointer-ids (:data (base-snapshot (:id branch))))))]
|
||||
(t/is (seq pinned))
|
||||
|
||||
;; the edit replaces the page's fragment on main, so only the
|
||||
;; the edit replaces the page's fragment on the source, so only the
|
||||
;; base still names the old one
|
||||
(update-file! profile-id file-id [(add-rect page-id)])
|
||||
(let [main-ids (set (vals (page-pointer-ids
|
||||
(:data (bfc/get-file th/*system* file-id)))))]
|
||||
(t/is (seq (remove main-ids pinned))))
|
||||
;; the save took an automatic snapshot of pre-edit main, which names
|
||||
(let [source-ids (set (vals (page-pointer-ids
|
||||
(:data (bfc/get-file th/*system* file-id)))))]
|
||||
(t/is (seq (remove source-ids pinned))))
|
||||
;; the save took an automatic snapshot of the pre-edit source, which names
|
||||
;; the same fragments; drop every snapshot but the base so the base
|
||||
;; is what keeps them alive
|
||||
(let [base-id (:base-snapshot-id (th/db-get :file-branch {:id (:id branch)}))]
|
||||
@ -191,7 +191,7 @@
|
||||
:direction :source->branch}))]
|
||||
(t/is (= 1 (-> diff :stats :added)))))))
|
||||
|
||||
(t/deftest update-from-main-pins-main-pointers
|
||||
(t/deftest update-from-source-pins-source-pointers
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile-id file-id]} (setup)
|
||||
branch (create-branch! profile-id file-id "update")
|
||||
@ -203,12 +203,12 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
|
||||
;; the repositioned base names main's current fragments for every
|
||||
;; page the update left equal to main
|
||||
(let [main-ids (page-pointer-ids (:data (bfc/get-file th/*system* file-id)))
|
||||
base-ids (page-pointer-ids (:data (base-snapshot (:id branch))))]
|
||||
;; the repositioned base names the source's current fragments for every
|
||||
;; page the update left equal to the source
|
||||
(let [source-ids (page-pointer-ids (:data (bfc/get-file th/*system* file-id)))
|
||||
base-ids (page-pointer-ids (:data (base-snapshot (:id branch))))]
|
||||
(t/is (seq base-ids))
|
||||
(t/is (= main-ids base-ids)))
|
||||
(t/is (= source-ids base-ids)))
|
||||
|
||||
(t/is (= (:pages-index (realized-data file-id))
|
||||
(:pages-index (realized-data (:branch-file-id branch))))))))
|
||||
@ -246,14 +246,14 @@
|
||||
[file-id branch-file-id dir]
|
||||
(db/run! th/*system*
|
||||
(fn [cfg]
|
||||
(let [main (:data (bfc/get-file cfg file-id :realize? true))
|
||||
(let [source (:data (bfc/get-file cfg file-id :realize? true))
|
||||
bfile (bfc/get-file cfg branch-file-id :realize? true :include-base-data? true)
|
||||
base (#'fbranch/branch-base-data cfg file-id bfile)
|
||||
branch (bm/remap-refs (:data bfile)
|
||||
(#'fbranch/branch-id-map cfg branch-file-id file-id))]
|
||||
(bm/compute-merge base main branch dir)))))
|
||||
(bm/compute-merge base source branch dir)))))
|
||||
|
||||
(t/deftest compare-loads-only-the-pages-main-moved
|
||||
(t/deftest compare-loads-only-the-pages-the-source-moved
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile-id file-id]} (setup)
|
||||
page-a (first (:pages (realized-data file-id)))
|
||||
@ -267,11 +267,11 @@
|
||||
branch (create-branch! profile-id file-id "lazy")
|
||||
bfid (:branch-file-id branch)
|
||||
page-b (first others)]
|
||||
;; the branch renames the shape main renames too, a conflict on
|
||||
;; page A, and adds a shape; main also adds a shape on page B, so
|
||||
;; main moved two of six pages
|
||||
;; the branch renames the shape the source renames too, a conflict on
|
||||
;; page A, and adds a shape; the source also adds a shape on page B, so
|
||||
;; the source moved two of six pages
|
||||
(update-file! profile-id bfid [(rename-shape page-a shape "branch") (add-rect page-a)])
|
||||
(update-file! profile-id file-id [(rename-shape page-a shape "main") (add-rect page-b)])
|
||||
(update-file! profile-id file-id [(rename-shape page-a shape "source") (add-rect page-b)])
|
||||
|
||||
(doseq [dir [:branch->source :source->branch]]
|
||||
(let [loads (atom 0)
|
||||
@ -288,10 +288,10 @@
|
||||
(t/is (= (:changes eager) (:changes (:result out))))
|
||||
(t/is (= (:conflicts eager) (:conflicts (:result out))))
|
||||
(t/is (= 1 (count (:conflicts eager)))))
|
||||
(t/testing (str dir " loads the base's six pages and main's two moved ones")
|
||||
(t/testing (str dir " loads the base's six pages and the source's two moved ones")
|
||||
(t/is (= 8 @loads))))))))
|
||||
|
||||
(t/deftest compare-reports-a-page-reorder-on-main
|
||||
(t/deftest compare-reports-a-page-reorder-on-the-source
|
||||
;; the page order lives in the document root, not in a page's fragment,
|
||||
;; so a reorder moves no fragment and must not bound the comparison
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
|
||||
@ -107,7 +107,7 @@
|
||||
[(add-rect page-id shape-a)
|
||||
(add-rect page-id shape-b)])))
|
||||
|
||||
;; main carries the damage before the fork, so the branch inherits
|
||||
;; the source carries the damage before the fork, so the branch inherits
|
||||
;; it through its merge base
|
||||
(t/is (th/success? (update-file profile file-id
|
||||
[(set-attr page-id shape-a :frame-id (uuid/next))]
|
||||
@ -157,7 +157,7 @@
|
||||
[(set-attr page-id shape-b :name "again")])))
|
||||
(t/is (= 1 (count (repair-rows branch-file-id)))))
|
||||
|
||||
;; the merge validates and repairs its own result, so main ends
|
||||
;; the merge validates and repairs its own result, so the source ends
|
||||
;; valid either way; the branch diff is what shows that the
|
||||
;; repair travels with the branch
|
||||
(t/testing "the branch diff carries the repaired shape"
|
||||
@ -166,7 +166,7 @@
|
||||
:branch-id branch-id}))]
|
||||
(t/is (some #(= shape-a (:id %)) (:changes diff)))))
|
||||
|
||||
(t/testing "the merge carries the repair into main"
|
||||
(t/testing "the merge carries the repair into the source"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
|
||||
@ -743,14 +743,14 @@
|
||||
(t/is (nil? (:path body)))))
|
||||
|
||||
(t/deftest conflict-error-answers-409
|
||||
;; A `:type :conflict` refusal (`:file-modified` on merge/update-from-main,
|
||||
;; A `:type :conflict` refusal (`:file-modified` on merge/update-from-source,
|
||||
;; `:file-locked` and restore `:file-modified` on snapshots) answers 409
|
||||
;; carrying its own ex-data; without a `:conflict` method it fell to the
|
||||
;; default handler: 500 with `:type :server-error`, logged as unhandled.
|
||||
(let [cause (ex-info "conflict"
|
||||
{:type :conflict
|
||||
:code :file-modified
|
||||
:hint "main was modified, recompute the diff and retry"})
|
||||
:hint "source was modified, recompute the diff and retry"})
|
||||
response (http-errors/handle cause {})
|
||||
body (::yres/body response)]
|
||||
(t/is (= 409 (::yres/status response)))
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
(t/testing "the op log starts empty"
|
||||
(t/is (empty? (oplog-rows branch-file-id))))
|
||||
|
||||
(t/testing "the derived state equals main"
|
||||
(t/testing "the derived state equals the source"
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-file-id})]
|
||||
@ -117,7 +117,7 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (contains? (-> out :result :data :colors) color-id)))))))
|
||||
|
||||
(t/deftest update-from-main-squashes-the-op-log
|
||||
(t/deftest update-from-source-squashes-the-op-log
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -127,13 +127,13 @@
|
||||
create (create-branch* profile (:id file) "oplog-update")
|
||||
branch-file-id (:branch-file-id create)
|
||||
branch-id (:id create)
|
||||
main-color (uuid/random)
|
||||
source-color (uuid/random)
|
||||
branch-color (uuid/random)]
|
||||
|
||||
;; main gains a color after the fork
|
||||
;; the source gains a color after the fork
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color
|
||||
:color {:id main-color :name "Main" :color "#00ff00" :opacity 1}})
|
||||
:color {:id source-color :name "Source" :color "#00ff00" :opacity 1}})
|
||||
|
||||
;; the branch gains its own color (so the squash is non-empty)
|
||||
(apply-change* profile branch-file-id
|
||||
@ -154,19 +154,19 @@
|
||||
(= branch-color (get-in % [:color :id])))
|
||||
ops))
|
||||
(t/is (not-any? #(and (= :add-color (:type %))
|
||||
(= main-color (get-in % [:color :id])))
|
||||
(= source-color (get-in % [:color :id])))
|
||||
ops))))
|
||||
|
||||
(t/testing "the derived state has both colors, main's through the base"
|
||||
(t/testing "the derived state has both colors, the source's through the base"
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-file-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [colors (-> out :result :data :colors)]
|
||||
(t/is (contains? colors main-color))
|
||||
(t/is (contains? colors source-color))
|
||||
(t/is (contains? colors branch-color)))))
|
||||
|
||||
(t/testing "the merge base moved to main's revn"
|
||||
(t/testing "the merge base moved to the source's revn"
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
mf (th/db-get :file {:id (:id file)})]
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))))))
|
||||
@ -220,38 +220,38 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:error (add-color* profile branch-file-id)))))))
|
||||
|
||||
(t/deftest update-from-main-compares-in-main-id-space
|
||||
(t/deftest update-from-source-compares-in-source-id-space
|
||||
;; A branch stores no data: its document is the base snapshot plus the op
|
||||
;; log, so every reference it inherited names MAIN. A local reference is a
|
||||
;; self reference in both files, because a branch keeps main's colours and
|
||||
;; typographies under the same entity ids, so the comparison must run in
|
||||
;; main's id space and the change that lands in the branch must still name
|
||||
;; the branch.
|
||||
;; log, so every reference it inherited names the SOURCE. A local reference
|
||||
;; is a self reference in both files, because a branch keeps the source's
|
||||
;; colours and typographies under the same entity ids, so the comparison
|
||||
;; must run in the source's id space and the change that lands in the
|
||||
;; branch must still name the branch.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:result :data :pages first)
|
||||
color-id (uuid/random)
|
||||
shape-id (uuid/random)
|
||||
fills (fn [ref-file color]
|
||||
[{:fill-color color
|
||||
:fill-opacity 1
|
||||
:fill-color-ref-id color-id
|
||||
:fill-color-ref-file ref-file}])]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
color-id (uuid/random)
|
||||
shape-id (uuid/random)
|
||||
fills (fn [ref-file color]
|
||||
[{:fill-color color
|
||||
:fill-opacity 1
|
||||
:fill-color-ref-id color-id
|
||||
:fill-color-ref-file ref-file}])]
|
||||
|
||||
;; main publishes a colour of its own and one of its shapes uses it, so
|
||||
;; the shape carries main's file id in a self reference
|
||||
(apply-change* profile main-id
|
||||
;; the source publishes a colour of its own and one of its shapes uses
|
||||
;; it, so the shape carries the source's file id in a self reference
|
||||
(apply-change* profile source-id
|
||||
{:type :add-color
|
||||
:color {:id color-id :name "Brand" :color "#ff0000" :opacity 1}})
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -260,18 +260,18 @@
|
||||
:obj (-> (cts/setup-shape
|
||||
{:id shape-id :name "Referenced" :type :rect
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills main-id "#ff0000")))})
|
||||
(assoc :fills (fills source-id "#ff0000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id "main-id-space")
|
||||
(let [create (create-branch* profile source-id "source-id-space")
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
(t/testing "main's repaint is not a conflict, and is not logged as a branch change"
|
||||
(apply-change* profile main-id
|
||||
(t/testing "the source's repaint is not a conflict, and is not logged as a branch change"
|
||||
(apply-change* profile source-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-id "#00ff00")}]})
|
||||
:operations [{:type :set :attr :fills :val (fills source-id "#00ff00")}]})
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -282,17 +282,17 @@
|
||||
:id branch-file-id})]
|
||||
(t/is (= "#00ff00" (get-in out [:result :data :pages-index page-id
|
||||
:objects shape-id :fills 0 :fill-color]))))
|
||||
;; main's own change arrives through the repositioned base, so the
|
||||
;; net the update writes is empty. A ref left in main's id space would
|
||||
;; the source's own change arrives through the repositioned base, so the
|
||||
;; net the update writes is empty. A ref left in the source's id space would
|
||||
;; make this shape differ from the new base and put it in the log.
|
||||
(t/is (empty? (oplog-rows branch-file-id))))
|
||||
|
||||
(t/testing "a genuine conflict still reports"
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-id "#0000ff")}]})
|
||||
:operations [{:type :set :attr :fills :val (fills source-id "#0000ff")}]})
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
@ -305,7 +305,7 @@
|
||||
(t/is (= 1 (count (-> out :result :conflicts))))
|
||||
(t/is (= shape-id (-> out :result :conflicts first :id)))))
|
||||
|
||||
(t/testing "taking main keeps the branch writeable"
|
||||
(t/testing "taking the source keeps the branch writeable"
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
@ -321,44 +321,45 @@
|
||||
(t/deftest update-resolutions-are-document-keyed
|
||||
;; A resolution names a DOCUMENT, not the role the merge engine happened to
|
||||
;; hand it. `branch_merge.cljc::compute-merge` reports every conflict with
|
||||
;; main's value under `:source` and the branch's under `:branch` in both
|
||||
;; directions, and the command applies each resolution in those same terms
|
||||
;; (`files_branch.clj::update-file-branch-from-source` inverts it before
|
||||
;; `branch_merge.cljc::compute-changes`, which runs with main as the source
|
||||
;; and the branch as the target). This test pins that contract at the
|
||||
;; command boundary: `:source` brings main's value into the
|
||||
;; the source's value under `:source` and the branch's under `:branch` in
|
||||
;; both directions, and the command applies each resolution in those same
|
||||
;; terms (`files_branch.clj::update-file-branch-from-source` inverts it
|
||||
;; before `branch_merge.cljc::compute-changes`, which runs with the branch
|
||||
;; as its `source` argument and the source file as its `branch` argument).
|
||||
;; This test pins that contract at the
|
||||
;; command boundary: `:source` brings the source's value into the
|
||||
;; branch, `:branch` keeps the branch's value, and a per-attribute map
|
||||
;; obeys the same vocabulary for the attribute it names.
|
||||
;;
|
||||
;; Each fixture also gives main one non-conflicting change, and it has to:
|
||||
;; Each fixture also gives the source one non-conflicting change, and it has to:
|
||||
;; a resolution that keeps the branch's own side leaves the engine nothing
|
||||
;; to apply for that entity, and an update with an empty change set takes
|
||||
;; the command's no-op path (`files_branch.clj::update-file-branch-from-source`
|
||||
;; discards the branch's op log there and moves the merge base to main).
|
||||
;; Without a main-side change, every resolution would leave the branch
|
||||
;; carrying main's value, so the two `:source` cases below could pass while
|
||||
;; the resolution was ignored. Main's extra change keeps the write path
|
||||
;; discards the branch's op log there and moves the merge base to the source).
|
||||
;; Without a source-side change, every resolution would leave the branch
|
||||
;; carrying the source's value, so the two `:source` cases below could pass while
|
||||
;; the resolution was ignored. The source's extra change keeps the write path
|
||||
;; exercised, and every case below fails if the mapping is inverted.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
branch-fill "#bb0000"
|
||||
main-fill "#00bb00"
|
||||
source-fill "#00bb00"
|
||||
fills (fn [color] [{:fill-color color :fill-opacity 1}])
|
||||
fixture (fn [idx name]
|
||||
(let [file (th/create-file* idx {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)
|
||||
color-id (uuid/random)]
|
||||
(let [file (th/create-file* idx {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)
|
||||
color-id (uuid/random)]
|
||||
|
||||
;; the shape enters the merge base before the fork
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -369,7 +370,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills "#000000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id name)]
|
||||
(let [create (create-branch* profile source-id name)]
|
||||
;; the same attribute diverges on the two sides
|
||||
(apply-change* profile (:branch-file-id create)
|
||||
{:type :mod-obj
|
||||
@ -377,17 +378,17 @@
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills
|
||||
:val (fills branch-fill)}]})
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills
|
||||
:val (fills main-fill)}]})
|
||||
;; main also gains a change the branch never touched,
|
||||
;; so the update has something of main's to apply
|
||||
(apply-change* profile main-id
|
||||
:val (fills source-fill)}]})
|
||||
;; the source also gains a change the branch never touched,
|
||||
;; so the update has something of the source's to apply
|
||||
(apply-change* profile source-id
|
||||
{:type :add-color
|
||||
:color {:id color-id :name "Main-only"
|
||||
:color {:id color-id :name "Source-only"
|
||||
:color "#336699" :opacity 1}})
|
||||
{:branch-id (:id create)
|
||||
:branch-file-id (:branch-file-id create)
|
||||
@ -405,12 +406,12 @@
|
||||
:branch-id branch-id
|
||||
:resolutions resolutions}))]
|
||||
|
||||
(t/testing "a whole-entity :source resolution applies main's value"
|
||||
(let [fx (fixture 1 "res-doc-main")
|
||||
(t/testing "a whole-entity :source resolution applies the source's value"
|
||||
(let [fx (fixture 1 "res-doc-source")
|
||||
out (update! fx {(:shape-id fx) :source})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status)))
|
||||
(t/is (= main-fill (fill-of fx)))))
|
||||
(t/is (= source-fill (fill-of fx)))))
|
||||
|
||||
(t/testing "a whole-entity :branch resolution keeps the branch's value"
|
||||
(let [fx (fixture 2 "res-doc-branch")
|
||||
@ -419,27 +420,27 @@
|
||||
(t/is (= :updated (-> out :result :status)))
|
||||
(t/is (= branch-fill (fill-of fx)))))
|
||||
|
||||
(t/testing "a per-attribute :source resolution applies main's value to that attribute"
|
||||
(t/testing "a per-attribute :source resolution applies the source's value to that attribute"
|
||||
(let [fx (fixture 3 "res-doc-attr")
|
||||
out (update! fx {(:shape-id fx) {:fills :source}})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status)))
|
||||
(t/is (= main-fill (fill-of fx))))))))
|
||||
(t/is (= source-fill (fill-of fx))))))))
|
||||
|
||||
;; A branch stores no data payload, so its op log IS its work: an update
|
||||
;; from main that discards that log without having folded the work into
|
||||
;; from the source that discards that log without having folded the work into
|
||||
;; the new base destroys it. `files_branch.clj::update-file-branch-from-source`
|
||||
;; has a cheap path for a branch that is already in sync with main, and
|
||||
;; has a cheap path for a branch that is already in sync with the source, and
|
||||
;; the three tests below pin both directions of it. Two of them reproduce
|
||||
;; an observed loss, and the third pins the case the cheap path is for.
|
||||
|
||||
(t/deftest update-from-main-keeps-a-branch-edit-when-main-has-none
|
||||
;; Main holds nothing of its own here, so
|
||||
(t/deftest update-from-source-keeps-a-branch-edit-when-source-has-none
|
||||
;; The source holds nothing of its own here, so
|
||||
;; `branch_merge.cljc::compute-changes` returns an empty change set and
|
||||
;; the command reached its cheap path on that result alone. The branch's
|
||||
;; own edit lived only in the op log, so discarding the log reverted the
|
||||
;; shape to the base's fill. Removing this test lets that loss come back
|
||||
;; through the "main has nothing to say" door.
|
||||
;; through the "the source has nothing to say" door.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -448,15 +449,15 @@
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)]
|
||||
|
||||
;; the shape enters the base before the fork, so the branch inherits it
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -467,7 +468,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills "#000000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id "fast-path-own-edit")
|
||||
(let [create (create-branch* profile source-id "fast-path-own-edit")
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
read-fill (fn []
|
||||
@ -477,7 +478,7 @@
|
||||
[:result :data :pages-index page-id :objects shape-id
|
||||
:fills 0 :fill-color]))]
|
||||
|
||||
;; the branch's only edit, and main never moves after the fork
|
||||
;; the branch's only edit, and the source never moves after the fork
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
@ -494,10 +495,10 @@
|
||||
(t/testing "the branch still derives its own edit from its log"
|
||||
(t/is (= branch-fill (read-fill))))))))
|
||||
|
||||
(t/deftest update-from-main-keeps-the-branch-on-a-branch-resolution
|
||||
(t/deftest update-from-source-keeps-the-branch-on-a-branch-resolution
|
||||
;; A conflict resolved to the branch removes the entity from the change
|
||||
;; set, because the branch's value is already the one that must survive.
|
||||
;; Main's repaint is the only change in play, so the change set came out
|
||||
;; The source's repaint is the only change in play, so the change set came out
|
||||
;; empty and the cheap path discarded the log that held the branch's own
|
||||
;; value. Removing this test lets the resolution path lose the branch's
|
||||
;; side while every other resolution case stays green.
|
||||
@ -505,19 +506,19 @@
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
branch-fill "#bb0000"
|
||||
main-fill "#00bb00"
|
||||
source-fill "#00bb00"
|
||||
fills (fn [color] [{:fill-color color :fill-opacity 1}])
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)]
|
||||
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -528,7 +529,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills "#000000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id "fast-path-conflict")
|
||||
(let [create (create-branch* profile source-id "fast-path-conflict")
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
read-fill (fn []
|
||||
@ -544,11 +545,11 @@
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills branch-fill)}]})
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-fill)}]})
|
||||
:operations [{:type :set :attr :fills :val (fills source-fill)}]})
|
||||
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -560,44 +561,44 @@
|
||||
(t/testing "the resolution keeps the branch's value after the update"
|
||||
(t/is (= branch-fill (read-fill))))))))
|
||||
|
||||
(t/deftest update-from-main-catches-a-branch-with-no-work-up-cheaply
|
||||
;; The cheap path's own case: main advanced its revision, the branch
|
||||
;; holds no work of its own, and the engine finds nothing of main's to
|
||||
(t/deftest update-from-source-catches-a-branch-with-no-work-up-cheaply
|
||||
;; The cheap path's own case: the source advanced its revision, the branch
|
||||
;; holds no work of its own, and the engine finds nothing of the source's to
|
||||
;; apply, so the repositioned base alone reproduces the branch's state.
|
||||
;; A branch that is behind main in CONTENT does not reach this path, for
|
||||
;; `branch_merge.cljc::compute-changes` reports main's own changes as the
|
||||
;; A branch that is behind the source in CONTENT does not reach this path, for
|
||||
;; `branch_merge.cljc::compute-changes` reports the source's own changes as the
|
||||
;; set the update must apply, and the command then takes the squash
|
||||
;; below. Removing this test lets the cheap path
|
||||
;; (`files_branch.clj::update-file-branch-from-source`) be widened or dropped
|
||||
;; until every such update pays for a branch snapshot, a branch revision,
|
||||
;; and a rewrite of an empty log.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
fills (fn [color] [{:fill-color color :fill-opacity 1}])
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)
|
||||
;; an edit that changes nothing: main's revision moves, its
|
||||
;; content does not, so the update has nothing of main's to apply
|
||||
bump-main! (fn []
|
||||
(let [f (th/db-get :file {:id main-id})]
|
||||
(th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id
|
||||
:session-id (uuid/random)
|
||||
:revn (:revn f)
|
||||
:vern (:vern f)
|
||||
:features cfeat/supported-features
|
||||
:changes []})))]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
fills (fn [color] [{:fill-color color :fill-opacity 1}])
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)
|
||||
;; an edit that changes nothing: the source's revision moves, its
|
||||
;; content does not, so the update has nothing of the source's to apply
|
||||
bump-source! (fn []
|
||||
(let [f (th/db-get :file {:id source-id})]
|
||||
(th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id source-id
|
||||
:session-id (uuid/random)
|
||||
:revn (:revn f)
|
||||
:vern (:vern f)
|
||||
:features cfeat/supported-features
|
||||
:changes []})))]
|
||||
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -608,7 +609,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills "#000000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id "fast-path-no-work")
|
||||
(let [create (create-branch* profile source-id "fast-path-no-work")
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
revn-before (:revn (th/db-get :file {:id branch-file-id}))
|
||||
@ -620,12 +621,12 @@
|
||||
:id file-id})
|
||||
:result :data :pages-index))]
|
||||
|
||||
;; main moves on in revision terms, and the branch still holds no
|
||||
;; the source moves on in revision terms, and the branch still holds no
|
||||
;; work of its own
|
||||
(bump-main!)
|
||||
(bump-source!)
|
||||
|
||||
(t/testing "the branch is behind main before the update"
|
||||
(t/is (pos? (- (:revn (th/db-get :file {:id main-id}))
|
||||
(t/testing "the branch is behind the source before the update"
|
||||
(t/is (pos? (- (:revn (th/db-get :file {:id source-id}))
|
||||
(:base-source-revn base-before)))))
|
||||
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
@ -634,13 +635,13 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
|
||||
(t/testing "the branch's derived state is main's"
|
||||
(t/is (= (derive main-id) (derive branch-file-id))))
|
||||
(t/testing "the branch's derived state is the source's"
|
||||
(t/is (= (derive source-id) (derive branch-file-id))))
|
||||
|
||||
(t/testing "the merge base moved to main's current revision"
|
||||
(let [base-after (th/db-get :file-branch {:id branch-id})
|
||||
main-file (th/db-get :file {:id main-id})]
|
||||
(t/is (= (:revn main-file) (:base-source-revn base-after)))
|
||||
(t/testing "the merge base moved to the source's current revision"
|
||||
(let [base-after (th/db-get :file-branch {:id branch-id})
|
||||
source-file (th/db-get :file {:id source-id})]
|
||||
(t/is (= (:revn source-file) (:base-source-revn base-after)))
|
||||
(t/is (not= (:base-snapshot-id base-before) (:base-snapshot-id base-after)))))
|
||||
|
||||
(t/testing "the branch was not rewritten to catch up"
|
||||
@ -805,7 +806,7 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
main (th/create-file* 1 {:profile-id (:id profile)
|
||||
source (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
ordinary (th/create-file* 2 {:profile-id (:id profile)
|
||||
@ -823,10 +824,10 @@
|
||||
new-op {:type :add-color
|
||||
:color {:id c3 :name "Three" :path "Brand / Three" :color "#333333" :opacity 1}}]
|
||||
|
||||
(apply-change* profile (:id main) seed)
|
||||
(apply-change* profile (:id source) seed)
|
||||
(apply-change* profile (:id ordinary) seed)
|
||||
|
||||
(let [branch-file-id (:branch-file-id (create-branch* profile (:id main) "straddle"))]
|
||||
(let [branch-file-id (:branch-file-id (create-branch* profile (:id source) "straddle"))]
|
||||
(apply-change* profile branch-file-id old-op)
|
||||
(apply-change* profile (:id ordinary) old-op)
|
||||
|
||||
@ -844,24 +845,24 @@
|
||||
(t/is (= expected derived)))))))))
|
||||
|
||||
(t/deftest merge-after-an-upgrade-compares-against-a-migrated-base
|
||||
;; The branch renames a color before the upgrade and main never touches
|
||||
;; it. After the upgrade main and the branch read migrated, so the base
|
||||
;; must read migrated too, or main's migrated path reads as an edit and
|
||||
;; The branch renames a color before the upgrade and the source never
|
||||
;; touches it. After the upgrade the source and the branch read migrated, so the base
|
||||
;; must read migrated too, or the source's migrated path reads as an edit and
|
||||
;; the rename as a modify-modify conflict.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
main (th/create-file* 1 {:profile-id (:id profile)
|
||||
source (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
upgraded (conj fmg/available-migrations test-migration)
|
||||
c1 (uuid/random)]
|
||||
|
||||
(apply-change* profile (:id main)
|
||||
(apply-change* profile (:id source)
|
||||
{:type :add-color
|
||||
:color {:id c1 :name "One" :path "Brand/One" :color "#111111" :opacity 1}})
|
||||
|
||||
(let [create (create-branch* profile (:id main) "rename-before-upgrade")]
|
||||
(let [create (create-branch* profile (:id source) "rename-before-upgrade")]
|
||||
(apply-change* profile (:branch-file-id create)
|
||||
{:type :mod-color
|
||||
:color {:id c1 :name "Uno" :path "Brand/One" :color "#111111" :opacity 1}})
|
||||
@ -882,22 +883,22 @@
|
||||
(t/is (= :merged (-> out :result :status)))
|
||||
(t/is (empty? (-> out :result :conflicts))))
|
||||
(t/is (= {:name "Uno" :path "Brand / One"}
|
||||
(-> (colors-of (read-file profile (:id main)))
|
||||
(-> (colors-of (read-file profile (:id source)))
|
||||
(get c1)
|
||||
(select-keys [:name :path]))))))))))
|
||||
|
||||
(t/deftest steady-state-branch-reads-run-no-migration
|
||||
;; No upgrade since the branch was cut: base, op log, main and branch
|
||||
;; No upgrade since the branch was cut: base, op log, source and branch
|
||||
;; share one data version, so reading, comparing and merging the branch
|
||||
;; must not run a migration, not even an empty one (the schema check at
|
||||
;; the end of `fmg/migrate` walks the whole document).
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
main (th/create-file* 1 {:profile-id (:id profile)
|
||||
source (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
create (create-branch* profile (:id main) "steady")
|
||||
create (create-branch* profile (:id source) "steady")
|
||||
branch-file-id (:branch-file-id create)
|
||||
real-migrate fmg/migrate
|
||||
real-migrate-data fmg/migrate-data
|
||||
@ -915,7 +916,7 @@
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "B" :path "Brand/B" :color "#222222" :opacity 1}})
|
||||
(apply-change* profile (:id main)
|
||||
(apply-change* profile (:id source)
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "M" :path "Brand/M" :color "#333333" :opacity 1}})
|
||||
|
||||
@ -935,33 +936,33 @@
|
||||
|
||||
(t/is (zero? @calls))))))
|
||||
|
||||
(t/deftest update-from-main-after-an-upgrade-compares-against-a-migrated-base
|
||||
;; Same history as the merge case, integrated the other way: main's
|
||||
;; migrated path must not read as a main-side edit of the color the
|
||||
(t/deftest update-from-source-after-an-upgrade-compares-against-a-migrated-base
|
||||
;; Same history as the merge case, integrated the other way: the source's
|
||||
;; migrated path must not read as a source-side edit of the color the
|
||||
;; branch renamed.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
main (th/create-file* 1 {:profile-id (:id profile)
|
||||
source (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
upgraded (conj fmg/available-migrations test-migration)
|
||||
c1 (uuid/random)
|
||||
c2 (uuid/random)]
|
||||
|
||||
(apply-change* profile (:id main)
|
||||
(apply-change* profile (:id source)
|
||||
{:type :add-color
|
||||
:color {:id c1 :name "One" :path "Brand/One" :color "#111111" :opacity 1}})
|
||||
|
||||
(let [create (create-branch* profile (:id main) "update-after-upgrade")]
|
||||
(let [create (create-branch* profile (:id source) "update-after-upgrade")]
|
||||
(apply-change* profile (:branch-file-id create)
|
||||
{:type :mod-color
|
||||
:color {:id c1 :name "Uno" :path "Brand/One" :color "#111111" :opacity 1}})
|
||||
|
||||
(with-redefs [fmg/available-migrations upgraded]
|
||||
;; main's own work after the upgrade gives the update something
|
||||
;; the source's own work after the upgrade gives the update something
|
||||
;; to bring in
|
||||
(apply-change* profile (:id main)
|
||||
(apply-change* profile (:id source)
|
||||
{:type :add-color
|
||||
:color {:id c2 :name "Two" :path "Brand / Two" :color "#222222" :opacity 1}})
|
||||
|
||||
@ -972,37 +973,37 @@
|
||||
(t/is (= :updated (-> out :result :status)))
|
||||
(t/is (empty? (-> out :result :conflicts))))
|
||||
|
||||
(t/testing "the branch keeps its rename and gains main's color"
|
||||
(t/testing "the branch keeps its rename and gains the source's color"
|
||||
(let [colors (colors-of (read-file profile (:branch-file-id create)))]
|
||||
(t/is (= {:name "Uno" :path "Brand / One"}
|
||||
(select-keys (get colors c1) [:name :path])))
|
||||
(t/is (= {:name "Two" :path "Brand / Two"}
|
||||
(select-keys (get colors c2) [:name :path]))))))))))
|
||||
|
||||
(t/deftest update-from-main-conflict-sides-name-the-documents
|
||||
(t/deftest update-from-source-conflict-sides-name-the-documents
|
||||
;; `update-file-branch-from-source` reports its conflicts in document terms:
|
||||
;; `:source` carries main's value and `:branch` the branch's, whatever the
|
||||
;; `:source` carries the source's value and `:branch` the branch's, whatever the
|
||||
;; direction the engine ran in. Resolving the conflict to `:branch` then
|
||||
;; keeps the branch's value end to end.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
branch-fill "#bb0000"
|
||||
main-fill "#00bb00"
|
||||
source-fill "#00bb00"
|
||||
fills (fn [color] [{:fill-color color :fill-opacity 1}])
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id
|
||||
:is-shared false})
|
||||
main-id (:id file)
|
||||
source-id (:id file)
|
||||
page-id (-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id main-id})
|
||||
:id source-id})
|
||||
:result :data :pages first)
|
||||
shape-id (uuid/random)
|
||||
color-id (uuid/random)]
|
||||
|
||||
;; the shape enters the merge base before the fork
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
@ -1013,7 +1014,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})
|
||||
(assoc :fills (fills "#000000")))})
|
||||
|
||||
(let [create (create-branch* profile main-id "update-conflict-sides")
|
||||
(let [create (create-branch* profile source-id "update-conflict-sides")
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
read-fill (fn []
|
||||
@ -1029,16 +1030,16 @@
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills branch-fill)}]})
|
||||
(apply-change* profile main-id
|
||||
(apply-change* profile source-id
|
||||
{:type :mod-obj
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-fill)}]})
|
||||
;; main also gains a change the branch never touched, so the update
|
||||
;; has something of main's to apply and takes the write path
|
||||
(apply-change* profile main-id
|
||||
:operations [{:type :set :attr :fills :val (fills source-fill)}]})
|
||||
;; the source also gains a change the branch never touched, so the update
|
||||
;; has something of the source's to apply and takes the write path
|
||||
(apply-change* profile source-id
|
||||
{:type :add-color
|
||||
:color {:id color-id :name "Main-only"
|
||||
:color {:id color-id :name "Source-only"
|
||||
:color "#336699" :opacity 1}})
|
||||
|
||||
(t/testing "the conflict names the two documents"
|
||||
@ -1048,9 +1049,9 @@
|
||||
c (first (-> out :result :conflicts))]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
(t/is (= shape-id (:id c)))
|
||||
(t/is (= main-fill (get-in c [:source :fills 0 :fill-color])))
|
||||
(t/is (= source-fill (get-in c [:source :fills 0 :fill-color])))
|
||||
(t/is (= branch-fill (get-in c [:branch :fills 0 :fill-color])))
|
||||
(t/is (= {:source (fills main-fill) :branch (fills branch-fill)}
|
||||
(t/is (= {:source (fills source-fill) :branch (fills branch-fill)}
|
||||
(get-in c [:changed-attrs :fills])))))
|
||||
|
||||
(t/testing "resolved to :branch, the branch keeps its own value"
|
||||
@ -1106,7 +1107,7 @@
|
||||
:mtype "image/png"}})})
|
||||
|
||||
{:profile profile
|
||||
:main-id (:id file)
|
||||
:source-id (:id file)
|
||||
:branch-id (:id create)
|
||||
:branch-file-id branch-file-id
|
||||
:page-id page-id
|
||||
@ -1130,12 +1131,12 @@
|
||||
;; Every op log row stamps the media id map the save or the update that
|
||||
;; wrote it applied (`media_id_map`, {old-id -> new-id}, the branch's id
|
||||
;; is the new one), so the comparison reads the branch's own record of
|
||||
;; which media rows are copies of main's and leaves the content identity
|
||||
;; which media rows are copies of the source's and leaves the content identity
|
||||
;; heuristic (`media-pairs`) for logs written before the column existed.
|
||||
|
||||
(defn- main-media-setup
|
||||
(defn- source-media-setup
|
||||
"The branch-side pairing scenario: an image whose `file_media_object`
|
||||
row MAIN owns is placed on the branch. The save's media fix-up copies
|
||||
row the SOURCE owns is placed on the branch. The save's media fix-up copies
|
||||
the row into the branch under a fresh id, which is the copy the pairs
|
||||
describe. Returns the pieces the assertions need."
|
||||
[]
|
||||
@ -1146,11 +1147,11 @@
|
||||
:is-shared false})
|
||||
storage (-> (:app.storage/storage th/*system*)
|
||||
(assoc :app.storage/backend :fs))
|
||||
sobj (sto/put-object! storage {::sto/content (sto/content "main-image")
|
||||
sobj (sto/put-object! storage {::sto/content (sto/content "source-image")
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"})
|
||||
fmo (th/create-file-media-object* {:file-id (:id file)
|
||||
:name "main.png"
|
||||
:name "source.png"
|
||||
:mtype "image/png"
|
||||
:media-id (:id sobj)})
|
||||
create (create-branch* profile (:id file) "media-remap")
|
||||
@ -1173,7 +1174,7 @@
|
||||
(t/is (nil? (:error out)) "the setup save lands"))
|
||||
|
||||
{:profile profile
|
||||
:main-id (:id file)
|
||||
:source-id (:id file)
|
||||
:branch-id (:id create)
|
||||
:branch-file-id branch-file-id
|
||||
:page-id page-id
|
||||
@ -1196,12 +1197,12 @@
|
||||
branch-file-id]))
|
||||
|
||||
(t/deftest branch-save-records-the-applied-media-id-map
|
||||
;; A branch save that copies main's media stamps its op log row with
|
||||
;; A branch save that copies the source's media stamps its op log row with
|
||||
;; the id remap the fix-up applied, as applied: the source's id maps to
|
||||
;; the branch's copy.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [branch-file-id fmo-id]}
|
||||
(main-media-setup)
|
||||
(source-media-setup)
|
||||
|
||||
[stamp]
|
||||
(->> (media-id-maps branch-file-id)
|
||||
@ -1222,7 +1223,7 @@
|
||||
;; fallback.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile branch-id branch-file-id]}
|
||||
(main-media-setup)
|
||||
(source-media-setup)
|
||||
|
||||
diff!
|
||||
(fn []
|
||||
@ -1250,9 +1251,9 @@
|
||||
(let [without-stamps (diff!)]
|
||||
(t/is (= @with-stamps without-stamps))))))
|
||||
|
||||
(t/deftest update-from-main-records-the-map-it-applied
|
||||
;; The update applies main's media to the branch in the branch's id
|
||||
;; space ({main-media-id -> branch-media-id}) and the squash row
|
||||
(t/deftest update-from-source-records-the-map-it-applied
|
||||
;; The update applies the source's media to the branch in the branch's id
|
||||
;; space ({source-media-id -> branch-media-id}) and the squash row
|
||||
;; records that map as applied, so a later comparison rebuilds the
|
||||
;; branch->source pairs from the record instead of the heuristic.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -1275,7 +1276,7 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
;; main's new media row is referenced by a main-side shape the
|
||||
;; the source's new media row is referenced by a source-side shape the
|
||||
;; update applies, so the update copies it into the branch and its
|
||||
;; map lands in the stamp
|
||||
(t/is (nil? (:error (apply-change* profile (:id file)
|
||||
@ -1285,13 +1286,13 @@
|
||||
:parent-id uuid/zero
|
||||
:frame-id uuid/zero
|
||||
:obj (cts/setup-shape
|
||||
{:id (uuid/random) :name "Main image" :type :image
|
||||
{:id (uuid/random) :name "Source image" :type :image
|
||||
:parent-id uuid/zero :frame-id uuid/zero
|
||||
:metadata {:id (:id fmo)
|
||||
:width 100 :height 100
|
||||
:mtype "image/png"}})}))))
|
||||
;; the branch carries its own change (so the squash writes a net
|
||||
;; row) and main adds a change of its own (so the update reaches
|
||||
;; row) and the source adds a change of its own (so the update reaches
|
||||
;; the write path)
|
||||
(t/is (nil? (:error (apply-change* profile branch-file-id
|
||||
{:type :add-color
|
||||
@ -1320,8 +1321,8 @@
|
||||
;; the same summary and the same merge result the heuristic produced
|
||||
;; on the same data: the record describes the same pairings.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile branch-id branch-file-id main-id page-id shape-id]}
|
||||
(main-media-setup)
|
||||
(let [{:keys [profile branch-id branch-file-id source-id page-id shape-id]}
|
||||
(source-media-setup)
|
||||
|
||||
diff!
|
||||
(fn []
|
||||
@ -1340,17 +1341,17 @@
|
||||
"same summary the heuristic produced"))
|
||||
|
||||
;; merge the stamped branch and check the merged shape references
|
||||
;; a media row MAIN owns
|
||||
;; a media row the SOURCE owns
|
||||
(let [merge (-> (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
:result)]
|
||||
(t/is (= :merged (:status merge)))
|
||||
(let [ref (-> (derived-obj profile main-id page-id shape-id)
|
||||
(let [ref (-> (derived-obj profile source-id page-id shape-id)
|
||||
media-ref)
|
||||
row (th/db-get :file-media-object {:id ref})]
|
||||
(t/is (some? row))
|
||||
(t/is (= main-id (:file-id row))))))))
|
||||
(t/is (= source-id (:file-id row))))))))
|
||||
|
||||
(t/deftest branch-save-fixes-foreign-media-refs-in-the-op-log
|
||||
;; An ordinary save carries the media fix-up with its payload: the
|
||||
@ -1389,14 +1390,14 @@
|
||||
(t/is (= 1 (count rows)))
|
||||
(t/is (= derived-ref (:id (first rows)))))))))
|
||||
|
||||
(t/deftest merge-carries-the-fixed-media-into-main
|
||||
(t/deftest merge-carries-the-fixed-media-into-the-source
|
||||
;; The fix-up's copy is owned by the branch file, so the merge must
|
||||
;; carry the row into main and point main's shape at a row main owns.
|
||||
;; carry the row into the source and point the source's shape at a row the source owns.
|
||||
;; With the reference left foreign, `files_branch.clj::unpaired-media-rows`
|
||||
;; drops the row (it filters by branch ownership) and main ends up
|
||||
;; drops the row (it filters by branch ownership) and the source ends up
|
||||
;; referencing media it does not own.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile main-id branch-id page-id shape-id]}
|
||||
(let [{:keys [profile source-id branch-id page-id shape-id]}
|
||||
(foreign-media-setup)
|
||||
|
||||
out
|
||||
@ -1407,7 +1408,7 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status)))
|
||||
|
||||
(let [ref (-> (derived-obj profile main-id page-id shape-id) media-ref)
|
||||
(let [ref (-> (derived-obj profile source-id page-id shape-id) media-ref)
|
||||
row (th/db-get :file-media-object {:id ref})]
|
||||
(t/is (some? row))
|
||||
(t/is (= main-id (:file-id row)))))))
|
||||
(t/is (= source-id (:file-id row)))))))
|
||||
|
||||
@ -102,14 +102,14 @@
|
||||
(t/is (= (:name file) (:source-name info)))
|
||||
(t/is (= 0 (:ahead info)))
|
||||
(t/is (= 0 (:behind info))))
|
||||
;; the main file is not a branch -> nil
|
||||
;; the source file is not a branch -> nil
|
||||
(let [out (th/command! {::th/type :get-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:result out)))))
|
||||
|
||||
(t/testing "merge base snapshot created on main"
|
||||
(t/testing "merge base snapshot created on the source"
|
||||
(let [rows (th/db-query :file-change {:file-id (:id file)})]
|
||||
(t/is (pos? (count rows)))
|
||||
(t/is (some #(= "system" (:created-by %)) rows))))
|
||||
@ -122,14 +122,14 @@
|
||||
meta (-> out :result :meta)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (map? stats))
|
||||
;; base == main == branch at fork -> nothing to merge, no conflicts
|
||||
;; base == source == branch at fork -> nothing to merge, no conflicts
|
||||
(t/is (= 0 (:conflicts stats)))
|
||||
;; the resolution UI gets the "when" of each side
|
||||
(t/is (some? (:source-at meta)))
|
||||
(t/is (some? (:branch-at meta)))
|
||||
(t/is (some? (:base-at meta)))))
|
||||
|
||||
(t/testing "merge branch into main (clean, no-op)"
|
||||
(t/testing "merge branch into the source (clean, no-op)"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id @branch-meta-id})]
|
||||
@ -150,10 +150,10 @@
|
||||
:file-id (:id file)
|
||||
:name "cache-probe"}))
|
||||
branch-file-id (:branch-file-id create)
|
||||
main-page-id (uuid/random)
|
||||
source-page-id (uuid/random)
|
||||
branch-page-id (uuid/random)]
|
||||
|
||||
(t/testing "diverge both sides: one page on main, one on the branch"
|
||||
(t/testing "diverge both sides: one page on the source, one on the branch"
|
||||
(let [mf (th/db-get :file {:id (:id file)})
|
||||
out (th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -162,7 +162,7 @@
|
||||
:revn (:revn mf)
|
||||
:vern (:vern mf)
|
||||
:features cfeat/supported-features
|
||||
:changes [{:type :add-page :id main-page-id :name "main-side"}]})]
|
||||
:changes [{:type :add-page :id source-page-id :name "source-side"}]})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [bf (th/db-get :file {:id branch-file-id})
|
||||
out (th/command! {::th/type :update-file
|
||||
@ -227,7 +227,7 @@
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "branch info reports diff-based ahead/behind"
|
||||
;; one logical change on the branch (the added color), main untouched
|
||||
;; one logical change on the branch (the added color), the source untouched
|
||||
(let [info (:result (th/command! {::th/type :get-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id branch-file-id}))]
|
||||
@ -244,7 +244,7 @@
|
||||
(t/is (= 0 (:behind row)))
|
||||
(t/is (= 0 (:conflicts row)))))
|
||||
|
||||
(t/testing "merge brings the new color into main"
|
||||
(t/testing "merge brings the new color into the source"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -259,7 +259,7 @@
|
||||
(t/is (contains? colors color-id))
|
||||
(t/is (= "Brand" (get-in colors [color-id :name]))))))))
|
||||
|
||||
(t/deftest update-branch-pulls-main-changes
|
||||
(t/deftest update-branch-pulls-source-changes
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -275,9 +275,9 @@
|
||||
branch-id (:id create)
|
||||
|
||||
color-id (uuid/random)
|
||||
color {:id color-id :name "MainColor" :color "#00ff00" :opacity 1}]
|
||||
color {:id color-id :name "SourceColor" :color "#00ff00" :opacity 1}]
|
||||
|
||||
(t/testing "add a color on main (after the branch was created)"
|
||||
(t/testing "add a color on the source (after the branch was created)"
|
||||
(let [mf (th/db-get :file {:id (:id file)})
|
||||
out (th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -289,7 +289,7 @@
|
||||
:changes [{:type :add-color :color color}]})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "compare in the :source->branch direction shows main's incoming change"
|
||||
(t/testing "compare in the :source->branch direction shows the source's incoming change"
|
||||
(let [diff (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
@ -298,7 +298,7 @@
|
||||
(t/is (= 1 (-> diff :stats :added)))
|
||||
(t/is (= color-id (-> added first :id)))))
|
||||
|
||||
(t/testing "update the branch from main"
|
||||
(t/testing "update the branch from the source"
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -311,7 +311,7 @@
|
||||
colors (-> out :result :data :colors)]
|
||||
(t/is (contains? colors color-id)))
|
||||
|
||||
;; merge base repositioned to the current state of main
|
||||
;; merge base repositioned to the current state of the source
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
mf (th/db-get :file {:id (:id file)})]
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))))))
|
||||
@ -343,7 +343,7 @@
|
||||
:changes [{:type :add-page :id new-page-id :name "Branch Page"}]})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "merge brings the new page into main"
|
||||
(t/testing "merge brings the new page into the source"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -357,8 +357,8 @@
|
||||
(t/is (contains? pages new-page-id)))))))
|
||||
|
||||
(t/deftest merge-reparents-existing-shape
|
||||
;; main: a rect at the page root. branch: that rect moved into a new board.
|
||||
;; after merge main must have the rect INSIDE the board and NOT loose at
|
||||
;; source: a rect at the page root. branch: that rect moved into a new board.
|
||||
;; after merge the source must have the rect INSIDE the board and NOT loose at
|
||||
;; root (regression: reparenting was applied as :set parent-id, which left
|
||||
;; the shape duplicated/loose).
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -374,7 +374,7 @@
|
||||
rect-id (uuid/random)
|
||||
board-id (uuid/random)]
|
||||
|
||||
(t/testing "add a rect at the root of main"
|
||||
(t/testing "add a rect at the root of the source"
|
||||
(let [mf (th/db-get :file {:id (:id file)})
|
||||
out (th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -444,9 +444,9 @@
|
||||
(t/is (not (contains? (set (get-in objects [uuid/zero :shapes])) rect-id)))))))))
|
||||
|
||||
(t/deftest merge-component-stays-a-component
|
||||
;; create a component on a branch, merge it into main, and verify the
|
||||
;; create a component on a branch, merge it into the source, and verify the
|
||||
;; merged main instance is still a valid component head (component-id set,
|
||||
;; component-file re-pointed to main) — regression: it was detached.
|
||||
;; component-file re-pointed to the source) — regression: it was detached.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -496,7 +496,7 @@
|
||||
:main-instance-page page-id}]})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "merge integrates the component into main as a real head"
|
||||
(t/testing "merge integrates the component into the source as a real head"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -508,9 +508,9 @@
|
||||
:id (:id file)})
|
||||
:result :data)
|
||||
shape (get-in data [:pages-index page-id :objects mi-id])]
|
||||
;; the component registry row landed in main
|
||||
;; the component registry row landed in the source
|
||||
(t/is (contains? (:components data) comp-id))
|
||||
;; the main instance is NOT detached: still a head pointing at main
|
||||
;; the main instance is NOT detached: still a head pointing at the source
|
||||
(t/is (= comp-id (:component-id shape)))
|
||||
(t/is (= (:id file) (:component-file shape)))
|
||||
(t/is (true? (:main-instance shape)))
|
||||
@ -566,7 +566,7 @@
|
||||
(t/is (some? (:deleted-at row)))
|
||||
(t/is (some? (:deleted-at frow))))))))
|
||||
|
||||
(t/deftest update-resolves-conflict-to-main
|
||||
(t/deftest update-resolves-conflict-to-source
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -586,7 +586,7 @@
|
||||
:features cfeat/supported-features
|
||||
:changes [change]})))]
|
||||
|
||||
;; color exists on main before branching (base = red)
|
||||
;; color exists on the source before branching (base = red)
|
||||
(apply-change (:id file) {:type :add-color :color {:id cid :name "Brand" :color "#ff0000" :opacity 1}})
|
||||
|
||||
(let [create (:result (th/command! {::th/type :create-file-branch
|
||||
@ -596,7 +596,7 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
;; main edits the color -> green; branch edits it -> blue (conflict)
|
||||
;; the source edits the color -> green; branch edits it -> blue (conflict)
|
||||
(apply-change (:id file) {:type :mod-color :color {:id cid :name "Brand" :color "#00ff00" :opacity 1}})
|
||||
(apply-change branch-file-id {:type :mod-color :color {:id cid :name "Brand" :color "#0000ff" :opacity 1}})
|
||||
|
||||
@ -606,7 +606,7 @@
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :conflicts (-> out :result :status)))))
|
||||
|
||||
(t/testing "resolving to main brings main's value into the branch"
|
||||
(t/testing "resolving to the source brings the source's value into the branch"
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
@ -619,7 +619,7 @@
|
||||
color (get-in out [:result :data :colors cid])]
|
||||
(t/is (= "#00ff00" (:color color)))))))))
|
||||
|
||||
(t/deftest branch-count-counts-from-main-without-comparing
|
||||
(t/deftest branch-count-counts-from-the-root-without-comparing
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
stranger (th/create-profile* 2 {:is-active true})
|
||||
@ -659,7 +659,7 @@
|
||||
(t/testing "archived branches count, deleted ones do not"
|
||||
(t/is (= {:count 2} (:result (count-of (:id profile) (:id file))))))
|
||||
|
||||
(t/testing "from a branch, the branches of its main are counted"
|
||||
(t/testing "from a branch, the branches of its family root are counted"
|
||||
(t/is (= {:count 2} (:result (count-of (:id profile) (:branch-file-id kept))))))
|
||||
|
||||
(t/testing "a profile that cannot read the file is refused"
|
||||
@ -709,11 +709,11 @@
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
main-data (fn []
|
||||
(-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})
|
||||
:result :data))]
|
||||
source-data (fn []
|
||||
(-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})
|
||||
:result :data))]
|
||||
(doseq [[label change landed?]
|
||||
[["file plugin data" file-plugin-change
|
||||
#(= "bar" (get-in % [:plugin-data :my-plugin "foo"]))]
|
||||
@ -734,7 +734,7 @@
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
(t/is (landed? (main-data)))))))))
|
||||
(t/is (landed? (source-data)))))))))
|
||||
|
||||
(t/deftest merge-reports-file-level-conflicts
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -747,7 +747,7 @@
|
||||
:name "b"}))]
|
||||
(apply-change* profile (:branch-file-id create) file-plugin-change)
|
||||
(apply-change* profile (:branch-file-id create) base-font-size-change)
|
||||
(apply-change* profile (:id file) (assoc file-plugin-change :value "main"))
|
||||
(apply-change* profile (:id file) (assoc file-plugin-change :value "source"))
|
||||
(apply-change* profile (:id file) (assoc base-font-size-change :base-font-size "18px"))
|
||||
(let [info (:result (th/command! {::th/type :get-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -831,7 +831,7 @@
|
||||
(let [out (merge! (:id second-b) {:comment " "})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
(t/testing "the merges are listed newest first, from main or a branch"
|
||||
(t/testing "the merges are listed newest first, from the source or a branch"
|
||||
(let [out (th/command! {::th/type :get-file-branch-merges
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)})
|
||||
@ -862,7 +862,7 @@
|
||||
:file-id (:id file)})]
|
||||
(t/is (th/ex-of-type? (:error out) :not-found)))))
|
||||
|
||||
(t/deftest merge-requires-main-edition-permissions
|
||||
(t/deftest merge-requires-source-edition-permissions
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile1 (th/create-profile* 1 {:is-active true})
|
||||
profile2 (th/create-profile* 2 {:is-active true})
|
||||
@ -877,7 +877,7 @@
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
;; profile2 is a team viewer, editor of the BRANCH file but only a
|
||||
;; viewer of main
|
||||
;; viewer of the source
|
||||
(th/create-team-role* {:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile2)
|
||||
:role :viewer})
|
||||
@ -893,7 +893,7 @@
|
||||
:branch-id branch-id})]
|
||||
(t/is (some? (:error out))))
|
||||
|
||||
;; but profile2 CAN update the branch from main (edits the branch)
|
||||
;; but profile2 CAN update the branch from the source (edits the branch)
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile2)
|
||||
:branch-id branch-id})]
|
||||
@ -927,7 +927,7 @@
|
||||
:project-id proj-id})
|
||||
cid (uuid/random)]
|
||||
|
||||
;; color exists on main before branching (base = red)
|
||||
;; color exists on the source before branching (base = red)
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id cid :name "Brand" :color "#ff0000" :opacity 1}})
|
||||
|
||||
@ -938,7 +938,7 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
;; main edits the color -> green; branch edits it -> blue (conflict)
|
||||
;; the source edits the color -> green; branch edits it -> blue (conflict)
|
||||
(apply-change* profile (:id file)
|
||||
{:type :mod-color :color {:id cid :name "Brand" :color "#00ff00" :opacity 1}})
|
||||
(apply-change* profile branch-file-id
|
||||
@ -954,7 +954,7 @@
|
||||
(t/is (= :validation (:type (ex-data error))))
|
||||
(t/is (= :params-validation (:code (ex-data error))))))
|
||||
|
||||
(t/testing "a typo in a per-attr value is refused, not silently read as main"
|
||||
(t/testing "a typo in a per-attr value is refused, not silently read as the source"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
@ -991,7 +991,7 @@
|
||||
branch-file-id (:branch-file-id create)
|
||||
cid (uuid/random)]
|
||||
|
||||
;; main advances after the branch was created
|
||||
;; the source advances after the branch was created
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id cid :name "M" :color "#00ff00" :opacity 1}})
|
||||
|
||||
@ -1022,20 +1022,20 @@
|
||||
:id branch-file-id})]
|
||||
(t/is (contains? (-> out :result :data :colors) cid)))))))
|
||||
|
||||
(t/deftest conflict-responses-carry-the-main-revn
|
||||
(t/deftest conflict-responses-carry-the-source-revn
|
||||
;; A `:conflicts` response is what a resolving client works from, so it
|
||||
;; names the revision of main its conflicts were computed against. The
|
||||
;; names the revision of the source its conflicts were computed against. The
|
||||
;; client sends that revision back as `expected-source-revn` with its
|
||||
;; resolutions, and a main that moved meanwhile is refused.
|
||||
;; resolutions, and a source that moved meanwhile is refused.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id})
|
||||
cid (uuid/random)
|
||||
main-revn (fn [] (:revn (th/db-get :file {:id (:id file)})))]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id})
|
||||
cid (uuid/random)
|
||||
source-revn (fn [] (:revn (th/db-get :file {:id (:id file)})))]
|
||||
|
||||
;; color exists on main before branching (base = red)
|
||||
;; color exists on the source before branching (base = red)
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id cid :name "Brand" :color "#ff0000" :opacity 1}})
|
||||
|
||||
@ -1046,16 +1046,16 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
;; main edits the color -> green; branch edits it -> blue (conflict).
|
||||
;; Main moves past the revision the branch was cut at, so the
|
||||
;; the source edits the color -> green; branch edits it -> blue (conflict).
|
||||
;; The source moves past the revision the branch was cut at, so the
|
||||
;; revision a response names is the current one, not the base's.
|
||||
(apply-change* profile (:id file)
|
||||
{:type :mod-color :color {:id cid :name "Brand" :color "#00ff00" :opacity 1}})
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :mod-color :color {:id cid :name "Brand" :color "#0000ff" :opacity 1}})
|
||||
|
||||
(t/testing "an update that stops on conflicts names main's revision"
|
||||
(let [revn (main-revn)
|
||||
(t/testing "an update that stops on conflicts names the source's revision"
|
||||
(let [revn (source-revn)
|
||||
out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -1063,8 +1063,8 @@
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
(t/is (= revn (-> out :result :source-revn)))))
|
||||
|
||||
(t/testing "a merge that stops on conflicts names main's revision"
|
||||
(let [revn (main-revn)
|
||||
(t/testing "a merge that stops on conflicts names the source's revision"
|
||||
(let [revn (source-revn)
|
||||
out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -1081,7 +1081,7 @@
|
||||
(t/is (nil? (:error retry)))
|
||||
(t/is (= :merged (-> retry :result :status)))))))))))
|
||||
|
||||
(t/deftest revn-gate-survives-update-from-main
|
||||
(t/deftest revn-gate-survives-update-from-source
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -1101,7 +1101,7 @@
|
||||
;; ONE change on the branch...
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color :color {:id bid :name "B" :color "#0000ff" :opacity 1}})
|
||||
;; ...while main advances MORE times than the branch (its revn ends up
|
||||
;; ...while the source advances MORE times than the branch (its revn ends up
|
||||
;; far ahead of the branch's own revn counter)
|
||||
(doseq [[id nm] [[m1 "M1"] [m2 "M2"] [m3 "M3"]]]
|
||||
(apply-change* profile (:id file)
|
||||
@ -1202,7 +1202,7 @@
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(t/testing "the parent branch takes the change in its op log, main does not"
|
||||
(t/testing "the parent branch takes the change in its op log, the root does not"
|
||||
(t/is (contains? (colors-of profile (:branch-file-id parent)) color-id))
|
||||
(t/is (seq (th/db-query :file-branch-change {:branch-id (:id parent)})))
|
||||
(t/is (empty? (th/db-query :file-data {:file-id (:branch-file-id parent) :type "main"})))
|
||||
@ -1212,7 +1212,7 @@
|
||||
(let [[row] (th/db-query :file-branch-merge {:file-id (:branch-file-id parent)})]
|
||||
(t/is (= "child" (:branch-name row)))))
|
||||
|
||||
(t/testing "merging the parent then brings the change into main"
|
||||
(t/testing "merging the parent then brings the change into the root"
|
||||
(t/is (nil? (:error (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id parent)}))))
|
||||
@ -1241,7 +1241,7 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id parent)}))))
|
||||
|
||||
(t/testing "the child now branches from main, its base with it"
|
||||
(t/testing "the child now branches from the root, its base with it"
|
||||
(let [row (th/db-get :file-branch {:id (:id child)})]
|
||||
(t/is (= "open" (:status row)))
|
||||
(t/is (= (:id file) (:source-file-id row)))
|
||||
@ -1249,7 +1249,7 @@
|
||||
(t/is (= (:id file) (:file-id (th/db-get :file-change {:id base-id}
|
||||
{::db/remove-deleted false}))))))
|
||||
|
||||
(t/testing "the child still derives its state and compares against main"
|
||||
(t/testing "the child still derives its state and compares against the root"
|
||||
(let [colors (colors-of profile (:branch-file-id child))]
|
||||
(t/is (contains? colors parent-color))
|
||||
(t/is (contains? colors child-color)))
|
||||
@ -1258,7 +1258,7 @@
|
||||
:branch-id (:id child)})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "the child merges into main"
|
||||
(t/testing "the child merges into the root"
|
||||
(t/is (nil? (:error (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id child)}))))
|
||||
@ -1291,7 +1291,7 @@
|
||||
|
||||
(t/deftest the-branch-quota-counts-the-whole-family
|
||||
;; Counted by direct source, the chain below holds one branch per
|
||||
;; source, so a third branch from main passed a quota of two.
|
||||
;; source, so a third branch from the root passed a quota of two.
|
||||
(with-redefs [cf/flags (stacking-flags)
|
||||
cf/get (th/config-get-mock {:quotes-branches-per-file 2})]
|
||||
(let [{:keys [profile proj-id file branches]} (branch-chain*)
|
||||
@ -1429,7 +1429,7 @@
|
||||
(t/is (nil? row))
|
||||
(t/is (some? (:deleted-at bf)))))))
|
||||
|
||||
(t/deftest merge-copies-branch-media-into-main
|
||||
(t/deftest merge-copies-branch-media-into-source
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -1444,7 +1444,7 @@
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"}))
|
||||
|
||||
;; media present on MAIN before branching (will be paired)
|
||||
;; media present on the SOURCE before branching (will be paired)
|
||||
sobj1 (mk-sobj "shared-image")
|
||||
fmo1 (th/create-file-media-object* {:file-id (:id file)
|
||||
:name "shared.png"
|
||||
@ -1488,7 +1488,7 @@
|
||||
(t/is (= 1 (:ahead info)))
|
||||
(t/is (= 0 (:behind info)))))
|
||||
|
||||
(t/testing "merging brings the new media with a MAIN-owned row"
|
||||
(t/testing "merging brings the new media with a source-owned row"
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -1501,14 +1501,14 @@
|
||||
media (-> out :result :data :media)
|
||||
added (->> (vals media) (filter #(= "new.png" (:name %))) first)]
|
||||
(t/is (some? added))
|
||||
;; the merged entry references a row owned by MAIN (a copy), not
|
||||
;; the merged entry references a row owned by the SOURCE (a copy), not
|
||||
;; the branch's row (which dies with the branch file)
|
||||
(t/is (not= (:id fmo2) (:id added)))
|
||||
(let [row (th/db-get :file-media-object {:id (:id added)})]
|
||||
(t/is (= (:id file) (:file-id row)))
|
||||
(t/is (= (:id sobj2) (:media-id row)))))))))
|
||||
|
||||
(t/deftest merge-copies-colour-image-media-into-main
|
||||
(t/deftest merge-copies-colour-image-media-into-source
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -1557,14 +1557,14 @@
|
||||
:id (:id file)})
|
||||
img-id (get-in out [:result :data :colors cid :image :id])]
|
||||
(t/is (some? img-id))
|
||||
;; the colour's image is a row owned by MAIN (a copy), not the
|
||||
;; the colour's image is a row owned by the SOURCE (a copy), not the
|
||||
;; branch's row (which dies with the branch file)
|
||||
(t/is (not= (:id fmo) img-id))
|
||||
(let [row (th/db-get :file-media-object {:id img-id})]
|
||||
(t/is (= (:id file) (:file-id row)))
|
||||
(t/is (= (:id sobj) (:media-id row))))))))
|
||||
|
||||
(t/deftest update-from-main-copies-colour-image-media-into-branch
|
||||
(t/deftest update-from-source-copies-colour-image-media-into-branch
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -1581,12 +1581,12 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
|
||||
;; media ADDED on MAIN after forking, used only by a library colour
|
||||
sobj (sto/put-object! storage {::sto/content (sto/content "main-colour-image")
|
||||
;; media ADDED on the SOURCE after forking, used only by a library colour
|
||||
sobj (sto/put-object! storage {::sto/content (sto/content "source-colour-image")
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"})
|
||||
fmo (th/create-file-media-object* {:file-id (:id file)
|
||||
:name "main-colour.png"
|
||||
:name "source-colour.png"
|
||||
:mtype "image/png"
|
||||
:media-id (:id sobj)})
|
||||
cid (uuid/random)
|
||||
@ -1626,7 +1626,7 @@
|
||||
|
||||
(t/testing "the update logs no phantom branch change"
|
||||
;; the colour image id must be re-pointed at the copy like every
|
||||
;; other ref (`bm/remap-changes`); left in main's id space it makes
|
||||
;; other ref (`bm/remap-changes`); left in the source's id space it makes
|
||||
;; the colour differ from the new base and lands in the op log
|
||||
(t/is (empty? (th/db-query :file-branch-change {:branch-id branch-id})))))))
|
||||
|
||||
@ -1813,11 +1813,11 @@
|
||||
(let [orig bm/compute-merge
|
||||
pruned (atom 0)]
|
||||
(with-redefs [bm/compute-merge
|
||||
(fn [base main branch dir & [opts]]
|
||||
(let [res (orig base main branch dir opts)]
|
||||
(fn [base source branch dir & [opts]]
|
||||
(let [res (orig base source branch dir opts)]
|
||||
(when (:only-pages opts)
|
||||
(swap! pruned inc)
|
||||
(t/is (= (orig base main branch dir (dissoc opts :only-pages)) res)
|
||||
(t/is (= (orig base source branch dir (dissoc opts :only-pages)) res)
|
||||
"the pruned summary differs from the whole-file summary"))
|
||||
res))]
|
||||
(f))
|
||||
@ -1842,7 +1842,7 @@
|
||||
branch-file-id (:branch-file-id create)
|
||||
rect-id (uuid/random)]
|
||||
|
||||
(t/testing "a page-scoped edit on the branch and a page on main"
|
||||
(t/testing "a page-scoped edit on the branch and a page on the source"
|
||||
(let [bf (th/db-get :file {:id branch-file-id})
|
||||
out (th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
@ -1868,7 +1868,7 @@
|
||||
:revn (:revn mf)
|
||||
:vern (:vern mf)
|
||||
:features cfeat/supported-features
|
||||
:changes [{:type :add-page :id (uuid/random) :name "main-side"}]})]
|
||||
:changes [{:type :add-page :id (uuid/random) :name "source-side"}]})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "the compare is pruned and reports the same summary"
|
||||
@ -2111,8 +2111,8 @@
|
||||
(t/is (zero? @reads) "the refused compare decoded the op log")
|
||||
(t/is (zero? @derives) "the refused compare derived the branch first"))))
|
||||
|
||||
(t/testing "an update from main stamps the squash it writes"
|
||||
(apply-change* profile (:id file) {:type :add-page :id (uuid/random) :name "on-main"})
|
||||
(t/testing "an update from the source stamps the squash it writes"
|
||||
(apply-change* profile (:id file) {:type :add-page :id (uuid/random) :name "on-source"})
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -2378,7 +2378,7 @@
|
||||
:name "meta"}))
|
||||
branch-id (:id create)]
|
||||
|
||||
;; main moves after the fork...
|
||||
;; the source moves after the fork...
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "M" :color "#00ff00" :opacity 1}})
|
||||
@ -2447,7 +2447,7 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
branch-color (uuid/random)
|
||||
main-color (uuid/random)
|
||||
source-color (uuid/random)
|
||||
|
||||
;; validation reports an error the repair cannot fix: the
|
||||
;; repair produces no changes and the re-validation still
|
||||
@ -2455,7 +2455,7 @@
|
||||
unfixable (fn [file _libs] (synthetic-validation-error file))
|
||||
no-repair (fn [_file _libs _errors] [])]
|
||||
|
||||
(t/testing "the merge refuses and leaves main and the branch untouched"
|
||||
(t/testing "the merge refuses and leaves the source and the branch untouched"
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color
|
||||
:color {:id branch-color :name "B" :color "#112233" :opacity 1}})
|
||||
@ -2484,7 +2484,7 @@
|
||||
(t/testing "the update refuses and leaves the branch untouched"
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color
|
||||
:color {:id main-color :name "M" :color "#445566" :opacity 1}})
|
||||
:color {:id source-color :name "M" :color "#445566" :opacity 1}})
|
||||
|
||||
(let [[base] (th/db-query :file-branch {:id branch-id})]
|
||||
(with-redefs [cfv/validate-file unfixable
|
||||
@ -2503,7 +2503,7 @@
|
||||
:id branch-file-id})
|
||||
:result :data :colors)]
|
||||
(t/is (contains? colors branch-color))
|
||||
(t/is (not (contains? colors main-color))))
|
||||
(t/is (not (contains? colors source-color))))
|
||||
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})]
|
||||
(t/is (= "open" (:status row)))
|
||||
@ -2617,12 +2617,12 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:id id})))]
|
||||
|
||||
(t/testing "the merge drops the cached summary of main"
|
||||
(t/testing "the merge drops the cached summary of the source"
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "B" :color "#112233" :opacity 1}})
|
||||
|
||||
;; the cache now describes the pre-merge main
|
||||
;; the cache now describes the pre-merge source
|
||||
(t/is (= 0 (-> (summary (:id file)) :colors :count)))
|
||||
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
@ -2727,7 +2727,7 @@
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :branch-not-found (-> out :error ex-data :code)))))
|
||||
(t/is (= :merged (-> @merged :result :status)))
|
||||
(t/testing "main holds the first merge's revn only"
|
||||
(t/testing "the source holds the first merge's revn only"
|
||||
(t/is (= (-> @merged :result :revn)
|
||||
(:revn (first (th/db-query :file {:id (:id file)}))))))
|
||||
(t/testing "the winning merge is the only one recorded"
|
||||
@ -2740,7 +2740,7 @@
|
||||
(t/deftest merge-releases-the-base-the-lock-shows
|
||||
;; the merge releases the base snapshot pin (on the delete path), and
|
||||
;; the id must come from the row as it stands under the lock: an
|
||||
;; update-from-main that repositions the base while the merge waits
|
||||
;; update-from-source that repositions the base while the merge waits
|
||||
;; must not leave the new base pinned for ten years while the
|
||||
;; superseded one is released a second time
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -2757,7 +2757,7 @@
|
||||
old-base (:base-snapshot-id (first (th/db-query :file-branch {:id branch-id})))
|
||||
cid (uuid/random)
|
||||
mid (uuid/random)]
|
||||
;; the branch carries its own change and main moves ahead, so the
|
||||
;; the branch carries its own change and the source moves ahead, so the
|
||||
;; competing update really repositions the merge base
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color :color {:id cid :name "C" :color "#112233" :opacity 1}})
|
||||
@ -2769,7 +2769,7 @@
|
||||
(with-redefs [db/xact-lock!
|
||||
(fn [conn id]
|
||||
;; before the merge takes any lock, an update
|
||||
;; from main repositions the merge base and
|
||||
;; from the source repositions the merge base and
|
||||
;; releases the pin the branch carried so far
|
||||
(when (compare-and-set! raced? false true)
|
||||
(t/is (nil? (:error (th/command! {::th/type :update-file-branch-from-source
|
||||
@ -2795,7 +2795,7 @@
|
||||
|
||||
(t/deftest update-releases-the-base-the-lock-shows
|
||||
;; the same stale base id on the update path: the second of two
|
||||
;; overlapping updates from main must release the base the first one
|
||||
;; overlapping updates from the source must release the base the first one
|
||||
;; created, not the one it superseded
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -2910,7 +2910,7 @@
|
||||
(t/is (= :file-modified (-> out :error ex-data :code)))
|
||||
(t/is (empty? @seen)))
|
||||
;; the merge deletes the branch: its file's clients hear of the
|
||||
;; deletion and main's of the merge
|
||||
;; deletion and the source's of the merge
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
@ -3075,7 +3075,7 @@
|
||||
conn))
|
||||
|
||||
fbranch/branch-diff-counts!
|
||||
(fn [cfg main-data branch]
|
||||
(fn [cfg source-data branch]
|
||||
(let [conn (db/get-connection cfg)
|
||||
prev (:conn (peek @runs))]
|
||||
(swap! runs conj
|
||||
@ -3089,7 +3089,7 @@
|
||||
:held (into []
|
||||
(remove #(.isClosed ^java.sql.Connection %))
|
||||
@checkouts)}))
|
||||
(orig-compute cfg main-data branch))]
|
||||
(orig-compute cfg source-data branch))]
|
||||
(t/is (nil? (:error (th/command! {::th/type :get-file-branches
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)})))))
|
||||
@ -3109,7 +3109,7 @@
|
||||
|
||||
(defn- squashed-log-types
|
||||
"Change types the branch's op log (`file_branch_change`) carries after
|
||||
the squash an update-from-main performs."
|
||||
the squash an update-from-source performs."
|
||||
[branch-id]
|
||||
(into []
|
||||
(mapcat (fn [row] (map :type (blob/decode (:changes row)))))
|
||||
@ -3118,10 +3118,10 @@
|
||||
(def ^:private media-change-types
|
||||
#{:add-media :mod-media :del-media})
|
||||
|
||||
(t/deftest update-from-main-deletes-the-paired-media-copy
|
||||
;; main deletes a media object the branch holds as a paired copy: the
|
||||
(t/deftest update-from-source-deletes-the-paired-media-copy
|
||||
;; the source deletes a media object the branch holds as a paired copy: the
|
||||
;; delete travels through `bm/remap-changes` with the pair map and must
|
||||
;; name the branch's copy, not main's row — the branch holds neither the
|
||||
;; name the branch's copy, not the source's row — the branch holds neither the
|
||||
;; id the change was computed with nor a second copy of the content
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -3153,8 +3153,8 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-file-id})]
|
||||
(-> out :result :data :media)))]
|
||||
;; a main-side change so the first update reaches the write path and
|
||||
;; copies main's row into the branch
|
||||
;; a source-side change so the first update reaches the write path and
|
||||
;; copies the source's row into the branch
|
||||
(t/is (nil? (:error (apply-change* profile (:id file)
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "C1"
|
||||
@ -3172,7 +3172,7 @@
|
||||
(t/is (= (:id sobj)
|
||||
(:media-id (th/db-get :file-media-object {:id (:id media)}))))))
|
||||
|
||||
(t/testing "deleting it on main deletes the branch's copy"
|
||||
(t/testing "deleting it on the source deletes the branch's copy"
|
||||
(t/is (nil? (:error (apply-change* profile (:id file)
|
||||
{:type :del-media :id (:id fmo)}))))
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
@ -3182,9 +3182,9 @@
|
||||
(t/is (empty? (branch-media)))))))
|
||||
|
||||
(t/deftest repeated-updates-squash-no-phantom-media
|
||||
;; a second update from main must not squash media changes the branch
|
||||
;; never made: the write re-points main's media rows at the branch's
|
||||
;; copies, and the squashed log compares the updated branch with main's
|
||||
;; a second update from the source must not squash media changes the branch
|
||||
;; never made: the write re-points the source's media rows at the branch's
|
||||
;; copies, and the squashed log compares the updated branch with the source's
|
||||
;; state — if one side is re-pointed and the other is not, the paired
|
||||
;; media reads as deleted+added on every update
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -3192,30 +3192,30 @@
|
||||
proj-id (:default-project-id profile)
|
||||
storage (-> (:app.storage/storage th/*system*)
|
||||
(assoc :app.storage/backend :fs))
|
||||
add-media-on-main! (fn [file name]
|
||||
(let [sobj (sto/put-object! storage {::sto/content (sto/content name)
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"})
|
||||
fmo (th/create-file-media-object* {:file-id (:id file)
|
||||
:name name
|
||||
:media-id (:id sobj)})]
|
||||
add-media-on-source! (fn [file name]
|
||||
(let [sobj (sto/put-object! storage {::sto/content (sto/content name)
|
||||
:bucket :file-media-object
|
||||
:content-type "image/png"})
|
||||
fmo (th/create-file-media-object* {:file-id (:id file)
|
||||
:name name
|
||||
:media-id (:id sobj)})]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-media
|
||||
:object {:id (:id fmo) :name name
|
||||
:media-id (:id sobj)
|
||||
:width 100 :height 100
|
||||
:mtype "image/png"}})))
|
||||
add-color-on-source! (fn [file]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-media
|
||||
:object {:id (:id fmo) :name name
|
||||
:media-id (:id sobj)
|
||||
:width 100 :height 100
|
||||
:mtype "image/png"}})))
|
||||
add-color-on-main! (fn [file]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "C"
|
||||
:color "#112233" :opacity 1}}))
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "C"
|
||||
:color "#112233" :opacity 1}}))
|
||||
update! (fn [branch-id]
|
||||
(th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))]
|
||||
|
||||
(t/testing "media added on main after the fork"
|
||||
(t/testing "media added on the source after the fork"
|
||||
(let [file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id proj-id})
|
||||
create (:result (th/command! {::th/type :create-file-branch
|
||||
@ -3223,11 +3223,11 @@
|
||||
:file-id (:id file)
|
||||
:name "after-fork"}))
|
||||
branch-id (:id create)]
|
||||
(t/is (nil? (:error (add-media-on-main! file "after.png"))))
|
||||
(t/is (nil? (:error (add-media-on-source! file "after.png"))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
(t/is (empty? (filter media-change-types (squashed-log-types branch-id))))
|
||||
;; again, with and without new main changes
|
||||
(t/is (nil? (:error (add-color-on-main! file))))
|
||||
;; again, with and without new source changes
|
||||
(t/is (nil? (:error (add-color-on-source! file))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
(t/is (empty? (filter media-change-types (squashed-log-types branch-id))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
@ -3236,18 +3236,18 @@
|
||||
(t/testing "media present before the fork"
|
||||
(let [file (th/create-file* 2 {:profile-id (:id profile)
|
||||
:project-id proj-id})
|
||||
_ (t/is (nil? (:error (add-media-on-main! file "before.png"))))
|
||||
_ (t/is (nil? (:error (add-media-on-source! file "before.png"))))
|
||||
create (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "before-fork"}))
|
||||
branch-id (:id create)]
|
||||
;; a main-side change so the update reaches the write path
|
||||
(t/is (nil? (:error (add-color-on-main! file))))
|
||||
;; a source-side change so the update reaches the write path
|
||||
(t/is (nil? (:error (add-color-on-source! file))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
(t/is (empty? (filter media-change-types (squashed-log-types branch-id))))
|
||||
;; again, with and without new main changes
|
||||
(t/is (nil? (:error (add-color-on-main! file))))
|
||||
;; again, with and without new source changes
|
||||
(t/is (nil? (:error (add-color-on-source! file))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
(t/is (empty? (filter media-change-types (squashed-log-types branch-id))))
|
||||
(t/is (= :updated (-> (update! branch-id) :result :status)))
|
||||
@ -3346,7 +3346,7 @@
|
||||
(#'fbranch/summary-cache-key row)))
|
||||
k-default (key-of bm/default-policies)
|
||||
k-ignore (key-of (assoc bm/default-policies :same-parent-reorder :ignore))
|
||||
k-expand (key-of (assoc bm/default-policies :container-delete-over-main-edits :expand))]
|
||||
k-expand (key-of (assoc bm/default-policies :container-delete-over-target-edits :expand))]
|
||||
|
||||
;; the key is stable for the same policies …
|
||||
(t/is (= k-default (key-of bm/default-policies)))
|
||||
@ -3427,20 +3427,20 @@
|
||||
(t/is (not (contains? (-> out :result :data :colors) color-id)))))
|
||||
|
||||
(t/testing "the update refuses the same way when every incoming change is excluded"
|
||||
(let [main-id (uuid/random)]
|
||||
(let [source-color-id (uuid/random)]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id main-id :name "Main" :color "#00ff00" :opacity 1}})
|
||||
{:type :add-color :color {:id source-color-id :name "Source" :color "#00ff00" :opacity 1}})
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:excluded #{(bm/change-key {:kind :color :id main-id})}})
|
||||
:excluded #{(bm/change-key {:kind :color :id source-color-id})}})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :nothing-to-merge (-> error ex-data :code))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-file-id})]
|
||||
(t/is (not (contains? (-> out :result :data :colors) main-id)))))))))
|
||||
(t/is (not (contains? (-> out :result :data :colors) source-color-id)))))))))
|
||||
|
||||
(t/deftest update-with-exclusion-replays-the-branch-from-its-base
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -3454,23 +3454,23 @@
|
||||
:name "partial-update"}))
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)
|
||||
main-1 (uuid/random)
|
||||
main-2 (uuid/random)
|
||||
own (uuid/random)]
|
||||
source-1 (uuid/random)
|
||||
source-2 (uuid/random)
|
||||
own (uuid/random)]
|
||||
|
||||
;; main advances twice; the branch carries work of its own
|
||||
;; the source advances twice; the branch carries work of its own
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id main-1 :name "M1" :color "#111111" :opacity 1}})
|
||||
{:type :add-color :color {:id source-1 :name "M1" :color "#111111" :opacity 1}})
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id main-2 :name "M2" :color "#222222" :opacity 1}})
|
||||
{:type :add-color :color {:id source-2 :name "M2" :color "#222222" :opacity 1}})
|
||||
(apply-change* profile branch-file-id
|
||||
{:type :add-color :color {:id own :name "Own" :color "#333333" :opacity 1}})
|
||||
|
||||
(t/testing "the update takes main's selected change and keeps the excluded one out"
|
||||
(t/testing "the update takes the source's selected change and keeps the excluded one out"
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:excluded #{(bm/change-key {:kind :color :id main-1})}})]
|
||||
:excluded #{(bm/change-key {:kind :color :id source-1})}})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
|
||||
@ -3480,27 +3480,27 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-file-id})
|
||||
colors (-> out :result :data :colors)]
|
||||
(t/is (contains? colors main-2))
|
||||
(t/is (contains? colors source-2))
|
||||
(t/is (contains? colors own))
|
||||
(t/is (not (contains? colors main-1))))
|
||||
(t/is (not (contains? colors source-1))))
|
||||
|
||||
;; the base moved to main, and main still holds the excluded work
|
||||
;; the base moved to the source, and the source still holds the excluded work
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
mf (th/db-get :file {:id (:id file)})]
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})]
|
||||
(t/is (contains? (-> out :result :data :colors) main-1))))
|
||||
(t/is (contains? (-> out :result :data :colors) source-1))))
|
||||
|
||||
(t/testing "the excluded main work is a branch-side delta over the new base"
|
||||
(t/testing "the excluded source work is a branch-side delta over the new base"
|
||||
;; the branch does not carry it and the base does, so the squashed
|
||||
;; net records the difference as a change of the branch's own
|
||||
(let [diff (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))]
|
||||
(t/is (some #(and (= :color (:kind %))
|
||||
(= main-1 (:id %))
|
||||
(= source-1 (:id %))
|
||||
(= :deleted (:status %)))
|
||||
(:changes diff))))))))
|
||||
|
||||
@ -3584,8 +3584,8 @@
|
||||
(t/is (= :not-found (th/ex-type (:error out))))
|
||||
(t/is (= :branch-not-found (th/ex-code (:error out)))))))))
|
||||
|
||||
(t/deftest merge-and-update-from-main-record-revision-rows
|
||||
;; the revision rows the merge and the update from main write carry
|
||||
(t/deftest merge-and-update-from-source-record-revision-rows
|
||||
;; the revision rows the merge and the update from the source write carry
|
||||
;; their kind, as the save path's do: a kind-filtered read sees them
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -3602,9 +3602,9 @@
|
||||
WHERE file_id = ? AND session_id = ?"
|
||||
file-id session-id])))]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id (uuid/random) :name "Main" :color "#00ff00" :opacity 1}})
|
||||
{:type :add-color :color {:id (uuid/random) :name "Source" :color "#00ff00" :opacity 1}})
|
||||
|
||||
(t/testing "the update from main"
|
||||
(t/testing "the update from the source"
|
||||
(let [session-id (uuid/random)
|
||||
out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
:parent-id uuid/zero :frame-id uuid/zero})}]))
|
||||
|
||||
(defn- setup-review
|
||||
"A file with a rect on main, a branch of it and an open design review of
|
||||
"A source file with a rect, a branch of it and an open design review of
|
||||
the branch. Returns the ids the tests need."
|
||||
[]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
@ -224,7 +224,7 @@
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "on main"
|
||||
:content "on the source"
|
||||
:review-id (:id review)})]
|
||||
(t/is (= :branch-review-not-open (-> out :error ex-data :code))))))
|
||||
|
||||
@ -243,11 +243,11 @@
|
||||
(t/is (= 1 (:people result)))
|
||||
(t/is (= 1 (count (:sessions result))))))))
|
||||
|
||||
(t/deftest merge-moves-the-tasks-and-their-threads-into-main
|
||||
(t/deftest merge-moves-the-tasks-and-their-threads-into-the-source
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ _] nil)]
|
||||
(let [{:keys [author page-id rect-id file branch branch-file-id review]} (setup-review)
|
||||
;; main has a thread of its own already: the moved one must not
|
||||
;; the source has a thread of its own already: the moved one must not
|
||||
;; take its number
|
||||
_ (th/command! {::th/type :create-comment-thread
|
||||
::rpc/profile-id (:id author)
|
||||
@ -255,7 +255,7 @@
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "on main"})
|
||||
:content "on the source"})
|
||||
thread (:result (th/command! {::th/type :create-comment-thread
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id branch-file-id
|
||||
@ -414,7 +414,7 @@
|
||||
(t/testing "a review thread with no task stays on the branch file"
|
||||
(t/is (= branch-file-id (:file-id (th/db-get :comment-thread {:id (:id quiet)})))))
|
||||
|
||||
(t/testing "main lists the moved threads and their tasks only"
|
||||
(t/testing "the source lists the moved threads and their tasks only"
|
||||
(let [threads (:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))
|
||||
@ -675,7 +675,7 @@
|
||||
(t/is (= [(:id @task)] (:task-ids message)))
|
||||
(t/is (empty? (:tasks message))))))))
|
||||
|
||||
(t/deftest the-merge-tells-main-that-its-tasks-changed
|
||||
(t/deftest the-merge-tells-the-source-that-its-tasks-changed
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ _] nil)]
|
||||
(let [{:keys [author page-id rect-id file branch branch-file-id]} (setup-review)
|
||||
@ -742,7 +742,7 @@
|
||||
:obj (cts/setup-shape attrs)}]))
|
||||
|
||||
(defn- setup-board-branch
|
||||
"A file whose main holds a board with a rect inside, and a branch of
|
||||
"A source file holding a board with a rect inside, and a branch of
|
||||
it. Returns the ids the tests need."
|
||||
[]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
@ -772,7 +772,7 @@
|
||||
:branch-file-id (:branch-file-id branch)})))
|
||||
|
||||
(defn- add-promo*
|
||||
"Add on the branch a board with a rect inside, which main lacks.
|
||||
"Add on the branch a board with a rect inside, which the source lacks.
|
||||
Returns their ids."
|
||||
[author branch-file-id page-id]
|
||||
(let [promo-id (uuid/random)
|
||||
@ -802,7 +802,7 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:id task-id})))
|
||||
|
||||
(t/deftest a-carried-task-lands-on-the-layer-its-parent-has-on-main
|
||||
(t/deftest a-carried-task-lands-on-the-layer-its-parent-has-on-the-source
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
(let [{:keys [author file page-id board-id rect-id branch branch-file-id]} (setup-board-branch)
|
||||
task (:result (create-task* author {:file-id branch-file-id
|
||||
@ -852,7 +852,7 @@
|
||||
:page-id page-id
|
||||
:frame-id promo-id
|
||||
:shape-id badge-id}))]
|
||||
;; something else merges: the board of main is renamed
|
||||
;; something else merges: the board of the source is renamed
|
||||
(update-file* author branch-file-id
|
||||
[{:type :mod-obj :page-id page-id :id board-id
|
||||
:operations [{:type :set :attr :name :val "Checkout v2"}]}])
|
||||
@ -920,7 +920,7 @@
|
||||
|
||||
(t/deftest a-resolved-thread-outside-any-review-moves-with-the-merge
|
||||
;; A thread without a review belongs to the file, which the merge
|
||||
;; carries to main: resolved or not, it moves.
|
||||
;; carries to the source: resolved or not, it moves.
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
(let [{:keys [author file page-id branch branch-file-id]} (setup-review)
|
||||
thread (thread* author branch-file-id page-id {:content "settled already"})]
|
||||
@ -975,8 +975,8 @@
|
||||
(ftask/lost-layer-landing {board-id board} nil (gpt/point 5)))))))
|
||||
|
||||
(defn- add-group*
|
||||
"Add on the branch, inside the board `board-id` of main, a group with a
|
||||
rect inside, which main lacks. Returns their ids."
|
||||
"Add on the branch, inside the board `board-id` of the source, a group with a
|
||||
rect inside, which the source lacks. Returns their ids."
|
||||
[author branch-file-id page-id board-id]
|
||||
(let [group-id (uuid/random)
|
||||
badge-id (uuid/random)]
|
||||
@ -998,10 +998,10 @@
|
||||
[{:type :mod-obj :page-id page-id :id board-id
|
||||
:operations [{:type :set :attr :name :val "Checkout v2"}]}]))
|
||||
|
||||
(t/deftest a-mark-in-an-excluded-group-lands-on-the-nearest-ancestor-on-main
|
||||
(t/deftest a-mark-in-an-excluded-group-lands-on-the-nearest-ancestor-on-the-source
|
||||
;; The merge leaves the new group out, and its rect with it. The thread
|
||||
;; and the task on the rect land on the board that holds the group, the
|
||||
;; nearest ancestor main has, not on the group, and keep the name of
|
||||
;; nearest ancestor the source has, not on the group, and keep the name of
|
||||
;; the rect.
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
(let [{:keys [author file page-id board-id branch branch-file-id]} (setup-board-branch)
|
||||
@ -1027,7 +1027,7 @@
|
||||
(t/is (= (:id file) (:file-id row)))
|
||||
(t/is (= board-id (:shape-id row)))
|
||||
(t/is (= "Badge" (:lost-shape-name row))))
|
||||
(t/testing "main lists the thread with the name of its lost layer"
|
||||
(t/testing "the source lists the thread with the name of its lost layer"
|
||||
(let [threads (:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))
|
||||
@ -1058,7 +1058,7 @@
|
||||
(t/is (nil? (:error (merge-excluding* author branch page-id [promo-id]))))
|
||||
(assoc setup :thread thread :task task :badge-id badge-id)))
|
||||
|
||||
(t/deftest a-mark-with-no-ancestor-on-main-lands-on-the-area-and-keeps-the-name
|
||||
(t/deftest a-mark-with-no-ancestor-on-the-source-lands-on-the-area-and-keeps-the-name
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
(let [{:keys [thread task]} (setup-area-landing)]
|
||||
(doseq [id [(:id thread) (:thread-id task)]]
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
(ns app.common.files.branch-merge
|
||||
"Three-way, entity-level merge/diff engine for file branching.
|
||||
|
||||
`compute-merge` takes the file `:data` of the merge base, main and
|
||||
branch and returns a serializable summary of what the branch changes
|
||||
relative to main, plus the set of conflicting entities. It never
|
||||
`compute-merge` takes the file `:data` of the merge base, the source
|
||||
and the branch and returns a serializable summary of what the branch
|
||||
changes relative to the source, plus the set of conflicting entities. It never
|
||||
mutates the blob. `compute-changes` translates the same comparison
|
||||
into `changes` for an actual merge or update, resolved conflicts
|
||||
included. It covers every kind `compute-merge` reports, token kinds
|
||||
@ -48,7 +48,7 @@
|
||||
"Policy chosen for each tree-shape case when none is configured."
|
||||
{:same-parent-reorder :merge
|
||||
:addition-under-deleted-parent :conflict
|
||||
:container-delete-over-main-edits :conflict})
|
||||
:container-delete-over-target-edits :conflict})
|
||||
|
||||
(def policy-values
|
||||
"Allowed alternatives per policy key.
|
||||
@ -72,7 +72,7 @@
|
||||
`:page-root` the addition lands at the page root (the behaviour before
|
||||
the policy).
|
||||
|
||||
`:container-delete-over-main-edits`: the source deleted container F while
|
||||
`:container-delete-over-target-edits`: the source deleted container F while
|
||||
the target modified or added something in F's subtree.
|
||||
`:conflict` a `:delete-modify` conflict on F.
|
||||
`:expand` only what the source deleted goes; the target's additions
|
||||
@ -81,7 +81,7 @@
|
||||
policy)."
|
||||
{:same-parent-reorder #{:merge :refuse :ignore}
|
||||
:addition-under-deleted-parent #{:conflict :refuse :reparent-to-ancestor :page-root}
|
||||
:container-delete-over-main-edits #{:conflict :expand :cascade}})
|
||||
:container-delete-over-target-edits #{:conflict :expand :cascade}})
|
||||
|
||||
(def ^:dynamic *policies*
|
||||
"Effective policies; the engine reads only `(get *policies* k)`."
|
||||
@ -176,7 +176,7 @@
|
||||
|
||||
Classifying on stripped shapes is what prevents FALSE conflicts: both
|
||||
sides adding children to the same frame only differ on `:shapes`, and a
|
||||
library sync on main only flips `:touched` — neither is a user change,
|
||||
library sync on the source only flips `:touched` — neither is a user change,
|
||||
so neither may turn a clean branch edit into a modify-modify/delete
|
||||
conflict. The merge still applies the real values: containment through
|
||||
add/del/move ops, geometry caches piggybacked on the geometry attrs
|
||||
@ -198,7 +198,7 @@
|
||||
`nil` value compares equal to an absent key.
|
||||
|
||||
The three sides reach the comparison by different routes: the base is a
|
||||
stored snapshot, main is its own saved data, and the branch is that base
|
||||
stored snapshot, the source is its own saved data, and the branch is that base
|
||||
with its op log replayed over it. They do not always spell an unset
|
||||
attribute the same way: one side can carry a key like
|
||||
`:fill-color-ref-file` or `:typography-ref-file` with `nil` where another
|
||||
@ -282,18 +282,18 @@
|
||||
(and in-b? (not in-o?) (not in-t?)) ; deleted in both
|
||||
acc
|
||||
|
||||
(and in-b? (not in-o?) (= b t)) ; deleted in branch, main intact
|
||||
(and in-b? (not in-o?) (= b t)) ; deleted in branch, source intact
|
||||
(update acc :changes conj (mk :deleted {:id id :label (entity-label kind t)}))
|
||||
|
||||
(and in-b? (not in-t?) (= b o)) ; deleted in main, branch intact
|
||||
(and in-b? (not in-t?) (= b o)) ; deleted in source, branch intact
|
||||
acc
|
||||
|
||||
(and in-b? (not in-o?) (not= b t)) ; delete (branch) / modify (main)
|
||||
(and in-b? (not in-o?) (not= b t)) ; delete (branch) / modify (source)
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :delete-modify
|
||||
:label (entity-label kind t)
|
||||
:base b :source t :branch nil}))
|
||||
|
||||
(and in-b? (not in-t?) (not= b o)) ; modify (branch) / delete (main)
|
||||
(and in-b? (not in-t?) (not= b o)) ; modify (branch) / delete (source)
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :modify-delete
|
||||
:label (entity-label kind o)
|
||||
:base b :source nil :branch o}))
|
||||
@ -302,7 +302,7 @@
|
||||
(and (not in-b?) in-o? (not in-t?)) ; new in branch
|
||||
(update acc :changes conj (mk :added {:id id :label (entity-label kind o)}))
|
||||
|
||||
(and (not in-b?) in-t? (not in-o?)) ; new in main only
|
||||
(and (not in-b?) in-t? (not in-o?)) ; new in source only
|
||||
acc
|
||||
|
||||
(and (not in-b?) in-o? in-t? (= o t)) ; both added the same
|
||||
@ -315,10 +315,10 @@
|
||||
:base nil :source t :branch o}))
|
||||
|
||||
;; --- present in all three ---
|
||||
(= o b) ; branch didn't touch -> main wins
|
||||
(= o b) ; branch didn't touch -> source wins
|
||||
acc
|
||||
|
||||
(= t b) ; main didn't touch, branch did
|
||||
(= t b) ; source didn't touch, branch did
|
||||
(let [ca (attr-diff t o)]
|
||||
(if (and drop-empty-modified? (map? o) (empty? ca))
|
||||
acc
|
||||
@ -623,7 +623,7 @@
|
||||
"The `:mod-page` attrs for the winning meta map `m` of a page whose
|
||||
target meta is `t`: a clearable attr `m` lacks but `t` still carries is
|
||||
emitted as explicit nil — the value `mod-page` removes on (an absent key
|
||||
would leave main's value in place)."
|
||||
would leave the target's value in place)."
|
||||
[t m]
|
||||
(reduce (fn [acc k]
|
||||
(cond-> acc
|
||||
@ -827,10 +827,11 @@
|
||||
|
||||
The policies name the documents and the engine handles two role
|
||||
shapes: `:lost`, the target deleted a container the source edits
|
||||
inside (main deleted P and the branch added into it, when merging),
|
||||
and `:dropped`, the source deleted a container the target edits into
|
||||
(the branch deleted F while main edited inside it, when merging). A
|
||||
merge maps each policy to its own shape; an update from main swaps the
|
||||
inside (the source file deleted P and the branch added into it, when
|
||||
merging), and `:dropped`, the source deleted a container the target
|
||||
edits into (the branch deleted F while the source file edited inside
|
||||
it, when merging). A merge maps each policy to its own shape; an
|
||||
update from the source file swaps the
|
||||
roles, so each policy drives the other shape through the alternative
|
||||
that means the same thing for the documents.
|
||||
|
||||
@ -848,7 +849,7 @@
|
||||
[dir]
|
||||
(let [update? (= dir :source->branch)
|
||||
add (policy :addition-under-deleted-parent)
|
||||
cont (policy :container-delete-over-main-edits)]
|
||||
cont (policy :container-delete-over-target-edits)]
|
||||
{:order (policy :same-parent-reorder)
|
||||
:lost (if update?
|
||||
(get {:conflict :conflict :expand :reparent-to-ancestor :cascade :cascade}
|
||||
@ -1229,16 +1230,16 @@
|
||||
attrs)))
|
||||
|
||||
(defn- set-rename-attrs
|
||||
"Attrs to rename a set: take branch's name/description but keep MAIN's
|
||||
"Attrs to rename a set: take branch's name/description but keep the SOURCE's
|
||||
tokens — emitted before the per-token pass, which then layers branch's
|
||||
token edits on top. `:set-token-set`/`update-set` relocates the set and
|
||||
updates theme references for the new name."
|
||||
[main-lib branch-lib set-id]
|
||||
[source-lib branch-lib set-id]
|
||||
(let [bs (ctob/get-set branch-lib set-id)]
|
||||
{:id set-id
|
||||
:name (ctob/get-name bs)
|
||||
:description (ctob/get-description bs)
|
||||
:tokens (ctob/get-tokens main-lib set-id)}))
|
||||
:tokens (ctob/get-tokens source-lib set-id)}))
|
||||
|
||||
(defn- set-meta-of
|
||||
[lib set-id]
|
||||
@ -1247,7 +1248,7 @@
|
||||
|
||||
(defn- set-rename-wins?
|
||||
"True when the rename/description change for `sid` is emitted: branch
|
||||
changed the set metadata and either main left it at the base or the
|
||||
changed the set metadata and either the source left it at the base or the
|
||||
resolution takes branch. Those renames run before the set-order moves
|
||||
in the change list, so they settle the names the moves address."
|
||||
[bl ml ol resolutions sid]
|
||||
@ -1507,8 +1508,8 @@
|
||||
|
||||
`:modified-at` is a \"last touched\" stamp refreshed on EVERY apply
|
||||
(`components-list/touch`, `types.library/touch`): diffing it flags
|
||||
spurious `:modified` entries — e.g. an update-from-main restamps the
|
||||
copied entities, making them differ from main forever after — and, when
|
||||
spurious `:modified` entries — e.g. an update-from-source restamps the
|
||||
copied entities, making them differ from the source forever after — and, when
|
||||
both sides edited the same entity, spurious `:modify-modify` conflicts
|
||||
whose only difference is the timestamp. Dropping it is safe because the
|
||||
change pipeline regenerates it on apply anyway."
|
||||
@ -1955,9 +1956,9 @@
|
||||
"The comparison itself. Both arities of `compute-merge` land here rather
|
||||
than one delegating to the other through the var, so that a test which
|
||||
counts engine calls counts comparisons and not dispatches."
|
||||
[base main branch dir only-pages copies?]
|
||||
[base source branch dir only-pages copies?]
|
||||
(let [update? (= dir :source->branch)
|
||||
[theirs ours] (if update? [branch main] [main branch])
|
||||
[theirs ours] (if update? [branch source] [source branch])
|
||||
results [(three-way-entities (strip-modified-at (:colors base))
|
||||
(strip-modified-at (:colors theirs))
|
||||
(strip-modified-at (:colors ours))
|
||||
@ -2022,10 +2023,10 @@
|
||||
copies)))))
|
||||
|
||||
(defn compute-merge
|
||||
"Compute the three-way diff between the merge `base`, `main` and
|
||||
"Compute the three-way diff between the merge `base`, `source` and
|
||||
`branch` file `:data`. Returns:
|
||||
|
||||
{:changes [<change descriptor> ...] ; clean, branch -> main
|
||||
{:changes [<change descriptor> ...] ; clean, branch -> source
|
||||
:conflicts [<conflict descriptor> ...] ; need resolution
|
||||
:stats {:added n :modified n :deleted n :conflicts n}
|
||||
:copies [<component copies> ...]} ; with `:copies? true` only
|
||||
@ -2049,7 +2050,7 @@
|
||||
`ours`-side change and no page outside it can hold a conflict, which
|
||||
needs one. A branch whose op log touches only those pages satisfies
|
||||
that by construction, since its state IS the base plus that log. It is
|
||||
NOT sound for the direction that reports main's changes, and passing it
|
||||
NOT sound for the direction that reports the source's changes, and passing it
|
||||
there would hide them.
|
||||
|
||||
The `:tokens-lib` is diffed as well (`diff-tokens`), so token changes
|
||||
@ -2102,9 +2103,9 @@
|
||||
number of the component's listed copies that follow that shape in a
|
||||
sync group or token slot the conflict's attrs drive: a copy keeping
|
||||
its override there, on either side, does not take the resolution."
|
||||
([base main branch dir] (compute-merge* base main branch dir nil false))
|
||||
([base main branch dir {:keys [only-pages copies?]}]
|
||||
(compute-merge* base main branch dir only-pages (true? copies?))))
|
||||
([base source branch dir] (compute-merge* base source branch dir nil false))
|
||||
([base source branch dir {:keys [only-pages copies?]}]
|
||||
(compute-merge* base source branch dir only-pages (true? copies?))))
|
||||
|
||||
(defn settled?
|
||||
"True for a summary entry that only shows a copy the copy rule settled
|
||||
@ -2164,22 +2165,22 @@
|
||||
;; present in all three
|
||||
(and in-b? in-o? in-t?)
|
||||
(cond (= o b) acc ; branch didn't touch
|
||||
(= t b) (conj acc (mod-fn id o)) ; main didn't touch, branch did
|
||||
(= t b) (conj acc (mod-fn id o)) ; source didn't touch, branch did
|
||||
(= o t) acc ; both reached same value
|
||||
(= res :branch) (conj acc (mod-fn id o)) ; modify/modify -> branch
|
||||
(map? res) (let [eff (merge-attrs t o res)] ; modify/modify -> per-attr
|
||||
(if (= eff t) acc (conj acc (mod-fn id eff))))
|
||||
:else acc)
|
||||
|
||||
;; deleted in branch, still in main
|
||||
;; deleted in branch, still in source
|
||||
(and in-b? (not in-o?) in-t?)
|
||||
(cond (= b t) (conj acc (del-fn id)) ; clean delete
|
||||
(= res :branch) (conj acc (del-fn id)) ; delete/modify -> branch (delete)
|
||||
:else acc)
|
||||
|
||||
;; deleted in main, still in branch
|
||||
;; deleted in source, still in branch
|
||||
(and in-b? in-o? (not in-t?))
|
||||
(cond (= b o) acc ; clean (already gone in main)
|
||||
(cond (= b o) acc ; clean (already gone in source)
|
||||
(= res :branch) (conj acc (add-fn id o)) ; modify/delete -> keep branch
|
||||
:else acc)
|
||||
|
||||
@ -2210,7 +2211,7 @@
|
||||
#{:x :y :width :height :rotation :transform :transform-inverse :flip-x :flip-y})
|
||||
|
||||
(defn- shape-set-ops
|
||||
"`:set` operations for the attrs that differ between the main and branch
|
||||
"`:set` operations for the attrs that differ between the source and branch
|
||||
shape (FULL maps, so geometry caches ride along), excluding the
|
||||
structural ones (see `structural-set-attrs`)."
|
||||
[t o]
|
||||
@ -2242,12 +2243,12 @@
|
||||
|
||||
(defn- page-move-changes
|
||||
"Emit `:mov-objects` for EXISTING shapes the branch reparented to a
|
||||
different container, when the branch wins (main left the shape untouched,
|
||||
different container, when the branch wins (the source left the shape untouched,
|
||||
or the conflict was resolved to `:branch`). Reparenting cannot be applied
|
||||
as a `:set :parent-id` op — that only rewrites the attribute and leaves
|
||||
the shape loose in its old parent, duplicated by file repair.
|
||||
`sbo`/`sto` are the STRIPPED base/main objects (see `strip-shapes`), used
|
||||
for the \"main untouched\" check so derived-attr churn on main does not
|
||||
`sbo`/`sto` are the STRIPPED base/source objects (see `strip-shapes`), used
|
||||
for the \"source untouched\" check so derived-attr churn on the source does not
|
||||
block a branch reparent."
|
||||
[to oo sbo sto resolutions page-id]
|
||||
(->> (keys oo)
|
||||
@ -2256,7 +2257,7 @@
|
||||
o (get oo id)]
|
||||
(when (and (some? t) ; exists on both sides
|
||||
(not= id uuid/zero)
|
||||
(or (= (get sbo id) (get sto id)) ; main untouched -> branch wins
|
||||
(or (= (get sbo id) (get sto id)) ; source untouched -> branch wins
|
||||
(= :branch (attr-side (get resolutions id) :parent-id))))
|
||||
(let [new-parent (:parent-id o)]
|
||||
(when (not= new-parent (:parent-id t)) ; reparented
|
||||
@ -2694,8 +2695,11 @@
|
||||
:unsupported (into #{} refused)}))
|
||||
|
||||
(defn compute-changes
|
||||
"Translate the branch→main merge into a vector of raw change maps
|
||||
applicable to main via `app.common.files.changes/process-changes`.
|
||||
"Translate the merge of `branch` into `source` into a vector of raw
|
||||
change maps applicable to `source` via
|
||||
`app.common.files.changes/process-changes`. An update from the source
|
||||
passes the two the other way round: the branch as `source`, the
|
||||
source file as `branch`, with the resolutions inverted.
|
||||
|
||||
Clean changes are always included. Conflicting entities are included
|
||||
only for those `resolutions` selects `:branch` (the caller must ensure
|
||||
@ -2718,7 +2722,7 @@
|
||||
the change, so the
|
||||
result is exactly what the target has, and a conflicting entity lands
|
||||
there whatever `resolutions` says. Excluding an added shape cascades to
|
||||
every shape the source places under it (its added descendants and any
|
||||
every shape `branch` places under it (its added descendants and any
|
||||
shape it reparented there), so no emitted change can reference a parent
|
||||
the merge does not create; the alternative policy, refusing the
|
||||
exclusion and naming those shapes instead, stays documented and is not
|
||||
@ -2730,17 +2734,17 @@
|
||||
written as one map merged token attr by token attr: the rule's side
|
||||
for the settled ones, the user's side for the open ones
|
||||
(`copy-resolution`). The operations written on a copy never mark an
|
||||
override the source does not have (`copy-touched-ops`). The attrs the
|
||||
override `branch` does not have (`copy-touched-ops`). The attrs the
|
||||
rule leaves at the target's value follow the component through
|
||||
`sync-copies`, which the caller runs after applying these changes."
|
||||
([base main branch]
|
||||
(compute-changes base main branch {}))
|
||||
([base main branch resolutions]
|
||||
(compute-changes base main branch resolutions nil))
|
||||
([base main branch resolutions merge-summary]
|
||||
(compute-changes base main branch resolutions merge-summary nil))
|
||||
([base main branch resolutions merge-summary excluded]
|
||||
(let [merge-summary (or merge-summary (compute-merge base main branch :branch->source))
|
||||
([base source branch]
|
||||
(compute-changes base source branch {}))
|
||||
([base source branch resolutions]
|
||||
(compute-changes base source branch resolutions nil))
|
||||
([base source branch resolutions merge-summary]
|
||||
(compute-changes base source branch resolutions merge-summary nil))
|
||||
([base source branch resolutions merge-summary excluded]
|
||||
(let [merge-summary (or merge-summary (compute-merge base source branch :branch->source))
|
||||
resolutions (or resolutions {})
|
||||
;; a `:settled` entry applies nothing, so excluding it excludes
|
||||
;; nothing: its key names a copy the rule decides whatever the
|
||||
@ -2776,7 +2780,7 @@
|
||||
;; regenerates it via `touch`, so the emitted values may omit it)
|
||||
colors (flat :color {}
|
||||
(strip-modified-at (:colors base))
|
||||
(strip-modified-at (:colors main))
|
||||
(strip-modified-at (:colors source))
|
||||
(strip-modified-at (:colors branch))
|
||||
(fn [_ o] {:type :add-color :color o})
|
||||
(fn [_ o] {:type :mod-color :color o})
|
||||
@ -2784,14 +2788,14 @@
|
||||
|
||||
typos (flat :typography {}
|
||||
(strip-modified-at (:typographies base))
|
||||
(strip-modified-at (:typographies main))
|
||||
(strip-modified-at (:typographies source))
|
||||
(strip-modified-at (:typographies branch))
|
||||
(fn [_ o] {:type :add-typography :typography o})
|
||||
(fn [_ o] {:type :mod-typography :typography o})
|
||||
(fn [id] {:type :del-typography :id id}))
|
||||
|
||||
media (flat :media {}
|
||||
(:media base) (:media main) (:media branch)
|
||||
(:media base) (:media source) (:media branch)
|
||||
(fn [_ o] {:type :add-media :object o})
|
||||
(fn [_ o] {:type :mod-media :object o})
|
||||
(fn [id] {:type :del-media :id id}))
|
||||
@ -2799,7 +2803,7 @@
|
||||
;; file-level plugin-data (flattened to [ns key] -> value)
|
||||
file-plugins (flat :file-plugin {}
|
||||
(flatten-plugin-data (:plugin-data base))
|
||||
(flatten-plugin-data (:plugin-data main))
|
||||
(flatten-plugin-data (:plugin-data source))
|
||||
(flatten-plugin-data (:plugin-data branch))
|
||||
(fn [[ns k] v] {:type :set-plugin-data :object-type :file :namespace ns :key k :value v})
|
||||
(fn [[ns k] v] {:type :set-plugin-data :object-type :file :namespace ns :key k :value v})
|
||||
@ -2808,29 +2812,29 @@
|
||||
;; file options: every side carries every option (`file-options`
|
||||
;; fills the default), so no option is ever added or deleted
|
||||
file-opts (flat :file-option {}
|
||||
(file-options base) (file-options main) (file-options branch)
|
||||
(file-options base) (file-options source) (file-options branch)
|
||||
set-option-change set-option-change (fn [_] nil))
|
||||
|
||||
;; tokens source: always present on every side (nil = self), so
|
||||
;; never added or deleted. The change names the target document.
|
||||
ids (self-ids base main branch)
|
||||
ids (self-ids base source branch)
|
||||
set-source (fn [_ library-id]
|
||||
{:type :set-tokens-source :file-id (:id main) :library-id library-id})
|
||||
{:type :set-tokens-source :file-id (:id source) :library-id library-id})
|
||||
source-changes (flat :tokens-source {}
|
||||
(tokens-source base ids) (tokens-source main ids)
|
||||
(tokens-source base ids) (tokens-source source ids)
|
||||
(tokens-source branch ids)
|
||||
set-source set-source (fn [_] nil))
|
||||
|
||||
;; pages: add (full page incl. objects) / delete + rename (mod-page)
|
||||
bpi (:pages-index base) mpi (:pages-index main) opi (:pages-index branch)
|
||||
bpi (:pages-index base) mpi (:pages-index source) opi (:pages-index branch)
|
||||
bpids (set (keys bpi)) mpids (set (keys mpi)) opids (set (keys opi))
|
||||
common-pages (set/intersection mpids opids)
|
||||
tri-common-pages (set/intersection bpids mpids opids)
|
||||
|
||||
;; presence over page CONTENT (mirrors `diff-pages`): a clean delete
|
||||
;; requires main untouched; a delete conflict resolved to `:branch`
|
||||
;; requires the source untouched; a delete conflict resolved to `:branch`
|
||||
;; either deletes (branch deleted) or RESTORES the full branch page
|
||||
;; via the add-fn (main deleted, branch edited)
|
||||
;; via the add-fn (source deleted, branch edited)
|
||||
page-presence (->> (flat :page {}
|
||||
(page-content-map bpi bpids)
|
||||
(page-content-map mpi mpids)
|
||||
@ -2853,7 +2857,7 @@
|
||||
(mapcat (fn [pid]
|
||||
(flat :page-guide {:page-id pid}
|
||||
(get-in base [:pages-index pid :guides] {})
|
||||
(get-in main [:pages-index pid :guides] {})
|
||||
(get-in source [:pages-index pid :guides] {})
|
||||
(get-in branch [:pages-index pid :guides] {})
|
||||
(fn [gid g] {:type :set-guide :page-id pid :id gid :params g})
|
||||
(fn [gid g] {:type :set-guide :page-id pid :id gid :params g})
|
||||
@ -2863,7 +2867,7 @@
|
||||
(mapcat (fn [pid]
|
||||
(flat :page-flow {:page-id pid}
|
||||
(get-in base [:pages-index pid :flows] {})
|
||||
(get-in main [:pages-index pid :flows] {})
|
||||
(get-in source [:pages-index pid :flows] {})
|
||||
(get-in branch [:pages-index pid :flows] {})
|
||||
(fn [fid f] {:type :set-flow :page-id pid :id fid :params f})
|
||||
(fn [fid f] {:type :set-flow :page-id pid :id fid :params f})
|
||||
@ -2875,7 +2879,7 @@
|
||||
(mapcat (fn [pid]
|
||||
(flat :page-grid {:page-id pid}
|
||||
(get-in base [:pages-index pid :default-grids] {})
|
||||
(get-in main [:pages-index pid :default-grids] {})
|
||||
(get-in source [:pages-index pid :default-grids] {})
|
||||
(get-in branch [:pages-index pid :default-grids] {})
|
||||
(fn [gt p] {:type :set-default-grid :page-id pid :grid-type gt :params p})
|
||||
(fn [gt p] {:type :set-default-grid :page-id pid :grid-type gt :params p})
|
||||
@ -2887,7 +2891,7 @@
|
||||
(mapcat (fn [pid]
|
||||
(flat :page-plugin {:page-id pid}
|
||||
(flatten-plugin-data (get-in base [:pages-index pid :plugin-data] {}))
|
||||
(flatten-plugin-data (get-in main [:pages-index pid :plugin-data] {}))
|
||||
(flatten-plugin-data (get-in source [:pages-index pid :plugin-data] {}))
|
||||
(flatten-plugin-data (get-in branch [:pages-index pid :plugin-data] {}))
|
||||
(fn [[ns k] v] {:type :set-plugin-data :object-type :page :object-id pid :namespace ns :key k :value v})
|
||||
(fn [[ns k] v] {:type :set-plugin-data :object-type :page :object-id pid :namespace ns :key k :value v})
|
||||
@ -2897,11 +2901,11 @@
|
||||
;; page order: reorder the common pages to branch's order via
|
||||
;; mov-page. Every :index counts the FULL :pages vector as it is
|
||||
;; when the op runs: the presence changes above are already in it
|
||||
;; and the moves before it have landed, so a page main added keeps
|
||||
;; and the moves before it have landed, so a page the source added keeps
|
||||
;; its slot while the common pages reorder around it.
|
||||
page-order-changes
|
||||
(let [order-of (fn [data] (filterv tri-common-pages (or (:pages data) [])))
|
||||
bo (order-of base) mo (order-of main) oo (order-of branch)]
|
||||
bo (order-of base) mo (order-of source) oo (order-of branch)]
|
||||
(if (and (not (excl? :page-order {} :page-order))
|
||||
(not= oo bo)
|
||||
(or (= mo bo) (= (get resolutions :page-order) :branch)))
|
||||
@ -2910,7 +2914,7 @@
|
||||
:add-page (:pages (ctpl/add-page {:pages pages} (:page change)))
|
||||
:del-page (:pages (ctpl/delete-page {:pages pages} (:id change)))
|
||||
pages))
|
||||
(vec (or (:pages main) []))
|
||||
(vec (or (:pages source) []))
|
||||
page-presence)
|
||||
;; target: the common pages in branch's order, every
|
||||
;; other page where it already is
|
||||
@ -2942,7 +2946,7 @@
|
||||
;; `page-shape-changes`); its `:unsupported` entries name the
|
||||
;; container a `:refuse` alternative could not place under
|
||||
dir (or (:dir merge-summary) :branch->source)
|
||||
shapes-res (mapv (fn [pid] (page-shape-changes base main branch resolutions pid dir excluded))
|
||||
shapes-res (mapv (fn [pid] (page-shape-changes base source branch resolutions pid dir excluded))
|
||||
common-pages)
|
||||
shapes (into [] (mapcat :changes) shapes-res)
|
||||
|
||||
@ -2951,7 +2955,7 @@
|
||||
;; as a proper del-component so the deletion propagates.
|
||||
components (flat :component {}
|
||||
(strip-modified-at (:components base))
|
||||
(strip-modified-at (:components main))
|
||||
(strip-modified-at (:components source))
|
||||
(strip-modified-at (:components branch))
|
||||
(fn [_ c] (assoc c :type :add-component))
|
||||
(fn [id c] (if (:deleted c)
|
||||
@ -2959,7 +2963,7 @@
|
||||
(assoc c :type :mod-component)))
|
||||
(fn [id] {:type :del-component :id id}))
|
||||
|
||||
bl (:tokens-lib base) ml (:tokens-lib main) ol (:tokens-lib branch)
|
||||
bl (:tokens-lib base) ml (:tokens-lib source) ol (:tokens-lib branch)
|
||||
set-ids (set/union (lib-set-ids bl) (lib-set-ids ml) (lib-set-ids ol))
|
||||
|
||||
;; set add/delete, presence over set CONTENT (mirrors `diff-tokens`):
|
||||
@ -2975,7 +2979,7 @@
|
||||
(fn [sid] {:type :set-token-set :id sid :attrs nil}))
|
||||
(filterv some?))
|
||||
|
||||
;; set rename: take branch name/description, keep main's tokens
|
||||
;; set rename: take branch name/description, keep the source's tokens
|
||||
;; (the per-token pass then layers branch's token edits). Emitted
|
||||
;; before token-vals. An excluded rename leaves the target's name
|
||||
;; standing, so the set-order moves below address that name.
|
||||
@ -3001,18 +3005,18 @@
|
||||
(= o m) m
|
||||
(= (get resolutions k) :branch) o
|
||||
:else m))
|
||||
main-theme-ids (active-theme-ids main)
|
||||
main-set-ids (active-set-ids main)
|
||||
theme-ids (settle (active-theme-ids base) main-theme-ids (active-theme-ids branch)
|
||||
:token-active-themes :active-themes)
|
||||
active-ids (settle (active-set-ids base) main-set-ids (active-set-ids branch)
|
||||
:token-active-sets :active-sets)
|
||||
source-theme-ids (active-theme-ids source)
|
||||
source-set-ids (active-set-ids source)
|
||||
theme-ids (settle (active-theme-ids base) source-theme-ids (active-theme-ids branch)
|
||||
:token-active-themes :active-themes)
|
||||
active-ids (settle (active-set-ids base) source-set-ids (active-set-ids branch)
|
||||
:token-active-sets :active-sets)
|
||||
active-changes
|
||||
(if (and (= theme-ids main-theme-ids) (= active-ids main-set-ids))
|
||||
(if (and (= theme-ids source-theme-ids) (= active-ids source-set-ids))
|
||||
[]
|
||||
[{:type :set-tokens-status :theme-ids theme-ids :set-ids active-ids}])
|
||||
|
||||
;; set order: reorder main's common sets to branch's order using
|
||||
;; set order: reorder the source's common sets to branch's order using
|
||||
;; "move nᵢ before nᵢ₊₁" right-to-left. Emitted after renames so set
|
||||
;; names are settled.
|
||||
set-order-changes
|
||||
@ -3023,8 +3027,8 @@
|
||||
(not= oo bo)
|
||||
(or (= mo bo) (= (get resolutions :token-set-order) :branch)))
|
||||
;; the moves address the sets by name as the renames above
|
||||
;; leave them: branch's name where the rename wins, main's
|
||||
;; where main's rename stands
|
||||
;; leave them: branch's name where the rename wins, the source's
|
||||
;; where the source's rename stands
|
||||
(let [names (mapv (fn [sid]
|
||||
(ctob/get-name
|
||||
(ctob/get-set (if (rename-wins? sid) ol ml) sid)))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user