diff options
| author | Craig Jennings <c@cjennings.net> | 2026-03-06 20:40:23 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-03-06 20:40:23 -0600 |
| commit | 873269cdea6a0c93f7eb25acabce8b72f8be6126 (patch) | |
| tree | 1e5f5484446f1e8d40df7e33a55ccef491158c49 /tests/test-ai-config-backend-and-model.el | |
| parent | 399901ab27b2d47e908782e94fbb96888aa89089 (diff) | |
test(gptel): add unit tests for ai-config, remove dead cj/gptel-backends
- Add testutil-ai-config.el with gptel stubs for batch testing
- Add tests for cj/gptel--model-to-string (9 tests)
- Add tests for cj/gptel--fresh-org-prefix (8 tests)
- Add tests for cj/gptel-backend-and-model (8 tests)
- Remove dead cj/gptel-backends defvar (duplicates cj/gptel--available-backends)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tests/test-ai-config-backend-and-model.el')
| -rw-r--r-- | tests/test-ai-config-backend-and-model.el | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test-ai-config-backend-and-model.el b/tests/test-ai-config-backend-and-model.el new file mode 100644 index 00000000..c03c58a2 --- /dev/null +++ b/tests/test-ai-config-backend-and-model.el @@ -0,0 +1,78 @@ +;;; test-ai-config-backend-and-model.el --- Tests for cj/gptel-backend-and-model -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for cj/gptel-backend-and-model from ai-config.el. +;; +;; Returns a formatted string "backend: model [timestamp]" for use in +;; org headings marking AI responses. Uses pcase to extract the display +;; name from vector backends, falling back to "AI" otherwise. + +;;; 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-backend-and-model-normal-vector-backend-extracts-name () + "Vector backend should use element at index 1 as display name." + (let ((gptel-backend (vector 'cl-struct "Claude")) + (gptel-model "claude-opus-4-6")) + (let ((result (cj/gptel-backend-and-model))) + (should (string-match-p "^Claude:" result)) + (should (string-match-p "claude-opus-4-6" result))))) + +(ert-deftest test-ai-config-backend-and-model-normal-contains-timestamp () + "Result should contain a bracketed timestamp." + (let ((gptel-backend nil) + (gptel-model nil)) + (should (string-match-p "\\[[-0-9]+ [0-9]+:[0-9]+:[0-9]+\\]" + (cj/gptel-backend-and-model))))) + +(ert-deftest test-ai-config-backend-and-model-normal-format-structure () + "Result should follow 'backend: model [timestamp]' format." + (let ((gptel-backend (vector 'cl-struct "TestBackend")) + (gptel-model "test-model")) + (should (string-match-p "^TestBackend: test-model \\[" + (cj/gptel-backend-and-model))))) + +;;; Boundary Cases + +(ert-deftest test-ai-config-backend-and-model-boundary-nil-backend-shows-ai () + "Nil backend should fall back to \"AI\" display name." + (let ((gptel-backend nil) + (gptel-model "some-model")) + (should (string-match-p "^AI:" (cj/gptel-backend-and-model))))) + +(ert-deftest test-ai-config-backend-and-model-boundary-nil-model-shows-empty () + "Nil model should produce empty string in model position." + (let ((gptel-backend nil) + (gptel-model nil)) + (should (string-match-p "^AI: \\[" (cj/gptel-backend-and-model))))) + +(ert-deftest test-ai-config-backend-and-model-boundary-string-backend-shows-ai () + "String backend (not vector) should fall back to \"AI\"." + (let ((gptel-backend "just-a-string") + (gptel-model "model")) + (should (string-match-p "^AI:" (cj/gptel-backend-and-model))))) + +(ert-deftest test-ai-config-backend-and-model-boundary-symbol-model-formatted () + "Symbol model should be formatted as its print representation." + (let ((gptel-backend nil) + (gptel-model 'some-model)) + (should (string-match-p "some-model" (cj/gptel-backend-and-model))))) + +(ert-deftest test-ai-config-backend-and-model-boundary-timestamp-reflects-today () + "Timestamp should contain today's date." + (let ((gptel-backend nil) + (gptel-model nil) + (today (format-time-string "%Y-%m-%d"))) + (should (string-match-p (regexp-quote today) + (cj/gptel-backend-and-model))))) + +(provide 'test-ai-config-backend-and-model) +;;; test-ai-config-backend-and-model.el ends here |
