aboutsummaryrefslogtreecommitdiff
path: root/tests/test-pearl-sync-hooks.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-25 21:30:34 -0500
committerCraig Jennings <c@cjennings.net>2026-05-25 21:30:34 -0500
commit1de0623168d13c51fb9a7c8a87f89030642ae4d0 (patch)
treea4edf8b91ebafe8590145488f88b47a887ca716c /tests/test-pearl-sync-hooks.el
parent60b51e1c996f1c8f152696946b9440f26ea9a956 (diff)
downloadpearl-1de0623168d13c51fb9a7c8a87f89030642ae4d0.tar.gz
pearl-1de0623168d13c51fb9a7c8a87f89030642ae4d0.zip
refactor(save): remove the immediate-state-push org-sync machinery
The opt-in org-sync mode pushed Linear state immediately — on every TODO-keyword cycle (the org-after-todo-state-change hook) and on every buffer save (the after-save hook scanning the whole file). That's the last immediate-push path, and it contradicts the one-write-path model the rest of v2 builds, so I removed it: pearl-enable-org-sync / -disable-org-sync, pearl-org-hook-function, pearl-sync-org-to-linear, pearl-sync-current-heading-to-linear, and the now-orphaned pearl--process-heading-at-point, pearl--map-org-state-to-linear, and pearl--update-issue-state-async. This finishes the "make org-sync private" task — there was nothing left to make private. Cycling a TODO keyword now marks state dirty (reconciled at the next save) instead of pushing. Saving the buffer pushes nothing. Re-introducing an auto-push on save is the separate "Automatic sync on save" task, which would call the save engine rather than this whole-file scanner. I kept pearl--extract-org-heading-properties and pearl--get-todo-states-pattern. They're general heading/keyword readers, not org-sync-specific, and the keyword-cycle save (the keyword-derivation follow-up) needs exactly them. The obsolete sync tests are replaced by two that assert the contract: the sync commands are gone, and a keyword cycle pushes nothing.
Diffstat (limited to 'tests/test-pearl-sync-hooks.el')
-rw-r--r--tests/test-pearl-sync-hooks.el168
1 files changed, 24 insertions, 144 deletions
diff --git a/tests/test-pearl-sync-hooks.el b/tests/test-pearl-sync-hooks.el
index 05864e7..0ee7d82 100644
--- a/tests/test-pearl-sync-hooks.el
+++ b/tests/test-pearl-sync-hooks.el
@@ -19,157 +19,37 @@
;;; Commentary:
-;; Tests for the org sync hook wiring: enable/disable add and remove
-;; buffer-local hooks; the after-save hook only fires for linear.org buffers;
-;; and per-heading sync degrades gracefully when point is before any heading.
+;; Save-model-v2 removed the opt-in org-sync mode. The after-save and
+;; TODO-cycle hooks that pushed Linear state immediately are gone -- every push
+;; now goes through the save engine (pearl-save-issue / pearl-save-all). These
+;; tests assert the removal: the sync commands no longer exist, and cycling a
+;; TODO keyword pushes nothing.
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
(require 'cl-lib)
-;;; enable / disable
-
-(ert-deftest test-pearl-enable-org-sync-adds-buffer-local-hooks ()
- "Enabling sync adds both hook functions buffer-locally."
- (with-temp-buffer
- (pearl-enable-org-sync)
- (should (memq 'pearl-org-hook-function after-save-hook))
- (should (memq 'pearl-sync-org-to-linear org-after-todo-state-change-hook))))
-
-(ert-deftest test-pearl-disable-org-sync-removes-hooks ()
- "Disabling sync removes both hook functions."
- (with-temp-buffer
- (pearl-enable-org-sync)
- (pearl-disable-org-sync)
- (should-not (memq 'pearl-org-hook-function after-save-hook))
- (should-not (memq 'pearl-sync-org-to-linear org-after-todo-state-change-hook))))
-
-;;; org-hook-function buffer guard
-
-(ert-deftest test-pearl-org-hook-function-skips-other-buffer ()
- "The after-save hook does nothing in a buffer that isn't the configured file."
- (let ((called nil)
- (pearl-org-file-path "/tmp/linear.org"))
- (cl-letf (((symbol-function 'pearl-sync-org-to-linear) (lambda () (setq called t))))
- (with-temp-buffer
- (setq buffer-file-name "/tmp/scratch.org")
- (pearl-org-hook-function)
- (should-not called)))))
-
-(ert-deftest test-pearl-org-hook-function-syncs-configured-buffer ()
- "The after-save hook syncs when the buffer visits `pearl-org-file-path'."
- (let ((called nil)
- (pearl-org-file-path "/tmp/linear.org"))
- (cl-letf (((symbol-function 'pearl-sync-org-to-linear) (lambda () (setq called t))))
- (with-temp-buffer
- (setq buffer-file-name "/tmp/linear.org")
- (pearl-org-hook-function)
- (should called)))))
-
-(ert-deftest test-pearl-org-hook-function-honors-custom-path ()
- "A non-default `pearl-org-file-path' is what the hook matches on.
-Regression: the hook used to hardcode a \"linear.org$\" regex, so a buffer
-named linear.org fired even when the configured file was elsewhere, and a
-custom-named configured file never fired."
- (let ((called nil)
- (pearl-org-file-path "/tmp/my-linear-issues.org"))
- (cl-letf (((symbol-function 'pearl-sync-org-to-linear) (lambda () (setq called t))))
- ;; A buffer literally named linear.org must NOT fire when the configured
- ;; file is something else.
- (with-temp-buffer
- (setq buffer-file-name "/tmp/linear.org")
- (pearl-org-hook-function)
- (should-not called))
- ;; The configured custom-named file DOES fire.
- (with-temp-buffer
- (setq buffer-file-name "/tmp/my-linear-issues.org")
- (pearl-org-hook-function)
- (should called)))))
-
-(ert-deftest test-pearl-org-hook-function-matches-through-symlink ()
- "A configured path and a visited symlink to the same file match via truename.
-The hook resolves both sides with `file-truename', so a symlink to the
-configured file still syncs -- this guards the choice of truename over a raw
-string compare."
- (let ((real (make-temp-file "linear-real-" nil ".org"))
- (link (make-temp-file "linear-link-" nil ".org"))
- (called nil))
- (unwind-protect
- (progn
- (delete-file link)
- (make-symbolic-link real link)
- (let ((pearl-org-file-path real))
- (cl-letf (((symbol-function 'pearl-sync-org-to-linear)
- (lambda () (setq called t))))
- (with-temp-buffer
- (setq buffer-file-name link)
- (pearl-org-hook-function)
- (should called)))))
- (when (file-exists-p link) (delete-file link))
- (when (file-exists-p real) (delete-file real)))))
-
-(ert-deftest test-pearl-org-hook-function-nil-path-no-op ()
- "With `pearl-org-file-path' nil, the hook is a no-op and does not error."
- (let ((called nil)
- (pearl-org-file-path nil))
- (cl-letf (((symbol-function 'pearl-sync-org-to-linear) (lambda () (setq called t))))
- (with-temp-buffer
- (setq buffer-file-name "/tmp/linear.org")
- (should (progn (pearl-org-hook-function) t))
- (should-not called)))))
-
-;;; sync-current-heading-to-linear
-
-(ert-deftest test-pearl-sync-current-heading-before-first-heading-no-error ()
- "Syncing with point before the first heading degrades gracefully.
-
-Regression: `org-back-to-heading' signals \"before first heading\" in the
-preamble, which must not propagate out of the sync entry point."
- (cl-letf (((symbol-function 'pearl--process-heading-at-point) (lambda () nil)))
- (with-temp-buffer
- (insert "#+TITLE: x\n\npreamble line\n")
- (org-mode)
- (goto-char (point-min))
- (should (progn (pearl-sync-current-heading-to-linear) t)))))
-
-(ert-deftest test-pearl-sync-current-heading-processes-on-heading ()
- "Syncing from within an entry processes that heading."
- (let ((called nil))
- (cl-letf (((symbol-function 'pearl--process-heading-at-point)
- (lambda () (setq called t))))
- (with-temp-buffer
- (insert "* Top\n*** TODO x\n")
- (org-mode)
- (goto-char (point-max))
- (pearl-sync-current-heading-to-linear)
- (should called)))))
-
-;;; sync-org-to-linear dispatcher
-
-(ert-deftest test-pearl-sync-org-to-linear-org-todo-syncs-current-heading ()
- "When invoked from `org-todo', only the current heading is synced."
- (let ((called nil)
- (this-command 'org-todo))
- (cl-letf (((symbol-function 'pearl-sync-current-heading-to-linear)
- (lambda () (setq called t))))
- (pearl-sync-org-to-linear)
- (should called))))
-
-(ert-deftest test-pearl-sync-org-to-linear-otherwise-scans-whole-file ()
- "Outside `org-todo', every matching heading in the buffer is processed."
- (let ((count 0)
- (this-command 'some-other-command)
- (pearl-state-to-todo-mapping '(("Todo" . "TODO") ("Done" . "DONE")))
- (pearl-todo-states-pattern nil)
- (pearl--todo-states-pattern-source nil))
- (cl-letf (((symbol-function 'pearl--process-heading-at-point)
- (lambda () (setq count (1+ count)))))
+(ert-deftest test-pearl-org-sync-commands-removed ()
+ "The opt-in org-sync mode and its push machinery no longer exist."
+ (should-not (fboundp 'pearl-enable-org-sync))
+ (should-not (fboundp 'pearl-disable-org-sync))
+ (should-not (fboundp 'pearl-org-hook-function))
+ (should-not (fboundp 'pearl-sync-org-to-linear))
+ (should-not (fboundp 'pearl-sync-current-heading-to-linear)))
+
+(ert-deftest test-pearl-keyword-cycle-pushes-nothing ()
+ "Cycling a TODO keyword pushes nothing -- pearl wires no TODO-cycle sync hook."
+ (let ((pushed nil))
+ (cl-letf (((symbol-function 'pearl--update-issue-async)
+ (lambda (&rest _) (setq pushed t))))
(with-temp-buffer
- (insert "*** TODO a\n*** DONE b\n")
- (org-mode)
- (pearl-sync-org-to-linear)
- (should (= 2 count))))))
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
+ (insert "*** TODO Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\n")
+ (org-mode)
+ (goto-char (point-min))
+ (org-todo "DONE"))
+ (should-not pushed)))))
(provide 'test-pearl-sync-hooks)
;;; test-pearl-sync-hooks.el ends here