aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-21 06:37:18 -0500
committerCraig Jennings <c@cjennings.net>2026-07-21 06:37:18 -0500
commit4f28daa3754c69f9fb3288bc7cdb5858f047f009 (patch)
tree4a2654bdc2b06febfbe278c956cf499453272428 /tests
parent0fa283a3a828bd99260792a4fffd772b2cec5bc0 (diff)
downloaddotemacs-4f28daa3754c69f9fb3288bc7cdb5858f047f009.tar.gz
dotemacs-4f28daa3754c69f9fb3288bc7cdb5858f047f009.zip
fix(system): resolve the locker at command time, not module load
lockscreen-cmd baked (env-wayland-p) into a defvar at load, so a daemon started before WAYLAND_DISPLAY reached its environment froze the locker to slock and Lock failed silently on Wayland. The lock command now resolves per call, with lockscreen-cmd kept as an explicit override. Craig confirmed the fix over the decline option since it also makes the systemd unit path safe to revive.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-system-commands-resolve-and-run.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test-system-commands-resolve-and-run.el b/tests/test-system-commands-resolve-and-run.el
index 9d92c5d6..7e5146b1 100644
--- a/tests/test-system-commands-resolve-and-run.el
+++ b/tests/test-system-commands-resolve-and-run.el
@@ -230,5 +230,37 @@ kill-emacs directly (the service owns the daemon lifecycle)."
(cj/system-command-menu))
(should (eq called 'cj/system-cmd-lock))))
+;;; Lock command resolves the locker at call time
+
+(defun test-system-cmd--run-lock-capturing ()
+ "Run the lock command; return the shell command line it launched."
+ (let (cmd-line)
+ (cl-letf (((symbol-function 'start-process-shell-command)
+ (lambda (_name _buf c) (setq cmd-line c) 'fake-proc))
+ ((symbol-function 'set-process-query-on-exit-flag) #'ignore)
+ ((symbol-function 'set-process-sentinel) #'ignore)
+ ((symbol-function 'message) #'ignore))
+ (cj/system-cmd-lock))
+ cmd-line))
+
+(ert-deftest test-system-cmd-lock-follows-session-type-at-call-time ()
+ "Normal: the locker tracks the live session type, not the load-time bake.
+A daemon started before WAYLAND_DISPLAY was imported used to freeze the
+locker to slock forever; Lock then failed silently on Wayland."
+ (let ((lockscreen-cmd nil))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () t)))
+ (should (string-match-p "loginctl lock-session"
+ (test-system-cmd--run-lock-capturing))))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () nil)))
+ (should (string-match-p "slock"
+ (test-system-cmd--run-lock-capturing))))))
+
+(ert-deftest test-system-cmd-lock-explicit-override-wins ()
+ "Boundary: a user-set lockscreen-cmd overrides the session-type resolution."
+ (let ((lockscreen-cmd "my-locker --now"))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () t)))
+ (should (string-match-p "my-locker --now"
+ (test-system-cmd--run-lock-capturing))))))
+
(provide 'test-system-commands-resolve-and-run)
;;; test-system-commands-resolve-and-run.el ends here