aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-14 14:19:45 -0500
committerCraig Jennings <c@cjennings.net>2026-06-14 14:19:45 -0500
commitaf2ad1febf87027cbd4408312c1fff2815a9a0ff (patch)
tree4a40812ea73abf8954f46ae7781a6d8106d57874 /tests
parent269f23a38789190d112b04e8e70c3a6d649193b1 (diff)
downloaddotemacs-af2ad1febf87027cbd4408312c1fff2815a9a0ff.tar.gz
dotemacs-af2ad1febf87027cbd4408312c1fff2815a9a0ff.zip
fix(modeline): drop per-render truename, guard vc fetch against signals
The VC modeline cache rebuilt its key every render, and the key included file-truename, so a stat ran on every redisplay rather than once per refresh as the comment claimed. Now it keys on (file show-remote). A moved symlink target is caught at the next TTL refresh, when vc-backend resolves the link fresh. And cj/modeline-vc-fetch is wrapped in condition-case returning nil, so a git signal on a slow or unmounted filesystem degrades to no-VC-info instead of breaking all redisplay.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-modeline-config-vc-cache-key.el60
-rw-r--r--tests/test-modeline-config-vc-cache.el7
2 files changed, 27 insertions, 40 deletions
diff --git a/tests/test-modeline-config-vc-cache-key.el b/tests/test-modeline-config-vc-cache-key.el
index ae869f4b8..6ba7985c2 100644
--- a/tests/test-modeline-config-vc-cache-key.el
+++ b/tests/test-modeline-config-vc-cache-key.el
@@ -1,56 +1,36 @@
;;; test-modeline-config-vc-cache-key.el --- Tests for VC modeline cache key -*- lexical-binding: t; -*-
;;; Commentary:
-;; The VC modeline cache keys on the file. A symlink whose target moves to a
-;; different VC tree must invalidate the cache, so the key includes the
-;; resolved `file-truename', not just the symlink path.
+;; The VC modeline cache keys on the file path and the `cj/modeline-vc-show-remote'
+;; flag only. `file-truename' is deliberately NOT in the key: it would run on
+;; every redisplay (the mode-line rebuilds the key each render to check validity),
+;; and a moved symlink target is picked up at the next TTL refresh anyway, since
+;; `vc-backend' resolves the link fresh. The per-render stat isn't worth it.
;;; Code:
(require 'ert)
-(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'modeline-config)
-;;; Normal Cases
-
-(ert-deftest test-modeline-vc-cache-key-includes-truename ()
- "Normal: the cache key includes the resolved truename of the file."
- (let ((f (make-temp-file "cj-mlkey-")))
- (unwind-protect
- (should (member (file-truename f) (cj/modeline-vc-cache-key f)))
- (delete-file f))))
-
-;;; Boundary Cases
-
-(ert-deftest test-modeline-vc-cache-key-changes-when-symlink-target-moves ()
- "Boundary: re-pointing a symlink to a new target changes the cache key.
-The symlink path is identical both times; only its truename differs, so a
-key that ignored the truename would serve a stale VC backend."
- (let* ((dir (make-temp-file "cj-mlkey-dir-" t))
- (target-a (expand-file-name "a" dir))
- (target-b (expand-file-name "b" dir))
- (link (expand-file-name "link" dir)))
- (unwind-protect
- (progn
- (write-region "" nil target-a)
- (write-region "" nil target-b)
- (make-symbolic-link target-a link)
- (let ((key-a (cj/modeline-vc-cache-key link)))
- (delete-file link)
- (make-symbolic-link target-b link)
- (let ((key-b (cj/modeline-vc-cache-key link)))
- (should-not (equal key-a key-b)))))
- (delete-directory dir t))))
+(ert-deftest test-modeline-vc-cache-key-is-file-and-show-remote ()
+ "Normal: the key is (FILE SHOW-REMOTE), with no per-render file-truename stat."
+ (let ((cj/modeline-vc-show-remote nil))
+ (should (equal (cj/modeline-vc-cache-key "/x/y.el") '("/x/y.el" nil)))))
+
+(ert-deftest test-modeline-vc-cache-key-tracks-show-remote ()
+ "Boundary: toggling show-remote yields a different key (separate cache entry)."
+ (should-not (equal (let ((cj/modeline-vc-show-remote nil))
+ (cj/modeline-vc-cache-key "/x/y.el"))
+ (let ((cj/modeline-vc-show-remote t))
+ (cj/modeline-vc-cache-key "/x/y.el")))))
(ert-deftest test-modeline-vc-cache-key-stable-for-same-file ()
- "Boundary: the key is stable across calls for an unchanged file."
- (let ((f (make-temp-file "cj-mlkey-stable-")))
- (unwind-protect
- (should (equal (cj/modeline-vc-cache-key f)
- (cj/modeline-vc-cache-key f)))
- (delete-file f))))
+ "Boundary: the key is stable across calls for an unchanged file + show-remote."
+ (let ((cj/modeline-vc-show-remote nil))
+ (should (equal (cj/modeline-vc-cache-key "/x/y.el")
+ (cj/modeline-vc-cache-key "/x/y.el")))))
(provide 'test-modeline-config-vc-cache-key)
;;; test-modeline-config-vc-cache-key.el ends here
diff --git a/tests/test-modeline-config-vc-cache.el b/tests/test-modeline-config-vc-cache.el
index b6aafbfbe..dab755442 100644
--- a/tests/test-modeline-config-vc-cache.el
+++ b/tests/test-modeline-config-vc-cache.el
@@ -98,5 +98,12 @@
(should (text-property-any 0 (length rendered)
'mouse-face 'mode-line-highlight rendered)))))
+(ert-deftest test-modeline-config-vc-fetch-swallows-vc-errors ()
+ "Error: a signal from the VC backend is swallowed (returns nil) rather than
+propagating into the mode-line redisplay path, where it would break all redisplay."
+ (cl-letf (((symbol-function 'file-remote-p) (lambda (&rest _) nil))
+ ((symbol-function 'vc-backend) (lambda (&rest _) (error "git boom"))))
+ (should (null (cj/modeline-vc-fetch "/tmp/project/file.el")))))
+
(provide 'test-modeline-config-vc-cache)
;;; test-modeline-config-vc-cache.el ends here