summaryrefslogtreecommitdiff
path: root/tests/test-ai-config-current-model-selection.el
blob: 14f9391c882cb4a2603db4e8a71b388213714fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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