aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 15:01:01 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 15:01:01 -0500
commit1a26149d4d7f16adb1552ba31a2de290a5c86fc4 (patch)
treeb61b23fd96ee757e6cc04020532c0717d20b102f
parent44b7e8e42383a0e2c7024f250c2d16de6b66c652 (diff)
downloadpearl-1a26149d4d7f16adb1552ba31a2de290a5c86fc4.tar.gz
pearl-1a26149d4d7f16adb1552ba31a2de290a5c86fc4.zip
test: cover sync-back push-failure branches at the command level
Added ERT tests that the three sync commands leave provenance untouched when the push fails (:success nil): pearl-sync-current-issue keeps LINEAR-DESC-SHA256 and -UPDATED-AT, pearl-sync-current-issue-title keeps LINEAR-TITLE-SHA256, and pearl-edit-current-comment keeps LINEAR-COMMENT-SHA256 — and in each case the edited text stays in the buffer for retry. Each test asserts the push was attempted with the rendered text. The commands already behave correctly; this locks it. 360 tests green.
-rw-r--r--tests/test-pearl-comment-editing.el20
-rw-r--r--tests/test-pearl-sync.el19
-rw-r--r--tests/test-pearl-title-sync.el16
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/test-pearl-comment-editing.el b/tests/test-pearl-comment-editing.el
index 05a3a76..866366f 100644
--- a/tests/test-pearl-comment-editing.el
+++ b/tests/test-pearl-comment-editing.el
@@ -214,6 +214,26 @@
(pearl-edit-current-comment)
(should-not updated)))))
+(ert-deftest test-pearl-edit-comment-push-failure-keeps-hash ()
+ "A failed comment push keeps the stored hash and the edited body for retry."
+ (test-pearl--in-org (test-pearl--comment-doc "u-me" "old body" "new body")
+ (let ((pearl--cache-viewer '(:id "u-me" :name "Me"))
+ (pushed-body nil)
+ (stored (secure-hash 'sha256 "old body")))
+ (cl-letf (((symbol-function 'pearl--fetch-comment-body-async)
+ (lambda (_id cb) (funcall cb "old body")))
+ ((symbol-function 'pearl--update-comment-async)
+ (lambda (_id body cb) (setq pushed-body body) (funcall cb '(:success nil)))))
+ (re-search-forward "new body")
+ (pearl-edit-current-comment)
+ ;; push attempted with the edited body ...
+ (should (string= "new body" pushed-body))
+ ;; ... but the stored hash is not advanced and the edit stays.
+ (goto-char (point-min))
+ (re-search-forward "^\\*\\*\\*\\*\\* Craig")
+ (should (string= stored (org-entry-get nil "LINEAR-COMMENT-SHA256")))
+ (should (string= "new body" (pearl--issue-body-at-point)))))))
+
;;; editability highlighting
(ert-deftest test-pearl-highlight-comments-colors-by-editability ()
diff --git a/tests/test-pearl-sync.el b/tests/test-pearl-sync.el
index 6127914..738e3ff 100644
--- a/tests/test-pearl-sync.el
+++ b/tests/test-pearl-sync.el
@@ -202,5 +202,24 @@ helper (nil when never called); the update helper reports success."
"* Just a plain heading\nno linear id here\n"
(should-error (pearl-sync-current-issue) :type 'user-error)))
+(ert-deftest test-pearl-sync-current-issue-push-failure-keeps-provenance ()
+ "A failed description push keeps the hash, timestamp, and edited body for retry."
+ (let ((updates nil)
+ (stored (secure-hash 'sha256 "baseline remote")))
+ (test-pearl--in-org
+ (format "*** TODO ENG-1 Title\n:PROPERTIES:\n:LINEAR-ID: a\n:LINEAR-DESC-SHA256: %s\n:LINEAR-DESC-UPDATED-AT: old\n:END:\nEdited body now.\n"
+ stored)
+ (cl-letf (((symbol-function 'pearl--fetch-issue-description-async)
+ (lambda (_id cb) (funcall cb '(:description "baseline remote" :updated-at "t0"))))
+ ((symbol-function 'pearl--update-issue-description-async)
+ (lambda (_id md cb) (push md updates) (funcall cb '(:success nil)))))
+ (pearl-sync-current-issue)
+ ;; the push was attempted with the rendered body ...
+ (should (equal (list (pearl--org-to-md "Edited body now.")) updates))
+ ;; ... but provenance is not advanced and the edit stays for retry.
+ (should (string= stored (org-entry-get nil "LINEAR-DESC-SHA256")))
+ (should (string= "old" (org-entry-get nil "LINEAR-DESC-UPDATED-AT")))
+ (should (string= "Edited body now." (pearl--issue-body-at-point)))))))
+
(provide 'test-pearl-sync)
;;; test-pearl-sync.el ends here
diff --git a/tests/test-pearl-title-sync.el b/tests/test-pearl-title-sync.el
index 6fbd284..512794c 100644
--- a/tests/test-pearl-title-sync.el
+++ b/tests/test-pearl-title-sync.el
@@ -161,5 +161,21 @@ stripped heading, so an unedited bracketed title is never clobbered on Linear."
(test-pearl--in-org "* Plain heading\nno id\n"
(should-error (pearl-sync-current-issue-title) :type 'user-error)))
+(ert-deftest test-pearl-sync-title-push-failure-keeps-provenance ()
+ "A failed title push keeps the hash and the edited heading for retry."
+ (let ((updates nil)
+ (stored (secure-hash 'sha256 "Old Title")))
+ (test-pearl--in-org
+ (format "*** TODO [#B] Edited Title\n:PROPERTIES:\n:LINEAR-ID: a\n:LINEAR-TITLE-SHA256: %s\n:END:\n"
+ stored)
+ (cl-letf (((symbol-function 'pearl--fetch-issue-title-async)
+ (lambda (_id cb) (funcall cb '(:title "Old Title" :updated-at "t0"))))
+ ((symbol-function 'pearl--update-issue-title-async)
+ (lambda (_id title cb) (push title updates) (funcall cb '(:success nil)))))
+ (pearl-sync-current-issue-title)
+ (should (equal '("Edited Title") updates))
+ (should (string= stored (org-entry-get nil "LINEAR-TITLE-SHA256")))
+ (should (string= "Edited Title" (pearl--issue-title-at-point)))))))
+
(provide 'test-pearl-title-sync)
;;; test-pearl-title-sync.el ends here