diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-31 07:14:56 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-31 07:14:56 -0500 |
| commit | b2710e21202a2f2f7542d11d19f0cd5d20b5ebf2 (patch) | |
| tree | 2293c2dda302e5eaf5cc41c7efd3d05166828fc5 /tests | |
| parent | 394c75b2f92e2a72390b3417e483849bed13a399 (diff) | |
| download | pearl-b2710e21202a2f2f7542d11d19f0cd5d20b5ebf2.tar.gz pearl-b2710e21202a2f2f7542d11d19f0cd5d20b5ebf2.zip | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-pearl-accounts.el | 34 |
1 files changed, 34 insertions, 0 deletions
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 |
