diff options
| author | Craig Jennings <c@cjennings.net> | 2026-03-06 21:20:29 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-03-06 21:20:29 -0600 |
| commit | 3b120b35fff1e21114c7ff189def31b538c7a2ac (patch) | |
| tree | 39b717b0f433f38d72240ed5a17b73bcad8eefb4 /tests/test-ai-config-current-model-selection.el | |
| parent | 3eb1a0ccaa37410e6fe0059a9cb10145efa0d615 (diff) | |
refactor(gptel): extract model-list and selection logic for testability
- Extract cj/gptel--build-model-list from cj/gptel-change-model
- Extract cj/gptel--current-model-selection from cj/gptel-change-model
- Add test-ai-config-build-model-list.el (9 tests)
- Add test-ai-config-current-model-selection.el (8 tests)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tests/test-ai-config-current-model-selection.el')
| -rw-r--r-- | tests/test-ai-config-current-model-selection.el | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test-ai-config-current-model-selection.el b/tests/test-ai-config-current-model-selection.el new file mode 100644 index 00000000..14f9391c --- /dev/null +++ b/tests/test-ai-config-current-model-selection.el @@ -0,0 +1,74 @@ +;;; test-ai-config-current-model-selection.el --- Tests for cj/gptel--current-model-selection -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for cj/gptel--current-model-selection from ai-config.el. +;; +;; Pure function that formats the active backend and model into a display +;; string like "Anthropic - Claude: claude-opus-4-6". Used as the default +;; selection in the model-switching completing-read prompt. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'testutil-ai-config) +(require 'ai-config) + +;;; Normal Cases + +(ert-deftest test-ai-config-current-model-selection-normal-matching-backend () + "When current backend is in the backends alist, use its display name." + (let* ((backend-obj 'my-backend) + (backends `(("Anthropic - Claude" . ,backend-obj)))) + (should (equal (cj/gptel--current-model-selection backends backend-obj "opus") + "Anthropic - Claude: opus")))) + +(ert-deftest test-ai-config-current-model-selection-normal-symbol-model () + "Symbol model should be converted to string in the output." + (let* ((backend-obj 'my-backend) + (backends `(("Claude" . ,backend-obj)))) + (should (equal (cj/gptel--current-model-selection backends backend-obj 'opus) + "Claude: opus")))) + +(ert-deftest test-ai-config-current-model-selection-normal-multiple-backends () + "Should find the correct backend name among multiple backends." + (let* ((backend-a 'backend-a) + (backend-b 'backend-b) + (backends `(("Claude" . ,backend-a) ("OpenAI" . ,backend-b)))) + (should (equal (cj/gptel--current-model-selection backends backend-b "gpt-4o") + "OpenAI: gpt-4o")))) + +;;; Boundary Cases + +(ert-deftest test-ai-config-current-model-selection-boundary-nil-backend-shows-ai () + "Nil backend (not in alist) should fall back to \"AI\"." + (should (equal (cj/gptel--current-model-selection '(("Claude" . x)) nil "opus") + "AI: opus"))) + +(ert-deftest test-ai-config-current-model-selection-boundary-unknown-backend-shows-ai () + "Backend not found in alist should fall back to \"AI\"." + (should (equal (cj/gptel--current-model-selection + '(("Claude" . backend-a)) 'unknown-backend "opus") + "AI: opus"))) + +(ert-deftest test-ai-config-current-model-selection-boundary-nil-model () + "Nil model should produce \"nil\" in the model position (symbolp nil)." + (let* ((backend 'my-backend) + (backends `(("Claude" . ,backend)))) + (should (equal (cj/gptel--current-model-selection backends backend nil) + "Claude: nil")))) + +(ert-deftest test-ai-config-current-model-selection-boundary-empty-backends () + "Empty backends alist should fall back to \"AI\" for backend name." + (should (equal (cj/gptel--current-model-selection nil 'anything "model") + "AI: model"))) + +(ert-deftest test-ai-config-current-model-selection-boundary-both-nil () + "Nil backend and nil model should produce \"AI: nil\"." + (should (equal (cj/gptel--current-model-selection nil nil nil) + "AI: nil"))) + +(provide 'test-ai-config-current-model-selection) +;;; test-ai-config-current-model-selection.el ends here |
