From 5f72705cf8534543134da907a26069fff97b799c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 15:04:30 -0500 Subject: test: assert the dirty-buffer path preserves disk and buffer state Extended the dirty-buffer coverage: with known content saved to disk and an unsaved edit on top, pearl--update-org-from-issues leaves the buffer modified with its edit, leaves the on-disk file at the original saved content (not the render, not the buffer text), and still surfaces the dirty buffer per the UX contract. 362 tests green. --- tests/test-pearl-org-write.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test-pearl-org-write.el b/tests/test-pearl-org-write.el index c253190..bd06ef0 100644 --- a/tests/test-pearl-org-write.el +++ b/tests/test-pearl-org-write.el @@ -26,6 +26,7 @@ ;;; Code: (require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'cl-lib) (defvar test-pearl--sample-issues '((:id "u" :identifier "ENG-1" :title "T" :priority 3 :state (:name "Todo"))) @@ -81,5 +82,33 @@ The state mapping is bound so rendering is deterministic." (should (string-match-p "unsaved edits" (buffer-string))) (should-not (string-match-p "ENG-1" (buffer-string))))))) +(ert-deftest test-pearl-update-org-dirty-buffer-preserves-disk-and-surfaces () + "A dirty buffer is left as-is, the on-disk file is untouched, and the buffer is surfaced." + (test-pearl--with-org-file tmp + (let ((buf (find-file-noselect tmp)) + (surfaced nil)) + (with-current-buffer buf + (insert "ORIGINAL DISK CONTENT\n") + (save-buffer) + ;; an unsaved edit on top of the saved content + (goto-char (point-max)) + (insert "UNSAVED EDIT\n")) + (cl-letf (((symbol-function 'pearl--surface-buffer) + (lambda (b) (setq surfaced b)))) + (pearl--update-org-from-issues test-pearl--sample-issues)) + ;; buffer keeps the unsaved edit and stays modified + (with-current-buffer buf + (should (buffer-modified-p)) + (should (string-match-p "UNSAVED EDIT" (buffer-string))) + (should-not (string-match-p "ENG-1" (buffer-string)))) + ;; the disk file still holds the original saved content — not the render, + ;; and not the unsaved buffer text + (let ((disk (with-temp-buffer (insert-file-contents tmp) (buffer-string)))) + (should (string-match-p "ORIGINAL DISK CONTENT" disk)) + (should-not (string-match-p "UNSAVED EDIT" disk)) + (should-not (string-match-p "ENG-1" disk))) + ;; the dirty buffer is still surfaced, per the UX contract + (should (eq surfaced buf))))) + (provide 'test-pearl-org-write) ;;; test-pearl-org-write.el ends here -- cgit v1.2.3