From b2710e21202a2f2f7542d11d19f0cd5d20b5ebf2 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 31 May 2026 07:14:56 -0500 Subject: fix(accounts): pearl-check-setup reports the active account, not the legacy key The setup check gated on pearl-api-key, which is normally unset once pearl-accounts is configured, so under multi-account it wrongly reported "API key is not set" and skipped the connection test even when the active account resolved a key fine. Under accounts mode it now resolves the active account's context, names it, and runs the test. An unusable setup (no default, missing key) reports the reason instead of signaling. Legacy single-account behavior is unchanged. The resolved key is never printed. --- pearl.el | 23 +++++++++++++++++------ tests/test-pearl-accounts.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pearl.el b/pearl.el index 7214214..2ef4fae 100644 --- a/pearl.el +++ b/pearl.el @@ -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 -- cgit v1.2.3