aboutsummaryrefslogtreecommitdiff
path: root/tests/test-ai-config-gptel-local-tools.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-10 02:43:48 -0500
committerCraig Jennings <c@cjennings.net>2026-05-10 02:43:48 -0500
commit0248afe222a0722ec336e8c09269612eb773702b (patch)
tree0108507c9b92616dca51b6c575137785f2f8d4dc /tests/test-ai-config-gptel-local-tools.el
parentc78574ab7a7bd0f9a6e4a61c6cdcd196257cff8e (diff)
downloaddotemacs-0248afe222a0722ec336e8c09269612eb773702b.tar.gz
dotemacs-0248afe222a0722ec336e8c09269612eb773702b.zip
Move GPTel tool loading into AI config
Move the local GPTel tool wiring out of init.el and into ai-config. The tools directory and feature list are now configurable, missing optional tools are non-fatal, and focused tests cover the loading behavior.
Diffstat (limited to 'tests/test-ai-config-gptel-local-tools.el')
-rw-r--r--tests/test-ai-config-gptel-local-tools.el57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test-ai-config-gptel-local-tools.el b/tests/test-ai-config-gptel-local-tools.el
new file mode 100644
index 00000000..8d3a45ac
--- /dev/null
+++ b/tests/test-ai-config-gptel-local-tools.el
@@ -0,0 +1,57 @@
+;;; test-ai-config-gptel-local-tools.el --- Tests for local GPTel tool loading -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; Tests for optional local GPTel tool loading from ai-config.el.
+
+;;; 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))
+(setq load-prefer-newer t)
+(require 'testutil-ai-config)
+(require 'ai-config)
+
+(defun test-ai-config-gptel-local-tools--write-tool (dir feature)
+ "Write a temporary tool module named FEATURE into DIR."
+ (let ((file (expand-file-name (format "%s.el" feature) dir)))
+ (write-region
+ (format ";;; %s.el --- test tool -*- lexical-binding: t; -*-\n(provide '%s)\n"
+ feature feature)
+ nil
+ file
+ nil
+ 'silent)))
+
+(ert-deftest test-ai-config-gptel-local-tools-missing-directory-is-non-fatal ()
+ "Missing optional tool directory should not signal or load anything."
+ (let ((dir (expand-file-name "missing-gptel-tools/"
+ (make-temp-file "gptel-tools-home-" t))))
+ (should-not (cj/gptel-load-local-tools dir '(test_missing_tool)))))
+
+(ert-deftest test-ai-config-gptel-local-tools-loads-present-tools ()
+ "Present tool modules should be loaded and returned in request order."
+ (let ((dir (make-temp-file "gptel-tools-" t))
+ (features '(test_gptel_tool_one test_gptel_tool_two)))
+ (dolist (feature features)
+ (test-ai-config-gptel-local-tools--write-tool dir feature))
+ (should (equal (cj/gptel-load-local-tools dir features)
+ features))
+ (dolist (feature features)
+ (should (featurep feature)))))
+
+(ert-deftest test-ai-config-gptel-local-tools-skips-missing-tool-files ()
+ "Missing optional tool files should not prevent present tools from loading."
+ (let ((dir (make-temp-file "gptel-tools-" t))
+ (present 'test_gptel_present_tool)
+ (missing 'test_gptel_missing_tool))
+ (test-ai-config-gptel-local-tools--write-tool dir present)
+ (should (equal (cj/gptel-load-local-tools dir (list present missing))
+ (list present)))
+ (should (featurep present))
+ (should-not (featurep missing))))
+
+(provide 'test-ai-config-gptel-local-tools)
+;;; test-ai-config-gptel-local-tools.el ends here