aboutsummaryrefslogtreecommitdiff
path: root/tests/test-ai-vterm--capture-state.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-08 19:21:26 -0500
committerCraig Jennings <c@cjennings.net>2026-05-08 19:21:26 -0500
commiteab070e5b542f525340ee7f07ea0560944639721 (patch)
tree09a0ce76e38821ecfa2ed8bfcdf50057096fe794 /tests/test-ai-vterm--capture-state.el
parent1d93e1a6569e4193c2b078a3d5df0bf47eeba9df (diff)
downloaddotemacs-eab070e5b542f525340ee7f07ea0560944639721.tar.gz
dotemacs-eab070e5b542f525340ee7f07ea0560944639721.zip
feat(ai-vterm): F9 toggle/redisplay/pick + persistent split geometry
F9 was a single command that always opened the project picker. Three small frustrations stacked up. With one claude buffer open and not visible, F9 was a redundant prompt to pick a project that already had a session. With claude visible, there was no way to bury it without M-x quit-window. With two projects' buffers alive, swapping between them was a buffer-switch chore. F9 is now a dispatch: - Claude visible in this frame: quit the window (toggle off) and capture the geometry first. - Exactly one claude buffer alive but hidden: re-display it (DWIM single-buffer case). - Zero or two-plus alive: fall through to the project picker. C-F9 is the always-pick-project entry point for explicit project switches. M-F9 is a buffer picker over the alive claude buffers. If a claude window is currently shown, the picked buffer replaces it in that window so the split orientation and size carry over. The shown buffer sorts last in the picker with a [shown] marker so RET picks "the other one." Split geometry persists across toggles. Two module-level vars (cj/--ai-vterm-last-direction, cj/--ai-vterm-last-size) capture at toggle-off and feed a custom display action. After M-S-t flips claude from right to bottom, F9 toggle-off-then-on returns it at the bottom. After a mouse resize, the next toggle restores that fraction. State is per-session. Restarts reset to default right/0.5. Two display-buffer fixes came out of testing: - save-window-excursion around (vterm name) keeps the dashboard from being buried on a fresh F9 at startup. vterm calls pop-to-buffer-same-window internally, which would otherwise replace the selected window's buffer before the alist could route the new one. - The action chain swaps display-buffer-use-some-window for a more specific cj/--ai-vterm-reuse-existing-claude. The generic version stole non-claude windows on C-F9 when the user was focused inside claude (claude on bottom, code on top -> new project landed in the code window). The specific version only reuses windows that already show a claude buffer. I reclaimed C-F9 from the gptel toggle in ai-config.el. C-; a t still binds gptel. I added eight new test files (claude-buffers, displayed-claude-window, dispatch, pick-buffer-candidates, window-geometry, capture-state, display-saved, reuse-existing-claude) plus a regression test on cj/--ai-vterm-show-or-create for the dashboard-preservation fix. All 73 ai-vterm tests pass and the full make test suite is green.
Diffstat (limited to 'tests/test-ai-vterm--capture-state.el')
-rw-r--r--tests/test-ai-vterm--capture-state.el64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-ai-vterm--capture-state.el b/tests/test-ai-vterm--capture-state.el
new file mode 100644
index 000000000..cecb3ab8b
--- /dev/null
+++ b/tests/test-ai-vterm--capture-state.el
@@ -0,0 +1,64 @@
+;;; test-ai-vterm--capture-state.el --- Tests for cj/--ai-vterm-capture-state -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The capture helper writes WINDOW's direction and size to module-
+;; level state vars `cj/--ai-vterm-last-direction' and
+;; `cj/--ai-vterm-last-size'. Called from `cj/ai-vterm''s toggle-off
+;; branch so the next F9 display can restore the user's chosen
+;; orientation and size. No-op on a dead window.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'ai-vterm)
+
+(ert-deftest test-ai-vterm--capture-state-right-split-sets-direction ()
+ "Normal: right-split window -> direction=right, size in (0.4, 0.6)."
+ (save-window-excursion
+ (delete-other-windows)
+ (let ((right (split-window (selected-window) nil 'right))
+ (cj/--ai-vterm-last-direction nil)
+ (cj/--ai-vterm-last-size nil))
+ (cj/--ai-vterm-capture-state right)
+ (should (eq cj/--ai-vterm-last-direction 'right))
+ (should (numberp cj/--ai-vterm-last-size))
+ (should (and (> cj/--ai-vterm-last-size 0.4)
+ (< cj/--ai-vterm-last-size 0.6))))))
+
+(ert-deftest test-ai-vterm--capture-state-below-split-sets-direction ()
+ "Normal: below-split window -> direction=below, size in (0.4, 0.6)."
+ (save-window-excursion
+ (delete-other-windows)
+ (let ((below (split-window (selected-window) nil 'below))
+ (cj/--ai-vterm-last-direction nil)
+ (cj/--ai-vterm-last-size nil))
+ (cj/--ai-vterm-capture-state below)
+ (should (eq cj/--ai-vterm-last-direction 'below))
+ (should (and (> cj/--ai-vterm-last-size 0.4)
+ (< cj/--ai-vterm-last-size 0.6))))))
+
+(ert-deftest test-ai-vterm--capture-state-noop-on-dead-window ()
+ "Boundary: nil window -> state remains unchanged."
+ (let ((cj/--ai-vterm-last-direction 'sentinel-dir)
+ (cj/--ai-vterm-last-size 0.123))
+ (cj/--ai-vterm-capture-state nil)
+ (should (eq cj/--ai-vterm-last-direction 'sentinel-dir))
+ (should (= cj/--ai-vterm-last-size 0.123))))
+
+(ert-deftest test-ai-vterm--capture-state-noop-on-deleted-window ()
+ "Boundary: deleted window -> state remains unchanged."
+ (let ((cj/--ai-vterm-last-direction 'sentinel-dir)
+ (cj/--ai-vterm-last-size 0.123)
+ (dead-win (save-window-excursion
+ (delete-other-windows)
+ (let ((w (split-window (selected-window) nil 'right)))
+ (delete-window w)
+ w))))
+ (cj/--ai-vterm-capture-state dead-win)
+ (should (eq cj/--ai-vterm-last-direction 'sentinel-dir))
+ (should (= cj/--ai-vterm-last-size 0.123))))
+
+(provide 'test-ai-vterm--capture-state)
+;;; test-ai-vterm--capture-state.el ends here