diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-07 19:25:18 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-07 19:25:18 -0500 |
| commit | 47b218ed15acd00c18cbc3bef604c4f2e0050a08 (patch) | |
| tree | 98c6541327b707e1e3c1f214f8a6dc7d0135a039 /tests/test-ai-vterm--display-rule.el | |
| parent | 3efaf9b5218fa769a297df5821ec89837207e57d (diff) | |
| download | dotemacs-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--display-rule.el')
| -rw-r--r-- | tests/test-ai-vterm--display-rule.el | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test-ai-vterm--display-rule.el b/tests/test-ai-vterm--display-rule.el new file mode 100644 index 000000000..af481eb3b --- /dev/null +++ b/tests/test-ai-vterm--display-rule.el @@ -0,0 +1,74 @@ +;;; test-ai-vterm--display-rule.el --- Tests for the AI-vterm display-buffer rule -*- lexical-binding: t; -*- + +;;; Commentary: +;; The module installs a `display-buffer-alist' entry routing buffers +;; whose names match "\\`claude \\[" to a right-side window. These +;; tests verify the rule reaches the right side and ignores buffers +;; that don't match the prefix. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'ai-vterm) + +(defun test-ai-vterm--cleanup (name) + "Kill buffer NAME if it exists." + (when (get-buffer name) + (kill-buffer name))) + +(defmacro test-ai-vterm--with-clean-frame (&rest body) + "Run BODY in a context with one window and the AI-vterm rule loaded." + (declare (indent 0) (debug t)) + `(save-window-excursion + (delete-other-windows) + (let ((display-buffer-alist (cj/--ai-vterm-display-rule-list))) + ,@body))) + +(ert-deftest test-ai-vterm--display-rule-routes-claude-buffer-to-right () + "Normal: a buffer named \"claude [foo]\" lands in a window to the right. + +The rule uses `display-buffer-in-direction' with `(direction . right)', +which splits the current window so the new window's left edge sits at +a positive column. The buffer winds up in that new window." + (let ((name "claude [display-rule-test]")) + (test-ai-vterm--cleanup name) + (unwind-protect + (test-ai-vterm--with-clean-frame + (let* ((buf (get-buffer-create name)) + (win (display-buffer buf))) + (should (windowp win)) + (should (> (window-left-column win) 0)))) + (test-ai-vterm--cleanup name)))) + +(ert-deftest test-ai-vterm--display-rule-skips-non-matching-buffer () + "Boundary: a buffer not named \"claude [...]\" does not match the rule. + +The rule's regex doesn't fire, so `display-buffer' falls back to the +default action -- reuse the current window -- and no rightward split +occurs." + (let ((name "scratch-buffer-no-match")) + (test-ai-vterm--cleanup name) + (unwind-protect + (test-ai-vterm--with-clean-frame + (let* ((buf (get-buffer-create name)) + (win (display-buffer buf))) + (should (windowp win)) + (should (= (window-left-column win) 0)))) + (test-ai-vterm--cleanup name)))) + +(ert-deftest test-ai-vterm--display-rule-prefix-not-substring () + "Boundary: \"foo claude [bar]\" does not match -- the rule anchors at start." + (let ((name "foo claude [substring-test]")) + (test-ai-vterm--cleanup name) + (unwind-protect + (test-ai-vterm--with-clean-frame + (let* ((buf (get-buffer-create name)) + (win (display-buffer buf))) + (should (windowp win)) + (should (= (window-left-column win) 0)))) + (test-ai-vterm--cleanup name)))) + +(provide 'test-ai-vterm--display-rule) +;;; test-ai-vterm--display-rule.el ends here |
