A peer-to-peer stack for code collaboration
Rename rad diff to rad patch (#522)
Merle Breitkreuz556645bfbc8d
diff --git a/bin/rad-diff b/bin/rad-patchsimilarity index 66%rename from bin/rad-diffrename to bin/rad-patchindex 9b86c8e..ac8d930 100755--- a/bin/rad-diff+++ b/bin/rad-patch@@ -1,7 +1,7 @@#!/usr/bin/env radicle(load! (find-module-file! "prelude.rad"))-(load! (find-module-file! "monadic/diff.rad"))+(load! (find-module-file! "monadic/patch.rad"))(load! (find-module-file! "prelude/io-utils.rad"))(load! (find-module-file! "monadic/project.rad"))@@ -10,7 +10,7 @@(import prelude/validation :as 'validation)-(def machine-name (fn [] (get-rsm-of-type! :rad-diff)))+(def machine-name (fn [] (get-rsm-of-type! :rad-patch)))(def valid-states["pending" "retracted" "accepted" "rejected"])@@ -25,16 +25,16 @@(def help(string-append- "rad diff - Radicle Diff CLI+ "rad patch - Radicle Patch CLIUsage:- rad diff list " list-opts-help "- rad diff propose <commit>- rad diff [show | retract | accept | reject] <diff-number>- rad diff comment <diff-number> <comment>- rad diff help+ rad patch list " list-opts-help "+ rad patch propose <commit>+ rad patch [show | retract | accept | reject] <patch-number>+ rad patch comment <patch-number> <comment>+ rad patch help- list - Lists all diffs+ list - Lists all patchesThe list can be filtered by state:" (string/intercalate ", " valid-states) "The flags for filtering by state:@@ -43,16 +43,16 @@<state2> ...'.If the option '--fancy' is appended, the list is opened viafzf (note that fzf has to be installed).- propose - Create a new diff from a single commit- show - Show a diff- comment - Add a comment to a diff- retract - Retract your own diff- This command is restricted to the creator of the diff or the+ propose - Create a new patch from a single commit+ show - Show a patch+ comment - Add a comment to a patch+ retract - Retract your own patch+ This command is restricted to the creator of the patch or themaintainer of the project.- accept - Accept a diff+ accept - Accept a patchAutomatically merges to master and pushes to origin. Thiscommand is restricted to the maintainer of the project.- reject - Reject a diff+ reject - Reject a patchThis command is restricted to the maintainer of the project.help - Print this help and exit"))@@ -61,13 +61,13 @@(fn [error](parse-failure error help)))-(def verify-diff-number- (fn [diff-no machine]- (match (lookup-default diff-no #f (list-diffs machine))+(def verify-patch-number+ (fn [patch-no machine]+ (match (lookup-default patch-no #f (list-patches machine))#f (do- (put-str! (error/item-not-found :diff (show diff-no)))+ (put-str! (error/item-not-found :patch (show patch-no)))(exit! 1))- 'the-diff the-diff)))+ 'the-patch the-patch)));; git interactions@@ -115,31 +115,31 @@(write-file! file patch)(process-git-with-exit! ["am" file] msg)))-(def checkout-diff!- "Creates a new branch diff/<DIFF-ID> based on the DIFF, and switches to it."- (fn [machine diff-no]- (def diff (verify-diff-number diff-no machine))- (def diff-branch (string-append "diff/" (show diff-no)))+(def checkout-patch!+ "Creates a new branch patch/<PATCH-ID> based on the PATCH, and switches to it."+ (fn [machine patch-no]+ (def patch (verify-patch-number patch-no machine))+ (def patch-branch (string-append "patch/" (show patch-no)))(process-git-with-exit!- ["checkout" "-b" diff-branch]- (error/checkout-new-branch-failure diff-branch))+ ["checkout" "-b" patch-branch]+ (error/checkout-new-branch-failure patch-branch))(apply-patch!- (lookup :patch diff)+ (lookup :patch patch)(error/applying-patch-failure))))-(def push-diff!- "Merges the DIFF to master, and pushes the changes."- (fn [machine diff-no]- (def diff (verify-diff-number diff-no machine))+(def push-patch!+ "Merges the PATCH to master, and pushes the changes."+ (fn [machine patch-no]+ (def patch (verify-patch-number patch-no machine))(process-git-with-exit)(apply-patch!- (lookup :patch diff)+ (lookup :patch patch)(error/applying-accepted-patch-failure))(process-git-with-exit!["push"]- (error/push-diff-failure))))+ (error/push-patch-failure))))(def verify-patch@@ -151,8 +151,8 @@(put-str! (error/parent-commit-not-master commit))(exit! 1)))))-(def new-diff!- "Creates a new diff on `machine` with a patch from the given `commit`."+(def new-patch!+ "Creates a new patch on `machine` with a patch from the given `commit`."(fn [machine commit](verify-commit commit)(verify-patch commit)@@ -162,18 +162,18 @@(def short-hash (get-short-hash! commit))(def title (get-title! commit))(def description (get-description! commit))- (def diff {:short-hash short-hash+ (def patch {:short-hash short-hash:title title:description description:author-name author-name:author-email author-email:patch patch})- (match (simple-create-diff! machine diff)- ['n] (put-str! (string-append "Proposing diff #" (show n)+ (match (simple-create-patch! machine patch)+ ['n] (put-str! (string-append "Proposing patch #" (show n)" to " machine))- _ (put-str! (error/no-number-returned :diff)))))+ _ (put-str! (error/no-number-returned :patch)))))-;; showing diffs+;; showing patches(def pretty-state(fn [state]@@ -238,7 +238,7 @@:author-name a-n}(string-append "### " a-n " [" c-a "]\n\n" b "\n"))))-(def pretty-diff+(def pretty-patch(fn [i](match i'{:patch p@@ -261,16 +261,16 @@x)))(def list-items- "Lists all diffs and filters them by `options`. If `--new` is passed as an+ "Lists all patches and filters them by `options`. If `--new` is passed as anoption only recent items are shown. If `--fancy is passed, the list is openedvia fzf."(fn [machine options](def mk-key- (fn [diff]+ (fn [patch](if (lookup :fancy options)- [(pretty-headline diff) diff]- [(pretty-row diff) diff])))+ [(pretty-headline patch) patch]+ [(pretty-row patch) patch])))(def filt(match (map (fn [opt] (read (string-append ":" opt))) (lookup :state options))@@ -280,21 +280,21 @@(def items(map mk-key(filter filt- (reverse (values (list-diffs machine))))))+ (reverse (values (list-patches machine))))))(def items-dict (dict-from-seq items))(if (empty-seq? items)- (put-str! "No diffs!")+ (put-str! "No patches!")(if (lookup :fancy options)(match (fzf-select-with-preview!(map first items)- (fn [s] (pretty-diff (lookup s items-dict))))+ (fn [s] (pretty-patch (lookup s items-dict))))(/just 's)(do (def selected (lookup s items-dict))- (def diff-number (match selected {:number 'n} n))+ (def patch-number (match selected {:number 'n} n))(def pretty-item(add-comment-md- (pretty-diff selected)))+ (pretty-patch selected)))(def edited-item (edit-in-editor! pretty-item))(def added-comment(string/unlines@@ -303,26 +303,26 @@(put-str!(if (eq? added-comment "")"Item was not updated."- (do (simple-add-comment! machine diff-number added-comment (get-git-username!))+ (do (simple-add-comment! machine patch-number added-comment (get-git-username!))(string-append "Sent comment: " added-comment)))))_ (put-str! "No selection made."))(do(put-str! (pretty-table-header))(map (fn [d] (put-str! (first d))) items))))))-(def show-diff!- "Shows a single DIFF `n`"+(def show-patch!+ "Shows a single PATCH `n`"(fn [machine n](if (number? n)(if (integral? n)(do- (def diff (verify-diff-number n machine))- (put-str! (pretty-diff diff)))- (cmd-parse-failure (error/whole-item-number :diff)))- (cmd-parse-failure (error/missing-item-number :diff "show")))))+ (def patch (verify-patch-number n machine))+ (put-str! (pretty-patch patch)))+ (cmd-parse-failure (error/whole-item-number :patch)))+ (cmd-parse-failure (error/missing-item-number :patch "show")))))-(def edit-diff-state!- "Edit the state of a DIFF. If the new state is `:accepted` the DIFF is then+(def edit-patch-state!+ "Edit the state of a PATCH. If the new state is `:accepted` the PATCH is thenalso merged to master and the changes pushed."(fn [machine n new-state](if (number? n)@@ -331,34 +331,34 @@(def edit-state-with-feedback!(fn [message](catch 'daemon-error- (simple-edit-diff! machine n {:state new-state})+ (simple-edit-patch! machine n {:state new-state})(fn [x](put-str!- (error/state-change-failure :diff (pretty-state new-state)))+ (error/state-change-failure :patch (pretty-state new-state)))(exit! 1)))(put-str! message)))- (verify-diff-number n machine)+ (verify-patch-number n machine)(if (eq? new-state :accepted)- (match (push-diff! machine n)+ (match (push-patch! machine n):ok (edit-state-with-feedback!- (string-append "Diff #" (show n) " has been " (pretty-state new-state) " and merged."))+ (string-append "Patch #" (show n) " has been " (pretty-state new-state) " and merged."))_ (exit! 1))(edit-state-with-feedback!- (string-append "Diff #" (show n) " has been " (pretty-state new-state)))))- (cmd-parse-failure (error/whole-item-number :diff)))- (cmd-parse-failure (error/missing-item-number :issue "change the state of")))))+ (string-append "Patch #" (show n) " has been " (pretty-state new-state)))))+ (cmd-parse-failure (error/whole-item-number :patch)))+ (cmd-parse-failure (error/missing-item-number :patch "change the state of")))))(def create-comment!- "Add a new `comment` to DIFF."+ "Add a new `comment` to PATCH."(fn [machine n comment](if (number? n)(if (integral? n)(do- (verify-diff-number n machine)+ (verify-patch-number n machine)(simple-add-comment! machine n comment (get-git-username!))- (put-str! (string-append "Added comment to diff #" (show n))))- (cmd-parse-failure (error/whole-item-number :diff)))- (cmd-parse-failure (error/missing-item-number :issue "comment on")))))+ (put-str! (string-append "Added comment to patch #" (show n))))+ (cmd-parse-failure (error/whole-item-number :patch)))+ (cmd-parse-failure (error/missing-item-number :patch "comment on")))))(def cmd-options[@@ -376,14 +376,14 @@(fn [](match args(/list-cmd 'options) (list-items (machine-name) options)- (/cmd-1 "propose" 'commit help) (new-diff! (machine-name) commit)- (/cmd-1 "checkout" 'diff-number help) (checkout-diff! (machine-name) (read diff-number))- (/cmd-1 "show" 'diff-number help) (show-diff! (machine-name) (read diff-number))- (/cmd-1 "retract" 'diff-number help) (edit-diff-state! (machine-name) (read diff-number) :retracted)- (/cmd-1 "accept" 'diff-number help) (edit-diff-state! (machine-name) (read diff-number) :accepted)- (/cmd-1 "reject" 'diff-number help) (edit-diff-state! (machine-name) (read diff-number) :rejected)- (/cmd-2 "comment" 'diff-number 'comment help) (create-comment! (machine-name) (read diff-number) comment)- (/cmd-0 "create-machine" help) (new-diff-machine! (machine-name))+ (/cmd-1 "propose" 'commit help) (new-patch! (machine-name) commit)+ (/cmd-1 "checkout" 'patch-number help) (checkout-patch! (machine-name) (read patch-number))+ (/cmd-1 "show" 'patch-number help) (show-patch! (machine-name) (read patch-number))+ (/cmd-1 "retract" 'patch-number help) (edit-patch-state! (machine-name) (read patch-number) :retracted)+ (/cmd-1 "accept" 'patch-number help) (edit-patch-state! (machine-name) (read patch-number) :accepted)+ (/cmd-1 "reject" 'patch-number help) (edit-patch-state! (machine-name) (read patch-number) :rejected)+ (/cmd-2 "comment" 'patch-number 'comment help) (create-comment! (machine-name) (read patch-number) comment)+ (/cmd-0 "create-machine" help) (new-patch-machine! (machine-name))["help"] (put-str! help)["-h"] (put-str! help)["--help"] (put-str! help)diff --git a/bin/rad-project b/bin/rad-projectindex 11de871..3b7608f 100755--- a/bin/rad-project+++ b/bin/rad-project@@ -4,7 +4,7 @@(file-module! "prelude/io-utils.rad")(file-module! "prelude/error-messages.rad")(file-module! "monadic/issue.rad")-(load! (find-module-file! "monadic/diff.rad"))+(load! (find-module-file! "monadic/patch.rad"))(file-module! "monadic/project.rad")(import prelude/strings '[unlines] :unqualified)@@ -161,8 +161,8 @@(config-ipfs-api-url! repo)(def issues (create-issue-machine!))(put-str! "=> Assembled rad-issue machine")- (def diff (create-diff-machine!))- (put-str! "=> Assembled rad-diff machine")+ (def patch (create-patch-machine!))+ (put-str! "=> Assembled rad-patch machine")(put-str! (string-append "=> project id: " project))(if (eq? "" (get-git-config! "remote.origin.url"))(do (put-str! (string-append "=> adding \"origin\" remote: " repo))@@ -171,7 +171,7 @@(setup-upstream!)(add-rsm! project { :id repo :type :rad-repo })(add-rsm! project { :id issues :type :rad-issue })- (add-rsm! project { :id diff :type :rad-diff })+ (add-rsm! project { :id patch :type :rad-patch })(set-git-config! "radicle.project-id" project)(put-str! "=> project created!")))diff --git a/rad/monadic/diff.rad b/rad/monadic/diff.raddeleted file mode 100644index b41f993..0000000--- a/rad/monadic/diff.rad+++ /dev/null@@ -1,106 +0,0 @@-(load! (find-module-file! "prelude.rad"))--(import prelude/lens :unqualified)-(import prelude/machine '[send-code!] :unqualified)-(import prelude/time '[install-fake-clock] :unqualified)-(import prelude/io :as 'io)-(import prelude/key-management '[set-fake-keys! use-fake-keys! get-keys!] :unqualified)--(def radicle-diff-machine-id- "The name of this machine."- "monadic/radicle/diff")--(def create-diff-machine!- "Create a remote diff machine. Returns the machine id"- (fn []- (def owner-keys (lookup :public-key (get-keys!)))- (def id (machine/new-machine!))- (machine/send-prelude! id)- (send-code! id (find-module-file! "monadic/diff-remote.rad"))- (machine/send-signed-command! id radicle-diff-machine-id 'add-admin {:key owner-keys})- id))--(def simple-diff- "Create an open diff with no comments or labels."- (fn [p]- (def t (now!))- (<> {:state :pending- :comments []- :created-at t- :modified-at t}- p)))--(def simple-comment- "Create a comment for an issue."- (fn [diff-number bod author-name]- (def t (now!))- {:body bod- :author-name author-name- :diff-number diff-number- :created-at t- :modified-at t}))--(def edit-diff!- "Edit a remote diff with the keys in `my-keys.rad`."- (fn [machine i]- (machine/send-signed-command! machine radicle-diff-machine-id 'edit-diff i)))--(def simple-edit-diff!- (fn [machine n i]- (edit-diff! machine- (<> {:diff-number n- :modified-at (now!)}- i))))--(def create-diff!- "Create a new remote diff with the keys in `my-keys.rad`."- (fn [machine i]- (machine/send-signed-command! machine radicle-diff-machine-id 'create-diff i)))--(def add-comment!- "Create a remote comment with the keys in `my-keys.rad`."- (fn [machine c]- (machine/send-signed-command! machine radicle-diff-machine-id 'add-comment c)))--(def simple-create-diff!- "Create a remote diff with sensible defaults."- (fn [machine diff]- (create-diff! machine (simple-diff diff))))--(def simple-add-comment!- "Create a remote comment."- (fn [machine n b name]- (add-comment! machine (simple-comment n b name))))--(def list-diffs- "Return the full map of diffs."- (fn [machine]- (machine/query! machine '(list-diffs))))--(:test- "The monadic diff machine works."- [:setup- (do (machine/install-remote-machine-fake)- (def owner-keys (gen-key-pair! (default-ecc-curve)))- (def non-owner-keys (gen-key-pair! (default-ecc-curve)))- (set-fake-keys! owner-keys)- (def machine (create-diff-machine!))- (simple-create-diff! machine {:title "title0" :description "desc0" :patch "patch0"})- (simple-create-diff! machine {:title "title1" :description "desc1" :patch "patch1"})- (simple-add-comment! machine 0 "comment0" "name0")- (simple-add-comment! machine 1 "comment1" "name1")- (simple-edit-diff! machine 0 {:state :accepted})- (def diffs (list-diffs machine)))]- [ (length (seq diffs)) ==> 2 ]- [ (view (.. (@ 0) (@ :title)) diffs) ==> "title0" ]- [ (view (.. (@ 1) (@ :title)) diffs) ==> "title1" ]- [ (view (... [(@ 0) (@ :comments) (@nth 0) (@ :body)]) diffs) ==> "comment0" ]- [ (view (... [(@ 1) (@ :comments) (@nth 0) (@ :body)]) diffs) ==> "comment1" ]- [ (view (.. (@ 0) (@ :state)) diffs) ==> :accepted ]- ;; authorization- [ (do- (set-fake-keys! non-owner-keys)- (catch 'validation-failure- (simple-edit-diff! machine 1 {:state :accepted})- (fn [_] :ok))) ==> :ok ]-)diff --git a/rad/monadic/diff-remote.rad b/rad/monadic/patch-remote.radsimilarity index 65%rename from rad/monadic/diff-remote.radrename to rad/monadic/patch-remote.radindex 84fe599..3ecc471 100644--- a/rad/monadic/diff-remote.rad+++ b/rad/monadic/patch-remote.rad@@ -13,24 +13,24 @@(def machine-id"The name of this machine."- "monadic/radicle/diff")+ "monadic/radicle/patch")-(def diffs- "DIFFs are stored in a dict in a ref, keyed by diff-number."+(def patches+ "PATCHes are stored in a dict in a ref, keyed by patch-number."(ref {}))-(def diff-counter- "We use a stateful counter for giving diff numbers."+(def patch-counter+ "We use a stateful counter for giving patch numbers."(make-counter))(def noncer (make-noncer))(def auth (make-simple-auth [:admin]))-(def set-diffs- "A helper to set stuff in the diffs ref."+(def set-patches+ "A helper to set stuff in the patches ref."(fn [l v]- (set-ref diffs l v)))+ (set-ref patches l v)))(def input-keys{:nonce (noncer :validator)@@ -59,9 +59,9 @@[(validator/keys input-keys)validator/signed]))-(def validator/diff-number- "A validator for numbers which refer to existing diffs."- (validator/pred "Existing diff number" (fn [n] (member? n (read-ref diffs)))))+(def validator/patch-number+ "A validator for numbers which refer to existing patches."+ (validator/pred "Existing patch number" (fn [n] (member? n (read-ref patches)))))(def comment-keys"A comment's body should be text that isn't too long."@@ -70,9 +70,9 @@(def validator/full-comment(validator/keys comment-keys))-(def validator/diff-reference+(def validator/patch-reference"Refers to an existing issue."- (validator/optional-keys {:issue-number validator/diff-number}))+ (validator/optional-keys {:issue-number validator/patch-number}))(def validator/comment-input"A comment input should refer to an existing issue."@@ -80,32 +80,32 @@[validator/inputvalidator/time-createdvalidator/full-comment- validator/diff-reference]))+ validator/patch-reference]))-(def diff-keys+(def patch-keys{:title (validator/string-of-max-length 100):description (validator/string-of-max-length 4000):patch (validator/type :string):state (validator/member [:pending :retracted :accepted :rejected]):comments (validator/every validator/full-comment)})-(def validator/full-diff (validator/keys diff-keys))+(def validator/full-patch (validator/keys patch-keys))-(def validator/diff-input- "An diff should have all the required fields, be a signed input, etc."+(def validator/patch-input+ "An patch should have all the required fields, be a signed input, etc."(validator/and[validator/inputvalidator/time-created- validator/full-diff]))+ validator/full-patch]))(def edit-keys(fn [ks](<> ks(<> (keys input-keys)- [:diff-number :modified-at :author :signature]))))+ [:patch-number :modified-at :author :signature]))))-(def validator/diff-edit-input- "An input to edit an diff."+(def validator/patch-edit-input+ "An input to edit a patch."(fn [ed](def auth-validation(match (lookup-default :state :nothing ed)@@ -113,49 +113,49 @@:retracted (validator/pred "edit author == original author"(fn [c](match c- {:diff-number 'n+ {:patch-number 'n:author 'a}- (eq? (view-ref diffs (... [(@ n) (@ :author)]))+ (eq? (view-ref patches (... [(@ n) (@ :author)]))a))))_ (auth [:allowed :admin])))((validator/and[validator/inputvalidator/time-modified- validator/diff-reference+ validator/patch-referenceauth-validation- (validator/contains-only (edit-keys (keys diff-keys)))]) ed)))+ (validator/contains-only (edit-keys (keys patch-keys)))]) ed)))(def strip-input"After an entity input has been processed/verified, we no longer need some ofthe fields."(fn [e]- (delete-many [:machine-id :signature :nonce :diff-number] e)))+ (delete-many [:machine-id :signature :nonce :patch-number] e)))-(def create-diff- "Create an diff from a dict, checking that it is valid and storing it in `diffs`."+(def create-patch+ "Create a patch from a dict, checking that it is valid and storing it in `patches`."(fn [i]- (validator/diff-input i)- (def n (diff-counter :next))+ (validator/patch-input i)+ (def n (patch-counter :next))(def i_(strip-input(<> i{:number n})))- (set-diffs (@ n) i_)+ (set-patches (@ n) i_)(noncer [:use (lookup :nonce i)])n))-(def over-diffs- "A helper to modify stuff in the diff ref."+(def over-patches+ "A helper to modify stuff in the patch ref."(fn [l f]- (over-ref diffs l f)))+ (over-ref patches l f)))(def add-comment- "Add a comment to a diff."+ "Add a comment to a patch."(fn [c](validator/comment-input c)(def c_ (strip-input c))- (over-diffs- (.. (@ (lookup :diff-number c)) (@ :comments))+ (over-patches+ (.. (@ (lookup :patch-number c)) (@ :comments))(fn [cs] (add-right c_ cs)))(noncer [:use (lookup :nonce c)])))@@ -164,22 +164,22 @@(fn [old](<> old new))))-(def edit-diff- "Modify some of the attributes of an diff."+(def edit-patch+ "Modify some of the attributes of a patch."(fn [i]- (validator/diff-edit-input i)+ (validator/patch-edit-input i)(def i_ (delete :author (strip-input i)))- (over-diffs (@ (lookup :diff-number i)) (merge-new i_))))+ (over-patches (@ (lookup :patch-number i)) (merge-new i_))))-(def list-diffs- "List existing diffs."- (fn [] (read-ref diffs)))+(def list-patches+ "List existing patches."+ (fn [] (read-ref patches)))(def commands"The set of allowed machine commands."- {'create-diff create-diff- 'list-diffs list-diffs- 'edit-diff edit-diff+ {'create-patch create-patch+ 'list-patches list-patches+ 'edit-patch edit-patch'add-comment add-comment'add-admin (add-admin auth)})diff --git a/rad/monadic/patch.rad b/rad/monadic/patch.radnew file mode 100644index 0000000..343b64a--- /dev/null+++ b/rad/monadic/patch.rad@@ -0,0 +1,106 @@+(load! (find-module-file! "prelude.rad"))++(import prelude/lens :unqualified)+(import prelude/machine '[send-code!] :unqualified)+(import prelude/time '[install-fake-clock] :unqualified)+(import prelude/io :as 'io)+(import prelude/key-management '[set-fake-keys! use-fake-keys! get-keys!] :unqualified)++(def radicle-patch-machine-id+ "The name of this machine."+ "monadic/radicle/patch")++(def create-patch-machine!+ "Create a remote patch machine. Returns the machine id"+ (fn []+ (def owner-keys (lookup :public-key (get-keys!)))+ (def id (machine/new-machine!))+ (machine/send-prelude! id)+ (send-code! id (find-module-file! "monadic/patch-remote.rad"))+ (machine/send-signed-command! id radicle-patch-machine-id 'add-admin {:key owner-keys})+ id))++(def simple-patch+ "Create an open patch with no comments or labels."+ (fn [p]+ (def t (now!))+ (<> {:state :pending+ :comments []+ :created-at t+ :modified-at t}+ p)))++(def simple-comment+ "Create a comment for an issue."+ (fn [patch-number bod author-name]+ (def t (now!))+ {:body bod+ :author-name author-name+ :patch-number patch-number+ :created-at t+ :modified-at t}))++(def edit-patch!+ "Edit a remote patch with the keys in `my-keys.rad`."+ (fn [machine i]+ (machine/send-signed-command! machine radicle-patch-machine-id 'edit-patch i)))++(def simple-edit-patch!+ (fn [machine n i]+ (edit-patch! machine+ (<> {:patch-number n+ :modified-at (now!)}+ i))))++(def create-patch!+ "Create a new remote patch with the keys in `my-keys.rad`."+ (fn [machine i]+ (machine/send-signed-command! machine radicle-patch-machine-id 'create-patch i)))++(def add-comment!+ "Create a remote comment with the keys in `my-keys.rad`."+ (fn [machine c]+ (machine/send-signed-command! machine radicle-patch-machine-id 'add-comment c)))++(def simple-create-patch!+ "Create a remote patch with sensible defaults."+ (fn [machine patch]+ (create-patch! machine (simple-patch patch))))++(def simple-add-comment!+ "Create a remote comment."+ (fn [machine n b name]+ (add-comment! machine (simple-comment n b name))))++(def list-patches+ "Return the full map of patches."+ (fn [machine]+ (machine/query! machine '(list-patches))))++(:test+ "The monadic patch machine works."+ [:setup+ (do (machine/install-remote-machine-fake)+ (def owner-keys (gen-key-pair! (default-ecc-curve)))+ (def non-owner-keys (gen-key-pair! (default-ecc-curve)))+ (set-fake-keys! owner-keys)+ (def machine (create-patch-machine!))+ (simple-create-patch! machine {:title "title0" :description "desc0" :patch "patch0"})+ (simple-create-patch! machine {:title "title1" :description "desc1" :patch "patch1"})+ (simple-add-comment! machine 0 "comment0" "name0")+ (simple-add-comment! machine 1 "comment1" "name1")+ (simple-edit-patch! machine 0 {:state :accepted})+ (def patches (list-patches machine)))]+ [ (length (seq patches)) ==> 2 ]+ [ (view (.. (@ 0) (@ :title)) patches) ==> "title0" ]+ [ (view (.. (@ 1) (@ :title)) patches) ==> "title1" ]+ [ (view (... [(@ 0) (@ :comments) (@nth 0) (@ :body)]) patches) ==> "comment0" ]+ [ (view (... [(@ 1) (@ :comments) (@nth 0) (@ :body)]) patches) ==> "comment1" ]+ [ (view (.. (@ 0) (@ :state)) patches) ==> :accepted ]+ ;; authorization+ [ (do+ (set-fake-keys! non-owner-keys)+ (catch 'validation-failure+ (simple-edit-patch! machine 1 {:state :accepted})+ (fn [_] :ok))) ==> :ok ]+)diff --git a/rad/monadic/project.rad b/rad/monadic/project.radindex 645e209..64f702d 100644--- a/rad/monadic/project.rad+++ b/rad/monadic/project.rad@@ -59,9 +59,9 @@(fn [machine id](add-rsm! machine { :id id :type :rad-issue })))-(def add-diff-rsm!+(def add-patch-rsm!(fn [machine id]- (add-rsm! machine { :id id :type :rad-diff })))+ (add-rsm! machine { :id id :type :rad-patch })))(def add-repo-rsm!(fn [machine id]@@ -87,20 +87,20 @@(install-fake-clock)(def machine (create-project! {:name "test" :description "test project"}))(add-issue-rsm! machine "a")- (add-diff-rsm! machine "b")+ (add-patch-rsm! machine "b")(add-repo-rsm! machine "c"))][ (get-meta! machine) ==> { :name "test" :description "test project" }][ (lookup :id (first-rsm-of-type! machine :rad-issue)) ==> "a" ]- [ (lookup :id (first-rsm-of-type! machine :rad-diff)) ==> "b" ]+ [ (lookup :id (first-rsm-of-type! machine :rad-patch)) ==> "b" ][ (lookup :id (first-rsm-of-type! machine :rad-repo)) ==> "c" ];; authorization[ (do(set-fake-keys! non-owner-keys)(def originally (length (list-rsms! machine)))(def res (catch 'validation-failure- (do (add-diff-rsm! machine "d")+ (do (add-patch-rsm! machine "d"):valid);; check that the machine has in fact not been added(fn [_] :not-valid)))diff --git a/rad/prelude/error-messages.rad b/rad/prelude/error-messages.radindex 769b9fd..220a4e4 100644--- a/rad/prelude/error-messages.rad+++ b/rad/prelude/error-messages.rad@@ -9,7 +9,7 @@upstream-push-failure item-not-found whole-item-number missing-item-numberstate-change-failure no-number-returned unknown-command unknown-commitparent-commit-not-master checkout-new-branch-failure checkout-master-failure- applying-patch-failure applying-accepted-patch-failure push-diff-failure+ applying-patch-failure applying-accepted-patch-failure push-patch-failuremissing-key-file rad-ipfs-name-publish-failure rad-ipfs-key-gen-failure]}@@ -73,11 +73,11 @@(def uppercase-item(fn [item]- (lookup item {:issue "Issue" :diff "Diff"})))+ (lookup item {:issue "Issue" :patch "Patch"})))(def lowercase-item(fn [item]- (lookup item {:issue "issue" :diff "diff"})))+ (lookup item {:issue "issue" :patch "patch"})));; rad project specific errors@@ -133,10 +133,10 @@ Make sure that git was initialized correctly and rerun 'rad project init'"])[(upstream-push-failure) ==> "Error: git -u origin master failed.Set the upstream branch manually and rerun 'rad project init'"])-;; rad diff specific errors+;; rad patch specific errors(def unknown-commit- "`rad diff propose` aborts if the provided commit is unknown."+ "`rad patch propose` aborts if the provided commit is unknown."(fn [commit](string-append"Commit " commit " can't be found.")))@@ -145,7 +145,7 @@ Set the upstream branch manually and rerun 'rad project init'"])[(unknown-commit "12345") ==> "Commit 12345 can't be found."])(def parent-commit-not-master- "`rad diff propose` aborts if the provided commit is unknown."+ "`rad patch propose` aborts if the provided commit is unknown."(fn [commit](string-append"Commit " commit " is not on top of origin/master.\n"@@ -156,15 +156,15 @@ Set the upstream branch manually and rerun 'rad project init'"])Squash all commits on your branch and rebase if necessary."])(def checkout-new-branch-failure- "`rad diff checkout` aborts if creating and switching to the diff branch fails."+ "`rad patch checkout` aborts if creating and switching to the patch branch fails."(fn [branch](string-append "Creating and switching to branch " branch " failed.")))(:test "checkout-new-branch-failure"- [(checkout-new-branch-failure "diff/3") ==> "Creating and switching to branch diff/3 failed."])+ [(checkout-new-branch-failure "patch/3") ==> "Creating and switching to branch patch/3 failed."])(def checkout-master-failure- "`rad diff accept` aborts if checking out the master branch fails."+ "`rad patch accept` aborts if checking out the master branch fails."(fn [](string-append"Checkout branch master failed.\n"@@ -175,7 +175,7 @@ Squash all commits on your branch and rebase if necessary."])Refusing to continue."])(def applying-patch-failure- "`rad diff checkout` aborts if applying the patch to the diff branch fails.+ "`rad patch checkout` aborts if applying the patch to the patch branch fails.Conflicts have to be resolved manually."(fn [](string-append@@ -187,7 +187,7 @@ Refusing to continue."])Abort or resolve any conflicts via 'git am'."])(def applying-accepted-patch-failure- "`rad diff accept` aborts if applying the patch to master fails.+ "`rad patch accept` aborts if applying the patch to master fails.Conflicts have to be resolved manually as well as pushing the commit."(fn [](string-append@@ -199,42 +199,42 @@ Abort or resolve any conflicts via 'git am'."])Abort or resolve any conflicts via 'git am'.Then run 'git push'."])-(def push-diff-failure- "`rad diff accept` aborts if pushing the diff failed."+(def push-patch-failure+ "`rad patch accept` aborts if pushing the patch failed."(fn [](string-append- "Pushing the diff failed.\n"+ "Pushing the patch failed.\n""This may be because you have no internet connection, ""you are not authorized to push to origin, ""or the remote is currently not reachable.")))-(:test "push-diff-failure"- [(push-diff-failure) ==> "Pushing the diff failed.+(:test "push-patch-failure"+ [(push-patch-failure) ==> "Pushing the patch failed.This may be because you have no internet connection, you are not authorized to push to origin, or the remote is currently not reachable."]);; shared app errors(def item-not-found- "Any command on a specific diff/issue aborts if it does not exist."+ "Any command on a specific patch/issue aborts if it does not exist."(fn [item item-number](string-append (uppercase-item item) " #" item-number " does not exist.")))(:test "item-not-found"- [(item-not-found :diff "2") ==> "Diff #2 does not exist."]+ [(item-not-found :patch "2") ==> "Patch #2 does not exist."][(item-not-found :issue "3") ==> "Issue #3 does not exist."])(def whole-item-number- "Any command on a specific diff/issue aborts if the provided `item-number`+ "Any command on a specific patch/issue aborts if the provided `item-number`is not a whole number."(fn [item](string-append (uppercase-item item) " numbers must be whole numbers!")))(:test "whole-item-number"- [(whole-item-number :diff) ==> "Diff numbers must be whole numbers!"]+ [(whole-item-number :patch) ==> "Patch numbers must be whole numbers!"][(whole-item-number :issue) ==> "Issue numbers must be whole numbers!"])(def missing-item-number- "Any command on a specific diff/issue aborts if the `item-number` is not provided."+ "Any command on a specific patch/issue aborts if the `item-number` is not provided."(fn [item action](def item-name (lowercase-item item))(string-append@@ -242,28 +242,28 @@ This may be because you have no internet connection, you are not authorized to p", please provide the " item-name " number.")))(:test "missing-item-number"- [(missing-item-number :diff "change the state of") ==> "To change the state of a diff, please provide the diff number."]+ [(missing-item-number :patch "change the state of") ==> "To change the state of a patch, please provide the patch number."][(missing-item-number :issue "show") ==> "To show an issue, please provide the issue number."])(def state-change-failure- "On changing the state of a diff/issue if the daemon returned an error."+ "On changing the state of a patch/issue if the daemon returned an error."(fn [item state](string-append(uppercase-item item) " could not be " state ". ""Are you authorized to do so?")))(:test "state-change-failure"- [(state-change-failure :diff "rejected") ==> "Diff could not be rejected. Are you authorized to do so?"]+ [(state-change-failure :patch "rejected") ==> "Patch could not be rejected. Are you authorized to do so?"][(state-change-failure :issue "closed") ==> "Issue could not be closed. Are you authorized to do so?"])(def no-number-returned- "On creating a diff/issue, when the creation was successful,- but no diff/issue number was returned."+ "On creating a patch/issue, when the creation was successful,+ but no patch/issue number was returned."(fn [item](string-append (uppercase-item item) " created but unexpected results returned.")))(:test "no-number-returned"- [(no-number-returned :diff) ==> "Diff created but unexpected results returned."]+ [(no-number-returned :patch) ==> "Patch created but unexpected results returned."][(no-number-returned :issue) ==> "Issue created but unexpected results returned."])(def unknown-commanddiff --git a/test/all.rad b/test/all.radindex 05fcb8e..c680590 100755--- a/test/all.rad+++ b/test/all.rad@@ -5,7 +5,7 @@(load! (find-module-file! "tests/stub-primitives.rad"))(load! (find-module-file! "prelude.rad"))-(load! (find-module-file! "monadic/diff.rad"))+(load! (find-module-file! "monadic/patch.rad"))(load! (find-module-file! "monadic/issue.rad"))(load! (find-module-file! "monadic/names.rad"))(load! (find-module-file! "monadic/project.rad"))diff --git a/test/e2e/DiffAppTest.hs b/test/e2e/PatchAppTest.hssimilarity index 68%rename from test/e2e/DiffAppTest.hsrename to test/e2e/PatchAppTest.hsindex b8db35d..f3aa689 100644--- a/test/e2e/DiffAppTest.hs+++ b/test/e2e/PatchAppTest.hs@@ -1,14 +1,14 @@--- | Test the Radicle diff app.-module DiffAppTest- ( test_diff_propose+-- | Test the Radicle patch app.+module PatchAppTest+ ( test_patch_propose) whereimport Protoludeimport Test.E2ESupport-test_diff_propose :: TestTree-test_diff_propose = testCaseSteps "diff propose" $ \step -> do+test_patch_propose :: TestTree+test_patch_propose = testCaseSteps "patch propose" $ \step -> dostep "Init project"_ <- runTestCommand "rad-key" ["create"]_ <- runTestCommand "git" ["config", "--global", "user.name", "Alice"]@@ -20,23 +20,23 @@ test_diff_propose = testCaseSteps "diff propose" $ \step -> do_ <- runTestCommand "git" ["commit", "--message", "first commit"]commitSha <- runTestCommand "git" ["rev-parse", "--short", "HEAD"]- step "rad diff propose"- _ <- runTestCommand "rad-diff" ["propose", "HEAD"]+ step "rad patch propose"+ _ <- runTestCommand "rad-patch" ["propose", "HEAD"]- listOutput <- runTestCommand "rad-diff" ["list"]+ listOutput <- runTestCommand "rad-patch" ["list"]assertContains listOutput "state #"assertContains listOutput "pending 0"- showOutput <- runTestCommand "rad-diff" ["show", "0"]+ showOutput <- runTestCommand "rad-patch" ["show", "0"]assertContains showOutput "pending 0"assertContains showOutput $ "From " <> commitShaassertContains showOutput "Comments\n---"- step "rad diff accept"+ step "rad patch accept"_ <- runTestCommand "git" ["checkout", "master"]- _ <- runTestCommand "rad-diff" ["accept", "0"]+ _ <- runTestCommand "rad-patch" ["accept", "0"]- showAcceptedOutput <- runTestCommand "rad-diff" ["show", "0"]+ showAcceptedOutput <- runTestCommand "rad-patch" ["show", "0"]assertContains showAcceptedOutput "accepted 0"logOutput <- runTestCommand "git" ["log", "master"]