diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 07:22:56 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 07:22:56 -0500 |
| commit | 9135298c45f2f03ab92903edb242c8f5f94396d5 (patch) | |
| tree | 7e7cb2f000c9ffb67a45931af8aaccb64ff7bf88 /tests/test-modeline-config-vc-cache-key.el | |
| parent | 12fb0108ba217f06fb9d40da8431d49540650402 (diff) | |
| download | dotemacs-9135298c45f2f03ab92903edb242c8f5f94396d5.tar.gz dotemacs-9135298c45f2f03ab92903edb242c8f5f94396d5.zip | |
fix(modeline): key VC cache on resolved truename for symlink moves
The VC modeline cache keyed on (list file cj/modeline-vc-show-remote). If file was a symlink whose target moved to a different VC tree (shared drives, CI workspaces), the key was unchanged and the cache kept serving the old branch/state.
Added the resolved file-truename to the key, so a symlink re-pointed at a new target produces a different key and the cache refreshes. The extra file-truename is one stat per modeline refresh, cheap next to the VC calls the cache exists to avoid. Tests cover truename inclusion, key stability for an unchanged file, and a symlink whose target moves.
Diffstat (limited to 'tests/test-modeline-config-vc-cache-key.el')
| -rw-r--r-- | tests/test-modeline-config-vc-cache-key.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-modeline-config-vc-cache-key.el b/tests/test-modeline-config-vc-cache-key.el new file mode 100644 index 00000000..ae869f4b --- /dev/null +++ b/tests/test-modeline-config-vc-cache-key.el @@ -0,0 +1,56 @@ +;;; 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. + +;;; 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-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)))) + +(provide 'test-modeline-config-vc-cache-key) +;;; test-modeline-config-vc-cache-key.el ends here |
