mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
Merge branch 'review-outlives-its-branch' into iop-vc-preview
# Conflicts: # backend/test/backend_tests/email_sending_test.clj
This commit is contained in:
commit
d119831c41
@ -186,14 +186,14 @@
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
<span style="font-weight:bold;">{{ source-user }}</span> has requested your review on the design review "{{ pull-request-title }}" ({{ pull-request-route }}).</div>
|
||||
<span style="font-weight:bold;">{{ source-user }}</span> has requested your review on the branch review "{{ review-title }}" ({{ review-route }}).</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div style="font-family:Source Sans Pro, sans-serif;font-size:16px;font-style:italic;line-height:150%;text-align:left;color:#212426;
|
||||
border-top: 1px solid #bfbfbf; border-bottom: 1px solid #bfbfbf; padding: 32px 0px;">
|
||||
{{ pull-request-description }}
|
||||
{{ review-description }}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -206,7 +206,7 @@
|
||||
<td align="center" bgcolor="#6911d4" role="presentation"
|
||||
style="border:none;border-radius:8px;cursor:auto;mso-padding-alt:10px 25px;background:#6911d4;"
|
||||
valign="middle">
|
||||
<a href="{{ pull-request-url }}"
|
||||
<a href="{{ review-url }}"
|
||||
style="display:inline-block;background:#6911d4;color:#FFFFFF;font-family:Source Sans Pro, sans-serif;font-size:16px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:8px;"
|
||||
target="_blank"> REVIEW THE CHANGES </a>
|
||||
</td>
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
Hello {{name|abbreviate:25}}!
|
||||
|
||||
{{ source-user }} has requested your review on the design review "{{ pull-request-title }}" ({{ pull-request-route }}).
|
||||
{{ source-user }} has requested your review on the branch review "{{ review-title }}" ({{ review-route }}).
|
||||
|
||||
--
|
||||
|
||||
{{ pull-request-description }}
|
||||
{{ review-description }}
|
||||
|
||||
--
|
||||
|
||||
{{ pull-request-url }}
|
||||
{{ review-url }}
|
||||
|
||||
The Penpot team.
|
||||
|
||||
@ -186,7 +186,7 @@
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
<span style="font-weight:bold;">{{ source-user }}</span> merged the branch "{{ branch-name }}" into "{{ file-name }}". Your open tasks moved to main as they were:</div>
|
||||
<span style="font-weight:bold;">{{ source-user }}</span> merged the branch "{{ branch-name }}" into "{{ file-name }}". Your open tasks are now on "{{ file-name }}":</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
1
backend/resources/app/email/tasks-merged/en.subj
Normal file
1
backend/resources/app/email/tasks-merged/en.subj
Normal file
@ -0,0 +1 @@
|
||||
Your tasks were merged
|
||||
@ -1,6 +1,6 @@
|
||||
Hello {{name|abbreviate:25}}!
|
||||
|
||||
{{ source-user }} merged the branch "{{ branch-name }}" into "{{ file-name }}". Your open tasks moved to main as they were:
|
||||
{{ source-user }} merged the branch "{{ branch-name }}" into "{{ file-name }}". Your open tasks are now on "{{ file-name }}":
|
||||
|
||||
{{ task-titles }}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Your tasks moved to main
|
||||
@ -4,7 +4,7 @@
|
||||
;; Optional: timeout in milliseconds, omitted means the thread waits for a
|
||||
;; permit forever, and a saturated limiter parks it for good. Values below:
|
||||
;; 60s for operations that can be slow (file updates, images, fonts, thumbnails,
|
||||
;; snapshots, imports, branches, pull requests) and 30s for the rest.
|
||||
;; snapshots, imports, branches, branch reviews) and 30s for the rest.
|
||||
;; Note: a queue bounds how many waiters pile up, a timeout bounds how long one
|
||||
;; waiter waits. Every entry sets a timeout and a queue: a command takes the
|
||||
;; limits it declares before the root ones, so the queue of a limit is where
|
||||
@ -99,20 +99,20 @@
|
||||
;; * `create-file-branch` realizes main once and writes one snapshot
|
||||
;; (`backend/src/app/rpc/commands/files_branch.clj::create-file-branch`),
|
||||
;; which is the anchor's shape and the anchor's cost.
|
||||
;; * `merge-file-branch` and `update-branch-from-main` hold three
|
||||
;; * `merge-file-branch` and `update-file-branch-from-source` hold three
|
||||
;; realized documents at once: main, the derived branch, and the base
|
||||
;; snapshot (`files_branch.clj::merge-file-branch`,
|
||||
;; `files_branch.clj::update-branch-from-main`). Both also write a
|
||||
;; `files_branch.clj::update-file-branch-from-source`). Both also write a
|
||||
;; snapshot and a whole file payload, and the update computes a
|
||||
;; second diff for the squash, so they earn the tightest count.
|
||||
;; * `materialize-file-branch` realizes the branch and the libraries it
|
||||
;; * `detach-file-branch` realizes the branch and the libraries it
|
||||
;; validates against, then writes the whole payload
|
||||
;; (`files_branch.clj::materialize-file-branch`), so it sits between
|
||||
;; (`files_branch.clj::detach-file-branch`), so it sits between
|
||||
;; the anchor and the merge pair.
|
||||
;; * `create-pull-request` and `update-pull-request-snapshot` realize the
|
||||
;; branch once and write one review snapshot
|
||||
;; (`files_pull_request.clj::create-pull-request`,
|
||||
;; `files_pull_request.clj::update-pull-request-snapshot`), which is
|
||||
;; * `create-branch-review` and `update-branch-review-revision` realize
|
||||
;; the branch once and write one review snapshot
|
||||
;; (`files_branch_review.clj::create-branch-review`,
|
||||
;; `files_branch_review.clj::update-branch-review-revision`), which is
|
||||
;; the anchor's shape again.
|
||||
;;
|
||||
;; The numbers here are example defaults, not measurements. Every entry
|
||||
@ -121,8 +121,8 @@
|
||||
;; warning (`climit.clj::wrap`). The write-side global queues
|
||||
;; follow the anchor's ratio of five waiters to three permits, rounded
|
||||
;; up. The per-profile entry of one permit and a queue of two keeps a
|
||||
;; single designer to one operation at a time. The two read-side
|
||||
;; entries are generous by design, with the ratio of
|
||||
;; single designer to one operation at a time. The read-side entries
|
||||
;; are generous by design, with the ratio of
|
||||
;; `:update-file/global` (fifty waiters to twenty permits), so a panel
|
||||
;; open waits for its turn instead of being refused: six
|
||||
;; three-document comparisons hold eighteen realized documents, fewer
|
||||
@ -157,20 +157,20 @@
|
||||
;; An update from main holds the same three documents and pays for a
|
||||
;; snapshot write and a squash diff on top, so it takes the merge's
|
||||
;; count. Provisional.
|
||||
:update-branch-from-main/global
|
||||
:update-file-branch-from-source/global
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
:update-branch-from-main/by-profile
|
||||
:update-file-branch-from-source/by-profile
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
;; Materialize realizes one document plus its libraries and writes the
|
||||
;; Detach realizes one document plus its libraries and writes the
|
||||
;; payload, which is cheaper than a merge and dearer than the anchor,
|
||||
;; so it admits two where the merge admits one and the anchor admits
|
||||
;; three. Provisional.
|
||||
:materialize-file-branch/global
|
||||
:detach-file-branch/global
|
||||
{:permits 2 :queue 4 :timeout 60000}
|
||||
|
||||
:materialize-file-branch/by-profile
|
||||
:detach-file-branch/by-profile
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
;; A cold listing realizes main once and derives every uncached branch,
|
||||
@ -188,21 +188,77 @@
|
||||
;; The compare dialog's query holds main, the derived branch, and the
|
||||
;; base at once, the same three documents the listing holds, so it takes
|
||||
;; the same count. Provisional.
|
||||
:get-branch-diff/global
|
||||
:get-file-branch-diff/global
|
||||
{:permits 6 :queue 15 :timeout 60000}
|
||||
|
||||
;; Creating a pull request realizes the branch and pins one review
|
||||
;; Creating a branch review realizes the branch and pins one review
|
||||
;; snapshot, the anchor's shape. Provisional.
|
||||
:create-pull-request/global
|
||||
:create-branch-review/global
|
||||
{:permits 3 :queue 5 :timeout 60000}
|
||||
|
||||
:create-pull-request/by-profile
|
||||
:create-branch-review/by-profile
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
;; Publishing the branch state also realizes the branch and pins one
|
||||
;; snapshot. The command declares a single instance-wide queue
|
||||
;; (`files_pull_request.clj::update-pull-request-snapshot`), so the
|
||||
;; (`files_branch_review.clj::update-branch-review-revision`), so the
|
||||
;; bounded wait sits on the global entry here rather than on a
|
||||
;; per-profile entry. Provisional.
|
||||
:update-pull-request-snapshot/global
|
||||
{:permits 3 :queue 4 :timeout 60000}}
|
||||
:update-branch-review-revision/global
|
||||
{:permits 3 :queue 4 :timeout 60000}
|
||||
|
||||
;; The review sandbox decodes the pinned snapshot and serves it whole:
|
||||
;; one realized document and one whole-file payload in memory, the
|
||||
;; anchor's shape with no snapshot write behind it. Three at once is the
|
||||
;; anchor's count, and eight waiters give the reviewers of one review
|
||||
;; room to open their sandboxes together. Provisional.
|
||||
:get-branch-review-bundle/global
|
||||
{:permits 3 :queue 8 :timeout 60000}
|
||||
|
||||
;; The activity decodes one blob per row of the review, folds the rows
|
||||
;; as they stream, and serves the folded history. No document is
|
||||
;; realized, but the work grows with the number of saves rather than
|
||||
;; with the size of the file, so it sits between the anchor's three and
|
||||
;; the listing's six, with the read-side ratio for its waiters.
|
||||
;; Provisional.
|
||||
:get-branch-review-activity/global
|
||||
{:permits 4 :queue 10 :timeout 60000}
|
||||
|
||||
;; Moving a thread left behind realizes the target document, then moves
|
||||
;; the thread, its tasks and their events: the one document
|
||||
;; `create-branch-review` realizes, so it takes the anchor's numbers,
|
||||
;; and the per-profile entry keeps one designer to one move at a time.
|
||||
;; Provisional.
|
||||
:move-branch-review-thread/global
|
||||
{:permits 3 :queue 5 :timeout 60000}
|
||||
|
||||
:move-branch-review-thread/by-profile
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
;; Marking the layers of deleted tasks carries their subtrees in,
|
||||
;; validates up to `max-restore-objects` shapes per layer
|
||||
;; (`files_task.clj::restore-objects`), and writes them into the event
|
||||
;; of every task of the layer, so one call can write a document-sized
|
||||
;; payload. The anchor's numbers bound those copies in flight, and the
|
||||
;; per-profile entry keeps one designer's bulk deletions from piling
|
||||
;; up. Provisional.
|
||||
:mark-tasks-layer-deleted/global
|
||||
{:permits 3 :queue 5 :timeout 60000}
|
||||
|
||||
:mark-tasks-layer-deleted/by-profile
|
||||
{:permits 1 :queue 2 :timeout 60000}
|
||||
|
||||
;; A file open asks for the branch of the file, and a cold miss on a
|
||||
;; diverged branch runs the compare dialog's own three-document
|
||||
;; comparison, so the open path shares the compare's numbers instead of
|
||||
;; opening a way around them. The shared summary cache answers a warm
|
||||
;; open without realizing anything. Provisional.
|
||||
:get-file-branch-info/global
|
||||
{:permits 6 :queue 15 :timeout 60000}
|
||||
|
||||
;; A cold review listing realizes the target once and compares each
|
||||
;; uncached diverged review against it, the branches listing's shape
|
||||
;; with main shared across rows, so it takes the listing's numbers.
|
||||
;; Provisional.
|
||||
:get-file-branch-reviews/global
|
||||
{:permits 6 :queue 15 :timeout 60000}}
|
||||
|
||||
@ -197,7 +197,6 @@
|
||||
f.revn,
|
||||
f.data AS legacy_data,
|
||||
f.ignore_sync_until,
|
||||
f.comment_thread_seqn,
|
||||
f.features,
|
||||
f.version,
|
||||
f.vern,
|
||||
@ -224,7 +223,6 @@
|
||||
f.has_media_trimmed,
|
||||
f.revn,
|
||||
f.ignore_sync_until,
|
||||
f.comment_thread_seqn,
|
||||
f.features,
|
||||
f.version,
|
||||
f.vern,
|
||||
|
||||
@ -565,14 +565,14 @@
|
||||
[:map
|
||||
[:name ::sm/text]
|
||||
[:source-user ::sm/text]
|
||||
[:pull-request-title ::sm/text]
|
||||
[:pull-request-route ::sm/text]
|
||||
[:review-title ::sm/text]
|
||||
[:review-route ::sm/text]
|
||||
;; plain :string on purpose: the description is optional and may be empty
|
||||
[:pull-request-description [:string {:max 4000}]]
|
||||
[:pull-request-url ::sm/text]])
|
||||
[:review-description [:string {:max 4000}]]
|
||||
[:review-url ::sm/text]])
|
||||
|
||||
(def review-request
|
||||
"Email sent to the requested reviewers of a pull request."
|
||||
"Email sent to the requested reviewers of a branch review."
|
||||
(template-factory
|
||||
:id ::review-request
|
||||
:schema schema:review-request))
|
||||
@ -590,7 +590,7 @@
|
||||
:id ::task-assigned
|
||||
:schema schema:task-assigned))
|
||||
|
||||
(def ^:private schema:tasks-moved
|
||||
(def ^:private schema:tasks-merged
|
||||
[:map
|
||||
[:name ::sm/text]
|
||||
[:source-user ::sm/text]
|
||||
@ -599,12 +599,12 @@
|
||||
[:task-titles ::sm/text]
|
||||
[:file-url ::sm/text]])
|
||||
|
||||
(def tasks-moved
|
||||
(def tasks-merged
|
||||
"Email sent to the assignees of the open tasks of a branch when the
|
||||
merge of the branch moves them into main."
|
||||
merge of the branch moves them into its target."
|
||||
(template-factory
|
||||
:id ::tasks-moved
|
||||
:schema schema:tasks-moved))
|
||||
:id ::tasks-merged
|
||||
:schema schema:tasks-merged))
|
||||
|
||||
(def ^:private schema:task-done
|
||||
[:map
|
||||
@ -717,7 +717,7 @@
|
||||
"task-assigned" (template-entry task-assigned schema:task-assigned)
|
||||
"task-done" (template-entry task-done schema:task-done)
|
||||
"task-reopened" (template-entry task-reopened schema:task-reopened)
|
||||
"tasks-moved" (template-entry tasks-moved schema:tasks-moved)})
|
||||
"tasks-merged" (template-entry tasks-merged schema:tasks-merged)})
|
||||
|
||||
(defn render-template
|
||||
"Render the templated email `template-id` from its JSON-decoded data,
|
||||
|
||||
@ -49,7 +49,6 @@
|
||||
:extra [:map
|
||||
[:options {:optional true} [:maybe :map]]
|
||||
[:backend {:optional true} [:maybe :string]]
|
||||
[:comment-thread-seqn {:optional true} [:maybe :int]]
|
||||
[:ignore-sync-until {:optional true} [:maybe ::ct/inst]]]})
|
||||
|
||||
(def ^:private page-projection
|
||||
|
||||
@ -596,7 +596,10 @@
|
||||
:fn (mg/resource "app/migrations/sql/0815-add-file-branch-change-review-table.sql")}
|
||||
|
||||
{:name "0816-mod-file-task-add-created-thread"
|
||||
:fn (mg/resource "app/migrations/sql/0816-mod-file-task-add-created-thread.sql")}])
|
||||
:fn (mg/resource "app/migrations/sql/0816-mod-file-task-add-created-thread.sql")}
|
||||
|
||||
{:name "0817-file-family-and-branch-review"
|
||||
:fn (mg/resource "app/migrations/sql/0817-file-family-and-branch-review.sql")}])
|
||||
|
||||
(defn apply-migrations!
|
||||
[pool name migrations]
|
||||
|
||||
@ -11,6 +11,10 @@ CREATE INDEX file_task__comment_id__idx
|
||||
|
||||
-- Until now a task came from a whole thread, with the title of its first
|
||||
-- message.
|
||||
--
|
||||
-- The update has no `AND t.comment_id IS NULL` guard: it runs once, when
|
||||
-- the column is new and empty. A squash that replays this step after
|
||||
-- tasks hold messages must add the guard, or it rewrites their messages.
|
||||
UPDATE file_task AS t
|
||||
SET comment_id = (SELECT c.id
|
||||
FROM comment AS c
|
||||
|
||||
@ -0,0 +1,442 @@
|
||||
-- A file and every branch cut from it, directly or through another
|
||||
-- branch, form a family. The family owns what must outlive a branch:
|
||||
-- its design reviews with their verdicts and activity, the comment
|
||||
-- threads, the tasks, the merge records, and the thread numbers. A file
|
||||
-- row stays the unit of storage and permission, so the objects GC can
|
||||
-- delete a branch file without taking a review or a thread with it: the
|
||||
-- columns that name a file now let go of it (ON DELETE SET NULL), and
|
||||
-- only the death of the family deletes them.
|
||||
--
|
||||
-- The family id is the id of its root file, so a family is found by eye
|
||||
-- from a file id and keeps that name after the root file row is gone. A
|
||||
-- family dies with the last of its files (the triggers at the end).
|
||||
--
|
||||
-- The same step renames the branching vocabulary the database stores:
|
||||
-- a pull request is a branch review, its reviews are reviewers with a
|
||||
-- verdict, main is the source of a branch, a spot of the canvas is a
|
||||
-- point, and the compare marks are marks.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- The family table, and the key of every file
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE file_family (
|
||||
id uuid PRIMARY KEY,
|
||||
-- the last thread number given in the family
|
||||
thread_seqn integer NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||||
);
|
||||
|
||||
ALTER TABLE file
|
||||
ADD COLUMN family_id uuid NULL REFERENCES file_family(id) ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
-- Every file maps to the root of its chain of branch edges. A file that
|
||||
-- is the branch of no edge is a root. The edge is followed whatever its
|
||||
-- state: a merged, archived, or detached branch stays in its family.
|
||||
CREATE TEMPORARY TABLE file_family_map ON COMMIT DROP AS
|
||||
WITH RECURSIVE up(id, root) AS (
|
||||
SELECT f.id, f.id
|
||||
FROM file AS f
|
||||
WHERE NOT EXISTS (SELECT 1 FROM file_branch AS b WHERE b.branch_file_id = f.id)
|
||||
UNION
|
||||
SELECT b.branch_file_id, up.root
|
||||
FROM file_branch AS b
|
||||
JOIN up ON (b.source_file_id = up.id)
|
||||
)
|
||||
SELECT id, root FROM up;
|
||||
|
||||
-- Only a cycle of edges leaves a file without a root, and no code writes
|
||||
-- one; such a file founds its own family rather than stop the boot.
|
||||
INSERT INTO file_family_map (id, root)
|
||||
SELECT f.id, f.id
|
||||
FROM file AS f
|
||||
WHERE NOT EXISTS (SELECT 1 FROM file_family_map AS m WHERE m.id = f.id);
|
||||
|
||||
-- The root's thread counter becomes the family's, so a number freed by a
|
||||
-- deleted thread is never given again.
|
||||
INSERT INTO file_family (id, thread_seqn, created_at)
|
||||
SELECT f.id, coalesce(f.comment_thread_seqn, 0), f.created_at
|
||||
FROM file AS f
|
||||
WHERE f.id IN (SELECT root FROM file_family_map);
|
||||
|
||||
UPDATE file AS f
|
||||
SET family_id = m.root
|
||||
FROM file_family_map AS m
|
||||
WHERE m.id = f.id;
|
||||
|
||||
ALTER TABLE file ALTER COLUMN family_id SET NOT NULL;
|
||||
|
||||
CREATE INDEX file__family_id__idx ON file(family_id);
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Renames: tables, columns, constraints, and indexes
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- A table rename keeps the names of its constraints and indexes, so each
|
||||
-- is renamed after its table. NOT NULL constraints keep their names.
|
||||
|
||||
ALTER TABLE file_pull_request RENAME TO file_branch_review;
|
||||
ALTER TABLE file_branch_review RENAME COLUMN review_snapshot_id TO pinned_snapshot_id;
|
||||
ALTER TABLE file_branch_review RENAME COLUMN review_revn TO pinned_revn;
|
||||
ALTER TABLE file_branch_review RENAME COLUMN review_updated_at TO pinned_at;
|
||||
ALTER INDEX file_pull_request_pkey RENAME TO file_branch_review_pkey;
|
||||
ALTER TABLE file_branch_review RENAME CONSTRAINT file_pull_request_status_check TO file_branch_review_status_check;
|
||||
ALTER TABLE file_branch_review RENAME CONSTRAINT file_pull_request_created_by_fkey TO file_branch_review_created_by_fkey;
|
||||
ALTER TABLE file_branch_review RENAME CONSTRAINT file_pull_request_closed_by_fkey TO file_branch_review_closed_by_fkey;
|
||||
ALTER INDEX file_pull_request__file_branch_id__open__idx RENAME TO file_branch_review__file_branch_id__open__idx;
|
||||
ALTER INDEX file_pull_request__review_snapshot_id__idx RENAME TO file_branch_review__pinned_snapshot_id__idx;
|
||||
|
||||
ALTER TABLE file_pull_request_review RENAME TO file_branch_reviewer;
|
||||
ALTER TABLE file_branch_reviewer RENAME COLUMN pull_request_id TO review_id;
|
||||
ALTER TABLE file_branch_reviewer RENAME COLUMN reviewed_revn TO verdict_revn;
|
||||
ALTER INDEX file_pull_request_review_pkey RENAME TO file_branch_reviewer_pkey;
|
||||
ALTER TABLE file_branch_reviewer RENAME CONSTRAINT file_pull_request_review_pull_request_id_fkey TO file_branch_reviewer_review_id_fkey;
|
||||
ALTER TABLE file_branch_reviewer RENAME CONSTRAINT file_pull_request_review_profile_id_fkey TO file_branch_reviewer_profile_id_fkey;
|
||||
ALTER INDEX file_pull_request_review__profile_id__idx RENAME TO file_branch_reviewer__profile_id__idx;
|
||||
|
||||
ALTER TABLE file_pull_request_activity RENAME TO file_branch_review_activity;
|
||||
ALTER TABLE file_branch_review_activity RENAME COLUMN pull_request_id TO review_id;
|
||||
ALTER INDEX file_pull_request_activity_pkey RENAME TO file_branch_review_activity_pkey;
|
||||
ALTER TABLE file_branch_review_activity RENAME CONSTRAINT file_pull_request_activity_pull_request_id_fkey TO file_branch_review_activity_review_id_fkey;
|
||||
ALTER TABLE file_branch_review_activity RENAME CONSTRAINT file_pull_request_activity_profile_id_fkey TO file_branch_review_activity_profile_id_fkey;
|
||||
ALTER INDEX file_pull_request_activity__pull_request_id__idx RENAME TO file_branch_review_activity__review_id__idx;
|
||||
ALTER INDEX file_pull_request_activity__profile_id__idx RENAME TO file_branch_review_activity__profile_id__idx;
|
||||
|
||||
-- The compare marks keep their branch key and its cascade on purpose.
|
||||
ALTER TABLE file_branch_change_review RENAME TO file_branch_change_mark;
|
||||
ALTER INDEX file_branch_change_review_pkey RENAME TO file_branch_change_mark_pkey;
|
||||
ALTER TABLE file_branch_change_mark RENAME CONSTRAINT file_branch_change_review_file_branch_id_fkey TO file_branch_change_mark_file_branch_id_fkey;
|
||||
ALTER TABLE file_branch_change_mark RENAME CONSTRAINT file_branch_change_review_profile_id_fkey TO file_branch_change_mark_profile_id_fkey;
|
||||
ALTER INDEX file_branch_change_review__profile_id__idx RENAME TO file_branch_change_mark__profile_id__idx;
|
||||
|
||||
-- main's revn when the base was (re)positioned: the source's revn now
|
||||
ALTER TABLE file_branch RENAME COLUMN base_revn TO base_source_revn;
|
||||
|
||||
ALTER TABLE file_branch_merge RENAME COLUMN pull_request_id TO review_id;
|
||||
ALTER TABLE file_branch_merge RENAME COLUMN pull_request_title TO review_title;
|
||||
|
||||
ALTER TABLE comment_thread RENAME COLUMN pull_request_id TO review_id;
|
||||
ALTER INDEX comment_thread__pull_request_id__idx RENAME TO comment_thread__review_id__idx;
|
||||
|
||||
ALTER TABLE file_task RENAME COLUMN pull_request_id TO review_id;
|
||||
ALTER INDEX file_task__pull_request_id__idx RENAME TO file_task__review_id__idx;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- A reviewer's verdict: none until they give one
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
ALTER TABLE file_branch_reviewer ADD COLUMN verdict text NULL;
|
||||
|
||||
UPDATE file_branch_reviewer SET verdict = nullif(state, 'pending');
|
||||
|
||||
-- drops file_pull_request_review_state_check with the column
|
||||
ALTER TABLE file_branch_reviewer DROP COLUMN state;
|
||||
|
||||
ALTER TABLE file_branch_reviewer
|
||||
ADD CONSTRAINT file_branch_reviewer_verdict_check
|
||||
CHECK (verdict IS NULL OR verdict IN ('approved', 'changes-requested'));
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Every row the family owns names it
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
ALTER TABLE file_branch_review
|
||||
ADD COLUMN family_id uuid NULL REFERENCES file_family(id) ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
UPDATE file_branch_review AS r
|
||||
SET family_id = f.family_id
|
||||
FROM file_branch AS b
|
||||
JOIN file AS f ON (f.id = b.source_file_id)
|
||||
WHERE b.id = r.file_branch_id;
|
||||
|
||||
ALTER TABLE file_branch_review ALTER COLUMN family_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE comment_thread
|
||||
ADD COLUMN family_id uuid NULL REFERENCES file_family(id) ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
UPDATE comment_thread AS ct
|
||||
SET family_id = f.family_id
|
||||
FROM file AS f
|
||||
WHERE f.id = ct.file_id;
|
||||
|
||||
ALTER TABLE comment_thread ALTER COLUMN family_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE file_task
|
||||
ADD COLUMN family_id uuid NULL REFERENCES file_family(id) ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
UPDATE file_task AS t
|
||||
SET family_id = f.family_id
|
||||
FROM file AS f
|
||||
WHERE f.id = t.file_id;
|
||||
|
||||
ALTER TABLE file_task ALTER COLUMN family_id SET NOT NULL;
|
||||
|
||||
-- A merge record belongs to the family of the file it merged into.
|
||||
ALTER TABLE file_branch_merge
|
||||
ADD COLUMN family_id uuid NULL REFERENCES file_family(id) ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
UPDATE file_branch_merge AS m
|
||||
SET family_id = f.family_id
|
||||
FROM file AS f
|
||||
WHERE f.id = m.file_id;
|
||||
|
||||
ALTER TABLE file_branch_merge ALTER COLUMN family_id SET NOT NULL;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- The bare review and merge columns become real keys
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- A review the objects GC deleted with its branch file left these ids
|
||||
-- dangling. Clear them first; repeating the pass changes nothing.
|
||||
|
||||
UPDATE comment_thread AS ct
|
||||
SET review_id = NULL
|
||||
WHERE ct.review_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM file_branch_review AS r WHERE r.id = ct.review_id);
|
||||
|
||||
UPDATE file_task AS t
|
||||
SET review_id = NULL
|
||||
WHERE t.review_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM file_branch_review AS r WHERE r.id = t.review_id);
|
||||
|
||||
UPDATE file_task AS t
|
||||
SET merge_id = NULL
|
||||
WHERE t.merge_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM file_branch_merge AS m WHERE m.id = t.merge_id);
|
||||
|
||||
UPDATE file_branch_merge AS m
|
||||
SET review_id = NULL
|
||||
WHERE m.review_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM file_branch_review AS r WHERE r.id = m.review_id);
|
||||
|
||||
ALTER TABLE comment_thread
|
||||
ADD CONSTRAINT comment_thread__review_id__fkey
|
||||
FOREIGN KEY (review_id) REFERENCES file_branch_review(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_task
|
||||
ADD CONSTRAINT file_task__review_id__fkey
|
||||
FOREIGN KEY (review_id) REFERENCES file_branch_review(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_task
|
||||
ADD CONSTRAINT file_task__merge_id__fkey
|
||||
FOREIGN KEY (merge_id) REFERENCES file_branch_merge(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_branch_merge
|
||||
ADD CONSTRAINT file_branch_merge__review_id__fkey
|
||||
FOREIGN KEY (review_id) REFERENCES file_branch_review(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Rows let go of a deleted file instead of going with it
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- A thread or a task keeps a file only while the file exists; the family
|
||||
-- keeps it reachable. The tasks drop the names they copied: the review
|
||||
-- and the merge record are kept now, and they carry the title and the
|
||||
-- branch name.
|
||||
|
||||
ALTER TABLE comment_thread DROP CONSTRAINT comment_thread_file_id_fkey;
|
||||
ALTER TABLE comment_thread ALTER COLUMN file_id DROP NOT NULL;
|
||||
ALTER TABLE comment_thread
|
||||
ADD CONSTRAINT comment_thread__file_id__fkey
|
||||
FOREIGN KEY (file_id) REFERENCES file(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_task DROP CONSTRAINT file_task_file_id_fkey;
|
||||
ALTER TABLE file_task ALTER COLUMN file_id DROP NOT NULL;
|
||||
ALTER TABLE file_task
|
||||
ADD CONSTRAINT file_task__file_id__fkey
|
||||
FOREIGN KEY (file_id) REFERENCES file(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_task
|
||||
DROP COLUMN review_title,
|
||||
DROP COLUMN branch_name;
|
||||
|
||||
-- The edge of a merged branch outlives the branch file: a review finds
|
||||
-- its target through it.
|
||||
ALTER TABLE file_branch DROP CONSTRAINT file_branch_branch_file_id_fkey;
|
||||
ALTER TABLE file_branch ALTER COLUMN branch_file_id DROP NOT NULL;
|
||||
ALTER TABLE file_branch
|
||||
ADD CONSTRAINT file_branch__branch_file_id__fkey
|
||||
FOREIGN KEY (branch_file_id) REFERENCES file(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
ALTER TABLE file_branch_review DROP CONSTRAINT file_pull_request_file_branch_id_fkey;
|
||||
ALTER TABLE file_branch_review ALTER COLUMN file_branch_id DROP NOT NULL;
|
||||
ALTER TABLE file_branch_review
|
||||
ADD CONSTRAINT file_branch_review__file_branch_id__fkey
|
||||
FOREIGN KEY (file_branch_id) REFERENCES file_branch(id) ON DELETE SET NULL DEFERRABLE;
|
||||
|
||||
-- A review's source and target come from its branch edge. Dropping the
|
||||
-- columns drops their foreign keys, their check, and their two indexes.
|
||||
ALTER TABLE file_branch_review
|
||||
DROP COLUMN source_file_id,
|
||||
DROP COLUMN target_file_id;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Thread numbers per family
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
DROP INDEX comment_thread__file_id__seqn__idx;
|
||||
|
||||
CREATE INDEX comment_thread__file_id__idx
|
||||
ON comment_thread(file_id) WHERE file_id IS NOT NULL;
|
||||
|
||||
-- The threads of a root file keep their numbers, so a family with no
|
||||
-- branch (every file before branching) changes nothing. The threads of
|
||||
-- the branches are numbered once after the root's counter, in the order
|
||||
-- they were written, and never again.
|
||||
WITH base AS (
|
||||
SELECT f.id AS family_id,
|
||||
greatest(coalesce(f.comment_thread_seqn, 0), coalesce(max(r.seqn), 0)) AS seqn
|
||||
FROM file AS f
|
||||
LEFT JOIN comment_thread AS r ON (r.file_id = f.id)
|
||||
WHERE f.id IN (SELECT family_id FROM comment_thread WHERE file_id <> family_id)
|
||||
GROUP BY f.id, f.comment_thread_seqn
|
||||
), numbered AS (
|
||||
SELECT t.id, t.family_id,
|
||||
row_number() OVER (PARTITION BY t.family_id ORDER BY t.created_at, t.id) AS n
|
||||
FROM comment_thread AS t
|
||||
WHERE t.file_id <> t.family_id
|
||||
)
|
||||
UPDATE comment_thread AS ct
|
||||
SET seqn = b.seqn + n.n
|
||||
FROM numbered AS n
|
||||
JOIN base AS b ON (b.family_id = n.family_id)
|
||||
WHERE ct.id = n.id;
|
||||
|
||||
-- one number per family, not per file
|
||||
CREATE UNIQUE INDEX comment_thread__family_id__seqn__idx
|
||||
ON comment_thread(family_id, seqn);
|
||||
|
||||
UPDATE file_family AS ff
|
||||
SET thread_seqn = s.seqn
|
||||
FROM (SELECT family_id, max(seqn) AS seqn
|
||||
FROM comment_thread
|
||||
GROUP BY family_id) AS s
|
||||
WHERE s.family_id = ff.id
|
||||
AND s.seqn > ff.thread_seqn;
|
||||
|
||||
ALTER TABLE file DROP COLUMN comment_thread_seqn;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Stored values that follow the renames
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- A spot of the canvas is a point. The anchor check also requires what
|
||||
-- each kind of anchor points at.
|
||||
ALTER TABLE comment_thread DROP CONSTRAINT comment_thread_anchor_type_check;
|
||||
ALTER TABLE comment_thread ALTER COLUMN anchor_type SET DEFAULT 'point';
|
||||
|
||||
UPDATE comment_thread SET anchor_type = 'point' WHERE anchor_type = 'canvas';
|
||||
|
||||
ALTER TABLE comment_thread
|
||||
ADD CONSTRAINT comment_thread__anchor__check
|
||||
CHECK ((anchor_type = 'layer' AND shape_id IS NOT NULL)
|
||||
OR (anchor_type = 'area' AND area IS NOT NULL)
|
||||
OR anchor_type = 'point')
|
||||
NOT VALID;
|
||||
|
||||
ALTER TABLE comment_thread VALIDATE CONSTRAINT comment_thread__anchor__check;
|
||||
|
||||
-- A merge no longer moves a task into main: it merges it.
|
||||
UPDATE file_task_event SET type = 'merged' WHERE type = 'moved-to-main';
|
||||
|
||||
-- The two sides of a comparison are the branch and its source.
|
||||
UPDATE file_branch_change_mark
|
||||
SET direction = CASE direction
|
||||
WHEN 'branch->main' THEN 'branch->source'
|
||||
WHEN 'main->branch' THEN 'source->branch'
|
||||
END
|
||||
WHERE direction IN ('branch->main', 'main->branch');
|
||||
|
||||
ALTER TABLE file_branch_change_mark
|
||||
ADD CONSTRAINT file_branch_change_mark_direction_check
|
||||
CHECK (direction IN ('branch->source', 'source->branch'));
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Indexes of the family read model
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
CREATE INDEX file_task__family_id__idx
|
||||
ON file_task(family_id) WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX file_branch_review__family_id__idx
|
||||
ON file_branch_review(family_id, status) WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX file_branch_review__file_branch_id__idx
|
||||
ON file_branch_review(file_branch_id) WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX file_branch_merge__family_id__idx
|
||||
ON file_branch_merge(family_id, created_at DESC);
|
||||
|
||||
-- One task per message of a thread.
|
||||
DROP INDEX file_task__comment_id__idx;
|
||||
|
||||
CREATE UNIQUE INDEX file_task__comment_id__unique__idx
|
||||
ON file_task(comment_id) WHERE comment_id IS NOT NULL AND deleted_at IS NULL;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- The life of a family
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- A file inserted without a family founds its own, named after it. Every
|
||||
-- path that creates a file (creation, duplication, import, templates)
|
||||
-- gets a family that way; branch creation then moves the branch file
|
||||
-- into the family of its source.
|
||||
CREATE FUNCTION create_file_family()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
INSERT INTO file_family (id) VALUES (NEW.id) ON CONFLICT (id) DO NOTHING;
|
||||
NEW.family_id := NEW.id;
|
||||
RETURN NEW;
|
||||
END $$;
|
||||
|
||||
CREATE TRIGGER file__create_family__tgr
|
||||
BEFORE INSERT ON file
|
||||
FOR EACH ROW
|
||||
WHEN (NEW.family_id IS NULL)
|
||||
EXECUTE FUNCTION create_file_family();
|
||||
|
||||
-- A file that moves to another family deletes the one it left once no
|
||||
-- file remains in it. The code that moves a file moves the rows of its
|
||||
-- family with it first: what stays behind goes with the family.
|
||||
CREATE FUNCTION delete_left_file_family()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
DELETE FROM file_family AS ff
|
||||
WHERE ff.id = OLD.family_id
|
||||
AND NOT EXISTS (SELECT 1 FROM file AS f WHERE f.family_id = OLD.family_id);
|
||||
RETURN NULL;
|
||||
END $$;
|
||||
|
||||
CREATE TRIGGER file__leave_family__tgr
|
||||
AFTER UPDATE OF family_id ON file
|
||||
FOR EACH ROW
|
||||
WHEN (OLD.family_id IS DISTINCT FROM NEW.family_id)
|
||||
EXECUTE FUNCTION delete_left_file_family();
|
||||
|
||||
-- When the last file of a family is hard-deleted, the family goes, and
|
||||
-- with it every review, verdict, activity row, thread, task, and merge
|
||||
-- record it owns. A trigger rather than a step of the objects GC: every
|
||||
-- path that hard-deletes files is covered, and none can leak a family
|
||||
-- nobody reaches.
|
||||
CREATE FUNCTION delete_empty_file_families()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
DELETE FROM file_family AS ff
|
||||
WHERE ff.id IN (SELECT DISTINCT family_id FROM old_rows)
|
||||
AND NOT EXISTS (SELECT 1 FROM file AS f WHERE f.family_id = ff.id);
|
||||
RETURN NULL;
|
||||
END $$;
|
||||
|
||||
CREATE TRIGGER file__delete_empty_family__tgr
|
||||
AFTER DELETE ON file
|
||||
REFERENCING OLD TABLE AS old_rows
|
||||
FOR EACH STATEMENT
|
||||
EXECUTE FUNCTION delete_empty_file_families();
|
||||
|
||||
-- Migration 0814 gave a thread to every task that had none. Those
|
||||
-- threads are not told apart from a thread the code made for a task:
|
||||
-- both hold the task's title as their only message, owned by the task's
|
||||
-- author. They stay.
|
||||
@ -433,7 +433,7 @@
|
||||
'app.rpc.commands.files-update
|
||||
'app.rpc.commands.files-snapshot
|
||||
'app.rpc.commands.files-branch
|
||||
'app.rpc.commands.files-pull-request
|
||||
'app.rpc.commands.files-branch-review
|
||||
'app.rpc.commands.files-task
|
||||
'app.rpc.commands.files-thumbnails
|
||||
'app.rpc.commands.jobs
|
||||
|
||||
@ -216,15 +216,22 @@
|
||||
(db/get-by-id conn :comment comment-id opts))
|
||||
|
||||
(def ^:private sql:get-next-seqn
|
||||
"SELECT (f.comment_thread_seqn + 1) AS next_seqn
|
||||
"SELECT ff.id AS family_id,
|
||||
(ff.thread_seqn + 1) AS next_seqn
|
||||
FROM file AS f
|
||||
JOIN file_family AS ff ON (ff.id = f.family_id)
|
||||
WHERE f.id = ?
|
||||
FOR UPDATE")
|
||||
FOR UPDATE OF ff")
|
||||
|
||||
(defn- get-next-seqn
|
||||
"The family of the file `file-id` and the next thread number of that
|
||||
family, as `{:family-id .. :next-seqn ..}`. Threads are numbered per
|
||||
family, so a thread keeps its number when a merge moves it from a
|
||||
branch to its target. The family row stays locked until the
|
||||
transaction ends, so two threads of one family never take the same
|
||||
number."
|
||||
[conn file-id]
|
||||
(let [res (db/exec-one! conn [sql:get-next-seqn file-id])]
|
||||
(:next-seqn res)))
|
||||
(db/exec-one! conn [sql:get-next-seqn file-id]))
|
||||
|
||||
(def sql:upsert-comment-thread-status
|
||||
"insert into comment_thread_status (thread_id, profile_id, modified_at)
|
||||
@ -278,8 +285,8 @@
|
||||
p.team_id AS team_id,
|
||||
f.name AS file_name,
|
||||
f.project_id AS project_id,
|
||||
fpr.title AS pull_request_title,
|
||||
fpr.status AS pull_request_status,
|
||||
fbr.title AS review_title,
|
||||
fbr.status AS review_status,
|
||||
first_value(c.content) OVER w AS content,
|
||||
(SELECT count(1)
|
||||
FROM comment AS c
|
||||
@ -294,7 +301,7 @@
|
||||
INNER JOIN project AS p ON (p.id = f.project_id)
|
||||
LEFT JOIN comment_thread_status AS cts ON (cts.thread_id = ct.id AND cts.profile_id = ?)
|
||||
LEFT JOIN profile AS pf ON (ct.owner_id = pf.id)
|
||||
LEFT JOIN file_pull_request AS fpr ON (fpr.id = ct.pull_request_id)
|
||||
LEFT JOIN file_branch_review AS fbr ON (fbr.id = ct.review_id)
|
||||
WHERE f.deleted_at IS NULL
|
||||
AND p.deleted_at IS NULL
|
||||
%1
|
||||
@ -495,10 +502,10 @@
|
||||
[:height ::sm/safe-number]])
|
||||
|
||||
(def ^:private schema:anchor
|
||||
"What a thread points at: a spot of a board (`:canvas`, the default),
|
||||
"What a thread points at: a spot of a board (`:point`, the default),
|
||||
a layer or a rectangle."
|
||||
[:multi {:dispatch :type :title "CommentThreadAnchor"}
|
||||
[:canvas [:map [:type [:= :canvas]]]]
|
||||
[:point [:map [:type [:= :point]]]]
|
||||
[:layer [:map
|
||||
[:type [:= :layer]]
|
||||
[:shape-id ::sm/uuid]]]
|
||||
@ -516,33 +523,35 @@
|
||||
[:frame-id ::sm/uuid]
|
||||
[:share-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:mentions {:optional true} [::sm/set ::sm/uuid]]
|
||||
;; the design review the thread is written in: an open pull request
|
||||
;; of this file (the branch file it reviews)
|
||||
[:pull-request-id {:optional true} ::sm/uuid]
|
||||
;; the design review the thread is written in: an open review of
|
||||
;; this file (the branch file it reviews)
|
||||
[:review-id {:optional true} ::sm/uuid]
|
||||
[:anchor {:optional true} schema:anchor]])
|
||||
|
||||
(def ^:private sql:get-open-pull-request-of-file
|
||||
"SELECT id FROM file_pull_request
|
||||
WHERE id = ?
|
||||
AND source_file_id = ?
|
||||
AND status = 'open'
|
||||
AND deleted_at IS NULL")
|
||||
(def ^:private sql:get-open-review-of-file
|
||||
"SELECT r.id
|
||||
FROM file_branch_review AS r
|
||||
JOIN file_branch AS b ON (b.id = r.file_branch_id)
|
||||
WHERE r.id = ?
|
||||
AND b.branch_file_id = ?
|
||||
AND r.status = 'open'
|
||||
AND r.deleted_at IS NULL")
|
||||
|
||||
(defn- check-review-of-file
|
||||
"Refuse a thread for a design review that is not an open review of the
|
||||
file the thread is written on."
|
||||
[conn pull-request-id file-id]
|
||||
(when-not (db/exec-one! conn [sql:get-open-pull-request-of-file pull-request-id file-id])
|
||||
[conn review-id file-id]
|
||||
(when-not (db/exec-one! conn [sql:get-open-review-of-file review-id file-id])
|
||||
(ex/raise :type :validation
|
||||
:code :pull-request-not-open
|
||||
:code :branch-review-not-open
|
||||
:hint "the thread names a design review that is not open on this file"
|
||||
:pull-request-id pull-request-id)))
|
||||
:review-id review-id)))
|
||||
|
||||
(defn- update-thread-seqn
|
||||
[conn file-id seqn]
|
||||
(db/update! conn :file
|
||||
{:comment-thread-seqn seqn}
|
||||
{:id file-id}
|
||||
[conn family-id seqn]
|
||||
(db/update! conn :file-family
|
||||
{:thread-seqn seqn}
|
||||
{:id family-id}
|
||||
{::db/return-keys false}))
|
||||
|
||||
(defn add-owner
|
||||
@ -590,22 +599,17 @@
|
||||
(defn- insert-comment-thread
|
||||
[{:keys [::db/conn] :as cfg}
|
||||
{:keys [::rpc/profile-id ::rpc/request-at ::file position content mentions frame-id
|
||||
pull-request-id anchor ::skip-subscriber-emails]}]
|
||||
review-id anchor ::skip-subscriber-emails]}]
|
||||
|
||||
(let [;; NOTE: we take the next seq number from a separate query
|
||||
;; because we need to lock the file for avoid race conditions
|
||||
|
||||
;; FIXME: this method touches and locks the file table,which
|
||||
;; is already heavy-update tablel; we need to think on move
|
||||
;; the sequence state management to a different table or
|
||||
;; different storage (example: redis) for alivate the update
|
||||
;; pression on the file table
|
||||
|
||||
_ (when pull-request-id
|
||||
(check-review-of-file conn pull-request-id (:id file)))
|
||||
(let [_ (when review-id
|
||||
(check-review-of-file conn review-id (:id file)))
|
||||
|
||||
profile (profile/get-profile conn profile-id)
|
||||
seqn (get-next-seqn conn (:id file))
|
||||
|
||||
;; the number comes from the family row, locked until the
|
||||
;; transaction ends: the file row, a heavily updated one, is
|
||||
;; not touched
|
||||
{:keys [family-id next-seqn]} (get-next-seqn conn (:id file))
|
||||
|
||||
file-id (get file :id)
|
||||
thread-id (uuid/next)
|
||||
@ -613,18 +617,19 @@
|
||||
thread (-> (db/insert! conn :comment-thread
|
||||
{:id thread-id
|
||||
:file-id file-id
|
||||
:family-id family-id
|
||||
:page-name (:page-name file)
|
||||
:page-id (:page-id file)
|
||||
:owner-id profile-id
|
||||
:participants (db/tjson #{profile-id})
|
||||
:created-at request-at
|
||||
:modified-at request-at
|
||||
:seqn seqn
|
||||
:seqn next-seqn
|
||||
:frame-id frame-id
|
||||
:position (db/pgpoint position)
|
||||
:mentions (db/encode-pgarray mentions conn "uuid")
|
||||
:pull-request-id pull-request-id
|
||||
:anchor-type (d/name (get anchor :type :canvas))
|
||||
:review-id review-id
|
||||
:anchor-type (d/name (get anchor :type :point))
|
||||
:shape-id (:shape-id anchor)
|
||||
:area (some-> (:area anchor) db/tjson)})
|
||||
(decode-row))
|
||||
@ -641,8 +646,8 @@
|
||||
;; Make the current thread as read.
|
||||
(upsert-comment-thread-status! conn profile-id thread-id request-at)
|
||||
|
||||
;; Optimistic update of current seq number on file.
|
||||
(update-thread-seqn conn file-id seqn)
|
||||
;; Advance the thread counter of the family.
|
||||
(update-thread-seqn conn family-id next-seqn)
|
||||
|
||||
;; Send mentions emails
|
||||
(send-comment-emails! cfg profile comment thread file
|
||||
|
||||
@ -127,7 +127,6 @@
|
||||
[:id ::sm/uuid]
|
||||
[:features ::cfeat/features]
|
||||
[:has-media-trimmed ::sm/boolean]
|
||||
[:comment-thread-seqn [::sm/int {:min 0}]]
|
||||
[:name [:string {:max 250}]]
|
||||
[:revn [::sm/int {:min 0}]]
|
||||
[:vern [::sm/int {:min 0}]]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -17,10 +17,16 @@
|
||||
who made it, which is what the thread of the task shows between its
|
||||
comments.
|
||||
|
||||
The merge of a branch moves its tasks into main (`move-branch-tasks`,
|
||||
called from `app.rpc.commands.files-branch`): the open ones keep going
|
||||
on main and the closed ones stay as the history of the branch."
|
||||
The merge of a branch moves into its target the threads that hold an
|
||||
open task, whole with their tasks, and the threads written outside any
|
||||
review (`move-branch-tasks`, called from
|
||||
`app.rpc.commands.files-branch`). Every other review thread stays on
|
||||
the branch file as the record of its review, and outlives that file:
|
||||
`get-review-threads` reads it and `move-branch-review-thread` moves it
|
||||
later. Every task, thread, and review belongs to the family of its file
|
||||
(`file_family`), which the branch shares with its target."
|
||||
(:require
|
||||
[app.binfile.common :as bfc]
|
||||
[app.common.data :as d]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.files.helpers :as cfh]
|
||||
@ -37,6 +43,7 @@
|
||||
[app.loggers.webhooks :as-alias webhooks]
|
||||
[app.msgbus :as mbus]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.climit :as-alias climit]
|
||||
[app.rpc.commands.comments :as comments]
|
||||
[app.rpc.commands.files :as files]
|
||||
[app.rpc.commands.profile :as profile]
|
||||
@ -115,9 +122,9 @@
|
||||
(def ^:private sql:select-tasks
|
||||
"SELECT t.id,
|
||||
t.file_id,
|
||||
t.pull_request_id,
|
||||
coalesce(fpr.title, t.review_title) AS review_title,
|
||||
fpr.status AS review_status,
|
||||
t.review_id,
|
||||
r.title AS review_title,
|
||||
r.status AS review_status,
|
||||
t.thread_id,
|
||||
t.comment_id,
|
||||
ct.seqn AS thread_seqn,
|
||||
@ -132,13 +139,14 @@
|
||||
t.lost_shape_name,
|
||||
t.position,
|
||||
t.merge_id,
|
||||
t.branch_name,
|
||||
m.branch_name,
|
||||
t.status_changed_at,
|
||||
t.status_changed_by,
|
||||
t.created_at,
|
||||
t.updated_at
|
||||
FROM file_task AS t
|
||||
LEFT JOIN file_pull_request AS fpr ON (fpr.id = t.pull_request_id)
|
||||
LEFT JOIN file_branch_review AS r ON (r.id = t.review_id)
|
||||
LEFT JOIN file_branch_merge AS m ON (m.id = t.merge_id)
|
||||
LEFT JOIN comment_thread AS ct ON (ct.id = t.thread_id)")
|
||||
|
||||
(def ^:private sql:get-file-tasks
|
||||
@ -188,21 +196,22 @@
|
||||
result))
|
||||
|
||||
(def ^:private sql:lock-file
|
||||
"SELECT id, deleted_at FROM file WHERE id = ? FOR UPDATE")
|
||||
"SELECT id, family_id, deleted_at FROM file WHERE id = ? FOR UPDATE")
|
||||
|
||||
(defn- lock-file
|
||||
"Lock the row of `file-id` and refuse a deleted file. Task creation and
|
||||
the move of the tasks of a merged branch (`move-branch-tasks`) take
|
||||
this lock: a task created during a merge either lands before the merge
|
||||
reads the tasks of the branch, or waits and finds the branch file
|
||||
deleted."
|
||||
"Lock the row of `file-id` and refuse a deleted file. Returns the row.
|
||||
Task creation and the move of the tasks of a merged branch
|
||||
(`move-branch-tasks`) take this lock: a task created during a merge
|
||||
either lands before the merge reads the tasks of the branch, or waits
|
||||
and finds the branch file deleted."
|
||||
[conn file-id]
|
||||
(let [file (db/exec-one! conn [sql:lock-file file-id])]
|
||||
(when (or (nil? file) (some? (:deleted-at file)))
|
||||
(ex/raise :type :not-found
|
||||
:code :object-not-found
|
||||
:hint "the file of the task does not exist or was deleted"
|
||||
:file-id file-id))))
|
||||
:file-id file-id))
|
||||
file))
|
||||
|
||||
;; --- Helpers: emails
|
||||
|
||||
@ -339,9 +348,9 @@
|
||||
;; thread sits
|
||||
[:position ::gpt/point]
|
||||
[:assignee-id {:optional true} [:maybe ::sm/uuid]]
|
||||
;; the design review the task is created in: an open pull request
|
||||
;; of this file (the branch file it reviews)
|
||||
[:pull-request-id {:optional true} [:maybe ::sm/uuid]]
|
||||
;; the design review the task is created in: an open review of this
|
||||
;; file (the branch file it reviews)
|
||||
[:review-id {:optional true} [:maybe ::sm/uuid]]
|
||||
;; the comment thread the task comes from, which stays attached, and
|
||||
;; the message of that thread it was made from; without them the
|
||||
;; task gets a thread of its own
|
||||
@ -349,11 +358,13 @@
|
||||
[:comment-id {:optional true} [:maybe ::sm/uuid]]])
|
||||
|
||||
(def ^:private sql:get-open-review-of-file
|
||||
"SELECT id, title FROM file_pull_request
|
||||
WHERE id = ?
|
||||
AND source_file_id = ?
|
||||
AND status = 'open'
|
||||
AND deleted_at IS NULL")
|
||||
"SELECT r.id
|
||||
FROM file_branch_review AS r
|
||||
JOIN file_branch AS b ON (b.id = r.file_branch_id)
|
||||
WHERE r.id = ?
|
||||
AND b.branch_file_id = ?
|
||||
AND r.status = 'open'
|
||||
AND r.deleted_at IS NULL")
|
||||
|
||||
(def ^:private sql:get-task-of-comment
|
||||
"SELECT id FROM file_task
|
||||
@ -392,7 +403,7 @@
|
||||
when there is none) and belongs to the design review of the task. The
|
||||
task tells its assignee by email, so the thread tells nobody that a
|
||||
comment was added."
|
||||
[cfg profile-id {:keys [file-id title page-id frame-id shape-id position pull-request-id]}]
|
||||
[cfg profile-id {:keys [file-id title page-id frame-id shape-id position review-id]}]
|
||||
(comments/create-comment-thread
|
||||
cfg
|
||||
(cond-> {::rpc/profile-id profile-id
|
||||
@ -405,8 +416,8 @@
|
||||
::comments/skip-subscriber-emails true
|
||||
:anchor (if (some? shape-id)
|
||||
{:type :layer :shape-id shape-id}
|
||||
{:type :canvas})}
|
||||
(some? pull-request-id) (assoc :pull-request-id pull-request-id))))
|
||||
{:type :point})}
|
||||
(some? review-id) (assoc :review-id review-id))))
|
||||
|
||||
(sv/defmethod ::create-task
|
||||
"Create an open task on a file, in a message of a comment thread: the
|
||||
@ -420,7 +431,7 @@
|
||||
::webhooks/event? true
|
||||
::sm/params schema:create-task}
|
||||
[cfg {:keys [::rpc/profile-id ::rpc/session-id file-id title page-id frame-id shape-id position
|
||||
assignee-id pull-request-id thread-id comment-id] :as params}]
|
||||
assignee-id review-id thread-id comment-id] :as params}]
|
||||
(check-tasks-enabled)
|
||||
(when (str/blank? title)
|
||||
(ex/raise :type :validation
|
||||
@ -431,14 +442,14 @@
|
||||
cfg {:file-id file-id :profile-id profile-id :session-id session-id}
|
||||
(comp vector :id)
|
||||
(fn [{:keys [::db/conn] :as cfg}]
|
||||
(lock-file conn file-id)
|
||||
(let [team-id (perms/get-team-id-for-file conn file-id)
|
||||
review (when pull-request-id
|
||||
(or (db/exec-one! conn [sql:get-open-review-of-file pull-request-id file-id])
|
||||
(ex/raise :type :validation
|
||||
:code :pull-request-not-open
|
||||
:hint "the task names a design review that is not open on this file"
|
||||
:pull-request-id pull-request-id)))
|
||||
(let [file (lock-file conn file-id)
|
||||
team-id (perms/get-team-id-for-file conn file-id)
|
||||
_ (when (and (some? review-id)
|
||||
(nil? (db/exec-one! conn [sql:get-open-review-of-file review-id file-id])))
|
||||
(ex/raise :type :validation
|
||||
:code :branch-review-not-open
|
||||
:hint "the task names a design review that is not open on this file"
|
||||
:review-id review-id))
|
||||
_ (when thread-id
|
||||
(check-thread conn thread-id file-id))
|
||||
_ (when comment-id
|
||||
@ -450,8 +461,8 @@
|
||||
task {:id (uuid/next)
|
||||
:position position
|
||||
:file-id file-id
|
||||
:pull-request-id pull-request-id
|
||||
:review-title (:title review)
|
||||
:family-id (:family-id file)
|
||||
:review-id review-id
|
||||
:thread-id (or thread-id (:id thread))
|
||||
:comment-id (or comment-id (:comment-id thread))
|
||||
:created-thread (some? thread)
|
||||
@ -594,38 +605,43 @@
|
||||
(send-task-status-email cfg profile-id task)
|
||||
task))))))
|
||||
|
||||
;; --- Helpers: the thread created with a task
|
||||
;; --- Helpers: the place of a thread
|
||||
|
||||
(defn- anchor-thread
|
||||
"Point the thread `thread-id` at the layer `shape-id`; with no layer, at
|
||||
the rectangle `area` of the canvas, or at the spot `position` when there
|
||||
is no area either."
|
||||
[conn thread-id {:keys [frame-id shape-id area position]}]
|
||||
(db/update! conn :comment-thread
|
||||
(cond
|
||||
(some? shape-id)
|
||||
{:frame-id frame-id
|
||||
:shape-id shape-id
|
||||
:anchor-type "layer"
|
||||
:area nil}
|
||||
|
||||
(some? area)
|
||||
{:frame-id frame-id
|
||||
:shape-id nil
|
||||
:anchor-type "area"
|
||||
:area (db/tjson area)
|
||||
:position (db/pgpoint position)}
|
||||
|
||||
:else
|
||||
{:frame-id frame-id
|
||||
:shape-id nil
|
||||
:anchor-type "point"
|
||||
:area nil
|
||||
:position (db/pgpoint position)})
|
||||
{:id thread-id}
|
||||
{::db/return-keys false}))
|
||||
|
||||
(defn- move-task-thread
|
||||
"Point the thread created with `task` where the task points now: at the
|
||||
layer `shape-id`; with no layer, at the rectangle `area` of the canvas,
|
||||
or at the spot `position` when there is no area either. A thread the
|
||||
task was made from keeps its own place."
|
||||
[conn task {:keys [frame-id shape-id area position]}]
|
||||
"Point the thread created with `task` where the task points now
|
||||
(`anchor-thread`). A thread the task was made from keeps its own place."
|
||||
[conn task landing]
|
||||
(when (:created-thread task)
|
||||
(db/update! conn :comment-thread
|
||||
(cond
|
||||
(some? shape-id)
|
||||
{:frame-id frame-id
|
||||
:shape-id shape-id
|
||||
:anchor-type "layer"
|
||||
:area nil}
|
||||
|
||||
(some? area)
|
||||
{:frame-id frame-id
|
||||
:shape-id nil
|
||||
:anchor-type "area"
|
||||
:area (db/tjson area)
|
||||
:position (db/pgpoint position)}
|
||||
|
||||
:else
|
||||
{:frame-id frame-id
|
||||
:shape-id nil
|
||||
:anchor-type "canvas"
|
||||
:area nil
|
||||
:position (db/pgpoint position)})
|
||||
{:id (:thread-id task)}
|
||||
{::db/return-keys false})))
|
||||
(anchor-thread conn (:thread-id task) landing)))
|
||||
|
||||
;; --- COMMAND: relink-task
|
||||
|
||||
@ -716,7 +732,9 @@
|
||||
the deleted layer, so it can be restored later, when the layer is small
|
||||
and valid enough (`restore-objects`). Returns the tasks it moved."
|
||||
{::doc/added "2.16"
|
||||
::sm/params schema:mark-tasks-layer-deleted}
|
||||
::sm/params schema:mark-tasks-layer-deleted
|
||||
::climit/id [[:mark-tasks-layer-deleted/by-profile ::rpc/profile-id]
|
||||
[:mark-tasks-layer-deleted/global]]}
|
||||
[cfg {:keys [::rpc/profile-id ::rpc/session-id file-id layers]}]
|
||||
(check-tasks-enabled)
|
||||
(files/check-read-permissions! cfg profile-id file-id)
|
||||
@ -824,32 +842,32 @@
|
||||
;; --- Review counts
|
||||
|
||||
(def ^:private sql:get-review-task-counts
|
||||
"SELECT pull_request_id, status, count(*) AS total
|
||||
"SELECT review_id, status, count(*) AS total
|
||||
FROM file_task
|
||||
WHERE pull_request_id = ANY(?)
|
||||
WHERE review_id = ANY(?)
|
||||
AND deleted_at IS NULL
|
||||
GROUP BY pull_request_id, status")
|
||||
GROUP BY review_id, status")
|
||||
|
||||
(def ^:private sql:get-review-comment-counts
|
||||
"SELECT pull_request_id, is_resolved, count(*) AS total
|
||||
"SELECT review_id, is_resolved, count(*) AS total
|
||||
FROM comment_thread
|
||||
WHERE pull_request_id = ANY(?)
|
||||
GROUP BY pull_request_id, is_resolved")
|
||||
WHERE review_id = ANY(?)
|
||||
GROUP BY review_id, is_resolved")
|
||||
|
||||
(defn get-review-counts
|
||||
"{pull-request-id {:tasks {status count} :comments-open n
|
||||
"{review-id {:tasks {status count} :comments-open n
|
||||
:comments-resolved n}} for the given design reviews."
|
||||
[conn pull-request-ids]
|
||||
(if (empty? pull-request-ids)
|
||||
[conn review-ids]
|
||||
(if (empty? review-ids)
|
||||
{}
|
||||
(let [ids (db/create-array conn "uuid" (vec pull-request-ids))
|
||||
(let [ids (db/create-array conn "uuid" (vec review-ids))
|
||||
empty {:tasks {} :comments-open 0 :comments-resolved 0}
|
||||
by-tasks (reduce (fn [acc {:keys [pull-request-id status total]}]
|
||||
(assoc-in acc [pull-request-id :tasks status] total))
|
||||
by-tasks (reduce (fn [acc {:keys [review-id status total]}]
|
||||
(assoc-in acc [review-id :tasks status] total))
|
||||
{}
|
||||
(db/exec! conn [sql:get-review-task-counts ids]))]
|
||||
(reduce (fn [acc {:keys [pull-request-id is-resolved total]}]
|
||||
(update acc pull-request-id
|
||||
(reduce (fn [acc {:keys [review-id is-resolved total]}]
|
||||
(update acc review-id
|
||||
(fn [counts]
|
||||
(assoc (merge empty counts)
|
||||
(if is-resolved :comments-resolved :comments-open)
|
||||
@ -857,7 +875,87 @@
|
||||
(update-vals by-tasks #(merge empty %))
|
||||
(db/exec! conn [sql:get-review-comment-counts ids])))))
|
||||
|
||||
;; --- Merge: move the tasks of a branch into main
|
||||
;; --- COMMAND QUERY: get-file-branch-counts
|
||||
;;
|
||||
;; The delete confirmation of a branch says how many threads and tasks go
|
||||
;; with it. `get-review-counts` answers per review, which leaves out what
|
||||
;; was written on the branch outside any review, so these count by the
|
||||
;; branch file, where the deletion lands: the file row goes, and the
|
||||
;; threads and tasks that named it lose their file with it.
|
||||
|
||||
(def ^:private sql:get-branch-file-id
|
||||
"SELECT fb.branch_file_id
|
||||
FROM file_branch AS fb
|
||||
WHERE fb.id = ?
|
||||
AND fb.deleted_at IS NULL")
|
||||
|
||||
(def ^:private sql:get-thread-count
|
||||
"SELECT count(*) AS total
|
||||
FROM comment_thread
|
||||
WHERE file_id = ?")
|
||||
|
||||
(def ^:private sql:get-task-counts
|
||||
"SELECT status, count(*) AS total
|
||||
FROM file_task
|
||||
WHERE file_id = ?
|
||||
AND deleted_at IS NULL
|
||||
GROUP BY status")
|
||||
|
||||
(defn- branch-counts
|
||||
"The live threads and tasks written on the branch file `file-id`:
|
||||
`{:threads n :open-tasks n :closed-tasks n}`, tasks split as
|
||||
`closed-statuses` splits them."
|
||||
[conn file-id]
|
||||
(let [threads (-> (db/exec-one! conn [sql:get-thread-count file-id]) :total)]
|
||||
(reduce (fn [counts {:keys [status total]}]
|
||||
(let [k (if (contains? closed-statuses status) :closed-tasks :open-tasks)]
|
||||
(update counts k + total)))
|
||||
{:threads threads :open-tasks 0 :closed-tasks 0}
|
||||
(db/exec! conn [sql:get-task-counts file-id]))))
|
||||
|
||||
(def ^:private schema:get-file-branch-counts
|
||||
[:map {:title "get-file-branch-counts"}
|
||||
[:branch-id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::get-file-branch-counts
|
||||
"What deleting the branch takes with it, for the confirmation the client
|
||||
shows before it deletes: how many live threads and tasks were written
|
||||
on the branch file, tasks split into open and closed, where closed
|
||||
means verified or dropped as won't do, as the merge reads a task. A
|
||||
thread has no deleted marker (a deleted thread is gone) and a
|
||||
logically deleted task is not counted. The dialog asks just before the
|
||||
delete, so the numbers are the ones the deletion lands on. Needs read
|
||||
rights on the branch file, and takes no climit: two indexed counts,
|
||||
nothing realized."
|
||||
{::doc/added "2.16"
|
||||
::sm/params schema:get-file-branch-counts}
|
||||
[cfg {:keys [::rpc/profile-id branch-id]}]
|
||||
(check-tasks-enabled)
|
||||
(db/run! cfg
|
||||
(fn [{:keys [::db/conn] :as cfg}]
|
||||
(let [row (db/exec-one! conn [sql:get-branch-file-id branch-id])
|
||||
branch-file-id (:branch-file-id row)]
|
||||
(when (nil? row)
|
||||
(ex/raise :type :not-found
|
||||
:code :branch-not-found
|
||||
:hint "unable to find branch with the provided id"
|
||||
:branch-id branch-id))
|
||||
;; a kept branch whose file the GC took away carries no
|
||||
;; threads or tasks any more, and cannot be deleted either
|
||||
(when (nil? branch-file-id)
|
||||
(ex/raise :type :not-found
|
||||
:code :object-not-found
|
||||
:hint "the branch has no file left to count"
|
||||
:branch-id branch-id))
|
||||
(files/check-read-permissions! cfg profile-id branch-file-id)
|
||||
(branch-counts conn branch-file-id)))))
|
||||
|
||||
;; --- Merge: move the threads and tasks of a branch into its target
|
||||
;;
|
||||
;; The thread is the unit: a merge moves a thread whole, with every task
|
||||
;; it holds, or leaves it on the branch file. A thread that stays keeps
|
||||
;; its review and its family when the branch file goes, and
|
||||
;; `move-branch-review-thread` can still move it later.
|
||||
|
||||
(def ^:private sql:get-branch-tasks
|
||||
"SELECT * FROM file_task
|
||||
@ -866,30 +964,26 @@
|
||||
ORDER BY created_at ASC
|
||||
FOR UPDATE")
|
||||
|
||||
(def ^:private sql:lock-thread-seqn
|
||||
"SELECT comment_thread_seqn FROM file WHERE id = ? FOR UPDATE")
|
||||
;; the threads the merge moves: those written outside any review, and
|
||||
;; those holding an open task
|
||||
(def ^:private sql:get-merged-threads
|
||||
"SELECT ct.id, ct.page_id, ct.shape_id, ct.anchor_type, ct.position
|
||||
FROM comment_thread AS ct
|
||||
WHERE ct.file_id = ?
|
||||
AND (ct.review_id IS NULL
|
||||
OR EXISTS (SELECT 1
|
||||
FROM file_task AS t
|
||||
WHERE t.thread_id = ct.id
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.status NOT IN ('verified', 'wont-do')))
|
||||
FOR UPDATE OF ct")
|
||||
|
||||
(defn- move-threads
|
||||
"Move the comment threads `thread-ids` of the branch into main. The
|
||||
number of a thread is unique in its file, so each one takes the next
|
||||
number of main."
|
||||
[conn main-id thread-ids]
|
||||
(when (seq thread-ids)
|
||||
(let [seqn (-> (db/exec-one! conn [sql:lock-thread-seqn main-id])
|
||||
(:comment-thread-seqn 0))]
|
||||
(doseq [[index thread-id] (d/enumerate thread-ids)]
|
||||
(db/update! conn :comment-thread
|
||||
{:file-id main-id
|
||||
:seqn (+ seqn index 1)}
|
||||
{:id thread-id}
|
||||
{::db/return-keys false}))
|
||||
(db/update! conn :file
|
||||
{:comment-thread-seqn (+ seqn (count thread-ids))}
|
||||
{:id main-id}
|
||||
{::db/return-keys false}))))
|
||||
(defn- open-task?
|
||||
[{:keys [status]}]
|
||||
(not (contains? closed-statuses status)))
|
||||
|
||||
(defn- send-tasks-moved-emails
|
||||
[{:keys [::db/conn] :as cfg} {:keys [team-id main-id actor-id branch-name file-name]} tasks]
|
||||
(defn- send-tasks-merged-emails
|
||||
[{:keys [::db/conn] :as cfg} {:keys [team-id target-id actor-id branch-name file-name]} tasks]
|
||||
(let [users (team-users conn team-id)
|
||||
actor (get-in users [actor-id :fullname] "")]
|
||||
(doseq [[assignee-id tasks] (group-by :assignee-id tasks)]
|
||||
@ -900,7 +994,7 @@
|
||||
(eml/send-template
|
||||
cfg
|
||||
{::eml/reuse-conn true
|
||||
::eml/template "tasks-moved"
|
||||
::eml/template "tasks-merged"
|
||||
:public-uri (cf/get :public-uri)
|
||||
:to email
|
||||
:name fullname
|
||||
@ -910,24 +1004,23 @@
|
||||
:task-titles (str/join "\n" (map #(str "- " (:title %)) tasks))
|
||||
:file-url (str/join [(cf/get :public-uri)
|
||||
"/#/workspace?"
|
||||
(uri/map->query-string {:file-id main-id
|
||||
(uri/map->query-string {:file-id target-id
|
||||
:team-id team-id})])}))))))
|
||||
|
||||
(defn- find-shape
|
||||
[data page-id shape-id]
|
||||
(get-in data [:pages-index page-id :objects shape-id]))
|
||||
|
||||
(defn- task-landing
|
||||
"Where an open task of a merged branch lands on main when the merge did
|
||||
not carry its layer: on the immediate parent of the layer when main has
|
||||
it, otherwise on the area of the canvas the layer covered. The layer is
|
||||
read from the branch document, or from the merge base when the branch
|
||||
deleted it; when neither has it, the task keeps its spot of the canvas.
|
||||
Nil when the task stays as it is: it is closed, points at the canvas,
|
||||
its layer reached main, or its page did not."
|
||||
[{:keys [merged-data branch-data base-data]} {:keys [page-id shape-id status position]}]
|
||||
(defn- layer-landing
|
||||
"Where a mark on the layer `shape-id` lands on the target when the
|
||||
target lacks the layer: on the immediate parent of the layer when the
|
||||
target has it, otherwise on the area of the canvas the layer covered.
|
||||
The layer is read from the branch document, or from the merge base when
|
||||
the branch deleted it; when neither has it, the mark keeps its spot
|
||||
`position` on the canvas. Nil when the mark stays as it is: it points
|
||||
at the canvas, its layer is on the target, or its page is not."
|
||||
[{:keys [merged-data branch-data base-data]} page-id shape-id position]
|
||||
(when (and (some? shape-id)
|
||||
(not (contains? closed-statuses status))
|
||||
(contains? (:pages-index merged-data) page-id)
|
||||
(nil? (find-shape merged-data page-id shape-id)))
|
||||
(let [layer (or (find-shape branch-data page-id shape-id)
|
||||
@ -950,6 +1043,21 @@
|
||||
{:frame-id uuid/zero
|
||||
:position position}))))
|
||||
|
||||
(defn- task-landing
|
||||
"Where an open task of a merged branch lands on the target
|
||||
(`layer-landing`). Nil for a closed task: it stays as it is."
|
||||
[datas {:keys [page-id shape-id position] :as task}]
|
||||
(when (open-task? task)
|
||||
(layer-landing datas page-id shape-id position)))
|
||||
|
||||
(defn- thread-landing
|
||||
"Where a thread of a merged branch lands on the target
|
||||
(`layer-landing`). Nil for a thread that points at no layer."
|
||||
[datas {:keys [anchor-type page-id shape-id position]}]
|
||||
(when (= "layer" anchor-type)
|
||||
(layer-landing datas page-id shape-id
|
||||
(cond-> position (db/pgpoint? position) (db/decode-pgpoint)))))
|
||||
|
||||
(defn- land-task
|
||||
"Point `task` where `task-landing` puts it, its thread created with it
|
||||
too, and record it as a `relinked` event."
|
||||
@ -967,53 +1075,230 @@
|
||||
{:shape-id shape-id :shape-name shape-name}
|
||||
{:shape-id nil :area area})))
|
||||
|
||||
(defn- move-to-target
|
||||
"Move `threads` and `tasks` into the file `target-id` for the merge
|
||||
`merge-id`. A thread keeps its number, which its family gives it. Each
|
||||
task records the merge and gets a `merged` event. A thread, or an open
|
||||
task, whose layer the target lacks lands where `thread-landing` or
|
||||
`task-landing` says, reading the layer in `datas`; a landed task gets
|
||||
a `relinked` event too."
|
||||
[conn {:keys [target-id merge-id branch-name profile-id]} datas threads tasks]
|
||||
(let [ts (ct/now)]
|
||||
(doseq [{:keys [id] :as thread} threads]
|
||||
(db/update! conn :comment-thread
|
||||
{:file-id target-id}
|
||||
{:id id}
|
||||
{::db/return-keys false})
|
||||
(when-let [landing (thread-landing datas thread)]
|
||||
(anchor-thread conn id landing)))
|
||||
(doseq [{:keys [id] :as task} tasks]
|
||||
(db/update! conn :file-task
|
||||
{:file-id target-id
|
||||
:merge-id merge-id
|
||||
:updated-at ts}
|
||||
{:id id}
|
||||
{::db/return-keys false})
|
||||
(insert-event conn id profile-id "merged"
|
||||
{:merge-id merge-id :branch-name branch-name})
|
||||
(when-let [landing (task-landing datas task)]
|
||||
(land-task conn profile-id task landing)))))
|
||||
|
||||
(defn- notify-merged-assignees
|
||||
"Tell the assignees of the open tasks among `tasks`, moved into
|
||||
`target-id`, by a `tasks-merged` email (`send-tasks-merged-emails`:
|
||||
never the actor `profile-id`, and only those who admit task emails)."
|
||||
[{:keys [::db/conn] :as cfg} {:keys [target-id branch-name profile-id]} tasks]
|
||||
(let [open (filterv open-task? tasks)]
|
||||
(when (seq open)
|
||||
(send-tasks-merged-emails cfg
|
||||
{:team-id (perms/get-team-id-for-file conn target-id)
|
||||
:target-id target-id
|
||||
:actor-id profile-id
|
||||
:branch-name branch-name
|
||||
:file-name (:name (db/get conn :file {:id target-id}
|
||||
{::sql/columns [:name]}))}
|
||||
open))))
|
||||
|
||||
(defn move-branch-tasks
|
||||
"Move every task of the branch file into main, inside the merge
|
||||
transaction: the open ones keep going on main, the closed ones stay as
|
||||
the history of the branch. Each task keeps the names it shows (the
|
||||
review title is refreshed from its pull request, which goes away with
|
||||
the branch), records the merge and gets a `moved-to-main` event. The
|
||||
threads of the tasks move with them. An open task whose layer the merge
|
||||
did not carry lands where `task-landing` says, with a `relinked` event,
|
||||
reading the layer in `merged-data`, `branch-data` and `base-data`. When
|
||||
`notify-assignees` is set, the assignees of the open tasks are told by
|
||||
email. Returns the moved tasks.
|
||||
"Move into the merge target `target-id`, inside the merge transaction,
|
||||
the threads of the branch file that hold an open task, whole with all
|
||||
their tasks, and the threads written outside any review, with theirs.
|
||||
An open task with no thread moves too. Every other thread stays on the
|
||||
branch file with its tasks, as the record of its review. The moved
|
||||
things land as `move-to-target` says, reading the layers in
|
||||
`merged-data`, `branch-data` and `base-data`. When `notify-assignees`
|
||||
is set, the assignees of the moved open tasks are told by email.
|
||||
Returns the moved tasks.
|
||||
|
||||
The branch file row is locked before the tasks are read, as task
|
||||
creation locks it (`lock-file`): a task created meanwhile is either
|
||||
read here or refused once the merge deleted the branch file."
|
||||
read here or refused once the merge deleted the branch file. The tasks
|
||||
of the branch are locked before the threads are chosen, so no task
|
||||
changes its state between the choice and the move."
|
||||
[{:keys [::db/conn] :as cfg}
|
||||
{:keys [branch-file-id main-id merge-id branch-name profile-id notify-assignees] :as params}]
|
||||
{:keys [branch-file-id notify-assignees] :as params}]
|
||||
(db/exec-one! conn [sql:lock-file branch-file-id])
|
||||
(let [tasks (into [] (map decode-row) (db/exec! conn [sql:get-branch-tasks branch-file-id]))]
|
||||
(when (seq tasks)
|
||||
(let [reviews (->> (keep :pull-request-id tasks)
|
||||
(distinct)
|
||||
(map #(db/get* conn :file-pull-request {:id %}))
|
||||
(remove nil?)
|
||||
(d/index-by :id))
|
||||
ts (ct/now)]
|
||||
(move-threads conn main-id (into [] (comp (keep :thread-id) (distinct)) tasks))
|
||||
(doseq [{:keys [id pull-request-id review-title] :as task} tasks]
|
||||
(db/update! conn :file-task
|
||||
{:file-id main-id
|
||||
:merge-id merge-id
|
||||
:branch-name branch-name
|
||||
:review-title (or (get-in reviews [pull-request-id :title]) review-title)
|
||||
:updated-at ts}
|
||||
{:id id}
|
||||
{::db/return-keys false})
|
||||
(insert-event conn (:id task) profile-id "moved-to-main"
|
||||
{:merge-id merge-id :branch-name branch-name})
|
||||
(when-let [landing (task-landing params task)]
|
||||
(land-task conn profile-id task landing)))
|
||||
(when notify-assignees
|
||||
(let [main (db/get conn :file {:id main-id} {::sql/columns [:name]})]
|
||||
(send-tasks-moved-emails cfg
|
||||
{:team-id (perms/get-team-id-for-file conn main-id)
|
||||
:main-id main-id
|
||||
:actor-id profile-id
|
||||
:branch-name branch-name
|
||||
:file-name (:name main)}
|
||||
(remove #(contains? closed-statuses (:status %)) tasks))))
|
||||
tasks))))
|
||||
(let [branch-tasks (into [] (map decode-row) (db/exec! conn [sql:get-branch-tasks branch-file-id]))
|
||||
threads (db/exec! conn [sql:get-merged-threads branch-file-id])
|
||||
thread-ids (into #{} (map :id) threads)
|
||||
tasks (filterv (fn [{:keys [thread-id] :as task}]
|
||||
(if (some? thread-id)
|
||||
(contains? thread-ids thread-id)
|
||||
(open-task? task)))
|
||||
branch-tasks)]
|
||||
(move-to-target conn params params threads tasks)
|
||||
(when notify-assignees
|
||||
(notify-merged-assignees cfg params tasks))
|
||||
tasks))
|
||||
|
||||
;; --- COMMAND: move-branch-review-thread
|
||||
|
||||
(def ^:private schema:move-branch-review-thread
|
||||
[:map {:title "move-branch-review-thread" :closed true}
|
||||
[:thread-id ::sm/uuid]])
|
||||
|
||||
(def ^:private sql:get-review-thread
|
||||
"SELECT ct.id,
|
||||
ct.file_id,
|
||||
ct.page_id,
|
||||
ct.shape_id,
|
||||
ct.anchor_type,
|
||||
ct.position,
|
||||
fb.source_file_id,
|
||||
m.id AS merge_id,
|
||||
m.file_id AS target_id,
|
||||
m.branch_name
|
||||
FROM comment_thread AS ct
|
||||
JOIN file_branch_review AS r ON (r.id = ct.review_id AND r.deleted_at IS NULL)
|
||||
JOIN file_branch AS fb ON (fb.id = r.file_branch_id)
|
||||
LEFT JOIN file_branch_merge AS m ON (m.file_branch_id = fb.id)
|
||||
WHERE ct.id = ?")
|
||||
|
||||
(def ^:private sql:get-thread-tasks
|
||||
"SELECT * FROM file_task
|
||||
WHERE thread_id = ?
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY created_at ASC
|
||||
FOR UPDATE")
|
||||
|
||||
(defn- get-review-thread
|
||||
"The thread `thread-id` of a design review, with the merge of its
|
||||
branch (`merge-id`, `target-id`, nil before the merge), or raise
|
||||
:not-found."
|
||||
[conn thread-id & {:as opts}]
|
||||
(let [thread (db/exec-one! conn [(cond-> sql:get-review-thread
|
||||
(::sql/for-update opts) (str " FOR UPDATE OF ct"))
|
||||
thread-id])]
|
||||
(when (nil? thread)
|
||||
(ex/raise :type :not-found
|
||||
:code :thread-not-found
|
||||
:hint "unable to find a thread of a design review with the provided id"
|
||||
:thread-id thread-id))
|
||||
thread))
|
||||
|
||||
(sv/defmethod ::move-branch-review-thread
|
||||
"Move a thread that stayed behind on a merged branch into the target of
|
||||
the merge, whole with its tasks: a review thread with no open task does
|
||||
not move with the merge. Anybody with edit rights on the target may move
|
||||
it. The thread lands on the target as the merge lands it, against the
|
||||
current data of the target: the branch document of a merged branch is
|
||||
not readable, so a thread or task whose layer the target lacks keeps
|
||||
its stored spot on the canvas. Each task records the merge with a
|
||||
`merged` event, and the assignees of its open tasks are told by a
|
||||
`tasks-merged` email. Refuses a thread of a branch that is not merged,
|
||||
and a thread already on the target."
|
||||
{::doc/added "2.16"
|
||||
::webhooks/event? true
|
||||
::sm/params schema:move-branch-review-thread
|
||||
::climit/id [[:move-branch-review-thread/by-profile ::rpc/profile-id]
|
||||
[:move-branch-review-thread/global]]}
|
||||
[cfg {:keys [::rpc/profile-id ::rpc/session-id thread-id]}]
|
||||
(check-tasks-enabled)
|
||||
(let [{:keys [target-id source-file-id]}
|
||||
(db/run! cfg (fn [{:keys [::db/conn]}] (get-review-thread conn thread-id)))]
|
||||
(when (nil? target-id)
|
||||
(files/check-read-permissions! cfg profile-id source-file-id)
|
||||
(ex/raise :type :validation
|
||||
:code :branch-not-merged
|
||||
:hint "the thread belongs to a branch that is not merged"
|
||||
:thread-id thread-id))
|
||||
(files/check-edition-permissions! cfg profile-id target-id)
|
||||
(run-and-notify
|
||||
cfg {:file-id target-id :profile-id profile-id :session-id session-id}
|
||||
:task-ids
|
||||
(fn [{:keys [::db/conn] :as cfg}]
|
||||
(lock-file conn target-id)
|
||||
(let [{:keys [file-id merge-id branch-name] :as thread}
|
||||
(get-review-thread conn thread-id {::sql/for-update true})]
|
||||
(when (= target-id file-id)
|
||||
(ex/raise :type :validation
|
||||
:code :thread-already-on-target
|
||||
:hint "the thread is already on the target of the merge"
|
||||
:thread-id thread-id))
|
||||
(let [tasks (into [] (map decode-row) (db/exec! conn [sql:get-thread-tasks thread-id]))
|
||||
;; no `branch-data` or `base-data`: a lost layer cannot be
|
||||
;; looked up, so `layer-landing` keeps the stored spot
|
||||
datas {:merged-data (:data (bfc/get-file cfg target-id :realize? true))}]
|
||||
(move-to-target conn {:target-id target-id
|
||||
:merge-id merge-id
|
||||
:branch-name branch-name
|
||||
:profile-id profile-id}
|
||||
datas [thread] tasks)
|
||||
(notify-merged-assignees cfg {:target-id target-id
|
||||
:branch-name branch-name
|
||||
:profile-id profile-id}
|
||||
tasks)
|
||||
{:thread-id thread-id
|
||||
:file-id target-id
|
||||
:task-ids (mapv :id tasks)}))))))
|
||||
|
||||
;; --- Review threads, wherever they live
|
||||
|
||||
(def ^:private sql:get-review-threads
|
||||
"SELECT ct.*,
|
||||
pf.fullname AS owner_fullname,
|
||||
pf.email AS owner_email,
|
||||
pf.photo_id AS owner_photo_id
|
||||
FROM comment_thread AS ct
|
||||
LEFT JOIN profile AS pf ON (pf.id = ct.owner_id)
|
||||
WHERE ct.review_id = ?
|
||||
ORDER BY ct.seqn ASC")
|
||||
|
||||
(def ^:private sql:get-review-comments
|
||||
"SELECT c.*,
|
||||
ct.file_id AS file_id,
|
||||
pf.fullname AS owner_fullname,
|
||||
pf.email AS owner_email,
|
||||
pf.photo_id AS owner_photo_id
|
||||
FROM comment AS c
|
||||
JOIN comment_thread AS ct ON (ct.id = c.thread_id)
|
||||
LEFT JOIN profile AS pf ON (pf.id = c.owner_id)
|
||||
WHERE ct.review_id = ?
|
||||
ORDER BY c.created_at ASC")
|
||||
|
||||
(def ^:private sql:get-review-thread-tasks
|
||||
(str sql:select-tasks
|
||||
" WHERE ct.review_id = ?
|
||||
AND t.deleted_at IS NULL
|
||||
ORDER BY t.created_at ASC"))
|
||||
|
||||
(defn get-review-threads
|
||||
"The threads of the design review `review-id`, by number, each with its
|
||||
`:comments`, oldest first, and its `:tasks` as `get-file-tasks` lists
|
||||
them. A thread is listed wherever it lives: on the target when the
|
||||
merge moved it, on the branch file when it stayed, or on no file
|
||||
(`file-id` nil) once the branch file is gone."
|
||||
[conn review-id]
|
||||
(let [comments (->> (db/exec! conn [sql:get-review-comments review-id])
|
||||
(into [] comments/xf-decode-row)
|
||||
(group-by :thread-id))
|
||||
tasks (->> (db/exec! conn [sql:get-review-thread-tasks review-id])
|
||||
(into [] (map decode-row))
|
||||
(group-by :thread-id))]
|
||||
(into []
|
||||
(comp comments/xf-decode-row
|
||||
(map (fn [{:keys [id] :as thread}]
|
||||
(assoc thread
|
||||
:comments (get comments id [])
|
||||
:tasks (get tasks id [])))))
|
||||
(db/exec! conn [sql:get-review-threads review-id]))))
|
||||
|
||||
@ -331,16 +331,19 @@
|
||||
:reprocess-changes-ms (get timings :reprocess-changes-ms)))
|
||||
(throw cause))))))
|
||||
|
||||
;; --- Design review activity
|
||||
;; --- Branch review activity
|
||||
|
||||
(def ^:private sql:get-open-review-of-branch-file
|
||||
"SELECT id FROM file_pull_request
|
||||
WHERE source_file_id = ?
|
||||
AND status = 'open'
|
||||
AND deleted_at IS NULL")
|
||||
"SELECT r.id
|
||||
FROM file_branch_review AS r
|
||||
JOIN file_branch AS b ON (b.id = r.file_branch_id)
|
||||
WHERE b.branch_file_id = ?
|
||||
AND r.status = 'open'
|
||||
AND r.deleted_at IS NULL")
|
||||
|
||||
(defn- get-open-review-id
|
||||
"The open design review of a branch file, if it has one."
|
||||
"The open branch review of a branch file, if it has one. Resolved
|
||||
through the branch edge: the review no longer stores its two sides."
|
||||
[conn file-id]
|
||||
(:id (db/exec-one! conn [sql:get-open-review-of-branch-file file-id])))
|
||||
|
||||
@ -358,14 +361,14 @@
|
||||
result)))
|
||||
|
||||
(defn- record-review-activity
|
||||
"Record the activity of a save of a branch under design review: who
|
||||
saved, the revn the save produced and what it did to each layer. A save
|
||||
that changed no layer records nothing."
|
||||
"Record the activity of a save of a branch under review: who saved, the
|
||||
revn the save produced and what it did to each layer. A save that
|
||||
changed no layer records nothing."
|
||||
[conn review-id profile-id {:keys [revn]} entries timestamp]
|
||||
(when (seq entries)
|
||||
(db/insert! conn :file-pull-request-activity
|
||||
(db/insert! conn :file-branch-review-activity
|
||||
{:id (uuid/next)
|
||||
:pull-request-id review-id
|
||||
:review-id review-id
|
||||
:profile-id profile-id
|
||||
:revn revn
|
||||
:entries (blob/encode entries)
|
||||
@ -401,8 +404,8 @@
|
||||
revn
|
||||
(get file :revn)
|
||||
|
||||
;; A save of a branch under design review records what it did
|
||||
;; to each layer, for the activity of the review.
|
||||
;; A save of a branch under review records what it did to each
|
||||
;; layer, for the activity of the review.
|
||||
review-id
|
||||
(when (:is-branch file)
|
||||
(get-open-review-id conn (:id file)))
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
[app.features.fdata :as fdata]
|
||||
[app.features.file-snapshots :as fsnap]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.files-pull-request :as fpr]
|
||||
[app.rpc.commands.files-branch-review :as fbr]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
[app.rpc.cond :as-alias cond]
|
||||
[app.rpc.doc :as-alias doc]
|
||||
@ -140,8 +140,8 @@
|
||||
file (-> (bfc/get-file cfg file-id)
|
||||
(bfc/file->response))
|
||||
|
||||
;; pull request review sandbox: the viewer shows the pinned
|
||||
;; review snapshot of the branch, not its live state
|
||||
;; branch review sandbox: the viewer shows the pinned snapshot
|
||||
;; of the branch, not its live state
|
||||
file (if-let [snapshot (::snapshot params)]
|
||||
(-> file
|
||||
(assoc :data (:data snapshot))
|
||||
@ -230,36 +230,47 @@
|
||||
:team (assoc team :permissions perms)
|
||||
:permissions perms}))
|
||||
|
||||
(defn- get-pull-request-view-context
|
||||
"Resolve the review-sandbox context of `pr-id`: permissions taken from
|
||||
the pull request's TARGET file (share-links do not apply here) with
|
||||
edition stripped, plus the pinned review snapshot whose data replaces
|
||||
the branch file's live state. Refuses when the pull request is not
|
||||
open or does not belong to `file-id` — the sandbox must never silently
|
||||
degrade to the live branch."
|
||||
[system profile-id file-id pr-id]
|
||||
(fpr/check-pull-requests-enabled!)
|
||||
(let [pr (db/get* system :file-pull-request {:id pr-id})]
|
||||
(when (or (nil? pr)
|
||||
(some? (:deleted-at pr))
|
||||
(not= file-id (:source-file-id pr)))
|
||||
(def ^:private sql:get-branch-review-for-viewer
|
||||
"SELECT r.id,
|
||||
r.status,
|
||||
r.pinned_snapshot_id,
|
||||
fb.branch_file_id AS source_file_id,
|
||||
fb.source_file_id AS target_file_id
|
||||
FROM file_branch_review AS r
|
||||
JOIN file_branch AS fb ON (fb.id = r.file_branch_id)
|
||||
WHERE r.id = ?
|
||||
AND r.deleted_at IS NULL")
|
||||
|
||||
(defn- get-branch-review-view-context
|
||||
"Resolve the review-sandbox context of `review-id`: permissions taken
|
||||
from the review's TARGET file (share-links do not apply here) with
|
||||
edition stripped, plus the pinned snapshot whose data replaces the
|
||||
branch file's live state. Refuses when the review is not open or its
|
||||
branch file is not `file-id` — the sandbox must never silently degrade
|
||||
to the live branch. Both sides come from the branch edge, which is the
|
||||
only place they live."
|
||||
[system profile-id file-id review-id]
|
||||
(fbr/check-branch-reviews-enabled!)
|
||||
(let [review (db/exec-one! system [sql:get-branch-review-for-viewer review-id])]
|
||||
(when (or (nil? review)
|
||||
(not= file-id (:source-file-id review)))
|
||||
(ex/raise :type :not-found
|
||||
:code :pull-request-not-found
|
||||
:hint "unable to find pull request with the provided id"
|
||||
:pull-request-id pr-id))
|
||||
(when (not= "open" (:status pr))
|
||||
:code :branch-review-not-found
|
||||
:hint "unable to find the branch review with the provided id"
|
||||
:review-id review-id))
|
||||
(when (not= "open" (:status review))
|
||||
(ex/raise :type :validation
|
||||
:code :pull-request-not-open
|
||||
:hint "the review sandbox only exists while the pull request is open"
|
||||
:pull-request-id pr-id))
|
||||
(let [perms (perms/get-file-read-permissions system profile-id (:target-file-id pr))
|
||||
snapshot (when (:review-snapshot-id pr)
|
||||
(fsnap/get-snapshot system (:source-file-id pr) (:review-snapshot-id pr)))]
|
||||
:code :branch-review-not-open
|
||||
:hint "the review sandbox only exists while the branch review is open"
|
||||
:review-id review-id))
|
||||
(let [perms (perms/get-file-read-permissions system profile-id (:target-file-id review))
|
||||
snapshot (when (:pinned-snapshot-id review)
|
||||
(fsnap/get-snapshot system (:source-file-id review) (:pinned-snapshot-id review)))]
|
||||
(when (and perms (nil? snapshot))
|
||||
(ex/raise :type :not-found
|
||||
:code :review-snapshot-missing
|
||||
:hint "the pull request review snapshot cannot be resolved"
|
||||
:pull-request-id pr-id))
|
||||
:hint "the branch review snapshot cannot be resolved"
|
||||
:review-id review-id))
|
||||
{:perms (some-> perms (assoc :can-edit false :is-admin false :is-owner false))
|
||||
:snapshot snapshot})))
|
||||
|
||||
@ -267,19 +278,19 @@
|
||||
[:map {:title "get-view-only-bundle"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:share-id {:optional true} ::sm/uuid]
|
||||
[:pr-id {:optional true} ::sm/uuid]
|
||||
[:review-id {:optional true} ::sm/uuid]
|
||||
[:features {:optional true} ::cfeat/features]])
|
||||
|
||||
(sv/defmethod ::get-view-only-bundle
|
||||
{::rpc/auth false
|
||||
::doc/added "1.17"
|
||||
::sm/params schema:get-view-only-bundle}
|
||||
[system {:keys [::rpc/profile-id file-id share-id pr-id] :as params}]
|
||||
[system {:keys [::rpc/profile-id file-id share-id review-id] :as params}]
|
||||
(db/run! system
|
||||
(fn [system]
|
||||
(let [{:keys [perms snapshot]}
|
||||
(if (some? pr-id)
|
||||
(get-pull-request-view-context system profile-id file-id pr-id)
|
||||
(if (some? review-id)
|
||||
(get-branch-review-view-context system profile-id file-id review-id)
|
||||
{:perms (perms/get-file-read-permissions system profile-id file-id share-id)})
|
||||
|
||||
params (-> params
|
||||
|
||||
@ -546,6 +546,13 @@
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; QUOTE: PULL-REQUESTS-PER-TEAM
|
||||
;;
|
||||
;; The quote id and its `:quotes-pull-requests-per-team` config key predate
|
||||
;; the branch-review vocabulary and stay as they are, so a deployment knob
|
||||
;; does not move under an operator. What it counts is open branch reviews,
|
||||
;; resolved through the family root: a review belongs to the family of the
|
||||
;; file its target lives on, and the family id IS that root file's id, so
|
||||
;; one join answers the team without walking the branch chain.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:private schema:pull-requests-per-team
|
||||
@ -558,12 +565,12 @@
|
||||
|
||||
(def ^:private sql:get-pull-requests-per-team
|
||||
"SELECT count(*) AS total
|
||||
FROM file_pull_request AS fpr
|
||||
JOIN file AS f ON (f.id = fpr.target_file_id)
|
||||
FROM file_branch_review AS r
|
||||
JOIN file AS f ON (f.id = r.family_id)
|
||||
JOIN project AS p ON (p.id = f.project_id)
|
||||
WHERE p.team_id = ?
|
||||
AND fpr.deleted_at IS NULL
|
||||
AND fpr.status = 'open'
|
||||
AND r.deleted_at IS NULL
|
||||
AND r.status = 'open'
|
||||
AND f.deleted_at IS NULL
|
||||
AND p.deleted_at IS NULL")
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
[app.common.time :as ct]
|
||||
[app.db :as db]
|
||||
[app.db.sql :as-alias sql]
|
||||
[app.features.file-snapshots :as fsnap]
|
||||
[app.jobs :as jobs]
|
||||
[app.loggers.audit :as audit]
|
||||
[app.rpc.commands.files :as files]
|
||||
@ -63,10 +64,72 @@
|
||||
{:id id :file-id file-id :type "snapshot"}
|
||||
{::db/return-keys false}))
|
||||
|
||||
;; --- Branching: what a deleted file takes with it
|
||||
;;
|
||||
;; A file's row is the unit of storage and permission, so the objects GC
|
||||
;; deletes it; its design reviews, threads, and tasks belong to the file
|
||||
;; family and outlive it, except those of a branch no merge accepted.
|
||||
|
||||
(def ^:private sql:get-branch-edges
|
||||
"SELECT fb.id AS edge_id,
|
||||
fb.base_snapshot_id,
|
||||
fb.source_file_id,
|
||||
EXISTS (SELECT 1
|
||||
FROM file_branch_merge AS fbm
|
||||
WHERE fbm.file_branch_id = fb.id) AS merged
|
||||
FROM file_branch AS fb
|
||||
WHERE fb.branch_file_id = ?")
|
||||
|
||||
(def ^:private sql:delete-unmerged-branch-reviews
|
||||
"DELETE FROM file_branch_review AS r
|
||||
WHERE r.file_branch_id = ?
|
||||
AND NOT EXISTS (SELECT 1
|
||||
FROM file_branch_merge AS fbm
|
||||
WHERE fbm.review_id = r.id)
|
||||
RETURNING r.pinned_snapshot_id")
|
||||
|
||||
(defn- delete-unmerged-branch
|
||||
"Delete what belonged to a branch that no merge accepted, before its
|
||||
file row goes: the threads written on it (their messages and read marks
|
||||
cascade), the tasks still on it, its reviews with their verdicts and
|
||||
activity, the merge base it was derived from, and the branch edge.
|
||||
|
||||
A merged branch keeps all of it. Its merge moved only the threads that
|
||||
hold an open task or that were written outside a review; a thread it
|
||||
leaves behind stays on the branch file, and the purge only nulls its
|
||||
`file_id`. Its edge and the review the merge names stay as the record
|
||||
of the merge, read long after the file is gone, and its merge base was
|
||||
released when it merged. Must run in the caller transaction."
|
||||
[{:keys [::db/conn] :as cfg}
|
||||
{:keys [file-id edge-id source-file-id base-snapshot-id deleted-at]}]
|
||||
;; a task names its thread with a `SET NULL` key, so the threads go
|
||||
;; first and the tasks are still found by their file afterwards
|
||||
(db/delete! conn :comment-thread {:file-id file-id} {::db/return-keys false})
|
||||
(db/delete! conn :file-task {:file-id file-id} {::db/return-keys false})
|
||||
(doseq [{:keys [pinned-snapshot-id]} (db/exec! conn [sql:delete-unmerged-branch-reviews edge-id])]
|
||||
;; the pinned revision is a change row of the branch file, held for
|
||||
;; years while the review lives; it dies with the review, or it would
|
||||
;; keep the file row from being collected
|
||||
(when (some? pinned-snapshot-id)
|
||||
(fsnap/delete! cfg
|
||||
:id pinned-snapshot-id
|
||||
:file-id file-id
|
||||
:deleted-at deleted-at)))
|
||||
;; the merge base is a change row of the source, pinned while the
|
||||
;; branch is open; it dies with the branch, or the source file row
|
||||
;; could not be collected either
|
||||
(when (some? base-snapshot-id)
|
||||
(fsnap/delete! cfg
|
||||
:id base-snapshot-id
|
||||
:file-id source-file-id
|
||||
:deleted-at deleted-at))
|
||||
(db/delete! conn :file-branch {:id edge-id} {::db/return-keys false}))
|
||||
|
||||
(def ^:private sql:get-file-branches
|
||||
"SELECT id, branch_file_id
|
||||
FROM file_branch
|
||||
WHERE source_file_id = ?
|
||||
AND branch_file_id IS NOT NULL
|
||||
AND deleted_at IS NULL")
|
||||
|
||||
(defmethod delete-object :file
|
||||
@ -86,29 +149,28 @@
|
||||
{:branch-file-id id}
|
||||
{::db/return-keys false})
|
||||
|
||||
;; Pull requests: when the deleted file is a branch copy, any open
|
||||
;; pull request over it can no longer be reviewed — close it (the
|
||||
;; row is kept: pull request history outlives its branch, and the
|
||||
;; review snapshot rows live in this file's file_change/file_data,
|
||||
;; which this same cascade marks deleted below). When the deleted
|
||||
;; file is a pull request TARGET, cascade the logical deletion: with
|
||||
;; main gone the pull request is unreachable forever.
|
||||
(db/update! conn :file-pull-request
|
||||
{:status "closed"
|
||||
:closed-at (ct/now)
|
||||
:updated-at (ct/now)}
|
||||
{:source-file-id id :status "open"}
|
||||
{::db/return-keys false})
|
||||
(db/update! conn :file-pull-request
|
||||
{:deleted-at deleted-at}
|
||||
{:target-file-id id}
|
||||
{::db/return-keys false})
|
||||
;; ... and settle what the branch owned. A branch no merge accepted
|
||||
;; takes its threads, tasks, reviews, and the edge itself with it; a
|
||||
;; merged branch keeps them, and the edge outlives the file, so the
|
||||
;; compare marks of either branch are deleted here: the cascade from
|
||||
;; the edge only reaches the marks of a branch whose edge goes.
|
||||
(doseq [{:keys [edge-id merged] :as edge} (db/exec! conn [sql:get-branch-edges id])]
|
||||
(db/delete! conn :file-branch-change-mark
|
||||
{:file-branch-id edge-id}
|
||||
{::db/return-keys false})
|
||||
(when-not merged
|
||||
(delete-unmerged-branch cfg (assoc edge
|
||||
:file-id id
|
||||
:deleted-at deleted-at))))
|
||||
|
||||
;; ... and when it is the SOURCE of branches, cascade the logical
|
||||
;; deletion to them: branch files are hidden from every listing, so
|
||||
;; once the source is gone nothing else could ever reach (or GC)
|
||||
;; them. A branch cannot be a source itself, so this recurses at
|
||||
;; most one level.
|
||||
;; them. Branches stack under `:branch-stacking`, so a branch file
|
||||
;; can be a source too: this follows the chain of edges to its end
|
||||
;; and a grandchild branch is deleted with the file its chain starts
|
||||
;; from. A parent that merged re-parented its children, so they are
|
||||
;; not in this branch list and survive it.
|
||||
(doseq [branch (db/exec! conn [sql:get-file-branches id])]
|
||||
(db/update! conn :file-branch
|
||||
{:deleted-at deleted-at}
|
||||
|
||||
@ -135,17 +135,18 @@
|
||||
{:fetch-size 5}))))))
|
||||
|
||||
;; A save of a branch under review records one activity row, and the table
|
||||
;; grows for the life of the review. The rows of one person's sitting (the
|
||||
;; same review and profile, no gap longer than `ra/default-session-gap-ms`)
|
||||
;; fold into one row once the sitting is finished: its entries concatenate
|
||||
;; in order, its last revn and timestamp stay. The reading side replays
|
||||
;; entries in order, so the fold leaves `net-entries` unchanged.
|
||||
;; grows for the life of the review, which is the life of its file family.
|
||||
;; The rows of one person's sitting (the same review and profile, no gap
|
||||
;; longer than `ra/default-session-gap-ms`) fold into one row once the
|
||||
;; sitting is finished: its entries concatenate in order, its last revn
|
||||
;; and timestamp stay. The reading side replays entries in order, so the
|
||||
;; fold leaves `net-entries` unchanged.
|
||||
|
||||
(def ^:private sql:get-review-activity-groups
|
||||
"SELECT pull_request_id, profile_id
|
||||
FROM file_pull_request_activity
|
||||
"SELECT review_id, profile_id
|
||||
FROM file_branch_review_activity
|
||||
WHERE created_at <= ?
|
||||
GROUP BY pull_request_id, profile_id
|
||||
GROUP BY review_id, profile_id
|
||||
ORDER BY max(created_at) ASC")
|
||||
|
||||
;; The profile comparison treats two nulls as equal, so the rows of a
|
||||
@ -157,8 +158,8 @@
|
||||
;; the other transaction instead, so the sitting is read whole.
|
||||
(def ^:private sql:lock-review-activity
|
||||
"SELECT id, revn, entries, created_at
|
||||
FROM file_pull_request_activity
|
||||
WHERE pull_request_id = ?
|
||||
FROM file_branch_review_activity
|
||||
WHERE review_id = ?
|
||||
AND profile_id IS NOT DISTINCT FROM ?::uuid
|
||||
AND created_at <= ?
|
||||
ORDER BY created_at ASC, id ASC
|
||||
@ -166,8 +167,8 @@
|
||||
|
||||
(def ^:private sql:get-next-review-activity
|
||||
"SELECT created_at
|
||||
FROM file_pull_request_activity
|
||||
WHERE pull_request_id = ?
|
||||
FROM file_branch_review_activity
|
||||
WHERE review_id = ?
|
||||
AND profile_id IS NOT DISTINCT FROM ?::uuid
|
||||
AND created_at > ?
|
||||
ORDER BY created_at ASC, id ASC
|
||||
@ -202,11 +203,11 @@
|
||||
|
||||
(defn- fold-review-activity-pair
|
||||
"Folds every finished sitting of one review and profile into one row."
|
||||
[conn [pull-request-id profile-id] cutoff gap-ms]
|
||||
[conn [review-id profile-id] cutoff gap-ms]
|
||||
(let [rows (db/exec! conn [sql:lock-review-activity
|
||||
pull-request-id profile-id cutoff])
|
||||
review-id profile-id cutoff])
|
||||
next-row (db/exec-one! conn [sql:get-next-review-activity
|
||||
pull-request-id profile-id cutoff])
|
||||
review-id profile-id cutoff])
|
||||
sittings (-> (split-sittings rows gap-ms)
|
||||
(drop-unfinished next-row gap-ms))]
|
||||
(reduce (fn [total sitting]
|
||||
@ -216,12 +217,12 @@
|
||||
entries (into []
|
||||
(mapcat (comp blob/decode :entries))
|
||||
sitting)]
|
||||
(db/update! conn :file-pull-request-activity
|
||||
(db/update! conn :file-branch-review-activity
|
||||
{:entries (blob/encode entries)}
|
||||
{:id (:id last-row)}
|
||||
{::db/return-keys false})
|
||||
(doseq [row (butlast sitting)]
|
||||
(db/delete! conn :file-pull-request-activity
|
||||
(db/delete! conn :file-branch-review-activity
|
||||
{:id (:id row)}
|
||||
{::db/return-keys false}))
|
||||
(+ total (dec (count sitting))))))
|
||||
@ -258,7 +259,7 @@
|
||||
(+ total deleted))))]
|
||||
(db/tx-run! (assoc cfg ::db/read-only true)
|
||||
(fn [{:keys [::db/conn ::cutoff]}]
|
||||
(transduce (comp (map (juxt :pull-request-id :profile-id))
|
||||
(transduce (comp (map (juxt :review-id :profile-id))
|
||||
(partition-all chunk-size))
|
||||
rf 0
|
||||
(db/plan conn [sql:get-review-activity-groups cutoff]
|
||||
|
||||
@ -184,7 +184,7 @@
|
||||
|
||||
(defn- update-branch
|
||||
[{:keys [profile branch-id]} & {:as params}]
|
||||
(th/command! (merge {::th/type :update-branch-from-main
|
||||
(th/command! (merge {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}
|
||||
params)))
|
||||
@ -253,7 +253,7 @@
|
||||
|
||||
(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"] [:main "#0000ff"]]]
|
||||
(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))]
|
||||
(both-edit-component ctx)
|
||||
@ -277,7 +277,7 @@
|
||||
|
||||
(t/deftest update-of-a-component-both-sides-edited-conflicts-on-the-component-only
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[side color] [[:branch "#00ff00"] [:main "#0000ff"]]]
|
||||
(doseq [[side color] [[:branch "#00ff00"] [:source "#0000ff"]]]
|
||||
(t/testing (str "resolved to " side)
|
||||
(let [{:keys [profile branch-file-id page-id mi-id copy-id] :as ctx} (setup (if (= :branch side) 1 2))]
|
||||
(both-edit-component ctx)
|
||||
@ -305,14 +305,14 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile branch-id comp-id mi-id copy-id] :as ctx} (setup 1)]
|
||||
(both-edit-component ctx)
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
diff (:result out)
|
||||
entry (first (filter #(= copy-id (:id %)) (:changes diff)))]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :settled (:status entry)))
|
||||
(t/is (= {:side :main :reason :follows-component} (get-in entry [:settled :attrs :fills])))
|
||||
(t/is (= {:side :source :reason :follows-component} (get-in entry [:settled :attrs :fills])))
|
||||
(t/is (= [[mi-id 1]] (mapv (juxt :id :copies-affected) (:conflicts diff))))
|
||||
(t/is (= [[comp-id mi-id #{copy-id}]]
|
||||
(mapv (juxt :component-id :main-id #(into #{} (map :id) (:copies %)))
|
||||
@ -457,8 +457,8 @@
|
||||
|
||||
(t/deftest a-token-both-sides-applied-to-the-component-conflicts-on-it-only
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(doseq [[n dir side token] [[1 :merge :branch "green"] [2 :merge :main "blue"]
|
||||
[3 :update :branch "green"] [4 :update :main "blue"]]]
|
||||
(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)]
|
||||
(save profile branch-file-id (tokenize-component page-id mi-id copy-id "green"))
|
||||
|
||||
432
backend/test/backend_tests/branch_family_gc_test.clj
Normal file
432
backend/test/backend_tests/branch_family_gc_test.clj
Normal file
@ -0,0 +1,432 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC Sucursal en España SL
|
||||
|
||||
(ns backend-tests.branch-family-gc-test
|
||||
"The objects GC deletes a branch's file row, and what the branch owned
|
||||
belongs to its file family: the review with its verdicts and activity,
|
||||
the review threads the merge left on the branch with their tasks, the
|
||||
branch edge that names it, and the compare marks of the branch. A merge
|
||||
moves the threads holding an open task to the target; the other review
|
||||
threads stay with the branch and outlive its file, readable through
|
||||
their review; a branch no merge accepted takes them with it. A deleted
|
||||
file reaches every branch cut from it, however deep the chain."
|
||||
(:require
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.rpc :as-alias rpc]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
(defn- flags
|
||||
"The test flags plus `:branching`, read at run time, inside the
|
||||
`th/state-init` fixture, so the flags it turns off stay off: a value
|
||||
captured when the namespace loads would carry the production defaults
|
||||
instead."
|
||||
[]
|
||||
(conj cf/flags :branching))
|
||||
|
||||
(defn- stack-flags
|
||||
[]
|
||||
(conj (flags) :branch-stacking))
|
||||
|
||||
(defn- page-id-of
|
||||
[profile file-id]
|
||||
(-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id file-id})
|
||||
:result :data :pages first))
|
||||
|
||||
(defn- update-file*
|
||||
[profile file-id changes]
|
||||
(let [f (th/db-get :file {:id file-id})]
|
||||
(th/command! {::th/type :update-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id file-id
|
||||
:session-id (uuid/random)
|
||||
:revn (:revn f)
|
||||
:vern (:vern f)
|
||||
:features cfeat/supported-features
|
||||
:changes changes})))
|
||||
|
||||
(defn- add-rect*
|
||||
[profile file-id page-id rect-id name]
|
||||
(update-file* profile file-id
|
||||
[{:type :add-obj
|
||||
:page-id page-id
|
||||
:id rect-id
|
||||
:parent-id uuid/zero
|
||||
:frame-id uuid/zero
|
||||
:obj (cts/setup-shape
|
||||
{:id rect-id :name name :type :rect
|
||||
:parent-id uuid/zero :frame-id uuid/zero})}]))
|
||||
|
||||
(defn- delete-obj*
|
||||
[profile file-id page-id shape-id]
|
||||
(update-file* profile file-id
|
||||
[{:type :del-obj :page-id page-id :id shape-id}]))
|
||||
|
||||
(defn- create-branch*
|
||||
[profile file-id name]
|
||||
(:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id file-id
|
||||
:name name})))
|
||||
|
||||
(defn- create-review*
|
||||
[profile branch reviewer]
|
||||
(:result (th/command! {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id branch)
|
||||
:title "Checkout redesign"
|
||||
:reviewers [(:id reviewer)]})))
|
||||
|
||||
(defn- submit-verdict*
|
||||
[profile review verdict]
|
||||
(th/command! {::th/type :submit-branch-review-verdict
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id review)
|
||||
:verdict verdict
|
||||
:comment "the token reads well"}))
|
||||
|
||||
(defn- create-thread*
|
||||
[profile file-id page-id params]
|
||||
(:result (th/command! (merge {::th/type :create-comment-thread
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "does this keep the token?"}
|
||||
params))))
|
||||
|
||||
(defn- threads-of
|
||||
[profile file-id]
|
||||
(:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id file-id})))
|
||||
|
||||
(defn- review-of
|
||||
[profile review-id]
|
||||
(:result (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id profile)
|
||||
:id review-id})))
|
||||
|
||||
(defn- activity-of
|
||||
[profile review-id]
|
||||
(:result (th/command! {::th/type :get-branch-review-activity
|
||||
::rpc/profile-id (:id profile)
|
||||
:id review-id})))
|
||||
|
||||
(defn- row
|
||||
"A row as it stands after a soft delete, or nil once it is gone."
|
||||
[table id]
|
||||
(th/db-get table {:id id} {::db/remove-deleted false}))
|
||||
|
||||
(defn- run-gc!
|
||||
"Run the deletion cascade the commands queued, then collect everything
|
||||
it marked, every delay past, as a later GC run would."
|
||||
[]
|
||||
(th/run-pending-jobs)
|
||||
(th/run-task! :objects-gc {:skip-delay true}))
|
||||
|
||||
(defn- setup-reviewed-branch
|
||||
"A file with a layer, a branch of it, and an open review of the branch
|
||||
with a reviewer. Returns the ids the tests need; the tests write the
|
||||
thread, because each one anchors it differently."
|
||||
[]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})
|
||||
page-id (page-id-of author (:id file))
|
||||
rect-id (uuid/random)]
|
||||
(th/create-team-role* {:team-id (:default-team-id author)
|
||||
:profile-id (:id reviewer)
|
||||
:role :editor})
|
||||
(add-rect* author (:id file) page-id rect-id "Pay button")
|
||||
(let [branch (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)
|
||||
:name "review-pay-button"}))
|
||||
review (create-review* author branch reviewer)]
|
||||
{:author author
|
||||
:reviewer reviewer
|
||||
:file file
|
||||
:page-id page-id
|
||||
:rect-id rect-id
|
||||
:branch branch
|
||||
:branch-file-id (:branch-file-id branch)
|
||||
:review review})))
|
||||
|
||||
(t/deftest a-merged-branch-s-thread-and-review-outlive-its-file
|
||||
;; The acceptance case: the review holds a thread with no task, whose
|
||||
;; layer the branch deleted before the merge, and a thread whose only
|
||||
;; task is closed. Neither holds an open task, so the merge leaves both
|
||||
;; on the branch, and deleting the branch file afterwards takes neither
|
||||
;; the threads nor the review with it: they lose their file and read
|
||||
;; through the review.
|
||||
(with-redefs [cf/flags (flags)]
|
||||
(let [{:keys [author reviewer file page-id rect-id branch branch-file-id review]}
|
||||
(setup-reviewed-branch)
|
||||
|
||||
thread (create-thread* author branch-file-id page-id
|
||||
{:anchor {:type :layer :shape-id rect-id}
|
||||
:review-id (:id review)})
|
||||
task (:result (th/command! {::th/type :create-task
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:review-id (:id review)
|
||||
:title "Drop the promo"}))]
|
||||
|
||||
(t/testing "the threads hang from the open review"
|
||||
(t/is (some? (:id review)))
|
||||
(t/is (some? (:id thread)))
|
||||
(t/is (= (:id review) (:review-id (row :comment-thread (:id thread)))))
|
||||
(t/is (= (:id review) (:review-id (row :comment-thread (:thread-id task))))))
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :set-task-status
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id task)
|
||||
:status "wont-do"}))))
|
||||
|
||||
(t/testing "the reviewer approves"
|
||||
(let [out (submit-verdict* reviewer review "approved")]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
;; the marks of a comparison are the branch's, not the review's
|
||||
(let [out (th/command! {::th/type :set-branch-change-mark
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:branch-id (:id branch)
|
||||
:direction :branch->source
|
||||
:change-key (str "shape:" rect-id)
|
||||
:fingerprint "0c0ffee"
|
||||
:reviewed true})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
;; the branch deletes the layer its thread points at: the review is
|
||||
;; open, so the save is the review's activity
|
||||
(t/is (nil? (:error (delete-obj* author branch-file-id page-id rect-id))))
|
||||
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
|
||||
(run-gc!)
|
||||
|
||||
(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/is (empty? (threads-of author (:id file)))))
|
||||
|
||||
(t/testing "the threads read through their review, with no file"
|
||||
(let [out (th/command! {::th/type :get-branch-review-threads
|
||||
::rpc/profile-id (:id author)
|
||||
:review-id (:id review)})
|
||||
threads (:result out)
|
||||
by-id (into {} (map (juxt :id identity)) threads)
|
||||
quiet (get by-id (:id thread))
|
||||
closed (get by-id (:thread-id task))]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= #{(:id thread) (:thread-id task)} (set (keys by-id))))
|
||||
(t/is (every? (comp nil? :file-id) threads))
|
||||
(t/is (= ["does this keep the token?"] (mapv :content (:comments quiet))))
|
||||
(t/is (= [] (:tasks quiet)))
|
||||
(t/is (= :layer (:anchor-type quiet)))
|
||||
(t/is (= rect-id (:shape-id quiet)))
|
||||
(t/is (= ["Drop the promo"] (mapv :content (:comments closed))))
|
||||
(t/is (= [(:id task)] (mapv :id (:tasks closed))))
|
||||
(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"
|
||||
(let [out (th/command! {::th/type :move-branch-review-thread
|
||||
::rpc/profile-id (:id author)
|
||||
:thread-id (:thread-id task)})
|
||||
tasks (:result (th/command! {::th/type :get-file-tasks
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))
|
||||
event (last (:result (th/command! {::th/type :get-task-events
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id task)})))]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= [(:thread-id task)] (mapv :id (threads-of author (:id file)))))
|
||||
(t/is (= (:id file) (:file-id (row :comment-thread (:thread-id task)))))
|
||||
(t/is (= [(:id task)] (mapv :id tasks)))
|
||||
(t/is (= (:id file) (:file-id (first tasks))))
|
||||
(t/is (some? (:merge-id (first tasks))))
|
||||
(t/is (= "merged" (:type event)))
|
||||
(t/is (= "review-pay-button" (-> event :payload :branch-name)))))
|
||||
|
||||
(t/testing "the review reads on main with its verdict"
|
||||
(let [result (review-of author (:id review))]
|
||||
(t/is (some? result))
|
||||
(t/is (= "Checkout redesign" (:title result)))
|
||||
(t/is (= "merged" (:status result)))
|
||||
(t/is (= "approved" (:overall-verdict result)))
|
||||
(t/is (= [(:id reviewer)] (mapv :profile-id (:reviews result))))
|
||||
(t/is (= ["approved"] (mapv :verdict (:reviews result))))
|
||||
(t/is (= (:id file) (:target-file-id result)))))
|
||||
|
||||
(t/testing "the activity of the review is kept"
|
||||
(let [{:keys [entries sessions people]} (activity-of author (:id review))]
|
||||
(t/is (= 1 people))
|
||||
(t/is (= 1 (count sessions)))
|
||||
(t/is (= [[rect-id]]
|
||||
(mapv (fn [sitting] (mapv :id (:entries sitting))) sessions)))
|
||||
(t/is (= [rect-id] (mapv :id entries)))
|
||||
(t/is (= [:deleted] (mapv :kind entries)))))
|
||||
|
||||
(t/testing "the branch edge outlives the file and still names the target"
|
||||
(let [edge (row :file-branch (:id branch))]
|
||||
(t/is (some? edge))
|
||||
(t/is (nil? (:branch-file-id edge)))
|
||||
(t/is (= "merged" (:status edge)))
|
||||
(t/is (= (:id file) (:source-file-id edge)))))
|
||||
|
||||
(t/testing "the compare marks die with the branch file"
|
||||
(t/is (empty? (th/db-query :file-branch-change-mark
|
||||
{:file-branch-id (:id branch)})))))))
|
||||
|
||||
(t/deftest a-deleted-unmerged-branch-takes-its-thread-and-review-with-it
|
||||
;; The mirror: nothing moved a thread or a task to the target, so the
|
||||
;; branch was all they had. Deleting it deletes them, its review with
|
||||
;; its verdicts and activity, and the edge itself.
|
||||
(with-redefs [cf/flags (flags)]
|
||||
(let [{:keys [author reviewer page-id file branch branch-file-id review]}
|
||||
(setup-reviewed-branch)
|
||||
|
||||
thread (create-thread* author branch-file-id page-id {:anchor {:type :point}})
|
||||
task (:result (th/command! {::th/type :create-task
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:title "Use the secondary token"}))]
|
||||
|
||||
(t/is (nil? (:error (submit-verdict* reviewer review "approved"))))
|
||||
|
||||
(let [out (th/command! {::th/type :set-branch-change-mark
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:branch-id (:id branch)
|
||||
:direction :branch->source
|
||||
:change-key "shape:pay-button"
|
||||
:fingerprint "0c0ffee"
|
||||
:reviewed true})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
;; a save of the branch while the review is open records activity
|
||||
(t/is (nil? (:error (add-rect* author branch-file-id page-id
|
||||
(uuid/random) "Badge"))))
|
||||
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
(run-gc!)
|
||||
|
||||
(t/testing "the branch file and its edge are gone"
|
||||
(t/is (nil? (row :file branch-file-id)))
|
||||
(t/is (nil? (row :file-branch (:id branch))))
|
||||
(t/is (empty? (th/db-query :file-branch-change-mark
|
||||
{:file-branch-id (:id branch)}))))
|
||||
|
||||
(t/testing "the thread is gone"
|
||||
(t/is (nil? (row :comment-thread (:id thread))))
|
||||
(t/is (= [] (threads-of author (:id file)))))
|
||||
|
||||
(t/testing "the task of the branch is gone with its thread"
|
||||
(t/is (some? (:id task)))
|
||||
(t/is (nil? (row :file-task (:id task))))
|
||||
(t/is (nil? (row :comment-thread (:thread-id task)))))
|
||||
|
||||
(t/testing "the review is gone with its verdicts and activity"
|
||||
(t/is (nil? (row :file-branch-review (:id review))))
|
||||
(t/is (empty? (th/db-query :file-branch-reviewer
|
||||
{:review-id (:id review)}
|
||||
{::db/remove-deleted false})))
|
||||
(t/is (empty? (th/db-query :file-branch-review-activity
|
||||
{:review-id (:id review)})))))))
|
||||
|
||||
(defn- stacked-branches
|
||||
"A file, a branch of it, and a branch of that branch, which only the
|
||||
`:branch-stacking` flag allows."
|
||||
[profile file]
|
||||
(let [parent (create-branch* profile (:id file) "parent")
|
||||
child (create-branch* profile (:branch-file-id parent) "child")]
|
||||
{:parent parent :child child}))
|
||||
|
||||
(t/deftest deleting-a-file-reaches-the-branches-of-its-branches
|
||||
;; The cascade follows the chain of edges to its end: a grandchild
|
||||
;; branch file is deleted with the file the chain starts from.
|
||||
(with-redefs [cf/flags (stack-flags)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
{:keys [parent child]} (stacked-branches profile file)]
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)}))))
|
||||
|
||||
(th/run-pending-jobs)
|
||||
|
||||
(t/testing "the cascade marks both branch files"
|
||||
(t/is (some? (:deleted-at (row :file (:branch-file-id parent)))))
|
||||
(t/is (some? (:deleted-at (row :file (:branch-file-id child))))))
|
||||
|
||||
(t/is (pos? (:processed (th/run-task! :objects-gc {:skip-delay true}))))
|
||||
|
||||
(t/testing "the file and both branch files are collected"
|
||||
(t/is (nil? (row :file (:id file))))
|
||||
(t/is (nil? (row :file (:branch-file-id parent))))
|
||||
(t/is (nil? (row :file (:branch-file-id child)))))
|
||||
|
||||
(t/testing "their edges go with them, nothing merged them"
|
||||
(t/is (nil? (row :file-branch (:id parent))))
|
||||
(t/is (nil? (row :file-branch (:id child))))))))
|
||||
|
||||
(t/deftest deleting-a-project-reaches-a-grandchild-branch
|
||||
;; The same chain under a project deletion, which reaches the branch
|
||||
;; files both through the project's file list and through the cascade
|
||||
;; of their source, and the family goes once its last file is gone.
|
||||
(with-redefs [cf/flags (stack-flags)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
project (th/create-project* 81 {:profile-id (:id profile)
|
||||
:team-id (:default-team-id profile)})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id project)})
|
||||
{:keys [parent child]} (stacked-branches profile file)]
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-project
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id project)}))))
|
||||
|
||||
(run-gc!)
|
||||
|
||||
(t/testing "every file of the family is gone"
|
||||
(t/is (nil? (row :file (:id file))))
|
||||
(t/is (nil? (row :file (:branch-file-id parent))))
|
||||
(t/is (nil? (row :file (:branch-file-id child)))))
|
||||
|
||||
(t/testing "the edges are gone and the family with them"
|
||||
(t/is (nil? (row :file-branch (:id parent))))
|
||||
(t/is (nil? (row :file-branch (:id child))))
|
||||
(t/is (nil? (th/db-get :file-family {:id (:id file)})))))))
|
||||
176
backend/test/backend_tests/branch_family_schema_test.clj
Normal file
176
backend/test/backend_tests/branch_family_schema_test.clj
Normal file
@ -0,0 +1,176 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC Sucursal en España SL
|
||||
|
||||
(ns backend-tests.branch-family-schema-test
|
||||
"The family schema of migration 0817: a file and its branches share a
|
||||
family, the rows the family owns name it, and no foreign key lets the
|
||||
deletion of a file take a review, a thread, or a task with it."
|
||||
(:require
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.email :as eml]
|
||||
[app.rpc :as-alias rpc]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
(defn- branching-flags
|
||||
"The test flags plus `:branching`, read inside the fixture so the flags
|
||||
the fixture turns off stay off."
|
||||
[]
|
||||
(conj cf/flags :branching))
|
||||
|
||||
(defn- query
|
||||
[sql & params]
|
||||
(db/exec! th/*pool* (into [sql] params)))
|
||||
|
||||
(defn- hard-delete-file!
|
||||
"Hard-delete a file row the way the objects GC does: the rows that
|
||||
still name it go first, or the `file` foreign keys reject the delete
|
||||
with the rows the GC purges before the file."
|
||||
[file-id]
|
||||
(th/db-force-delete :file-change {:file-id file-id})
|
||||
(th/db-force-delete :file-data {:file-id file-id})
|
||||
(th/db-force-delete :file {:id file-id}))
|
||||
|
||||
(defn- family-of
|
||||
[table id]
|
||||
(-> (query (str "SELECT family_id FROM " table " WHERE id = ?") id)
|
||||
first
|
||||
:family-id))
|
||||
|
||||
(defn- page-id-of
|
||||
[profile file-id]
|
||||
(-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id file-id})
|
||||
:result :data :pages first))
|
||||
|
||||
(defn- setup-branch
|
||||
"A file, a branch of it, an open review of the branch, a thread and a
|
||||
task on the branch, and a thread on the file."
|
||||
[]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})
|
||||
page-id (page-id-of author (:id file))
|
||||
_ (th/create-team-role* {:team-id (:default-team-id author)
|
||||
:profile-id (:id reviewer)
|
||||
:role :editor})
|
||||
branch (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)
|
||||
:name "feature-login"}))
|
||||
review (:result (th/command! {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)
|
||||
:title "Checkout redesign"
|
||||
:reviewers [(:id reviewer)]}))
|
||||
thread (fn [file-id]
|
||||
(:result (th/command! {::th/type :create-comment-thread
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "Check the spacing"})))
|
||||
task (:result (th/command! {::th/type :create-task
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:branch-file-id branch)
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:title "Use the secondary token"}))]
|
||||
{:file file
|
||||
:branch branch
|
||||
:branch-file-id (:branch-file-id branch)
|
||||
:review review
|
||||
:file-thread (thread (:id file))
|
||||
:branch-thread (thread (:branch-file-id branch))
|
||||
:task task}))
|
||||
|
||||
(t/deftest a-file-founds-its-own-family
|
||||
(let [profile (th/create-profile* 1)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})]
|
||||
(t/is (= (:id file) (family-of "file" (:id file))))
|
||||
(t/is (= 1 (count (query "SELECT id FROM file_family WHERE id = ?" (:id file)))))))
|
||||
|
||||
(t/deftest the-family-goes-with-its-last-file
|
||||
(let [profile (th/create-profile* 1)
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})]
|
||||
(hard-delete-file! (:id file))
|
||||
(t/is (empty? (query "SELECT id FROM file_family WHERE id = ?" (:id file))))))
|
||||
|
||||
(t/deftest a-branch-and-its-rows-carry-the-family-of-the-source
|
||||
(with-redefs [cf/flags (branching-flags)
|
||||
eml/send-template (fn [_ _] nil)]
|
||||
(let [{:keys [file branch-file-id review file-thread branch-thread task]} (setup-branch)
|
||||
family-id (:id file)]
|
||||
(t/is (some? branch-file-id))
|
||||
(t/is (= family-id (family-of "file" (:id file))))
|
||||
(t/is (= family-id (family-of "file" branch-file-id)))
|
||||
(t/is (= family-id (family-of "file_branch_review" (:id review))))
|
||||
(t/is (= family-id (family-of "comment_thread" (:id file-thread))))
|
||||
(t/is (= family-id (family-of "comment_thread" (:id branch-thread))))
|
||||
(t/is (= family-id (family-of "file_task" (:id task))))
|
||||
|
||||
(t/testing "the threads of the file and of its branch share one numbering"
|
||||
(let [seqns (->> (query "SELECT seqn FROM comment_thread WHERE family_id = ?" family-id)
|
||||
(mapv :seqn))
|
||||
top (-> (query "SELECT thread_seqn FROM file_family WHERE id = ?" family-id)
|
||||
first :thread-seqn)]
|
||||
;; the file's thread, the branch's thread, and the task's thread
|
||||
(t/is (= 3 (count seqns)))
|
||||
(t/is (= (count seqns) (count (set seqns))))
|
||||
(t/is (= top (apply max seqns)))))
|
||||
|
||||
(t/testing "hard-deleting the branch file keeps the review, its threads, and its tasks"
|
||||
(hard-delete-file! branch-file-id)
|
||||
(t/is (= family-id (family-of "file_branch_review" (:id review))))
|
||||
(t/is (= [[nil family-id]]
|
||||
(map (juxt :file-id :family-id)
|
||||
(query "SELECT file_id, family_id FROM comment_thread WHERE id = ?"
|
||||
(:id branch-thread)))))
|
||||
(t/is (= [[nil family-id]]
|
||||
(map (juxt :file-id :family-id)
|
||||
(query "SELECT file_id, family_id FROM file_task WHERE id = ?"
|
||||
(:id task)))))
|
||||
(t/is (seq (query "SELECT id FROM file_family WHERE id = ?" family-id)))))))
|
||||
|
||||
(t/deftest no-file-deletion-cascades-into-the-family-rows
|
||||
;; Only the death of the family may delete a review, a thread, or a
|
||||
;; task: a cascade from `file` would destroy them at every branch GC.
|
||||
(t/is (= []
|
||||
(query "SELECT conrelid::regclass::text AS tbl, conname
|
||||
FROM pg_constraint
|
||||
WHERE contype = 'f'
|
||||
AND confdeltype = 'c'
|
||||
AND confrelid = 'file'::regclass
|
||||
AND conrelid IN ('file_branch_review'::regclass,
|
||||
'comment_thread'::regclass,
|
||||
'file_task'::regclass)"))))
|
||||
|
||||
(t/deftest thread-numbers-are-unique-per-family
|
||||
(t/is (= [{:indisunique true :columns "family_id, seqn"}]
|
||||
(query "SELECT i.indisunique,
|
||||
(SELECT string_agg(a.attname, ', ' ORDER BY k.ord)
|
||||
FROM unnest(i.indkey) WITH ORDINALITY AS k(attnum, ord)
|
||||
JOIN pg_attribute AS a
|
||||
ON (a.attrelid = i.indrelid AND a.attnum = k.attnum)) AS columns
|
||||
FROM pg_index AS i
|
||||
WHERE i.indexrelid = 'comment_thread__family_id__seqn__idx'::regclass")))
|
||||
(t/is (empty? (query "SELECT attname
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = 'file'::regclass
|
||||
AND attname = 'comment_thread_seqn'
|
||||
AND NOT attisdropped"))))
|
||||
@ -188,7 +188,7 @@
|
||||
(save profile main-id [(set-fill page-id mi-id "#0000ff")
|
||||
(set-fill page-id copy-id "#0000ff")])
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -226,10 +226,10 @@
|
||||
|
||||
(t/deftest materialize-keeps-the-base-components
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [{:keys [profile page-id comp-id mi-id copy-id branch-file-id]} (setup)
|
||||
out (th/command! {::th/type :materialize-file-branch
|
||||
(let [{:keys [profile page-id comp-id mi-id copy-id branch-id branch-file-id]} (setup)
|
||||
out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
|
||||
(let [file (get-file profile branch-file-id)
|
||||
@ -269,14 +269,14 @@
|
||||
(assoc :fills [{:fill-opacity 1
|
||||
:fill-image {:id (:id fmo) :width 100 :height 100
|
||||
:mtype "image/png"}}])))])
|
||||
branch-file-id (-> (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id main-id
|
||||
:name "photos"})
|
||||
:result :branch-file-id)
|
||||
out (th/command! {::th/type :materialize-file-branch
|
||||
create (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id main-id
|
||||
:name "photos"}))
|
||||
branch-file-id (:branch-file-id create)
|
||||
out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
|
||||
(let [image-id (-> (get-file profile branch-file-id)
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
(let [res (bm/compute-merge (file-data 0 {})
|
||||
(file-data 5 {})
|
||||
(file-data 0 nil-ref)
|
||||
:main->branch)]
|
||||
: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 (= :modified (:status (first (:changes res)))))))
|
||||
@ -53,7 +53,7 @@
|
||||
(let [res (bm/compute-merge (file-data 0 nil-ref)
|
||||
(file-data 5 nil-ref)
|
||||
(file-data 0 {})
|
||||
:main->branch)]
|
||||
:source->branch)]
|
||||
(is (zero? (count (:conflicts res))))
|
||||
(is (= 1 (count (:changes res)))))))
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
(let [res (bm/compute-merge (file-data 0 {})
|
||||
(file-data 5 {})
|
||||
(file-data -5 {})
|
||||
:main->branch)]
|
||||
:source->branch)]
|
||||
(is (= 1 (count (:conflicts res))))
|
||||
(is (= :modify-modify (:reason (first (:conflicts res)))))))
|
||||
|
||||
@ -70,6 +70,6 @@
|
||||
(let [res (bm/compute-merge (file-data 0 {})
|
||||
(file-data 5 {})
|
||||
(file-data 0 {})
|
||||
:main->branch)]
|
||||
:source->branch)]
|
||||
(is (zero? (count (:conflicts res))))
|
||||
(is (= 1 (count (:changes res)))))))
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
|
||||
(defn- update-from-main!
|
||||
[profile branch-file-id]
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (branch-row-id branch-file-id)})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -258,7 +258,7 @@
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (branch-row-id branch-id)}))))
|
||||
:branch-id (branch-row-id branch-id)}))))
|
||||
|
||||
;; the deletion is pending and the branch still links the library
|
||||
(t/is (some? (:deleted-at (th/db-get :file {:id branch-id}
|
||||
|
||||
@ -185,10 +185,10 @@
|
||||
(t/is (true? (th/run-task! :file-gc {:file-id file-id})))
|
||||
(t/is (every? (live-fragment-ids file-id) pinned))
|
||||
|
||||
(let [diff (:result (th/command! {::th/type :get-branch-diff
|
||||
(let [diff (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id profile-id
|
||||
:branch-id (:id branch)
|
||||
:direction :main->branch}))]
|
||||
:direction :source->branch}))]
|
||||
(t/is (= 1 (-> diff :stats :added)))))))
|
||||
|
||||
(t/deftest update-from-main-pins-main-pointers
|
||||
@ -197,7 +197,7 @@
|
||||
branch (create-branch! profile-id file-id "update")
|
||||
page-id (first (:pages (realized-data file-id)))]
|
||||
(update-file! profile-id file-id [(add-rect page-id)])
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id profile-id
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -273,11 +273,11 @@
|
||||
(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)])
|
||||
|
||||
(doseq [dir [:branch->main :main->branch]]
|
||||
(doseq [dir [:branch->source :source->branch]]
|
||||
(let [loads (atom 0)
|
||||
load fdata/load-pointer
|
||||
out (with-redefs [fdata/load-pointer (fn [& args] (swap! loads inc) (apply load args))]
|
||||
(th/command! {::th/type :get-branch-diff
|
||||
(th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id profile-id
|
||||
:branch-id (:id branch)
|
||||
:direction dir}))
|
||||
@ -300,11 +300,11 @@
|
||||
_ (update-file! profile-id file-id [{:type :add-page :id page-b :name "B"}])
|
||||
branch (create-branch! profile-id file-id "reorder")]
|
||||
(update-file! profile-id file-id [{:type :mov-page :id page-b :index 0}])
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id profile-id
|
||||
:branch-id (:id branch)
|
||||
:direction :main->branch})
|
||||
eager (eager-compare file-id (:branch-file-id branch) :main->branch)]
|
||||
:direction :source->branch})
|
||||
eager (eager-compare file-id (:branch-file-id branch) :source->branch)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (seq (:changes eager)))
|
||||
(t/is (= (:changes eager) (:changes (:result out))))))))
|
||||
|
||||
@ -161,7 +161,7 @@
|
||||
;; 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"
|
||||
(let [diff (:result (th/command! {::th/type :get-branch-diff
|
||||
(let [diff (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))]
|
||||
(t/is (some #(= shape-a (:id %)) (:changes diff)))))
|
||||
|
||||
@ -174,7 +174,7 @@
|
||||
"request-file-access" "request-file-access-yourpenpot"
|
||||
"request-file-access-yourpenpot-view" "request-team-access"
|
||||
"comment-mention" "comment-thread" "comment-notification"
|
||||
"review-request" "task-assigned" "tasks-moved"
|
||||
"review-request" "task-assigned" "tasks-merged"
|
||||
"task-done" "task-reopened"}
|
||||
(set (keys emails/templates)))))
|
||||
|
||||
|
||||
@ -165,32 +165,35 @@
|
||||
{::db/remove-deleted false})))))))
|
||||
|
||||
(defn- create-review!
|
||||
"An open review of a branch of `file`: the branch and pull request rows
|
||||
the review activity points at."
|
||||
"An open review of a branch of `file`: the branch file, the branch edge
|
||||
the review hangs from, and the review row its activity points at. The
|
||||
branch joins the family of its source, as `create-file-branch` does."
|
||||
[profile file]
|
||||
(let [branch (th/create-file* 2 {:profile-id (:id profile)
|
||||
(let [family (:family-id (th/db-get :file {:id (:id file)}))
|
||||
branch (th/create-file* 2 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
_ (th/db-update! :file {:is-branch true} {:id (:id branch)})
|
||||
_ (th/db-update! :file {:is-branch true
|
||||
:family-id family}
|
||||
{:id (:id branch)})
|
||||
br (th/db-insert! :file-branch
|
||||
{:id (uuid/next)
|
||||
:branch-file-id (:id branch)
|
||||
:source-file-id (:id file)
|
||||
:base-revn 0
|
||||
:base-source-revn 0
|
||||
:created-by (:id profile)
|
||||
:name "feature-checkout"})]
|
||||
(th/db-insert! :file-pull-request
|
||||
(th/db-insert! :file-branch-review
|
||||
{:id (uuid/next)
|
||||
:file-branch-id (:id br)
|
||||
:source-file-id (:id branch)
|
||||
:target-file-id (:id file)
|
||||
:family-id family
|
||||
:title "Checkout redesign"
|
||||
:created-by (:id profile)})))
|
||||
|
||||
(defn- insert-activity!
|
||||
[profile review revn entries created-at]
|
||||
(th/db-insert! :file-pull-request-activity
|
||||
(th/db-insert! :file-branch-review-activity
|
||||
{:id (uuid/next)
|
||||
:pull-request-id (:id review)
|
||||
:review-id (:id review)
|
||||
:profile-id (:id profile)
|
||||
:revn revn
|
||||
:entries (blob/encode entries)
|
||||
@ -227,8 +230,8 @@
|
||||
(t/is (pos? (:processed result)))
|
||||
|
||||
(let [rows (sort-by :created-at
|
||||
(th/db-query :file-pull-request-activity
|
||||
{:pull-request-id (:id review)}))]
|
||||
(th/db-query :file-branch-review-activity
|
||||
{:review-id (:id review)}))]
|
||||
(t/testing "the sitting folds into its last row and the open one stays"
|
||||
(t/is (= 2 (count rows)))
|
||||
(t/is (= [(:id row3) (:id row4)] (mapv :id rows))))
|
||||
|
||||
@ -140,7 +140,7 @@
|
||||
{:type :add-color
|
||||
:color {:id branch-color :name "Branch" :color "#ff0000" :opacity 1}})
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -169,7 +169,7 @@
|
||||
(t/testing "the merge base moved to main'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-revn row))))))))
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))))))
|
||||
|
||||
(defn- add-color* [profile file-id]
|
||||
(apply-change* profile file-id
|
||||
@ -186,7 +186,7 @@
|
||||
create (create-branch* profile (:id file) name)]
|
||||
(th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id create)})
|
||||
:branch-id (:id create)})
|
||||
[profile create]))
|
||||
|
||||
(t/deftest an-archived-branch-refuses-saves
|
||||
@ -204,7 +204,7 @@
|
||||
branch-file-id (:branch-file-id create)]
|
||||
(th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id create)
|
||||
:branch-id (:id create)
|
||||
:archived false})
|
||||
(let [out (add-color* profile branch-file-id)]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -214,9 +214,9 @@
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [[profile create] (archived-branch* "oplog-materialized")
|
||||
branch-file-id (:branch-file-id create)
|
||||
out (th/command! {::th/type :materialize-file-branch
|
||||
out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:error (add-color* profile branch-file-id)))))))
|
||||
|
||||
@ -272,7 +272,7 @@
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-id "#00ff00")}]})
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -298,7 +298,7 @@
|
||||
:page-id page-id
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills branch-file-id "#ffffff")}]})
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
@ -306,10 +306,10 @@
|
||||
(t/is (= shape-id (-> out :result :conflicts first :id)))))
|
||||
|
||||
(t/testing "taking main keeps the branch writeable"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions {shape-id :main}})]
|
||||
:resolutions {shape-id :source}})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
@ -321,22 +321,22 @@
|
||||
(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 `:main` and the branch's under `:branch` in both
|
||||
;; 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-branch-from-main` inverts it before
|
||||
;; (`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: `:main` brings main's value into the
|
||||
;; command boundary: `:source` brings main'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:
|
||||
;; 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-branch-from-main`
|
||||
;; 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 `:main` cases below could pass while
|
||||
;; 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
|
||||
;; exercised, and every case below fails if the mapping is inverted.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -400,14 +400,14 @@
|
||||
[:result :data :pages-index page-id :objects shape-id
|
||||
:fills 0 :fill-color]))
|
||||
update! (fn [{:keys [branch-id]} resolutions]
|
||||
(th/command! {::th/type :update-branch-from-main
|
||||
(th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions resolutions}))]
|
||||
|
||||
(t/testing "a whole-entity :main resolution applies main's value"
|
||||
(t/testing "a whole-entity :source resolution applies main's value"
|
||||
(let [fx (fixture 1 "res-doc-main")
|
||||
out (update! fx {(:shape-id fx) :main})]
|
||||
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)))))
|
||||
@ -419,16 +419,16 @@
|
||||
(t/is (= :updated (-> out :result :status)))
|
||||
(t/is (= branch-fill (fill-of fx)))))
|
||||
|
||||
(t/testing "a per-attribute :main resolution applies main's value to that attribute"
|
||||
(t/testing "a per-attribute :source resolution applies main's value to that attribute"
|
||||
(let [fx (fixture 3 "res-doc-attr")
|
||||
out (update! fx {(:shape-id fx) {:fills :main}})]
|
||||
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))))))))
|
||||
|
||||
;; 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
|
||||
;; the new base destroys it. `files_branch.clj::update-branch-from-main`
|
||||
;; 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
|
||||
;; 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.
|
||||
@ -485,7 +485,7 @@
|
||||
:operations [{:type :set :attr :fills :val (fills branch-fill)}]})
|
||||
(t/is (= branch-fill (read-fill)))
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -550,7 +550,7 @@
|
||||
:id shape-id
|
||||
:operations [{:type :set :attr :fills :val (fills main-fill)}]})
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions {shape-id :branch}})]
|
||||
@ -568,7 +568,7 @@
|
||||
;; `branch_merge.cljc::compute-changes` reports main'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-branch-from-main`) be widened or dropped
|
||||
;; (`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)]
|
||||
@ -626,9 +626,9 @@
|
||||
|
||||
(t/testing "the branch is behind main before the update"
|
||||
(t/is (pos? (- (:revn (th/db-get :file {:id main-id}))
|
||||
(:base-revn base-before)))))
|
||||
(:base-source-revn base-before)))))
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -640,7 +640,7 @@
|
||||
(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-revn base-after)))
|
||||
(t/is (= (:revn main-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"
|
||||
@ -706,7 +706,7 @@
|
||||
(t/is (= (:id profile2) (:created-by (first rows))))))))))
|
||||
|
||||
(t/deftest create-refuses-a-blank-branch-name
|
||||
;; `::update-file-branch` refuses a blank name; creation used to
|
||||
;; `::update-file-branch-info` refuses a blank name; creation used to
|
||||
;; accept one, leaving behind a branch the rename would reject.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -757,11 +757,11 @@
|
||||
(t/is (contains? (-> out :result :data :colors) color-id))))
|
||||
|
||||
(t/testing "materialize is what creates the payload row"
|
||||
(let [out (th/command! {::th/type :materialize-file-branch
|
||||
(let [out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :materialized (-> out :result :status))))
|
||||
(t/is (= :detached (-> out :result :status))))
|
||||
(t/is (some? (th/db-get :file-data {:file-id branch-file-id :type "main"})))))))
|
||||
|
||||
;;; --- Data versions across an upgrade
|
||||
@ -868,7 +868,7 @@
|
||||
|
||||
(with-redefs [fmg/available-migrations upgraded]
|
||||
(t/testing "the compare reports the rename as a clean change"
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -920,11 +920,11 @@
|
||||
:color {:id (uuid/random) :name "M" :path "Brand/M" :color "#333333" :opacity 1}})
|
||||
|
||||
(read-file profile branch-file-id)
|
||||
(t/is (= :updated (-> (th/command! {::th/type :update-branch-from-main
|
||||
(t/is (= :updated (-> (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id create)})
|
||||
:result :status)))
|
||||
(t/is (nil? (:error (th/command! {::th/type :get-branch-diff
|
||||
(t/is (nil? (:error (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id create)}))))
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
@ -965,7 +965,7 @@
|
||||
{:type :add-color
|
||||
:color {:id c2 :name "Two" :path "Brand / Two" :color "#222222" :opacity 1}})
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -980,8 +980,8 @@
|
||||
(select-keys (get colors c2) [:name :path]))))))))))
|
||||
|
||||
(t/deftest update-from-main-conflict-sides-name-the-documents
|
||||
;; `update-branch-from-main` reports its conflicts in document terms:
|
||||
;; `:main` carries main's value and `:branch` the branch's, whatever the
|
||||
;; `update-file-branch-from-source` reports its conflicts in document terms:
|
||||
;; `:source` carries main'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)]
|
||||
@ -1042,19 +1042,19 @@
|
||||
:color "#336699" :opacity 1}})
|
||||
|
||||
(t/testing "the conflict names the two documents"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
c (first (-> out :result :conflicts))]
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
(t/is (= shape-id (:id c)))
|
||||
(t/is (= main-fill (get-in c [:main :fills 0 :fill-color])))
|
||||
(t/is (= main-fill (get-in c [:source :fills 0 :fill-color])))
|
||||
(t/is (= branch-fill (get-in c [:branch :fills 0 :fill-color])))
|
||||
(t/is (= {:main (fills main-fill) :branch (fills branch-fill)}
|
||||
(t/is (= {:source (fills main-fill) :branch (fills branch-fill)}
|
||||
(get-in c [:changed-attrs :fills])))))
|
||||
|
||||
(t/testing "resolved to :branch, the branch keeps its own value"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions {shape-id :branch}})]
|
||||
@ -1226,7 +1226,7 @@
|
||||
|
||||
diff!
|
||||
(fn []
|
||||
(-> (th/command! {::th/type :get-branch-diff
|
||||
(-> (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
:result
|
||||
@ -1254,7 +1254,7 @@
|
||||
;; 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
|
||||
;; records that map as applied, so a later comparison rebuilds the
|
||||
;; branch->main pairs from the record instead of the heuristic.
|
||||
;; branch->source pairs from the record instead of the heuristic.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -1301,7 +1301,7 @@
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "C1"
|
||||
:color "#112233" :opacity 1}}))))
|
||||
(t/is (= :updated (-> (th/command! {::th/type :update-branch-from-main
|
||||
(t/is (= :updated (-> (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
:result :status)))
|
||||
@ -1325,7 +1325,7 @@
|
||||
|
||||
diff!
|
||||
(fn []
|
||||
(-> (th/command! {::th/type :get-branch-diff
|
||||
(-> (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
:result
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC Sucursal en España SL
|
||||
|
||||
(ns backend-tests.rpc-file-pull-request-test
|
||||
(ns backend-tests.rpc-file-branch-review-test
|
||||
(:require
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.files.branch-merge :as bm]
|
||||
@ -56,15 +56,15 @@
|
||||
:file-id (:id file)
|
||||
:name name})))
|
||||
|
||||
(defn- create-pr*
|
||||
(defn- create-review*
|
||||
[profile branch-id params]
|
||||
(th/command! (merge {::th/type :create-pull-request
|
||||
(th/command! (merge {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:title "review me"}
|
||||
params)))
|
||||
|
||||
(t/deftest create-and-list-pull-requests
|
||||
(t/deftest create-and-list-branch-reviews
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
@ -78,14 +78,14 @@
|
||||
|
||||
(let [branch (create-branch* author file "feature")
|
||||
branch-file-id (:branch-file-id branch)
|
||||
pr-id (volatile! nil)]
|
||||
review-id (volatile! nil)]
|
||||
|
||||
(add-color* author branch-file-id "Brand")
|
||||
|
||||
(t/testing "create pull request with a reviewer"
|
||||
(let [out (create-pr* author (:id branch)
|
||||
{:description "please check the brand color"
|
||||
:reviewers [(:id reviewer)]})]
|
||||
(t/testing "create branch review with a reviewer"
|
||||
(let [out (create-review* author (:id branch)
|
||||
{:description "please check the brand color"
|
||||
:reviewers [(:id reviewer)]})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
(t/is (uuid? (:id result)))
|
||||
@ -93,11 +93,11 @@
|
||||
(t/is (= (:id file) (:target-file-id result)))
|
||||
(t/is (= "open" (:status result)))
|
||||
(t/is (= [(:id reviewer)] (:reviewers result)))
|
||||
(vreset! pr-id (:id result)))))
|
||||
(vreset! review-id (:id result)))))
|
||||
|
||||
(t/testing "review snapshot is pinned on the branch file"
|
||||
(let [rows (->> (th/db-query :file-change {:file-id branch-file-id})
|
||||
(filter #(some-> (:label %) (str/starts-with? "pr-review/"))))]
|
||||
(filter #(some-> (:label %) (str/starts-with? "branch-review/"))))]
|
||||
(t/is (= 1 (count rows)))
|
||||
(t/is (every? (fn [{:keys [deleted-at]}]
|
||||
(and (some? deleted-at)
|
||||
@ -105,17 +105,17 @@
|
||||
rows))))
|
||||
|
||||
(t/testing "list from the target file"
|
||||
(let [out (th/command! {::th/type :get-file-pull-requests
|
||||
(let [out (th/command! {::th/type :get-file-branch-reviews
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [[row :as result] (:result out)]
|
||||
(t/is (= 1 (count result)))
|
||||
(t/is (= @pr-id (:id row)))
|
||||
(t/is (= @review-id (:id row)))
|
||||
(t/is (= "review me" (:title row)))
|
||||
(t/is (= "feature" (:branch-name row)))
|
||||
(t/is (= (:name file) (:target-name row)))
|
||||
(t/is (= "pending" (:review-state row)))
|
||||
(t/is (= "pending" (:overall-verdict row)))
|
||||
(t/is (false? (:outdated row)))
|
||||
;; the branch carries one change (the added color)
|
||||
(t/is (= 1 (:ahead row)))
|
||||
@ -123,35 +123,35 @@
|
||||
(t/is (= 0 (:conflicts row)))
|
||||
(t/is (= 1 (count (:reviews row))))
|
||||
(t/is (= (:id reviewer) (-> row :reviews first :profile-id)))
|
||||
(t/is (= "pending" (-> row :reviews first :state))))))
|
||||
(t/is (nil? (-> row :reviews first :verdict))))))
|
||||
|
||||
(t/testing "list resolves a branch file id to its target"
|
||||
(let [out (th/command! {::th/type :get-file-pull-requests
|
||||
(let [out (th/command! {::th/type :get-file-branch-reviews
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id branch-file-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= 1 (count (:result out))))))
|
||||
|
||||
(t/testing "get single pull request"
|
||||
(let [out (th/command! {::th/type :get-pull-request
|
||||
(t/testing "get single branch review"
|
||||
(let [out (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:id @pr-id})]
|
||||
:id @review-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "review me" (-> out :result :title)))))))))
|
||||
|
||||
(t/deftest one-open-pull-request-per-branch
|
||||
(t/deftest one-open-review-per-branch
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})
|
||||
branch (create-branch* author file "feature")]
|
||||
|
||||
(t/is (nil? (:error (create-pr* author (:id branch) {}))))
|
||||
(t/is (nil? (:error (create-review* author (:id branch) {}))))
|
||||
|
||||
(let [out (create-pr* author (:id branch) {:title "second"})
|
||||
(let [out (create-review* author (:id branch) {:title "second"})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :pull-request-already-exists (-> error ex-data :code)))))))
|
||||
(t/is (= :branch-review-already-exists (-> error ex-data :code)))))))
|
||||
|
||||
(t/deftest create-validates-reviewers-and-permissions
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
@ -167,21 +167,21 @@
|
||||
:role :viewer})
|
||||
|
||||
(t/testing "a reviewer outside the team is refused"
|
||||
(let [out (create-pr* author (:id branch)
|
||||
{:reviewers [(:id stranger)]})
|
||||
(let [out (create-review* author (:id branch)
|
||||
{:reviewers [(:id stranger)]})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :reviewer-not-team-member (-> error ex-data :code)))))
|
||||
|
||||
(t/testing "the author is silently dropped from the reviewer list"
|
||||
(let [out (create-pr* author (:id branch)
|
||||
{:reviewers [(:id author) (:id viewer)]})]
|
||||
(let [out (create-review* author (:id branch)
|
||||
{:reviewers [(:id author) (:id viewer)]})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= [(:id viewer)] (-> out :result :reviewers)))))
|
||||
|
||||
(t/testing "a viewer of the branch file cannot create a pull request"
|
||||
(t/testing "a viewer of the branch file cannot create a branch review"
|
||||
(let [branch2 (create-branch* author file "feature-2")
|
||||
out (create-pr* viewer (:id branch2) {})]
|
||||
out (create-review* viewer (:id branch2) {})]
|
||||
(t/is (some? (:error out))))))))
|
||||
|
||||
(t/deftest bundle-serves-the-pinned-snapshot
|
||||
@ -198,15 +198,15 @@
|
||||
{:type :add-color
|
||||
:color {:id color-1 :name "One" :color "#111111" :opacity 1}})
|
||||
|
||||
(let [pr (:result (create-pr* author (:id branch) {}))]
|
||||
(let [pr (:result (create-review* author (:id branch) {}))]
|
||||
|
||||
;; the branch keeps moving AFTER the pull request was created
|
||||
;; the branch keeps moving AFTER the branch review was created
|
||||
(apply-change* author bfid
|
||||
{:type :add-color
|
||||
:color {:id color-2 :name "Two" :color "#222222" :opacity 1}})
|
||||
|
||||
(t/testing "the sandbox shows the reviewed state, not the live branch"
|
||||
(let [out (th/command! {::th/type :get-pull-request-bundle
|
||||
(let [out (th/command! {::th/type :get-branch-review-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
result (:result out)
|
||||
@ -217,32 +217,32 @@
|
||||
;; read-only by construction, whatever the caller's role is
|
||||
(t/is (false? (-> result :permissions :can-edit)))))
|
||||
|
||||
(t/testing "the pull request reports the branch moved on"
|
||||
(let [out (th/command! {::th/type :get-pull-request
|
||||
(t/testing "the branch review reports the branch moved on"
|
||||
(let [out (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (true? (-> out :result :outdated)))))
|
||||
|
||||
(t/testing "publishing the branch state refreshes the sandbox"
|
||||
(let [out (th/command! {::th/type :update-pull-request-snapshot
|
||||
(let [out (th/command! {::th/type :update-branch-review-revision
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (true? (-> out :result :updated))))
|
||||
|
||||
(let [out (th/command! {::th/type :get-pull-request-bundle
|
||||
(let [out (th/command! {::th/type :get-branch-review-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
colors (-> out :result :data :colors)]
|
||||
(t/is (contains? colors color-2)))
|
||||
|
||||
(let [out (th/command! {::th/type :get-pull-request
|
||||
(let [out (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (false? (-> out :result :outdated)))))
|
||||
|
||||
(t/testing "publishing again with no new changes is a no-op"
|
||||
(let [out (th/command! {::th/type :update-pull-request-snapshot
|
||||
(let [out (th/command! {::th/type :update-branch-review-revision
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -262,9 +262,9 @@
|
||||
{:type :add-color
|
||||
:color {:id color-1 :name "One" :color "#111111" :opacity 1}})
|
||||
|
||||
(let [pr (:result (create-pr* author (:id branch) {}))]
|
||||
(let [pr (:result (create-review* author (:id branch) {}))]
|
||||
|
||||
;; the branch keeps moving AFTER the pull request was created
|
||||
;; the branch keeps moving AFTER the branch review was created
|
||||
(apply-change* author bfid
|
||||
{:type :add-color
|
||||
:color {:id color-2 :name "Two" :color "#222222" :opacity 1}})
|
||||
@ -276,32 +276,32 @@
|
||||
(let [out (th/command! {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id bfid
|
||||
:pr-id (:id pr)})
|
||||
:review-id (:id pr)})
|
||||
result (:result out)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= (:review-revn pr) (-> result :file :revn)))
|
||||
(t/is (= (:pinned-revn pr) (-> result :file :revn)))
|
||||
(t/is (false? (-> result :permissions :can-edit)))))
|
||||
|
||||
(t/testing "the viewer bundle without pr-id keeps the live state"
|
||||
(t/testing "the viewer bundle without review-id keeps the live state"
|
||||
(let [out (th/command! {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id bfid})
|
||||
bf (th/db-get :file {:id bfid})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= (:revn bf) (-> out :result :file :revn)))
|
||||
(t/is (< (:review-revn pr) (:revn bf)))))
|
||||
(t/is (< (:pinned-revn pr) (:revn bf)))))
|
||||
|
||||
(t/testing "the viewer bundle refuses a closed pull request"
|
||||
(th/command! {::th/type :close-pull-request
|
||||
(t/testing "the viewer bundle refuses a closed branch review"
|
||||
(th/command! {::th/type :close-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
(let [out (th/command! {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id bfid
|
||||
:pr-id (:id pr)})
|
||||
:review-id (:id pr)})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :pull-request-not-open (-> error ex-data :code)))))))))
|
||||
(t/is (= :branch-review-not-open (-> error ex-data :code)))))))))
|
||||
|
||||
(t/deftest review-lifecycle
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
@ -321,58 +321,58 @@
|
||||
(let [branch (create-branch* author file "feature")
|
||||
bfid (:branch-file-id branch)
|
||||
_ (add-color* author bfid "Brand")
|
||||
pr (:result (create-pr* author (:id branch)
|
||||
{:reviewers [(:id reviewer)]}))]
|
||||
pr (:result (create-review* author (:id branch)
|
||||
{:reviewers [(:id reviewer)]}))]
|
||||
|
||||
(t/testing "a non-assigned member cannot submit a review"
|
||||
(let [out (th/command! {::th/type :submit-pull-request-review
|
||||
(let [out (th/command! {::th/type :submit-branch-review-verdict
|
||||
::rpc/profile-id (:id other)
|
||||
:id (:id pr)
|
||||
:state "approved"})
|
||||
:verdict "approved"})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :not-a-reviewer (-> error ex-data :code)))))
|
||||
|
||||
(t/testing "an approval flips the aggregate review state"
|
||||
(let [out (th/command! {::th/type :submit-pull-request-review
|
||||
(let [out (th/command! {::th/type :submit-branch-review-verdict
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:id (:id pr)
|
||||
:state "approved"
|
||||
:verdict "approved"
|
||||
:comment "ship it"})]
|
||||
(t/is (nil? (:error out))))
|
||||
(let [out (th/command! {::th/type :get-pull-request
|
||||
(let [out (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
row (:result out)]
|
||||
(t/is (= "approved" (:review-state row)))
|
||||
(t/is (= "approved" (:overall-verdict row)))
|
||||
(t/is (false? (-> row :reviews first :stale)))))
|
||||
|
||||
(t/testing "publishing new changes makes the verdict stale"
|
||||
(add-color* author bfid "Another")
|
||||
(let [out (th/command! {::th/type :update-pull-request-snapshot
|
||||
(let [out (th/command! {::th/type :update-branch-review-revision
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (nil? (:error out))))
|
||||
(let [row (:result (th/command! {::th/type :get-pull-request
|
||||
(let [row (:result (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)}))]
|
||||
;; the verdict is kept for the history but no longer current
|
||||
(t/is (= "in-review" (:review-state row)))
|
||||
(t/is (= "in-review" (:overall-verdict row)))
|
||||
(t/is (true? (-> row :reviews first :stale)))))
|
||||
|
||||
(t/testing "requesting changes beats an approval"
|
||||
(let [out (th/command! {::th/type :submit-pull-request-review
|
||||
(let [out (th/command! {::th/type :submit-branch-review-verdict
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:id (:id pr)
|
||||
:state "changes-requested"
|
||||
:verdict "changes-requested"
|
||||
:comment "the second color is off-brand"})]
|
||||
(t/is (nil? (:error out))))
|
||||
(let [row (:result (th/command! {::th/type :get-pull-request
|
||||
(let [row (:result (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)}))]
|
||||
(t/is (= "changes-requested" (:review-state row)))))))))
|
||||
(t/is (= "changes-requested" (:overall-verdict row)))))))))
|
||||
|
||||
(t/deftest update-pull-request-metadata-and-reviewers
|
||||
(t/deftest update-branch-review-metadata-and-reviewers
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer-1 (th/create-profile* 2 {:is-active true})
|
||||
@ -387,25 +387,25 @@
|
||||
:role role}))
|
||||
|
||||
(let [branch (create-branch* author file "feature")
|
||||
pr (:result (create-pr* author (:id branch)
|
||||
{:reviewers [(:id reviewer-1)]}))]
|
||||
pr (:result (create-review* author (:id branch)
|
||||
{:reviewers [(:id reviewer-1)]}))]
|
||||
|
||||
(t/testing "a plain editor (not author, not admin) cannot manage it"
|
||||
(let [out (th/command! {::th/type :update-pull-request
|
||||
(let [out (th/command! {::th/type :update-branch-review-info
|
||||
::rpc/profile-id (:id editor)
|
||||
:id (:id pr)
|
||||
:title "hijacked"})]
|
||||
(t/is (some? (:error out)))))
|
||||
|
||||
(t/testing "the author can replace title, description and reviewers"
|
||||
(let [out (th/command! {::th/type :update-pull-request
|
||||
(let [out (th/command! {::th/type :update-branch-review-info
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)
|
||||
:title "better title"
|
||||
:description "more context"
|
||||
:reviewers [(:id reviewer-2)]})]
|
||||
(t/is (nil? (:error out))))
|
||||
(let [row (:result (th/command! {::th/type :get-pull-request
|
||||
(let [row (:result (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)}))]
|
||||
(t/is (= "better title" (:title row)))
|
||||
@ -413,15 +413,15 @@
|
||||
(t/is (= [(:id reviewer-2)] (mapv :profile-id (:reviews row))))))
|
||||
|
||||
(t/testing "a removed reviewer can no longer submit"
|
||||
(let [out (th/command! {::th/type :submit-pull-request-review
|
||||
(let [out (th/command! {::th/type :submit-branch-review-verdict
|
||||
::rpc/profile-id (:id reviewer-1)
|
||||
:id (:id pr)
|
||||
:state "approved"})
|
||||
:verdict "approved"})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :not-a-reviewer (-> error ex-data :code)))))))))
|
||||
|
||||
(t/deftest close-and-reopen-pull-request
|
||||
(t/deftest close-and-reopen-branch-review
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
editor (th/create-profile* 2 {:is-active true})
|
||||
@ -438,32 +438,32 @@
|
||||
|
||||
(let [branch (create-branch* author file "feature")
|
||||
bfid (:branch-file-id branch)
|
||||
pr (:result (create-pr* author (:id branch) {}))]
|
||||
pr (:result (create-review* author (:id branch) {}))]
|
||||
|
||||
(t/testing "a plain editor cannot close someone else's pull request"
|
||||
(let [out (th/command! {::th/type :close-pull-request
|
||||
(t/testing "a plain editor cannot close someone else's branch review"
|
||||
(let [out (th/command! {::th/type :close-branch-review
|
||||
::rpc/profile-id (:id editor)
|
||||
:id (:id pr)})]
|
||||
(t/is (some? (:error out)))))
|
||||
|
||||
(t/testing "a team admin can close it"
|
||||
(let [out (th/command! {::th/type :close-pull-request
|
||||
(let [out (th/command! {::th/type :close-branch-review
|
||||
::rpc/profile-id (:id admin)
|
||||
:id (:id pr)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "closed" (-> out :result :status)))))
|
||||
|
||||
(t/testing "the sandbox stops resolving once closed"
|
||||
(let [out (th/command! {::th/type :get-pull-request-bundle
|
||||
(let [out (th/command! {::th/type :get-branch-review-bundle
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :pull-request-not-open (-> error ex-data :code)))))
|
||||
(t/is (= :branch-review-not-open (-> error ex-data :code)))))
|
||||
|
||||
(t/testing "the review snapshot pin is released on close"
|
||||
(let [rows (->> (th/db-query :file-change {:file-id bfid})
|
||||
(filter #(some-> (:label %) (str/starts-with? "pr-review/"))))]
|
||||
(filter #(some-> (:label %) (str/starts-with? "branch-review/"))))]
|
||||
(t/is (seq rows))
|
||||
(t/is (every? (fn [{:keys [deleted-at]}]
|
||||
(and (some? deleted-at)
|
||||
@ -472,29 +472,29 @@
|
||||
|
||||
(t/testing "the author can reopen it, re-pinned at the current head"
|
||||
(add-color* author bfid "Late")
|
||||
(let [out (th/command! {::th/type :reopen-pull-request
|
||||
(let [out (th/command! {::th/type :reopen-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
bf (th/db-get :file {:id bfid})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "open" (-> out :result :status)))
|
||||
(t/is (= (:revn bf) (-> out :result :review-revn)))))))))
|
||||
(t/is (= (:revn bf) (-> out :result :pinned-revn)))))))))
|
||||
|
||||
(t/deftest branch-lifecycle-closes-pull-requests
|
||||
(t/deftest branch-lifecycle-closes-reviews
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})]
|
||||
|
||||
(t/testing "merging the branch marks the pull request merged"
|
||||
(t/testing "merging the branch marks the branch review merged"
|
||||
(let [branch (create-branch* author file "merge-me")
|
||||
_ (add-color* author (:branch-file-id branch) "Brand")
|
||||
pr (:result (create-pr* author (:id branch) {}))
|
||||
pr (:result (create-review* author (:id branch) {}))
|
||||
out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [[row] (th/db-query :file-pull-request {:id (:id pr)})]
|
||||
(let [[row] (th/db-query :file-branch-review {:id (:id pr)})]
|
||||
(t/is (= "merged" (:status row)))
|
||||
(t/is (some? (:closed-at row)))
|
||||
;; the row survives as history even though the branch is gone
|
||||
@ -504,27 +504,27 @@
|
||||
(let [merges (:result (th/command! {::th/type :get-file-branch-merges
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))]
|
||||
(t/is (= [(:id pr)] (mapv :pull-request-id merges)))
|
||||
(t/is (= [(:title pr)] (mapv :pull-request-title merges))))))
|
||||
(t/is (= [(:id pr)] (mapv :review-id merges)))
|
||||
(t/is (= [(:title pr)] (mapv :review-title merges))))))
|
||||
|
||||
(t/testing "deleting the branch closes the pull request"
|
||||
(t/testing "deleting the branch closes the branch review"
|
||||
(let [branch (create-branch* author file "delete-me")
|
||||
pr (:result (create-pr* author (:id branch) {}))
|
||||
pr (:result (create-review* author (:id branch) {}))
|
||||
out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id branch)})]
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [[row] (th/db-query :file-pull-request {:id (:id pr)})]
|
||||
(let [[row] (th/db-query :file-branch-review {:id (:id pr)})]
|
||||
(t/is (= "closed" (:status row))))))
|
||||
|
||||
(t/testing "archiving the branch closes the pull request"
|
||||
(t/testing "archiving the branch closes the branch review"
|
||||
(let [branch (create-branch* author file "archive-me")
|
||||
pr (:result (create-pr* author (:id branch) {}))
|
||||
pr (:result (create-review* author (:id branch) {}))
|
||||
out (th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id branch)})]
|
||||
:branch-id (:id branch)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [[row] (th/db-query :file-pull-request {:id (:id pr)})]
|
||||
(let [[row] (th/db-query :file-branch-review {:id (:id pr)})]
|
||||
(t/is (= "closed" (:status row)))))))))
|
||||
|
||||
(t/deftest create-serializes-against-a-concurrent-merge
|
||||
@ -553,19 +553,19 @@
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id branch-id})))
|
||||
(orig-lock conn id))]
|
||||
(let [out (th/command! {::th/type :create-pull-request
|
||||
(let [out (th/command! {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id branch-id
|
||||
:title "review me"})]
|
||||
(t/is (= :merged (-> @merged :result :status)))
|
||||
(t/is (= :branch-not-found (-> out :error ex-data :code)))
|
||||
(t/is (= [] (th/db-query :file-pull-request {:file-branch-id branch-id})))))))))
|
||||
(t/is (= [] (th/db-query :file-branch-review {:file-branch-id branch-id})))))))))
|
||||
|
||||
(t/deftest reopen-serializes-against-a-concurrent-merge
|
||||
;; the reopen must re-read the branch under the advisory lock too: the
|
||||
;; merge that wins the race closes the branch under the closed pull
|
||||
;; request's feet, so a reopen arriving afterwards must refuse instead
|
||||
;; of reviving a review over a branch that is already merged and gone.
|
||||
;; merge that wins the race closes the branch under the closed review's
|
||||
;; feet, so a reopen arriving afterwards must refuse instead of
|
||||
;; reviving a review over a branch that is already merged and gone.
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
@ -574,8 +574,8 @@
|
||||
branch-id (:id branch)
|
||||
branch-file-id (:branch-file-id branch)]
|
||||
(add-color* author branch-file-id "Brand")
|
||||
(let [pr (:result (create-pr* author branch-id {}))]
|
||||
(t/is (nil? (:error (th/command! {::th/type :close-pull-request
|
||||
(let [pr (:result (create-review* author branch-id {}))]
|
||||
(t/is (nil? (:error (th/command! {::th/type :close-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)}))))
|
||||
(let [orig-lock db/xact-lock!
|
||||
@ -591,34 +591,34 @@
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id branch-id})))
|
||||
(orig-lock conn id))]
|
||||
(let [out (th/command! {::th/type :reopen-pull-request
|
||||
(let [out (th/command! {::th/type :reopen-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})]
|
||||
(t/is (= :merged (-> @merged :result :status)))
|
||||
(t/is (= :branch-not-open (-> out :error ex-data :code)))
|
||||
(t/is (= "closed" (:status (first (th/db-query :file-pull-request {:id (:id pr)}))))))))))))
|
||||
(t/is (= "closed" (:status (first (th/db-query :file-branch-review {:id (:id pr)}))))))))))))
|
||||
|
||||
(t/deftest closed-pull-requests-listing
|
||||
(t/deftest closed-branch-reviews-listing
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})
|
||||
branch (create-branch* author file "feature")
|
||||
pr (:result (create-pr* author (:id branch) {}))]
|
||||
pr (:result (create-review* author (:id branch) {}))]
|
||||
|
||||
(th/command! {::th/type :close-pull-request
|
||||
(th/command! {::th/type :close-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id pr)})
|
||||
|
||||
(t/testing "closed pull requests are hidden by default"
|
||||
(let [out (th/command! {::th/type :get-file-pull-requests
|
||||
(t/testing "closed branch reviews are hidden by default"
|
||||
(let [out (th/command! {::th/type :get-file-branch-reviews
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= 0 (count (:result out))))))
|
||||
|
||||
(t/testing "and visible with include-closed"
|
||||
(let [out (th/command! {::th/type :get-file-pull-requests
|
||||
(let [out (th/command! {::th/type :get-file-branch-reviews
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)
|
||||
:include-closed true})]
|
||||
@ -626,7 +626,7 @@
|
||||
(t/is (= 1 (count (:result out))))
|
||||
(t/is (= "closed" (-> out :result first :status))))))))
|
||||
|
||||
(t/deftest pull-request-listing-shares-the-branch-summary-cache
|
||||
(t/deftest review-listing-shares-the-branch-summary-cache
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
@ -635,7 +635,7 @@
|
||||
branches (fn [] (:result (th/command! {::th/type :get-file-branches
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)})))
|
||||
prs (fn [] (:result (th/command! {::th/type :get-file-pull-requests
|
||||
prs (fn [] (:result (th/command! {::th/type :get-file-branch-reviews
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)})))
|
||||
summary (fn [row] (select-keys row [:ahead :behind :conflicts]))]
|
||||
@ -643,7 +643,7 @@
|
||||
;; diverge both sides so the comparison is real work
|
||||
(add-color* author (:branch-file-id branch) "Brand")
|
||||
(add-color* author (:id file) "Accent")
|
||||
(t/is (nil? (:error (create-pr* author (:id branch) {}))))
|
||||
(t/is (nil? (:error (create-review* author (:id branch) {}))))
|
||||
|
||||
(let [orig-merge bm/compute-merge
|
||||
calls (atom 0)]
|
||||
@ -660,7 +660,7 @@
|
||||
(t/is (pos? cold-calls))
|
||||
(t/is (= {:ahead 1 :behind 1 :conflicts 0} (summary cold-branch))))
|
||||
|
||||
(t/testing "the pull-request listing arrives warm and agrees"
|
||||
(t/testing "the review listing arrives warm and agrees"
|
||||
(t/is (zero? pr-calls))
|
||||
(t/is (= (summary cold-branch) (summary warm-pr))))
|
||||
|
||||
@ -668,18 +668,18 @@
|
||||
(t/is (zero? @calls))
|
||||
(t/is (= (summary warm-pr) (summary repeat-pr))))))))))
|
||||
|
||||
(t/deftest branching-flag-gates-pull-request-commands
|
||||
(t/deftest branching-flag-gates-review-commands
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id author)
|
||||
:project-id (:default-project-id author)})
|
||||
branch (with-redefs [cf/flags (pr-flags)]
|
||||
(create-branch* author file "feature"))
|
||||
out (create-pr* author (:id branch) {})
|
||||
out (create-review* author (:id branch) {})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :branching-disabled (-> error ex-data :code)))))
|
||||
|
||||
(t/deftest pull-request-commands-notify-only-after-the-commit
|
||||
(t/deftest review-commands-notify-only-after-the-commit
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
@ -696,68 +696,68 @@
|
||||
;; and `:expected` is the state that must already be visible
|
||||
;; there (the transaction has committed)
|
||||
cases
|
||||
[{:label "create-pull-request"
|
||||
:type :create-pull-request
|
||||
[{:label "create-branch-review"
|
||||
:type :create-branch-review
|
||||
:actor :author
|
||||
:params (fn [_] {:branch-id (:id branch)
|
||||
:title "review me"
|
||||
:reviewers [(:id reviewer)]})
|
||||
:message-type :pull-request-created
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request {:id id})
|
||||
:message-type :branch-review-created
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-review {:id id})
|
||||
[:status]))
|
||||
:expected (constantly {:status "open"})}
|
||||
|
||||
{:label "update-pull-request"
|
||||
:type :update-pull-request
|
||||
{:label "update-branch-review-info"
|
||||
:type :update-branch-review-info
|
||||
:actor :author
|
||||
:params (fn [id] {:id id :title "renamed"})
|
||||
:message-type :pull-request-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request {:id id})
|
||||
:message-type :branch-review-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-review {:id id})
|
||||
[:title]))
|
||||
:expected (constantly {:title "renamed"})}
|
||||
|
||||
{:label "update-pull-request-snapshot"
|
||||
:type :update-pull-request-snapshot
|
||||
{:label "update-branch-review-revision"
|
||||
:type :update-branch-review-revision
|
||||
:actor :author
|
||||
;; the sandbox only republishes when the branch moved
|
||||
:before (fn [] (add-color* author bfid "Extra"))
|
||||
:params (fn [id] {:id id})
|
||||
:message-type :pull-request-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request {:id id})
|
||||
[:review-revn]))
|
||||
:expected (fn [_] {:review-revn (:revn (th/db-get :file {:id bfid}))})}
|
||||
:message-type :branch-review-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-review {:id id})
|
||||
[:pinned-revn]))
|
||||
:expected (fn [_] {:pinned-revn (:revn (th/db-get :file {:id bfid}))})}
|
||||
|
||||
{:label "submit-pull-request-review"
|
||||
:type :submit-pull-request-review
|
||||
{:label "submit-branch-review-verdict"
|
||||
:type :submit-branch-review-verdict
|
||||
:actor :reviewer
|
||||
:params (fn [id] {:id id :state "approved" :comment "ship it"})
|
||||
:message-type :pull-request-review-submitted
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request-review
|
||||
{:pull-request-id id
|
||||
:params (fn [id] {:id id :verdict "approved" :comment "ship it"})
|
||||
:message-type :branch-review-verdict-submitted
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-reviewer
|
||||
{:review-id id
|
||||
:profile-id (:id reviewer)})
|
||||
[:state :reviewed-revn]))
|
||||
:expected (fn [id] {:state "approved"
|
||||
:reviewed-revn (:review-revn (th/db-get :file-pull-request {:id id}))})}
|
||||
[:verdict :verdict-revn]))
|
||||
:expected (fn [id] {:verdict "approved"
|
||||
:verdict-revn (:pinned-revn (th/db-get :file-branch-review {:id id}))})}
|
||||
|
||||
{:label "close-pull-request"
|
||||
:type :close-pull-request
|
||||
{:label "close-branch-review"
|
||||
:type :close-branch-review
|
||||
:actor :author
|
||||
:params (fn [id] {:id id})
|
||||
:message-type :pull-request-closed
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request {:id id})
|
||||
:message-type :branch-review-closed
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-review {:id id})
|
||||
[:status]))
|
||||
:expected (constantly {:status "closed"})}
|
||||
|
||||
{:label "reopen-pull-request"
|
||||
:type :reopen-pull-request
|
||||
{:label "reopen-branch-review"
|
||||
:type :reopen-branch-review
|
||||
:actor :author
|
||||
:params (fn [id] {:id id})
|
||||
:message-type :pull-request-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-pull-request {:id id})
|
||||
:message-type :branch-review-updated
|
||||
:view (fn [id] (select-keys (th/db-get :file-branch-review {:id id})
|
||||
[:status]))
|
||||
:expected (constantly {:status "open"})}]]
|
||||
(loop [cases cases
|
||||
pr-id nil]
|
||||
review-id nil]
|
||||
(when-some [{:keys [label type actor before params message-type view expected]}
|
||||
(first cases)]
|
||||
(let [seen (atom [])
|
||||
@ -765,19 +765,19 @@
|
||||
out (with-redefs [mbus/pub!
|
||||
(fn [_ & {:keys [message]}]
|
||||
(swap! seen conj {:message message
|
||||
:row (view (:pull-request-id message))}))]
|
||||
:row (view (:review-id message))}))]
|
||||
(th/command! (merge {::th/type type
|
||||
::rpc/profile-id (actors actor)}
|
||||
(params pr-id))))]
|
||||
(params review-id))))]
|
||||
(t/is (nil? (:error out)) (str label " runs"))
|
||||
(let [{:keys [message row]} (first @seen)]
|
||||
(t/is (= 1 (count @seen)) (str label " publishes once"))
|
||||
(t/is (= message-type (:type message)) (str label " message type"))
|
||||
(t/is (= (expected (:pull-request-id message)) row)
|
||||
(t/is (= (expected (:review-id message)) row)
|
||||
(str label " publishes only after the commit")))
|
||||
(recur (rest cases) (or pr-id (-> out :result :id))))))))))
|
||||
(recur (rest cases) (or review-id (-> out :result :id))))))))))
|
||||
|
||||
(t/deftest rolled-back-pull-request-commands-notify-nothing
|
||||
(t/deftest rolled-back-review-commands-notify-nothing
|
||||
(with-redefs [cf/flags (pr-flags)]
|
||||
(let [author (th/create-profile* 1 {:is-active true})
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
@ -789,14 +789,14 @@
|
||||
(let [branch (create-branch* author file "rollback")
|
||||
seen (atom [])]
|
||||
;; the reviewer emails are queued inside the transaction: make
|
||||
;; that queueing fail after the pull request row is written
|
||||
;; that queueing fail after the branch review row is written
|
||||
(with-redefs [mbus/pub! (fn [_ & {:keys [message]}]
|
||||
(swap! seen conj message))
|
||||
eml/send-template (fn [_ _] (throw (IllegalStateException. "boom")))]
|
||||
(let [out (create-pr* author (:id branch) {:reviewers [(:id reviewer)]})]
|
||||
(let [out (create-review* author (:id branch) {:reviewers [(:id reviewer)]})]
|
||||
(t/is (some? (:error out)))))
|
||||
(t/is (empty? @seen))
|
||||
(t/is (empty? (th/db-query :file-pull-request
|
||||
(t/is (empty? (th/db-query :file-branch-review
|
||||
{:file-branch-id (:id branch)})))))))
|
||||
|
||||
(t/deftest activity-folds-every-row-not-the-newest-window
|
||||
@ -808,12 +808,12 @@
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id file)})
|
||||
:result :data :pages first)
|
||||
branch (create-branch* author file "feature")
|
||||
pr-id (-> (create-pr* author (:id branch) {}) :result :id)
|
||||
paid-id (uuid/random)
|
||||
board-id (uuid/random)
|
||||
promo-id (uuid/random)
|
||||
start (ct/now)
|
||||
branch (create-branch* author file "feature")
|
||||
review-id (-> (create-review* author (:id branch) {}) :result :id)
|
||||
paid-id (uuid/random)
|
||||
board-id (uuid/random)
|
||||
promo-id (uuid/random)
|
||||
start (ct/now)
|
||||
|
||||
paid {:id paid-id :page-id page-id :name "Pay" :type :rect
|
||||
:frame-id board-id :frame-name "Checkout" :kind :added}
|
||||
@ -827,7 +827,7 @@
|
||||
|
||||
row
|
||||
(fn [revn at entries]
|
||||
[(uuid/next) pr-id (:id author) revn
|
||||
[(uuid/next) review-id (:id author) revn
|
||||
(blob/encode entries)
|
||||
at])
|
||||
|
||||
@ -847,14 +847,14 @@
|
||||
(ct/plus start (ct/duration {:hours 2 :seconds 2000}))
|
||||
[changed (assoc promo :kind :deleted)])]))]
|
||||
|
||||
(db/insert-many! th/*pool* :file-pull-request-activity
|
||||
[:id :pull-request-id :profile-id :revn :entries :created-at]
|
||||
(db/insert-many! th/*pool* :file-branch-review-activity
|
||||
[:id :review-id :profile-id :revn :entries :created-at]
|
||||
rows
|
||||
{::db/return-keys false})
|
||||
|
||||
(let [out (th/command! {::th/type :get-pull-request-activity
|
||||
(let [out (th/command! {::th/type :get-branch-review-activity
|
||||
::rpc/profile-id (:id author)
|
||||
:id pr-id})
|
||||
:id review-id})
|
||||
result (:result out)
|
||||
entry (->> (:entries result)
|
||||
(some #(when (= paid-id (:id %)) %)))]
|
||||
@ -115,7 +115,7 @@
|
||||
(t/is (some #(= "system" (:created-by %)) rows))))
|
||||
|
||||
(t/testing "diff right after creation has no conflicts"
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id @branch-meta-id})
|
||||
stats (-> out :result :stats)
|
||||
@ -125,7 +125,7 @@
|
||||
;; base == main == 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? (:main-at meta)))
|
||||
(t/is (some? (:source-at meta)))
|
||||
(t/is (some? (:branch-at meta)))
|
||||
(t/is (some? (:base-at meta)))))
|
||||
|
||||
@ -289,17 +289,17 @@
|
||||
:changes [{:type :add-color :color color}]})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "compare in the :main->branch direction shows main's incoming change"
|
||||
(let [diff (:result (th/command! {::th/type :get-branch-diff
|
||||
(t/testing "compare in the :source->branch direction shows main's incoming change"
|
||||
(let [diff (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:direction :main->branch}))
|
||||
:direction :source->branch}))
|
||||
added (filterv #(= :added (:status %)) (:changes diff))]
|
||||
(t/is (= 1 (-> diff :stats :added)))
|
||||
(t/is (= color-id (-> added first :id)))))
|
||||
|
||||
(t/testing "update the branch from main"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -314,7 +314,7 @@
|
||||
;; merge base repositioned to the current state of main
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
mf (th/db-get :file {:id (:id file)})]
|
||||
(t/is (= (:revn mf) (:base-revn row))))))))
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))))))
|
||||
|
||||
(t/deftest merge-applies-page-add
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -531,9 +531,9 @@
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
(t/testing "rename"
|
||||
(let [out (th/command! {::th/type :update-file-branch
|
||||
(let [out (th/command! {::th/type :update-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id
|
||||
:branch-id branch-id
|
||||
:name "renamed"})]
|
||||
(t/is (nil? (:error out))))
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})]
|
||||
@ -542,7 +542,7 @@
|
||||
(t/testing "archive hides it from the default list"
|
||||
(let [out (th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "archived" (-> out :result :status))))
|
||||
(let [out (th/command! {::th/type :get-file-branches
|
||||
@ -558,7 +558,7 @@
|
||||
(t/testing "delete marks branch and branch file deleted"
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :deleted (-> out :result :status))))
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
@ -601,16 +601,16 @@
|
||||
(apply-change branch-file-id {:type :mod-color :color {:id cid :name "Brand" :color "#0000ff" :opacity 1}})
|
||||
|
||||
(t/testing "update without resolutions reports conflicts"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :conflicts (-> out :result :status)))))
|
||||
|
||||
(t/testing "resolving to main brings main's value into the branch"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions {cid :main}})]
|
||||
:resolutions {cid :source}})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
@ -651,10 +651,10 @@
|
||||
deleted (create! "deleted")]
|
||||
(th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id archived)})
|
||||
:branch-id (:id archived)})
|
||||
(th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id deleted)})
|
||||
:branch-id (:id deleted)})
|
||||
|
||||
(t/testing "archived branches count, deleted ones do not"
|
||||
(t/is (= {:count 2} (:result (count-of (:id profile) (:id file))))))
|
||||
@ -842,7 +842,7 @@
|
||||
(t/is (every? #(= (:id file) (:file-id %)) merges))
|
||||
(t/is (= [nil "Ships the new header"] (mapv :comment merges))
|
||||
"the comment is trimmed, and a blank one is no comment")
|
||||
(t/is (every? (comp nil? :pull-request-id) merges))))
|
||||
(t/is (every? (comp nil? :review-id) merges))))
|
||||
|
||||
(t/testing "a merged branch leaves the branch listing"
|
||||
(let [out (th/command! {::th/type :get-file-branches
|
||||
@ -894,12 +894,12 @@
|
||||
(t/is (some? (:error out))))
|
||||
|
||||
;; but profile2 CAN update the branch from main (edits the branch)
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile2)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))))))
|
||||
|
||||
(t/deftest merge-refuses-stale-expected-main-revn
|
||||
(t/deftest merge-refuses-stale-expected-source-revn
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -914,7 +914,7 @@
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:expected-main-revn 9999})
|
||||
:expected-source-revn 9999})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :file-modified (-> error ex-data :code)))))))
|
||||
@ -977,7 +977,7 @@
|
||||
:id (:id file)})]
|
||||
(t/is (= "#0000ff" (get-in out [:result :data :colors cid :color])))))))))
|
||||
|
||||
(t/deftest update-refuses-stale-expected-main-revn
|
||||
(t/deftest update-refuses-stale-expected-source-revn
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -996,10 +996,10 @@
|
||||
{:type :add-color :color {:id cid :name "M" :color "#00ff00" :opacity 1}})
|
||||
|
||||
(t/testing "a stale token is refused and the branch is unchanged"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:expected-main-revn 9999})
|
||||
:expected-source-revn 9999})
|
||||
error (:error out)]
|
||||
(t/is (some? error))
|
||||
(t/is (= :file-modified (-> error ex-data :code))))
|
||||
@ -1011,10 +1011,10 @@
|
||||
|
||||
(t/testing "the current token lets the update through"
|
||||
(let [mf (th/db-get :file {:id (:id file)})
|
||||
out (th/command! {::th/type :update-branch-from-main
|
||||
out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:expected-main-revn (:revn mf)})]
|
||||
:expected-source-revn (:revn mf)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
@ -1025,7 +1025,7 @@
|
||||
(t/deftest conflict-responses-carry-the-main-revn
|
||||
;; A `:conflicts` response is what a resolving client works from, so it
|
||||
;; names the revision of main its conflicts were computed against. The
|
||||
;; client sends that revision back as `expected-main-revn` with its
|
||||
;; client sends that revision back as `expected-source-revn` with its
|
||||
;; resolutions, and a main that moved meanwhile is refused.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -1056,12 +1056,12 @@
|
||||
|
||||
(t/testing "an update that stops on conflicts names main's revision"
|
||||
(let [revn (main-revn)
|
||||
out (th/command! {::th/type :update-branch-from-main
|
||||
out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
(t/is (= revn (-> out :result :main-revn)))))
|
||||
(t/is (= revn (-> out :result :source-revn)))))
|
||||
|
||||
(t/testing "a merge that stops on conflicts names main's revision"
|
||||
(let [revn (main-revn)
|
||||
@ -1070,14 +1070,14 @@
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :conflicts (-> out :result :status)))
|
||||
(t/is (= revn (-> out :result :main-revn)))
|
||||
(t/is (= revn (-> out :result :source-revn)))
|
||||
|
||||
(t/testing "and the merge accepts that revision back with resolutions"
|
||||
(let [retry (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:resolutions {cid :branch}
|
||||
:expected-main-revn (-> out :result :main-revn)})]
|
||||
:expected-source-revn (-> out :result :source-revn)})]
|
||||
(t/is (nil? (:error retry)))
|
||||
(t/is (= :merged (-> retry :result :status)))))))))))
|
||||
|
||||
@ -1107,7 +1107,7 @@
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id id :name nm :color "#00ff00" :opacity 1}}))
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -1140,6 +1140,166 @@
|
||||
(t/is (some? error))
|
||||
(t/is (= :cannot-branch-a-branch (-> error ex-data :code)))))))
|
||||
|
||||
;;; --- Stacked branches (`:branch-stacking`)
|
||||
|
||||
(defn- stacking-flags
|
||||
[]
|
||||
(conj cf/flags :branching :branch-stacking))
|
||||
|
||||
(defn- color-change
|
||||
[id]
|
||||
{:type :add-color
|
||||
:color {:id id :name (str "c-" id) :color "#112233" :opacity 1}})
|
||||
|
||||
(defn- colors-of
|
||||
[profile file-id]
|
||||
(-> (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id file-id})
|
||||
:result :data :colors keys set))
|
||||
|
||||
(t/deftest branch-of-a-branch-with-the-stacking-flag
|
||||
(with-redefs [cf/flags (stacking-flags)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
parent (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "parent"}))
|
||||
out (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:branch-file-id parent)
|
||||
:name "child"})
|
||||
child (:result out)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= (:branch-file-id parent)
|
||||
(:source-file-id (th/db-get :file-branch {:id (:id child)}))))
|
||||
(t/testing "the whole chain is one family"
|
||||
(let [family (:family-id (th/db-get :file {:id (:id file)}))]
|
||||
(t/is (= family (:family-id (th/db-get :file {:id (:branch-file-id parent)}))))
|
||||
(t/is (= family (:family-id (th/db-get :file {:id (:branch-file-id child)})))))))))
|
||||
|
||||
(t/deftest child-merges-into-its-parent-branch
|
||||
(with-redefs [cf/flags (stacking-flags)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
parent (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "parent"}))
|
||||
child (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:branch-file-id parent)
|
||||
:name "child"}))
|
||||
color-id (uuid/random)]
|
||||
(t/is (nil? (:error (apply-change* profile (:branch-file-id child) (color-change color-id)))))
|
||||
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id child)})]
|
||||
(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/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"})))
|
||||
(t/is (not (contains? (colors-of profile (:id file)) color-id))))
|
||||
|
||||
(t/testing "the merge is recorded on the parent"
|
||||
(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/is (nil? (:error (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id parent)}))))
|
||||
(t/is (contains? (colors-of profile (:id file)) color-id))))))
|
||||
|
||||
(t/deftest merging-a-parent-hands-its-open-child-to-the-target
|
||||
(with-redefs [cf/flags (stacking-flags)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)})
|
||||
parent (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "parent"}))
|
||||
parent-color (uuid/random)
|
||||
_ (apply-change* profile (:branch-file-id parent) (color-change parent-color))
|
||||
child (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:branch-file-id parent)
|
||||
:name "child"}))
|
||||
child-color (uuid/random)
|
||||
_ (apply-change* profile (:branch-file-id child) (color-change child-color))
|
||||
base-id (:base-snapshot-id (th/db-get :file-branch {:id (:id child)}))]
|
||||
|
||||
(t/is (nil? (:error (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id parent)}))))
|
||||
|
||||
(t/testing "the child now branches from main, 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)))
|
||||
(t/is (= 0 (:base-source-revn row)))
|
||||
(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"
|
||||
(let [colors (colors-of profile (:branch-file-id child))]
|
||||
(t/is (contains? colors parent-color))
|
||||
(t/is (contains? colors child-color)))
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id child)})]
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "the child merges into main"
|
||||
(t/is (nil? (:error (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id child)}))))
|
||||
(let [colors (colors-of profile (:id file))]
|
||||
(t/is (contains? colors parent-color))
|
||||
(t/is (contains? colors child-color)))))))
|
||||
|
||||
(defn- branch-chain*
|
||||
"A file, a branch of it and a branch of that branch."
|
||||
[]
|
||||
(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})
|
||||
create (fn [source-id name]
|
||||
(:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id source-id
|
||||
:name name})))
|
||||
child (create (:id file) "child")
|
||||
grand (create (:branch-file-id child) "grandchild")]
|
||||
{:proj-id proj-id :file file :branches [child grand]}))
|
||||
|
||||
(defn- branch-files-deleted?
|
||||
[branches]
|
||||
(every? #(some? (:deleted-at (th/db-get :file {:id (:branch-file-id %)}
|
||||
{::db/remove-deleted false})))
|
||||
branches))
|
||||
|
||||
(t/deftest deleting-a-project-reaches-a-grandchild
|
||||
(with-redefs [cf/flags (stacking-flags)]
|
||||
(let [{:keys [proj-id branches]} (branch-chain*)]
|
||||
(th/run-task! :delete-object {:object :project :id proj-id :deleted-at (ct/in-future {:days 7})})
|
||||
(t/is (branch-files-deleted? branches)))))
|
||||
|
||||
(t/deftest deleting-a-root-file-reaches-a-grandchild
|
||||
(with-redefs [cf/flags (stacking-flags)]
|
||||
(let [{:keys [file branches]} (branch-chain*)]
|
||||
(th/run-task! :delete-object {:object :file :id (:id file) :deleted-at (ct/in-future {:days 7})})
|
||||
(t/is (branch-files-deleted? branches)))))
|
||||
|
||||
(t/deftest deleting-source-cascades-to-branches
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
@ -1159,7 +1319,9 @@
|
||||
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})
|
||||
bf (th/db-get :file {:id branch-file-id} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at row)))
|
||||
;; the branch file is marked, and the edge of a branch no merge
|
||||
;; accepted is deleted with it
|
||||
(t/is (nil? row))
|
||||
(t/is (some? (:deleted-at bf)))))))
|
||||
|
||||
(t/deftest merge-copies-branch-media-into-main
|
||||
@ -1333,7 +1495,7 @@
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -1486,11 +1648,11 @@
|
||||
:id branch-file-id}))]
|
||||
|
||||
(t/testing "materialize persists the derived state and drops the branch"
|
||||
(let [out (th/command! {::th/type :materialize-file-branch
|
||||
(let [out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :materialized (-> out :result :status)))
|
||||
(t/is (= :detached (-> out :result :status)))
|
||||
(t/is (true? (-> out :result :changed))))
|
||||
|
||||
(let [row (th/db-get :file {:id branch-file-id})]
|
||||
@ -1531,11 +1693,11 @@
|
||||
(t/is (empty? errors))))
|
||||
|
||||
(t/testing "materializing again is a no-op"
|
||||
(let [out (th/command! {::th/type :materialize-file-branch
|
||||
(let [out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :materialized (-> out :result :status)))
|
||||
(t/is (= :detached (-> out :result :status)))
|
||||
(t/is (false? (-> out :result :changed)))))))))
|
||||
|
||||
(defn- with-pruning-checked
|
||||
@ -1608,7 +1770,7 @@
|
||||
(let [result (volatile! nil)
|
||||
pruned (with-pruning-checked
|
||||
(fn []
|
||||
(vreset! result (th/command! {::th/type :get-branch-diff
|
||||
(vreset! result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))))]
|
||||
(t/is (nil? (:error @result)))
|
||||
@ -1660,7 +1822,7 @@
|
||||
(let [result (volatile! nil)
|
||||
pruned (with-pruning-checked
|
||||
(fn []
|
||||
(vreset! result (th/command! {::th/type :get-branch-diff
|
||||
(vreset! result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))))]
|
||||
(t/is (nil? (:error @result)))
|
||||
@ -1687,7 +1849,7 @@
|
||||
(t/is (= :branching-shape-limit-exceeded (:code data)))
|
||||
(t/is (= 0 (:limit data)))
|
||||
(t/is (pos? (:actual data)))
|
||||
(t/is (str/includes? (:hint data) "materialise"))
|
||||
(t/is (str/includes? (:hint data) "detach"))
|
||||
(t/is (empty? (th/db-query :file-branch {:source-file-id (:id file)}))))))
|
||||
|
||||
(t/testing "the page gate refuses branch creation and names the limit"
|
||||
@ -1720,7 +1882,7 @@
|
||||
:features cfeat/supported-features
|
||||
:changes [{:type :add-page :id (uuid/random) :name "one"}]})]
|
||||
(with-redefs [cf/get (th/config-get-mock {:branching-max-oplog-changes 0})]
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
data (ex-data (:error out))]
|
||||
@ -1729,7 +1891,7 @@
|
||||
(t/is (= :branching-oplog-limit-exceeded (:code data)))
|
||||
(t/is (= 0 (:limit data)))
|
||||
(t/is (= 1 (:actual data)))
|
||||
(t/is (str/includes? (:hint data) "materialise")))))))))
|
||||
(t/is (str/includes? (:hint data) "detach")))))))))
|
||||
|
||||
(t/deftest oplog-depth-gate-refuses-a-compare-before-the-derive
|
||||
;; The derive replays the whole op log, so it is the cost the depth gate
|
||||
@ -1754,7 +1916,7 @@
|
||||
(with-redefs [bfc/branch-file-data (fn [& args]
|
||||
(swap! derives inc)
|
||||
(apply derive args))]
|
||||
(th/command! {::th/type :get-branch-diff
|
||||
(th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})))]
|
||||
|
||||
@ -1776,7 +1938,7 @@
|
||||
(t/is (= :compare (:operation data)))
|
||||
(t/is (= 1 (:actual data)))
|
||||
(t/is (zero? @derives) "the refused compare derived the branch first")
|
||||
(t/is (str/includes? (:hint data) "materialise"))
|
||||
(t/is (str/includes? (:hint data) "detach"))
|
||||
(t/is (not (str/includes? (:hint data) "merge")))))))))
|
||||
|
||||
(t/deftest oplog-depth-gate-counts-the-changes-a-row-holds
|
||||
@ -1812,7 +1974,7 @@
|
||||
(fn [& args]
|
||||
(swap! derives inc)
|
||||
(apply derive! args))]
|
||||
(th/command! {::th/type :get-branch-diff
|
||||
(th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})))]
|
||||
|
||||
@ -1846,7 +2008,7 @@
|
||||
|
||||
(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"})
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -1938,13 +2100,13 @@
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "audited-exit"})
|
||||
out (th/command! {::th/type :materialize-file-branch
|
||||
out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id (-> created :result :branch-file-id)})
|
||||
:branch-id (-> created :result :id)})
|
||||
props (-> out :result meta :app.loggers.audit/props)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "materialize" (:branch-operation props)))
|
||||
(t/is (= "materialized" (:branch-outcome props)))
|
||||
(t/is (= "detach" (:branch-operation props)))
|
||||
(t/is (= "detached" (:branch-outcome props)))
|
||||
(t/is (int? (:branch-duration-ms props))))))))
|
||||
|
||||
(t/deftest delete-serializes-against-a-concurrent-merge
|
||||
@ -1981,7 +2143,7 @@
|
||||
(orig-lock conn id))]
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :branch-not-found (-> out :error ex-data :code)))
|
||||
(t/is (= :merged (-> @merged :result :status)))
|
||||
;; the merge's deletion is the only one: the row still says
|
||||
@ -2013,7 +2175,7 @@
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :branch-not-found (-> out :error ex-data :code))))
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})]
|
||||
(t/is (= "merged" (:status row)))
|
||||
@ -2036,9 +2198,9 @@
|
||||
branch-id (:id create)
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
(let [out (th/command! {::th/type :update-file-branch
|
||||
(let [out (th/command! {::th/type :update-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id
|
||||
:branch-id branch-id
|
||||
:name "new-name"})]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
@ -2059,9 +2221,9 @@
|
||||
branch-id (:id create)]
|
||||
|
||||
(t/testing "a rename carries its operation, outcome and duration"
|
||||
(let [out (th/command! {::th/type :update-file-branch
|
||||
(let [out (th/command! {::th/type :update-file-branch-info
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id
|
||||
:branch-id branch-id
|
||||
:name "audited-rename"})
|
||||
props (-> out :result meta :app.loggers.audit/props)]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -2072,7 +2234,7 @@
|
||||
(t/testing "archiving reports archive-branch, restoring restore-branch"
|
||||
(let [out (th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})
|
||||
:branch-id branch-id})
|
||||
props (-> out :result meta :app.loggers.audit/props)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "archive-branch" (:branch-operation props)))
|
||||
@ -2080,7 +2242,7 @@
|
||||
(t/is (int? (:branch-duration-ms props))))
|
||||
(let [out (th/command! {::th/type :archive-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id
|
||||
:branch-id branch-id
|
||||
:archived false})
|
||||
props (-> out :result meta :app.loggers.audit/props)]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -2091,7 +2253,7 @@
|
||||
(t/testing "a delete reports delete-branch and its outcome"
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})
|
||||
:branch-id branch-id})
|
||||
props (-> out :result meta :app.loggers.audit/props)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "delete-branch" (:branch-operation props)))
|
||||
@ -2117,7 +2279,7 @@
|
||||
:color {:id (uuid/random) :name "M" :color "#00ff00" :opacity 1}})
|
||||
|
||||
;; ...and the update repositions the merge base to a new snapshot
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -2125,7 +2287,7 @@
|
||||
|
||||
(let [brow (first (th/db-query :file-branch {:id branch-id}))
|
||||
base (first (th/db-query :file-change {:id (:base-snapshot-id brow)}))
|
||||
meta (:meta (:result (th/command! {::th/type :get-branch-diff
|
||||
meta (:meta (:result (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})))]
|
||||
;; `:base-at` is when the CURRENT base snapshot row was created...
|
||||
@ -2222,7 +2384,7 @@
|
||||
(let [[base] (th/db-query :file-branch {:id branch-id})]
|
||||
(with-redefs [cfv/validate-file unfixable
|
||||
cfr/repair-file no-repair]
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})
|
||||
data (ex-data (:error out))]
|
||||
@ -2240,16 +2402,16 @@
|
||||
|
||||
(let [[row] (th/db-query :file-branch {:id branch-id})]
|
||||
(t/is (= "open" (:status row)))
|
||||
(t/is (= (:base-revn base) (:base-revn row))))))
|
||||
(t/is (= (:base-source-revn base) (:base-source-revn row))))))
|
||||
|
||||
(t/testing "materialize never refuses: the exit door lets the user out"
|
||||
(with-redefs [cfv/validate-file unfixable
|
||||
cfr/repair-file no-repair]
|
||||
(let [out (th/command! {::th/type :materialize-file-branch
|
||||
(let [out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :materialized (-> out :result :status)))
|
||||
(t/is (= :detached (-> out :result :status)))
|
||||
(t/is (true? (-> out :result :changed)))))
|
||||
|
||||
(let [row (th/db-get :file {:id branch-file-id})]
|
||||
@ -2293,7 +2455,7 @@
|
||||
|
||||
(with-redefs [cfv/validate-file (validate-once)
|
||||
cfr/repair-file (repair! "repaired-update")]
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -2374,7 +2536,7 @@
|
||||
;; the cache now describes the pre-update branch
|
||||
(t/is (= 0 (-> (summary b2-fid) :colors :count)))
|
||||
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id b2-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
@ -2393,11 +2555,11 @@
|
||||
:name "R"
|
||||
:color "#778899"
|
||||
:opacity 1}}])]
|
||||
(let [out (th/command! {::th/type :materialize-file-branch
|
||||
(let [out (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id b2-fid})]
|
||||
:branch-id b2-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :materialized (-> out :result :status)))))
|
||||
(t/is (= :detached (-> out :result :status)))))
|
||||
|
||||
(t/is (= 2 (-> (summary b2-fid) :colors :count)))))))
|
||||
|
||||
@ -2412,7 +2574,7 @@
|
||||
;; outer one holds any lock.
|
||||
;;
|
||||
;; The RPC concurrency limiter caps `:merge-file-branch/global` and
|
||||
;; `:update-branch-from-main/global` at one permit each, and would
|
||||
;; `:update-file-branch-from-source/global` at one permit each, and would
|
||||
;; serialize two same-kind commands completely (the nested one could
|
||||
;; never run inside the outer one's transaction), hiding the lock-level
|
||||
;; race these tests target; the interleaved tests run with the bulkhead
|
||||
@ -2505,7 +2667,7 @@
|
||||
;; from main 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-branch-from-main
|
||||
(t/is (nil? (:error (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))))
|
||||
(reset! superseded
|
||||
@ -2555,7 +2717,7 @@
|
||||
;; the second one takes any lock: it repositions
|
||||
;; the merge base and releases the old pin
|
||||
(when (compare-and-set! raced? false true)
|
||||
(t/is (nil? (:error (th/command! {::th/type :update-branch-from-main
|
||||
(t/is (nil? (:error (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))))
|
||||
(let [brow (first (th/db-query :file-branch {:id branch-id}))]
|
||||
@ -2563,7 +2725,7 @@
|
||||
(reset! superseded
|
||||
(:deleted-at (first (th/db-query :file-change {:id old-base}))))))
|
||||
(orig-lock conn id))]
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :updated (-> out :result :status)))))
|
||||
@ -2606,7 +2768,7 @@
|
||||
:branch (first (th/db-query :file-branch {:id branch-id}))}))]
|
||||
(let [out (th/command! {::th/type :delete-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:id branch-id})]
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= :deleted (-> out :result :status)))))
|
||||
(let [[{:keys [message branch]}] @seen]
|
||||
@ -2634,12 +2796,12 @@
|
||||
(with-redefs [mbus/pub!
|
||||
(fn [_ & {:keys [message]}]
|
||||
(swap! seen conj {:message message
|
||||
:main-revn (:revn (first (th/db-query :file {:id (:id file)})))}))]
|
||||
:source-revn (:revn (first (th/db-query :file {:id (:id file)})))}))]
|
||||
;; a refused merge publishes nothing
|
||||
(let [out (th/command! {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id
|
||||
:expected-main-revn 9999})]
|
||||
:expected-source-revn 9999})]
|
||||
(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
|
||||
@ -2649,12 +2811,12 @@
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :merged (-> out :result :status))))
|
||||
(let [by-type (into {} (map (juxt (comp :type :message) identity)) @seen)
|
||||
{:keys [message main-revn]} (get by-type :file-merged)]
|
||||
{:keys [message source-revn]} (get by-type :file-merged)]
|
||||
(t/is (= 2 (count @seen)))
|
||||
(t/is (= #{:file-deleted :file-merged} (set (keys by-type))))
|
||||
(t/is (= branch-file-id (get-in by-type [:file-deleted :message :file-id])))
|
||||
;; the merge was already committed when the message left
|
||||
(t/is (= (:revn message) main-revn)))))))
|
||||
(t/is (= (:revn message) source-revn)))))))
|
||||
|
||||
(t/deftest update-notifies-only-after-the-commit
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
@ -2677,7 +2839,7 @@
|
||||
(swap! seen conj {:topic topic
|
||||
:message message
|
||||
:branch-revn (:revn (first (th/db-query :file {:id branch-file-id})))}))]
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
@ -2688,11 +2850,10 @@
|
||||
;; the update was already committed when the message left
|
||||
(t/is (= (:revn message) branch-revn)))))))
|
||||
|
||||
(t/deftest materialize-takes-the-branch-file-id
|
||||
;; `:branch-file-id` names the branch FILE — the id `::create-file-branch`
|
||||
;; returns under that same key — while the sibling commands take the
|
||||
;; `file_branch` row id. The old generic `:file-id` name is refused by
|
||||
;; the schema.
|
||||
(t/deftest detach-takes-the-branch-row-id
|
||||
;; `:branch-id` names the `file_branch` row, as in every other branch
|
||||
;; command; the branch FILE id under the old `:branch-file-id` name is
|
||||
;; refused by the schema.
|
||||
(with-redefs [cf/flags (conj cf/flags :branching)]
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
proj-id (:default-project-id profile)
|
||||
@ -2702,25 +2863,25 @@
|
||||
create (:result (th/command! {::th/type :create-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file)
|
||||
:name "to-materialize"}))
|
||||
:name "to-detach"}))
|
||||
branch-file-id (:branch-file-id create)]
|
||||
|
||||
(t/testing "the old :file-id param is refused by the schema"
|
||||
(let [{:keys [error]} (th/command! {::th/type :materialize-file-branch
|
||||
(t/testing "the old :branch-file-id param is refused by the schema"
|
||||
(let [{:keys [error]} (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id branch-file-id})]
|
||||
:branch-file-id branch-file-id})]
|
||||
(t/is (some? error))
|
||||
(t/is (th/ex-of-type? error :validation))
|
||||
(t/is (th/ex-of-code? error :params-validation)))
|
||||
;; refused before the handler runs, so the branch is untouched
|
||||
(t/is (true? (:is-branch (th/db-get :file {:id branch-file-id})))))
|
||||
|
||||
(t/testing "materialize runs on :branch-file-id"
|
||||
(let [{:keys [error result]} (th/command! {::th/type :materialize-file-branch
|
||||
(t/testing "detach runs on :branch-id"
|
||||
(let [{:keys [error result]} (th/command! {::th/type :detach-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-file-id branch-file-id})]
|
||||
:branch-id (:id create)})]
|
||||
(t/is (nil? error))
|
||||
(t/is (= :materialized (:status result)))
|
||||
(t/is (= :detached (:status result)))
|
||||
(t/is (true? (:changed result))))))))
|
||||
|
||||
;;; --- A comparison that cannot be made is never "in sync"
|
||||
@ -2893,7 +3054,7 @@
|
||||
{:type :add-color
|
||||
:color {:id (uuid/random) :name "C1"
|
||||
:color "#112233" :opacity 1}}))))
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
@ -2909,7 +3070,7 @@
|
||||
(t/testing "deleting it on main 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-branch-from-main
|
||||
(let [out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (= :updated (-> out :result :status))))
|
||||
@ -2945,7 +3106,7 @@
|
||||
:color {:id (uuid/random) :name "C"
|
||||
:color "#112233" :opacity 1}}))
|
||||
update! (fn [branch-id]
|
||||
(th/command! {::th/type :update-branch-from-main
|
||||
(th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))]
|
||||
|
||||
@ -3051,7 +3212,7 @@
|
||||
(spit path content)
|
||||
(.setLastModified path mtime))
|
||||
compare! (fn []
|
||||
(let [out (th/command! {::th/type :get-branch-diff
|
||||
(let [out (th/command! {::th/type :get-file-branch-diff
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id})]
|
||||
(t/is (nil? (:error out)))))]
|
||||
@ -3164,7 +3325,7 @@
|
||||
(let [main-id (uuid/random)]
|
||||
(apply-change* profile (:id file)
|
||||
{:type :add-color :color {:id main-id :name "Main" :color "#00ff00" :opacity 1}})
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(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})}})
|
||||
@ -3201,7 +3362,7 @@
|
||||
{: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"
|
||||
(let [out (th/command! {::th/type :update-branch-from-main
|
||||
(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})}})]
|
||||
@ -3221,7 +3382,7 @@
|
||||
;; the base moved to main, and main 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-revn row))))
|
||||
(t/is (= (:revn mf) (:base-source-revn row))))
|
||||
(let [out (th/command! {::th/type :get-file
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})]
|
||||
@ -3230,7 +3391,7 @@
|
||||
(t/testing "the excluded main 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-branch-diff
|
||||
(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 %))
|
||||
@ -3256,7 +3417,7 @@
|
||||
:file-id (:id file)
|
||||
:name "review-marks"}))
|
||||
mark (fn [profile direction change-key fingerprint reviewed]
|
||||
(th/command! {::th/type :set-branch-change-review
|
||||
(th/command! {::th/type :set-branch-change-mark
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id branch)
|
||||
:direction direction
|
||||
@ -3264,7 +3425,7 @@
|
||||
:fingerprint fingerprint
|
||||
:reviewed reviewed}))
|
||||
marks (fn [profile direction]
|
||||
(let [out (th/command! {::th/type :get-branch-change-reviews
|
||||
(let [out (th/command! {::th/type :get-branch-change-marks
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id branch)
|
||||
:direction direction})]
|
||||
@ -3272,49 +3433,49 @@
|
||||
(into {} (map (juxt :change-key :fingerprint)) (:result out))))]
|
||||
|
||||
(t/testing "a mark is read back with its fingerprint"
|
||||
(t/is (nil? (:error (mark owner :branch->main "shape/p/1" "a1" true))))
|
||||
(t/is (nil? (:error (mark owner :branch->main "shape/p/2" "b1" true))))
|
||||
(t/is (= {"shape/p/1" "a1" "shape/p/2" "b1"} (marks owner :branch->main))))
|
||||
(t/is (nil? (:error (mark owner :branch->source "shape/p/1" "a1" true))))
|
||||
(t/is (nil? (:error (mark owner :branch->source "shape/p/2" "b1" true))))
|
||||
(t/is (= {"shape/p/1" "a1" "shape/p/2" "b1"} (marks owner :branch->source))))
|
||||
|
||||
(t/testing "marking again keeps one mark, with the newest fingerprint"
|
||||
(t/is (nil? (:error (mark owner :branch->main "shape/p/1" "a2" true))))
|
||||
(t/is (= {"shape/p/1" "a2" "shape/p/2" "b1"} (marks owner :branch->main))))
|
||||
(t/is (nil? (:error (mark owner :branch->source "shape/p/1" "a2" true))))
|
||||
(t/is (= {"shape/p/1" "a2" "shape/p/2" "b1"} (marks owner :branch->source))))
|
||||
|
||||
(t/testing "each direction has its own marks"
|
||||
(t/is (= {} (marks owner :main->branch)))
|
||||
(t/is (nil? (:error (mark owner :main->branch "shape/p/1" "m1" true))))
|
||||
(t/is (= {"shape/p/1" "m1"} (marks owner :main->branch)))
|
||||
(t/is (= "a2" (get (marks owner :branch->main) "shape/p/1"))))
|
||||
(t/is (= {} (marks owner :source->branch)))
|
||||
(t/is (nil? (:error (mark owner :source->branch "shape/p/1" "m1" true))))
|
||||
(t/is (= {"shape/p/1" "m1"} (marks owner :source->branch)))
|
||||
(t/is (= "a2" (get (marks owner :branch->source) "shape/p/1"))))
|
||||
|
||||
(t/testing "the marks of a profile are not anybody else's"
|
||||
(t/is (= {} (marks mate :branch->main)))
|
||||
(t/is (nil? (:error (mark mate :branch->main "shape/p/2" "theirs" true))))
|
||||
(t/is (= {"shape/p/2" "theirs"} (marks mate :branch->main)))
|
||||
(t/is (= "b1" (get (marks owner :branch->main) "shape/p/2"))))
|
||||
(t/is (= {} (marks mate :branch->source)))
|
||||
(t/is (nil? (:error (mark mate :branch->source "shape/p/2" "theirs" true))))
|
||||
(t/is (= {"shape/p/2" "theirs"} (marks mate :branch->source)))
|
||||
(t/is (= "b1" (get (marks owner :branch->source) "shape/p/2"))))
|
||||
|
||||
(t/testing "clearing a mark removes that one alone"
|
||||
(t/is (nil? (:error (mark owner :branch->main "shape/p/1" "a2" false))))
|
||||
(t/is (= {"shape/p/2" "b1"} (marks owner :branch->main)))
|
||||
(t/is (= {"shape/p/1" "m1"} (marks owner :main->branch)))
|
||||
(t/is (= {"shape/p/2" "theirs"} (marks mate :branch->main))))
|
||||
(t/is (nil? (:error (mark owner :branch->source "shape/p/1" "a2" false))))
|
||||
(t/is (= {"shape/p/2" "b1"} (marks owner :branch->source)))
|
||||
(t/is (= {"shape/p/1" "m1"} (marks owner :source->branch)))
|
||||
(t/is (= {"shape/p/2" "theirs"} (marks mate :branch->source))))
|
||||
|
||||
(t/testing "a profile that cannot read the file neither marks nor reads"
|
||||
(let [out (mark stranger :branch->main "shape/p/1" "x" true)]
|
||||
(let [out (mark stranger :branch->source "shape/p/1" "x" true)]
|
||||
(t/is (th/ex-info? (:error out)))
|
||||
(t/is (= :not-found (th/ex-type (:error out)))))
|
||||
(let [out (th/command! {::th/type :get-branch-change-reviews
|
||||
(let [out (th/command! {::th/type :get-branch-change-marks
|
||||
::rpc/profile-id (:id stranger)
|
||||
:branch-id (:id branch)
|
||||
:direction :branch->main})]
|
||||
:direction :branch->source})]
|
||||
(t/is (= :not-found (th/ex-type (:error out)))))
|
||||
(t/is (= {"shape/p/2" "b1"} (marks owner :branch->main))
|
||||
(t/is (= {"shape/p/2" "b1"} (marks owner :branch->source))
|
||||
"the refused mark was not written"))
|
||||
|
||||
(t/testing "a branch that does not exist is not found"
|
||||
(let [out (th/command! {::th/type :get-branch-change-reviews
|
||||
(let [out (th/command! {::th/type :get-branch-change-marks
|
||||
::rpc/profile-id (:id owner)
|
||||
:branch-id (uuid/next)
|
||||
:direction :branch->main})]
|
||||
:direction :branch->source})]
|
||||
(t/is (= :not-found (th/ex-type (:error out))))
|
||||
(t/is (= :branch-not-found (th/ex-code (:error out)))))))))
|
||||
|
||||
@ -3340,7 +3501,7 @@
|
||||
|
||||
(t/testing "the update from main"
|
||||
(let [session-id (uuid/random)
|
||||
out (th/command! {::th/type :update-branch-from-main
|
||||
out (th/command! {::th/type :update-file-branch-from-source
|
||||
::rpc/profile-id (:id profile)
|
||||
::rpc/session-id session-id
|
||||
:branch-id branch-id})]
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)
|
||||
:name "feature-login"}))
|
||||
review (:result (th/command! {::th/type :create-pull-request
|
||||
review (:result (th/command! {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)
|
||||
:title "Checkout redesign"
|
||||
@ -117,11 +117,18 @@
|
||||
:page-id page-id
|
||||
:shape-id rect-id
|
||||
:assignee-id (:id author)
|
||||
:pull-request-id (:id review)})
|
||||
:review-id (:id review)})
|
||||
task (:result out)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= "open" (:status task)))
|
||||
(t/is (= "Checkout redesign" (:review-title task)))
|
||||
(t/is (= "Checkout redesign"
|
||||
(->> (th/command! {::th/type :get-file-tasks
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id branch-file-id})
|
||||
:result
|
||||
(filter #(= (:id task) (:id %)))
|
||||
first
|
||||
:review-title)))
|
||||
|
||||
(t/testing "the assignee marks it done and the reviewer verifies it"
|
||||
(t/is (nil? (:error (set-status* author (:id task) "done"))))
|
||||
@ -137,7 +144,7 @@
|
||||
(t/is (= {:from "done" :to "verified"} (:payload (last events))))))
|
||||
|
||||
(t/testing "the review counts its tasks"
|
||||
(let [row (:result (th/command! {::th/type :get-pull-request
|
||||
(let [row (:result (th/command! {::th/type :get-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id review)}))]
|
||||
(t/is (= {"verified" 1} (-> row :counts :tasks))))))))
|
||||
@ -196,14 +203,14 @@
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 10 20)
|
||||
:content "The pay button loses contrast"
|
||||
:pull-request-id (:id review)
|
||||
:review-id (:id review)
|
||||
:anchor {:type :layer :shape-id rect-id}})]
|
||||
(t/is (nil? (:error out)))
|
||||
(let [[thread] (:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:file-id branch-file-id}))]
|
||||
(t/is (= (:id review) (:pull-request-id thread)))
|
||||
(t/is (= "Checkout redesign" (:pull-request-title thread)))
|
||||
(t/is (= (:id review) (:review-id thread)))
|
||||
(t/is (= "Checkout redesign" (:review-title thread)))
|
||||
(t/is (= :layer (:anchor-type thread)))
|
||||
(t/is (= rect-id (:shape-id thread)))))))
|
||||
|
||||
@ -217,8 +224,8 @@
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "on main"
|
||||
:pull-request-id (:id review)})]
|
||||
(t/is (= :pull-request-not-open (-> out :error ex-data :code))))))
|
||||
:review-id (:id review)})]
|
||||
(t/is (= :branch-review-not-open (-> out :error ex-data :code))))))
|
||||
|
||||
(t/deftest branch-save-under-review-records-its-activity
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
@ -226,7 +233,7 @@
|
||||
(update-file* author branch-file-id
|
||||
[{:type :mod-obj :page-id page-id :id rect-id
|
||||
:operations [{:type :set :attr :name :val "Pay"}]}])
|
||||
(let [result (:result (th/command! {::th/type :get-pull-request-activity
|
||||
(let [result (:result (th/command! {::th/type :get-branch-review-activity
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id review)}))]
|
||||
(t/is (= [{:id rect-id :kind :modified :attrs {:name ["Pay button" "Pay"]}}]
|
||||
@ -255,12 +262,12 @@
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "fix the radius"
|
||||
:pull-request-id (:id review)}))
|
||||
:review-id (:id review)}))
|
||||
open (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:shape-id rect-id
|
||||
:thread-id (:id thread)
|
||||
:pull-request-id (:id review)}))
|
||||
:review-id (:id review)}))
|
||||
closed (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:title "Drop the promo"}))]
|
||||
@ -283,16 +290,213 @@
|
||||
(t/is (every? #(= (:id merge-row) (:merge-id %)) tasks))
|
||||
(t/is (every? #(= "feature-login" (:branch-name %)) tasks))
|
||||
(t/is (= "Checkout redesign"
|
||||
(:review-title (th/db-get :file-task {:id (:id open)})))))
|
||||
(:review-title (first (filter #(= (:id open) (:id %)) tasks)))))
|
||||
(t/is (= (:id review) (:review-id merge-row)))
|
||||
(t/is (= "Checkout redesign" (:review-title merge-row)))
|
||||
(t/is (= (:family-id (th/db-get :file {:id (:id file)})) (:family-id merge-row))))
|
||||
|
||||
(t/testing "the threads move with their tasks and take the next numbers of main"
|
||||
(t/testing "every task gets a `merged` event naming the merge"
|
||||
(let [events (:result (th/command! {::th/type :get-task-events
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id open)}))]
|
||||
(t/is (= "merged" (:type (last events))))
|
||||
(t/is (= "feature-login" (-> events last :payload :branch-name)))))
|
||||
|
||||
(t/testing "the threads move with their tasks and keep their numbers in the family"
|
||||
(let [moved (th/db-get :comment-thread {:id (:id thread)})
|
||||
closed (th/db-get :comment-thread {:id (:thread-id closed)})]
|
||||
closed (th/db-get :comment-thread {:id (:thread-id closed)})
|
||||
family (:family-id (th/db-get :file {:id (:id file)}))]
|
||||
(t/is (= (:id file) (:file-id moved)))
|
||||
(t/is (= (:id file) (:file-id closed)))
|
||||
(t/is (= [family family] [(:family-id moved) (:family-id closed)]))
|
||||
(t/is (= [2 3] [(:seqn moved) (:seqn closed)]))
|
||||
(t/is (= 3 (:comment-thread-seqn (th/db-get :file {:id (:id file)}
|
||||
{::db/remove-deleted false})))))))))
|
||||
(t/is (= 3 (:thread-seqn (th/db-get :file-family {:id family})))))))))
|
||||
|
||||
;; --- What the merge moves: the thread is the unit
|
||||
|
||||
(defn- thread*
|
||||
[profile file-id page-id params]
|
||||
(:result (th/command! (merge {::th/type :create-comment-thread
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:frame-id uuid/zero
|
||||
:position (gpt/point 0)
|
||||
:content "fix the radius"}
|
||||
params))))
|
||||
|
||||
(defn- message-ids*
|
||||
"The ids of the messages of a thread, oldest first."
|
||||
[profile thread-id]
|
||||
(->> (th/command! {::th/type :get-comments
|
||||
::rpc/profile-id (:id profile)
|
||||
:thread-id thread-id})
|
||||
:result
|
||||
(sort-by :created-at)
|
||||
(mapv :id)))
|
||||
|
||||
(defn- setup-review-threads
|
||||
"The branch of `setup-review` with four threads: a review thread holding
|
||||
an open task and a closed one (`mixed`), a review thread whose only task
|
||||
is closed (`closed` is that task), a review thread with no task
|
||||
(`quiet`), and a thread written outside the review (`loose`)."
|
||||
[]
|
||||
(let [{:keys [author reviewer page-id branch-file-id review] :as setup} (setup-review)
|
||||
mixed (thread* reviewer branch-file-id page-id {:review-id (:id review)})
|
||||
_ (th/command! {::th/type :create-comment
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:thread-id (:id mixed)
|
||||
:content "and the shadow"})
|
||||
[first-id reply-id] (message-ids* author (:id mixed))
|
||||
open (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:review-id (:id review)
|
||||
:thread-id (:id mixed)
|
||||
:comment-id first-id
|
||||
:assignee-id (:id reviewer)
|
||||
:title "Fix the radius"}))
|
||||
done (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:review-id (:id review)
|
||||
:thread-id (:id mixed)
|
||||
:comment-id reply-id
|
||||
:title "Fix the shadow"}))
|
||||
closed (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:review-id (:id review)
|
||||
:assignee-id (:id reviewer)
|
||||
:title "Drop the promo"}))
|
||||
quiet (thread* reviewer branch-file-id page-id {:review-id (:id review)
|
||||
:content "Is this button still needed?"})
|
||||
loose (thread* author branch-file-id page-id {:content "a note outside the review"})]
|
||||
(set-status* author (:id done) "wont-do")
|
||||
(set-status* author (:id closed) "wont-do")
|
||||
(assoc setup
|
||||
:mixed mixed
|
||||
:open open
|
||||
:done done
|
||||
:closed closed
|
||||
:quiet quiet
|
||||
:loose loose)))
|
||||
|
||||
(defn- merge*
|
||||
[profile branch & {:as params}]
|
||||
(th/command! (merge {::th/type :merge-file-branch
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id (:id branch)}
|
||||
params)))
|
||||
|
||||
(t/deftest merge-moves-the-threads-with-an-open-task-and-those-outside-reviews
|
||||
(let [sent (atom [])]
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ params] (swap! sent conj params) nil)]
|
||||
(let [{:keys [author reviewer file branch branch-file-id review mixed open done closed quiet loose]}
|
||||
(setup-review-threads)]
|
||||
(reset! sent [])
|
||||
(t/is (nil? (:error (merge* author branch :notify-assignees true))))
|
||||
|
||||
(t/testing "a thread holding an open task moves whole, with its closed task"
|
||||
(t/is (= (:id file) (:file-id (th/db-get :comment-thread {:id (:id mixed)}))))
|
||||
(let [rows (mapv #(th/db-get :file-task {:id (:id %)}) [open done])]
|
||||
(t/is (= [(:id file) (:id file)] (mapv :file-id rows)))
|
||||
(t/is (every? (comp some? :merge-id) rows))))
|
||||
|
||||
(t/testing "a thread written outside any review moves"
|
||||
(t/is (= (:id file) (:file-id (th/db-get :comment-thread {:id (:id loose)})))))
|
||||
|
||||
(t/testing "a review thread with no open task stays on the branch file"
|
||||
(let [task (th/db-get :file-task {:id (:id closed)})]
|
||||
(t/is (= branch-file-id (:file-id task)))
|
||||
(t/is (nil? (:merge-id task)))
|
||||
(t/is (= branch-file-id (:file-id (th/db-get :comment-thread {:id (:thread-id closed)}))))))
|
||||
|
||||
(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"
|
||||
(let [threads (:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))
|
||||
tasks (:result (th/command! {::th/type :get-file-tasks
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))]
|
||||
(t/is (= #{(:id mixed) (:id loose)} (into #{} (map :id) threads)))
|
||||
(t/is (= #{(:id open) (:id done)} (into #{} (map :id) tasks)))))
|
||||
|
||||
(t/testing "the assignee of the moved open task is told, and nobody else"
|
||||
(let [merged (filterv #(= "tasks-merged" (::eml/template %)) @sent)]
|
||||
(t/is (= [(:email reviewer)] (mapv :to merged)))
|
||||
(t/is (= "- Fix the radius" (:task-titles (first merged))))))
|
||||
|
||||
(t/testing "the review is kept as merged"
|
||||
(t/is (= "merged" (:status (th/db-get :file-branch-review {:id (:id review)})))))))))
|
||||
|
||||
(defn- move-thread*
|
||||
[profile thread-id]
|
||||
(th/command! {::th/type :move-branch-review-thread
|
||||
::rpc/profile-id (:id profile)
|
||||
:thread-id thread-id}))
|
||||
|
||||
(t/deftest a-thread-left-behind-moves-to-the-target-on-request
|
||||
(let [sent (atom [])]
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ params] (swap! sent conj params) nil)]
|
||||
(let [{:keys [author reviewer file branch branch-file-id closed quiet]} (setup-review-threads)
|
||||
viewer (th/create-profile* 3 {:is-active true})
|
||||
thread-id (:thread-id closed)]
|
||||
(th/create-team-role* {:team-id (:default-team-id author)
|
||||
:profile-id (:id viewer)
|
||||
:role :viewer})
|
||||
|
||||
(t/testing "a thread of a branch that is not merged is refused"
|
||||
(t/is (= :branch-not-merged (-> (move-thread* author thread-id) :error ex-data :code)))
|
||||
(t/is (= branch-file-id (:file-id (th/db-get :comment-thread {:id thread-id})))))
|
||||
|
||||
(t/is (nil? (:error (merge* author branch))))
|
||||
(t/is (= branch-file-id (:file-id (th/db-get :comment-thread {:id thread-id}))))
|
||||
|
||||
;; the task of the thread left behind is open again: no command
|
||||
;; reaches a task on the deleted branch file, so the row is set
|
||||
;; directly, to see the move tell its assignee
|
||||
(th/db-exec! ["UPDATE file_task SET status = 'reopened' WHERE id = ?" (:id closed)])
|
||||
|
||||
(t/testing "a viewer of the target may not move it"
|
||||
(t/is (= :not-found (-> (move-thread* viewer thread-id) :error ex-data :type)))
|
||||
(t/is (= branch-file-id (:file-id (th/db-get :comment-thread {:id thread-id})))))
|
||||
|
||||
(reset! sent [])
|
||||
|
||||
(t/testing "an editor of the target moves it whole, with its task"
|
||||
(let [out (move-thread* author thread-id)
|
||||
task (th/db-get :file-task {:id (:id closed)})
|
||||
[merge-row] (th/db-query :file-branch-merge {:file-id (:id file)})]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= [(:id closed)] (-> out :result :task-ids)))
|
||||
(t/is (= (:id file) (:file-id (th/db-get :comment-thread {:id thread-id}))))
|
||||
(t/is (= (:id file) (:file-id task)))
|
||||
(t/is (= (:id merge-row) (:merge-id task)))
|
||||
(let [event (last (:result (th/command! {::th/type :get-task-events
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id closed)})))]
|
||||
(t/is (= "merged" (:type event)))
|
||||
(t/is (= "feature-login" (-> event :payload :branch-name))))))
|
||||
|
||||
(t/testing "the assignee of the moved open task is told, the mover not"
|
||||
(let [merged (filterv #(= "tasks-merged" (::eml/template %)) @sent)]
|
||||
(t/is (= [(:email reviewer)] (mapv :to merged)))
|
||||
(t/is (= "- Drop the promo" (:task-titles (first merged))))))
|
||||
|
||||
(t/testing "the moved thread reads on the target, the other one still not"
|
||||
(let [threads (:result (th/command! {::th/type :get-comment-threads
|
||||
::rpc/profile-id (:id author)
|
||||
:file-id (:id file)}))
|
||||
ids (into #{} (map :id) threads)]
|
||||
(t/is (contains? ids thread-id))
|
||||
(t/is (not (contains? ids (:id quiet))))))
|
||||
|
||||
(t/testing "a thread already on the target is refused"
|
||||
(t/is (= :thread-already-on-target
|
||||
(-> (move-thread* author thread-id) :error ex-data :code))))))))
|
||||
|
||||
(t/deftest each-message-of-a-thread-may-be-a-task
|
||||
(with-redefs [cf/flags (task-flags)]
|
||||
@ -368,7 +572,7 @@
|
||||
:shape-id rect-id
|
||||
:position (gpt/point 30 40)
|
||||
:title " Use the secondary token "
|
||||
:pull-request-id (:id review)})
|
||||
:review-id (:id review)})
|
||||
task (:result out)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (some? (:thread-id task)))
|
||||
@ -378,7 +582,7 @@
|
||||
(let [thread (th/db-get :comment-thread {:id (:thread-id task)})]
|
||||
(t/is (= branch-file-id (:file-id thread)))
|
||||
(t/is (= (:id reviewer) (:owner-id thread)))
|
||||
(t/is (= (:id review) (:pull-request-id thread)))
|
||||
(t/is (= (:id review) (:review-id thread)))
|
||||
(t/is (= "layer" (:anchor-type thread)))
|
||||
(t/is (= rect-id (:shape-id thread)))))
|
||||
|
||||
@ -404,9 +608,9 @@
|
||||
:page-id page-id
|
||||
:position (gpt/point 120 340)}))
|
||||
thread (th/db-get :comment-thread {:id (:thread-id task)})]
|
||||
(t/is (= "canvas" (:anchor-type thread)))
|
||||
(t/is (= "point" (:anchor-type thread)))
|
||||
(t/is (nil? (:shape-id thread)))
|
||||
(t/is (nil? (:pull-request-id thread)))
|
||||
(t/is (nil? (:review-id thread)))
|
||||
(t/is (= {:x 120.0 :y 340.0} (into {} (db/decode-pgpoint (:position thread))))))))
|
||||
|
||||
(t/deftest deleting-a-thread-deletes-its-tasks
|
||||
@ -667,6 +871,49 @@
|
||||
(t/is (= "relinked" (:type event)))
|
||||
(t/is (some? (-> event :payload :area)))))))
|
||||
|
||||
(t/deftest a-moved-review-thread-whose-layer-the-branch-deleted-lands-on-its-parent
|
||||
;; The thread is the unit: a review thread holding an open task moves
|
||||
;; with the merge, and when the branch deleted the layer it points at,
|
||||
;; the thread itself lands on the parent of that layer, as its task does.
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ _] nil)]
|
||||
(let [{:keys [author file page-id board-id rect-id branch branch-file-id]} (setup-board-branch)
|
||||
reviewer (th/create-profile* 2 {:is-active true})
|
||||
_ (th/create-team-role* {:team-id (:default-team-id author)
|
||||
:profile-id (:id reviewer)
|
||||
:role :editor})
|
||||
review (:result (th/command! {::th/type :create-branch-review
|
||||
::rpc/profile-id (:id author)
|
||||
:branch-id (:id branch)
|
||||
:title "Checkout redesign"
|
||||
:reviewers [(:id reviewer)]}))
|
||||
thread (thread* reviewer branch-file-id page-id
|
||||
{:frame-id board-id
|
||||
:review-id (:id review)
|
||||
:anchor {:type :layer :shape-id rect-id}
|
||||
:content "Is this button still needed?"})
|
||||
task (:result (create-task* author {:file-id branch-file-id
|
||||
:page-id page-id
|
||||
:frame-id board-id
|
||||
:shape-id rect-id
|
||||
:review-id (:id review)
|
||||
:thread-id (:id thread)
|
||||
:comment-id (first (message-ids* author (:id thread)))}))]
|
||||
(t/is (some? (:id task)))
|
||||
(t/is (nil? (:error (update-file* author branch-file-id
|
||||
[{:type :del-obj :page-id page-id :id rect-id}]))))
|
||||
(t/is (nil? (:error (merge* author branch))))
|
||||
|
||||
(let [row (th/db-get :comment-thread {:id (:id thread)})]
|
||||
(t/is (= (:id file) (:file-id row)))
|
||||
(t/is (= (:id review) (:review-id row)))
|
||||
(t/is (= "layer" (:anchor-type row)))
|
||||
(t/is (= board-id (:shape-id row)))
|
||||
(t/is (= board-id (:frame-id row))))
|
||||
(let [row (th/db-get :file-task {:id (:id task)})]
|
||||
(t/is (= (:id file) (:file-id row)))
|
||||
(t/is (= board-id (:shape-id row)))))))
|
||||
|
||||
;; --- Deleted layers of any size
|
||||
|
||||
(t/deftest a-task-on-a-board-larger-than-the-snapshot-cap-is-still-marked-lost
|
||||
@ -966,3 +1213,43 @@
|
||||
{:id (:id author)})
|
||||
(let [task (new-task)]
|
||||
(t/is (= [] (move reviewer task "done"))))))))))
|
||||
|
||||
;; --- Counts of what a branch deletion takes with it
|
||||
|
||||
(defn- branch-counts*
|
||||
[profile branch-id]
|
||||
(th/command! {::th/type :get-file-branch-counts
|
||||
::rpc/profile-id (:id profile)
|
||||
:branch-id branch-id}))
|
||||
|
||||
(t/deftest branch-counts-say-what-a-delete-takes-with-it
|
||||
(with-redefs [cf/flags (task-flags)
|
||||
eml/send-template (fn [_ _] nil)]
|
||||
(let [{:keys [author reviewer branch quiet closed]} (setup-review-threads)]
|
||||
|
||||
(t/testing "threads and tasks are counted by the branch file"
|
||||
(let [out (branch-counts* author (:id branch))]
|
||||
(t/is (nil? (:error out)))
|
||||
;; `mixed` holds the open task and the closed one, the closed
|
||||
;; task outside it got a thread of its own, and `quiet` and
|
||||
;; `loose` are the threads with no task
|
||||
(t/is (= {:threads 4 :open-tasks 1 :closed-tasks 2} (:result out)))))
|
||||
|
||||
(t/testing "a deleted thread and a deleted task are not counted"
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-comment-thread
|
||||
::rpc/profile-id (:id reviewer)
|
||||
:id (:id quiet)}))))
|
||||
(t/is (nil? (:error (th/command! {::th/type :delete-task
|
||||
::rpc/profile-id (:id author)
|
||||
:id (:id closed)}))))
|
||||
(t/is (= {:threads 3 :open-tasks 1 :closed-tasks 1}
|
||||
(:result (branch-counts* author (:id branch))))))
|
||||
|
||||
(t/testing "a profile that cannot read the branch file is refused"
|
||||
(let [stranger (th/create-profile* 3 {:is-active true})]
|
||||
(t/is (= :not-found (-> (branch-counts* stranger (:id branch))
|
||||
:error ex-data :type)))))
|
||||
|
||||
(t/testing "a branch that does not exist is not found"
|
||||
(t/is (= :branch-not-found (-> (branch-counts* author (uuid/random))
|
||||
:error ex-data :code)))))))
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
(def ^:private safe-library-envelope-keys
|
||||
"Top-level keys a trimmed library may expose next to `:data`. Anything
|
||||
else is design content leaking through the envelope (see F3)."
|
||||
#{:backend :comment-thread-seqn :created-at :features :has-media-trimmed
|
||||
#{:backend :created-at :features :has-media-trimmed
|
||||
:id :is-indirect :is-shared :migrations :modified-at :name :project-id
|
||||
:revn :synced-at :team-id :vern :version})
|
||||
|
||||
|
||||
@ -16,9 +16,10 @@
|
||||
included, except the residual page attrs (`:page-attrs`), which
|
||||
`unsupported-kinds` reports so the caller refuses them.
|
||||
|
||||
Direction `:branch->main` (merge/compare) treats main as `theirs` and
|
||||
branch as `ours`; `:main->branch` (update from main) swaps them. The
|
||||
reported payload names the DOCUMENTS either way (see `compute-merge`)."
|
||||
Direction `:branch->source` (merge/compare) treats the source as `theirs`
|
||||
and the branch as `ours`; `:source->branch` (update from the source) swaps
|
||||
them. The reported payload names the DOCUMENTS either way (see
|
||||
`compute-merge`)."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.changes :as cfc]
|
||||
@ -97,7 +98,7 @@
|
||||
(name kind)))
|
||||
|
||||
(defn- shallow-attr-diff
|
||||
"Map of attr -> {:main v :branch v} for the keys whose values differ
|
||||
"Map of attr -> {:source v :branch v} for the keys whose values differ
|
||||
between the `theirs` and `ours` entity maps. Powers the
|
||||
\"property changes\" detail in the compare view. Returns `{}` for
|
||||
non-map entities (e.g. order/name tuples)."
|
||||
@ -109,7 +110,7 @@
|
||||
ov (get ours k)]
|
||||
(if (= tv ov)
|
||||
acc
|
||||
(assoc acc k {:main tv :branch ov}))))
|
||||
(assoc acc k {:source tv :branch ov}))))
|
||||
{}
|
||||
ks))
|
||||
{}))
|
||||
@ -117,28 +118,28 @@
|
||||
;; --- Per-property conflict resolution ---
|
||||
;;
|
||||
;; A resolution value for a conflicting entity is one of:
|
||||
;; :main keep main entirely
|
||||
;; :source keep the source entirely
|
||||
;; :branch take branch entirely
|
||||
;; {attr -> side} per-property: choose :main or :branch for each
|
||||
;; {attr -> side} per-property: choose :source or :branch for each
|
||||
;; changed attribute independently
|
||||
;; The per-attr map only applies to conflicts that carry `:changed-attrs`
|
||||
;; (modify-modify / add-add). Structural conflicts (delete/modify, order,
|
||||
;; presence, …) stay keyword-only.
|
||||
|
||||
(defn- attr-side
|
||||
"Resolved side (`:main`/`:branch`) for attribute `k` under resolution
|
||||
"Resolved side (`:source`/`:branch`) for attribute `k` under resolution
|
||||
`res`. `:branch` keyword -> branch for every attr; a map -> its per-attr
|
||||
choice (defaulting to `:main`); anything else (`:main`, nil) -> main."
|
||||
choice (defaulting to `:source`); anything else (`:source`, nil) -> source."
|
||||
[res k]
|
||||
(cond
|
||||
(= res :branch) :branch
|
||||
(map? res) (if (= :branch (get res k)) :branch :main)
|
||||
:else :main))
|
||||
(map? res) (if (= :branch (get res k)) :branch :source)
|
||||
:else :source))
|
||||
|
||||
(defn- merge-attrs
|
||||
"Entity to apply for a per-attr resolution: start from main (`t`) and
|
||||
overlay branch's value for each differing attr resolved to `:branch`.
|
||||
For `res = :branch` this equals `o`; for `:main`/nil it equals `t`.
|
||||
"Entity to apply for a per-attr resolution: start from the source (`t`)
|
||||
and overlay branch's value for each differing attr resolved to `:branch`.
|
||||
For `res = :branch` this equals `o`; for `:source`/nil it equals `t`.
|
||||
An attr the winning side does not carry is REMOVED (absent key — how the
|
||||
closed change schemas express removal) rather than assoc-ed nil."
|
||||
[t o res]
|
||||
@ -152,13 +153,13 @@
|
||||
(shallow-attr-diff t o)))
|
||||
|
||||
(defn conflict-resolved?
|
||||
"True when `res` fully resolves `conflict`. A keyword `:main`/`:branch`
|
||||
"True when `res` fully resolves `conflict`. A keyword `:source`/`:branch`
|
||||
always resolves it; a per-attr map resolves it only when it carries a
|
||||
choice for every key in the conflict's `:changed-attrs` (and the
|
||||
conflict actually has changed-attrs)."
|
||||
[conflict res]
|
||||
(cond
|
||||
(contains? #{:main :branch} res) true
|
||||
(contains? #{:source :branch} res) true
|
||||
(map? res) (let [attrs (keys (:changed-attrs conflict))]
|
||||
(boolean (and (seq attrs)
|
||||
(every? #(contains? res %) attrs))))
|
||||
@ -245,10 +246,11 @@
|
||||
additions/modifications/deletions that apply cleanly to `theirs`, and
|
||||
conflicts are entities both sides diverged on.
|
||||
|
||||
Entries label the two sides for the `:branch->main` roles: `:main` holds
|
||||
the `theirs` value and `:branch` the `ours` one. `compute-merge` renames
|
||||
them to the two documents before reporting them (see `doc-sides`), so a
|
||||
summary names main's value `:main` and the branch's `:branch` in both
|
||||
Entries label the two sides for the `:branch->source` roles: `:source`
|
||||
holds the `theirs` value and `:branch` the `ours` one. `compute-merge`
|
||||
renames them to the two documents before reporting them (see
|
||||
`doc-sides`), so a summary names the source's value `:source` and the
|
||||
branch's `:branch` in both
|
||||
directions.
|
||||
|
||||
`ctx`: `{:kind <keyword> :page-id <optional uuid>}`. Optional display
|
||||
@ -289,12 +291,12 @@
|
||||
(and in-b? (not in-o?) (not= b t)) ; delete (branch) / modify (main)
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :delete-modify
|
||||
:label (entity-label kind t)
|
||||
:base b :main t :branch nil}))
|
||||
:base b :source t :branch nil}))
|
||||
|
||||
(and in-b? (not in-t?) (not= b o)) ; modify (branch) / delete (main)
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :modify-delete
|
||||
:label (entity-label kind o)
|
||||
:base b :main nil :branch o}))
|
||||
:base b :source nil :branch o}))
|
||||
|
||||
;; --- additions ---
|
||||
(and (not in-b?) in-o? (not in-t?)) ; new in branch
|
||||
@ -310,7 +312,7 @@
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :add-add
|
||||
:label (entity-label kind o)
|
||||
:changed-attrs (attr-diff t o)
|
||||
:base nil :main t :branch o}))
|
||||
:base nil :source t :branch o}))
|
||||
|
||||
;; --- present in all three ---
|
||||
(= o b) ; branch didn't touch -> main wins
|
||||
@ -330,7 +332,7 @@
|
||||
(update acc :conflicts conj (mk :conflict {:id id :reason :modify-modify
|
||||
:label (entity-label kind o)
|
||||
:changed-attrs (attr-diff t o)
|
||||
:base b :main t :branch o})))))
|
||||
:base b :source t :branch o})))))
|
||||
{:changes [] :conflicts []}
|
||||
ids)))
|
||||
|
||||
@ -354,8 +356,8 @@
|
||||
;; at a time, as Penpot's own sync does (`generate-update-tokens` in
|
||||
;; `app.common.logic.libraries`): a slot follows the component unless
|
||||
;; the sync group of the shape attr it drives is touched.
|
||||
;; The sides are the comparison roles: `:main` is `theirs` (the target),
|
||||
;; `:branch` is `ours` (the source).
|
||||
;; The sides are the comparison roles: `:source` is `theirs` (the target),
|
||||
;; `:branch` is `ours` (the side merged in).
|
||||
|
||||
(def ^:private text-content-groups
|
||||
"The groups a text `:content` change marks on top of `:content-group`
|
||||
@ -382,10 +384,10 @@
|
||||
(defn- copy-reason
|
||||
"Why the copy rule took a side for an attr or token slot no more than
|
||||
one side overrode: `t?`/`o?` say whether the target/source did. Named
|
||||
in the comparison roles (`:main` = target), as the sides are."
|
||||
in the comparison roles (`:source` = target), as the sides are."
|
||||
[t? o?]
|
||||
(cond o? :override-branch
|
||||
t? :override-main
|
||||
t? :override-source
|
||||
:else :follows-component))
|
||||
|
||||
(defn- token-slot-sides
|
||||
@ -410,7 +412,7 @@
|
||||
(if (or (nil? group) (and t? o?))
|
||||
(update acc :open-slots conj slot)
|
||||
(-> acc
|
||||
(assoc-in [:slots slot] (if o? :branch :main))
|
||||
(assoc-in [:slots slot] (if o? :branch :source))
|
||||
(assoc-in [:slot-reasons slot] (copy-reason t? o?))))))
|
||||
{:slots {} :slot-reasons {} :open-slots #{}}
|
||||
(sort-by name (filter #(not= (get theirs-tokens %) (get ours-tokens %))
|
||||
@ -426,7 +428,7 @@
|
||||
:slots {token-attr side} :slot-reasons {token-attr reason}
|
||||
:open-slots #{token-attr}}` over the attrs that differ between the two
|
||||
sides: `:auto` holds the side the rule picks for each sync attr no
|
||||
more than one side overrode (`:main` when none did), `:reasons` why
|
||||
more than one side overrode (`:source` when none did), `:reasons` why
|
||||
(`copy-reason`), and `:open` the attrs left to the user, the ones both
|
||||
sides overrode and the ones outside every sync group.
|
||||
`:applied-tokens` is settled per slot (`token-slot-sides`): it is open
|
||||
@ -452,14 +454,14 @@
|
||||
(update :open conj attr)
|
||||
|
||||
(empty? open-slots)
|
||||
(assoc-in [:auto attr] (if (some #{:branch} (vals slots)) :branch :main))))
|
||||
(assoc-in [:auto attr] (if (some #{:branch} (vals slots)) :branch :source))))
|
||||
(let [group (ctk/resolve-sync-group (:type so) attr)
|
||||
t? (and (some? group) (overrode? group tt sb st attr))
|
||||
o? (and (some? group) (overrode? group ot sb so attr))]
|
||||
(if (or (nil? group) (and t? o?))
|
||||
(update acc :open conj attr)
|
||||
(-> acc
|
||||
(assoc-in [:auto attr] (if o? :branch :main))
|
||||
(assoc-in [:auto attr] (if o? :branch :source))
|
||||
(assoc-in [:reasons attr] (copy-reason t? o?)))))))
|
||||
{:auto {} :reasons {} :open #{} :slots {} :slot-reasons {} :open-slots #{}}
|
||||
(shallow-attr-diff st so))))))
|
||||
@ -505,7 +507,7 @@
|
||||
settled (settled-sides sides)
|
||||
change (fn [status attrs]
|
||||
(-> c
|
||||
(dissoc :reason :base :main :branch)
|
||||
(dissoc :reason :base :source :branch)
|
||||
(assoc :status status
|
||||
:changed-attrs (select-keys changed-attrs attrs)
|
||||
:settled settled)))]
|
||||
@ -539,10 +541,10 @@
|
||||
:else {})
|
||||
auto)]
|
||||
(if (or (seq slots) (seq open-slots))
|
||||
(let [user (if (= :branch (get res :applied-tokens)) :branch :main)
|
||||
(let [user (if (= :branch (get res :applied-tokens)) :branch :source)
|
||||
slots (merge (zipmap open-slots (repeat user)) slots)]
|
||||
(assoc res
|
||||
:applied-tokens (if (some #{:branch} (vals slots)) :branch :main)
|
||||
:applied-tokens (if (some #{:branch} (vals slots)) :branch :source)
|
||||
::token-slots slots))
|
||||
res)))
|
||||
|
||||
@ -665,7 +667,7 @@
|
||||
|
||||
(defn- slim-conflict-sides
|
||||
[slim-fn conflicts]
|
||||
(mapv (fn [c] (-> c (update :base slim-fn) (update :main slim-fn) (update :branch slim-fn)))
|
||||
(mapv (fn [c] (-> c (update :base slim-fn) (update :source slim-fn) (update :branch slim-fn)))
|
||||
conflicts))
|
||||
|
||||
(defn- flatten-plugin-data
|
||||
@ -835,16 +837,16 @@
|
||||
A mechanism's alternatives:
|
||||
`:lost` `:conflict` (a `:modify-delete` conflict on the container:
|
||||
`:branch` restores it as the source has it, additions
|
||||
included, `:main` drops the source's shapes), `:refuse`,
|
||||
included, `:source` drops the source's shapes), `:refuse`,
|
||||
`:reparent-to-ancestor`, `:page-root`, `:cascade` (the
|
||||
container goes with its whole subtree).
|
||||
`:dropped` `:conflict` (a `:delete-modify` conflict on the container:
|
||||
`:branch` deletes the whole subtree knowingly, `:main`
|
||||
`:branch` deletes the whole subtree knowingly, `:source`
|
||||
keeps it as the target has it), `:expand` (the target's
|
||||
shapes relocate to the container's slot in its parent),
|
||||
`:page-root`, `:refuse`, `:cascade`."
|
||||
[dir]
|
||||
(let [update? (= dir :main->branch)
|
||||
(let [update? (= dir :source->branch)
|
||||
add (policy :addition-under-deleted-parent)
|
||||
cont (policy :container-delete-over-main-edits)]
|
||||
{:order (policy :same-parent-reorder)
|
||||
@ -905,7 +907,7 @@
|
||||
(`lost-root`). `:conflict` replaces them with one `:modify-delete`
|
||||
conflict on that shape: resolved to `:branch` it restores the shape
|
||||
and its subtree as the source has them, additions included; resolved
|
||||
to `:main` it leaves them out. `:refuse` adds an `:unsupported`
|
||||
to `:source` it leaves them out. `:refuse` adds an `:unsupported`
|
||||
`:shape-orphan` entry per deleted shape holding an addition. The other
|
||||
alternatives act in `page-shape-changes`.
|
||||
|
||||
@ -913,7 +915,7 @@
|
||||
subtree the target edited (added, changed or reordered something in).
|
||||
`:conflict` turns each into one `:delete-modify` conflict that replaces
|
||||
its `:deleted` entry and every entry inside its subtree: resolved to
|
||||
`:branch` the whole subtree goes, resolved to `:main` it stays as the
|
||||
`:branch` the whole subtree goes, resolved to `:source` it stays as the
|
||||
target has it. `:refuse` adds an `:unsupported` `:shape-orphan` entry
|
||||
per such shape the target added inside. The other alternatives act in
|
||||
`page-shape-changes`.
|
||||
@ -1018,7 +1020,7 @@
|
||||
:conflicts conflicts'}))))
|
||||
|
||||
(defn- diff-pages
|
||||
([base theirs ours] (diff-pages base theirs ours nil :branch->main))
|
||||
([base theirs ours] (diff-pages base theirs ours nil :branch->source))
|
||||
([base theirs ours only-pages dir]
|
||||
;; `only-pages` bounds every page pass, the presence one included,
|
||||
;; because `page-content` strips the shapes of every page it looks at
|
||||
@ -1128,7 +1130,7 @@
|
||||
rehydrate (fn [e]
|
||||
(assoc e
|
||||
:base (get bo (:id e))
|
||||
:main (get to (:id e))
|
||||
:source (get to (:id e))
|
||||
:branch (get oo (:id e))))
|
||||
;; an added or deleted shape is missing from
|
||||
;; one of the two documents, and the compare
|
||||
@ -1520,10 +1522,10 @@
|
||||
(def ^:private flip-doc
|
||||
"The other document, for a side or a copy rule reason named after one;
|
||||
anything else (`:open`, `:follows-component`) names none."
|
||||
{:main :branch
|
||||
:branch :main
|
||||
:override-main :override-branch
|
||||
:override-branch :override-main})
|
||||
{:source :branch
|
||||
:branch :source
|
||||
:override-source :override-branch
|
||||
:override-branch :override-source})
|
||||
|
||||
(defn- flip-decision
|
||||
"A copy rule decision `{:side .. :reason ..}` named after the other
|
||||
@ -1536,21 +1538,21 @@
|
||||
(defn- doc-sides
|
||||
"Rewrite one summary entry from the comparison roles to the documents.
|
||||
|
||||
`three-way-entities` reports entries in the `:branch->main` roles — the
|
||||
`theirs` value under `:main`, the `ours` value under `:branch`. For
|
||||
`:main->branch` the engine runs with those roles fed the other way round
|
||||
(so the reported changes are main's), and this renames the payload back
|
||||
before `compute-merge` reports it: the two entity sides, the two values
|
||||
inside every `:changed-attrs` pair, the two delete reasons, and the
|
||||
sides and reasons of the copy rule's `:settled` decisions.
|
||||
`:delete-modify` names the branch's deletion against main's modification
|
||||
and `:modify-delete` the branch's modification against main's deletion —
|
||||
the same meaning in both directions."
|
||||
`three-way-entities` reports entries in the `:branch->source` roles: the
|
||||
`theirs` value under `:source`, the `ours` value under `:branch`. For
|
||||
`:source->branch` the engine runs with those roles fed the other way
|
||||
round (so the reported changes are the source's), and this renames the
|
||||
payload back before `compute-merge` reports it: the two entity sides,
|
||||
the two values inside every `:changed-attrs` pair, the two delete
|
||||
reasons, and the sides and reasons of the copy rule's `:settled`
|
||||
decisions. `:delete-modify` names the branch's deletion against the
|
||||
source's modification and `:modify-delete` the branch's modification
|
||||
against the source's deletion: the same meaning in both directions."
|
||||
[{:keys [status changed-attrs settled] :as entry}]
|
||||
(let [entry (cond-> entry
|
||||
(map? changed-attrs)
|
||||
(assoc :changed-attrs
|
||||
(into {} (map (fn [[k v]] [k {:main (:branch v) :branch (:main v)}]))
|
||||
(into {} (map (fn [[k v]] [k {:source (:branch v) :branch (:source v)}]))
|
||||
changed-attrs))
|
||||
|
||||
(some? settled)
|
||||
@ -1559,7 +1561,7 @@
|
||||
(update :token-slots update-vals flip-decision))))]
|
||||
(if (= :conflict status)
|
||||
(-> entry
|
||||
(assoc :main (:branch entry) :branch (:main entry))
|
||||
(assoc :source (:branch entry) :branch (:source entry))
|
||||
(update :reason #(get {:delete-modify :modify-delete
|
||||
:modify-delete :delete-modify} % %)))
|
||||
entry)))
|
||||
@ -1760,14 +1762,14 @@
|
||||
both (fn [] (if (and (some? os) (not= (strip-nil-attrs (get bo id))
|
||||
(strip-nil-attrs os)))
|
||||
:branch
|
||||
:main))
|
||||
:source))
|
||||
acc (reduce
|
||||
(fn [acc group]
|
||||
(let [t? (contains? tt group) o? (contains? ot group)]
|
||||
(if (or t? o?)
|
||||
(update acc :keeps #(if (contains? % group)
|
||||
%
|
||||
(assoc % group (cond (and t? o?) (both) o? :branch :else :main))))
|
||||
(assoc % group (cond (and t? o?) (both) o? :branch :else :source))))
|
||||
(-> acc
|
||||
(update :follows conj group)
|
||||
(update ::followed conj [m group])
|
||||
@ -1781,7 +1783,7 @@
|
||||
o? (and (some? group) (contains? ot group))
|
||||
decision (if (and t? o?)
|
||||
{:side :open :reason :override-both}
|
||||
{:side (if o? :branch :main) :reason (copy-reason t? o?)})]
|
||||
{:side (if o? :branch :source) :reason (copy-reason t? o?)})]
|
||||
(cond-> (update acc :token-slots
|
||||
#(let [prev (get % slot)]
|
||||
(if (and (some? prev) (>= (override-rank prev) (override-rank decision)))
|
||||
@ -1921,11 +1923,11 @@
|
||||
conflict's resolution."
|
||||
[{:keys [shape-type changed-attrs]}]
|
||||
(into #{}
|
||||
(mapcat (fn [[attr {:keys [main branch]}]]
|
||||
(mapcat (fn [[attr {:keys [source branch]}]]
|
||||
(case attr
|
||||
:shapes [:shapes-group]
|
||||
:applied-tokens (filter #(not= (get main %) (get branch %))
|
||||
(set/union (set (keys main)) (set (keys branch))))
|
||||
:applied-tokens (filter #(not= (get source %) (get branch %))
|
||||
(set/union (set (keys source)) (set (keys branch))))
|
||||
(some-> (ctk/resolve-sync-group shape-type attr) vector))))
|
||||
changed-attrs))
|
||||
|
||||
@ -1954,7 +1956,7 @@
|
||||
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?]
|
||||
(let [update? (= dir :main->branch)
|
||||
(let [update? (= dir :source->branch)
|
||||
[theirs ours] (if update? [branch main] [main branch])
|
||||
results [(three-way-entities (strip-modified-at (:colors base))
|
||||
(strip-modified-at (:colors theirs))
|
||||
@ -1987,8 +1989,8 @@
|
||||
(diff-tokens base theirs ours)]
|
||||
{:keys [changes conflicts]} (merge-results results)
|
||||
;; the engine reports `ours`' changes against `theirs` and labels
|
||||
;; those roles `:main`/`:branch`; the summary names the DOCUMENTS,
|
||||
;; so `:main->branch` (theirs=branch, ours=main) is renamed here
|
||||
;; those roles `:source`/`:branch`; the summary names the DOCUMENTS,
|
||||
;; so `:source->branch` (theirs=branch, ours=source) is renamed here
|
||||
;; (see `doc-sides`)
|
||||
changes (if update? (mapv doc-sides changes) changes)
|
||||
conflicts (if update? (mapv doc-sides conflicts) conflicts)
|
||||
@ -2028,14 +2030,14 @@
|
||||
:stats {:added n :modified n :deleted n :conflicts n}
|
||||
:copies [<component copies> ...]} ; with `:copies? true` only
|
||||
|
||||
Every entry names the two DOCUMENTS, whatever `dir`: `:main` carries
|
||||
main's value, `:branch` the branch's, and each `:changed-attrs` pair
|
||||
(`attribute -> {:main v :branch v}`) says the same. The two delete
|
||||
reasons do not flip with `dir` either: `:delete-modify` names the
|
||||
branch's deletion against main's modification, `:modify-delete` the
|
||||
branch's modification against main's deletion. The `:changes` do follow
|
||||
`dir` — `:branch->main` reports the branch's outgoing changes,
|
||||
`:main->branch` main's incoming ones.
|
||||
Every entry names the two DOCUMENTS, whatever `dir`: `:source` carries
|
||||
the source's value, `:branch` the branch's, and each `:changed-attrs`
|
||||
pair (`attribute -> {:source v :branch v}`) says the same. The two
|
||||
delete reasons do not flip with `dir` either: `:delete-modify` names the
|
||||
branch's deletion against the source's modification, `:modify-delete`
|
||||
the branch's modification against the source's deletion. The `:changes`
|
||||
do follow `dir`: `:branch->source` reports the branch's outgoing
|
||||
changes, `:source->branch` the source's incoming ones.
|
||||
|
||||
`opts` may carry `:copies? true`, which adds `:copies` and each
|
||||
conflict's `:copies-affected` (below): the scan it takes reads every
|
||||
@ -2071,7 +2073,7 @@
|
||||
|
||||
with `r` one of `:follows-component` (no side overrode it: the target
|
||||
keeps its value until the sync sets the component's, so `s` names the
|
||||
target), `:override-main` and `:override-branch`. `:applied-tokens`
|
||||
target), `:override-source` and `:override-branch`. `:applied-tokens`
|
||||
shows through its slots, and is among `:open-attrs` exactly when a
|
||||
slot is open. A `:settled` entry applies nothing: it counts
|
||||
in no `:stats`, `compute-changes` and `nothing-to-merge?` ignore it,
|
||||
@ -2147,7 +2149,7 @@
|
||||
|
||||
Clean (non-conflicting) changes are always emitted. Conflicting
|
||||
entities are emitted only when `resolutions` selects `:branch` for that
|
||||
id (taking the branch side); `:main` (or absent) leaves main untouched.
|
||||
id (taking the branch side); `:source` (or absent) leaves the source untouched.
|
||||
The caller is responsible for refusing the merge while conflicts remain
|
||||
unresolved."
|
||||
[base theirs ours resolutions add-fn mod-fn del-fn]
|
||||
@ -2520,7 +2522,7 @@
|
||||
(filterv some?))
|
||||
|
||||
;; the ids the merge deletes. `:dropped :conflict` resolved to
|
||||
;; `:main` keeps the container's whole subtree as the target has
|
||||
;; `:source` keeps the container's whole subtree as the target has
|
||||
;; it, so no delete inside it is emitted
|
||||
deleted (into #{} (keep (fn [{:keys [type id]}]
|
||||
(when (= :del-obj type) id)))
|
||||
@ -2529,7 +2531,7 @@
|
||||
(source-deleted-roots to deleted))
|
||||
kept (when (= :conflict dropped-mode)
|
||||
(into #{} (mapcat #(preorder-ids to %))
|
||||
(filter #(= :main (get resolutions %)) dropped-roots)))
|
||||
(filter #(= :source (get resolutions %)) dropped-roots)))
|
||||
mod-del (if (seq kept)
|
||||
(filterv (fn [{:keys [type id]}]
|
||||
(not (and (= :del-obj type) (contains? kept id))))
|
||||
@ -2738,7 +2740,7 @@
|
||||
([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->main))
|
||||
(let [merge-summary (or merge-summary (compute-merge base main 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
|
||||
@ -2939,7 +2941,7 @@
|
||||
;; shapes: the tree-shape policies act per page (see
|
||||
;; `page-shape-changes`); its `:unsupported` entries name the
|
||||
;; container a `:refuse` alternative could not place under
|
||||
dir (or (:dir merge-summary) :branch->main)
|
||||
dir (or (:dir merge-summary) :branch->source)
|
||||
shapes-res (mapv (fn [pid] (page-shape-changes base main branch resolutions pid dir excluded))
|
||||
common-pages)
|
||||
shapes (into [] (mapcat :changes) shapes-res)
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
"What the saves of a branch under design review did to its layers.
|
||||
|
||||
The backend records one row per branch save while a review is open
|
||||
(`file_pull_request_activity`). `entries` builds that row from the
|
||||
(`file_branch_review_activity`). `entries` builds that row from the
|
||||
change vector of the save and the file data before and after it: one
|
||||
entry per touched layer, with the kind of change and, for a modified
|
||||
layer, the value before and after of each property a person reads.
|
||||
|
||||
@ -206,10 +206,16 @@
|
||||
:export-link-later
|
||||
|
||||
;; Enables file branching: isolated file copies ("branches") that
|
||||
;; can be merged back to their source file, including pull requests
|
||||
;; can be merged back to their source file, including design reviews
|
||||
;; (review requests over a pinned snapshot of a branch). Disabled by
|
||||
;; default.
|
||||
:branching})
|
||||
:branching
|
||||
|
||||
;; Lets a branch be cut from another branch. A merge into the parent
|
||||
;; then lands in the parent's op log, and a merged parent hands its
|
||||
;; open children to its own target. Requires `:branching`. Disabled
|
||||
;; by default.
|
||||
:branch-stacking})
|
||||
|
||||
(def all-flags
|
||||
(set/union email login varia))
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
|
||||
(t/deftest identity-no-changes
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}})
|
||||
r (bm/compute-merge base base base :branch->main)]
|
||||
r (bm/compute-merge base base base :branch->source)]
|
||||
(t/is (= [] (:changes r)))
|
||||
(t/is (= [] (:conflicts r)))
|
||||
(t/is (= {:added 0 :modified 0 :deleted 0 :conflicts 0} (:stats r)))))
|
||||
@ -50,7 +50,7 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A"}})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A"}
|
||||
:s2 {:id :s2 :name "B"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (filter #(= :added (:status %)) (:changes r)))]
|
||||
(t/is (= 1 (-> r :stats :added)))
|
||||
(t/is (= 0 (-> r :stats :conflicts)))
|
||||
@ -62,11 +62,11 @@
|
||||
(t/deftest modified-in-branch
|
||||
(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->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))]
|
||||
(t/is (= 1 (-> r :stats :modified)))
|
||||
(t/is (= :modified (:status c)))
|
||||
(t/is (= {:main "red" :branch "blue"} (get-in c [:changed-attrs :fill])))))
|
||||
(t/is (= {:source "red" :branch "blue"} (get-in c [:changed-attrs :fill])))))
|
||||
|
||||
(t/deftest root-frame-and-shapes-churn-hidden
|
||||
;; adding a top-level shape mutates the root frame's `:shapes`; that churn
|
||||
@ -76,7 +76,7 @@
|
||||
branch (mkdata {uuid/zero {:id uuid/zero :name "Root Frame" :shapes [:s1 :s2]}
|
||||
:s1 {:id :s1 :name "A"}
|
||||
:s2 {:id :s2 :name "B"}})
|
||||
r (bm/compute-merge base base branch :branch->main)]
|
||||
r (bm/compute-merge base base branch :branch->source)]
|
||||
(t/is (= #{:s2} (set (map :id (:changes r)))))
|
||||
(t/is (= 1 (-> r :stats :added)))
|
||||
(t/is (= 0 (-> r :stats :modified)))))
|
||||
@ -89,7 +89,7 @@
|
||||
(binding [bm/*policies* (assoc bm/default-policies :same-parent-reorder :ignore)]
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :shapes [:c1 :c2]}})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :shapes [:c2 :c1]}})
|
||||
r (bm/compute-merge base base branch :branch->main)]
|
||||
r (bm/compute-merge base base branch :branch->source)]
|
||||
(t/is (= [] (:changes r)))
|
||||
(t/is (= 0 (-> r :stats :modified)))
|
||||
(t/is (= [] (:changes (bm/compute-changes base base branch)))))))
|
||||
@ -105,7 +105,7 @@
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"
|
||||
:parent-id :new :frame-id :new
|
||||
:selrect {:x 9} :points [3 4] :shapes [:c1 :c2]}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))
|
||||
chg (bm/compute-changes base base branch)
|
||||
ops (->> (:changes chg)
|
||||
@ -133,7 +133,7 @@
|
||||
branch (mkdata {:t1 {:id :t1 :name "Text" :type :text
|
||||
:parent-id :board :frame-id :board}
|
||||
:board {:id :board :name "Board" :type :frame :shapes [:t1]}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
moved (first (filter #(and (= :modified (:status %)) (= :t1 (:id %))) (:changes r)))]
|
||||
(t/is (some? moved))
|
||||
(t/is (contains? (:changed-attrs moved) :frame-id))))
|
||||
@ -146,7 +146,7 @@
|
||||
:r1 {:id :r1 :name "Box" :type :rect}
|
||||
:c1 {:id :c1 :name "Btn" :type :frame
|
||||
:component-id (uuid/random) :main-instance true}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
by-id (into {} (map (juxt :id identity)) (:changes r))]
|
||||
(t/is (= :text (get-in by-id [:t1 :shape-type])))
|
||||
(t/is (= :rect (get-in by-id [:r1 :shape-type])))
|
||||
@ -155,7 +155,7 @@
|
||||
(t/deftest deleted-in-branch
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A"} :s2 {:id :s2 :name "B"}})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))]
|
||||
(t/is (= 1 (-> r :stats :deleted)))
|
||||
(t/is (= :deleted (:status c)))
|
||||
@ -169,9 +169,9 @@
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :selrect {:x 1}}
|
||||
:s3 {:id :s3 :name "C" :selrect {:x 3}}})
|
||||
merge (into {} (map (juxt :id identity))
|
||||
(:changes (bm/compute-merge base base branch :branch->main)))
|
||||
(:changes (bm/compute-merge base base branch :branch->source)))
|
||||
update (into {} (map (juxt :id identity))
|
||||
(:changes (bm/compute-merge base branch base :main->branch)))]
|
||||
(:changes (bm/compute-merge base branch base :source->branch)))]
|
||||
(t/is (= {:id :s2 :name "B" :selrect {:x 2}} (get-in merge [:s2 :shape])))
|
||||
(t/is (= {:id :s3 :name "C" :selrect {:x 3}} (get-in merge [:s3 :shape])))
|
||||
(t/is (= {:id :s2 :name "B" :selrect {:x 2}} (get-in update [:s2 :shape])))
|
||||
@ -183,9 +183,9 @@
|
||||
[:pages-index :p1 :flows] {:f1 flow})
|
||||
branch (assoc-in base [:pages-index :p1 :flows] {})
|
||||
merge (first (filter #(= :page-flow (:kind %))
|
||||
(:changes (bm/compute-merge base base branch :branch->main))))
|
||||
(:changes (bm/compute-merge base base branch :branch->source))))
|
||||
update (first (filter #(= :page-flow (:kind %))
|
||||
(:changes (bm/compute-merge base branch base :main->branch))))]
|
||||
(:changes (bm/compute-merge base branch base :source->branch))))]
|
||||
(t/is (= :deleted (:status merge)))
|
||||
(t/is (= flow (:flow merge)))
|
||||
(t/is (= :deleted (:status update)))
|
||||
@ -194,14 +194,14 @@
|
||||
(t/deftest modified-carries-no-shape
|
||||
(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->main)]
|
||||
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
|
||||
(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->main)]
|
||||
r (bm/compute-merge base base branch :branch->source)]
|
||||
(t/is (= 0 (-> r :stats :conflicts)))
|
||||
(t/is (= 1 (-> r :stats :modified)))))
|
||||
|
||||
@ -209,7 +209,7 @@
|
||||
;; 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->main)]
|
||||
r (bm/compute-merge base main base :branch->source)]
|
||||
(t/is (= [] (:changes r)))
|
||||
(t/is (= 0 (-> r :stats :conflicts)))))
|
||||
|
||||
@ -217,11 +217,11 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}})
|
||||
main (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->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
cf (first (:conflicts r))]
|
||||
(t/is (= 1 (-> r :stats :conflicts)))
|
||||
(t/is (= :modify-modify (:reason cf)))
|
||||
(t/is (= "green" (get-in cf [:changed-attrs :fill :main])))
|
||||
(t/is (= "green" (get-in cf [:changed-attrs :fill :source])))
|
||||
(t/is (= "blue" (get-in cf [:changed-attrs :fill :branch])))))
|
||||
|
||||
(t/deftest delete-modify-conflict
|
||||
@ -229,7 +229,7 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}})
|
||||
main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}})
|
||||
branch (mkdata {})
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
cf (first (:conflicts r))]
|
||||
(t/is (= 1 (-> r :stats :conflicts)))
|
||||
(t/is (= :delete-modify (:reason cf)))))
|
||||
@ -237,7 +237,7 @@
|
||||
(t/deftest color-added-in-branch
|
||||
(let [base (mkdata {} :colors {})
|
||||
branch (mkdata {} :colors {:c1 {:id :c1 :name "Primary"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (filter #(= :color (:kind %)) (:changes r)))]
|
||||
(t/is (= :added (:status c)))
|
||||
(t/is (= "Primary" (:label c)))))
|
||||
@ -257,7 +257,7 @@
|
||||
(let [cid (uuid/random)
|
||||
base (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t0"}})
|
||||
branch (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t1"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
{:keys [changes unsupported]} (bm/compute-changes base base branch)]
|
||||
(t/is (= [] (:changes r)))
|
||||
(t/is (= [] (:conflicts r)))
|
||||
@ -272,7 +272,7 @@
|
||||
base (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t0"}})
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= [] (:conflicts r)))
|
||||
(t/is (= 0 (-> r :stats :conflicts)))))
|
||||
|
||||
@ -282,10 +282,10 @@
|
||||
(let [cid (uuid/random)
|
||||
base (comp-data {cid {:id cid :name "Button" :path "" :modified-at "t0"}})
|
||||
branch (comp-data {cid {:id cid :name "Primary Button" :path "" :modified-at "t1"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (filter #(= :component (:kind %)) (:changes r)))]
|
||||
(t/is (= :modified (:status c)))
|
||||
(t/is (= {:main "Button" :branch "Primary Button"} (get-in c [:changed-attrs :name])))
|
||||
(t/is (= {:source "Button" :branch "Primary Button"} (get-in c [:changed-attrs :name])))
|
||||
(t/is (not (contains? (:changed-attrs c) :modified-at)))))
|
||||
|
||||
;; --- compute-changes (merge -> change maps)
|
||||
@ -470,7 +470,7 @@
|
||||
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 :main})]
|
||||
(let [{:keys [changes]} (bm/compute-changes base main 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 {})]
|
||||
@ -486,13 +486,13 @@
|
||||
;; --- per-property (per-attr) conflict resolution
|
||||
|
||||
(t/deftest conflict-resolved?-predicate
|
||||
(let [cf {:changed-attrs {:fill {:main "g" :branch "b"}
|
||||
:rx {:main 0 :branch 8}}}]
|
||||
(let [cf {:changed-attrs {:fill {:source "g" :branch "b"}
|
||||
:rx {:source 0 :branch 8}}}]
|
||||
;; whole-entity keyword always resolves
|
||||
(t/is (true? (bm/conflict-resolved? cf :main)))
|
||||
(t/is (true? (bm/conflict-resolved? cf :source)))
|
||||
(t/is (true? (bm/conflict-resolved? cf :branch)))
|
||||
;; a full per-attr map resolves
|
||||
(t/is (true? (bm/conflict-resolved? cf {:fill :branch :rx :main})))
|
||||
(t/is (true? (bm/conflict-resolved? cf {:fill :branch :rx :source})))
|
||||
;; a partial map does not
|
||||
(t/is (false? (bm/conflict-resolved? cf {:fill :branch})))
|
||||
;; nil / empty map do not
|
||||
@ -507,7 +507,7 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red" :rx 0}})
|
||||
main (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 :main}})
|
||||
{:keys [changes]} (bm/compute-changes base main branch {:s1 {:fill :branch :rx :source}})
|
||||
ops (-> (group-by :type changes) :mod-obj first :operations)]
|
||||
(t/is (= [{:type :set :attr :fill :val "blue"}] ops))))
|
||||
|
||||
@ -531,7 +531,7 @@
|
||||
(let [base (mkdata {} :colors {:c1 {:id :c1 :name "A" :opacity 1}})
|
||||
main (mkdata {} :colors {:c1 {:id :c1 :name "Main" :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 :main}})
|
||||
{:keys [changes]} (bm/compute-changes base main 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)))))
|
||||
@ -759,7 +759,7 @@
|
||||
(t/deftest compute-merge-file-plugin-data
|
||||
(let [base (file-level-data)
|
||||
branch (file-level-data :plugin-data {:my-plugin {"foo" "bar"}})
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))]
|
||||
(t/is (= {:added 1 :modified 0 :deleted 0 :conflicts 0} (:stats r)))
|
||||
(t/is (= :file-plugin (:kind c)))
|
||||
@ -768,7 +768,7 @@
|
||||
(t/deftest compute-merge-file-base-font-size
|
||||
(let [base (file-level-data :base-font-size "16px")
|
||||
branch (file-level-data :base-font-size "20px")
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))]
|
||||
(t/is (= {:added 0 :modified 1 :deleted 0 :conflicts 0} (:stats r)))
|
||||
(t/is (= :file-option (:kind c)))
|
||||
@ -777,18 +777,18 @@
|
||||
(t/deftest compute-merge-file-base-font-size-absent-is-the-default
|
||||
(let [base (file-level-data)
|
||||
branch (file-level-data :base-font-size "16px")]
|
||||
(t/is (empty? (:changes (bm/compute-merge base base branch :branch->main))))))
|
||||
(t/is (empty? (:changes (bm/compute-merge base base branch :branch->source))))))
|
||||
|
||||
(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")
|
||||
branch (file-level-data :plugin-data {:my-plugin {"foo" "c"}} :base-font-size "20px")
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main 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)))
|
||||
(t/is (= #{["b" "c"] ["18px" "20px"]}
|
||||
(set (map (juxt :main :branch) (:conflicts r)))))))
|
||||
(set (map (juxt :source :branch) (:conflicts r)))))))
|
||||
|
||||
(t/deftest compute-changes-file-plugin-data
|
||||
(let [base (file-level-data :plugin-data {:my-plugin {"gone" "x"}})
|
||||
@ -831,7 +831,7 @@
|
||||
(t/deftest compute-changes-file-level-update-from-main
|
||||
(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 :main->branch)
|
||||
r (bm/compute-merge base main base :source->branch)
|
||||
data' (cfc/process-changes base (:changes (bm/compute-changes base base main {} r)))]
|
||||
(t/is (= 2 (count (:changes r))))
|
||||
(t/is (= "bar" (get-in data' [:plugin-data :my-plugin "foo"])))
|
||||
@ -853,7 +853,7 @@
|
||||
(t/deftest compute-merge-tokens-source-one-side
|
||||
(let [base (source-data nil)
|
||||
branch (source-data lib-a)
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
c (first (:changes r))]
|
||||
(t/is (= {:added 0 :modified 1 :deleted 0 :conflicts 0} (:stats r)))
|
||||
(t/is (= :tokens-source (:kind c)))
|
||||
@ -877,14 +877,14 @@
|
||||
(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->main))))
|
||||
(t/is (empty? (:changes (bm/compute-merge base main base :branch->source))))
|
||||
(t/is (empty? (:changes (bm/compute-changes base main 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)]
|
||||
(t/is (empty? (:changes (bm/compute-merge base base branch :branch->main))))
|
||||
(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
|
||||
@ -902,15 +902,15 @@
|
||||
(let [base (source-data nil)
|
||||
main (source-data lib-a)
|
||||
branch (source-data lib-b)
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
c (first (:conflicts r))
|
||||
apply* (fn [resolutions]
|
||||
(:tokens-source
|
||||
(cfc/process-changes main (:changes (bm/compute-changes base main branch resolutions)))))]
|
||||
(t/is (= 1 (-> r :stats :conflicts)))
|
||||
(t/is (= {:kind :tokens-source :id :tokens-source :reason :modify-modify
|
||||
:base nil :main lib-a :branch lib-b}
|
||||
(select-keys c [:kind :id :reason :base :main :branch])))
|
||||
: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/is (= lib-a (apply* {}))))
|
||||
@ -920,7 +920,7 @@
|
||||
(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 :main->branch)
|
||||
r (bm/compute-merge base main base :source->branch)
|
||||
{:keys [changes unsupported]} (bm/compute-changes base base main {} r)]
|
||||
(t/is (= [:tokens-source] (map :kind (:changes r))))
|
||||
(t/is (empty? unsupported))
|
||||
@ -1066,7 +1066,7 @@
|
||||
(filterv #(= :set-tokens-status (:type %))
|
||||
(:changes (bm/compute-changes base main branch resolutions))))]
|
||||
(t/is (= #{:token-active-themes :token-active-sets}
|
||||
(set (map :kind (:conflicts (bm/compute-merge base main branch :branch->main))))))
|
||||
(set (map :kind (:conflicts (bm/compute-merge base main branch :branch->source))))))
|
||||
(t/is (= [] (status-changes {})) "an unresolved conflict keeps main's status")
|
||||
(t/is (= [{:type :set-tokens-status :theme-ids #{th-b} :set-ids #{sid-b}}]
|
||||
(status-changes {:active-themes :branch :active-sets :branch})))))
|
||||
@ -1084,7 +1084,7 @@
|
||||
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->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= [] (:conflicts r)))
|
||||
(t/is (= #{:b} (set (map :id (:changes r)))))))
|
||||
|
||||
@ -1094,7 +1094,7 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :touched nil}})
|
||||
main (mkdata {:s1 {:id :s1 :name "A" :touched #{:fill-group}}})
|
||||
branch (mkdata {})
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= [] (:conflicts r)))
|
||||
(t/is (= [:deleted] (mapv :status (:changes r))))))
|
||||
|
||||
@ -1108,7 +1108,7 @@
|
||||
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->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->source)
|
||||
{:keys [changes]} (bm/compute-changes base main branch {:f1 :branch})
|
||||
adds (into {} (comp (filter #(= :add-obj (:type %)))
|
||||
(map (juxt :id identity)))
|
||||
@ -1123,11 +1123,11 @@
|
||||
(t/is (= "Frame RENAMED" (get-in adds [:f1 :obj :name])))))
|
||||
|
||||
(t/deftest compute-changes-modify-delete-resolved-main-drops-shape
|
||||
;; same conflict resolved to :main -> nothing is re-added
|
||||
;; same conflict resolved to :source -> nothing is re-added
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A"}})
|
||||
main (mkdata {})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A2"}})
|
||||
{:keys [changes]} (bm/compute-changes base main branch {:s1 :main})]
|
||||
{:keys [changes]} (bm/compute-changes base main branch {:s1 :source})]
|
||||
(t/is (= [] (filterv #(= :add-obj (:type %)) changes)))))
|
||||
|
||||
;;; --- Regression tests: order resolution ids ---
|
||||
@ -1142,7 +1142,7 @@
|
||||
base (pages-data pi [p1 p2 p3])
|
||||
main (pages-data pi [p2 p1 p3])
|
||||
branch (pages-data pi [p3 p1 p2])
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->source)
|
||||
conflict (first (filter #(= :page-order (:kind %)) conflicts))
|
||||
{:keys [changes]} (bm/compute-changes base main branch {:page-order :branch})]
|
||||
(t/is (= :page-order (:id conflict)))
|
||||
@ -1162,7 +1162,7 @@
|
||||
base (mk {:id p2 :name "P2" :objects {}})
|
||||
main (mk {:id p2 :name "P2" :objects {s1 {:id s1 :name "New"}}})
|
||||
branch (mk nil)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->source)
|
||||
conflict (first (filter #(= :page (:kind %)) conflicts))]
|
||||
(t/is (some? conflict))
|
||||
(t/is (= :delete-modify (:reason conflict)))
|
||||
@ -1170,8 +1170,8 @@
|
||||
;; resolved to :branch -> the page is deleted
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {p2 :branch})]
|
||||
(t/is (= [p2] (mapv :id (filter #(= :del-page (:type %)) changes)))))
|
||||
;; resolved to :main -> the page is kept, nothing emitted for it
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {p2 :main})]
|
||||
;; resolved to :source -> the page is kept, nothing emitted for it
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {p2 :source})]
|
||||
(t/is (= [] (filterv #(= :del-page (:type %)) changes))))))
|
||||
|
||||
(t/deftest page-deleted-in-main-edited-in-branch-restores
|
||||
@ -1182,7 +1182,7 @@
|
||||
base (pages-data (pi-with {}) [p1 p2])
|
||||
main (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->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main 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
|
||||
@ -1198,7 +1198,7 @@
|
||||
p2 {:id p2 :name "P2" :objects {}}}
|
||||
base (pages-data pi [p1 p2])
|
||||
branch (pages-data {p1 {:id p1 :name "P1" :objects {}}} [p1])
|
||||
{:keys [conflicts]} (bm/compute-merge base base branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base base branch :branch->source)
|
||||
{:keys [changes]} (bm/compute-changes base base branch)]
|
||||
(t/is (= [] conflicts))
|
||||
(t/is (= [p2] (mapv :id (filter #(= :del-page (:type %)) changes))))))
|
||||
@ -1215,16 +1215,16 @@
|
||||
base (with-tokens base-lib)
|
||||
main (with-tokens main-lib)
|
||||
branch (with-tokens branch-lib)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main 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 :main -> set (and token) kept
|
||||
;; resolved to :branch -> set deleted; to :source -> set (and token) kept
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {sid :branch})]
|
||||
(t/is (some #(and (= :set-token-set (:type %)) (nil? (:attrs %))) changes)))
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {sid :main})]
|
||||
(let [{:keys [changes]} (bm/compute-changes base main branch {sid :source})]
|
||||
(t/is (= [] (filterv #(= :set-token-set (:type %)) changes)))
|
||||
(t/is (= [] (filterv #(= :set-token (:type %)) changes))))))
|
||||
|
||||
@ -1237,7 +1237,7 @@
|
||||
base (with-tokens base-lib)
|
||||
main (with-tokens main-lib)
|
||||
branch (with-tokens branch-lib)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main 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
|
||||
@ -1258,7 +1258,7 @@
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :x 100
|
||||
:selrect {:x 100} :points [{:x 100}]}})
|
||||
{:keys [changes]} (bm/compute-changes base main branch
|
||||
{:s1 {:x :branch :name :main}})
|
||||
{:s1 {:x :branch :name :source}})
|
||||
ops (->> changes
|
||||
(filter #(= :mod-obj (:type %)))
|
||||
first :operations
|
||||
@ -1278,32 +1278,32 @@
|
||||
base (mkdata {:s1 (mk "A")})
|
||||
main (mkdata {:s1 (mk "MAIN")})
|
||||
branch (mkdata {:s1 (mk "BRANCH")})
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->source)
|
||||
c (first conflicts)]
|
||||
(t/is (= :modify-modify (:reason c)))
|
||||
;; changed-attrs stay noise-free (no derived attrs)
|
||||
(t/is (= #{:name} (set (keys (:changed-attrs c)))))
|
||||
;; but every side carries the full shape, caches included
|
||||
(t/is (= selrect (get-in c [:base :selrect])))
|
||||
(t/is (= selrect (get-in c [:main :selrect])))
|
||||
(t/is (= selrect (get-in c [:source :selrect])))
|
||||
(t/is (= selrect (get-in c [:branch :selrect])))
|
||||
(t/is (= "MAIN" (get-in c [:main :name])))
|
||||
(t/is (= "MAIN" (get-in c [:source :name])))
|
||||
(t/is (= "BRANCH" (get-in c [:branch :name])))))
|
||||
|
||||
(t/deftest main->branch-conflict-sides-name-the-documents
|
||||
;; A conflict descriptor names the DOCUMENTS in both directions: `:main`
|
||||
(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`
|
||||
;; pairs included.
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}})
|
||||
main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}})
|
||||
r (bm/compute-merge base main branch :main->branch)
|
||||
r (bm/compute-merge base main branch :source->branch)
|
||||
c (first (:conflicts r))]
|
||||
(t/is (= 1 (-> r :stats :conflicts)))
|
||||
(t/is (= :modify-modify (:reason c)))
|
||||
(t/is (= "green" (get-in c [:main :fill])))
|
||||
(t/is (= "green" (get-in c [:source :fill])))
|
||||
(t/is (= "blue" (get-in c [:branch :fill])))
|
||||
(t/is (= {:main "green" :branch "blue"} (get-in c [:changed-attrs :fill])))))
|
||||
(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
|
||||
@ -1312,20 +1312,20 @@
|
||||
(let [base (mkdata {:s1 {:id :s1 :name "A" :fill "red"}})
|
||||
main (mkdata {:s1 {:id :s1 :name "A" :fill "green"}})
|
||||
branch (mkdata {})
|
||||
r (bm/compute-merge base main branch :main->branch)
|
||||
r (bm/compute-merge base main 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 [:main :fill])))
|
||||
(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 {})
|
||||
branch (mkdata {:s1 {:id :s1 :name "A" :fill "blue"}})
|
||||
r (bm/compute-merge base main branch :main->branch)
|
||||
r (bm/compute-merge base main branch :source->branch)
|
||||
c (first (:conflicts r))]
|
||||
(t/is (= 1 (-> r :stats :conflicts)))
|
||||
(t/is (= :modify-delete (:reason c)))
|
||||
(t/is (nil? (:main c)))
|
||||
(t/is (nil? (:source c)))
|
||||
(t/is (= "blue" (get-in c [:branch :fill])))))
|
||||
|
||||
(t/deftest remap-changes-rewrites-a-del-media-id
|
||||
@ -1424,25 +1424,25 @@
|
||||
(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"])
|
||||
branch (tree-edit base assoc-in [f :shapes] [b a])
|
||||
r (bm/compute-merge base base branch :branch->main)
|
||||
r (bm/compute-merge base base branch :branch->source)
|
||||
entry (first (:changes r))
|
||||
{:keys [data unsupported]} (merged base base branch {})]
|
||||
(t/is (= 1 (-> r :stats :modified)))
|
||||
(t/is (= [f] (mapv :id (:changes r))))
|
||||
(t/is (= {:main [a b] :branch [b a]} (get-in entry [:changed-attrs :shapes])))
|
||||
(t/is (= {:source [a b] :branch [b a]} (get-in entry [:changed-attrs :shapes])))
|
||||
(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->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= [] (:conflicts r)))
|
||||
(t/is (= [b a m] (tree-children (:data (merged base main 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 :main->branch)]
|
||||
(t/is (= {:main [b a] :branch [a b]}
|
||||
r (bm/compute-merge base main 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)))))))
|
||||
|
||||
@ -1453,12 +1453,12 @@
|
||||
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])
|
||||
branch (tree-edit base assoc-in [f :shapes] [b a c])
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->main)
|
||||
{:keys [conflicts]} (bm/compute-merge base main branch :branch->source)
|
||||
cf (first conflicts)]
|
||||
(t/is (= [[f :modify-modify]] (mapv (juxt :id :reason) conflicts)))
|
||||
(t/is (= {:main [c a b] :branch [b a c]} (get-in cf [:changed-attrs :shapes])))
|
||||
(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 :main})) 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/deftest same-parent-reorder-refuse
|
||||
@ -1468,7 +1468,7 @@
|
||||
(let [f (uuid/next) a (uuid/next) b (uuid/next)
|
||||
base (tree-data [f nil :frame "F"] [a f :rect "A"] [b f :rect "B"])
|
||||
branch (tree-edit base assoc-in [f :shapes] [b a])
|
||||
r (bm/compute-merge base base branch :branch->main)]
|
||||
r (bm/compute-merge base base 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-order :status :unsupported :id f :page-id (tree-page-id base)
|
||||
@ -1483,7 +1483,7 @@
|
||||
(let [f (uuid/next) a (uuid/next) b (uuid/next)
|
||||
base (tree-data [f nil :frame "F"] [a f :rect "A"] [b f :rect "B"])
|
||||
branch (tree-edit base assoc-in [f :shapes] [b a])
|
||||
r (bm/compute-merge base base branch :branch->main)]
|
||||
r (bm/compute-merge base base branch :branch->source)]
|
||||
(t/is (= {:added 0 :modified 0 :deleted 0 :conflicts 0} (:stats r)))
|
||||
(t/is (= [a b] (tree-children (:data (merged base base branch {})) f))))))
|
||||
|
||||
@ -1504,12 +1504,12 @@
|
||||
(t/deftest addition-under-deleted-parent-conflict
|
||||
;; ws1: main 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, `:main` drops M.
|
||||
;; 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)
|
||||
branch (tree-add base m p :rect "M")
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main 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)))
|
||||
@ -1519,7 +1519,7 @@
|
||||
(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 :main})))]
|
||||
(let [objs (tree-objects (:data (merged base main branch {p :source})))]
|
||||
(t/is (= #{uuid/zero} (set (keys objs)))))))
|
||||
|
||||
(t/deftest addition-under-deleted-parent-conflict-lifts-restores
|
||||
@ -1530,7 +1530,7 @@
|
||||
base (tree-data [p nil :frame "P"] [c p :rect "C"])
|
||||
main (tree-delete base p)
|
||||
branch (tree-edit base assoc-in [c :name] "C renamed")
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main 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})))]
|
||||
@ -1546,7 +1546,7 @@
|
||||
base (tree-data [p nil :frame "P"] [c p :rect "C"])
|
||||
main (tree-delete base p)
|
||||
branch (tree-add base m p :rect "M")
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main 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)
|
||||
@ -1556,9 +1556,9 @@
|
||||
(t/is (= #{:shape-orphan} (:unsupported (bm/compute-changes base main 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->main)))))
|
||||
(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 :main}))))))))
|
||||
(t/is (empty? (:unsupported (bm/compute-changes base main branch {c :source}))))))))
|
||||
|
||||
(t/deftest addition-under-deleted-parent-reparent-to-ancestor
|
||||
;; `:reparent-to-ancestor`: main deletes P inside board G; the branch's
|
||||
@ -1568,7 +1568,7 @@
|
||||
base (tree-data [g nil :frame "G"] [h g :rect "H"] [p g :frame "P"] [c p :rect "C"])
|
||||
main (tree-delete base p)
|
||||
branch (tree-add base m p :rect "M")
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
{:keys [data unsupported]} (merged base main branch {})
|
||||
objs (tree-objects data)]
|
||||
(t/is (= [] (:conflicts r)))
|
||||
@ -1589,7 +1589,7 @@
|
||||
main (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->main))))
|
||||
(t/is (= [] (:conflicts (bm/compute-merge base main branch :branch->source))))
|
||||
(t/is (= [m] (get-in objs [uuid/zero :shapes])))
|
||||
(t/is (= uuid/zero (get-in objs [m :parent-id]))))))
|
||||
|
||||
@ -1606,14 +1606,14 @@
|
||||
{:f f :c c :d d :n n :k k :base base :main main :branch branch}))
|
||||
|
||||
(t/deftest container-delete-over-main-edits-conflict
|
||||
;; default `:conflict`: one `:delete-modify` conflict on F. `:main` keeps
|
||||
;; 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->main)]
|
||||
r (bm/compute-merge base main 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 :main})))]
|
||||
(let [objs (tree-objects (:data (merged base main 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]))))
|
||||
@ -1622,14 +1622,14 @@
|
||||
|
||||
(t/deftest container-delete-over-main-edits-expand
|
||||
;; `:expand`: only what the branch deleted goes; main's addition N, and
|
||||
;; C when its conflict is resolved to `:main`, move to F's parent where
|
||||
;; 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->main)]
|
||||
r (bm/compute-merge base main 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 :main})))]
|
||||
(let [objs (tree-objects (:data (merged base main 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])))
|
||||
@ -1641,10 +1641,10 @@
|
||||
;; `: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->main)]
|
||||
r (bm/compute-merge base main 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 :main})))]
|
||||
(let [objs (tree-objects (:data (merged base main branch {c :source})))]
|
||||
(t/is (= #{uuid/zero k} (set (keys objs))))))))
|
||||
|
||||
;;; --- Regression tests: mov-page indexes ---
|
||||
@ -1776,7 +1776,7 @@
|
||||
(mkdata {})
|
||||
(mkdata {})
|
||||
(mkdata {id {:id id :name "A"}})
|
||||
:branch->main)))))))))
|
||||
:branch->source)))))))))
|
||||
|
||||
(t/deftest excluded-clean-change-is-not-emitted
|
||||
(let [a (uuid/next) b (uuid/next)
|
||||
@ -1801,14 +1801,14 @@
|
||||
(let [a (uuid/next)
|
||||
base (tree-data [a nil :rect "A"])
|
||||
branch (tree-edit base assoc-in [a :name] "A2")
|
||||
summary (bm/compute-merge base base branch :branch->main)
|
||||
summary (bm/compute-merge base base branch :branch->source)
|
||||
ka (bm/change-key {:kind :shape :page-id (uuid/custom 7 1) :id a})]
|
||||
(t/is (seq (:changes summary)))
|
||||
(t/is (bm/nothing-to-merge? summary #{ka}))
|
||||
(t/is (not (bm/nothing-to-merge? summary #{})))
|
||||
(t/is (not (bm/nothing-to-merge? summary #{(str ka "-stale")})))
|
||||
(t/testing "a summary with no entries is not a refusal: the merge closes the branch"
|
||||
(t/is (not (bm/nothing-to-merge? (bm/compute-merge base base base :branch->main) #{}))))))
|
||||
(t/is (not (bm/nothing-to-merge? (bm/compute-merge base base base :branch->source) #{}))))))
|
||||
|
||||
(t/deftest excluded-conflict-resolves-to-the-target
|
||||
(let [a (uuid/next)
|
||||
@ -1817,7 +1817,7 @@
|
||||
main (tree-edit base assoc-in [a :name] "main")
|
||||
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->main)))))
|
||||
(t/is (= 1 (count (:conflicts (bm/compute-merge base main 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/testing "the exclusion is the recorded choice: the target keeps its value"
|
||||
@ -1929,9 +1929,9 @@
|
||||
(let [base (mkdata {:k (copy-shape "red")})
|
||||
main (mkdata {:k (copy-shape "blue")})
|
||||
branch (mkdata {:k (copy-shape "green")})
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/is (= [[:k :settled {:attrs {:fills {:side :main :reason :follows-component}}
|
||||
(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)))
|
||||
@ -1941,7 +1941,7 @@
|
||||
(let [base (mkdata {:k (copy-shape "red")})
|
||||
main (mkdata {:k (copy-shape "blue")})
|
||||
branch (mkdata {:k (copy-shape "green" :touched #{:fill-group})})
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
ops (copy-ops (:changes (bm/compute-changes base main branch {} r)))]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/testing "the summary reports the override as a change the merge applies"
|
||||
@ -1956,9 +1956,9 @@
|
||||
(let [base (mkdata {:k (copy-shape "red")})
|
||||
main (mkdata {:k (copy-shape "blue" :touched #{:fill-group})})
|
||||
branch (mkdata {:k (copy-shape "green")})
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/is (= [[:k :settled {:fills {:side :main :reason :override-main}}]]
|
||||
(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)))))))
|
||||
|
||||
@ -1966,7 +1966,7 @@
|
||||
(let [base (mkdata {:k (copy-shape "red")})
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main 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"
|
||||
@ -1981,8 +1981,8 @@
|
||||
main (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->main)
|
||||
ops (copy-ops (:changes (bm/compute-changes base main branch {:k :main} r)))]
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
ops (copy-ops (:changes (bm/compute-changes base main 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}}]
|
||||
@ -1993,7 +1993,7 @@
|
||||
(let [base (mkdata {:k (copy-shape "red")})
|
||||
main (mkdata {:k (copy-shape "blue" :touched #{:fill-group})})
|
||||
branch (mkdata {:k (copy-shape "green")})
|
||||
r (bm/compute-merge base main branch :main->branch)
|
||||
r (bm/compute-merge base main branch :source->branch)
|
||||
ops (copy-ops (:changes (bm/compute-changes base branch main {} r)))]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/is (= [{:type :set :attr :fills :val [{:fill-color "blue"}] :ignore-touched true}
|
||||
@ -2014,7 +2014,7 @@
|
||||
(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 :main->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
|
||||
@ -2039,9 +2039,9 @@
|
||||
(let [base (mkdata {:k (tokens-copy {})})
|
||||
main (mkdata {:k (tokens-copy {:fill "blue"})})
|
||||
branch (mkdata {:k (tokens-copy {:fill "green"})})
|
||||
r (bm/compute-merge base main branch :branch->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/is (= [[:k :settled {:fill {:side :main :reason :follows-component}}]]
|
||||
(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)))))))
|
||||
|
||||
@ -2051,7 +2051,7 @@
|
||||
(let [base (mkdata {:k (tokens-copy {})})
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main 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))))
|
||||
@ -2067,13 +2067,13 @@
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main 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/is (= {:fill "yellow" :r1 "round"}
|
||||
(->> (copy-ops (:changes (bm/compute-changes base main branch
|
||||
{:k {:applied-tokens :main :fills :main}}
|
||||
{:k {:applied-tokens :source :fills :source}}
|
||||
r)))
|
||||
(filter #(= :applied-tokens (:attr %)))
|
||||
first :val))))
|
||||
@ -2089,7 +2089,7 @@
|
||||
(let [base (mkdata {:k (tokens-copy {})})
|
||||
main (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})})
|
||||
branch (mkdata {:k (tokens-copy {:fill "green"})})
|
||||
r (bm/compute-merge base main branch :main->branch)]
|
||||
r (bm/compute-merge base main branch :source->branch)]
|
||||
(t/is (empty? (:conflicts r)))
|
||||
(t/is (= {:fill "red"}
|
||||
(->> (copy-ops (:changes (bm/compute-changes base branch main {} r)))
|
||||
@ -2146,14 +2146,14 @@
|
||||
(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->main)]
|
||||
r (merge-copies (:data file) (:data main) (: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->main)
|
||||
(t/is (not (contains? (bm/compute-merge (:data file) (:data main) (:data branch) :branch->source)
|
||||
:copies))))))))
|
||||
|
||||
(t/deftest copies-show-the-override-one-side-keeps
|
||||
@ -2163,11 +2163,11 @@
|
||||
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"
|
||||
(let [r (merge-copies (:data file) (:data override) (:data edited) :branch->main)]
|
||||
(t/is (= {(thi/id :copy1) {:follows #{} :keeps {:fill-group :main} :token-slots {}}}
|
||||
(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"
|
||||
(let [r (merge-copies (:data file) (:data edited) (:data override) :main->branch)]
|
||||
(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)))))))))
|
||||
|
||||
@ -2179,7 +2179,7 @@
|
||||
(t/testing (name label)
|
||||
(let [main (tho/update-color file label "#0000ff")
|
||||
branch (tho/update-color file label "#00ff00")
|
||||
r (merge-copies (:data file) (:data main) (:data branch) :branch->main)]
|
||||
r (merge-copies (:data file) (:data main) (: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"
|
||||
@ -2191,7 +2191,7 @@
|
||||
(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->main)]
|
||||
r (merge-copies (:data base) (:data main) (: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"
|
||||
@ -2199,7 +2199,7 @@
|
||||
(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->main)]
|
||||
r (merge-copies (:data file) (:data main) (:data branch) :branch->source)]
|
||||
(t/is (= [[(thi/id :main-child) 0]]
|
||||
(mapv (juxt :id :copies-affected) (:conflicts r))))))))))
|
||||
|
||||
@ -2225,7 +2225,7 @@
|
||||
(into #{}
|
||||
(map (juxt :component-id :via #(into #{} (map :id) (:copies %))))
|
||||
(:copies (merge-copies (:data file) (:data file) (:data branch)
|
||||
:branch->main))))
|
||||
:branch->source))))
|
||||
expected #{[(thi/id :component1) nil #{(thi/id :nested2-head)}]
|
||||
[(thi/id :component2) (thi/id :component1) #{(thi/id :copy2-root)}]}]
|
||||
(t/testing "the branch left its copies unsynced"
|
||||
@ -2234,7 +2234,7 @@
|
||||
(t/is (= expected (summary synced))))
|
||||
(t/testing "component2's copy follows the fill"
|
||||
(t/is (= #{:fill-group}
|
||||
(->> (:copies (merge-copies (:data file) (:data file) (:data edited) :branch->main))
|
||||
(->> (:copies (merge-copies (:data file) (:data file) (:data edited) :branch->source))
|
||||
(filter #(= (thi/id :component2) (:component-id %)))
|
||||
first :copies first :follows))))))))
|
||||
|
||||
@ -2244,7 +2244,7 @@
|
||||
(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"}})
|
||||
branch (mkdata {:k (copy-shape "green") :s {:id :s :name "S" :fill "blue"}})
|
||||
r (bm/compute-merge base main branch :branch->main)
|
||||
r (bm/compute-merge base main branch :branch->source)
|
||||
settled (filterv bm/settled? (:changes r))
|
||||
k-key (:key (first settled))
|
||||
s-key (:key (first (remove bm/settled? (:changes r))))
|
||||
@ -2265,7 +2265,7 @@
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= {:attrs {:opacity {:side :branch :reason :override-branch}}
|
||||
:token-slots {}
|
||||
:open-attrs #{:fills}
|
||||
@ -2276,7 +2276,7 @@
|
||||
main (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->main)]
|
||||
r (bm/compute-merge base main branch :branch->source)]
|
||||
(t/is (= {:attrs {}
|
||||
:token-slots {:r1 {:side :branch :reason :override-branch}}
|
||||
:open-attrs #{:applied-tokens :fills}
|
||||
@ -2286,9 +2286,9 @@
|
||||
(let [base (mkdata {:k (tokens-copy {})})
|
||||
main (mkdata {:k (tokens-copy {:fill "red"} :touched #{:fill-group})})
|
||||
branch (mkdata {:k (tokens-copy {:fill "green"})})
|
||||
r (bm/compute-merge base main branch :main->branch)]
|
||||
(t/is (= [[:k :modified {:attrs {:fills {:side :main :reason :override-main}}
|
||||
:token-slots {:fill {:side :main :reason :override-main}}
|
||||
r (bm/compute-merge base main branch :source->branch)]
|
||||
(t/is (= [[:k :modified {:attrs {:fills {:side :source :reason :override-source}}
|
||||
:token-slots {:fill {:side :source :reason :override-source}}
|
||||
:open-attrs #{}
|
||||
:open-token-slots #{}}]]
|
||||
(mapv (juxt :id :status :settled) (:changes r)))))))
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
"~:key": "color//c7ce0794-0992-8105-8004-38f2804439a1",
|
||||
"~:label": "Brand",
|
||||
"~:changed-attrs": {
|
||||
"~:color": { "~:main": "#000000", "~:branch": "#ff0000" }
|
||||
"~:color": { "~:source": "#000000", "~:branch": "#ff0000" }
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -27,8 +27,8 @@
|
||||
},
|
||||
"~:meta": {
|
||||
"~:base-at": "~m1713536343369",
|
||||
"~:main-at": "~m1713873823633",
|
||||
"~:source-at": "~m1713873823633",
|
||||
"~:branch-at": "~m1713873823633",
|
||||
"~:main-revn": 11
|
||||
"~:source-revn": 11
|
||||
}
|
||||
}
|
||||
@ -9,10 +9,10 @@
|
||||
"~:key": "color//c7ce0794-0992-8105-8004-38f2804439b1",
|
||||
"~:label": "Brand",
|
||||
"~:base": { "~:name": "Brand", "~:color": "#000000", "~:opacity": 1 },
|
||||
"~:main": { "~:name": "Brand", "~:color": "#00ff00", "~:opacity": 1 },
|
||||
"~:source": { "~:name": "Brand", "~:color": "#00ff00", "~:opacity": 1 },
|
||||
"~:branch": { "~:name": "Brand", "~:color": "#ff0000", "~:opacity": 1 },
|
||||
"~:changed-attrs": {
|
||||
"~:color": { "~:main": "#00ff00", "~:branch": "#ff0000" }
|
||||
"~:color": { "~:source": "#00ff00", "~:branch": "#ff0000" }
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -38,7 +38,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"~:main": {
|
||||
"~:source": {
|
||||
"~:type": "~:text",
|
||||
"~:content": {
|
||||
"~:type": "root",
|
||||
@ -77,7 +77,7 @@
|
||||
"~:id": "~uc7ce0794-0992-8105-8004-38f2804439b3",
|
||||
"~:key": "typography//c7ce0794-0992-8105-8004-38f2804439b3",
|
||||
"~:label": "Heading",
|
||||
"~:main": null,
|
||||
"~:source": null,
|
||||
"~:branch": { "~:name": "Heading", "~:font-size": "32" }
|
||||
}
|
||||
],
|
||||
@ -89,8 +89,8 @@
|
||||
},
|
||||
"~:meta": {
|
||||
"~:base-at": "~m1713536343369",
|
||||
"~:main-at": "~m1713873823633",
|
||||
"~:source-at": "~m1713873823633",
|
||||
"~:branch-at": "~m1713873823633",
|
||||
"~:main-revn": 11
|
||||
"~:source-revn": 11
|
||||
}
|
||||
}
|
||||
@ -9,8 +9,8 @@
|
||||
"~:created-at": "~m1713536343369",
|
||||
"~:updated-at": "~m1713873823633",
|
||||
"~:status": "open",
|
||||
"~:review-revn": 11,
|
||||
"~:review-updated-at": "~m1713873823633",
|
||||
"~:pinned-revn": 11,
|
||||
"~:pinned-at": "~m1713873823633",
|
||||
"~:closed-at": null,
|
||||
"~:closed-by": null,
|
||||
"~:branch-name": "checkout",
|
||||
@ -18,14 +18,14 @@
|
||||
"~:reviews": [
|
||||
{
|
||||
"~:profile-id": "~uc7ce0794-0992-8105-8004-38e630f29a9b",
|
||||
"~:state": "pending",
|
||||
"~:reviewed-revn": null,
|
||||
"~:verdict": "pending",
|
||||
"~:verdict-revn": null,
|
||||
"~:comment": null,
|
||||
"~:updated-at": "~m1713873823633",
|
||||
"~:stale": false
|
||||
}
|
||||
],
|
||||
"~:review-state": "pending",
|
||||
"~:overall-verdict": "pending",
|
||||
"~:outdated": false,
|
||||
"~:ahead": 1,
|
||||
"~:behind": 0,
|
||||
@ -9,8 +9,8 @@
|
||||
},
|
||||
"~:meta": {
|
||||
"~:base-at": "~m1713536343369",
|
||||
"~:main-at": "~m1713873823633",
|
||||
"~:source-at": "~m1713873823633",
|
||||
"~:branch-at": "~m1713873823633",
|
||||
"~:main-revn": 11
|
||||
"~:source-revn": 11
|
||||
}
|
||||
}
|
||||
@ -10,8 +10,8 @@
|
||||
"~:created-at": "~m1713536343369",
|
||||
"~:updated-at": "~m1713873823633",
|
||||
"~:status": "open",
|
||||
"~:review-revn": 11,
|
||||
"~:review-updated-at": "~m1713873823633",
|
||||
"~:pinned-revn": 11,
|
||||
"~:pinned-at": "~m1713873823633",
|
||||
"~:closed-at": null,
|
||||
"~:closed-by": null,
|
||||
"~:branch-name": "checkout",
|
||||
@ -19,14 +19,14 @@
|
||||
"~:reviews": [
|
||||
{
|
||||
"~:profile-id": "~uc7ce0794-0992-8105-8004-38e630f29a9b",
|
||||
"~:state": "pending",
|
||||
"~:reviewed-revn": null,
|
||||
"~:verdict": "pending",
|
||||
"~:verdict-revn": null,
|
||||
"~:comment": null,
|
||||
"~:updated-at": "~m1713873823633",
|
||||
"~:stale": false
|
||||
}
|
||||
],
|
||||
"~:review-state": "pending",
|
||||
"~:overall-verdict": "pending",
|
||||
"~:outdated": false,
|
||||
"~:ahead": 1,
|
||||
"~:behind": 0,
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"~:id": "~uc7ce0794-0992-8105-8004-38f280443999",
|
||||
"~:profile-id": "~uc7ce0794-0992-8105-8004-38e630f29a9b",
|
||||
"~:state": "approved",
|
||||
"~:reviewed-revn": 11
|
||||
"~:verdict": "approved",
|
||||
"~:verdict-revn": 11
|
||||
}
|
||||
@ -16,13 +16,13 @@ const setupBranch = async (workspacePage, diff) => {
|
||||
"get-file-branch-info?file-id=*":
|
||||
"pull-requests/get-file-branch-info-branch.json",
|
||||
"get-file-branches?file-id=*": "pull-requests/get-file-branches-empty.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branches-empty.json",
|
||||
"get-file-tasks?file-id=*": "pull-requests/get-file-branches-empty.json",
|
||||
"get-branch-diff?branch-id=*": `compare/${diff}`,
|
||||
"get-branch-change-reviews?branch-id=*":
|
||||
"compare/get-branch-change-reviews-empty.json",
|
||||
"set-branch-change-review": "compare/set-branch-change-review.json",
|
||||
"get-file-branch-diff?branch-id=*": `compare/${diff}`,
|
||||
"get-branch-change-marks?branch-id=*":
|
||||
"compare/get-branch-change-marks-empty.json",
|
||||
"set-branch-change-mark": "compare/set-branch-change-mark.json",
|
||||
});
|
||||
};
|
||||
|
||||
@ -39,7 +39,7 @@ test("comparing takes the canvas, read-only, and Escape leaves it", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspacePage = new WorkspacePage(page);
|
||||
await setupBranch(workspacePage, "get-branch-diff-changes.json");
|
||||
await setupBranch(workspacePage, "get-file-branch-diff-changes.json");
|
||||
await workspacePage.goToWorkspace();
|
||||
await enterCompare(page);
|
||||
|
||||
@ -67,7 +67,7 @@ test("comparing takes the canvas, read-only, and Escape leaves it", async ({
|
||||
|
||||
test("a change left out stays out of the merge", async ({ page }) => {
|
||||
const workspacePage = new WorkspacePage(page);
|
||||
await setupBranch(workspacePage, "get-branch-diff-changes.json");
|
||||
await setupBranch(workspacePage, "get-file-branch-diff-changes.json");
|
||||
await workspacePage.goToWorkspace();
|
||||
await enterCompare(page);
|
||||
|
||||
@ -103,14 +103,14 @@ test("main's changes are listed apart and update the branch", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspacePage = new WorkspacePage(page);
|
||||
await setupBranch(workspacePage, "get-branch-diff-changes.json");
|
||||
await setupBranch(workspacePage, "get-file-branch-diff-changes.json");
|
||||
await workspacePage.goToWorkspace();
|
||||
await enterCompare(page);
|
||||
|
||||
const incoming = page.waitForRequest(
|
||||
(req) =>
|
||||
req.url().includes("get-branch-diff") &&
|
||||
req.url().includes("main-%3Ebranch"),
|
||||
req.url().includes("get-file-branch-diff") &&
|
||||
req.url().includes("source-%3Ebranch"),
|
||||
);
|
||||
await changes(page).getByRole("tab", { name: "In main" }).click();
|
||||
await incoming;
|
||||
@ -124,7 +124,7 @@ test("main's changes are listed apart and update the branch", async ({
|
||||
).toBeVisible();
|
||||
|
||||
const update = page.waitForRequest((req) =>
|
||||
req.url().includes("update-branch-from-main"),
|
||||
req.url().includes("update-file-branch-from-source"),
|
||||
);
|
||||
await banner(page)
|
||||
.getByRole("button", { name: "Update with 2 changes" })
|
||||
@ -137,7 +137,7 @@ test("conflicts are decided in the sidebar before they apply", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspacePage = new WorkspacePage(page);
|
||||
await setupBranch(workspacePage, "get-branch-diff-conflicts.json");
|
||||
await setupBranch(workspacePage, "get-file-branch-diff-conflicts.json");
|
||||
await workspacePage.goToWorkspace();
|
||||
await enterCompare(page);
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ const setupMainWithBranches = async (workspacePage) => {
|
||||
"get-file-branch-count?file-id=*":
|
||||
"branches/get-file-branch-count-two.json",
|
||||
"get-file-branches?file-id=*": "branches/get-file-branches-two.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branches-empty.json",
|
||||
});
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@ const setupBranching = async (workspacePage, rpcs) => {
|
||||
"get-file-branch-info?file-id=*":
|
||||
"pull-requests/get-file-branch-info-none.json",
|
||||
"get-file-branches?file-id=*": "pull-requests/get-file-branches-empty.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branches-empty.json",
|
||||
...rpcs,
|
||||
});
|
||||
|
||||
@ -12,9 +12,10 @@ const setupBranchFile = async (workspacePage, branchInfo) => {
|
||||
"get-file-branch-info?file-id=*": `pull-requests/${branchInfo}`,
|
||||
"get-file-branches?file-id=*":
|
||||
"pull-requests/get-file-branches-closed.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branches-empty.json",
|
||||
"get-branch-diff?branch-id=*": "pull-requests/get-branch-diff-empty.json",
|
||||
"get-file-branch-diff?branch-id=*":
|
||||
"pull-requests/get-file-branch-diff-empty.json",
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -18,12 +18,13 @@ const setupPullRequestSandbox = async (workspacePage) => {
|
||||
"get-file-branch-info?file-id=*":
|
||||
"pull-requests/get-file-branch-info-none.json",
|
||||
"get-file-branches?file-id=*": "pull-requests/get-file-branches-empty.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"pull-requests/get-file-pull-requests.json",
|
||||
"get-pull-request?id=*": "pull-requests/get-pull-request.json",
|
||||
"get-branch-diff?branch-id=*": "pull-requests/get-branch-diff-empty.json",
|
||||
"submit-pull-request-review":
|
||||
"pull-requests/submit-pull-request-review.json",
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branch-reviews.json",
|
||||
"get-branch-review?id=*": "pull-requests/get-branch-review.json",
|
||||
"get-file-branch-diff?branch-id=*":
|
||||
"pull-requests/get-file-branch-diff-empty.json",
|
||||
"submit-branch-review-verdict":
|
||||
"pull-requests/submit-branch-review-verdict.json",
|
||||
});
|
||||
};
|
||||
|
||||
@ -160,8 +161,8 @@ test("closing the pull request asks for confirmation", async ({ page }) => {
|
||||
const workspacePage = new WorkspacePage(page);
|
||||
await setupPullRequestSandbox(workspacePage);
|
||||
await workspacePage.mockRPC(
|
||||
"close-pull-request",
|
||||
"pull-requests/close-pull-request.json",
|
||||
"close-branch-review",
|
||||
"pull-requests/close-branch-review.json",
|
||||
);
|
||||
await workspacePage.goToWorkspace({ extraParams: `&pr-id=${PR_ID}` });
|
||||
|
||||
@ -187,7 +188,7 @@ test("on a branch, requesting a review is the primary action", async ({
|
||||
await workspacePage.mockRPCs({
|
||||
"get-file-branch-info?file-id=*":
|
||||
"pull-requests/get-file-branch-info-branch.json",
|
||||
"get-file-pull-requests?file-id=*":
|
||||
"get-file-branch-reviews?file-id=*":
|
||||
"pull-requests/get-file-branches-empty.json",
|
||||
});
|
||||
await workspacePage.goToWorkspace();
|
||||
|
||||
@ -154,7 +154,7 @@
|
||||
;; the pinned review snapshot instead of the live
|
||||
;; branch state
|
||||
(uuid? pr-id)
|
||||
(assoc :pr-id pr-id))
|
||||
(assoc :review-id pr-id))
|
||||
|
||||
resolve (partial resolve-viewer-fragment file-id share-id)]
|
||||
|
||||
|
||||
@ -253,7 +253,7 @@
|
||||
(ptk/reify ::rename-branch
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :update-file-branch {:id id :name name})
|
||||
(->> (rp/cmd! :update-file-branch-info {:branch-id id :name name})
|
||||
(rx/mapcat (fn [_] (rx/of (fetch-branches) (fetch-branch-context))))
|
||||
(rx/catch (fn [cause] (rx/of (refusal-notification cause (tr "workspace.branches.lifecycle.error")))))))))
|
||||
|
||||
@ -265,7 +265,7 @@
|
||||
(ptk/reify ::set-branch-description
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :update-file-branch {:id id :description description})
|
||||
(->> (rp/cmd! :update-file-branch-info {:branch-id id :description description})
|
||||
(rx/mapcat (fn [_] (rx/of (fetch-branches) (fetch-branch-context))))
|
||||
(rx/catch (fn [cause] (rx/of (refusal-notification cause (tr "workspace.branches.lifecycle.error")))))))))
|
||||
|
||||
@ -278,7 +278,7 @@
|
||||
(ptk/reify ::archive-branch
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :archive-file-branch {:id id :archived archived?})
|
||||
(->> (rp/cmd! :archive-file-branch {:branch-id id :archived archived?})
|
||||
(rx/mapcat (fn [_] (rx/of (fetch-branches) (fetch-branch-context))))
|
||||
(rx/catch (fn [cause] (rx/of (refusal-notification cause (tr "workspace.branches.lifecycle.error"))))))))))
|
||||
|
||||
@ -293,7 +293,7 @@
|
||||
(ptk/reify ::delete-branch
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :delete-file-branch {:id id})
|
||||
(->> (rp/cmd! :delete-file-branch {:branch-id id})
|
||||
(rx/mapcat (fn [_] (rx/concat
|
||||
(rx/of (ntf/success (tr "workspace.branches.lifecycle.deleted"))
|
||||
(fetch-branches))
|
||||
@ -303,21 +303,21 @@
|
||||
(rx/catch (fn [cause] (rx/of (refusal-notification cause (tr "workspace.branches.lifecycle.error"))))))))))
|
||||
|
||||
(defn materialize-branch
|
||||
"Turn a branch into an ordinary file: `branch-file-id` is the branch's
|
||||
FILE (the id `create-file-branch` returns), not the branch row id, and
|
||||
the command persists the branch's derived state as the file's own data
|
||||
payload, drops the op log and clears the branch marker, so every later
|
||||
read and write takes the ordinary route. The content stays; what goes is
|
||||
the branch itself, so the file can no longer be compared with main or
|
||||
merged into it. The branch row is soft-deleted, so refreshing the panel
|
||||
drops the row and refreshing the context drops the banner when the file
|
||||
that left the branch is the open one."
|
||||
[branch-file-id]
|
||||
(assert (uuid? branch-file-id) "expected valid uuid for `branch-file-id`")
|
||||
"Turn a branch into an ordinary file: `branch-id` is the branch row id
|
||||
(the `:id` of a row of `get-file-branches`), and the command persists
|
||||
the branch's derived state as the file's own data payload, drops the op
|
||||
log and clears the branch marker, so every later read and write takes
|
||||
the ordinary route. The content stays; what goes is the branch itself,
|
||||
so the file can no longer be compared with main or merged into it. The
|
||||
branch row is soft-deleted, so refreshing the panel drops the row and
|
||||
refreshing the context drops the banner when the file that left the
|
||||
branch is the open one."
|
||||
[branch-id]
|
||||
(assert (uuid? branch-id) "expected valid uuid for `branch-id`")
|
||||
(ptk/reify ::materialize-branch
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :materialize-file-branch {:branch-file-id branch-file-id})
|
||||
(->> (rp/cmd! :detach-file-branch {:branch-id branch-id})
|
||||
(rx/mapcat (fn [_] (rx/of (ntf/success (tr "workspace.branches.materialize.success"))
|
||||
(fetch-branches)
|
||||
(fetch-branch-context))))
|
||||
@ -430,7 +430,7 @@
|
||||
values it moved between. A review mark is kept with it, so a mark made
|
||||
on a change that later became another one no longer counts."
|
||||
[item]
|
||||
(str (hash [(:status item) (:changed-attrs item) (:shape item) (:main item) (:branch item)])))
|
||||
(str (hash [(:status item) (:changed-attrs item) (:shape item) (:source item) (:branch item)])))
|
||||
|
||||
(declare fetch-diff-reviewed)
|
||||
|
||||
@ -443,11 +443,11 @@
|
||||
|
||||
(defn fetch-branch-diff
|
||||
"Load the 3-way diff for `branch-id`. `direction` selects which side's
|
||||
changes to show: `:branch->main` (default, the branch's outgoing changes)
|
||||
or `:main->branch` (main's incoming changes the branch is missing). A
|
||||
newer fetch cancels any previous in-flight one, so a stale response can
|
||||
never land over a direction/branch switch."
|
||||
([branch-id] (fetch-branch-diff branch-id :branch->main))
|
||||
changes to show: `:branch->source` (default, the branch's outgoing
|
||||
changes) or `:source->branch` (the source's incoming changes the branch
|
||||
lacks). A newer fetch cancels any previous in-flight one, so a stale
|
||||
response can never land over a direction/branch switch."
|
||||
([branch-id] (fetch-branch-diff branch-id :branch->source))
|
||||
([branch-id direction]
|
||||
(assert (uuid? branch-id) "expected valid uuid for `branch-id`")
|
||||
(ptk/reify ::fetch-branch-diff
|
||||
@ -472,7 +472,7 @@
|
||||
:resolutions (when same? (:resolutions prev))})))
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ stream]
|
||||
(->> (rp/cmd! :get-branch-diff {:branch-id branch-id :direction direction})
|
||||
(->> (rp/cmd! :get-file-branch-diff {:branch-id branch-id :direction direction})
|
||||
(rx/mapcat #(rx/of (update-branch-diff {:status :loaded :diff %})
|
||||
(fetch-diff-reviewed)))
|
||||
(rx/catch (fn [_]
|
||||
@ -484,7 +484,7 @@
|
||||
entry) for the direction it shows: the change keys left OUT of the
|
||||
merge or update. Each direction keeps its own."
|
||||
[diff-state]
|
||||
(get-in diff-state [:excluded (:direction diff-state :branch->main)] #{}))
|
||||
(get-in diff-state [:excluded (:direction diff-state :branch->source)] #{}))
|
||||
|
||||
(defn toggle-diff-excluded
|
||||
"Toggle the per-change selection of the current diff, in the direction
|
||||
@ -500,7 +500,7 @@
|
||||
(ptk/reify ::toggle-diff-excluded
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [direction (get-in state [:workspace-branch-diff :direction] :branch->main)]
|
||||
(let [direction (get-in state [:workspace-branch-diff :direction] :branch->source)]
|
||||
(update-in state [:workspace-branch-diff :excluded direction]
|
||||
(fn [excluded]
|
||||
(let [excluded (or excluded #{})
|
||||
@ -546,7 +546,7 @@
|
||||
(let [{:keys [branch-id direction status] :as diff-st} (:workspace-branch-diff state)]
|
||||
(if (= :loaded status)
|
||||
(let [items (diff-items diff-st)]
|
||||
(->> (rp/cmd! :get-branch-change-reviews {:branch-id branch-id :direction direction})
|
||||
(->> (rp/cmd! :get-branch-change-marks {:branch-id branch-id :direction direction})
|
||||
(rx/map (fn [marks]
|
||||
(set-diff-reviewed
|
||||
branch-id direction
|
||||
@ -586,7 +586,7 @@
|
||||
item (get (diff-items diff-st) item-key)]
|
||||
;; only a change of the diff has a mark to keep
|
||||
(if (and (some? item) (uuid? branch-id))
|
||||
(->> (rp/cmd! :set-branch-change-review
|
||||
(->> (rp/cmd! :set-branch-change-mark
|
||||
{:branch-id branch-id
|
||||
:direction direction
|
||||
:change-key item-key
|
||||
@ -668,12 +668,13 @@
|
||||
the compare mode fetches on its own is computed in another id space and
|
||||
may list a different set, or none at all.
|
||||
|
||||
`main-revn` is main's revn when the command computed those conflicts. It
|
||||
is stored with them because the diff fetch can still be in flight when
|
||||
the user applies; see `conflict-main-revn`. `excluded` is the per-change
|
||||
selection the attempt was made with and `comment` what the user said
|
||||
about the merge: applying the resolutions sends both again."
|
||||
[{:keys [branch mode conflicts main-revn excluded comment]}]
|
||||
`source-revn` is the source's revn when the command computed those
|
||||
conflicts. It is stored with them because the diff fetch can still be in
|
||||
flight when the user applies; see `conflict-source-revn`. `excluded` is
|
||||
the per-change selection the attempt was made with and `comment` what
|
||||
the user said about the merge: applying the resolutions sends both
|
||||
again."
|
||||
[{:keys [branch mode conflicts source-revn excluded comment]}]
|
||||
(ptk/reify ::open-conflict-resolutions
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
@ -682,7 +683,7 @@
|
||||
:branch branch
|
||||
:mode mode
|
||||
:conflicts (vec conflicts)
|
||||
:main-revn main-revn
|
||||
:source-revn source-revn
|
||||
:excluded excluded
|
||||
:comment comment}))))
|
||||
|
||||
@ -695,56 +696,59 @@
|
||||
(update [_ state]
|
||||
(dissoc state :workspace-branch-conflicts))))
|
||||
|
||||
(defn- conflict-main-revn
|
||||
"Main's revn when the server computed the conflict set stored for
|
||||
(defn- conflict-source-revn
|
||||
"The source's revn when the server computed the conflict set stored for
|
||||
`branch-id`, or nil when the stored set belongs to another branch.
|
||||
|
||||
Resolving fetches the diff in its own direction, and that fetch
|
||||
replaces the loaded diff with a loading state until it answers. The user
|
||||
can resolve every conflict and apply inside that window, so merge and
|
||||
update fall back to this revn: resolutions never leave without the token
|
||||
that lets the server refuse them when main has moved (`:file-modified`).
|
||||
Main's revn is the same in both directions, so the mode does not matter."
|
||||
that lets the server refuse them when the source has moved
|
||||
(`:file-modified`). The source's revn is the same in both directions, so
|
||||
the mode does not matter."
|
||||
[state branch-id]
|
||||
(let [conflicts-st (:workspace-branch-conflicts state)]
|
||||
(when (= branch-id (:branch-id conflicts-st))
|
||||
(:main-revn conflicts-st))))
|
||||
(:source-revn conflicts-st))))
|
||||
|
||||
(defn update-branch-from-main
|
||||
"Bring main's changes into the branch (reverse of merge). `branch` is the
|
||||
branch row. With conflicts and no `resolutions`, hands them over to be
|
||||
resolved (`open-conflict-resolutions`); with resolutions, applies them.
|
||||
"Bring the source's changes into the branch (reverse of merge). `branch`
|
||||
is the branch row. With conflicts and no `resolutions`, hands them over
|
||||
to be resolved (`open-conflict-resolutions`); with resolutions, applies
|
||||
them.
|
||||
|
||||
Options (`opts`): `:resolutions` `{entity-id (:main|:branch)}` as below,
|
||||
and `:excluded`, the per-change selection (change keys,
|
||||
`app.common.files.branch-merge/change-key`) naming main's changes the
|
||||
user deselected, which the branch keeps its own value for.
|
||||
Options (`opts`): `:resolutions` `{entity-id (:source|:branch)}` as
|
||||
below, and `:excluded`, the per-change selection (change keys,
|
||||
`app.common.files.branch-merge/change-key`) naming the source's changes
|
||||
the user deselected, which the branch keeps its own value for.
|
||||
|
||||
When the current diff in state is this branch's `:main->branch` diff,
|
||||
its main revn is sent as `expected-main-revn` so the server refuses to
|
||||
apply resolutions computed against a stale diff (`:file-modified`); in
|
||||
that case the diff is re-fetched and the user is asked to review it
|
||||
When the current diff in state is this branch's `:source->branch` diff,
|
||||
its source revn is sent as `expected-source-revn` so the server refuses
|
||||
to apply resolutions computed against a stale diff (`:file-modified`);
|
||||
in that case the diff is re-fetched and the user is asked to review it
|
||||
again (same as `merge-branch`). Resolutions sent before that diff has
|
||||
loaded carry the revn of the conflict answer instead
|
||||
(`conflict-main-revn`)."
|
||||
(`conflict-source-revn`)."
|
||||
([branch] (update-branch-from-main branch nil))
|
||||
([branch {:keys [resolutions excluded]}]
|
||||
(ptk/reify ::update-branch-from-main
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [branch-id (:id branch)
|
||||
diff-st (:workspace-branch-diff state)
|
||||
main-revn (or (when (and (= branch-id (:branch-id diff-st))
|
||||
(= :main->branch (:direction diff-st)))
|
||||
(get-in diff-st [:diff :meta :main-revn]))
|
||||
(when (seq resolutions)
|
||||
(conflict-main-revn state branch-id)))]
|
||||
(let [branch-id (:id branch)
|
||||
diff-st (:workspace-branch-diff state)
|
||||
source-revn (or (when (and (= branch-id (:branch-id diff-st))
|
||||
(= :source->branch (:direction diff-st)))
|
||||
(get-in diff-st [:diff :meta :source-revn]))
|
||||
(when (seq resolutions)
|
||||
(conflict-source-revn state branch-id)))]
|
||||
(rx/concat
|
||||
(rx/of (ev/event {::ev/name "update-branch-from-main"}))
|
||||
(->> (rp/cmd! :update-branch-from-main (cond-> {:branch-id branch-id}
|
||||
(seq resolutions) (assoc :resolutions resolutions)
|
||||
(seq excluded) (assoc :excluded excluded)
|
||||
(some? main-revn) (assoc :expected-main-revn main-revn)))
|
||||
(->> (rp/cmd! :update-file-branch-from-source
|
||||
(cond-> {:branch-id branch-id}
|
||||
(seq resolutions) (assoc :resolutions resolutions)
|
||||
(seq excluded) (assoc :excluded excluded)
|
||||
(some? source-revn) (assoc :expected-source-revn source-revn)))
|
||||
(rx/mapcat
|
||||
(fn [{:keys [status conflicts] :as answer}]
|
||||
(case status
|
||||
@ -759,7 +763,7 @@
|
||||
:conflicts (rx/of (open-conflict-resolutions {:branch branch
|
||||
:mode :update
|
||||
:conflicts conflicts
|
||||
:main-revn (:main-revn answer)
|
||||
:source-revn (:source-revn answer)
|
||||
:excluded excluded}))
|
||||
:unsupported (rx/of (ntf/warn (tr "workspace.branches.update.unsupported")))
|
||||
(rx/of (ntf/error (tr "workspace.branches.update.error"))))))
|
||||
@ -771,12 +775,13 @@
|
||||
;; update-specific "main moved" key exists, so this
|
||||
;; reuses merge's)
|
||||
(rx/of (ntf/warn (tr "workspace.branches.merge.main-moved"))
|
||||
(fetch-branch-diff branch-id :main->branch))
|
||||
(fetch-branch-diff branch-id :source->branch))
|
||||
(rx/of (refusal-notification cause (tr "workspace.branches.update.error")))))))))))))
|
||||
|
||||
(defn set-conflict-resolution
|
||||
"Choose `:main` or `:branch` for a whole conflicting entity (by id). This
|
||||
is the per-element \"Use this\" action; it overwrites any per-attr map."
|
||||
"Choose `:source` or `:branch` for a whole conflicting entity (by id).
|
||||
This is the per-element \"Use this\" action; it overwrites any per-attr
|
||||
map."
|
||||
[id choice]
|
||||
(ptk/reify ::set-conflict-resolution
|
||||
ptk/UpdateEvent
|
||||
@ -785,7 +790,7 @@
|
||||
|
||||
(defn set-conflict-resolutions
|
||||
"Store several conflict resolutions at once, `{entity-id resolution}`,
|
||||
over the ones already chosen. A resolution is `:main`, `:branch` or a
|
||||
over the ones already chosen. A resolution is `:source`, `:branch` or a
|
||||
per-attr `{attr side}` map."
|
||||
[resolutions]
|
||||
(ptk/reify ::set-conflict-resolutions
|
||||
@ -807,35 +812,35 @@
|
||||
file, and open clients reload main via the `:file-merged` msgbus event.
|
||||
|
||||
Options:
|
||||
- `:resolutions` — optional `{entity-id (:main|:branch)}` map used to
|
||||
- `:resolutions` — optional `{entity-id (:source|:branch)}` map used to
|
||||
resolve conflicts before integrating.
|
||||
- `:comment` — what the user says about the merge, kept with its
|
||||
record and shown in the reviews dialog.
|
||||
- `:notify-assignees` — tell the assignees of the open tasks of the
|
||||
branch, by email, that the merge moved their tasks into main.
|
||||
branch, by email, that the merge moved their tasks into the target.
|
||||
- `:excluded` — the per-change selection (change keys,
|
||||
`app.common.files.branch-merge/change-key`) naming the changes the
|
||||
user deselected, which main keeps its own value for.
|
||||
user deselected, which the target keeps its own value for.
|
||||
|
||||
When the current diff in state belongs to this branch, its main revn is
|
||||
sent as `expected-main-revn` so the server refuses to apply resolutions
|
||||
computed against a stale diff (`:file-modified`); in that case the diff
|
||||
is re-fetched and the user is asked to review it again. Resolutions sent
|
||||
before that diff has loaded carry the revn of the conflict answer instead
|
||||
(`conflict-main-revn`). Unresolved conflicts are handed over to be
|
||||
resolved (`open-conflict-resolutions`)."
|
||||
When the current diff in state belongs to this branch, its source revn
|
||||
is sent as `expected-source-revn` so the server refuses to apply
|
||||
resolutions computed against a stale diff (`:file-modified`); in that
|
||||
case the diff is re-fetched and the user is asked to review it again.
|
||||
Resolutions sent before that diff has loaded carry the revn of the
|
||||
conflict answer instead (`conflict-source-revn`). Unresolved conflicts
|
||||
are handed over to be resolved (`open-conflict-resolutions`)."
|
||||
([branch] (merge-branch branch nil))
|
||||
([branch {:keys [resolutions comment excluded notify-assignees]}]
|
||||
(assert (uuid? (:id branch)) "expected a branch row with a valid `:id`")
|
||||
(ptk/reify ::merge-branch
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [branch-id (:id branch)
|
||||
diff-st (:workspace-branch-diff state)
|
||||
main-revn (or (when (= branch-id (:branch-id diff-st))
|
||||
(get-in diff-st [:diff :meta :main-revn]))
|
||||
(when (seq resolutions)
|
||||
(conflict-main-revn state branch-id)))]
|
||||
(let [branch-id (:id branch)
|
||||
diff-st (:workspace-branch-diff state)
|
||||
source-revn (or (when (= branch-id (:branch-id diff-st))
|
||||
(get-in diff-st [:diff :meta :source-revn]))
|
||||
(when (seq resolutions)
|
||||
(conflict-source-revn state branch-id)))]
|
||||
(rx/concat
|
||||
(rx/of (ev/event {::ev/name "merge-branch"}))
|
||||
(->> (rp/cmd! :merge-file-branch
|
||||
@ -844,7 +849,7 @@
|
||||
(seq excluded) (assoc :excluded excluded)
|
||||
notify-assignees (assoc :notify-assignees true)
|
||||
(not (str/blank? comment)) (assoc :comment (str/trim comment))
|
||||
(some? main-revn) (assoc :expected-main-revn main-revn)))
|
||||
(some? source-revn) (assoc :expected-source-revn source-revn)))
|
||||
(rx/mapcat
|
||||
(fn [{:keys [status source-file-id conflicts] :as answer}]
|
||||
(case status
|
||||
@ -858,7 +863,7 @@
|
||||
:conflicts (rx/of (open-conflict-resolutions {:branch branch
|
||||
:mode :merge
|
||||
:conflicts conflicts
|
||||
:main-revn (:main-revn answer)
|
||||
:source-revn (:source-revn answer)
|
||||
:excluded excluded
|
||||
:comment comment}))
|
||||
:unsupported (rx/of (ntf/warn (tr "workspace.branches.merge.unsupported")))
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
:hovered-from where the pointer is: its row (`:list`) or its layer
|
||||
(`:canvas`)
|
||||
:attr the property in turn while resolving a conflict
|
||||
:preview the side (`:main`, `:branch`) of that property the canvas
|
||||
:preview the side (`:source`, `:branch`) of that property the canvas
|
||||
tries out while the pointer is on its option
|
||||
:peek true while the canvas shows main in place of the branch
|
||||
:filter :all | :layers | :library | :left-out
|
||||
@ -117,7 +117,7 @@
|
||||
(let [shape (or (get objects (:id item))
|
||||
(:shape item)
|
||||
(:branch item)
|
||||
(:main item))
|
||||
(:source item))
|
||||
{:keys [x y width height]} (or (:selrect shape) shape)]
|
||||
(when (and (number? x) (number? y) (number? width) (number? height))
|
||||
{:x x :y y :width width :height height}))))
|
||||
@ -232,10 +232,10 @@
|
||||
;; --- What the mode shows
|
||||
|
||||
(defn set-direction
|
||||
"Show the changes of the branch (`:branch->main`) or the ones main has
|
||||
and the branch lacks (`:main->branch`)."
|
||||
"Show the changes of the branch (`:branch->source`) or the ones the
|
||||
source has and the branch lacks (`:source->branch`)."
|
||||
[direction]
|
||||
(assert (contains? #{:branch->main :main->branch} direction) "expected a direction")
|
||||
(assert (contains? #{:branch->source :source->branch} direction) "expected a direction")
|
||||
(ptk/reify ::set-direction
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
@ -519,9 +519,9 @@
|
||||
diff-st (:workspace-branch-diff state)
|
||||
branch (get-in state [:workspace-compare :branch])
|
||||
direction (case (:mode attempt)
|
||||
:update :main->branch
|
||||
:merge :branch->main
|
||||
(:direction diff-st :branch->main))]
|
||||
:update :source->branch
|
||||
:merge :branch->source
|
||||
(:direction diff-st :branch->source))]
|
||||
(cond
|
||||
;; the conflicts belong to a branch that is not the open file
|
||||
(and (nil? branch) (uuid? (get-in attempt [:branch :branch-file-id])))
|
||||
@ -579,7 +579,7 @@
|
||||
excluded (if (some? attempt)
|
||||
(:excluded attempt)
|
||||
(dwb/diff-excluded diff-st))]
|
||||
(if (= :main->branch (:direction diff-st))
|
||||
(if (= :source->branch (:direction diff-st))
|
||||
(rx/of (dwb/update-branch-from-main branch {:resolutions res
|
||||
:excluded excluded}))
|
||||
(rx/of (dwb/merge-branch branch {:resolutions res
|
||||
@ -623,11 +623,11 @@
|
||||
(watch [_ state stream]
|
||||
(let [branch-id (get-in state [:workspace-compare :branch :id])
|
||||
diff-st (:workspace-branch-diff state)
|
||||
direction (if (= :main->branch (:direction diff-st))
|
||||
:branch->main
|
||||
:main->branch)]
|
||||
direction (if (= :source->branch (:direction diff-st))
|
||||
:branch->source
|
||||
:source->branch)]
|
||||
(if (and (some? branch-id) (= branch-id (:branch-id diff-st)))
|
||||
(->> (rp/cmd! :get-branch-diff {:branch-id branch-id :direction direction})
|
||||
(->> (rp/cmd! :get-file-branch-diff {:branch-id branch-id :direction direction})
|
||||
(rx/map set-other-changes)
|
||||
(rx/catch (fn [_] (rx/empty)))
|
||||
(rx/take-until
|
||||
|
||||
@ -166,10 +166,10 @@
|
||||
:file-restored (handle-file-restored msg)
|
||||
:file-merged (handle-file-merged msg)
|
||||
:library-change (handle-library-change msg)
|
||||
:pull-request-created (handle-pull-request-change msg)
|
||||
:pull-request-updated (handle-pull-request-change msg)
|
||||
:pull-request-review-submitted (handle-pull-request-change msg)
|
||||
:pull-request-closed (handle-pull-request-change msg)
|
||||
:branch-review-created (handle-pull-request-change msg)
|
||||
:branch-review-updated (handle-pull-request-change msg)
|
||||
:branch-review-verdict-submitted (handle-pull-request-change msg)
|
||||
:branch-review-closed (handle-pull-request-change msg)
|
||||
:file-tasks-change (dwtk/handle-tasks-change msg)
|
||||
:notification (dc/handle-notification msg)
|
||||
:team-role-change (handle-change-team-role msg)
|
||||
@ -397,12 +397,12 @@
|
||||
"A pull request of this file changed (created / edited / reviewed /
|
||||
closed): refresh the sidebar list, and the sandbox banner when it is
|
||||
showing that pull request."
|
||||
[{:keys [pull-request-id] :as _msg}]
|
||||
[{:keys [review-id] :as _msg}]
|
||||
(ptk/reify ::handle-pull-request-change
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/of (dwpr/fetch-pull-requests)
|
||||
(dwpr/refresh-pull-request-preview-info pull-request-id)))))
|
||||
(dwpr/refresh-pull-request-preview-info review-id)))))
|
||||
|
||||
(def ^:private schema:handle-library-change
|
||||
[:map {:title "handle-library-change"}
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
(watch [_ state _]
|
||||
(when (enabled?)
|
||||
(when-let [file-id (:current-file-id state)]
|
||||
(->> (rp/cmd! :get-file-pull-requests {:file-id file-id :include-closed true})
|
||||
(->> (rp/cmd! :get-file-branch-reviews {:file-id file-id :include-closed true})
|
||||
(rx/map #(update-pull-requests-state {:status :loaded :data %}))
|
||||
(rx/catch (fn [_]
|
||||
(rx/of (update-pull-requests-state {:status :loaded :data []}))))))))))
|
||||
@ -93,7 +93,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(when (and (enabled?) (some? team-id))
|
||||
(->> (rp/cmd! :get-profile-pending-reviews {:team-id team-id})
|
||||
(->> (rp/cmd! :get-profile-review-requests {:team-id team-id})
|
||||
(rx/map set-pending-reviews)
|
||||
(rx/catch (fn [_] (rx/of (set-pending-reviews [])))))))))
|
||||
|
||||
@ -127,7 +127,7 @@
|
||||
(rx/of ::dwp/force-persist (ev/event {::ev/name "create-pull-request"}))
|
||||
(rx/of (ev/event {::ev/name "create-pull-request"})))
|
||||
(->> wait
|
||||
(rx/mapcat #(rp/cmd! :create-pull-request
|
||||
(rx/mapcat #(rp/cmd! :create-branch-review
|
||||
{:branch-id branch-id
|
||||
:title title
|
||||
:description description
|
||||
@ -138,7 +138,7 @@
|
||||
(fetch-pull-requests))))
|
||||
(rx/catch
|
||||
(fn [cause]
|
||||
(if (= :pull-request-already-exists (:code (ex-data cause)))
|
||||
(if (= :branch-review-already-exists (:code (ex-data cause)))
|
||||
(rx/of (ntf/warn (tr "workspace.pull-requests.create.already-exists")))
|
||||
(rx/of (ntf/error (tr "workspace.pull-requests.create.error"))))))))))))
|
||||
|
||||
@ -150,7 +150,7 @@
|
||||
(ptk/reify ::update-pull-request
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :update-pull-request
|
||||
(->> (rp/cmd! :update-branch-review-info
|
||||
(cond-> {:id id}
|
||||
(some? title) (assoc :title title)
|
||||
(some? description) (assoc :description description)
|
||||
@ -176,7 +176,7 @@
|
||||
(rx/of ::dwp/force-persist (ev/event {::ev/name "update-pull-request-snapshot"}))
|
||||
(rx/of (ev/event {::ev/name "update-pull-request-snapshot"})))
|
||||
(->> wait
|
||||
(rx/mapcat #(rp/cmd! :update-pull-request-snapshot {:id id}))
|
||||
(rx/mapcat #(rp/cmd! :update-branch-review-revision {:id id}))
|
||||
(rx/mapcat
|
||||
(fn [{:keys [updated]}]
|
||||
(rx/of (if updated
|
||||
@ -189,19 +189,21 @@
|
||||
(rx/of (ntf/error (tr "workspace.pull-requests.lifecycle.error")))))))))))
|
||||
|
||||
(defn submit-review
|
||||
"Submit (or retract, with \"pending\") a verdict on a pull request. Only
|
||||
"Submit a verdict on a pull request, or retract it with `nil`. Only
|
||||
assigned reviewers may submit (enforced server-side)."
|
||||
[id verdict comment]
|
||||
(assert (uuid? id) "expected valid uuid for `id`")
|
||||
(assert (contains? #{"approved" "changes-requested" "pending"} verdict)
|
||||
(assert (or (nil? verdict)
|
||||
(contains? #{"approved" "changes-requested"} verdict))
|
||||
"expected a valid verdict")
|
||||
(ptk/reify ::submit-review
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/concat
|
||||
(rx/of (ev/event {::ev/name "submit-pull-request-review"}))
|
||||
(->> (rp/cmd! :submit-pull-request-review
|
||||
(cond-> {:id id :state verdict}
|
||||
(->> (rp/cmd! :submit-branch-review-verdict
|
||||
(cond-> {:id id}
|
||||
(some? verdict) (assoc :verdict verdict)
|
||||
(some? comment) (assoc :comment comment)))
|
||||
(rx/mapcat
|
||||
(fn [_]
|
||||
@ -225,7 +227,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [inside? (= id (get-in state [:workspace-pr-preview :pr-id]))]
|
||||
(->> (rp/cmd! :close-pull-request {:id id})
|
||||
(->> (rp/cmd! :close-branch-review {:id id})
|
||||
(rx/mapcat
|
||||
(fn [_]
|
||||
(rx/concat
|
||||
@ -244,7 +246,7 @@
|
||||
(ptk/reify ::reopen-pull-request
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :reopen-pull-request {:id id})
|
||||
(->> (rp/cmd! :reopen-branch-review {:id id})
|
||||
(rx/mapcat (fn [_] (rx/of (ntf/success (tr "workspace.pull-requests.lifecycle.reopened"))
|
||||
(fetch-pull-requests))))
|
||||
(rx/catch
|
||||
@ -253,7 +255,7 @@
|
||||
:branch-not-open
|
||||
(rx/of (ntf/warn (tr "workspace.pull-requests.lifecycle.branch-gone")))
|
||||
|
||||
:pull-request-already-exists
|
||||
:branch-review-already-exists
|
||||
(rx/of (ntf/warn (tr "workspace.pull-requests.create.already-exists")))
|
||||
|
||||
(rx/of (ntf/error (tr "workspace.pull-requests.lifecycle.error"))))))))))
|
||||
@ -299,7 +301,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(when (= id (get-in state [:workspace-pr-preview :pr-id]))
|
||||
(->> (rp/cmd! :get-pull-request {:id id})
|
||||
(->> (rp/cmd! :get-branch-review {:id id})
|
||||
(rx/mapcat
|
||||
(fn [info]
|
||||
(if (not= "open" (:status info))
|
||||
@ -344,7 +346,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [file-id (:current-file-id state)]
|
||||
(->> (rp/cmd! :get-pull-request {:id pr-id})
|
||||
(->> (rp/cmd! :get-branch-review {:id pr-id})
|
||||
(rx/mapcat
|
||||
(fn [info]
|
||||
(cond
|
||||
|
||||
@ -153,12 +153,12 @@
|
||||
(case (get-tool state)
|
||||
:comment
|
||||
(rx/of (dcmt/create-draft
|
||||
(cond-> (assoc (draft-params state position) :pull-request-id pr-id)
|
||||
(cond-> (assoc (draft-params state position) :review-id pr-id)
|
||||
(and (some? shape) (not= :frame (:type shape)))
|
||||
(assoc :anchor {:type :layer :shape-id (:id shape)})
|
||||
|
||||
(or (nil? shape) (= :frame (:type shape)))
|
||||
(assoc :anchor {:type :canvas}))))
|
||||
(assoc :anchor {:type :point}))))
|
||||
|
||||
;; on the empty canvas the task points at the canvas itself
|
||||
:task
|
||||
@ -171,7 +171,7 @@
|
||||
:else (:frame-id shape))
|
||||
:shape-id (:id shape)
|
||||
:position position
|
||||
:pull-request-id pr-id}))
|
||||
:review-id pr-id}))
|
||||
(if (nil? pr-id)
|
||||
(rx/of (forget-task-tool))
|
||||
(rx/empty)))
|
||||
@ -189,7 +189,7 @@
|
||||
(let [position {:x (- (+ x width) 1) :y (+ y 1)}]
|
||||
(rx/of (dcmt/create-draft
|
||||
(-> (draft-params state (gpt/point position))
|
||||
(assoc :pull-request-id (review-id state))
|
||||
(assoc :review-id (review-id state))
|
||||
(assoc :anchor {:type :area :area area}))))))))
|
||||
|
||||
;; --- Activity
|
||||
@ -223,7 +223,7 @@
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rp/cmd! :get-pull-request-activity {:id pr-id})
|
||||
(->> (rp/cmd! :get-branch-review-activity {:id pr-id})
|
||||
(rx/map (partial activity-fetched pr-id))
|
||||
(rx/catch (fn [_]
|
||||
(rx/of (fn [state]
|
||||
|
||||
@ -352,7 +352,7 @@
|
||||
objects (dsh/lookup-page-objects state (:page-id params))
|
||||
params (-> params
|
||||
(select-keys [:title :page-id :frame-id :shape-id :assignee-id
|
||||
:pull-request-id :thread-id :comment-id :position])
|
||||
:review-id :thread-id :comment-id :position])
|
||||
;; the root of the page is the canvas: no layer
|
||||
(update :shape-id #(when (not= uuid/zero %) %))
|
||||
(update :frame-id #(or % uuid/zero))
|
||||
@ -368,7 +368,7 @@
|
||||
(rx/concat
|
||||
(rx/of (ev/event {::ev/name "create-task"
|
||||
:from-thread thread?
|
||||
:in-review (some? (:pull-request-id params))}))
|
||||
:in-review (some? (:review-id params))}))
|
||||
(->> (rp/cmd! :create-task params)
|
||||
(rx/mapcat (fn [task]
|
||||
(rx/concat
|
||||
@ -675,9 +675,9 @@
|
||||
(filter #(and (to-do? %) (= profile-id (:assignee-id %))) tasks))
|
||||
|
||||
(defn review-tasks
|
||||
"The tasks of the design review `pull-request-id`."
|
||||
[tasks pull-request-id]
|
||||
(filter #(= pull-request-id (:pull-request-id %)) tasks))
|
||||
"The tasks of the design review `review-id`."
|
||||
[tasks review-id]
|
||||
(filter #(= review-id (:review-id %)) tasks))
|
||||
|
||||
(defn sort-tasks
|
||||
"Open work first (oldest first), then the tasks to verify, then the
|
||||
|
||||
@ -196,7 +196,9 @@
|
||||
team-id (some-> params :team-id uuid/parse*)
|
||||
file-id (some-> params :file-id uuid/parse*)
|
||||
page-id (some-> params :page-id uuid/parse*)
|
||||
pr-id (some-> params :pr-id uuid/parse*)
|
||||
;; review-request emails link with review-id; the app's own
|
||||
;; navigation still writes pr-id
|
||||
pr-id (some-> (or (:review-id params) (:pr-id params)) uuid/parse*)
|
||||
task-id (some-> params :task-id uuid/parse*)
|
||||
layout (some-> params :layout keyword)]
|
||||
[:> team-container* {:team-id team-id}
|
||||
@ -212,7 +214,7 @@
|
||||
(let [params (get params :query)
|
||||
index (some-> (rt/get-query-param params :index) parse-long)
|
||||
share-id (some-> (:share-id params) uuid/parse*)
|
||||
pr-id (some-> (:pr-id params) uuid/parse*)
|
||||
pr-id (some-> (or (:review-id params) (:pr-id params)) uuid/parse*)
|
||||
section (or (some-> (:section params) keyword)
|
||||
:interactions)
|
||||
|
||||
|
||||
@ -1068,8 +1068,8 @@
|
||||
:position (:position parent)
|
||||
:thread-id (:id parent)
|
||||
:comment-id (:id comment)
|
||||
:pull-request-id (when (= "open" (:pull-request-status parent))
|
||||
(:pull-request-id parent))
|
||||
:review-id (when (= "open" (:review-status parent))
|
||||
(:review-id parent))
|
||||
:title (subs text 0 (min 250 (count text)))})))))]
|
||||
|
||||
[:div {:class (stl/css :floating-thread-item-wrapper)}
|
||||
@ -1206,8 +1206,8 @@
|
||||
[:> comment-floating-thread-header* {:thread thread
|
||||
:origin origin}]]
|
||||
|
||||
(when (some? (:pull-request-id thread))
|
||||
[:> review-label* {:label (or (:pull-request-title thread)
|
||||
(when (some? (:review-id thread))
|
||||
[:> review-label* {:label (or (:review-title thread)
|
||||
(tr "workspace.review.design-review"))}])
|
||||
|
||||
;; the workspace passes what a message shows about its task
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
|
||||
{:keys [branch phase selected]} mode
|
||||
{:keys [status diff resolutions]} diff-st
|
||||
incoming? (= :main->branch (:direction diff-st))
|
||||
incoming? (= :source->branch (:direction diff-st))
|
||||
excluded (dwb/diff-excluded diff-st)
|
||||
reviewed (or (:reviewed diff-st) #{})
|
||||
active (:filter mode)
|
||||
@ -94,10 +94,10 @@
|
||||
branch changed and has what main itself changed."
|
||||
[objects page-id items other incoming]
|
||||
(let [on-page (fn [items] (filterv #(= page-id (:page-id %)) items))
|
||||
[own others] (if incoming [:main :branch] [:branch :main])]
|
||||
[own others] (if incoming [:source :branch] [:branch :source])]
|
||||
(-> objects
|
||||
(brs/side-objects (on-page items) :main :branch own)
|
||||
(brs/side-objects (on-page other) :main :branch others))))
|
||||
(brs/side-objects (on-page items) :source :branch own)
|
||||
(brs/side-objects (on-page other) :source :branch others))))
|
||||
|
||||
(defn main-extent
|
||||
"The rect that holds every layer of `main` (`main-objects`), nil for an
|
||||
@ -147,7 +147,7 @@
|
||||
(brc/selectable-item? %)
|
||||
(not (contains? excluded (:key %))))
|
||||
(:items model))
|
||||
:main :branch :main))
|
||||
:source :branch :source))
|
||||
result
|
||||
(cond
|
||||
(:hidden mode)
|
||||
|
||||
@ -120,14 +120,14 @@
|
||||
[{:keys [comparison]}]
|
||||
(let [{:keys [mode status incoming model selected excluded reviewed copies]} comparison
|
||||
counts (:counts mode)
|
||||
direction (if incoming :main->branch :branch->main)
|
||||
direction (if incoming :source->branch :branch->source)
|
||||
tabs (mf/with-memo [counts]
|
||||
[{:id "branch->main"
|
||||
[{:id "branch->source"
|
||||
:label (tab-label (tr "workspace.compare.direction.branch")
|
||||
(get counts :branch->main))}
|
||||
{:id "main->branch"
|
||||
(get counts :branch->source))}
|
||||
{:id "source->branch"
|
||||
:label (tab-label (tr "workspace.compare.direction.main")
|
||||
(get counts :main->branch))}])
|
||||
(get counts :source->branch))}])
|
||||
follows (mf/with-memo [copies]
|
||||
(brc/copy-follow-counts copies))]
|
||||
[:> tab-switcher* {:tabs tabs
|
||||
@ -172,7 +172,7 @@
|
||||
[{:keys [comparison]}]
|
||||
(let [{:keys [mode conflicts selected resolutions]} comparison
|
||||
total (count (:conflicts conflicts))
|
||||
on-all-main (mf/use-fn (mf/deps comparison) #(cc/keep-all comparison :main))
|
||||
on-all-main (mf/use-fn (mf/deps comparison) #(cc/keep-all comparison :source))
|
||||
on-all-branch (mf/use-fn (mf/deps comparison) #(cc/keep-all comparison :branch))]
|
||||
(if (zero? total)
|
||||
[:div {:class (stl/css :empty)}
|
||||
|
||||
@ -327,9 +327,9 @@
|
||||
resolving? (= phase :resolve)
|
||||
hidden? (:hidden mode)
|
||||
loaded? (= status :loaded)
|
||||
direction (if incoming :main->branch :branch->main)
|
||||
direction (if incoming :source->branch :branch->source)
|
||||
total (get-in model [:counts :all])
|
||||
other-dir (if incoming :branch->main :main->branch)
|
||||
other-dir (if incoming :branch->source :source->branch)
|
||||
;; the changes of the other direction come with every diff, so
|
||||
;; its tab can count them before it is shown
|
||||
other-total (mf/with-memo [(:other-changes mode) (:other-conflicts mode) data]
|
||||
|
||||
@ -115,20 +115,20 @@
|
||||
(:description pr)])]))
|
||||
|
||||
(defn- verdict-label
|
||||
[{:keys [state stale]}]
|
||||
[{:keys [verdict stale]}]
|
||||
(cond
|
||||
stale (tr "workspace.pull-requests.review-state.stale")
|
||||
(= "approved" state) (tr "workspace.pull-requests.review-state.approved")
|
||||
(= "changes-requested" state) (tr "workspace.pull-requests.review-state.changes-requested")
|
||||
:else (tr "workspace.pull-requests.review-state.pending")))
|
||||
stale (tr "workspace.pull-requests.review-state.stale")
|
||||
(= "approved" verdict) (tr "workspace.pull-requests.review-state.approved")
|
||||
(= "changes-requested" verdict) (tr "workspace.pull-requests.review-state.changes-requested")
|
||||
:else (tr "workspace.pull-requests.review-state.pending")))
|
||||
|
||||
(defn- verdict-tone
|
||||
[{:keys [state stale]}]
|
||||
[{:keys [verdict stale]}]
|
||||
(cond
|
||||
stale "neutral"
|
||||
(= "approved" state) "success"
|
||||
(= "changes-requested" state) "warning"
|
||||
:else "neutral"))
|
||||
stale "neutral"
|
||||
(= "approved" verdict) "success"
|
||||
(= "changes-requested" verdict) "warning"
|
||||
:else "neutral"))
|
||||
|
||||
(mf/defc reviewers-block*
|
||||
"The reviewers of the review and their verdicts; its author and the
|
||||
@ -229,7 +229,7 @@
|
||||
(tr "workspace.review.details.last-change-by"
|
||||
(ct/timeago (:created-at last-save))
|
||||
(rvc/profile-name profiles (:profile-id last-save)))
|
||||
(ct/timeago (:review-updated-at pr)))]]]
|
||||
(ct/timeago (:pinned-at pr)))]]]
|
||||
|
||||
(when (and (pos? missing) (= "open" (:status pr)))
|
||||
[:> context-notification* {:level :warning :appearance :ghost}
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
"Whether the review layer draws `thread` instead of the plain comment
|
||||
bubbles: a thread of a design review, or one attached to a task."
|
||||
[task-thread-ids thread]
|
||||
(or (some? (:pull-request-id thread))
|
||||
(or (some? (:review-id thread))
|
||||
(contains? task-thread-ids (:id thread))))
|
||||
|
||||
(defn- screen-style
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
[{:keys [thread objects is-open show-review]}]
|
||||
(let [owner (d/without-nils (dcmt/get-owner thread))
|
||||
replies (dec (or (:count-comments thread) 1))
|
||||
review? (some? (:pull-request-id thread))
|
||||
review? (some? (:review-id thread))
|
||||
|
||||
on-click
|
||||
(mf/use-fn
|
||||
@ -70,7 +70,7 @@
|
||||
[:> layer-chip* {:label (rvc/thread-anchor-label objects thread)
|
||||
:icon (rvc/thread-anchor-icon thread)}])
|
||||
:review (when (and show-review review?)
|
||||
(or (:pull-request-title thread)
|
||||
(or (:review-title thread)
|
||||
(tr "workspace.review.design-review")))
|
||||
:is-review review?
|
||||
:is-open is-open
|
||||
@ -143,10 +143,10 @@
|
||||
;; --- Tasks
|
||||
|
||||
(mf/defc tasks-tab*
|
||||
"The tasks of the review (`pull-request-id`), or of the file when there
|
||||
is none: its progress, filters and list. With `show-review`, each task
|
||||
"The tasks of the review (`review-id`), or of the file when there is
|
||||
none: its progress, filters and list. With `show-review`, each task
|
||||
names the design review it belongs to."
|
||||
[{:keys [tasks pull-request-id grouped show-review]}]
|
||||
[{:keys [tasks review-id grouped show-review]}]
|
||||
(let [profile (mf/deref refs/profile)
|
||||
local (mf/deref refs/review-local)
|
||||
selected (mf/deref refs/selected-shapes)
|
||||
@ -175,7 +175,7 @@
|
||||
|
||||
on-new-task
|
||||
(mf/use-fn
|
||||
(mf/deps selected objects page-id pull-request-id)
|
||||
(mf/deps selected objects page-id review-id)
|
||||
(fn [_]
|
||||
(let [shape (some->> (first selected) (get objects))]
|
||||
(if (some? shape)
|
||||
@ -183,7 +183,7 @@
|
||||
{:page-id page-id
|
||||
:frame-id (if (cfh/frame-shape? shape) (:id shape) (:frame-id shape))
|
||||
:shape-id (:id shape)
|
||||
:pull-request-id pull-request-id}))
|
||||
:review-id review-id}))
|
||||
;; no layer chosen yet: the task tool picks it on the canvas
|
||||
(st/emit! (dwrv/set-tool :task))))))]
|
||||
|
||||
@ -254,7 +254,7 @@
|
||||
tab (get local :panel-tab :inspect)
|
||||
|
||||
threads (mf/with-memo [threads* pr-id]
|
||||
(filterv #(= pr-id (:pull-request-id %)) (vals threads*)))
|
||||
(filterv #(= pr-id (:review-id %)) (vals threads*)))
|
||||
tasks (mf/with-memo [tasks* pr-id]
|
||||
(vec (dwtk/sort-tasks (dwtk/review-tasks (vals tasks*) pr-id))))
|
||||
|
||||
@ -290,5 +290,5 @@
|
||||
[:div {:class (stl/css :inspect-tab)} inspect]
|
||||
[:div {:class (stl/css :review-tab-content)}
|
||||
(if (= tab :tasks)
|
||||
[:> tasks-tab* {:tasks tasks :pull-request-id pr-id}]
|
||||
[:> tasks-tab* {:tasks tasks :review-id pr-id}]
|
||||
[:> comments-tab* {:threads threads}])])]])))
|
||||
|
||||
@ -213,7 +213,7 @@
|
||||
[{:keys [task data profiles is-selected show-review on-open]}]
|
||||
(let [objects (page-objects data (:page-id task))
|
||||
assignee (get profiles (:assignee-id task))
|
||||
review? (some? (:pull-request-id task))
|
||||
review? (some? (:review-id task))
|
||||
|
||||
on-click
|
||||
(mf/use-fn
|
||||
@ -296,7 +296,7 @@
|
||||
(tr "workspace.tasks.event.relinked" actor (:shape-name payload)))
|
||||
"layer-deleted" (tr "workspace.tasks.event.layer-deleted" actor (:shape-name payload))
|
||||
"layer-restored" (tr "workspace.tasks.event.layer-restored" actor (:shape-name payload))
|
||||
"moved-to-main" (tr "workspace.tasks.event.moved-to-main" (:branch-name payload))
|
||||
"merged" (tr "workspace.tasks.event.moved-to-main" (:branch-name payload))
|
||||
"deleted" (tr "workspace.tasks.event.deleted" actor)
|
||||
nil)))
|
||||
|
||||
@ -305,7 +305,7 @@
|
||||
(case type
|
||||
"layer-deleted" i/triangle-alert
|
||||
"status" (if (= "done" (:to payload)) i/tick i/view-as-list)
|
||||
"moved-to-main" i/git-merge
|
||||
"merged" i/git-merge
|
||||
"deleted" i/delete
|
||||
i/view-as-list))
|
||||
|
||||
@ -395,7 +395,7 @@
|
||||
(mf/use-fn
|
||||
(mf/deps task file-id)
|
||||
(fn [_]
|
||||
(st/emit! (dwpr/open-pull-request {:id (:pull-request-id task)
|
||||
(st/emit! (dwpr/open-pull-request {:id (:review-id task)
|
||||
:source-file-id file-id}))))]
|
||||
|
||||
[:div {:class (stl/css :task-state)}
|
||||
@ -412,7 +412,7 @@
|
||||
[:> text* {:as "span" :typography t/body-small :class (stl/css :task-state-text)}
|
||||
assignee]
|
||||
[:> assignee-menu* {:task task :label assignee}])
|
||||
(when (and (some? (:pull-request-id task))
|
||||
(when (and (some? (:review-id task))
|
||||
(= "open" (:review-status task))
|
||||
(nil? preview))
|
||||
[:div {:class (stl/css :task-state-origin)}
|
||||
@ -675,9 +675,9 @@
|
||||
"The tasks of the branch workspace list: those of each design review
|
||||
first (the open review first), then the others."
|
||||
[tasks]
|
||||
(let [[review other] ((juxt filter remove) (comp some? :pull-request-id) tasks)]
|
||||
(let [[review other] ((juxt filter remove) (comp some? :review-id) tasks)]
|
||||
(concat
|
||||
(->> (group-by :pull-request-id review)
|
||||
(->> (group-by :review-id review)
|
||||
(sort-by (fn [[_ items]] (if (= "open" (:review-status (first items))) 0 1)))
|
||||
(map (fn [[id items]] {:id id :title (:review-title (first items)) :tasks items})))
|
||||
(when (seq other)
|
||||
|
||||
@ -415,11 +415,11 @@
|
||||
them as entries of their own; this ties them to their cause. `objects`
|
||||
is the page as the side that holds the layer has it, `inner` the
|
||||
entries folded under it (`fold-cascades`), and `incoming` says the
|
||||
changes are main's, going to the branch, rather than the branch's
|
||||
going to main."
|
||||
changes are the source's, going to the branch, rather than the branch's
|
||||
going to the source."
|
||||
[item items objects inner incoming]
|
||||
(let [from (if incoming :branch :main)
|
||||
to (if incoming :main :branch)
|
||||
(let [from (if incoming :branch :source)
|
||||
to (if incoming :source :branch)
|
||||
deleted? (= :deleted (:status item))
|
||||
ids (into #{(:id item)} (map :id) inner)
|
||||
page-id (:page-id item)
|
||||
@ -649,23 +649,23 @@
|
||||
(defn- attr-sources
|
||||
"Every changed attr of a conflict with who changed it, using the base
|
||||
value both sides started from. `:conflict` attrs moved on both sides; a
|
||||
`:main` or `:branch` attr moved on that side alone, so its value is not
|
||||
in doubt. Without a base (both sides added the entity) every attr
|
||||
`:source` or `:branch` attr moved on that side alone, so its value is
|
||||
not in doubt. Without a base (both sides added the entity) every attr
|
||||
conflicts."
|
||||
[conflict]
|
||||
(let [base (:base conflict)
|
||||
has-base? (map? base)]
|
||||
(->> (:changed-attrs conflict)
|
||||
(map (fn [[attr {:keys [main branch]}]]
|
||||
(map (fn [[attr {:keys [source branch]}]]
|
||||
(let [base-v (get base attr)]
|
||||
{:attr attr
|
||||
:base base-v
|
||||
:main main
|
||||
:source source
|
||||
:branch branch
|
||||
:source (cond
|
||||
:origin (cond
|
||||
(not has-base?) :conflict
|
||||
(= base-v main) :branch
|
||||
(= base-v branch) :main
|
||||
(= base-v source) :branch
|
||||
(= base-v branch) :source
|
||||
:else :conflict)})))
|
||||
(sort-by (comp attr-label :attr))
|
||||
vec)))
|
||||
@ -678,21 +678,21 @@
|
||||
[conflict]
|
||||
(let [all (attr-sources conflict)
|
||||
visible (filterv #(not (contains? technical-attrs (:attr %))) all)]
|
||||
(if (and (not-any? #(= :conflict (:source %)) visible)
|
||||
(some #(= :conflict (:source %)) all))
|
||||
(if (and (not-any? #(= :conflict (:origin %)) visible)
|
||||
(some #(= :conflict (:origin %)) all))
|
||||
all
|
||||
visible)))
|
||||
|
||||
(defn conflicting-attrs
|
||||
[rows]
|
||||
(into [] (comp (filter #(= :conflict (:source %))) (map :attr)) rows))
|
||||
(into [] (comp (filter #(= :conflict (:origin %))) (map :attr)) rows))
|
||||
|
||||
(defn- hidden-conflicts
|
||||
"The conflicting attrs `conflict-attr-rows` does not show."
|
||||
[conflict]
|
||||
(let [shown (into #{} (map :attr) (conflict-attr-rows conflict))]
|
||||
(into []
|
||||
(comp (filter #(= :conflict (:source %)))
|
||||
(comp (filter #(= :conflict (:origin %)))
|
||||
(map :attr)
|
||||
(remove shown))
|
||||
(attr-sources conflict))))
|
||||
@ -704,15 +704,15 @@
|
||||
conflicting attrs comes out resolved."
|
||||
[conflict]
|
||||
(into {}
|
||||
(comp (remove #(= :conflict (:source %)))
|
||||
(map (juxt :attr :source)))
|
||||
(comp (remove #(= :conflict (:origin %)))
|
||||
(map (juxt :attr :origin)))
|
||||
(attr-sources conflict)))
|
||||
|
||||
(defn per-attr?
|
||||
"Whether a conflict can be decided property by property."
|
||||
[conflict]
|
||||
(and (seq (:changed-attrs conflict))
|
||||
(map? (:main conflict))
|
||||
(map? (:source conflict))
|
||||
(map? (:branch conflict))))
|
||||
|
||||
(defn choose-attr
|
||||
@ -720,10 +720,10 @@
|
||||
`res` (nil, a whole-side keyword or a per-attr map)."
|
||||
[conflict res attr side]
|
||||
(let [seed (cond
|
||||
(map? res) res
|
||||
(= res :branch) (zipmap (keys (:changed-attrs conflict)) (repeat :branch))
|
||||
(= res :main) (zipmap (keys (:changed-attrs conflict)) (repeat :main))
|
||||
:else (prefill-resolution conflict))]
|
||||
(map? res) res
|
||||
(= res :branch) (zipmap (keys (:changed-attrs conflict)) (repeat :branch))
|
||||
(= res :source) (zipmap (keys (:changed-attrs conflict)) (repeat :source))
|
||||
:else (prefill-resolution conflict))]
|
||||
(reduce (fn [res hidden] (assoc res hidden side))
|
||||
(assoc seed attr side)
|
||||
(hidden-conflicts conflict))))
|
||||
@ -740,12 +740,12 @@
|
||||
side))
|
||||
|
||||
(defn attr-choice
|
||||
"Currently-selected side (`:main`/`:branch`) for `attr` under resolution
|
||||
`res`, or nil when undecided."
|
||||
"Currently-selected side (`:source`/`:branch`) for `attr` under
|
||||
resolution `res`, or nil when undecided."
|
||||
[res attr]
|
||||
(cond
|
||||
(= res :branch) :branch
|
||||
(= res :main) :main
|
||||
(= res :source) :source
|
||||
(map? res) (get res attr)
|
||||
:else nil))
|
||||
|
||||
@ -756,14 +756,14 @@
|
||||
[conflict res]
|
||||
(let [rows (conflict-attr-rows conflict)]
|
||||
(into []
|
||||
(keep (fn [{:keys [attr base main branch]}]
|
||||
(keep (fn [{:keys [attr base source branch]}]
|
||||
(let [choice (attr-choice res attr)
|
||||
has-base? (map? (:base conflict))]
|
||||
(cond
|
||||
(and (= choice :branch) (or (not has-base?) (not= main base)))
|
||||
{:attr attr :side :main :value main}
|
||||
(and (= choice :branch) (or (not has-base?) (not= source base)))
|
||||
{:attr attr :side :source :value source}
|
||||
|
||||
(and (= choice :main) (or (not has-base?) (not= branch base)))
|
||||
(and (= choice :source) (or (not has-base?) (not= branch base)))
|
||||
{:attr attr :side :branch :value branch}
|
||||
|
||||
:else nil))))
|
||||
@ -774,7 +774,7 @@
|
||||
this side edited it, `:dropped` when only the other side edited it (so
|
||||
keeping this side drops that edit), or nil when neither did."
|
||||
[conflict side]
|
||||
(let [other (if (= side :main) :branch :main)
|
||||
(let [other (if (= side :source) :branch :source)
|
||||
base (content-paragraphs (get-in conflict [:base :content]))
|
||||
mine (content-paragraphs (get-in conflict [side :content]))
|
||||
theirs (content-paragraphs (get-in conflict [other :content]))]
|
||||
@ -808,13 +808,13 @@
|
||||
[conflict]
|
||||
(boolean
|
||||
(and (per-attr? conflict)
|
||||
(some #(and (= :content (:attr %)) (= :conflict (:source %)))
|
||||
(some #(and (= :content (:attr %)) (= :conflict (:origin %)))
|
||||
(conflict-attr-rows conflict)))))
|
||||
|
||||
(defn dropped-paragraphs
|
||||
"The paragraph edits keeping `side` drops."
|
||||
[conflict side]
|
||||
(let [other (if (= side :main) :branch :main)]
|
||||
(let [other (if (= side :source) :branch :source)]
|
||||
(filterv #(= :kept (:status %)) (paragraph-rows conflict other))))
|
||||
|
||||
(defn loses-work?
|
||||
@ -823,7 +823,7 @@
|
||||
[conflict]
|
||||
(boolean
|
||||
(and (text-conflict? conflict)
|
||||
(seq (dropped-paragraphs conflict :main))
|
||||
(seq (dropped-paragraphs conflict :source))
|
||||
(seq (dropped-paragraphs conflict :branch)))))
|
||||
|
||||
(defn pending-attr
|
||||
@ -1005,13 +1005,13 @@
|
||||
[reason]
|
||||
(case reason
|
||||
:follows-component (tr "workspace.branches.review.copies.reason.follows-component")
|
||||
:override-main (tr "workspace.branches.review.copies.reason.override-main")
|
||||
:override-source (tr "workspace.branches.review.copies.reason.override-main")
|
||||
:override-branch (tr "workspace.branches.review.copies.reason.override-branch")
|
||||
(tr "workspace.branches.review.copies.reason.override-both")))
|
||||
|
||||
(defn side-label
|
||||
[side]
|
||||
(if (= side :main)
|
||||
(if (= side :source)
|
||||
(tr "workspace.branches.review.side.main")
|
||||
(tr "workspace.branches.review.side.branch")))
|
||||
|
||||
@ -1061,8 +1061,8 @@
|
||||
{}
|
||||
(sort-by (comp group-label key) (:keeps copy)))]
|
||||
(reduce (fn [acc [slot {:keys [side reason]}]]
|
||||
(if (and (contains? #{:main :branch} side)
|
||||
(contains? #{:override-main :override-branch} reason))
|
||||
(if (and (contains? #{:source :branch} side)
|
||||
(contains? #{:override-source :override-branch} reason))
|
||||
(update acc side (fnil conj []) (token-slot-label slot))
|
||||
acc))
|
||||
groups
|
||||
|
||||
@ -149,7 +149,7 @@
|
||||
(mf/defc side-pill*
|
||||
"The name of a side: main, or the branch by its name."
|
||||
[{:keys [side branch-name is-review]}]
|
||||
(if (= side :main)
|
||||
(if (= side :source)
|
||||
[:> branch-pill* {:label (tr "workspace.branches.main") :is-main true}]
|
||||
[:> branch-pill* {:label (or branch-name (tr "workspace.branches.review.side.branch"))
|
||||
:is-review (boolean is-review)}]))
|
||||
@ -183,7 +183,7 @@
|
||||
values (get-in conflict [:changed-attrs attr])
|
||||
on-choose (mf/use-fn (mf/deps attr on-pick) #(on-pick attr %))]
|
||||
[:div {:class (stl/css :options) :role "radiogroup"}
|
||||
(for [side [:main :branch]]
|
||||
(for [side [:source :branch]]
|
||||
[:> option-card* {:key (name side)
|
||||
:side side
|
||||
:branch-name branch-name
|
||||
@ -201,7 +201,7 @@
|
||||
(let [choice (brc/attr-choice res :content)
|
||||
on-choose (mf/use-fn (mf/deps on-pick) #(on-pick :content %))]
|
||||
[:div {:class (stl/css :options) :role "radiogroup"}
|
||||
(for [side [:main :branch]
|
||||
(for [side [:source :branch]
|
||||
:let [rows (brc/paragraph-rows conflict side)
|
||||
lost (brc/dropped-paragraphs conflict side)]]
|
||||
[:> option-card* {:key (name side)
|
||||
@ -232,7 +232,7 @@
|
||||
deleted the entity, or both added it differently."
|
||||
[{:keys [conflict res branch-name is-review on-choose on-preview]}]
|
||||
[:div {:class (stl/css :options) :role "radiogroup"}
|
||||
(for [side [:main :branch]]
|
||||
(for [side [:source :branch]]
|
||||
[:> option-card* {:key (name side)
|
||||
:side side
|
||||
:branch-name branch-name
|
||||
@ -243,7 +243,7 @@
|
||||
:on-choose on-choose
|
||||
:on-preview on-preview}
|
||||
[:> text* {:as "span" :typography t/body-small :class (stl/css :muted)}
|
||||
(if (= side :main)
|
||||
(if (= side :source)
|
||||
(tr "workspace.branches.resolve.keep-main-version")
|
||||
(tr "workspace.branches.resolve.keep-branch-version"))]])])
|
||||
|
||||
@ -266,9 +266,9 @@
|
||||
{::mf/private true}
|
||||
[{:keys [rows res branch-name selected on-pick on-select]}]
|
||||
[:div {:class (stl/css :attrs)}
|
||||
(for [{:keys [attr main branch source]} rows
|
||||
(for [{:keys [attr source branch origin]} rows
|
||||
:let [choice (brc/attr-choice res attr)
|
||||
conflicting? (= source :conflict)]]
|
||||
conflicting? (= origin :conflict)]]
|
||||
[:div {:class (stl/css-case :attr true
|
||||
:is-conflicting (and conflicting? (nil? choice))
|
||||
:is-selected (= attr selected))
|
||||
@ -285,7 +285,7 @@
|
||||
[:> tag* {:tone "success"} (tr "workspace.branches.resolve.tag.your-choice")]
|
||||
conflicting?
|
||||
[:> tag* {:tone "warning"} (tr "workspace.branches.resolve.tag.conflict")]
|
||||
(= source :main)
|
||||
(= origin :source)
|
||||
[:> tag* {:tone "purple"}
|
||||
(tr "workspace.branches.resolve.tag.from" (tr "workspace.branches.compare.main"))]
|
||||
:else
|
||||
@ -294,15 +294,15 @@
|
||||
(or branch-name (tr "workspace.branches.compare.branch")))])]
|
||||
[:div {:class (stl/css :attr-values)}
|
||||
[:> pick-button* {:attr attr
|
||||
:side :main
|
||||
:value main
|
||||
:choice (or choice (when-not conflicting? source))
|
||||
:side :source
|
||||
:value source
|
||||
:choice (or choice (when-not conflicting? origin))
|
||||
:is-conflicting conflicting?
|
||||
:on-pick on-pick}]
|
||||
[:> pick-button* {:attr attr
|
||||
:side :branch
|
||||
:value branch
|
||||
:choice (or choice (when-not conflicting? source))
|
||||
:choice (or choice (when-not conflicting? origin))
|
||||
:is-conflicting conflicting?
|
||||
:on-pick on-pick}]]])])
|
||||
|
||||
@ -322,7 +322,7 @@
|
||||
:as "span"
|
||||
:typography t/body-small
|
||||
:class (stl/css :outcome-line)}
|
||||
(if (= side :main)
|
||||
(if (= side :source)
|
||||
(tr "workspace.branches.resolve.drops.main-short" (str/lower (brc/attr-label attr)))
|
||||
(tr "workspace.branches.resolve.drops.branch-short" (str/lower (brc/attr-label attr))))
|
||||
" "
|
||||
@ -385,7 +385,7 @@
|
||||
|
||||
;; which value is whose: main first, then the branch
|
||||
[:div {:class (stl/css :legend)}
|
||||
[:> side-pill* {:side :main}]
|
||||
[:> side-pill* {:side :source}]
|
||||
[:> side-pill* {:side :branch :branch-name branch-name :is-review is-review}]]
|
||||
|
||||
(cond
|
||||
|
||||
@ -182,9 +182,9 @@
|
||||
open-objs
|
||||
(brs/side-objects open-objs
|
||||
(filterv #(= (:page-id item) (:page-id %)) items)
|
||||
(if (= open-side :main) :branch :main)
|
||||
(if (= open-side :source) :branch :source)
|
||||
open-side
|
||||
(if incoming :main :branch))))
|
||||
(if incoming :source :branch))))
|
||||
shape (get objects (:id item))
|
||||
page (get-in data [:pages-index (:page-id item) :name])
|
||||
deleted? (= :deleted (:status item))
|
||||
@ -259,8 +259,8 @@
|
||||
(not own?)
|
||||
(conj (tr "workspace.branches.review.copies.follows-all"))
|
||||
|
||||
(seq (:main keeps))
|
||||
(conj (tr "workspace.branches.review.copies.keeps-main" (lower-list (:main keeps))))
|
||||
(seq (:source keeps))
|
||||
(conj (tr "workspace.branches.review.copies.keeps-main" (lower-list (:source keeps))))
|
||||
|
||||
(seq (:branch keeps))
|
||||
(conj (tr "workspace.branches.review.copies.keeps-branch" (lower-list (:branch keeps))))
|
||||
@ -355,7 +355,7 @@
|
||||
[label
|
||||
(mf/html
|
||||
[:span {:class (stl/css :settled-value)}
|
||||
[:> tag* {:tone (if (= side :main) "purple" "accent")}
|
||||
[:> tag* {:tone (if (= side :source) "purple" "accent")}
|
||||
(brc/side-label side)]
|
||||
[:span (brc/reason-label reason)]])])
|
||||
rows)}]
|
||||
|
||||
@ -63,15 +63,15 @@
|
||||
|
||||
(mf/defc value-steps*
|
||||
"Each property of a change as `before → after`, the name of the
|
||||
property over its two values. `incoming` says the change is main's,
|
||||
going to the branch: its new value is then main's."
|
||||
property over its two values. `incoming` says the change is the
|
||||
source's, going to the branch: its new value is then the source's."
|
||||
[{:keys [attrs incoming]}]
|
||||
[:div {:class (stl/css :steps)}
|
||||
(for [[attr {:keys [main branch]}] attrs]
|
||||
(for [[attr {:keys [source branch]}] attrs]
|
||||
[:div {:class (stl/css :steps-row) :key (str attr)}
|
||||
[:> text* {:as "span" :typography t/body-small :class (stl/css :steps-name)}
|
||||
(brc/attr-label attr)]
|
||||
[:div {:class (stl/css :steps-values)}
|
||||
[:> value-chip* {:value (if incoming branch main) :is-old true}]
|
||||
[:> value-chip* {:value (if incoming branch source) :is-old true}]
|
||||
[:> i/icon* {:icon-id i/arrow-long-right :size "s" :class (stl/css :steps-arrow)}]
|
||||
[:> value-chip* {:value (if incoming main branch)}]]])])
|
||||
[:> value-chip* {:value (if incoming source branch)}]]])])
|
||||
|
||||
@ -241,7 +241,7 @@
|
||||
(cond
|
||||
(bm/conflict-resolved? conflict res)
|
||||
(cond
|
||||
(= res :main) (tr "workspace.branches.resolve.row.kept-main")
|
||||
(= res :source) (tr "workspace.branches.resolve.row.kept-main")
|
||||
(= res :branch) (tr "workspace.branches.resolve.row.kept-branch")
|
||||
(seq drops) (tr "workspace.branches.resolve.row.drops"
|
||||
(str/lower (str/join ", " (map (comp brc/attr-label :attr) drops))))
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#{:path :bool})
|
||||
|
||||
(defn- with-values
|
||||
"`entity` with each attr of `attrs` (`{attr {:main .. :branch ..}}`)
|
||||
"`entity` with each attr of `attrs` (`{attr {:source .. :branch ..}}`)
|
||||
set to the value `side-of` picks a side for; an attr it picks no side
|
||||
for stays as it is."
|
||||
[entity attrs side-of]
|
||||
@ -48,11 +48,11 @@
|
||||
entity)))
|
||||
|
||||
(defn side-entity
|
||||
"One side (`:main` or `:branch`) of diff entry `item`. A conflict carries
|
||||
both; a clean change carries the attrs that differ, so the side the open
|
||||
file does not hold is the open entity with those attrs swapped in. An
|
||||
entry that does not exist on a side has no entity there: `origin` is
|
||||
the side that made the change, so what it added is missing on the
|
||||
"One side (`:source` or `:branch`) of diff entry `item`. A conflict
|
||||
carries both; a clean change carries the attrs that differ, so the side
|
||||
the open file does not hold is the open entity with those attrs swapped
|
||||
in. An entry that does not exist on a side has no entity there: `origin`
|
||||
is the side that made the change, so what it added is missing on the
|
||||
other one and what it deleted is missing on its own. An added or
|
||||
deleted shape the open file lacks comes whole in the entry's `:shape`."
|
||||
[item side open-side origin open-entity]
|
||||
@ -122,11 +122,11 @@
|
||||
open (get objects id)]
|
||||
(cond
|
||||
(not= :shape (:kind conflict)) objects
|
||||
(= :main res) (put-entity objects id (:main conflict))
|
||||
(= :source res) (put-entity objects id (:source conflict))
|
||||
(and (map? res) (some? open))
|
||||
(put-entity objects id
|
||||
(with-values open (:changed-attrs conflict)
|
||||
#(when (= :main (get res %)) :main)))
|
||||
#(when (= :source (get res %)) :source)))
|
||||
:else objects)))
|
||||
objects
|
||||
conflicts))
|
||||
|
||||
@ -48,11 +48,11 @@
|
||||
(defn- display-state
|
||||
"The single most relevant label for a pull request: its stored status
|
||||
for finished ones, the aggregate review verdict for open ones."
|
||||
[{:keys [status review-state]}]
|
||||
[{:keys [status overall-verdict]}]
|
||||
(case status
|
||||
"merged" :merged
|
||||
"closed" :closed
|
||||
(case review-state
|
||||
(case overall-verdict
|
||||
"changes-requested" :changes-requested
|
||||
"approved" :approved
|
||||
"in-review" :in-review
|
||||
@ -84,7 +84,7 @@
|
||||
"[current-approvals total-reviewers] of a pull request; stale verdicts
|
||||
do not count."
|
||||
[{:keys [reviews]}]
|
||||
[(count (filter #(and (= "approved" (:state %)) (not (:stale %))) reviews))
|
||||
[(count (filter #(and (= "approved" (:verdict %)) (not (:stale %))) reviews))
|
||||
(count reviews)])
|
||||
|
||||
(defn- pr->branch
|
||||
@ -471,7 +471,7 @@
|
||||
[:div {:class (stl/css :pr-info-item)}
|
||||
[:span {:class (stl/css :field-label)} (tr "workspace.pull-requests.info.updated-at")]
|
||||
[:div {:class (stl/css :pr-info-value)}
|
||||
[:span (ct/format-inst (:review-updated-at pr) :localized-date-time)]]]
|
||||
[:span (ct/format-inst (:pinned-at pr) :localized-date-time)]]]
|
||||
|
||||
[:div {:class (stl/css :pr-info-item)}
|
||||
[:span {:class (stl/css :field-label)} (tr "workspace.pull-requests.info.approvals")]
|
||||
@ -491,19 +491,19 @@
|
||||
[:span {:class (stl/css :reviewer-name)}
|
||||
(get reviewer :fullname "—")]
|
||||
[:span {:class (stl/css-case :reviewer-state true
|
||||
:reviewer-approved (and (= "approved" (:state review))
|
||||
:reviewer-approved (and (= "approved" (:verdict review))
|
||||
(not (:stale review)))
|
||||
:reviewer-changes (and (= "changes-requested" (:state review))
|
||||
:reviewer-changes (and (= "changes-requested" (:verdict review))
|
||||
(not (:stale review)))
|
||||
:reviewer-stale (:stale review))}
|
||||
(cond
|
||||
(:stale review)
|
||||
(tr "workspace.pull-requests.review-state.stale")
|
||||
|
||||
(= "approved" (:state review))
|
||||
(= "approved" (:verdict review))
|
||||
(tr "workspace.pull-requests.review-state.approved")
|
||||
|
||||
(= "changes-requested" (:state review))
|
||||
(= "changes-requested" (:verdict review))
|
||||
(tr "workspace.pull-requests.review-state.changes-requested")
|
||||
|
||||
:else
|
||||
@ -628,7 +628,7 @@
|
||||
outdated? (boolean (:outdated pr))
|
||||
|
||||
tasks (mf/with-memo [tasks* pr]
|
||||
(filterv #(= (:id pr) (:pull-request-id %)) (vals tasks*)))
|
||||
(filterv #(= (:id pr) (:review-id %)) (vals tasks*)))
|
||||
closed (count (filter #(contains? #{"verified" "wont-do"} (:status %)) tasks))
|
||||
total (count tasks)
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@
|
||||
(tr "workspace.branches.reviews.merged")]
|
||||
[:> route* {:branch-name (:branch-name merge)}]]
|
||||
;; the merge accepted a design review: name it, it may be gone by now
|
||||
(when-let [title (:pull-request-title merge)]
|
||||
(when-let [title (:review-title merge)]
|
||||
[:div {:class (stl/css :entry-review)}
|
||||
[:> i/icon* {:icon-id i/git-pull-request-arrow :size "s"}]
|
||||
[:span {:class (stl/css :entry-review-title)}
|
||||
@ -306,7 +306,7 @@
|
||||
(mf/with-memo [all-merges filter-v profiles]
|
||||
(filterv #(matches? filter-v [(:branch-name %)
|
||||
(:comment %)
|
||||
(:pull-request-title %)
|
||||
(:review-title %)
|
||||
(get-in profiles [(:merged-by %) :fullname])])
|
||||
all-merges))
|
||||
|
||||
|
||||
@ -33,11 +33,11 @@
|
||||
(mock/stub (fn [cmd params]
|
||||
(swap! calls conj [cmd params])
|
||||
(cond
|
||||
(= cmd :get-branch-diff) (rx/subject)
|
||||
(= cmd :get-file-branch-diff) (rx/subject)
|
||||
(seq (:resolutions params)) (rx/empty)
|
||||
:else (rx/of {:status :conflicts
|
||||
:conflicts [{:id conflict-id}]
|
||||
:main-revn conflict-revn})))))
|
||||
:source-revn conflict-revn})))))
|
||||
|
||||
(defn- make-store
|
||||
[]
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
(defn- branch-cmd
|
||||
[mode]
|
||||
(if (= mode :update) :update-branch-from-main :merge-file-branch))
|
||||
(if (= mode :update) :update-file-branch-from-source :merge-file-branch))
|
||||
|
||||
(defn- open-conflicts!
|
||||
"Ask for a `mode` (`:merge` or `:update`) of `branch` and let the conflict
|
||||
@ -57,14 +57,14 @@
|
||||
(dwb/update-branch-from-main branch)
|
||||
(dwb/merge-branch branch)))
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)
|
||||
(if (= mode :update) :main->branch :branch->main))))
|
||||
(if (= mode :update) :source->branch :branch->source))))
|
||||
|
||||
(defn- apply-resolutions!
|
||||
"Resolve every conflict to main and apply, as the compare mode does."
|
||||
[store mode branch]
|
||||
(ptk/emit! store (dwb/set-conflict-resolutions
|
||||
(into {}
|
||||
(map (fn [conflict] [(:id conflict) :main]))
|
||||
(map (fn [conflict] [(:id conflict) :source]))
|
||||
(get-in @store [:workspace-branch-conflicts :conflicts]))))
|
||||
(let [resolutions (get-in @store [:workspace-branch-diff :resolutions])]
|
||||
(ptk/emit! store (if (= mode :update)
|
||||
@ -96,8 +96,8 @@
|
||||
"the diff fetch has not answered")
|
||||
(apply-resolutions! store mode branch)
|
||||
(let [params (last-params calls mode)]
|
||||
(t/is (= {conflict-id :main} (:resolutions params)))
|
||||
(t/is (= conflict-revn (:expected-main-revn params))
|
||||
(t/is (= {conflict-id :source} (:resolutions params)))
|
||||
(t/is (= conflict-revn (:expected-source-revn params))
|
||||
"the resolutions carry the revn of the conflict answer"))
|
||||
(rx/dispose! store))))
|
||||
(done'))
|
||||
@ -118,9 +118,9 @@
|
||||
(open-conflicts! store mode branch)
|
||||
;; the diff fetch answers, computed at a newer main
|
||||
(ptk/emit! store (dwb/update-branch-diff {:status :loaded
|
||||
:diff {:meta {:main-revn 9}}}))
|
||||
:diff {:meta {:source-revn 9}}}))
|
||||
(apply-resolutions! store mode branch)
|
||||
(t/is (= 9 (:expected-main-revn (last-params calls mode))))
|
||||
(t/is (= 9 (:expected-source-revn (last-params calls mode))))
|
||||
(rx/dispose! store))))
|
||||
(done'))
|
||||
done))))
|
||||
@ -138,7 +138,7 @@
|
||||
store (make-store)]
|
||||
(reset! calls [])
|
||||
(open-conflicts! store mode branch)
|
||||
(t/is (not (contains? (last-params calls mode) :expected-main-revn))
|
||||
(t/is (not (contains? (last-params calls mode) :expected-source-revn))
|
||||
"the first request has neither resolutions nor a diff")
|
||||
;; ask again while the diff is loading, with the conflict
|
||||
;; answer's revn already stored
|
||||
@ -148,7 +148,7 @@
|
||||
(let [params (last-params calls mode)]
|
||||
(t/is (= 2 (count (filter #(= (branch-cmd mode) (first %)) @calls))))
|
||||
(t/is (not (contains? params :resolutions)))
|
||||
(t/is (not (contains? params :expected-main-revn))
|
||||
(t/is (not (contains? params :expected-source-revn))
|
||||
"the stored revn only travels with resolutions"))
|
||||
(rx/dispose! store))))
|
||||
(done'))
|
||||
@ -200,7 +200,7 @@
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
||||
(t/is (= #{k1} (excluded store))))
|
||||
(t/testing "the other direction has a selection of its own"
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch) :main->branch))
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch) :source->branch))
|
||||
(t/is (= #{} (excluded store)))
|
||||
(ptk/emit! store (dwb/toggle-diff-excluded #{k2}))
|
||||
(t/is (= #{k2} (excluded store))))
|
||||
@ -266,11 +266,11 @@
|
||||
|
||||
(def ^:private title
|
||||
{:kind :shape :status :modified :id (uuid/next) :key "shape/p/title"
|
||||
:changed-attrs {:opacity {:main 1 :branch 0.5}}})
|
||||
:changed-attrs {:opacity {:source 1 :branch 0.5}}})
|
||||
|
||||
(def ^:private logo
|
||||
{:kind :shape :status :modified :id (uuid/next) :key "shape/p/logo"
|
||||
:changed-attrs {:rx {:main 0 :branch 8}}})
|
||||
:changed-attrs {:rx {:source 0 :branch 8}}})
|
||||
|
||||
(defn- review-stub
|
||||
"Fake `rp/cmd!` for a comparison that lists `title` and `logo`: the diff
|
||||
@ -280,11 +280,11 @@
|
||||
(mock/stub (fn [cmd params]
|
||||
(swap! calls conj [cmd params])
|
||||
(case cmd
|
||||
:get-branch-diff (rx/of {:changes [title logo] :conflicts []})
|
||||
:get-branch-change-reviews (rx/of @marks)
|
||||
:set-branch-change-review (if fail-set?
|
||||
(rx/throw (ex-info "refused" {}))
|
||||
(rx/of nil))
|
||||
:get-file-branch-diff (rx/of {:changes [title logo] :conflicts []})
|
||||
:get-branch-change-marks (rx/of @marks)
|
||||
:set-branch-change-mark (if fail-set?
|
||||
(rx/throw (ex-info "refused" {}))
|
||||
(rx/of nil))
|
||||
(rx/empty)))))
|
||||
|
||||
(defn- last-call
|
||||
@ -310,8 +310,8 @@
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
||||
(await (async/wait-for-store store #(seq (reviewed store)) "the marks load"))
|
||||
(t/is (= #{(:key title)} (reviewed store)))
|
||||
(t/is (= {:branch-id (:id branch) :direction :branch->main}
|
||||
(last-call calls :get-branch-change-reviews))
|
||||
(t/is (= {:branch-id (:id branch) :direction :branch->source}
|
||||
(last-call calls :get-branch-change-marks))
|
||||
"the marks are the ones of the direction compared")
|
||||
(rx/dispose! store))))))
|
||||
|
||||
@ -323,21 +323,21 @@
|
||||
(mock/with-mocks* {rp/cmd! (review-stub calls marks false)}
|
||||
(let [store (make-store)]
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-change-reviews))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-change-marks))
|
||||
"the marks are asked for"))
|
||||
(ptk/emit! store (dwb/toggle-diff-reviewed (:key logo) true))
|
||||
(t/is (= #{(:key logo)} (reviewed store)) "the mark shows at once")
|
||||
(await (async/wait-for #(some? (last-call calls :set-branch-change-review))
|
||||
(await (async/wait-for #(some? (last-call calls :set-branch-change-mark))
|
||||
"the mark is kept"))
|
||||
(t/is (= {:branch-id (:id branch)
|
||||
:direction :branch->main
|
||||
:direction :branch->source
|
||||
:change-key (:key logo)
|
||||
:fingerprint (dwb/change-fingerprint logo)
|
||||
:reviewed true}
|
||||
(last-call calls :set-branch-change-review)))
|
||||
(last-call calls :set-branch-change-mark)))
|
||||
(ptk/emit! store (dwb/toggle-diff-reviewed (:key logo)))
|
||||
(t/is (= #{} (reviewed store)) "without a side it flips")
|
||||
(await (async/wait-for #(false? (:reviewed (last-call calls :set-branch-change-review)))
|
||||
(await (async/wait-for #(false? (:reviewed (last-call calls :set-branch-change-mark)))
|
||||
"the mark is cleared"))
|
||||
(rx/dispose! store))))))
|
||||
|
||||
@ -349,7 +349,7 @@
|
||||
(mock/with-mocks* {rp/cmd! (review-stub calls marks true)}
|
||||
(let [store (make-store)]
|
||||
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-change-reviews))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-change-marks))
|
||||
"the marks are asked for"))
|
||||
(ptk/emit! store (dwb/toggle-diff-reviewed (:key title) true))
|
||||
(await (async/wait-for-store store #(empty? (reviewed store))
|
||||
|
||||
@ -58,15 +58,15 @@
|
||||
(mock/with-mocks* {rp/cmd! (cmd-stub calls)}
|
||||
(let [store (on-branch)]
|
||||
(ptk/emit! store (dwcp/enter branch))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-diff))
|
||||
(await (async/wait-for #(some? (last-call calls :get-file-branch-diff))
|
||||
"the diff is asked for"))
|
||||
(t/is (dwcp/comparing? @store))
|
||||
(t/is (= {:id (:id branch) :name "feature-login" :branch-file-id branch-file-id}
|
||||
(get-in @store [:workspace-compare :branch]))
|
||||
"the mode keeps what names the branch, not its counts")
|
||||
(t/is (= :compare (get-in @store [:workspace-compare :phase])))
|
||||
(t/is (= {:branch-id (:id branch) :direction :branch->main}
|
||||
(last-call calls :get-branch-diff)))
|
||||
(t/is (= {:branch-id (:id branch) :direction :branch->source}
|
||||
(last-call calls :get-file-branch-diff)))
|
||||
(rx/dispose! store))))))
|
||||
|
||||
(t/deftest ^:async the-mode-does-not-open-with-main-open
|
||||
@ -107,8 +107,8 @@
|
||||
(ptk/emit! store (dwcp/enter branch))
|
||||
(ptk/emit! store (dwcp/set-filter :library))
|
||||
(ptk/emit! store (dwcp/select "color//a/1" {:travel false}))
|
||||
(ptk/emit! store (dwcp/set-direction :main->branch))
|
||||
(await (async/wait-for #(= :main->branch (:direction (last-call calls :get-branch-diff)))
|
||||
(ptk/emit! store (dwcp/set-direction :source->branch))
|
||||
(await (async/wait-for #(= :source->branch (:direction (last-call calls :get-file-branch-diff)))
|
||||
"the other direction is asked for"))
|
||||
(t/is (= {:selected nil :filter :all :phase :compare}
|
||||
(select-keys (:workspace-compare @store) [:selected :filter :phase])))
|
||||
@ -120,8 +120,8 @@
|
||||
clash {:kind :shape :status :conflict :id (uuid/next)}
|
||||
answers (mock/stub (fn [cmd params]
|
||||
(swap! calls conj [cmd params])
|
||||
(if (and (= :get-branch-diff cmd)
|
||||
(= :main->branch (:direction params)))
|
||||
(if (and (= :get-file-branch-diff cmd)
|
||||
(= :source->branch (:direction params)))
|
||||
(rx/of {:changes [change] :conflicts [clash]})
|
||||
(rx/subject))))]
|
||||
(await
|
||||
@ -132,15 +132,15 @@
|
||||
(ptk/emit! store (dwcp/enter branch))
|
||||
(await (async/wait-for #(some? (get-in @store [:workspace-compare :other-changes]))
|
||||
"the other direction answers"))
|
||||
(t/is (= [:branch->main :main->branch]
|
||||
(t/is (= [:branch->source :source->branch]
|
||||
(->> @calls
|
||||
(filter #(= :get-branch-diff (first %)))
|
||||
(filter #(= :get-file-branch-diff (first %)))
|
||||
(mapv (comp :direction second))))
|
||||
"the diff listed, then its other direction")
|
||||
(t/is (= [change] (get-in @store [:workspace-compare :other-changes])))
|
||||
(t/is (= [clash] (get-in @store [:workspace-compare :other-conflicts]))
|
||||
"with its conflicts, which its tab counts")
|
||||
(ptk/emit! store (dwcp/set-direction :main->branch))
|
||||
(ptk/emit! store (dwcp/set-direction :source->branch))
|
||||
(t/is (nil? (get-in @store [:workspace-compare :other-changes]))
|
||||
"the ones of the direction left do not stay")
|
||||
(t/is (nil? (get-in @store [:workspace-compare :other-conflicts])))
|
||||
@ -160,8 +160,8 @@
|
||||
(ptk/emit! store (dwcp/set-view :highlight))
|
||||
(t/is (false? (get-in @store [:workspace-compare :hidden]))
|
||||
"picking a view shows the changes again")
|
||||
(ptk/emit! store (dwcp/set-count :main->branch 4))
|
||||
(t/is (= {:main->branch 4} (get-in @store [:workspace-compare :counts])))
|
||||
(ptk/emit! store (dwcp/set-count :source->branch 4))
|
||||
(t/is (= {:source->branch 4} (get-in @store [:workspace-compare :counts])))
|
||||
(rx/dispose! store)))
|
||||
|
||||
(t/deftest choosing-the-change-chosen-lets-it-go
|
||||
@ -285,7 +285,7 @@
|
||||
(ptk/emit! store (dwcp/set-side-mode :aligned))
|
||||
(ptk/emit! store (dwcp/exit))
|
||||
(ptk/emit! store (dwcp/enter branch))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-diff))
|
||||
(await (async/wait-for #(some? (last-call calls :get-file-branch-diff))
|
||||
"the diff is asked for"))
|
||||
(t/is (= :aligned (side-mode store)) "the one picked last")
|
||||
(rx/dispose! store))))
|
||||
@ -301,7 +301,7 @@
|
||||
(mock/with-mocks* {rp/cmd! (cmd-stub calls)}
|
||||
(let [store (on-branch)]
|
||||
(ptk/emit! store (dwcp/enter branch))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-diff))
|
||||
(await (async/wait-for #(some? (last-call calls :get-file-branch-diff))
|
||||
"the diff is asked for"))
|
||||
(t/is (= :linked (side-mode store)))
|
||||
(rx/dispose! store))))
|
||||
@ -320,7 +320,7 @@
|
||||
:mode :merge
|
||||
:conflicts [{:id (uuid/next)}]}))
|
||||
(ptk/emit! store (dwcp/start-resolve))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-diff))
|
||||
(await (async/wait-for #(some? (last-call calls :get-file-branch-diff))
|
||||
"the diff is asked for"))
|
||||
(t/is (= :aligned (side-mode store)))
|
||||
(rx/dispose! store))))
|
||||
@ -440,7 +440,7 @@
|
||||
(ptk/emit! store (dwcp/toggle-hidden))
|
||||
(ptk/emit! store (dwcp/set-filter :library))
|
||||
(ptk/emit! store (dwcp/toggle-group "library"))
|
||||
(ptk/emit! store (dwcp/set-count :main->branch 4))
|
||||
(ptk/emit! store (dwcp/set-count :source->branch 4))
|
||||
(t/is (not (dwcp/comparing? @store)) "none of them creates the mode")
|
||||
(rx/dispose! store)))
|
||||
|
||||
@ -506,11 +506,11 @@
|
||||
:mode :update
|
||||
:conflicts [{:id (uuid/next)}]}))
|
||||
(ptk/emit! store (dwcp/start-resolve))
|
||||
(await (async/wait-for #(some? (last-call calls :get-branch-diff))
|
||||
(await (async/wait-for #(some? (last-call calls :get-file-branch-diff))
|
||||
"the diff is asked for"))
|
||||
(t/is (= :resolve (get-in @store [:workspace-compare :phase])))
|
||||
(t/is (= (:id branch) (get-in @store [:workspace-compare :branch :id])))
|
||||
(t/is (= :main->branch (:direction (last-call calls :get-branch-diff)))
|
||||
(t/is (= :source->branch (:direction (last-call calls :get-file-branch-diff)))
|
||||
"an update resolves main's changes")
|
||||
(rx/dispose! store))))))
|
||||
|
||||
@ -534,14 +534,14 @@
|
||||
store (make-store {:current-file-id branch-file-id
|
||||
:workspace-compare {:branch branch :phase :resolve :selected "x"}
|
||||
:workspace-branch-diff {:branch-id (:id branch)
|
||||
:resolutions {conflict-id :main}}
|
||||
:resolutions {conflict-id :source}}
|
||||
:workspace-branch-conflicts {:branch-id (:id branch)
|
||||
:conflicts [{:id conflict-id}]}})]
|
||||
(ptk/emit! store (dwcp/back-to-compare))
|
||||
(t/is (= {:phase :compare :selected nil}
|
||||
(select-keys (:workspace-compare @store) [:phase :selected])))
|
||||
(t/is (nil? (:workspace-branch-conflicts @store)))
|
||||
(t/is (= {conflict-id :main} (get-in @store [:workspace-branch-diff :resolutions])))
|
||||
(t/is (= {conflict-id :source} (get-in @store [:workspace-branch-diff :resolutions])))
|
||||
(rx/dispose! store)))
|
||||
|
||||
(defn- resolving
|
||||
@ -554,8 +554,8 @@
|
||||
:workspace-branch-diff
|
||||
(merge {:branch-id (:id branch)
|
||||
:status :loaded
|
||||
:diff {:conflicts [{:id conflict-id}] :meta {:main-revn 9}}
|
||||
:resolutions {conflict-id :branch (uuid/next) :main}}
|
||||
:diff {:conflicts [{:id conflict-id}] :meta {:source-revn 9}}
|
||||
:resolutions {conflict-id :branch (uuid/next) :source}}
|
||||
diff-st)
|
||||
:workspace-branch-conflicts attempt}))
|
||||
|
||||
@ -565,12 +565,12 @@
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! (cmd-stub calls)}
|
||||
(let [store (resolving conflict-id
|
||||
{:direction :branch->main
|
||||
:excluded {:branch->main #{"from-the-comparison"}}}
|
||||
{:direction :branch->source
|
||||
:excluded {:branch->source #{"from-the-comparison"}}}
|
||||
{:branch-id (:id branch)
|
||||
:mode :merge
|
||||
:conflicts [{:id conflict-id}]
|
||||
:main-revn 7
|
||||
:source-revn 7
|
||||
:excluded #{"from-the-attempt"}
|
||||
:comment "Ships the header"})]
|
||||
(ptk/emit! store (dwcp/apply-resolutions))
|
||||
@ -580,7 +580,7 @@
|
||||
:resolutions {conflict-id :branch}
|
||||
:excluded #{"from-the-attempt"}
|
||||
:comment "Ships the header"
|
||||
:expected-main-revn 9}
|
||||
:expected-source-revn 9}
|
||||
(last-call calls :merge-file-branch))
|
||||
"only the choices of its conflicts travel, with its selection and comment")
|
||||
(rx/dispose! store))))))
|
||||
@ -591,17 +591,17 @@
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! (cmd-stub calls)}
|
||||
(let [store (resolving conflict-id
|
||||
{:direction :main->branch
|
||||
:excluded {:main->branch #{"left-out"}
|
||||
:branch->main #{"other-direction"}}}
|
||||
{:direction :source->branch
|
||||
:excluded {:source->branch #{"left-out"}
|
||||
:branch->source #{"other-direction"}}}
|
||||
nil)]
|
||||
(ptk/emit! store (dwcp/apply-resolutions))
|
||||
(await (async/wait-for #(some? (last-call calls :update-branch-from-main))
|
||||
(await (async/wait-for #(some? (last-call calls :update-file-branch-from-source))
|
||||
"the update is asked for"))
|
||||
(t/is (= {:branch-id (:id branch)
|
||||
:resolutions {conflict-id :branch}
|
||||
:excluded #{"left-out"}
|
||||
:expected-main-revn 9}
|
||||
(last-call calls :update-branch-from-main)))
|
||||
:expected-source-revn 9}
|
||||
(last-call calls :update-file-branch-from-source)))
|
||||
(t/is (nil? (last-call calls :merge-file-branch)))
|
||||
(rx/dispose! store))))))
|
||||
|
||||
@ -23,18 +23,18 @@
|
||||
:status :conflict
|
||||
:reason :modify-modify
|
||||
:base {:rx 8 :width 320 :opacity 1}
|
||||
:main {:rx 12 :width 320 :opacity 0.5}
|
||||
:source {:rx 12 :width 320 :opacity 0.5}
|
||||
:branch {:rx 4 :width 360 :opacity 1}
|
||||
:changed-attrs {:rx {:main 12 :branch 4}
|
||||
:width {:main 320 :branch 360}
|
||||
:opacity {:main 0.5 :branch 1}}})
|
||||
:changed-attrs {:rx {:source 12 :branch 4}
|
||||
:width {:source 320 :branch 360}
|
||||
:opacity {:source 0.5 :branch 1}}})
|
||||
|
||||
(defn- sources
|
||||
[conflict]
|
||||
(into {} (map (juxt :attr :source)) (brc/conflict-attr-rows conflict)))
|
||||
(into {} (map (juxt :attr :origin)) (brc/conflict-attr-rows conflict)))
|
||||
|
||||
(t/deftest only-properties-both-sides-moved-conflict
|
||||
(t/is (= {:rx :conflict :width :branch :opacity :main} (sources card))))
|
||||
(t/is (= {:rx :conflict :width :branch :opacity :source} (sources card))))
|
||||
|
||||
(t/deftest without-a-base-every-property-conflicts
|
||||
(t/is (= #{:conflict} (set (vals (sources (assoc card :base nil :reason :add-add))))))
|
||||
@ -42,27 +42,27 @@
|
||||
|
||||
(t/deftest independent-edits-come-filled-in
|
||||
(let [res (brc/prefill-resolution card)]
|
||||
(t/is (= {:width :branch :opacity :main} res))
|
||||
(t/is (= {:width :branch :opacity :source} res))
|
||||
(t/is (not (bm/conflict-resolved? card res))
|
||||
"the conflicting radius still waits for a choice")))
|
||||
|
||||
(t/deftest choosing-the-conflicting-property-resolves-the-conflict
|
||||
(let [res (brc/choose-attr card nil :rx :branch)]
|
||||
(t/is (= {:rx :branch :width :branch :opacity :main} res))
|
||||
(t/is (= {:rx :branch :width :branch :opacity :source} res))
|
||||
(t/is (bm/conflict-resolved? card res))
|
||||
(t/is (= [{:attr :rx :side :main :value 12}]
|
||||
(t/is (= [{:attr :rx :side :source :value 12}]
|
||||
(brc/dropped-values card res))
|
||||
"keeping the branch radius drops main's, and nothing else")))
|
||||
|
||||
(t/deftest a-conflict-without-conflicting-properties-comes-out-resolved
|
||||
(let [conflict (-> card
|
||||
(assoc-in [:main :rx] 8)
|
||||
(assoc-in [:source :rx] 8)
|
||||
(update :changed-attrs dissoc :rx))]
|
||||
(t/is (bm/conflict-resolved? conflict (brc/prefill-resolution conflict)))))
|
||||
|
||||
(t/deftest bulk-choice-keeps-independent-edits
|
||||
(t/is (= {:rx :main :width :branch :opacity :main} (brc/choose-side card :main)))
|
||||
(t/is (= :branch (brc/choose-side (assoc card :changed-attrs {} :main nil) :branch))
|
||||
(t/is (= {:rx :source :width :branch :opacity :source} (brc/choose-side card :source)))
|
||||
(t/is (= :branch (brc/choose-side (assoc card :changed-attrs {} :source nil) :branch))
|
||||
"an entity that cannot be split takes the whole side"))
|
||||
|
||||
(t/deftest paragraphs-say-which-edits-a-side-keeps-and-drops
|
||||
@ -75,10 +75,10 @@
|
||||
note {:kind :shape
|
||||
:status :conflict
|
||||
:base {:content (text "One" "Two" "Three")}
|
||||
:main {:content (text "One step" "Two" "Three")}
|
||||
:source {:content (text "One step" "Two" "Three")}
|
||||
:branch {:content (text "One" "Two" "Three more")}
|
||||
:changed-attrs {:content {}}}]
|
||||
(t/is (= [:kept nil :dropped] (mapv :status (brc/paragraph-rows note :main))))
|
||||
(t/is (= [:kept nil :dropped] (mapv :status (brc/paragraph-rows note :source))))
|
||||
(t/is (= [:dropped nil :kept] (mapv :status (brc/paragraph-rows note :branch))))))
|
||||
|
||||
;; --- What a new or deleted entry is, where it lands, what it affects
|
||||
@ -205,7 +205,7 @@
|
||||
|
||||
(t/deftest a-board-with-a-layout-resizes-with-the-layer
|
||||
(let [items [(gone icon-id)
|
||||
(edit button-id {:width {:main 163 :branch 131}})]
|
||||
(edit button-id {:width {:source 163 :branch 131}})]
|
||||
fx (brc/shape-effects (gone icon-id) items proto-objects [] false)]
|
||||
(t/is (= [{:id button-id :name "Button" :layout :flex :from [163 48] :to [131 48]}]
|
||||
(:layouts fx)))
|
||||
@ -214,20 +214,20 @@
|
||||
|
||||
(t/deftest an-update-reads-the-sides-the-other-way-round
|
||||
(let [items [(gone icon-id)
|
||||
(edit button-id {:width {:main 131 :branch 163}})]
|
||||
(edit button-id {:width {:source 131 :branch 163}})]
|
||||
fx (brc/shape-effects (gone icon-id) items proto-objects [] true)]
|
||||
(t/is (= [[163 48] [131 48]] ((juxt :from :to) (first (:layouts fx)))))))
|
||||
|
||||
(t/deftest a-fixed-board-moves-its-other-layers
|
||||
(let [items [(gone icon-id)
|
||||
(edit label-id {:x {:main 40 :branch 20}})]
|
||||
(edit label-id {:x {:source 40 :branch 20}})]
|
||||
fx (brc/shape-effects (gone icon-id) items proto-objects [] false)]
|
||||
(t/is (= [{:id button-id :name "Button" :layout :flex :moved 1}] (:layouts fx)))))
|
||||
|
||||
(t/deftest prototype-links-into-a-deleted-board-go-with-it
|
||||
(let [link {:event-type :click :action-type :navigate :destination screen-id}
|
||||
items [(gone screen-id)
|
||||
(assoc (edit cta-id {:interactions {:main [link] :branch []}}) :label "CTA")
|
||||
(assoc (edit cta-id {:interactions {:source [link] :branch []}}) :label "CTA")
|
||||
{:kind :page-flow :status :deleted :id :f1 :page-id page-id :label "f1"
|
||||
:flow {:id :f1 :name "Onboarding" :starting-frame screen-id}}
|
||||
{:kind :page-flow :status :deleted :id :f2 :page-id page-id :label "f2"
|
||||
@ -240,7 +240,7 @@
|
||||
(t/deftest an-added-layer-breaks-no-links
|
||||
(let [link {:event-type :click :action-type :navigate :destination screen-id}
|
||||
added (assoc (gone screen-id) :status :added)
|
||||
items [added (edit cta-id {:interactions {:main [] :branch [link]}})]
|
||||
items [added (edit cta-id {:interactions {:source [] :branch [link]}})]
|
||||
fx (brc/shape-effects added items proto-objects [] false)]
|
||||
(t/is (= [] (:interactions fx)))))
|
||||
|
||||
@ -257,7 +257,7 @@
|
||||
:key (str "color//" color-id)})
|
||||
|
||||
(def ^:private clash
|
||||
(assoc (change :clash :conflict) :changed-attrs {:rx {:main 1 :branch 2}}))
|
||||
(assoc (change :clash :conflict) :changed-attrs {:rx {:source 1 :branch 2}}))
|
||||
|
||||
(def ^:private diff
|
||||
{:changes [(change :title :modified)
|
||||
@ -353,7 +353,7 @@
|
||||
(t/deftest conflicts-wait-until-every-property-has-a-choice
|
||||
(let [other (assoc card :id :other)
|
||||
card (assoc card :id :card)
|
||||
res {:card (brc/choose-side card :main)}
|
||||
res {:card (brc/choose-side card :source)}
|
||||
{:keys [pending decided rows]} (brc/conflict-model [card other] res)]
|
||||
(t/is (= [:other] (map :id pending)))
|
||||
(t/is (= [:card] (map :id decided)))
|
||||
@ -361,18 +361,18 @@
|
||||
|
||||
(t/deftest only-conflicts-without-a-choice-get-prefilled
|
||||
(let [card (assoc card :id :card)
|
||||
seed (brc/prefill-resolutions [card (assoc card :id :chosen)] {:chosen :main})]
|
||||
(t/is (= {:card {:width :branch :opacity :main}} seed))))
|
||||
seed (brc/prefill-resolutions [card (assoc card :id :chosen)] {:chosen :source})]
|
||||
(t/is (= {:card {:width :branch :opacity :source}} seed))))
|
||||
|
||||
(t/deftest the-property-in-turn-is-the-first-without-a-choice
|
||||
(let [both (assoc card
|
||||
:base {:rx 8 :width 320 :opacity 1 :fills :a}
|
||||
:main (assoc (:main card) :fills :b)
|
||||
:source (assoc (:source card) :fills :b)
|
||||
:branch (assoc (:branch card) :fills :c)
|
||||
:changed-attrs (assoc (:changed-attrs card) :fills {:main :b :branch :c}))
|
||||
:changed-attrs (assoc (:changed-attrs card) :fills {:source :b :branch :c}))
|
||||
[first-attr second-attr] (brc/conflicting-attrs (brc/conflict-attr-rows both))]
|
||||
(t/is (= first-attr (brc/pending-attr both nil nil)))
|
||||
(t/is (= second-attr (brc/pending-attr both nil second-attr)) "the one the user took")
|
||||
(t/is (= second-attr (brc/pending-attr both {first-attr :main} nil)))
|
||||
(t/is (nil? (brc/pending-attr (assoc card :main nil) nil nil))
|
||||
(t/is (= second-attr (brc/pending-attr both {first-attr :source} nil)))
|
||||
(t/is (nil? (brc/pending-attr (assoc card :source nil) nil nil))
|
||||
"a conflict that does not split by property has none")))
|
||||
|
||||
@ -37,10 +37,10 @@
|
||||
:shape {:id path-id :type :path :name "path" :parent-id icon-id}}
|
||||
{:kind :shape :status :deleted :id icon-id :shape icon}
|
||||
{:kind :shape :status :modified :id board-id
|
||||
:changed-attrs {:width {:main 163 :branch 131}}}])
|
||||
:changed-attrs {:width {:source 163 :branch 131}}}])
|
||||
|
||||
(t/deftest a-deleted-layer-comes-back-on-the-side-that-has-it
|
||||
(let [main (brs/side-objects branch-objects items :main :branch)]
|
||||
(let [main (brs/side-objects branch-objects items :source :branch)]
|
||||
(t/is (= icon (get main icon-id)))
|
||||
(t/is (contains? main path-id))
|
||||
(t/is (= [icon-id] (get-in main [board-id :shapes])))))
|
||||
@ -51,7 +51,7 @@
|
||||
(t/is (= [] (get-in branch [board-id :shapes])))))
|
||||
|
||||
(t/deftest a-resized-board-draws-at-its-own-size
|
||||
(let [main (brs/side-objects branch-objects items :main :branch)]
|
||||
(let [main (brs/side-objects branch-objects items :source :branch)]
|
||||
(t/is (= 163 (get-in main [board-id :selrect :width])))
|
||||
(t/is (= 131 (get-in branch-objects [board-id :selrect :width])))))
|
||||
|
||||
@ -79,19 +79,19 @@
|
||||
|
||||
(def ^:private moves
|
||||
[{:kind :shape :status :modified :id group-id
|
||||
:changed-attrs {:x {:main 10 :branch 300} :y {:main 20 :branch 400}}}
|
||||
:changed-attrs {:x {:source 10 :branch 300} :y {:source 20 :branch 400}}}
|
||||
{:kind :shape :status :modified :id line-id
|
||||
:changed-attrs {:content {:main (line-content 30 40)
|
||||
:changed-attrs {:content {:source (line-content 30 40)
|
||||
:branch (line-content 500 600)}}}])
|
||||
|
||||
(t/deftest a-moved-group-takes-its-place-on-the-other-side
|
||||
(let [main (brs/side-objects moved-objects moves :main :branch)]
|
||||
(let [main (brs/side-objects moved-objects moves :source :branch)]
|
||||
(t/is (= {:x 10 :y 20 :width 50 :height 60}
|
||||
(select-keys (get-in main [group-id :selrect]) [:x :y :width :height])))
|
||||
(t/is (= 300 (get-in moved-objects [group-id :selrect :x])) "the branch keeps its own")))
|
||||
|
||||
(t/deftest a-moved-path-takes-its-place-on-the-other-side
|
||||
(let [main (brs/side-objects moved-objects moves :main :branch)]
|
||||
(let [main (brs/side-objects moved-objects moves :source :branch)]
|
||||
(t/is (= {:x 30 :y 40 :width 10 :height 20}
|
||||
(select-keys (get-in main [line-id :selrect]) [:x :y :width :height])))
|
||||
(t/is (= 500 (get-in moved-objects [line-id :selrect :x])) "the branch keeps its own")))
|
||||
@ -108,11 +108,11 @@
|
||||
"What main did since the branch left: it widened the button, added a
|
||||
badge to it and deleted nothing the branch still has."
|
||||
[{:kind :shape :status :modified :id board-id :key "board"
|
||||
:changed-attrs {:width {:main 200 :branch 131}}}
|
||||
:changed-attrs {:width {:source 200 :branch 131}}}
|
||||
{:kind :shape :status :added :id badge-id :key "badge" :shape badge}])
|
||||
|
||||
(t/deftest an-update-brings-what-main-added-and-changed
|
||||
(let [after (brs/side-objects branch-objects incoming :main :branch :main)]
|
||||
(let [after (brs/side-objects branch-objects incoming :source :branch :source)]
|
||||
(t/is (= 200 (get-in after [board-id :selrect :width])))
|
||||
(t/is (= badge (get after badge-id)))
|
||||
(t/is (= [badge-id] (get-in after [board-id :shapes])))))
|
||||
@ -123,7 +123,7 @@
|
||||
(assoc-in [board-id :shapes] [badge-id]))
|
||||
after (brs/side-objects with-badge
|
||||
[{:kind :shape :status :deleted :id badge-id}]
|
||||
:main :branch :main)]
|
||||
:source :branch :source)]
|
||||
(t/is (not (contains? after badge-id)))
|
||||
(t/is (= [] (get-in after [board-id :shapes])))))
|
||||
|
||||
@ -131,17 +131,17 @@
|
||||
|
||||
(def ^:private clash
|
||||
{:kind :shape :status :conflict :id board-id
|
||||
:main {:id board-id :type :frame :name "Main button" :parent-id uuid/zero
|
||||
:source {:id board-id :type :frame :name "Main button" :parent-id uuid/zero
|
||||
:x 0 :y 0 :width 163 :height 48 :opacity 0.5 :shapes []}
|
||||
:branch (get branch-objects board-id)
|
||||
:changed-attrs {:width {:main 163 :branch 131}
|
||||
:opacity {:main 0.5 :branch nil}}})
|
||||
:changed-attrs {:width {:source 163 :branch 131}
|
||||
:opacity {:source 0.5 :branch nil}}})
|
||||
|
||||
(t/deftest a-conflict-shows-the-side-chosen-for-each-property
|
||||
(let [none (brs/resolved-objects branch-objects [clash] {})
|
||||
mixed (brs/resolved-objects branch-objects [clash] {board-id {:width :branch :opacity :main}})
|
||||
whole (brs/resolved-objects branch-objects [clash] {board-id :main})
|
||||
gone (brs/resolved-objects branch-objects [(assoc clash :main nil)] {board-id :main})]
|
||||
mixed (brs/resolved-objects branch-objects [clash] {board-id {:width :branch :opacity :source}})
|
||||
whole (brs/resolved-objects branch-objects [clash] {board-id :source})
|
||||
gone (brs/resolved-objects branch-objects [(assoc clash :source nil)] {board-id :source})]
|
||||
(t/is (identical? branch-objects none) "no choice: the branch as it is")
|
||||
(t/is (= 0.5 (get-in mixed [board-id :opacity])))
|
||||
(t/is (= 131 (get-in mixed [board-id :selrect :width])) "the branch keeps its width")
|
||||
@ -185,11 +185,11 @@
|
||||
(t/deftest the-canvas-shows-the-choices-and-the-side-tried-out
|
||||
(let [item (assoc clash :page-id page-id)
|
||||
chosen (cc/canvas-objects (comparison {:phase :resolve
|
||||
:resolutions {board-id {:opacity :main}}})
|
||||
:resolutions {board-id {:opacity :source}}})
|
||||
branch-objects page-id)
|
||||
tried (cc/canvas-objects (comparison {:phase :resolve
|
||||
:mode {:preview :main}
|
||||
:item (assoc item :main nil)})
|
||||
:mode {:preview :source}
|
||||
:item (assoc item :source nil)})
|
||||
branch-objects page-id)]
|
||||
(t/is (= :result (:kind chosen)))
|
||||
(t/is (= 0.5 (get-in chosen [:objects board-id :opacity])))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user