diff options
| -rw-r--r-- | modules/signal-config.el | 9 | ||||
| -rw-r--r-- | tests/test-signal-config.el | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/modules/signal-config.el b/modules/signal-config.el index bed0f1e6..00279d4c 100644 --- a/modules/signal-config.el +++ b/modules/signal-config.el @@ -165,7 +165,14 @@ Three branches: If startup launches but the RPC handshake exits before the first response, the subsequent `signel--send-rpc' call (in the pre-warm or any later fetch) signals through its own error path; check =*signel-log*= and -=*signel-stderr*= for detail and link the account manually." +=*signel-stderr*= for detail and link the account manually. + +Loads the `signel' feature explicitly before reading any of its +private variables: the use-package above autoloads only on +`signel-start' / `signel-stop' / `signel-chat' / `signel-dashboard', +so without this require the first branch's read of `signel--process-name' +fires a void-variable error before the autoload would trigger." + (require 'signel) (cond ((process-live-p (get-process signel--process-name)) nil) diff --git a/tests/test-signal-config.el b/tests/test-signal-config.el index 6ddc7917..b362e03b 100644 --- a/tests/test-signal-config.el +++ b/tests/test-signal-config.el @@ -199,6 +199,29 @@ starting an account-less daemon." ((symbol-function 'get-process) (lambda (_) nil))) (should-error (cj/signel--ensure-started) :type 'user-error)))) +(ert-deftest test-signal-config-ensure-started-requires-signel-first () + "Error: ensure-started must `require' signel BEFORE reading any of +its private variables, so a `void-variable' error cannot fire when +called before signel has been autoloaded. Captures the bug where +`signel--process-name' was forward-declared in signal-config but not +yet bound at runtime because the `use-package' autoload had not fired. + +Asserts ordering, not just presence: a future refactor that moves the +`require' below the `cond' would still execute the require eventually +but the variable read in the cond would fire void-variable first. +The test fails if `require' isn't the first call inside the function." + (let ((call-order nil)) + (cl-letf (((symbol-function 'require) + (lambda (feature &optional _filename _noerror) + (push (list 'require feature) call-order) + t)) + ((symbol-function 'process-live-p) + (lambda (_) (push 'process-live-p call-order) t)) + ((symbol-function 'get-process) + (lambda (_) (push 'get-process call-order) 'fake-proc))) + (cj/signel--ensure-started) + (should (equal (car (reverse call-order)) '(require signel)))))) + ;;; cj/signel--fetch-contacts + cj/signel--contact-cache (ert-deftest test-signal-config-fetch-contacts-issues-list-contacts-rpc () |
