aboutsummaryrefslogtreecommitdiff
path: root/tests/test-ai-vterm--pick-project.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-07 19:25:18 -0500
committerCraig Jennings <c@cjennings.net>2026-05-07 19:25:18 -0500
commit47b218ed15acd00c18cbc3bef604c4f2e0050a08 (patch)
tree98c6541327b707e1e3c1f214f8a6dc7d0135a039 /tests/test-ai-vterm--pick-project.el
parent3efaf9b5218fa769a297df5821ec89837207e57d (diff)
downloaddotemacs-47b218ed15acd00c18cbc3bef604c4f2e0050a08.tar.gz
dotemacs-47b218ed15acd00c18cbc3bef604c4f2e0050a08.zip
feat(ai-vterm): add Claude launcher with vertical-split vterm
The new module picks a Claude-template project from a filtered completing-read list. It scans the same roots the `ai` shell launcher uses, then opens or reuses a vterm buffer named `claude [<repo>]` on the right. F9 launches it. The prior `cj/toggle-gptel` binding moves from F9 to C-F9 so both AI tools share the same physical key. The display rule chains reuse-window -> use-some-window -> in-direction (right). The resulting window isn't dedicated. That matters because side-window dedication was breaking `buffer-move` (C-M-arrows) and `switch-to-buffer` replacement on the claude buffer. I also narrowed `vterm-toggle`'s display rule to skip `claude [` buffers. Otherwise it claimed them first with its bottom-split + dedicated treatment. I added 23 tests across 5 files: the buffer-name transform, candidate walker, show-or-create dispatch, picker, and display rule. Design lives at docs/design/ai-vterm.org.
Diffstat (limited to 'tests/test-ai-vterm--pick-project.el')
-rw-r--r--tests/test-ai-vterm--pick-project.el48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-ai-vterm--pick-project.el b/tests/test-ai-vterm--pick-project.el
new file mode 100644
index 00000000..6fa2d185
--- /dev/null
+++ b/tests/test-ai-vterm--pick-project.el
@@ -0,0 +1,48 @@
+;;; test-ai-vterm--pick-project.el --- Tests for cj/--ai-vterm-pick-project -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The picker presents abbreviated paths to `completing-read', then
+;; returns the absolute path corresponding to the user's choice. Empty
+;; candidate set raises a `user-error' rather than offering an empty
+;; prompt.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'ai-vterm)
+
+(ert-deftest test-ai-vterm--pick-project-returns-absolute-path-of-choice ()
+ "Normal: user picks a candidate, picker returns its absolute path."
+ (cl-letf (((symbol-function 'cj/--ai-vterm-candidates)
+ (lambda () '("/home/u/code/foo" "/home/u/code/bar")))
+ ((symbol-function 'completing-read)
+ (lambda (_p collection &rest _)
+ ;; Pick the one whose display form matches ~/code/bar
+ ;; (collection is alist of display . abs)
+ (car (cl-find-if
+ (lambda (cell) (string-match-p "bar" (car cell)))
+ collection)))))
+ (should (equal (cj/--ai-vterm-pick-project) "/home/u/code/bar"))))
+
+(ert-deftest test-ai-vterm--pick-project-empty-candidates-raises-user-error ()
+ "Error: no candidates -> user-error rather than empty prompt."
+ (cl-letf (((symbol-function 'cj/--ai-vterm-candidates) (lambda () nil)))
+ (should-error (cj/--ai-vterm-pick-project) :type 'user-error)))
+
+(ert-deftest test-ai-vterm--pick-project-presents-abbreviated-paths ()
+ "Normal: the completing-read collection holds abbreviated display forms."
+ (let (received-collection)
+ (cl-letf (((symbol-function 'cj/--ai-vterm-candidates)
+ (lambda () (list (expand-file-name "~/code/foo"))))
+ ((symbol-function 'completing-read)
+ (lambda (_p collection &rest _)
+ (setq received-collection collection)
+ (caar collection))))
+ (cj/--ai-vterm-pick-project)
+ (should (equal (caar received-collection) "~/code/foo")))))
+
+(provide 'test-ai-vterm--pick-project)
+;;; test-ai-vterm--pick-project.el ends here