diff --git a/backend/dev/branch_merge_cases.clj b/backend/dev/branch_merge_cases.clj index ce82d4724c..4036ae8deb 100644 --- a/backend/dev/branch_merge_cases.clj +++ b/backend/dev/branch_merge_cases.clj @@ -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) diff --git a/backend/resources/app/branch-merge-policies.edn b/backend/resources/app/branch-merge-policies.edn index 3f27381b16..5a357c3c59 100644 --- a/backend/resources/app/branch-merge-policies.edn +++ b/backend/resources/app/branch-merge-policies.edn @@ -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} diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index e257cc0882..f7dd851bfd 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -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 diff --git a/backend/src/app/features/file_snapshots.clj b/backend/src/app/features/file_snapshots.clj index 78897dcdf2..82ecac5445 100644 --- a/backend/src/app/features/file_snapshots.clj +++ b/backend/src/app/features/file_snapshots.clj @@ -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! diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 23bc1b46bc..2a5d3a9feb 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -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 diff --git a/backend/src/app/rpc/commands/files_branch.clj b/backend/src/app/rpc/commands/files_branch.clj index 441d0f4ca1..5b9fbf6522 100644 --- a/backend/src/app/rpc/commands/files_branch.clj +++ b/backend/src/app/rpc/commands/files_branch.clj @@ -6,11 +6,11 @@ (ns app.rpc.commands.files-branch "RPC commands for file branching: create a branch of a file linked to - its source file (\"main\"), list branches, diff a branch against main, - merge a branch into main (with conflict resolutions), and update a - branch from main. A branch is a file row with no data of its own: its - state is derived from a pinned base snapshot of main plus the branch's - op log (`app.binfile.common/branch-file-data`). See + its source file, list branches, diff a branch against its source, + merge a branch into its source (with conflict resolutions), and update + a branch from its source. A branch is a file row with no data of its + own: its state is derived from a pinned base snapshot of the source + plus the branch's op log (`app.binfile.common/branch-file-data`). See `app.rpc.commands.files-snapshot` for the patterns this namespace mirrors." (:require @@ -187,12 +187,13 @@ ;; --- Helpers: media pairing ;; ;; A branch copies no media at creation: the content it inherits from its -;; base references main's file_media_object rows. Rows cross between the -;; two files only as copies under FRESH ids (`copy-media-rows!`): an update -;; from main copies the media main added into the branch, and a merge -;; copies the media the branch added into main. So the same image can -;; carry a different id on each side. Before diffing or merging, the -;; branch-side media ids must be normalized back to the target's ids +;; base references the source's file_media_object rows. Rows cross between +;; the two files only as copies under FRESH ids (`copy-media-rows!`): an +;; update from the source copies the media the source added into the +;; branch, and a merge copies the media the branch added into the source. +;; So the same image can carry a different id on each side. Before +;; diffing or merging, the branch-side media ids must be normalized back +;; to the target's ids ;; (together with the file id, via `bm/remap-refs`); otherwise every image ;; looks changed, and merged shapes would reference media rows owned by the ;; branch file — which break when the branch is deleted and GC'd. @@ -207,8 +208,8 @@ "{from-media-id -> to-media-id} for the file_media_object rows present on both files with the same content identity (storage object + name + dimensions + mtype), such as the rows one file received as a copy of - the other's (`copy-media-rows!`, run by an update from main or a merge). - Rows with several identical copies are paired positionally (they are + the other's (`copy-media-rows!`, run by an update from the source or a + merge). Rows with several identical copies are paired positionally (they are interchangeable). Media added on one side stays unpaired." [cfg from-file-id to-file-id] (let [ident (juxt :media-id :name :width :height :mtype) @@ -290,39 +291,41 @@ ;; --- Helpers: merge base snapshot -(defn- read-main-for-write - "Read main for a command that writes a snapshot naming main's fragments - or persists main itself. Returns `[stored file]`: `stored` keeps main's - fragment pointers, and `file` is the same document realized and - checked against the size limits. +(defn- read-source-for-write + "Read the source for a command that writes a snapshot naming the + source's fragments or persists the source itself. Returns `[stored + file]`: `stored` keeps the source's fragment pointers, and `file` is + the same document realized and checked against the size limits. The row is read FOR UPDATE, since a data read cannot take FOR SHARE. File-gc takes it FOR UPDATE too and marks every fragment that neither - main nor a committed snapshot names, so a snapshot that copies main's - pointers must commit before the next pass can read the row." - [cfg main-id operation] - (let [stored (bfc/get-file cfg main-id :lock-for-update? true) + the source nor a committed snapshot names, so a snapshot that copies + the source's pointers must commit before the next pass can read the + row." + [cfg source-id operation] + (let [stored (bfc/get-file cfg source-id :lock-for-update? true) file (-> (fdata/realize cfg stored) (check-file-size-limits! operation))] [stored file])) -(defn- reattach-main-pointers - "`file` with main's stored fragment pointers put back on every page - whose value still equals main's, so a base or a merged main shares - those fragments instead of writing copies, and an unchanged page keeps - its fragment id. `stored` is the first value `read-main-for-write` - returns." - [cfg main-id stored file] - (fdata/with-pointers cfg main-id +(defn- reattach-source-pointers + "`file` with the source's stored fragment pointers put back on every + page whose value still equals the source's, so a base or a merged + source shares those fragments instead of writing copies, and an + unchanged page keeps its fragment id. `stored` is the first value + `read-source-for-write` returns." + [cfg source-id stored file] + (fdata/with-pointers cfg source-id (fdata/reattach-unchanged (fdata/original-pointers (:data stored)) file))) (defn- get-base-data "The merge-base `:data` from the branch's base snapshot, migrated to the current data version (`bfc/migrate-branch-base`): `bfc/get-file` - migrates main and the branch on read, and a base left at an older + migrates the source and the branch on read, and a base left at an older version reads as a change on every side that migrated. Raises when the - snapshot cannot be resolved: silently falling back to main would degrade - the three-way merge into \"branch overwrites main\" without conflicts. + snapshot cannot be resolved: silently falling back to the source would + degrade the three-way merge into \"branch overwrites source\" without + conflicts. Prefer `branch-base-data` where the branch file was read with `:include-base-data? true`: the derive decoded the merge base to replay @@ -331,8 +334,9 @@ The snapshot stores the branch's id space — its media references name the branch's own paired rows, what the replay reproduces — while a - comparison runs in main's id space, so the media ids are normalized - back here through the pairs, the way `branch-id-map` normalizes the + comparison runs in the source's id space, so the media ids are + normalized back here through the pairs, the way `branch-id-map` + normalizes the branch's own data." [cfg {:keys [source-file-id branch-file-id base-snapshot-id] :as branch}] (when-not base-snapshot-id @@ -357,8 +361,8 @@ nil. Like `get-base-data`, it comes back with the media ids normalized into - main's id space: the snapshot names the branch's own paired rows, the - comparison runs against main's." + the source's id space: the snapshot names the branch's own paired rows, + the comparison runs against the source's." [cfg source-file-id {:keys [id] :as branch-file}] (-> (or (::bfc/base-data branch-file) (ex/raise :type :assertion @@ -367,33 +371,34 @@ (bm/remap-refs (branch-media-pairs cfg id source-file-id)))) (defn- moved-pages - "The pages on which main can differ from a branch's base: every page - whose fragment main does not share with the base. Nil when that set - cannot bound a comparison, which leaves the whole-file comparison in - place: main or the base holds no pointers, or main ordered the pages - both hold differently from the base. The page order lives in the - document root rather than in a page's fragment, and a bounded - comparison only orders the pages it covers. `stored` is main's `:data` - with its pointers unrealized, `base` the comparison's base, and + "The pages on which the source can differ from a branch's base: every + page whose fragment the source does not share with the base. Nil when + that set cannot bound a comparison, which leaves the whole-file + comparison in place: the source or the base holds no pointers, or the + source ordered the pages both hold differently from the base. The + page order lives in the document root rather than in a page's + fragment, and a bounded comparison only orders the pages it covers. + `stored` is the source's `:data` with its pointers unrealized, `base` + the comparison's base, and `base-ids` the `::bfc/base-page-pointers` of the branch read." [stored base base-ids] (when (seq base-ids) - (let [main-ids (fdata/get-page-pointer-ids stored) - both (set/intersection (set (:pages stored)) (set (:pages base)))] - (when (and (seq main-ids) + (let [source-ids (fdata/get-page-pointer-ids stored) + both (set/intersection (set (:pages stored)) (set (:pages base)))] + (when (and (seq source-ids) (= (filterv both (:pages stored)) (filterv both (:pages base)))) (into #{} (remove (fn [page-id] - (let [id (get main-ids page-id)] + (let [id (get source-ids page-id)] (and (some? id) (= id (get base-ids page-id)))))) (into (set (keys (:pages-index stored))) (keys base-ids))))))) -(defn- comparison-main - "Main realized for a comparison with a branch, and the pages main moved - since the branch's base (`moved-pages`). Only the moved pages load: - every other page holds the same document as the base's, so the base's - page, which the derive already realized, stands in for it. `base-data` - is the comparison's base, in main's id space." +(defn- comparison-source + "The source realized for a comparison with a branch, and the pages the + source moved since the branch's base (`moved-pages`). Only the moved + pages load: every other page holds the same document as the base's, so + the base's page, which the derive already realized, stands in for it. + `base-data` is the comparison's base, in the source's id space." [cfg source-file-id branch-file base-data] (let [stored (bfc/get-file cfg source-file-id) moved (moved-pages (:data stored) base-data (::bfc/base-page-pointers branch-file)) @@ -656,14 +661,14 @@ (fn [{:keys [::db/conn] :as cfg}] (db/exec-one! conn ["SET CONSTRAINTS ALL DEFERRED"]) - ;; Serialize against concurrent update-file on main - ;; (same advisory lock) so the base snapshot and the - ;; branch's initial state (the empty op log over that - ;; base) are taken from the SAME state of main. + ;; Serialize against concurrent update-file on the + ;; source (same advisory lock) so the base snapshot and + ;; the branch's initial state (the empty op log over + ;; that base) are taken from the SAME state of the source. ;; ;; The family id is locked too: the quota counts the ;; whole family, and two creators cutting from two files - ;; of it (main and a child of main) would otherwise take + ;; of it (the root and a branch of it) would otherwise take ;; two different locks and both pass the quota for the ;; last slot. Sorted, as `merge-file-branch` takes its ;; two, to avoid deadlocks. The family id is the root @@ -688,12 +693,12 @@ (quotes/check! {::quotes/id ::quotes/branches-per-file} {::quotes/id ::quotes/branches-per-team})) - ;; 1. Pin the merge base: a system snapshot of main, + ;; 1. Pin the merge base: a system snapshot of the source, ;; kept long-lived so it is not pruned by the snapshot ;; GC while the branch is open (it is released when the ;; branch is deleted or its base moves). The snapshot - ;; stores main's fragment pointers, not its pages, so - ;; main's row is read FOR UPDATE: file-gc takes it FOR + ;; stores the source's fragment pointers, not its pages, + ;; so the source's row is read FOR UPDATE: file-gc takes it FOR ;; UPDATE as well, and a pass that ran between this read ;; and the commit could mark a fragment the base names. (let [file (bfc/get-file cfg file-id :lock-for-update? true) @@ -709,7 +714,7 @@ branch-id (uuid/next) ;; 2. Create the branch file: an empty file row - ;; carrying main's project, features and data + ;; carrying the source's project, features and data ;; version. No data, no media, no library copy: ;; the read path derives the state. branch-file @@ -731,7 +736,7 @@ ;; a family of its own, which goes once it is empty). ;; No file role is granted: a branch takes its ;; permissions from the team (and project) roles - ;; alone, so every editor of main can open and edit + ;; alone, so every editor of the source can open and edit ;; it, and its creator gets no extra rights. (db/update! conn :file {:is-branch true @@ -740,7 +745,7 @@ {::db/return-keys false}) ;; 4. The branch resolves libraries exactly like - ;; main (component instances from shared libraries + ;; the source (component instances from shared libraries ;; must keep resolving on the derived state). (doseq [rel (bfc/get-files-rels cfg #{file-id})] (let [rel-params (-> rel @@ -885,22 +890,23 @@ (defn branch-diff-counts! "Entity-level `[ahead behind conflicts]` change counts between a branch - file and its source (main) — the same numbers the compare dialog lists + file and its source — the same numbers the compare dialog lists (root-frame churn and structural noise filtered out). The revn deltas are used only as a cheap gate to skip the (expensive) 3-way diff when a - side hasn't moved. `main-data` may be pre-realized and shared across + side hasn't moved. `source-data` may be pre-realized and shared across branches of the same source; otherwise it is loaded on demand. The forward pass is bounded to the pages the branch's op log touched when that set is complete (`branch-affected-pages`), and the reverse - pass, which reports MAIN's changes, to the pages whose fragment main no - longer shares with the base (`moved-pages`). Without a shared - `main-data`, main loads only those pages (`comparison-main`). + pass, which reports the SOURCE's changes, to the pages whose fragment + the source no longer shares with the base (`moved-pages`). Without a + shared `source-data`, the source loads only those pages + (`comparison-source`). Raises on failure instead of degrading: the caller decides whether the result is worth caching, and a value computed from an error must never enter the summary cache." - [cfg main-data {:keys [source-file-id branch-file-id ahead-revn behind-revn]}] + [cfg source-data {:keys [source-file-id branch-file-id ahead-revn behind-revn]}] (bp/with-policies (if (and (zero? ahead-revn) (zero? behind-revn)) [0 0 0] @@ -914,27 +920,27 @@ (branch-id-map cfg branch-file-id source-file-id)) base-data (branch-base-data cfg source-file-id branch-file) base-ids (::bfc/base-page-pointers branch-file) - [main-data moved] + [source-data moved] (cond - (nil? main-data) - (let [[file moved] (comparison-main cfg source-file-id branch-file base-data)] + (nil? source-data) + (let [[file moved] (comparison-source cfg source-file-id branch-file base-data)] [(:data file) moved]) ;; the stored document is a handful of pointers, read only ;; when the base holds pointers to compare them with (seq base-ids) - [main-data (moved-pages (:data (bfc/get-file cfg source-file-id)) base-data base-ids)] + [source-data (moved-pages (:data (bfc/get-file cfg source-file-id)) base-data base-ids)] :else - [main-data nil]) + [source-data nil]) clean-count (fn [m] (let [s (:stats m)] (+ (:added s) (:modified s) (:deleted s)))) fwd (when (pos? ahead-revn) - (bm/compute-merge base-data main-data branch-data :branch->source + (bm/compute-merge base-data source-data branch-data :branch->source (when-let [pages (branch-affected-pages cfg branch-file-id)] {:only-pages pages}))) bwd (when (pos? behind-revn) - (bm/compute-merge base-data branch-data main-data :branch->source + (bm/compute-merge base-data branch-data source-data :branch->source (when moved {:only-pages moved})))] [(if fwd (clean-count fwd) 0) (if bwd (clean-count bwd) 0) @@ -968,9 +974,9 @@ (defn cached-summary "The cached summary of a branch row, or nil when it would have to be - computed. Public because a listing decides whether to realize main - before it pays for it, and a listing whose rows are all cached needs no - main at all." + computed. Public because a listing decides whether to realize the + source before it pays for it, and a listing whose rows are all cached + needs no source at all." [row] (bp/with-policies (ucache/get branch-summary-cache (summary-cache-key row)))) @@ -988,16 +994,16 @@ error never enters the cache. `branch` carries the key tuple and the pair being compared, with - `source-file-id` naming main and `branch-file-id` the branch, whichever + `source-file-id` naming the source and `branch-file-id` the branch, whichever listing is asking." - [cfg main-data branch] + [cfg source-data branch] (bp/with-policies (let [[ahead-revn behind-revn] (revn-deltas branch)] (try (ucache/get branch-summary-cache (summary-cache-key branch) (fn [_] - (branch-diff-counts! cfg main-data + (branch-diff-counts! cfg source-data (assoc branch :ahead-revn ahead-revn :behind-revn behind-revn)))) @@ -1011,7 +1017,7 @@ (sv/defmethod ::get-file-branches "List the branches of a file. `ahead`/`behind` are entity-level change counts (matching the compare dialog), gated by the cheap revn deltas so - in-sync branches skip the diff entirely; `main` is realized once and + in-sync branches skip the diff entirely; the source is realized once and shared across branches. A row whose comparison cannot be made carries `:diff-error true` and no @@ -1049,36 +1055,36 @@ ;; only OPEN branches get diff counts: merged/archived ones ;; are not going to be merged as-is, so the expensive diff ;; would be wasted work (and their base may be released) - open? (fn [row] (= "open" (:status row))) + open? (fn [row] (= "open" (:status row))) ;; an open branch whose cheap revn deltas say it diverged is ;; the only one the listing looks a comparison up for - diverged? (fn [row] (let [[a b] (revn-deltas row)] (or (pos? a) (pos? b)))) - compared (filterv (fn [row] (and (open? row) (diverged? row))) rows) + diverged? (fn [row] (let [[a b] (revn-deltas row)] (or (pos? a) (pos? b)))) + compared (filterv (fn [row] (and (open? row) (diverged? row))) rows) ;; the rows the summary cache answers without computing - cached (filterv (comp some? cached-summary) compared) - ;; realize main once, only if some compared branch is not + cached (filterv (comp some? cached-summary) compared) + ;; realize the source once, only if some compared branch is not ;; already cached - need? (< (count cached) (count compared)) - main-data (when need? - (db/run! cfg (fn [cfg] (:data (bfc/get-file cfg file-id :realize? true))))) - branches (mapv (fn [row] - (let [counts (if (open? row) - ;; a cached summary answers without - ;; touching the database; anything - ;; else compares on a connection of - ;; its own, taken and returned around - ;; the comparison - (or (cached-summary row) - (db/run! cfg (fn [cfg] (cached-diff-counts cfg main-data row)))) - [0 0 0]) - [ahead behind conflicts] counts] - (cond-> (-> row - (assoc :ahead ahead :behind behind :conflicts conflicts) - (dissoc :branch-revn :source-revn :base-snapshot-id :base-branch-revn)) - ;; the comparison could not be made: the - ;; marker stands where the counts would be - (nil? counts) (assoc :diff-error true)))) - rows)] + need? (< (count cached) (count compared)) + source-data (when need? + (db/run! cfg (fn [cfg] (:data (bfc/get-file cfg file-id :realize? true))))) + branches (mapv (fn [row] + (let [counts (if (open? row) + ;; a cached summary answers without + ;; touching the database; anything + ;; else compares on a connection of + ;; its own, taken and returned around + ;; the comparison + (or (cached-summary row) + (db/run! cfg (fn [cfg] (cached-diff-counts cfg source-data row)))) + [0 0 0]) + [ahead behind conflicts] counts] + (cond-> (-> row + (assoc :ahead ahead :behind behind :conflicts conflicts) + (dissoc :branch-revn :source-revn :base-snapshot-id :base-branch-revn)) + ;; the comparison could not be made: the + ;; marker stands where the counts would be + (nil? counts) (assoc :diff-error true)))) + rows)] (audited branches tpoint :list-branches {:branches-compared (count compared) :branches-cached (count cached)}))) @@ -1100,7 +1106,7 @@ produced by `branch-merge/compute-merge` (stats, changes, conflicts). The base is read at the current data version, the version `bfc/get-file` - reads main and the branch at (`bfc/migrate-branch-base`), so a Penpot + reads the source and the branch at (`bfc/migrate-branch-base`), so a Penpot upgrade since the branch was cut does not read as a change on any side." {::doc/added "2.16" ::sm/params schema:get-file-branch-diff @@ -1127,13 +1133,13 @@ branch-file (bfc/get-file cfg (:branch-file-id branch) :realize? true :include-base-data? true) base-data (branch-base-data cfg (:source-file-id branch) branch-file) - ;; the size gate runs after the derive: main loads only the + ;; the size gate runs after the derive: the source loads only the ;; pages it moved since the base, so the base is needed first, ;; and the derive's own cost is bounded by the gates the base ;; passed when it was written - [main-file moved] (comparison-main cfg (:source-file-id branch) branch-file base-data) - _ (check-file-size-limits! main-file :compare) - main-data (:data main-file) + [source-file moved] (comparison-source cfg (:source-file-id branch) branch-file base-data) + _ (check-file-size-limits! source-file :compare) + source-data (:data source-file) branch-data (bm/remap-refs (:data branch-file) (branch-id-map cfg (:branch-file-id branch) (:source-file-id branch))) @@ -1146,7 +1152,7 @@ ::db/remove-deleted false})) ;; each direction is bounded to the pages the side it reports ;; can have changed: the branch's to the pages its log - ;; touched, main's to the pages whose fragment it no longer + ;; touched, the source's to the pages whose fragment it no longer ;; shares with the base opts (if (= dir :branch->source) (when-let [pages (affected-pages log)] @@ -1159,11 +1165,11 @@ ;; `:source-revn` so the client can do optimistic concurrency on merge ;; (`expected-source-revn`). The last editor's identity is intentionally ;; omitted: files do not store a reliable "modified-by". - (-> (bm/compute-merge base-data main-data branch-data dir (assoc opts :copies? true)) + (-> (bm/compute-merge base-data source-data branch-data dir (assoc opts :copies? true)) (assoc :meta {:base-at base-at - :source-at (:modified-at main-file) + :source-at (:modified-at source-file) :branch-at (:modified-at branch-file) - :source-revn (:revn main-file)}) + :source-revn (:revn source-file)}) (audited tpoint :compare)))))) ;; --- Helpers: post-commit notification @@ -1200,10 +1206,10 @@ [:excluded {:optional true} [::sm/set :string]] [:expected-source-revn {:optional true} ::sm/int] ;; what the user says about the merge; kept in its record - ;; (`file_branch_merge`), shown in the list of merges of main + ;; (`file_branch_merge`), shown in the list of merges of the source [:comment {:optional true} [:string {:max 4000}]] ;; tell the assignees of the open tasks of the branch, by email, that - ;; the merge moved their tasks into main + ;; the merge moved their tasks into the source [:notify-assignees {:optional true} ::sm/boolean]]) (sv/defmethod ::merge-file-branch @@ -1216,14 +1222,14 @@ merges the side its resolution picks, per entity or per attr. Change kinds the engine cannot translate (`bm/unsupported-kinds`) make it return `{:status :unsupported}` so no change is silently dropped. Otherwise it - takes a safety snapshot of main, applies the merge to main through the + takes a safety snapshot of the source, applies the merge to the source through the production change pipeline, records the merge with its `comment` (`file_branch_merge`), deletes the branch and its file and notifies open clients via msgbus. Copies follow the merged components: a copy attr no side overrode is no conflict, and after the merge (and its repair) applies, the copies - of every local component whose main it changed are synced on main + of every local component whose main it changed are synced on the source (`bm/sync-copies`). The sync changes go into the same `file_change` row and the same validation as the merge." {::doc/added "2.16" @@ -1247,11 +1253,11 @@ :branch-id branch-id)) (let [tpoint (ct/tpoint) - main-id (:source-file-id branch) + source-id (:source-file-id branch) branch-file-id (:branch-file-id branch) messages (volatile! [])] - ;; Only editors of main can integrate (same rule as Figma). - (files/check-edition-permissions! cfg profile-id main-id) + ;; Only editors of the source can integrate (same rule as Figma). + (files/check-edition-permissions! cfg profile-id source-id) (tx-run-notify! cfg @@ -1263,7 +1269,7 @@ ;; to avoid deadlocks): without the branch lock, edits saved to ;; the branch while the merge runs would be silently lost when ;; the branch is marked merged and deleted below. - (run! (partial db/xact-lock! conn) (sort [main-id branch-file-id])) + (run! (partial db/xact-lock! conn) (sort [source-id branch-file-id])) ;; the row read before the lock is stale by now: a competing ;; merge, delete or archive may have committed while these @@ -1279,35 +1285,35 @@ :branch-id branch-id)) ;; a merge into a branch needs that branch open: an ;; archived target is set aside (`:branch-stacking`) - _ (check-source-open conn main-id) - [main-stored main-file] (read-main-for-write cfg main-id :merge) + _ (check-source-open conn source-id) + [source-stored source-file] (read-source-for-write cfg source-id :merge) _ (check-oplog-depth-limit! (bfc/get-branch-oplog-depth cfg branch-file-id) branch-file-id :merge) branch-file (bfc/get-file cfg branch-file-id :realize? true :include-base-data? true) - base-data (branch-base-data cfg main-id branch-file) + base-data (branch-base-data cfg source-id branch-file) - ;; canonicalize the branch's local refs to main's ids: the + ;; canonicalize the branch's local refs to the source's ids: the ;; branch file id (components, library color/typography ;; refs) and the paired media ids; media ADDED on the ;; branch gets fresh ids pre-allocated here — the rows are - ;; copied into main only if the merge actually applies. - pairs (branch-media-pairs cfg branch-file-id main-id) + ;; copied into the source only if the merge actually applies. + pairs (branch-media-pairs cfg branch-file-id source-id) new-media (unpaired-media-rows cfg branch-file-id (:data branch-file) pairs) fresh-map (into {} (map (fn [row] [(:id row) (uuid/next)])) new-media) id-map (-> pairs (merge fresh-map) - (assoc branch-file-id main-id)) + (assoc branch-file-id source-id)) branch-data (bm/remap-refs (:data branch-file) id-map)] (when (and (some? expected-source-revn) - (not= expected-source-revn (:revn main-file))) + (not= expected-source-revn (:revn source-file))) (ex/raise :type :conflict :code :file-modified - :hint "main was modified, recompute the diff and retry")) + :hint "source was modified, recompute the diff and retry")) - (let [merge-summary (bm/compute-merge base-data (:data main-file) + (let [merge-summary (bm/compute-merge base-data (:data source-file) branch-data :branch->source ;; `:copies` for the conflict dialog {:copies? true}) @@ -1339,12 +1345,12 @@ :comment comment :created-at ts}) ;; the threads with an open task, and those - ;; written outside any review, move to main + ;; written outside any review, move to the source ;; with their tasks (on the layer the merge ;; left them); the other review threads stay ;; with the branch as the record of its review moved (ftask/move-branch-tasks cfg {:branch-file-id branch-file-id - :target-id main-id + :target-id source-id :merge-id merge-id :branch-name (:name branch) :profile-id profile-id @@ -1352,18 +1358,18 @@ :merged-data merged-data :branch-data branch-data :base-data base-data})] - ;; main's open clients patch their task list + ;; the source's open clients patch their task list (when (seq moved) (vswap! messages conj - {:topic main-id + {:topic source-id :message (ftask/tasks-change-message - conn {:file-id main-id + conn {:file-id source-id :profile-id profile-id :session-id session-id :task-ids (map :id moved)})}))) ;; the open branches cut from this one follow it into ;; the target (`:branch-stacking`) - (reparent-child-branches conn branch-file-id main-id) + (reparent-child-branches conn branch-file-id source-id) (db/update! conn :file-branch {:status "merged" :merged-at ts @@ -1384,12 +1390,12 @@ ;; `:copies` tells the conflict dialog which copies the ;; integration syncs (`bm/compute-merge`) (audited {:status :conflicts :conflicts conflicts :copies (:copies merge-summary) - :source-revn (:revn main-file)} + :source-revn (:revn source-file)} tpoint :merge) :else (let [{:keys [changes unsupported]} - (bm/compute-changes base-data (:data main-file) branch-data + (bm/compute-changes base-data (:data source-file) branch-data (or resolutions {}) merge-summary excluded)] @@ -1406,35 +1412,35 @@ tpoint :merge) (empty? changes) - ;; Nothing to integrate (branch matches main): close the - ;; branch without touching main. + ;; Nothing to integrate (branch matches the source): + ;; close the branch without touching the source. (let [ts (ct/now)] - (finish-branch! ts (:data main-file)) - (audited {:status :merged :revn (:revn main-file) :source-file-id main-id} + (finish-branch! ts (:data source-file)) + (audited {:status :merged :revn (:revn source-file) :source-file-id source-id} tpoint :merge)) :else - (let [team (teams/get-team conn :profile-id profile-id :file-id main-id) + (let [team (teams/get-team conn :profile-id profile-id :file-id source-id) delay (ldel/get-deletion-delay team) ts (ct/now)] - (fdata/with-tracked-pointers cfg main-id - (binding [cfeat/*current* (:features main-file) - cfeat/*previous* (:features main-file)] + (fdata/with-tracked-pointers cfg source-id + (binding [cfeat/*current* (:features source-file) + cfeat/*previous* (:features source-file)] - ;; Safety snapshot of pre-merge main (rollback via - ;; versions). It names main's fragments rather than - ;; copying its pages. - (fsnap/create! cfg main-stored + ;; Safety snapshot of the pre-merge source (rollback + ;; via versions). It names the source's fragments + ;; rather than copying its pages. + (fsnap/create! cfg source-stored {:label (str "pre-merge/" (:name branch)) :created-by "system" :deleted-at (ct/in-future delay) :profile-id profile-id}) - ;; media added on the branch: copy its rows into main + ;; media added on the branch: copy its rows into the source ;; under the pre-allocated ids the changes reference - (copy-media-rows! conn main-id fresh-map new-media) + (copy-media-rows! conn source-id fresh-map new-media) - (let [applied (-> main-file + (let [applied (-> source-file (update :revn inc) (update :data #(cpc/process-changes % changes))) libs (bfc/get-resolved-file-libraries cfg applied) @@ -1452,8 +1458,8 @@ ;; synced, as the workspace syncs them after ;; an edit (`bm/sync-copies`) {synced :data sync :changes} - (bm/sync-copies main-id (:data merged) - (into (bm/changed-components (:data main-file) changes) + (bm/sync-copies source-id (:data merged) + (into (bm/changed-components (:data source-file) changes) (bm/changed-components (:data applied) repair))) merged (assoc merged :data synced) libs (if (seq sync) @@ -1482,7 +1488,7 @@ :created-at ts :updated-at ts :deleted-at (ct/in-future {:hours 1}) - :file-id main-id + :file-id source-id :revn (:revn merged) :version (:version merged) :features (into-array (:features merged)) @@ -1492,14 +1498,14 @@ {::db/return-keys false}) (let [all-changes (-> (vec changes) (into repair) (into sync))] - (if (:is-branch main-file) + (if (:is-branch source-file) ;; a target that is itself a branch ;; (`:branch-stacking`) stores no data (persist-merge-into-branch cfg merged ts all-changes) ;; a page the merge left as it was keeps its ;; fragment instead of being written again (fupd/persist-file! (assoc cfg ::fupd/timestamp ts) - (reattach-main-pointers cfg main-id main-stored merged)))) + (reattach-source-pointers cfg source-id source-stored merged)))) (when (contains? cf/flags :redis-cache) (fupd/invalidate-caches! cfg merged)) @@ -1507,13 +1513,13 @@ (finish-branch! ts (:data merged)) (vswap! messages conj - {:topic main-id + {:topic source-id :message {:type :file-merged - :file-id main-id + :file-id source-id :session-id session-id :revn (:revn merged)}}) - (audited {:status :merged :revn (:revn merged) :source-file-id main-id} + (audited {:status :merged :revn (:revn merged) :source-file-id source-id} tpoint :merge)))))))))))))))) ;; --- COMMAND: update-file-branch-from-source @@ -1525,26 +1531,26 @@ ;; branch) | {attr -> side} (per-attr) [:resolutions {:optional true} [:map-of :any [:or [:enum :source :branch] [:map-of :keyword [:enum :source :branch]]]]] ;; the compare panel's per-change selection as a set of change keys - ;; (`app.common.files.branch-merge/change-key`): main's changes the user + ;; (`app.common.files.branch-merge/change-key`): the source's changes the user ;; deselected, which the branch keeps its own value for [:excluded {:optional true} [::sm/set :string]] [:expected-source-revn {:optional true} ::sm/int]]) (defn- persist-branch-update! - "Persist the result of an update-from-main integration on a branch + "Persist the result of an update-from-source integration on a branch file: update the `file` row and the project modified-at without any data payload, and REPLACE the branch's op log with the squashed branch-only changes. The repositioned merge base already carries - everything main contributed, so replaying the squash over it + everything the source contributed, so replaying the squash over it reproduces the updated branch exactly, and the log never accumulates - main-side ops (which would otherwise be double-applied on read). + source-side ops (which would otherwise be double-applied on read). The squash is computed between documents `bfc/get-file` read at the current data version, so its row records that version. The row also stamps the media id map the update applied, as applied - ({main-media-id -> branch-media-id}): the squashed changes were - computed against main's document moved into the branch's id space, so + ({source-media-id -> branch-media-id}): the squashed changes were + computed against the source's document moved into the branch's id space, so the pairing the log describes after the squash is the one the stamps rebuild (`branch-media-pairs`), not the content identity heuristic." [{:keys [::db/conn] :as cfg} file ts branch-id changes media-map] @@ -1575,17 +1581,17 @@ (sv/defmethod ::update-file-branch-from-source - "Bring the changes main received since the merge base into the branch - (the reverse direction of a merge). Returns `{:status :conflicts}` (with - the `:source-revn` they were computed against and the summary's - `:copies`) when main and the branch + "Bring the changes the source received since the merge base into the + branch (the reverse direction of a merge). Returns `{:status + :conflicts}` (with the `:source-revn` they were computed against and + the summary's `:copies`) when the source and the branch diverged on the same entity and it is not resolved in `resolutions`, or `{:status :unsupported}` for change kinds not yet translatable. On - success it applies main's changes (and any conflicts resolved to main) - to the branch, takes a safety snapshot, and repositions the merge base - to the current state of main. + success it applies the source's changes (and any conflicts resolved to + the source) to the branch, takes a safety snapshot, and repositions the + merge base to the current state of the source. - Copies follow the integrated components as in a merge: after main's + Copies follow the integrated components as in a merge: after the source's changes apply, the copies of every local component whose main they changed are synced on the branch, in the branch's id space (`bm/sync-copies`), before the squash records the branch's net." @@ -1606,7 +1612,7 @@ (let [tpoint (ct/tpoint) branch-file-id (:branch-file-id branch) - main-id (:source-file-id branch) + source-id (:source-file-id branch) messages (volatile! [])] ;; Editing the branch -> need edition permissions on the branch file. (files/check-edition-permissions! cfg profile-id branch-file-id) @@ -1632,13 +1638,13 @@ :branch-id branch-id)) ;; an archived source is set aside, so nothing flows ;; from it either (`:branch-stacking`) - _ (check-source-open conn main-id) - [main-stored main-file] (read-main-for-write cfg main-id :update-from-source) + _ (check-source-open conn source-id) + [source-stored source-file] (read-source-for-write cfg source-id :update-from-source) _ (when (and (some? expected-source-revn) - (not= expected-source-revn (:revn main-file))) + (not= expected-source-revn (:revn source-file))) (ex/raise :type :conflict :code :file-modified - :hint "main was modified, recompute the diff and retry")) + :hint "source was modified, recompute the diff and retry")) _ (check-oplog-depth-limit! (bfc/get-branch-oplog-depth cfg branch-file-id) branch-file-id :update-from-source) @@ -1650,7 +1656,7 @@ ;; Two id maps, one per direction of the crossing. ;; - ;; The COMPARISON runs in main's id space, the id space the + ;; The COMPARISON runs in the source's id space, the id space the ;; merge base was captured in, the id space the compare view ;; uses (`files_branch.clj::branch-id-map` in ;; `files_branch.clj::get-file-branch-diff`), and the only id space @@ -1658,27 +1664,27 @@ ;; no data, so `binfile.clj::branch-file-data` replays its op ;; log over that base and everything it inherited carries the ;; base's ids. Comparing in the branch's id space instead - ;; rewrites main's and the base's local references to the - ;; branch file id, and a self reference in main is then + ;; rewrites the source's and the base's local references to the + ;; branch file id, and a self reference in the source is then ;; unequal to the branch's own copy of it, so every shape - ;; main touched that carries one reads as an edit on both + ;; the source touched that carries one reads as an edit on both ;; sides. base-data base-raw - main-raw (:data main-file) + source-raw (:data source-file) branch-cmp (bm/remap-refs (:data branch-file) - (branch-id-map cfg branch-file-id main-id)) + (branch-id-map cfg branch-file-id source-id)) ;; The WRITE runs in the branch's id space: a reference is only - ;; a reference in the file it names, so main's file id and - ;; main's media rows are re-pointed at the branch's ids before - ;; the change reaches the branch. Media ADDED on main has no + ;; a reference in the file it names, so the source's file id and + ;; the source's media rows are re-pointed at the branch's ids before + ;; the change reaches the branch. Media ADDED on the source has no ;; branch row yet, so it gets a fresh id here and its row is ;; copied below only if the update applies. - ;; the WRITE direction ({main-media-id -> branch-media-id}) + ;; the WRITE direction ({source-media-id -> branch-media-id}) ;; is the inverse of the comparison's pairs pairs (set/map-invert - (branch-media-pairs cfg branch-file-id main-id)) - new-media (unpaired-media-rows cfg main-id main-raw pairs) + (branch-media-pairs cfg branch-file-id source-id)) + new-media (unpaired-media-rows cfg source-id source-raw pairs) fresh-map (into {} (map (fn [row] [(:id row) (uuid/next)])) new-media) ;; the branch's OWN id space: every media row the branch ;; references is one of its own — a paired copy or one of @@ -1686,8 +1692,8 @@ ;; base name those; `apply-map` adds the file id on top for ;; the change payloads, which re-point their file refs too. media-map (merge pairs fresh-map) - apply-map (assoc media-map main-id branch-file-id) - main-data (bm/remap-refs main-raw apply-map) + apply-map (assoc media-map source-id branch-file-id) + source-data (bm/remap-refs source-raw apply-map) ;; did the branch carry its OWN changes before this update? ;; (revn moved since the base was last positioned) @@ -1700,21 +1706,21 @@ ;; the base is pinned in the branch's id space — its media ;; references name the branch's own rows — because it is what ;; the op log replays over: the derived document carries that - ;; id space, so a base naming main's rows would make every + ;; id space, so a base naming the source's rows would make every ;; paired media read as deleted+added on the next squash. The - ;; comparisons normalize it back to main's id space on read + ;; comparisons normalize it back to the source's id space on read ;; (`get-base-data`/`branch-base-data`). A page the remap - ;; left equal to main's names main's fragment. - (let [new-base (fsnap/create! cfg (reattach-main-pointers - cfg main-id main-stored - (assoc main-file :data base-data)) + ;; left equal to the source's names the source's fragment. + (let [new-base (fsnap/create! cfg (reattach-source-pointers + cfg source-id source-stored + (assoc source-file :data base-data)) {:label (str "branch-base/" (:name branch)) :created-by "system" :deleted-at (ct/in-future {:days 3650}) :profile-id profile-id}) ;; the ahead/behind revn gate compares each side's revn ;; against this stored counter to SKIP the diff. After - ;; an update the new base equals MAIN, so a branch that + ;; an update the new base equals the SOURCE, so a branch that ;; had its own changes still differs from it even if ;; its revn never moves again — keep the gate open by ;; storing one revn less; the diff then reports the @@ -1724,14 +1730,14 @@ (release-base-snapshot! cfg branch (ct/in-future delay)) (db/update! conn :file-branch {:base-snapshot-id (:id new-base) - :base-source-revn (:revn main-file) + :base-source-revn (:revn source-file) :base-branch-revn branch-revn :updated-at ts} {:id branch-id} {::db/return-keys false}))) merge-summary - (bm/compute-merge base-data main-raw branch-cmp :source->branch {:copies? true}) + (bm/compute-merge base-data source-raw branch-cmp :source->branch {:copies? true}) conflicts (:conflicts merge-summary) resolved? (fn [c] (or (contains? excluded (:key c)) @@ -1739,9 +1745,9 @@ unresolved (remove resolved? conflicts) ;; Resolutions arrive document-keyed (`:source` = the source's value). - ;; The update runs compute-changes with main as the source and - ;; the branch as the target, where the `:branch` keyword means - ;; "take the source (main)" — so invert each side to that + ;; The update runs compute-changes with the source file as + ;; the source and the branch as the target, where the + ;; `:branch` keyword means "take the source file" — so invert each side to that ;; vocabulary, including the per-attr maps, value by value. flip (fn [v] (case v :source :branch, :branch :source, v)) inverted (into {} (map (fn [[k v]] @@ -1753,7 +1759,7 @@ (cond (seq unresolved) (audited {:status :conflicts :conflicts conflicts :copies (:copies merge-summary) - :source-revn (:revn main-file)} + :source-revn (:revn source-file)} tpoint :update-from-source) (bm/nothing-to-merge? merge-summary excluded) @@ -1765,14 +1771,15 @@ :hint "select at least one change to merge") :else - ;; target = branch, source = main -> changes that bring main's - ;; net changes (and conflicts resolved to main) into the branch. - ;; The `:source->branch` summary reports main's changes against the + ;; target = branch, source = the source file -> changes that + ;; bring the source's net changes (and conflicts resolved to + ;; the source) into the branch. The `:source->branch` summary + ;; reports the source's changes against the ;; branch, the same assignment compute-changes runs with here, so ;; it can be reused for the unsupported-kinds gate without ;; re-diffing. (let [{:keys [changes unsupported]} - (bm/compute-changes base-data branch-cmp main-raw + (bm/compute-changes base-data branch-cmp source-raw (or inverted {}) merge-summary excluded)] @@ -1790,7 +1797,7 @@ (and (empty? changes) (not branch-diverged?) (empty? excluded)) (let [ts (ct/now)] - ;; the branch is in sync with main: the repositioned + ;; the branch is in sync with the source: the repositioned ;; base already represents the branch, so the op log ;; is emptied (old ops were built against the old base). ;; The log is a branch's only durable record, so it may @@ -1799,15 +1806,15 @@ ;; that log, so it falls through to the squash below, ;; which re-derives the net against the new base. The ;; shortcut needs no exclusion in play either: excluded - ;; main work is NOT in the branch, so the branch differs + ;; source work is NOT in the branch, so the branch differs ;; from the repositioned base and the squash has to ;; record that difference as a branch-side delta. (db/delete! conn :file-branch-change {:branch-id branch-id}) ;; in sync, so no row is copied and the pairs are all ;; the id space the base needs: unpaired rows stay - ;; named by the id main owns, which is what the branch + ;; named by the id the source owns, which is what the branch ;; references while it holds no copy - (reposition-base! ts (:revn branch-file) (bm/remap-refs main-raw pairs)) + (reposition-base! ts (:revn branch-file) (bm/remap-refs source-raw pairs)) (audited {:status :updated :revn (:revn branch-file)} tpoint :update-from-source)) :else @@ -1822,7 +1829,7 @@ :deleted-at (ct/in-future delay) :profile-id profile-id}) - ;; media added on main: copy its rows into the branch + ;; media added on the source: copy its rows into the branch ;; under the pre-allocated ids the changes reference (copy-media-rows! conn branch-file-id fresh-map new-media) @@ -1892,8 +1899,8 @@ (into sync)))} {::db/return-keys false}) - ;; SQUASH: the new base (main's current state) - ;; already carries everything main contributed, + ;; SQUASH: the new base (the source's current + ;; state) already carries everything the source contributed, ;; so the op log is replaced with the net ;; branch-only changes computed against the new ;; base. Refuse if that net cannot be translated @@ -1902,7 +1909,7 @@ ;; undoes the snapshot and media copies above. (let [{net-changes :changes unsupported :unsupported} - (bm/compute-changes main-data main-data (:data updated) {})] + (bm/compute-changes source-data source-data (:data updated) {})] (when (seq unsupported) (ex/raise :type :validation :code :unsupported-update-squash @@ -1912,14 +1919,14 @@ ;; update applied: the log it replaces was ;; written against the OLD merge base, and ;; the squash is what names the branch's - ;; pairing with main from now on + ;; pairing with the source from now on (persist-branch-update! cfg updated ts branch-id net-changes media-map)) (when (contains? cf/flags :redis-cache) (fupd/invalidate-caches! cfg updated)) (reposition-base! ts (:revn updated) - (bm/remap-refs main-raw media-map)) + (bm/remap-refs source-raw media-map)) (vswap! messages conj {:topic branch-file-id @@ -2097,7 +2104,7 @@ entity-level `ahead`/`behind`/`conflicts` counts read through the summary cache (`cached-diff-counts`); otherwise nil. A cache miss on an open branch whose revn deltas are not both zero runs the three-way diff - (`branch-diff-counts!`), which loads main, the branch and its base. + (`branch-diff-counts!`), which loads the source, the branch and its base. Returns nil when branching is disabled, so it is safe to call on every file open. @@ -2201,7 +2208,7 @@ "List the merges into a file, newest first: each one names the merged branch, who merged it and when, the comment left with it and the design review it accepted, if any. When the file is itself a branch, the - merges into its source (main) are listed. The records outlive the + merges into its source are listed. The records outlive the branches they name (see the `file_branch_merge` migration)." {::doc/added "2.16" ::sm/params schema:get-file-branch-merges} @@ -2209,14 +2216,14 @@ (check-branching-enabled!) (db/run! cfg (fn [{:keys [::db/conn] :as cfg}] - (let [main-id (:id (db/exec-one! conn [sql:resolve-source-file file-id file-id]))] - (files/check-read-permissions! cfg profile-id main-id) - (db/exec! conn [sql:get-file-branch-merges main-id]))))) + (let [source-id (:id (db/exec-one! conn [sql:resolve-source-file file-id file-id]))] + (files/check-read-permissions! cfg profile-id source-id) + (db/exec! conn [sql:get-file-branch-merges source-id]))))) ;; --- COMMANDS: the changes a profile marked as viewed (defn- get-readable-branch - "The branch `branch-id`, once `profile-id` is known to read its main. + "The branch `branch-id`, once `profile-id` is known to read its source. Raises when there is no such branch." [{:keys [::db/conn] :as cfg} profile-id branch-id] (let [branch (db/get* conn :file-branch {:id branch-id})] diff --git a/backend/src/app/rpc/commands/files_update.clj b/backend/src/app/rpc/commands/files_update.clj index 167f6f1052..5e6f0c3a3c 100644 --- a/backend/src/app/rpc/commands/files_update.clj +++ b/backend/src/app/rpc/commands/files_update.clj @@ -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) diff --git a/backend/test/backend_tests/branch_copies_follow_component_test.clj b/backend/test/backend_tests/branch_copies_follow_component_test.clj index 8e542bc59a..900de3af4e 100644 --- a/backend/test/backend_tests/branch_copies_follow_component_test.clj +++ b/backend/test/backend_tests/branch_copies_follow_component_test.clj @@ -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)]) diff --git a/backend/test/backend_tests/branch_family_gc_test.clj b/backend/test/backend_tests/branch_family_gc_test.clj index c013c8d299..322a59b2dd 100644 --- a/backend/test/backend_tests/branch_family_gc_test.clj +++ b/backend/test/backend_tests/branch_family_gc_test.clj @@ -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}) diff --git a/backend/test/backend_tests/branch_file_identity_test.clj b/backend/test/backend_tests/branch_file_identity_test.clj index 6f5729122f..3e27101388 100644 --- a/backend/test/backend_tests/branch_file_identity_test.clj +++ b/backend/test/backend_tests/branch_file_identity_test.clj @@ -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 diff --git a/backend/test/backend_tests/branch_file_queries_test.clj b/backend/test/backend_tests/branch_file_queries_test.clj index 8ad7c82876..668d49747f 100644 --- a/backend/test/backend_tests/branch_file_queries_test.clj +++ b/backend/test/backend_tests/branch_file_queries_test.clj @@ -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))))))) diff --git a/backend/test/backend_tests/branch_merge_test.clj b/backend/test/backend_tests/branch_merge_test.clj index 9c7572168c..b14a3eac96 100644 --- a/backend/test/backend_tests/branch_merge_test.clj +++ b/backend/test/backend_tests/branch_merge_test.clj @@ -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" diff --git a/backend/test/backend_tests/branch_payload_writers_test.clj b/backend/test/backend_tests/branch_payload_writers_test.clj index a6ce99ea2f..99254391a9 100644 --- a/backend/test/backend_tests/branch_payload_writers_test.clj +++ b/backend/test/backend_tests/branch_payload_writers_test.clj @@ -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)))) diff --git a/backend/test/backend_tests/branch_pointer_base_test.clj b/backend/test/backend_tests/branch_pointer_base_test.clj index 5a94f5803f..6213b44f5a 100644 --- a/backend/test/backend_tests/branch_pointer_base_test.clj +++ b/backend/test/backend_tests/branch_pointer_base_test.clj @@ -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)] diff --git a/backend/test/backend_tests/branch_save_repair_test.clj b/backend/test/backend_tests/branch_save_repair_test.clj index c3df44c2b7..c2b4ce75d6 100644 --- a/backend/test/backend_tests/branch_save_repair_test.clj +++ b/backend/test/backend_tests/branch_save_repair_test.clj @@ -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})] diff --git a/backend/test/backend_tests/http_middleware_test.clj b/backend/test/backend_tests/http_middleware_test.clj index 98890f0691..ab626c8c29 100644 --- a/backend/test/backend_tests/http_middleware_test.clj +++ b/backend/test/backend_tests/http_middleware_test.clj @@ -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))) diff --git a/backend/test/backend_tests/rpc_file_branch_oplog_test.clj b/backend/test/backend_tests/rpc_file_branch_oplog_test.clj index 186879cc38..533a39e6a5 100644 --- a/backend/test/backend_tests/rpc_file_branch_oplog_test.clj +++ b/backend/test/backend_tests/rpc_file_branch_oplog_test.clj @@ -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))))))) diff --git a/backend/test/backend_tests/rpc_file_branch_test.clj b/backend/test/backend_tests/rpc_file_branch_test.clj index bfc3a23190..00f3c5e237 100644 --- a/backend/test/backend_tests/rpc_file_branch_test.clj +++ b/backend/test/backend_tests/rpc_file_branch_test.clj @@ -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) diff --git a/backend/test/backend_tests/rpc_file_task_test.clj b/backend/test/backend_tests/rpc_file_task_test.clj index e7e87a54a7..798b81919d 100644 --- a/backend/test/backend_tests/rpc_file_task_test.clj +++ b/backend/test/backend_tests/rpc_file_task_test.clj @@ -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)]] diff --git a/common/src/app/common/files/branch_merge.cljc b/common/src/app/common/files/branch_merge.cljc index 07358770e1..ed981d7f98 100644 --- a/common/src/app/common/files/branch_merge.cljc +++ b/common/src/app/common/files/branch_merge.cljc @@ -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 [ ...] ; clean, branch -> main + {:changes [ ...] ; clean, branch -> source :conflicts [ ...] ; need resolution :stats {:added n :modified n :deleted n :conflicts n} :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))) diff --git a/common/test/common_tests/files_branch_merge_test.cljc b/common/test/common_tests/files_branch_merge_test.cljc index ed6cee730d..e3a8d30289 100644 --- a/common/test/common_tests/files_branch_merge_test.cljc +++ b/common/test/common_tests/files_branch_merge_test.cljc @@ -197,27 +197,27 @@ r (bm/compute-merge base base branch :branch->source)] (t/is (not (contains? (first (:changes r)) :shape))))) -(t/deftest fast-forward-main-untouched - ;; main == base; branch changed -> all branch changes apply cleanly +(t/deftest fast-forward-source-untouched + ;; source == base; branch changed -> all branch changes apply cleanly (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}}) r (bm/compute-merge base base branch :branch->source)] (t/is (= 0 (-> r :stats :conflicts))) (t/is (= 1 (-> r :stats :modified))))) -(t/deftest main-only-change-not-reported - ;; branch == base; main changed -> branch contributes nothing - (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) - r (bm/compute-merge base main base :branch->source)] +(t/deftest source-only-change-not-reported + ;; branch == base; source changed -> branch contributes nothing + (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + r (bm/compute-merge base source base :branch->source)] (t/is (= [] (:changes r))) (t/is (= 0 (-> r :stats :conflicts))))) (t/deftest modify-modify-conflict (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}}) - r (bm/compute-merge base main branch :branch->source) + r (bm/compute-merge base source branch :branch->source) cf (first (:conflicts r))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= :modify-modify (:reason cf))) @@ -225,11 +225,11 @@ (t/is (= "blue" (get-in cf [:changed-attrs :fill :branch]))))) (t/deftest delete-modify-conflict - ;; deleted in branch, modified in main + ;; deleted in branch, modified in source (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) branch (mkdata {}) - r (bm/compute-merge base main branch :branch->source) + r (bm/compute-merge base source branch :branch->source) cf (first (:conflicts r))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= :delete-modify (:reason cf))))) @@ -270,9 +270,9 @@ ;; the differing :modified-at must NOT create a modify-modify conflict. (let [cid (uuid/random) base (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t0"}}) - main (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t1"}}) + source (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t1"}}) branch (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t2"}}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [] (:conflicts r))) (t/is (= 0 (-> r :stats :conflicts))))) @@ -305,7 +305,7 @@ ;; shapes with no refs are left untouched. Covers component, library ;; color/typography and media references plus the :media/:colors indexes. (let [branch-id (uuid/next) - main-id (uuid/next) + source-id (uuid/next) ext-lib (uuid/next) media-old (uuid/next) media-new (uuid/next) @@ -323,15 +323,15 @@ :fill-image {:id media-old}}}) (assoc :media {media-old {:id media-old :name "img"}}) (assoc :colors {:c1 {:id :c1 :image {:id media-old}}})) - data' (bm/remap-refs data {branch-id main-id + data' (bm/remap-refs data {branch-id source-id media-old media-new}) objs (get-in data' [:pages-index :p1 :objects])] - (t/is (= main-id (get-in objs [:s1 :component-file]))) + (t/is (= source-id (get-in objs [:s1 :component-file]))) (t/is (= ext-lib (get-in objs [:s2 :component-file]))) (t/is (not (contains? (get objs :s3) :component-file))) - (t/is (= main-id (get-in objs [:s4 :fill-color-ref-file]))) - (t/is (= main-id (get-in objs [:s4 :content :children 0 :children 0 :typography-ref-file]))) - (t/is (= main-id (get-in objs [:s4 :content :children 0 :children 0 :children 0 :typography-ref-file]))) + (t/is (= source-id (get-in objs [:s4 :fill-color-ref-file]))) + (t/is (= source-id (get-in objs [:s4 :content :children 0 :children 0 :typography-ref-file]))) + (t/is (= source-id (get-in objs [:s4 :content :children 0 :children 0 :children 0 :typography-ref-file]))) (t/is (= media-new (get-in objs [:s5 :metadata :id]))) (t/is (= media-new (get-in objs [:s5 :fill-image :id]))) (t/is (= {media-new {:id media-new :name "img"}} (:media data'))) @@ -339,19 +339,19 @@ (t/deftest remap-refs-remaps-document-id-and-tokens-source (let [branch-id (uuid/next) - main-id (uuid/next) + source-id (uuid/next) ext-lib (uuid/next) media-old (uuid/next)] (t/testing "the file id map moves the document and its self-named source" (let [data' (bm/remap-refs (assoc (mkdata {}) :id branch-id :tokens-source branch-id) - {branch-id main-id})] - (t/is (= main-id (:id data'))) - (t/is (= main-id (:tokens-source data'))) - (t/is (cfo/effective-tokens-source? data' main-id)))) + {branch-id source-id})] + (t/is (= source-id (:id data'))) + (t/is (= source-id (:tokens-source data'))) + (t/is (cfo/effective-tokens-source? data' source-id)))) (t/testing "a library tokens source outside the map stays" (let [data' (bm/remap-refs (assoc (mkdata {}) :id branch-id :tokens-source ext-lib) - {branch-id main-id})] - (t/is (= main-id (:id data'))) + {branch-id source-id})] + (t/is (= source-id (:id data'))) (t/is (= ext-lib (:tokens-source data'))))) (t/testing "a media-only map leaves the document id alone" (let [data' (bm/remap-refs (assoc (mkdata {}) :id branch-id) {media-old (uuid/next)})] @@ -359,21 +359,21 @@ (t/is (not (contains? data' :tokens-source))))) (t/testing "remap-changes maps a set-tokens-source change" (t/is (= [{:type :set-tokens-source :file-id branch-id :library-id branch-id}] - (bm/remap-changes [{:type :set-tokens-source :file-id main-id :library-id main-id}] - {main-id branch-id}))) + (bm/remap-changes [{:type :set-tokens-source :file-id source-id :library-id source-id}] + {source-id branch-id}))) (t/is (= [{:type :set-tokens-source :file-id branch-id :library-id nil}] - (bm/remap-changes [{:type :set-tokens-source :file-id main-id :library-id nil}] - {main-id branch-id})))))) + (bm/remap-changes [{:type :set-tokens-source :file-id source-id :library-id nil}] + {source-id branch-id})))))) (t/deftest merge-component-keeps-head-and-remaps-file - ;; a component created on a branch must merge into main as a VALID head: - ;; its main instance keeps component-id/main-instance and its - ;; component-file is re-pointed from the branch id to main's id (else main + ;; a component created on a branch must merge into the source as a VALID + ;; head: its main instance keeps component-id/main-instance and its + ;; component-file is re-pointed from the branch id to the source's id (else the source ;; can't resolve the component and repair detaches it). (let [comp-id :c1 mi-id :mi branch-id (uuid/next) - main-id (uuid/next) + source-id (uuid/next) base (mkdata {uuid/zero {:id uuid/zero :type :frame :shapes []}}) branch (-> (mkdata {uuid/zero {:id uuid/zero :type :frame :shapes [mi-id]} mi-id {:id mi-id :type :frame :name "Comp" :shapes [] @@ -382,8 +382,8 @@ :component-id comp-id :component-file branch-id}}) (assoc :components {comp-id {:id comp-id :name "Comp" :path "" :main-instance-id mi-id :main-instance-page :p1}})) - ;; emulate the RPC: canonicalize the branch's local file id to main's - branch' (bm/remap-refs branch {branch-id main-id}) + ;; emulate the RPC: canonicalize the branch's local file id to the source's + branch' (bm/remap-refs branch {branch-id source-id}) {:keys [changes unsupported]} (bm/compute-changes base base branch') add-mi (first (filter #(and (= :add-obj (:type %)) (= mi-id (:id %))) changes)) add-comp (first (filter #(= :add-component (:type %)) changes))] @@ -391,8 +391,8 @@ ;; registry row merged (t/is (= comp-id (:id add-comp))) (t/is (= mi-id (:main-instance-id add-comp))) - ;; the merged main instance is still a head, re-pointed to main's id - (t/is (= main-id (get-in add-mi [:obj :component-file]))) + ;; the merged main instance is still a head, re-pointed to the source's id + (t/is (= source-id (get-in add-mi [:obj :component-file]))) (t/is (= comp-id (get-in add-mi [:obj :component-id]))) (t/is (true? (get-in add-mi [:obj :main-instance]))) (t/is (true? (get-in add-mi [:obj :component-root]))))) @@ -431,7 +431,7 @@ (t/is (empty? (filter #(and (= :mod-obj (:type %)) (= :root (:id %))) changes))))) (t/deftest compute-changes-reparent-existing-shape - ;; main: rect R loose at root. branch: R moved into a new group G. + ;; source: rect R loose at root. branch: R moved into a new group G. ;; the merge must MOVE R into G (mov-objects), not :set its parent-id — ;; otherwise R is left loose at root and duplicated by file repair. (let [base (mkdata {uuid/zero {:id uuid/zero :type :frame :shapes [:r]} @@ -463,24 +463,24 @@ (t/deftest compute-changes-resolve-shape-conflict (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}})] ;; resolved to branch -> sets the branch value - (let [{:keys [changes]} (bm/compute-changes base main branch {:s1 :branch}) + (let [{:keys [changes]} (bm/compute-changes base source branch {:s1 :branch}) op (-> (group-by :type changes) :mod-obj first :operations first)] (t/is (= {:type :set :attr :fill :val "blue"} op))) - ;; resolved to main -> nothing emitted - (let [{:keys [changes]} (bm/compute-changes base main branch {:s1 :source})] + ;; resolved to the source -> nothing emitted + (let [{:keys [changes]} (bm/compute-changes base source branch {:s1 :source})] (t/is (empty? (filterv #(= :mod-obj (:type %)) changes)))) ;; unresolved -> nothing emitted (caller refuses the merge) - (let [{:keys [changes]} (bm/compute-changes base main branch {})] + (let [{:keys [changes]} (bm/compute-changes base source branch {})] (t/is (empty? (filterv #(= :mod-obj (:type %)) changes)))))) (t/deftest compute-changes-resolve-color-conflict (let [base (mkdata {} :colors {:c1 {:id :c1 :name "A"}}) - main (mkdata {} :colors {:c1 {:id :c1 :name "Main"}}) + source (mkdata {} :colors {:c1 {:id :c1 :name "Source"}}) branch (mkdata {} :colors {:c1 {:id :c1 :name "Branch"}}) - {:keys [changes]} (bm/compute-changes base main branch {:c1 :branch})] + {:keys [changes]} (bm/compute-changes base source branch {:c1 :branch})] (t/is (= "Branch" (-> (group-by :type changes) :mod-color first :color :name))))) ;; --- per-property (per-attr) conflict resolution @@ -502,12 +502,12 @@ (t/is (false? (bm/conflict-resolved? {} {:fill :branch}))))) (t/deftest compute-changes-resolve-shape-per-attr - ;; both fill and rx conflict; keep branch fill, keep main rx -> only the - ;; fill set op is emitted (rx resolved to main is a no-op against main) + ;; both fill and rx conflict; keep branch fill, keep the source's rx -> only + ;; the fill set op is emitted (rx resolved to the source is a no-op against it) (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red" :rx 0}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green" :rx 4}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green" :rx 4}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue" :rx 8}}) - {:keys [changes]} (bm/compute-changes base main branch {:s1 {:fill :branch :rx :source}}) + {:keys [changes]} (bm/compute-changes base source branch {:s1 {:fill :branch :rx :source}}) ops (-> (group-by :type changes) :mod-obj first :operations)] (t/is (= [{:type :set :attr :fill :val "blue"}] ops)))) @@ -515,23 +515,23 @@ ;; per-attr map selecting branch for every attr equals the whole `:branch` ;; resolution (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red" :rx 0}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green" :rx 4}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green" :rx 4}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue" :rx 8}}) - per (-> (bm/compute-changes base main branch {:s1 {:fill :branch :rx :branch}}) + per (-> (bm/compute-changes base source branch {:s1 {:fill :branch :rx :branch}}) :changes (->> (group-by :type)) :mod-obj first :operations set) - whole (-> (bm/compute-changes base main branch {:s1 :branch}) + whole (-> (bm/compute-changes base source branch {:s1 :branch}) :changes (->> (group-by :type)) :mod-obj first :operations set)] (t/is (= whole per)) (t/is (= #{{:type :set :attr :fill :val "blue"} {:type :set :attr :rx :val 8}} per)))) (t/deftest compute-changes-resolve-color-per-attr - ;; color conflict on two attrs; take branch name, keep main description -> - ;; merged color carries branch name + main description + ;; color conflict on two attrs; take branch name, keep the source's description -> + ;; merged color carries branch name + the source's description (let [base (mkdata {} :colors {:c1 {:id :c1 :name "A" :opacity 1}}) - main (mkdata {} :colors {:c1 {:id :c1 :name "Main" :opacity 1}}) + source (mkdata {} :colors {:c1 {:id :c1 :name "Srce" :opacity 1}}) branch (mkdata {} :colors {:c1 {:id :c1 :name "Brnc" :opacity 0.5}}) - {:keys [changes]} (bm/compute-changes base main branch {:c1 {:name :branch :opacity :source}}) + {:keys [changes]} (bm/compute-changes base source branch {:c1 {:name :branch :opacity :source}}) color (-> (group-by :type changes) :mod-color first :color)] (t/is (= "Brnc" (:name color))) (t/is (= 1 (:opacity color))))) @@ -563,10 +563,10 @@ branch-lib (ctob/update-token base-lib sid tid (fn [t] (ctob/make-token (assoc (into {} t) :value "#0000ff")))) base (with-tokens base-lib) - main (with-tokens base-lib) + source (with-tokens base-lib) branch (with-tokens branch-lib) - {:keys [changes unsupported]} (bm/compute-changes base main branch) + {:keys [changes unsupported]} (bm/compute-changes base source branch) set-token-change (first (filter #(= :set-token (:type %)) changes))] (t/is (empty? unsupported)) @@ -574,7 +574,7 @@ (t/is (= tid (:token-id set-token-change))) (t/is (= "#0000ff" (-> set-token-change :attrs :value))) - ;; round-trip: apply the change to main's tokens-lib and read the value back + ;; round-trip: apply the change to the source's tokens-lib and read the value back (let [data' (cfc/process-changes {:tokens-lib base-lib} changes) tok (ctob/get-token (:tokens-lib data') sid tid)] (t/is (= "#0000ff" (:value tok)))))) @@ -598,7 +598,7 @@ (t/is (empty? unsupported)) (t/is (some #(= sid2 (:id %)) (:set-token-set by-type))) (t/is (some #(= tid2 (:token-id %)) (:set-token by-type))) - ;; round-trip: the new set and its token exist in main afterwards + ;; round-trip: the new set and its token exist in the source afterwards (let [data' (cfc/process-changes {:tokens-lib base-lib} changes)] (t/is (some? (ctob/get-set (:tokens-lib data') sid2))) (t/is (some? (ctob/get-token (:tokens-lib data') sid2 tid2)))))) @@ -678,7 +678,7 @@ {:keys [changes unsupported]} (bm/compute-changes base base branch)] (t/is (empty? unsupported)) (t/is (seq (filter #(= :mov-page (:type %)) changes))) - ;; round-trip: main ends up in branch's page order + ;; round-trip: the source ends up in branch's page order (let [data' (cfc/process-changes base changes)] (t/is (= [p3 p1 p2] (:pages data')))))) @@ -693,7 +693,7 @@ (t/is (empty? unsupported)) (t/is (= gid (:id ch))) (t/is (= pid (:page-id ch))) - ;; round-trip: the guide is present on main afterwards + ;; round-trip: the guide is present on the source afterwards (let [data' (cfc/process-changes base changes)] (t/is (contains? (get-in data' [:pages-index pid :guides]) gid))))) @@ -715,7 +715,7 @@ (t/is (= pid (:page-id ch))) (t/is (= :square (:grid-type ch))) (t/is (= grid (:params ch))) - ;; round-trip: the grid is present on main afterwards + ;; round-trip: the grid is present on the source afterwards (let [data' (cfc/process-changes base changes)] (t/is (= grid (get-in data' [:pages-index pid :default-grids :square])))))) @@ -781,9 +781,9 @@ (t/deftest compute-merge-file-level-conflicts (let [base (file-level-data :plugin-data {:my-plugin {"foo" "a"}} :base-font-size "16px") - main (file-level-data :plugin-data {:my-plugin {"foo" "b"}} :base-font-size "18px") + source (file-level-data :plugin-data {:my-plugin {"foo" "b"}} :base-font-size "18px") branch (file-level-data :plugin-data {:my-plugin {"foo" "c"}} :base-font-size "20px") - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= 2 (-> r :stats :conflicts))) (t/is (= #{:file-plugin :file-option} (set (map :kind (:conflicts r))))) (t/is (every? #(= :modify-modify (:reason %)) (:conflicts r))) @@ -815,11 +815,11 @@ (t/deftest compute-changes-file-level-conflict-resolutions (let [base (file-level-data :plugin-data {:my-plugin {"foo" "a"}} :base-font-size "16px") - main (file-level-data :plugin-data {:my-plugin {"foo" "b"}} :base-font-size "18px") + source (file-level-data :plugin-data {:my-plugin {"foo" "b"}} :base-font-size "18px") branch (file-level-data :plugin-data {:my-plugin {"foo" "c"}} :base-font-size "20px") apply* (fn [resolutions] - (cfc/process-changes main (:changes (bm/compute-changes base main branch resolutions))))] - (t/testing "unresolved: main keeps its values" + (cfc/process-changes source (:changes (bm/compute-changes base source branch resolutions))))] + (t/testing "unresolved: the source keeps its values" (let [data' (apply* {})] (t/is (= "b" (get-in data' [:plugin-data :my-plugin "foo"]))) (t/is (= "18px" (get-in data' [:options :base-font-size]))))) @@ -828,26 +828,26 @@ (t/is (= "c" (get-in data' [:plugin-data :my-plugin "foo"]))) (t/is (= "20px" (get-in data' [:options :base-font-size]))))))) -(t/deftest compute-changes-file-level-update-from-main +(t/deftest compute-changes-file-level-update-from-source (let [base (file-level-data) - main (file-level-data :plugin-data {:my-plugin {"foo" "bar"}} :base-font-size "20px") - r (bm/compute-merge base main base :source->branch) - data' (cfc/process-changes base (:changes (bm/compute-changes base base main {} r)))] + source (file-level-data :plugin-data {:my-plugin {"foo" "bar"}} :base-font-size "20px") + r (bm/compute-merge base source base :source->branch) + data' (cfc/process-changes base (:changes (bm/compute-changes base base source {} r)))] (t/is (= 2 (count (:changes r)))) (t/is (= "bar" (get-in data' [:plugin-data :my-plugin "foo"]))) (t/is (= "20px" (get-in data' [:options :base-font-size]))))) ;; --- tokens source -(def ^:private main-file-id (uuid/custom 0 100)) +(def ^:private source-file-id (uuid/custom 0 100)) (def ^:private lib-a (uuid/custom 0 101)) (def ^:private lib-b (uuid/custom 0 102)) (defn- source-data - "File-level data of main's file whose tokens source is `source` (nil = + "File-level data of the source file whose tokens source is `source` (nil = the file itself)." [source] - (cond-> (assoc (file-level-data) :id main-file-id) + (cond-> (assoc (file-level-data) :id source-file-id) (some? source) (assoc :tokens-source source))) (t/deftest compute-merge-tokens-source-one-side @@ -866,62 +866,62 @@ branch (source-data lib-a) {:keys [changes unsupported]} (bm/compute-changes base base branch)] (t/is (empty? unsupported)) - (t/is (= [{:type :set-tokens-source :file-id main-file-id :library-id lib-a}] changes)) + (t/is (= [{:type :set-tokens-source :file-id source-file-id :library-id lib-a}] changes)) (t/is (= lib-a (:tokens-source (cfc/process-changes base changes)))))) (t/testing "the branch points the file back at itself" (let [base (source-data lib-a) branch (source-data nil) {:keys [changes]} (bm/compute-changes base base branch)] - (t/is (= [{:type :set-tokens-source :file-id main-file-id :library-id nil}] changes)) + (t/is (= [{:type :set-tokens-source :file-id source-file-id :library-id nil}] changes)) (t/is (not (contains? (cfc/process-changes base changes) :tokens-source))))) - (t/testing "main's change stays when the branch leaves the source alone" - (let [base (source-data nil) - main (source-data lib-a)] - (t/is (empty? (:changes (bm/compute-merge base main base :branch->source)))) - (t/is (empty? (:changes (bm/compute-changes base main base))))))) + (t/testing "the source file's change stays when the branch leaves the tokens source alone" + (let [base (source-data nil) + source (source-data lib-a)] + (t/is (empty? (:changes (bm/compute-merge base source base :branch->source)))) + (t/is (empty? (:changes (bm/compute-changes base source base))))))) (t/deftest compute-merge-tokens-source-self-id-reads-as-self ;; a source naming the file itself is the same as no source (let [base (source-data nil) - branch (source-data main-file-id)] + branch (source-data source-file-id)] (t/is (empty? (:changes (bm/compute-merge base base branch :branch->source)))) (t/is (empty? (:changes (bm/compute-changes base base branch)))))) (t/deftest tokens-source-merges-after-branch-remap - ;; a branch that named its own file id merges into main as "self" + ;; a branch that named its own file id merges into the source as "self" (let [branch-id (uuid/custom 0 103) base (source-data lib-a) branch (-> (source-data nil) (assoc :id branch-id :tokens-source branch-id) - (bm/remap-refs {branch-id main-file-id})) + (bm/remap-refs {branch-id source-file-id})) {:keys [changes]} (bm/compute-changes base base branch)] - (t/is (= [{:type :set-tokens-source :file-id main-file-id :library-id nil}] changes)) + (t/is (= [{:type :set-tokens-source :file-id source-file-id :library-id nil}] changes)) (t/is (not (contains? (cfc/process-changes base changes) :tokens-source))))) (t/deftest compute-merge-tokens-source-conflict (let [base (source-data nil) - main (source-data lib-a) + source (source-data lib-a) branch (source-data lib-b) - r (bm/compute-merge base main branch :branch->source) + r (bm/compute-merge base source branch :branch->source) c (first (:conflicts r)) apply* (fn [resolutions] (:tokens-source - (cfc/process-changes main (:changes (bm/compute-changes base main branch resolutions)))))] + (cfc/process-changes source (:changes (bm/compute-changes base source branch resolutions)))))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= {:kind :tokens-source :id :tokens-source :reason :modify-modify :base nil :source lib-a :branch lib-b} (select-keys c [:kind :id :reason :base :source :branch]))) (t/is (bm/conflict-resolved? c :branch)) - (t/testing "unresolved: main keeps its source" + (t/testing "unresolved: the source file keeps its tokens source" (t/is (= lib-a (apply* {})))) (t/testing "resolved to the branch: the branch's source lands" (t/is (= lib-b (apply* {:tokens-source :branch})))))) -(t/deftest compute-changes-tokens-source-update-from-main - (let [base (source-data nil) - main (source-data lib-a) - r (bm/compute-merge base main base :source->branch) - {:keys [changes unsupported]} (bm/compute-changes base base main {} r)] +(t/deftest compute-changes-tokens-source-update-from-source + (let [base (source-data nil) + source (source-data lib-a) + r (bm/compute-merge base source base :source->branch) + {:keys [changes unsupported]} (bm/compute-changes base base source {} r)] (t/is (= [:tokens-source] (map :kind (:changes r)))) (t/is (empty? unsupported)) (t/is (= lib-a (:tokens-source (cfc/process-changes base changes)))))) @@ -940,7 +940,7 @@ (t/is (empty? unsupported)) (t/is (= cid (:id add))) (t/is (= "Button" (:name add))) - ;; round-trip: the component row exists in main afterwards + ;; round-trip: the component row exists in the source afterwards (let [data' (cfc/process-changes {:components {}} changes)] (t/is (contains? (:components data') cid))))) @@ -1008,7 +1008,7 @@ (with-tokens branch-lib))] (t/is (empty? unsupported)) (t/is (seq (filter #(= :move-token-set (:type %)) changes))) - ;; round-trip: main ends up in branch's set order + ;; round-trip: the source ends up in branch's set order (let [data' (cfc/process-changes {:tokens-lib base-lib} changes) order (mapv ctob/get-name (ctob/get-sets (:tokens-lib data')))] (t/is (= ["c" "a" "b"] order))))) @@ -1024,7 +1024,7 @@ ch (first (filter #(= :set-tokens-status (:type %)) changes))] (t/is (empty? unsupported)) (t/is (= #{sid} (:set-ids ch))) - ;; round-trip: main's active sets match the branch + ;; round-trip: the source's active sets match the branch (let [data' (cfc/process-changes base changes)] (t/is (= #{sid} (ctos/get-active-set-ids (:tokens-status data'))))))) @@ -1041,14 +1041,14 @@ (t/is (empty? unsupported)) (t/is (= #{thid} (:theme-ids ch))) (t/is (= #{sid} (:set-ids ch)) "activating a theme activates its sets") - ;; round-trip: main's tokens status matches the branch + ;; round-trip: the source's tokens status matches the branch (let [status (:tokens-status (cfc/process-changes base changes))] (t/is (= #{thid} (ctos/get-active-theme-ids status))) (t/is (= #{sid} (ctos/get-active-set-ids status)))))) (t/deftest token-activation-conflict-settles-by-resolution ;; Both sides activate a different theme of one group, so both halves of - ;; the status diverge. Main's status stands until a resolution takes the + ;; the status diverge. The source's status stands until a resolution takes the ;; branch's. (let [sid-a (uuid/next) sid-b (uuid/next) @@ -1060,14 +1060,14 @@ (ctob/add-theme (ctob/make-token-theme {:id th-a :name "A" :group "" :sets #{"a"}})) (ctob/add-theme (ctob/make-token-theme {:id th-b :name "B" :group "" :sets #{"b"}}))) base (with-status lib identity) - main (with-status lib #(cfo/activate-theme % lib th-a)) + source (with-status lib #(cfo/activate-theme % lib th-a)) branch (with-status lib #(cfo/activate-theme % lib th-b)) status-changes (fn [resolutions] (filterv #(= :set-tokens-status (:type %)) - (:changes (bm/compute-changes base main branch resolutions))))] + (:changes (bm/compute-changes base source branch resolutions))))] (t/is (= #{:token-active-themes :token-active-sets} - (set (map :kind (:conflicts (bm/compute-merge base main branch :branch->source)))))) - (t/is (= [] (status-changes {})) "an unresolved conflict keeps main's status") + (set (map :kind (:conflicts (bm/compute-merge base source branch :branch->source)))))) + (t/is (= [] (status-changes {})) "an unresolved conflict keeps the source's status") (t/is (= [{:type :set-tokens-status :theme-ids #{th-b} :set-ids #{sid-b}}] (status-changes {:active-themes :branch :active-sets :branch}))))) @@ -1078,38 +1078,38 @@ ;; frame's :shapes (derived) — that must NOT be a conflict on the frame. (let [base (mkdata {:f1 {:id :f1 :name "Frame" :type :frame :shapes [:a]} :a {:id :a :name "A"}}) - main (mkdata {:f1 {:id :f1 :name "Frame" :type :frame :shapes [:a :m]} + source (mkdata {:f1 {:id :f1 :name "Frame" :type :frame :shapes [:a :m]} :a {:id :a :name "A"} :m {:id :m :name "M" :parent-id :f1 :frame-id :f1}}) branch (mkdata {:f1 {:id :f1 :name "Frame" :type :frame :shapes [:a :b]} :a {:id :a :name "A"} :b {:id :b :name "B" :parent-id :f1 :frame-id :f1}}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [] (:conflicts r))) (t/is (= #{:b} (set (map :id (:changes r))))))) -(t/deftest no-delete-conflict-on-touched-only-main-change - ;; branch deletes a shape; main only flipped its :touched (library sync, +(t/deftest no-delete-conflict-on-touched-only-source-change + ;; branch deletes a shape; the source only flipped its :touched (library sync, ;; not a user change) — that must stay a CLEAN delete, not a conflict. (let [base (mkdata {:s1 {:id :s1 :name "A" :touched nil}}) - main (mkdata {:s1 {:id :s1 :name "A" :touched #{:fill-group}}}) + source (mkdata {:s1 {:id :s1 :name "A" :touched #{:fill-group}}}) branch (mkdata {}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [] (:conflicts r))) (t/is (= [:deleted] (mapv :status (:changes r)))))) (t/deftest compute-changes-restores-shape-on-modify-delete-branch - ;; main deleted a frame the branch modified; resolving :branch must - ;; re-add the frame AND its surviving child (main's delete was recursive). + ;; the source deleted a frame the branch modified; resolving :branch must + ;; re-add the frame AND its surviving child (the source's delete was recursive). (let [base (mkdata {:f1 {:id :f1 :name "Frame" :type :frame :shapes [:c1] :parent-id uuid/zero :frame-id uuid/zero} :c1 {:id :c1 :name "Child" :parent-id :f1 :frame-id :f1}}) - main (mkdata {}) + source (mkdata {}) branch (mkdata {:f1 {:id :f1 :name "Frame RENAMED" :type :frame :shapes [:c1] :parent-id uuid/zero :frame-id uuid/zero} :c1 {:id :c1 :name "Child" :parent-id :f1 :frame-id :f1}}) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) - {:keys [changes]} (bm/compute-changes base main branch {:f1 :branch}) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) + {:keys [changes]} (bm/compute-changes base source branch {:f1 :branch}) adds (into {} (comp (filter #(= :add-obj (:type %))) (map (juxt :id identity))) changes)] @@ -1122,12 +1122,12 @@ (t/is (< (idx :f1) (idx :c1)))) (t/is (= "Frame RENAMED" (get-in adds [:f1 :obj :name]))))) -(t/deftest compute-changes-modify-delete-resolved-main-drops-shape +(t/deftest compute-changes-modify-delete-resolved-source-drops-shape ;; same conflict resolved to :source -> nothing is re-added (let [base (mkdata {:s1 {:id :s1 :name "A"}}) - main (mkdata {}) + source (mkdata {}) branch (mkdata {:s1 {:id :s1 :name "A2"}}) - {:keys [changes]} (bm/compute-changes base main branch {:s1 :source})] + {:keys [changes]} (bm/compute-changes base source branch {:s1 :source})] (t/is (= [] (filterv #(= :add-obj (:type %)) changes))))) ;;; --- Regression tests: order resolution ids --- @@ -1140,11 +1140,11 @@ p2 {:id p2 :name "P2" :objects {}} p3 {:id p3 :name "P3" :objects {}}} base (pages-data pi [p1 p2 p3]) - main (pages-data pi [p2 p1 p3]) + source (pages-data pi [p2 p1 p3]) branch (pages-data pi [p3 p1 p2]) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) conflict (first (filter #(= :page-order (:kind %)) conflicts)) - {:keys [changes]} (bm/compute-changes base main branch {:page-order :branch})] + {:keys [changes]} (bm/compute-changes base source branch {:page-order :branch})] (t/is (= :page-order (:id conflict))) (t/is (seq (filter #(= :mov-page (:type %)) changes))) (let [data' (cfc/process-changes (pages-data pi [p2 p1 p3]) changes)] @@ -1152,7 +1152,7 @@ ;;; --- Regression tests: page delete-vs-modify --- -(t/deftest page-deleted-in-branch-edited-in-main-conflicts +(t/deftest page-deleted-in-branch-edited-in-source-conflicts (let [p1 (uuid/next) p2 (uuid/next) s1 (uuid/next) mk (fn [p2-page] {:pages-index (cond-> {p1 {:id p1 :name "P1" :objects {}}} @@ -1160,39 +1160,39 @@ :pages (if p2-page [p1 p2] [p1]) :colors {} :typographies {} :media {} :components {}}) base (mk {:id p2 :name "P2" :objects {}}) - main (mk {:id p2 :name "P2" :objects {s1 {:id s1 :name "New"}}}) + source (mk {:id p2 :name "P2" :objects {s1 {:id s1 :name "New"}}}) branch (mk nil) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) conflict (first (filter #(= :page (:kind %)) conflicts))] (t/is (some? conflict)) (t/is (= :delete-modify (:reason conflict))) (t/is (= p2 (:id conflict))) ;; resolved to :branch -> the page is deleted - (let [{:keys [changes]} (bm/compute-changes base main branch {p2 :branch})] + (let [{:keys [changes]} (bm/compute-changes base source branch {p2 :branch})] (t/is (= [p2] (mapv :id (filter #(= :del-page (:type %)) changes))))) ;; resolved to :source -> the page is kept, nothing emitted for it - (let [{:keys [changes]} (bm/compute-changes base main branch {p2 :source})] + (let [{:keys [changes]} (bm/compute-changes base source branch {p2 :source})] (t/is (= [] (filterv #(= :del-page (:type %)) changes)))))) -(t/deftest page-deleted-in-main-edited-in-branch-restores +(t/deftest page-deleted-in-source-edited-in-branch-restores (let [p1 (uuid/next) p2 (uuid/next) s1 (uuid/next) pi-with (fn [objects] {p1 {:id p1 :name "P1" :objects {}} p2 {:id p2 :name "P2" :objects objects}}) base (pages-data (pi-with {}) [p1 p2]) - main (pages-data {p1 {:id p1 :name "P1" :objects {}}} [p1]) + source (pages-data {p1 {:id p1 :name "P1" :objects {}}} [p1]) branch (pages-data (pi-with {s1 {:id s1 :name "New"}}) [p1 p2]) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) conflict (first (filter #(= :page (:kind %)) conflicts))] (t/is (= :modify-delete (:reason conflict))) ;; resolved to :branch -> the full branch page is re-added - (let [{:keys [changes]} (bm/compute-changes base main branch {p2 :branch}) + (let [{:keys [changes]} (bm/compute-changes base source branch {p2 :branch}) add (first (filter #(= :add-page (:type %)) changes))] (t/is (= p2 (get-in add [:page :id]))) (t/is (contains? (get-in add [:page :objects]) s1))))) (t/deftest page-clean-delete-still-clean - ;; branch deletes a page main did not touch -> clean delete, no conflict + ;; branch deletes a page the source did not touch -> clean delete, no conflict (let [p1 (uuid/next) p2 (uuid/next) pi {p1 {:id p1 :name "P1" :objects {}} p2 {:id p2 :name "P2" :objects {}}} @@ -1205,45 +1205,45 @@ ;;; --- Regression tests: token-set delete-vs-modify --- -(t/deftest token-set-deleted-in-branch-edited-in-main-conflicts +(t/deftest token-set-deleted-in-branch-edited-in-source-conflicts (let [sid (uuid/next) tid (uuid/next) base-lib (token-lib sid tid "#ff0000") - ;; main edits a token inside the set the branch deletes - main-lib (ctob/update-token base-lib sid tid + ;; the source edits a token inside the set the branch deletes + source-lib (ctob/update-token base-lib sid tid (fn [t] (ctob/make-token (assoc (into {} t) :value "#00ff00")))) branch-lib (ctob/delete-set base-lib sid) base (with-tokens base-lib) - main (with-tokens main-lib) + source (with-tokens source-lib) branch (with-tokens branch-lib) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) conflict (first (filter #(= :token-set (:kind %)) conflicts))] (t/is (some? conflict)) (t/is (= :delete-modify (:reason conflict))) ;; no redundant token-level conflicts for the deleted set (t/is (= [] (filterv #(= :token (:kind %)) conflicts))) ;; resolved to :branch -> set deleted; to :source -> set (and token) kept - (let [{:keys [changes]} (bm/compute-changes base main branch {sid :branch})] + (let [{:keys [changes]} (bm/compute-changes base source branch {sid :branch})] (t/is (some #(and (= :set-token-set (:type %)) (nil? (:attrs %))) changes))) - (let [{:keys [changes]} (bm/compute-changes base main branch {sid :source})] + (let [{:keys [changes]} (bm/compute-changes base source branch {sid :source})] (t/is (= [] (filterv #(= :set-token-set (:type %)) changes))) (t/is (= [] (filterv #(= :set-token (:type %)) changes)))))) -(t/deftest token-set-deleted-in-main-edited-in-branch-restores +(t/deftest token-set-deleted-in-source-edited-in-branch-restores (let [sid (uuid/next) tid (uuid/next) base-lib (token-lib sid tid "#ff0000") - main-lib (ctob/delete-set base-lib sid) + source-lib (ctob/delete-set base-lib sid) branch-lib (ctob/update-token base-lib sid tid (fn [t] (ctob/make-token (assoc (into {} t) :value "#0000ff")))) base (with-tokens base-lib) - main (with-tokens main-lib) + source (with-tokens source-lib) branch (with-tokens branch-lib) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) conflict (first (filter #(= :token-set (:kind %)) conflicts))] (t/is (= :modify-delete (:reason conflict))) ;; resolved to :branch -> the set is re-created WITH its tokens - (let [{:keys [changes]} (bm/compute-changes base main branch {sid :branch}) + (let [{:keys [changes]} (bm/compute-changes base source branch {sid :branch}) restore (first (filter #(and (= :set-token-set (:type %)) (some? (:attrs %))) changes)) - data' (cfc/process-changes (with-tokens main-lib) changes)] + data' (cfc/process-changes (with-tokens source-lib) changes)] (t/is (some? restore)) (t/is (seq (get-in restore [:attrs :tokens]))) (t/is (= "#0000ff" (:value (ctob/get-token (:tokens-lib data') sid tid))))))) @@ -1253,11 +1253,11 @@ ;; bring the branch's :selrect/:points so geometry stays consistent (let [base (mkdata {:s1 {:id :s1 :name "A" :x 0 :selrect {:x 0} :points [{:x 0}]}}) - main (mkdata {:s1 {:id :s1 :name "MAIN" :x 0 + source (mkdata {:s1 {:id :s1 :name "SOURCE" :x 0 :selrect {:x 0} :points [{:x 0}]}}) branch (mkdata {:s1 {:id :s1 :name "A" :x 100 :selrect {:x 100} :points [{:x 100}]}}) - {:keys [changes]} (bm/compute-changes base main branch + {:keys [changes]} (bm/compute-changes base source branch {:s1 {:x :branch :name :source}}) ops (->> changes (filter #(= :mod-obj (:type %))) @@ -1276,9 +1276,9 @@ mk (fn [name] {:id :s1 :name name :type :frame :selrect selrect :points [{:x 0 :y 0}] :shapes []}) base (mkdata {:s1 (mk "A")}) - main (mkdata {:s1 (mk "MAIN")}) + source (mkdata {:s1 (mk "SOURCE")}) branch (mkdata {:s1 (mk "BRANCH")}) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) c (first conflicts)] (t/is (= :modify-modify (:reason c))) ;; changed-attrs stay noise-free (no derived attrs) @@ -1287,17 +1287,17 @@ (t/is (= selrect (get-in c [:base :selrect]))) (t/is (= selrect (get-in c [:source :selrect]))) (t/is (= selrect (get-in c [:branch :selrect]))) - (t/is (= "MAIN" (get-in c [:source :name]))) + (t/is (= "SOURCE" (get-in c [:source :name]))) (t/is (= "BRANCH" (get-in c [:branch :name]))))) (t/deftest source->branch-conflict-sides-name-the-documents ;; A conflict descriptor names the DOCUMENTS in both directions: `:source` - ;; is main's value and `:branch` the branch's, the `:changed-attrs` + ;; is the source's value and `:branch` the branch's, the `:changed-attrs` ;; pairs included. (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}}) - r (bm/compute-merge base main branch :source->branch) + r (bm/compute-merge base source branch :source->branch) c (first (:conflicts r))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= :modify-modify (:reason c))) @@ -1306,22 +1306,22 @@ (t/is (= {:source "green" :branch "blue"} (get-in c [:changed-attrs :fill]))))) (t/deftest delete-reasons-name-the-same-side-in-both-directions - ;; `:delete-modify` names the branch's deletion against main's + ;; `:delete-modify` names the branch's deletion against the source's ;; modification, `:modify-delete` the branch's modification against - ;; main's deletion — the same meaning in both directions. + ;; the source's deletion — the same meaning in both directions. (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) + source (mkdata {:s1 {:id :s1 :name "A" :fill "green"}}) branch (mkdata {}) - r (bm/compute-merge base main branch :source->branch) + r (bm/compute-merge base source branch :source->branch) c (first (:conflicts r))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= :delete-modify (:reason c))) (t/is (= "green" (get-in c [:source :fill]))) (t/is (nil? (:branch c)))) (let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}}) - main (mkdata {}) + source (mkdata {}) branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}}) - r (bm/compute-merge base main branch :source->branch) + r (bm/compute-merge base source branch :source->branch) c (first (:conflicts r))] (t/is (= 1 (-> r :stats :conflicts))) (t/is (= :modify-delete (:reason c))) @@ -1406,20 +1406,20 @@ (update-in data [:pages-index (tree-page-id data)] ctst/delete-shape id true)) (defn- merged - "Merge `branch` into `main` under `resolutions` and apply the changes - to main through the production change pipeline." - [base main branch resolutions] - (let [{:keys [changes unsupported]} (bm/compute-changes base main branch resolutions)] + "Merge `branch` into `source` under `resolutions` and apply the changes + to the source through the production change pipeline." + [base source branch resolutions] + (let [{:keys [changes unsupported]} (bm/compute-changes base source branch resolutions)] {:unsupported unsupported :changes changes - :data (cfc/process-changes main changes)})) + :data (cfc/process-changes source changes)})) (defn- policies [k v] (assoc bm/default-policies k v)) (t/deftest same-parent-reorder-merge-is-shown-and-applied - ;; ws1: base and main hold [A B] in F and the branch [B A]. Under the + ;; ws1: base and the source hold [A B] in F and the branch [B A]. Under the ;; default `:merge` the reorder is a modification of F and lands. (let [f (uuid/next) a (uuid/next) b (uuid/next) m (uuid/next) base (tree-data [f nil :frame "F"] [a f :rect "A"] [b f :rect "B"]) @@ -1433,33 +1433,33 @@ (t/is (empty? unsupported)) (t/is (= [b a] (tree-children data f))) - (t/testing "main adding a child to F is not a conflict and keeps its slot" - (let [main (tree-add base m f :rect "M") - r (bm/compute-merge base main branch :branch->source)] + (t/testing "the source adding a child to F is not a conflict and keeps its slot" + (let [source (tree-add base m f :rect "M") + r (bm/compute-merge base source branch :branch->source)] (t/is (= [] (:conflicts r))) - (t/is (= [b a m] (tree-children (:data (merged base main branch {})) f))))) + (t/is (= [b a m] (tree-children (:data (merged base source branch {})) f))))) - (t/testing "update from main reports and applies main's reorder" - (let [main (tree-edit base assoc-in [f :shapes] [b a]) - r (bm/compute-merge base main base :source->branch)] + (t/testing "update from the source reports and applies the source's reorder" + (let [source (tree-edit base assoc-in [f :shapes] [b a]) + r (bm/compute-merge base source base :source->branch)] (t/is (= {:source [b a] :branch [a b]} (get-in (first (:changes r)) [:changed-attrs :shapes]))) - (t/is (= [b a] (tree-children (:data (merged base base main {})) f))))))) + (t/is (= [b a] (tree-children (:data (merged base base source {})) f))))))) (t/deftest same-parent-reorder-merge-both-sides-conflict ;; both sides reorder F differently: a conflict on F whose resolution ;; picks the order (let [f (uuid/next) a (uuid/next) b (uuid/next) c (uuid/next) base (tree-data [f nil :frame "F"] [a f :rect "A"] [b f :rect "B"] [c f :rect "C"]) - main (tree-edit base assoc-in [f :shapes] [c a b]) + source (tree-edit base assoc-in [f :shapes] [c a b]) branch (tree-edit base assoc-in [f :shapes] [b a c]) - {:keys [conflicts]} (bm/compute-merge base main branch :branch->source) + {:keys [conflicts]} (bm/compute-merge base source branch :branch->source) cf (first conflicts)] (t/is (= [[f :modify-modify]] (mapv (juxt :id :reason) conflicts))) (t/is (= {:source [c a b] :branch [b a c]} (get-in cf [:changed-attrs :shapes]))) - (t/is (= [b a c] (tree-children (:data (merged base main branch {f :branch})) f))) - (t/is (= [c a b] (tree-children (:data (merged base main branch {f :source})) f))) - (t/is (= [b a c] (tree-children (:data (merged base main branch {f {:shapes :branch}})) f))))) + (t/is (= [b a c] (tree-children (:data (merged base source branch {f :branch})) f))) + (t/is (= [c a b] (tree-children (:data (merged base source branch {f :source})) f))) + (t/is (= [b a c] (tree-children (:data (merged base source branch {f {:shapes :branch}})) f))))) (t/deftest same-parent-reorder-refuse ;; `:refuse`: the reorder is an `:unsupported` entry naming F, so the @@ -1488,52 +1488,52 @@ (t/is (= [a b] (tree-children (:data (merged base base branch {})) f)))))) (t/deftest added-siblings-keep-the-branch-order - ;; ws1: main adds Z at index 0 of F, the branch adds siblings to F. The + ;; ws1: the source adds Z at index 0 of F, the branch adds siblings to F. The ;; merged F holds the branch's siblings in the branch's order. (let [f (uuid/custom 9 100) z (uuid/custom 9 200) ss (mapv #(uuid/custom 9 %) (range 1 9)) base (tree-data [f nil :frame "F"]) - main (tree-add base z f :rect "Z" :index 0) + source (tree-add base z f :rect "Z" :index 0) branch (reduce (fn [d [i s]] (tree-add d s f :rect (str "S" i))) base (map-indexed vector ss)) - out (tree-children (:data (merged base main branch {})) f)] + out (tree-children (:data (merged base source branch {})) f)] (t/is (= ss (filterv (set ss) out))) (t/is (= (inc (count ss)) (count out))))) (t/deftest addition-under-deleted-parent-conflict - ;; ws1: main deletes frame P, the branch adds M inside P. Default + ;; ws1: the source deletes frame P, the branch adds M inside P. Default ;; `:conflict`: a `:modify-delete` conflict on P; `:branch` restores P as ;; the branch has it, `:source` drops M. (let [p (uuid/next) c (uuid/next) m (uuid/next) base (tree-data [p nil :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-add base m p :rect "M") - r (bm/compute-merge base main branch :branch->source) + r (bm/compute-merge base source branch :branch->source) cf (first (:conflicts r))] (t/is (= [[p :modify-delete]] (mapv (juxt :id :reason) (:conflicts r)))) (t/is (= [{:id m :label "M"}] (:subtree-edits cf))) (t/is (= "P" (get-in cf [:branch :name]))) (t/is (not-any? #(= m (:id %)) (:changes r))) - (let [objs (tree-objects (:data (merged base main branch {p :branch})))] + (let [objs (tree-objects (:data (merged base source branch {p :branch})))] (t/is (= [p] (get-in objs [uuid/zero :shapes]))) (t/is (= [c m] (get-in objs [p :shapes]))) (t/is (= p (get-in objs [m :parent-id])))) - (let [objs (tree-objects (:data (merged base main branch {p :source})))] + (let [objs (tree-objects (:data (merged base source branch {p :source})))] (t/is (= #{uuid/zero} (set (keys objs))))))) (t/deftest addition-under-deleted-parent-conflict-lifts-restores - ;; ws1: main deletes frame P, the branch renames its child C. The + ;; ws1: the source deletes frame P, the branch renames its child C. The ;; conflict sits on P, and `:branch` restores P around C instead of ;; putting C on the page root. (let [p (uuid/next) c (uuid/next) base (tree-data [p nil :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-edit base assoc-in [c :name] "C renamed") - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [[p :modify-delete]] (mapv (juxt :id :reason) (:conflicts r)))) (t/is (= [{:id c :label "C renamed"}] (:subtree-edits (first (:conflicts r))))) - (let [objs (tree-objects (:data (merged base main branch {p :branch})))] + (let [objs (tree-objects (:data (merged base source branch {p :branch})))] (t/is (= [p] (get-in objs [uuid/zero :shapes]))) (t/is (= p (get-in objs [c :parent-id]))) (t/is (= "C renamed" (get-in objs [c :name])))))) @@ -1544,32 +1544,32 @@ (binding [bm/*policies* (policies :addition-under-deleted-parent :refuse)] (let [p (uuid/next) c (uuid/next) m (uuid/next) base (tree-data [p nil :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-add base m p :rect "M") - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] ;; every summary entry carries its `change-key` as well (the compare ;; panel selects by it); the refusal content is what this asserts (t/is (= [{:kind :shape-orphan :status :unsupported :id p :page-id (tree-page-id base) :label "P" :policy :addition-under-deleted-parent :shapes [m]}] (mapv #(dissoc % :key) (filterv #(= :unsupported (:status %)) (:changes r))))) - (t/is (= #{:shape-orphan} (:unsupported (bm/compute-changes base main branch {})))) + (t/is (= #{:shape-orphan} (:unsupported (bm/compute-changes base source branch {})))) (let [branch (tree-edit base assoc-in [c :name] "C renamed")] (t/is (= [[c :modify-delete]] - (mapv (juxt :id :reason) (:conflicts (bm/compute-merge base main branch :branch->source))))) - (t/is (= #{:shape-orphan} (:unsupported (bm/compute-changes base main branch {c :branch})))) - (t/is (empty? (:unsupported (bm/compute-changes base main branch {c :source})))))))) + (mapv (juxt :id :reason) (:conflicts (bm/compute-merge base source branch :branch->source))))) + (t/is (= #{:shape-orphan} (:unsupported (bm/compute-changes base source branch {c :branch})))) + (t/is (empty? (:unsupported (bm/compute-changes base source branch {c :source})))))))) (t/deftest addition-under-deleted-parent-reparent-to-ancestor - ;; `:reparent-to-ancestor`: main deletes P inside board G; the branch's + ;; `:reparent-to-ancestor`: the source deletes P inside board G; the branch's ;; addition M and a restored C land under G, where P was (binding [bm/*policies* (policies :addition-under-deleted-parent :reparent-to-ancestor)] (let [g (uuid/next) h (uuid/next) p (uuid/next) c (uuid/next) m (uuid/next) base (tree-data [g nil :frame "G"] [h g :rect "H"] [p g :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-add base m p :rect "M") - r (bm/compute-merge base main branch :branch->source) - {:keys [data unsupported]} (merged base main branch {}) + r (bm/compute-merge base source branch :branch->source) + {:keys [data unsupported]} (merged base source branch {}) objs (tree-objects data)] (t/is (= [] (:conflicts r))) (t/is (empty? unsupported)) @@ -1577,7 +1577,7 @@ (t/is (= g (get-in objs [m :parent-id]))) (t/is (= g (get-in objs [m :frame-id]))) (let [branch (tree-edit base assoc-in [c :name] "C renamed") - objs (tree-objects (:data (merged base main branch {c :branch})))] + objs (tree-objects (:data (merged base source branch {c :branch})))] (t/is (= [h c] (get-in objs [g :shapes]))) (t/is (= g (get-in objs [c :frame-id]))))))) @@ -1586,87 +1586,87 @@ (binding [bm/*policies* (policies :addition-under-deleted-parent :page-root)] (let [p (uuid/next) c (uuid/next) m (uuid/next) base (tree-data [p nil :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-add base m p :rect "M") - objs (tree-objects (:data (merged base main branch {})))] - (t/is (= [] (:conflicts (bm/compute-merge base main branch :branch->source)))) + objs (tree-objects (:data (merged base source branch {})))] + (t/is (= [] (:conflicts (bm/compute-merge base source branch :branch->source)))) (t/is (= [m] (get-in objs [uuid/zero :shapes]))) (t/is (= uuid/zero (get-in objs [m :parent-id])))))) (defn- container-delete-case - "ws1: the branch deletes frame F, main recolours its child C and adds N + "ws1: the branch deletes frame F, the source recolours its child C and adds N inside it; D is an untouched child of F and K a sibling of F." [] (let [f (uuid/next) c (uuid/next) d (uuid/next) n (uuid/next) k (uuid/next) base (tree-data [k nil :rect "K"] [f nil :frame "F"] [c f :rect "C"] [d f :rect "D"]) - main (-> base + source (-> base (tree-edit assoc-in [c :fills] [{:fill-color "#FF0000" :fill-opacity 1}]) (tree-add n f :rect "N")) branch (tree-delete base f)] - {:f f :c c :d d :n n :k k :base base :main main :branch branch})) + {:f f :c c :d d :n n :k k :base base :source source :branch branch})) -(t/deftest container-delete-over-main-edits-conflict +(t/deftest container-delete-over-target-edits-conflict ;; default `:conflict`: one `:delete-modify` conflict on F. `:source` keeps - ;; F and its subtree as main has them, `:branch` deletes it all. - (let [{:keys [f c d n k base main branch]} (container-delete-case) - r (bm/compute-merge base main branch :branch->source)] + ;; F and its subtree as the source has them, `:branch` deletes it all. + (let [{:keys [f c d n k base source branch]} (container-delete-case) + r (bm/compute-merge base source branch :branch->source)] (t/is (= [[f :delete-modify]] (mapv (juxt :id :reason) (:conflicts r)))) (t/is (= #{c n} (set (map :id (:subtree-edits (first (:conflicts r))))))) (t/is (= [] (:changes r))) - (let [objs (tree-objects (:data (merged base main branch {f :source})))] + (let [objs (tree-objects (:data (merged base source branch {f :source})))] (t/is (= [k f] (get-in objs [uuid/zero :shapes]))) (t/is (= [c d n] (get-in objs [f :shapes]))) (t/is (= "#FF0000" (get-in objs [c :fills 0 :fill-color])))) - (let [objs (tree-objects (:data (merged base main branch {f :branch})))] + (let [objs (tree-objects (:data (merged base source branch {f :branch})))] (t/is (= #{uuid/zero k} (set (keys objs))))))) -(t/deftest container-delete-over-main-edits-expand - ;; `:expand`: only what the branch deleted goes; main's addition N, and +(t/deftest container-delete-over-target-edits-expand + ;; `:expand`: only what the branch deleted goes; the source's addition N, and ;; C when its conflict is resolved to `:source`, move to F's parent where ;; F was - (binding [bm/*policies* (policies :container-delete-over-main-edits :expand)] - (let [{:keys [f c d n k base main branch]} (container-delete-case) - r (bm/compute-merge base main branch :branch->source)] + (binding [bm/*policies* (policies :container-delete-over-target-edits :expand)] + (let [{:keys [f c d n k base source branch]} (container-delete-case) + r (bm/compute-merge base source branch :branch->source)] (t/is (= [[c :delete-modify]] (mapv (juxt :id :reason) (:conflicts r)))) (t/is (= #{f d} (set (map :id (:changes r))))) - (let [objs (tree-objects (:data (merged base main branch {c :source})))] + (let [objs (tree-objects (:data (merged base source branch {c :source})))] (t/is (= [k c n] (get-in objs [uuid/zero :shapes]))) (t/is (= #{uuid/zero k c n} (set (keys objs)))) (t/is (= uuid/zero (get-in objs [n :frame-id]))) (t/is (= "#FF0000" (get-in objs [c :fills 0 :fill-color])))) - (let [objs (tree-objects (:data (merged base main branch {c :branch})))] + (let [objs (tree-objects (:data (merged base source branch {c :branch})))] (t/is (= [k n] (get-in objs [uuid/zero :shapes]))))))) -(t/deftest container-delete-over-main-edits-cascade - ;; `:cascade`: F goes with its whole subtree, main's edits included - (binding [bm/*policies* (policies :container-delete-over-main-edits :cascade)] - (let [{:keys [f c d k base main branch]} (container-delete-case) - r (bm/compute-merge base main branch :branch->source)] +(t/deftest container-delete-over-target-edits-cascade + ;; `:cascade`: F goes with its whole subtree, the source's edits included + (binding [bm/*policies* (policies :container-delete-over-target-edits :cascade)] + (let [{:keys [f c d k base source branch]} (container-delete-case) + r (bm/compute-merge base source branch :branch->source)] (t/is (= [[c :delete-modify]] (mapv (juxt :id :reason) (:conflicts r)))) (t/is (= #{f d} (set (map :id (filter #(= :deleted (:status %)) (:changes r)))))) - (let [objs (tree-objects (:data (merged base main branch {c :source})))] + (let [objs (tree-objects (:data (merged base source branch {c :source})))] (t/is (= #{uuid/zero k} (set (keys objs)))))))) ;;; --- Regression tests: mov-page indexes --- (t/deftest compute-changes-page-order-counts-full-pages ;; `:mov-page :index` counts the FULL :pages vector as it is when the op - ;; runs: a page main added keeps its slot while the common pages reorder + ;; runs: a page the source added keeps its slot while the common pages reorder ;; to branch's order around it. Counting the common-pages order instead ;; pushed such a page out of its slot (to the end). (let [p1 (uuid/next) p2 (uuid/next) p3 (uuid/next) x (uuid/next) page (fn [id n] {:id id :name n :objects {}}) pages3 {p1 (page p1 "P1") p2 (page p2 "P2") p3 (page p3 "P3")} pages4 (assoc pages3 x (page x "X")) - order (fn [main-pages] + order (fn [source-pages] (let [base (pages-data pages3 [p1 p2 p3]) - main (pages-data pages4 main-pages) + source (pages-data pages4 source-pages) branch (pages-data pages3 [p1 p3 p2]) - {:keys [changes]} (bm/compute-changes base main branch)] - (:pages (cfc/process-changes main changes))))] - ;; main's extra page at the end: the reorder comes out right + {:keys [changes]} (bm/compute-changes base source branch)] + (:pages (cfc/process-changes source changes))))] + ;; the source's extra page at the end: the reorder comes out right (t/is (= [p1 p3 p2 x] (order [p1 p2 p3 x]))) - ;; main's extra page interleaved: it keeps its slot + ;; the source's extra page interleaved: it keeps its slot (t/is (= [p1 x p3 p2] (order [p1 x p2 p3]))) (t/is (= [x p1 p3 p2] (order [x p1 p2 p3]))))) @@ -1675,7 +1675,7 @@ (t/deftest compute-changes-page-meta-clear-carries-nil ;; a branch that renames a page and clears its background must REMOVE the ;; background: `mod-page` removes only on an explicit nil, so the change - ;; carries it — an absent key would leave main's background in place + ;; carries it — an absent key would leave the source's background in place (let [pid (uuid/next) base (pages-data {pid {:id pid :name "P" :objects {} :background "#ff0000"}} [pid]) branch (assoc-in base [:pages-index pid] {:id pid :name "Renamed" :objects {}}) @@ -1692,45 +1692,45 @@ ;;; --- Regression tests: per-attr resolution on flat collections --- (t/deftest compute-changes-per-attr-removes-missing-attr - ;; main added an :opacity the branch does not carry; resolving that attr + ;; the source added an :opacity the branch does not carry; resolving that attr ;; to :branch takes branch's state, where the attr is ABSENT — the shape ;; `schema:library-color` expresses removal with (closed map: optional ;; keys, never nil values) (let [cid (uuid/next) base (mkdata {} :colors {cid {:id cid :name "A" :color "#ff0000"}}) - main (mkdata {} :colors {cid {:id cid :name "A" :color "#ff0000" :opacity 0.5}}) + source (mkdata {} :colors {cid {:id cid :name "A" :color "#ff0000" :opacity 0.5}}) branch (mkdata {} :colors {cid {:id cid :name "Brnc" :color "#ff0000"}}) - {:keys [changes]} (bm/compute-changes base main branch {cid {:name :branch :opacity :branch}}) + {:keys [changes]} (bm/compute-changes base source branch {cid {:name :branch :opacity :branch}}) color (-> (group-by :type changes) :mod-color first :color)] (t/is (= "Brnc" (:name color))) (t/is (not (contains? color :opacity))) ;; round-trip: the applied color carries no :opacity either - (let [data' (cfc/process-changes main changes)] + (let [data' (cfc/process-changes source changes)] (t/is (not (contains? (get-in data' [:colors cid]) :opacity)))))) ;;; --- Regression tests: token-set order vs renames --- (t/deftest compute-changes-token-set-order-after-rename - ;; main renamed alpha to ALPHA while the branch reordered to [beta alpha]: + ;; the source renamed alpha to ALPHA while the branch reordered to [beta alpha]: ;; the moves must address the sets by the names they carry AFTER the - ;; emitted renames settle (main's rename stands), else `move-set` finds no + ;; emitted renames settle (the source's rename stands), else `move-set` finds no ;; set at the stale name and the reorder silently drops (let [a (uuid/next) b (uuid/next) base-lib (-> (ctob/make-tokens-lib) (ctob/add-set (ctob/make-token-set {:id a :name "alpha"})) (ctob/add-set (ctob/make-token-set {:id b :name "beta"}))) - main-lib (ctob/update-set base-lib a + source-lib (ctob/update-set base-lib a (fn [s] (ctob/make-token-set {:id (ctob/get-id s) :name "ALPHA" :tokens (ctob/get-tokens base-lib a)}))) branch-lib (ctob/move-set base-lib ["beta"] ["beta"] ["alpha"] false) {:keys [changes unsupported]} (bm/compute-changes (with-tokens base-lib) - (with-tokens main-lib) + (with-tokens source-lib) (with-tokens branch-lib)) - data' (cfc/process-changes {:tokens-lib main-lib} changes)] + data' (cfc/process-changes {:tokens-lib source-lib} changes)] (t/is (empty? unsupported)) (t/is (seq (filter #(= :move-token-set (:type %)) changes))) - ;; the reorder survives main's rename + ;; the reorder survives the source's rename (t/is (= ["beta" "ALPHA"] (mapv ctob/get-name (ctob/get-sets (:tokens-lib data'))))))) ;;; --- Regression tests: shape-pass refusals --- @@ -1743,21 +1743,21 @@ (binding [bm/*policies* (policies :addition-under-deleted-parent :refuse)] (let [p (uuid/next) c (uuid/next) m (uuid/next) base (tree-data [p nil :frame "P"] [c p :rect "C"]) - main (tree-delete base p) + source (tree-delete base p) branch (tree-add base m p :rect "M") - {:keys [unsupported]} (bm/compute-changes base main branch {} {:changes [] :conflicts []})] + {:keys [unsupported]} (bm/compute-changes base source branch {} {:changes [] :conflicts []})] (t/is (= #{:shape-orphan} unsupported))))) ;;; --- Selective merge: the exclusion set (`bm/change-key`) --- (defn- orphan-parents "Parent ids a change creates or moves a shape under that nothing the - merge emits provides: absent from `main` and never created by the + merge emits provides: absent from `source` and never created by the change list. A non-empty result is an orphan the translation let through." - [main changes] + [source changes] (let [created (into #{} (comp (filter #(= :add-obj (:type %))) (map :id)) changes) - kept (into created (keys (tree-objects main)))] + kept (into created (keys (tree-objects source)))] (into #{} (comp (filter #(contains? #{:add-obj :mov-objects} (:type %))) (map :parent-id) @@ -1814,17 +1814,17 @@ (let [a (uuid/next) pid (uuid/custom 7 1) base (tree-data [a nil :rect "A"]) - main (tree-edit base assoc-in [a :name] "main") + source (tree-edit base assoc-in [a :name] "source") branch (tree-edit base assoc-in [a :name] "branch") ka (bm/change-key {:kind :shape :page-id pid :id a})] - (t/is (= 1 (count (:conflicts (bm/compute-merge base main branch :branch->source))))) + (t/is (= 1 (count (:conflicts (bm/compute-merge base source branch :branch->source))))) (t/testing "a :branch resolution still applies while the change is included" - (t/is (= 1 (count (:changes (bm/compute-changes base main branch {a :branch} nil #{})))))) + (t/is (= 1 (count (:changes (bm/compute-changes base source branch {a :branch} nil #{})))))) (t/testing "the exclusion is the recorded choice: the target keeps its value" - (let [{:keys [changes]} (bm/compute-changes base main branch {a :branch} nil #{ka}) - data (cfc/process-changes main changes)] + (let [{:keys [changes]} (bm/compute-changes base source branch {a :branch} nil #{ka}) + data (cfc/process-changes source changes)] (t/is (empty? changes)) - (t/is (= "main" (get-in (tree-objects data) [a :name]))))))) + (t/is (= "source" (get-in (tree-objects data) [a :name]))))))) (t/deftest excluding-an-addition-leaves-its-child-shapes-out (let [g (uuid/next) c1 (uuid/next) c2 (uuid/next) m (uuid/next) @@ -1856,49 +1856,49 @@ (t/is (empty? (orphan-parents base changes))))))) (t/deftest excluded-deletion-takes-no-relocation-with-it - ;; under `:container-delete-over-main-edits :expand` the target's shapes + ;; under `:container-delete-over-target-edits :expand` the target's shapes ;; move out of a container the source deleted before it goes; excluding ;; that deletion keeps the container and takes no relocation with it - (binding [bm/*policies* (policies :container-delete-over-main-edits :expand)] + (binding [bm/*policies* (policies :container-delete-over-target-edits :expand)] (let [f (uuid/next) x (uuid/next) pid (uuid/custom 7 1) base (tree-data [f nil :frame "F"] [x f :rect "X"]) ;; the source deletes F whole while the target renamed X branch (tree-delete base f) - main (tree-edit base assoc-in [x :name] "X renamed") + source (tree-edit base assoc-in [x :name] "X renamed") kf (bm/change-key {:kind :shape :page-id pid :id f})] (t/testing "without the exclusion the delete lands with its relocation" - (let [{:keys [changes]} (bm/compute-changes base main branch {} nil #{})] + (let [{:keys [changes]} (bm/compute-changes base source branch {} nil #{})] (t/is (= [f] (mapv :id (filter #(= :del-obj (:type %)) changes)))) (t/is (= 1 (count (filter #(= :mov-objects (:type %)) changes)))) - (t/is (empty? (orphan-parents main changes))))) + (t/is (empty? (orphan-parents source changes))))) (t/testing "the excluded container survives and nothing relocates out of it" - (let [{:keys [changes]} (bm/compute-changes base main branch {} nil #{kf})] + (let [{:keys [changes]} (bm/compute-changes base source branch {} nil #{kf})] (t/is (empty? (filter #(= :del-obj (:type %)) changes))) (t/is (empty? (filter #(= :mov-objects (:type %)) changes))) - (t/is (empty? (orphan-parents main changes)))))))) + (t/is (empty? (orphan-parents source changes)))))))) (t/deftest squashed-net-replays-the-updated-branch - ;; the update-from-main invariant: whatever the exclusion keeps out of + ;; the update-from-source invariant: whatever the exclusion keeps out of ;; the branch becomes a branch-side delta of the squashed net, so the ;; branch state still replays from its repositioned base (let [a (uuid/next) b (uuid/next) c (uuid/next) base (tree-data [a nil :rect "A"] [b nil :rect "B"]) - main (-> (tree-edit base assoc-in [a :name] "A-main") - (tree-edit assoc-in [b :name] "B-main")) + source (-> (tree-edit base assoc-in [a :name] "A-source") + (tree-edit assoc-in [b :name] "B-source")) branch (tree-add base c nil :rect "C") kb (bm/change-key {:kind :shape :page-id (uuid/custom 7 1) :id b}) - ;; source = main, target = branch (the update direction) - {incoming :changes} (bm/compute-changes base branch main {} nil #{kb}) + ;; compute-changes' source = the branch, its branch = the source file (the update direction) + {incoming :changes} (bm/compute-changes base branch source {} nil #{kb}) updated (cfc/process-changes branch incoming) - ;; the repositioned base is main's own state - new-base main + ;; the repositioned base is the source's own state + new-base source {net :changes unsupported :unsupported} (bm/compute-changes new-base new-base updated {})] (t/is (empty? unsupported)) (t/is (empty? (filter #(and (= :mod-obj (:type %)) (= b (:id %))) incoming))) (t/is (= 1 (count incoming))) - (t/testing "the excluded main work stays in the net as a branch-side delta" + (t/testing "the excluded source work stays in the net as a branch-side delta" (t/is (some #(and (= :mod-obj (:type %)) (= b (:id %))) net)) (t/is (some #(and (= :add-obj (:type %)) (= c (:id %))) net))) (t/testing "replaying the squashed net over the new base reproduces the branch" @@ -1927,22 +1927,22 @@ ;; follows the merged component, so the target keeps its value until ;; the sync after the merge sets it (let [base (mkdata {:k (copy-shape "red")}) - main (mkdata {:k (copy-shape "blue")}) + source (mkdata {:k (copy-shape "blue")}) branch (mkdata {:k (copy-shape "green")}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (empty? (:conflicts r))) (t/is (= [[:k :settled {:attrs {:fills {:side :source :reason :follows-component}} :token-slots {} :open-attrs #{} :open-token-slots #{}}]] (mapv (juxt :id :status :settled) (:changes r)))) (t/is (= {:added 0 :modified 0 :deleted 0 :conflicts 0} (:stats r))) - (t/is (empty? (copy-ops (:changes (bm/compute-changes base main branch {} r))))))) + (t/is (empty? (copy-ops (:changes (bm/compute-changes base source branch {} r))))))) (t/deftest copy-attr-the-source-overrode-wins (let [base (mkdata {:k (copy-shape "red")}) - main (mkdata {:k (copy-shape "blue")}) + source (mkdata {:k (copy-shape "blue")}) branch (mkdata {:k (copy-shape "green" :touched #{:fill-group})}) - r (bm/compute-merge base main branch :branch->source) - ops (copy-ops (:changes (bm/compute-changes base main branch {} r)))] + r (bm/compute-merge base source branch :branch->source) + ops (copy-ops (:changes (bm/compute-changes base source branch {} r)))] (t/is (empty? (:conflicts r))) (t/testing "the summary reports the override as a change the merge applies" (t/is (= [[:k :modified #{:fills}]] @@ -1954,47 +1954,47 @@ (t/deftest copy-attr-the-target-overrode-stays (let [base (mkdata {:k (copy-shape "red")}) - main (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) + source (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) branch (mkdata {:k (copy-shape "green")}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (empty? (:conflicts r))) (t/is (= [[:k :settled {:fills {:side :source :reason :override-source}}]] (mapv (juxt :id :status (comp :attrs :settled)) (:changes r)))) - (t/is (empty? (copy-ops (:changes (bm/compute-changes base main branch {} r))))))) + (t/is (empty? (copy-ops (:changes (bm/compute-changes base source branch {} r))))))) (t/deftest copy-attr-both-sides-overrode-is-a-conflict (let [base (mkdata {:k (copy-shape "red")}) - main (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) + source (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) branch (mkdata {:k (copy-shape "green" :touched #{:fill-group})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [:k] (mapv :id (:conflicts r)))) (t/is (= #{:fills} (set (keys (:changed-attrs (first (:conflicts r))))))) (t/testing "resolved to the branch, the copy takes its value and override" (t/is (= [{:type :set :attr :fills :val [{:fill-color "green"}] :ignore-touched true}] - (copy-ops (:changes (bm/compute-changes base main branch {:k :branch} r)))))))) + (copy-ops (:changes (bm/compute-changes base source branch {:k :branch} r)))))))) (t/deftest copy-conflict-narrows-to-the-attrs-both-sides-overrode ;; both overrode the fill; only the branch overrode the opacity: the ;; conflict asks about the fill, and the opacity comes from the branch ;; whatever the user picks (let [base (mkdata {:k (copy-shape "red" :opacity 1)}) - main (mkdata {:k (copy-shape "blue" :opacity 1 :touched #{:fill-group})}) + source (mkdata {:k (copy-shape "blue" :opacity 1 :touched #{:fill-group})}) branch (mkdata {:k (copy-shape "green" :opacity 0.5 :touched #{:fill-group :layer-effects-group})}) - r (bm/compute-merge base main branch :branch->source) - ops (copy-ops (:changes (bm/compute-changes base main branch {:k :source} r)))] + r (bm/compute-merge base source branch :branch->source) + ops (copy-ops (:changes (bm/compute-changes base source branch {:k :source} r)))] (t/is (= #{:fills} (set (keys (:changed-attrs (first (:conflicts r))))))) (t/is (= [{:type :set :attr :opacity :val 0.5 :ignore-touched true} {:type :set-touched :touched #{:fill-group :layer-effects-group}}] ops)))) -(t/deftest copy-rule-holds-updating-from-main - ;; the update direction: main is the source, the branch the target +(t/deftest copy-rule-holds-updating-from-source + ;; the update direction: the source file is the incoming side, the branch the target (let [base (mkdata {:k (copy-shape "red")}) - main (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) + source (mkdata {:k (copy-shape "blue" :touched #{:fill-group})}) branch (mkdata {:k (copy-shape "green")}) - r (bm/compute-merge base main branch :source->branch) - ops (copy-ops (:changes (bm/compute-changes base branch main {} r)))] + r (bm/compute-merge base source branch :source->branch) + ops (copy-ops (:changes (bm/compute-changes base branch source {} r)))] (t/is (empty? (:conflicts r))) (t/is (= [{:type :set :attr :fills :val [{:fill-color "blue"}] :ignore-touched true} {:type :set-touched :touched #{:fill-group}}] @@ -2002,7 +2002,7 @@ (t/deftest reset-of-a-base-override-clears-it-on-the-target ;; the base holds K's fill override; the branch reset it (the - ;; component's value, no `:fill-group`), main left K alone: the merge + ;; component's value, no `:fill-group`), the source left K alone: the merge ;; writes the value and clears the override, in that order, whatever ;; order the attr diff yields (let [base (mkdata {:k (copy-shape "red" :touched #{:fill-group})}) @@ -2010,14 +2010,14 @@ (t/is (= [{:type :set :attr :fills :val [{:fill-color "white"}] :ignore-touched true} {:type :set-touched :touched nil}] (copy-ops (:changes (bm/compute-changes base base branch))))) - (t/testing "updating from main, the same reset on main reaches the branch" + (t/testing "updating from the source, the same reset on the source reaches the branch" (t/is (= [{:type :set :attr :fills :val [{:fill-color "white"}] :ignore-touched true} {:type :set-touched :touched nil}] (copy-ops (:changes (bm/compute-changes base base branch {} (bm/compute-merge base branch base :source->branch))))))))) (t/deftest clean-copy-change-marks-no-override - ;; the branch synced K from its component and main left K alone: the + ;; the branch synced K from its component and the source left K alone: the ;; merge writes the value without marking it overridden (let [base (mkdata {:k (copy-shape "red")}) branch (mkdata {:k (copy-shape "green")})] @@ -2037,62 +2037,62 @@ (t/deftest copy-token-no-side-overrode-follows-the-component (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "blue"})}) + source (mkdata {:k (tokens-copy {:fill "blue"})}) branch (mkdata {:k (tokens-copy {:fill "green"})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (empty? (:conflicts r))) (t/is (= [[:k :settled {:fill {:side :source :reason :follows-component}}]] (mapv (juxt :id :status (comp :token-slots :settled)) (:changes r)))) - (t/is (empty? (copy-ops (:changes (bm/compute-changes base main branch {} r))))))) + (t/is (empty? (copy-ops (:changes (bm/compute-changes base source branch {} r))))))) (t/deftest copy-token-slots-settle-one-at-a-time - ;; main applied a fill token by hand, the branch a radius token by hand: + ;; the source applied a fill token by hand, the branch a radius token by hand: ;; each side's slot wins, and the copy carries both (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) + source (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) branch (mkdata {:k (tokens-copy {:r1 "round"} :touched #{:radius-group})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (empty? (:conflicts r))) (t/is (= [[:k :modified #{:applied-tokens}]] (mapv (juxt :id :status (comp set keys :changed-attrs)) (:changes r)))) (t/is (= [{:type :set :attr :applied-tokens :val {:fill "yellow" :r1 "round"} :ignore-touched true} {:type :set-touched :touched #{:fill-group :radius-group}}] - (copy-ops (:changes (bm/compute-changes base main branch {} r))))))) + (copy-ops (:changes (bm/compute-changes base source branch {} r))))))) (t/deftest copy-token-slot-both-sides-overrode-is-a-conflict ;; both applied a fill token by hand; only the branch a radius token: ;; the conflict asks about `:applied-tokens`, and the user's side ;; decides the fill slot only (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) + source (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) branch (mkdata {:k (tokens-copy {:fill "red" :r1 "round"} :touched #{:fill-group :radius-group})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= [:k] (mapv :id (:conflicts r)))) (t/is (contains? (:changed-attrs (first (:conflicts r))) :applied-tokens)) - (t/testing "resolved to main, the radius slot still comes from the branch" + (t/testing "resolved to the source, the radius slot still comes from the branch" (t/is (= {:fill "yellow" :r1 "round"} - (->> (copy-ops (:changes (bm/compute-changes base main branch + (->> (copy-ops (:changes (bm/compute-changes base source branch {:k {:applied-tokens :source :fills :source}} r))) (filter #(= :applied-tokens (:attr %))) first :val)))) (t/testing "resolved to the branch, both slots come from it" (t/is (= {:fill "red" :r1 "round"} - (->> (copy-ops (:changes (bm/compute-changes base main branch {:k :branch} r))) + (->> (copy-ops (:changes (bm/compute-changes base source branch {:k :branch} r))) (filter #(= :applied-tokens (:attr %))) first :val)))))) -(t/deftest copy-token-rule-holds-updating-from-main - ;; main (the source) applied a fill token to the copy by hand; the +(t/deftest copy-token-rule-holds-updating-from-source + ;; the source (the incoming side) applied a fill token to the copy by hand; the ;; branch synced its own component edit (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})}) + source (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})}) branch (mkdata {:k (tokens-copy {:fill "green"})}) - r (bm/compute-merge base main branch :source->branch)] + r (bm/compute-merge base source branch :source->branch)] (t/is (empty? (:conflicts r))) (t/is (= {:fill "red"} - (->> (copy-ops (:changes (bm/compute-changes base branch main {} r))) + (->> (copy-ops (:changes (bm/compute-changes base branch source {} r))) (filter #(= :applied-tokens (:attr %))) first :val))))) @@ -2135,25 +2135,25 @@ (defn- merge-copies "`bm/compute-merge` with the copies summary." - [base main branch dir] - (bm/compute-merge base main branch dir {:copies? true})) + [base source branch dir] + (bm/compute-merge base source branch dir {:copies? true})) (t/deftest copies-list-a-copy-the-other-side-added-as-following - ;; the branch edits the component, main adds a second copy: both + ;; the branch edits the component, the source adds a second copy: both ;; copies follow the merged component's fill (thi/test-fixture (fn [] (let [file (component-with-copy) branch (tho/update-color file :main-child "#00ff00") - main (thc/instantiate-component file :c1 :copy2) - r (merge-copies (:data file) (:data main) (:data branch) :branch->source)] + source (thc/instantiate-component file :c1 :copy2) + r (merge-copies (:data file) (:data source) (:data branch) :branch->source)] (t/is (= [{:component-id (thi/id :c1) :main-id (thi/id :main-root)}] (mapv #(select-keys % [:component-id :main-id]) (:copies r)))) (t/is (= {(thi/id :copy1) {:follows #{:fill-group} :keeps {} :token-slots {}} (thi/id :copy2) {:follows #{:fill-group} :keeps {} :token-slots {}}} (copies-of r))) (t/testing "without `:copies? true` the summary carries no copies" - (t/is (not (contains? (bm/compute-merge (:data file) (:data main) (:data branch) :branch->source) + (t/is (not (contains? (bm/compute-merge (:data file) (:data source) (:data branch) :branch->source) :copies)))))))) (t/deftest copies-show-the-override-one-side-keeps @@ -2162,11 +2162,11 @@ (let [file (component-with-copy) edited (tho/update-color file :main-child "#00ff00") override (tho/update-bottom-color file :copy1 "#ff0000")] - (t/testing "merging: the branch edits the component, main overrides the copy" + (t/testing "merging: the branch edits the component, the source overrides the copy" (let [r (merge-copies (:data file) (:data override) (:data edited) :branch->source)] (t/is (= {(thi/id :copy1) {:follows #{} :keeps {:fill-group :source} :token-slots {}}} (copies-of r))))) - (t/testing "updating: main edits the component, the branch overrides the copy" + (t/testing "updating: the source edits the component, the branch overrides the copy" (let [r (merge-copies (:data file) (:data edited) (:data override) :source->branch)] (t/is (= {(thi/id :copy1) {:follows #{} :keeps {:fill-group :branch} :token-slots {}}} (copies-of r))))))))) @@ -2177,29 +2177,29 @@ (let [file (component-with-copy)] (doseq [label [:main-root :main-child]] (t/testing (name label) - (let [main (tho/update-color file label "#0000ff") + (let [source (tho/update-color file label "#0000ff") branch (tho/update-color file label "#00ff00") - r (merge-copies (:data file) (:data main) (:data branch) :branch->source)] + r (merge-copies (:data file) (:data source) (:data branch) :branch->source)] (t/is (= [[(thi/id label) 1]] (mapv (juxt :id :copies-affected) (:conflicts r))))))) (t/testing "a copy keeping its override of the conflict's group is not affected" - ;; main overrides copy1's child fill; copy2 follows everything + ;; the source overrides copy1's child fill; copy2 follows everything (let [base (thc/instantiate-component file :c1 :copy2)] (doseq [[label affected] [[:main-child 1] [:main-root 2]]] (t/testing (name label) - (let [main (-> base + (let [source (-> base (tho/update-bottom-color :copy1 "#ff0000") (tho/update-color label "#0000ff")) branch (tho/update-color base label "#00ff00") - r (merge-copies (:data base) (:data main) (:data branch) :branch->source)] + r (merge-copies (:data base) (:data source) (:data branch) :branch->source)] (t/is (= [[(thi/id label) affected]] (mapv (juxt :id :copies-affected) (:conflicts r))))))))) (t/testing "no copy follows the conflict's group: none is affected" - (let [main (-> file + (let [source (-> file (tho/update-bottom-color :copy1 "#ff0000") (tho/update-color :main-child "#0000ff")) branch (tho/update-color file :main-child "#00ff00") - r (merge-copies (:data file) (:data main) (:data branch) :branch->source)] + r (merge-copies (:data file) (:data source) (:data branch) :branch->source)] (t/is (= [[(thi/id :main-child) 0]] (mapv (juxt :id :copies-affected) (:conflicts r)))))))))) @@ -2242,19 +2242,19 @@ ;; both sides synced K from their own edit of the component, and the ;; branch edited S (let [base (mkdata {:k (copy-shape "red") :s {:id :s :name "S" :fill "red"}}) - main (mkdata {:k (copy-shape "blue") :s {:id :s :name "S" :fill "red"}}) + source (mkdata {:k (copy-shape "blue") :s {:id :s :name "S" :fill "red"}}) branch (mkdata {:k (copy-shape "green") :s {:id :s :name "S" :fill "blue"}}) - r (bm/compute-merge base main branch :branch->source) + r (bm/compute-merge base source branch :branch->source) settled (filterv bm/settled? (:changes r)) k-key (:key (first settled)) s-key (:key (first (remove bm/settled? (:changes r)))) unshown (update r :changes #(filterv (complement bm/settled?) %)) - changes (:changes (bm/compute-changes base main branch {} r))] + changes (:changes (bm/compute-changes base source branch {} r))] (t/is (= [[:k :settled]] (mapv (juxt :id :status) settled))) (t/is (= {:added 0 :modified 1 :deleted 0 :conflicts 0} (:stats r))) (t/testing "compute-changes ignores it, excluded or not" - (t/is (= changes (:changes (bm/compute-changes base main branch {} unshown)))) - (t/is (= changes (:changes (bm/compute-changes base main branch {} r #{k-key}))))) + (t/is (= changes (:changes (bm/compute-changes base source branch {} unshown)))) + (t/is (= changes (:changes (bm/compute-changes base source branch {} r #{k-key}))))) (t/testing "nothing-to-merge? ignores it" (t/is (not (bm/nothing-to-merge? r #{k-key}))) (t/is (true? (bm/nothing-to-merge? r #{s-key})))))) @@ -2262,10 +2262,10 @@ (t/deftest a-partly-settled-copy-conflict-names-what-stays-open (t/testing "attrs: both override the fill, only the branch the opacity" (let [base (mkdata {:k (copy-shape "red" :opacity 1)}) - main (mkdata {:k (copy-shape "blue" :opacity 1 :touched #{:fill-group})}) + source (mkdata {:k (copy-shape "blue" :opacity 1 :touched #{:fill-group})}) branch (mkdata {:k (copy-shape "green" :opacity 0.5 :touched #{:fill-group :layer-effects-group})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= {:attrs {:opacity {:side :branch :reason :override-branch}} :token-slots {} :open-attrs #{:fills} @@ -2273,20 +2273,20 @@ (:settled (first (:conflicts r))))))) (t/testing "token slots: both apply a fill token, only the branch a radius one" (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) + source (mkdata {:k (tokens-copy {:fill "yellow"} :touched #{:fill-group})}) branch (mkdata {:k (tokens-copy {:fill "red" :r1 "round"} :touched #{:fill-group :radius-group})}) - r (bm/compute-merge base main branch :branch->source)] + r (bm/compute-merge base source branch :branch->source)] (t/is (= {:attrs {} :token-slots {:r1 {:side :branch :reason :override-branch}} :open-attrs #{:applied-tokens :fills} :open-token-slots #{:fill}} (:settled (first (:conflicts r))))))) - (t/testing "updating from main, the sides name the documents" + (t/testing "updating from the source, the sides name the documents" (let [base (mkdata {:k (tokens-copy {})}) - main (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})}) + source (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})}) branch (mkdata {:k (tokens-copy {:fill "green"})}) - r (bm/compute-merge base main branch :source->branch)] + r (bm/compute-merge base source branch :source->branch)] (t/is (= [[:k :modified {:attrs {:fills {:side :source :reason :override-source}} :token-slots {:fill {:side :source :reason :override-source}} :open-attrs #{}