aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-04 17:48:49 -0500
committerCraig Jennings <c@cjennings.net>2026-07-04 17:48:49 -0500
commit389a4005b48d186fe4956f0455605b6fdb1dbb65 (patch)
tree2970f8ab15f1a24792ff29effdc28e594ec340b6 /tests
parent48f0bbd7a1894fafd46f1093d5a17300efbba0bb (diff)
downloaddotemacs-389a4005b48d186fe4956f0455605b6fdb1dbb65.tar.gz
dotemacs-389a4005b48d186fe4956f0455605b6fdb1dbb65.zip
fix(org): log state changes into LOGBOOK and drop no-op transitions
State-change log lines were written inline (org-log-into-drawer nil), where a line landing between a heading and its DEADLINE/SCHEDULED line broke org's planning-line parser and dropped the entry from agenda views. org also logged no-op "State X from X" transitions that carry no information. Set org-log-into-drawer to t so state changes land in :LOGBOOK: drawers, and add an around-advice on org-add-log-setup that skips identical from/to transitions. The suppression decision lives in a pure predicate so it's tested without driving org-todo. This removes the cause rather than stripping the lines after they appear.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-config-noop-state-log.el59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test-org-config-noop-state-log.el b/tests/test-org-config-noop-state-log.el
new file mode 100644
index 00000000..125eb300
--- /dev/null
+++ b/tests/test-org-config-noop-state-log.el
@@ -0,0 +1,59 @@
+;;; test-org-config-noop-state-log.el --- Suppress no-op state-change logs -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; org's state-change logging writes "- State X from X" lines for no-op
+;; transitions (identical from/to state), which carry no information. With
+;; `org-log-into-drawer' nil those lines also land inline, where they wedge
+;; between a heading and its planning line and break org's parser. Two fixes
+;; in `cj/org-todo-settings': log state changes into :LOGBOOK: drawers
+;; (`org-log-into-drawer' t), and suppress no-op state logs at the
+;; `org-add-log-setup' choke point via `cj/org--suppress-noop-state-log'.
+
+;;; Code:
+
+(require 'ert)
+(require 'org) ;; declares the org-log-* vars special
+(require 'org-config)
+
+(ert-deftest test-org-config-log-into-drawer-enabled ()
+ "Normal: cj/org-todo-settings enables org-log-into-drawer (LOGBOOK)."
+ (let ((org-log-into-drawer nil))
+ (cj/org-todo-settings)
+ (should (eq org-log-into-drawer t))))
+
+(ert-deftest test-org-config-noop-state-log-p-identical-is-noop ()
+ "Normal: identical from/to state on a 'state purpose is a no-op."
+ (should (cj/org--noop-state-log-p 'state "TODO" "TODO")))
+
+(ert-deftest test-org-config-noop-state-log-p-real-change-not-noop ()
+ "Normal: a genuine state change is not a no-op."
+ (should-not (cj/org--noop-state-log-p 'state "DONE" "TODO")))
+
+(ert-deftest test-org-config-noop-state-log-p-nil-prev-not-noop ()
+ "Boundary: a nil previous state (initial log) is not a no-op."
+ (should-not (cj/org--noop-state-log-p 'state "TODO" nil)))
+
+(ert-deftest test-org-config-noop-state-log-p-non-state-purpose-not-noop ()
+ "Boundary: identical strings under a non-state purpose are not suppressed."
+ (should-not (cj/org--noop-state-log-p 'note "x" "x")))
+
+(ert-deftest test-org-config-noop-state-log-p-nil-both-not-noop ()
+ "Error: a nil/nil state pair is not a suppressible no-op."
+ (should-not (cj/org--noop-state-log-p 'state nil nil)))
+
+(ert-deftest test-org-config-suppress-advice-skips-noop ()
+ "Normal: the advice does NOT call through for a no-op state transition."
+ (let ((called nil))
+ (cj/org--suppress-noop-state-log
+ (lambda (&rest _) (setq called t)) 'state "TODO" "TODO")
+ (should-not called)))
+
+(ert-deftest test-org-config-suppress-advice-passes-real-change ()
+ "Normal: the advice calls through for a genuine state change."
+ (let ((called nil))
+ (cj/org--suppress-noop-state-log
+ (lambda (&rest _) (setq called t)) 'state "DONE" "TODO")
+ (should called)))
+
+(provide 'test-org-config-noop-state-log)
+;;; test-org-config-noop-state-log.el ends here