diff options
| -rw-r--r-- | pearl.el | 23 | ||||
| -rw-r--r-- | tests/test-pearl-accounts.el | 34 |
2 files changed, 51 insertions, 6 deletions
@@ -5870,13 +5870,24 @@ resolves to a single label." ;;;###autoload (defun pearl-check-setup () - "Check if Linear.el is properly set up." + "Check if Pearl is properly set up, then test the connection. +Under accounts mode reports on the active account (resolving the default on +first need) rather than the legacy `pearl-api-key' global, which is normally +unset once `pearl-accounts' is configured." (interactive) - (if pearl-api-key - (progn - (message "API key is set (length: %d). Testing connection..." (length pearl-api-key)) - (pearl-test-connection)) - (message "Linear API key is not set. Use M-x customize-variable RET pearl-api-key"))) + (if pearl-accounts + (condition-case err + (let ((ctx (pearl--current-account-context))) + (message "Account %s is set up (key resolved). Testing connection..." + (plist-get ctx :name)) + (pearl-test-connection)) + (error (message "Pearl accounts are configured but not usable: %s" + (error-message-string err)))) + (if pearl-api-key + (progn + (message "API key is set (length: %d). Testing connection..." (length pearl-api-key)) + (pearl-test-connection)) + (message "Linear API key is not set. Use M-x customize-variable RET pearl-api-key")))) ;;;###autoload (defun pearl-load-api-key-from-env () diff --git a/tests/test-pearl-accounts.el b/tests/test-pearl-accounts.el index c0514a8..f8bc06b 100644 --- a/tests/test-pearl-accounts.el +++ b/tests/test-pearl-accounts.el @@ -477,5 +477,39 @@ account first\" — the refresh the guard tells the user to run must resolve." (pearl--update-source-header 1 nil) (should (null (pearl--read-buffer-account)))))) +;;; pearl-check-setup is account-aware + +(ert-deftest test-pearl-check-setup-accounts-mode-resolves-and-tests () + "Under accounts, check-setup reports the active account and runs the test even +when the legacy `pearl-api-key' global is unset — the account resolves the key." + (let ((pearl-accounts '(("work" :api-key-source (:literal "kw") :org-file "/tmp/w.org"))) + (pearl-active-account "work") (pearl-default-account "work") + (pearl-api-key nil) + (tested nil)) + (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t)))) + (pearl-check-setup) + (should tested)))) + +(ert-deftest test-pearl-check-setup-accounts-mode-unresolvable-skips-test () + "Under accounts with no usable active account, check-setup reports and does not +fire the connection test (and does not signal)." + (let ((pearl-accounts '(("work" :api-key-source (:literal "kw") :org-file "/tmp/w.org"))) + (pearl-active-account nil) (pearl-default-account nil) + (tested nil)) + (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t)))) + (pearl-check-setup) + (should-not tested)))) + +(ert-deftest test-pearl-check-setup-legacy-mode-unchanged () + "In legacy mode the gate still reads the global key: set -> test, unset -> message." + (let ((pearl-accounts nil) (pearl-active-account nil) (pearl-default-account nil) + (tested nil)) + (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t)))) + (let ((pearl-api-key "lin_legacy")) (pearl-check-setup)) + (should tested) + (setq tested nil) + (let ((pearl-api-key nil)) (pearl-check-setup)) + (should-not tested)))) + (provide 'test-pearl-accounts) ;;; test-pearl-accounts.el ends here |
