aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-20 16:00:38 -0400
committerCraig Jennings <c@cjennings.net>2026-06-20 16:00:38 -0400
commit64916462f5c81b854d3fbc6f5c543ecf5ac25bf5 (patch)
tree4ac1275810afc50d6b52f90b534cd99d612c316b /tests
parent2b7a3139e8f2aef5ca2e072a29e1892f517f77b7 (diff)
downloaddotemacs-64916462f5c81b854d3fbc6f5c543ecf5ac25bf5.tar.gz
dotemacs-64916462f5c81b854d3fbc6f5c543ecf5ac25bf5.zip
fix(ai-term): keep the F9 toggle reversible in a 3+ window layout
In a layout where the agent had its own split window (e.g. code on top, a working window, and the agent below), toggling the agent off deleted its window correctly, but toggling back on reused the working window at the edge -- displacing its buffer and collapsing three windows to two. The slot-reuse that avoids a third window on a fresh show was firing on a re-show after the agent's own window was already deleted. Flag the toggle-off that deletes the agent's own window; on the next toggle-on, reuse-edge-window consumes the flag and falls through to a fresh re-split, so the agent returns to its own window and the other windows are untouched. The flag only changes the 3+ window case -- after a delete in a 2-window slot-reuse layout one window remains, where re-split and reuse-edge already coincide, so the existing reuse-edge tests are unaffected.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-ai-term--reuse-edge-window.el41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test-ai-term--reuse-edge-window.el b/tests/test-ai-term--reuse-edge-window.el
index f6259ae50..a9a0529e8 100644
--- a/tests/test-ai-term--reuse-edge-window.el
+++ b/tests/test-ai-term--reuse-edge-window.el
@@ -269,5 +269,46 @@ most-recent agent, which would now be the other one."
(when (get-buffer right-name) (kill-buffer right-name))
(cj/test--kill-agent-buffers))))
+(ert-deftest test-ai-term--reuse-edge-window-3win-toggle-restores-own-window ()
+ "Regression: in a 3-window layout the agent has its own split, so toggling it
+off then on restores it as its own window without displacing a working window.
+Before the fix, toggle-on reused the bottom edge (the user's main window),
+collapsing three windows to two and hiding the main buffer. A toggle must be
+reversible: off then on returns to the same layout."
+ (cj/test--kill-agent-buffers)
+ (let ((agent-name "agent [3win-toggle]")
+ (code-name "*test-3win-code*")
+ (main-name "*test-3win-main*")
+ (cj/--ai-term-last-direction nil)
+ (cj/--ai-term-last-size nil)
+ (cj/--ai-term-last-was-bury nil))
+ (unwind-protect
+ (save-window-excursion
+ (delete-other-windows)
+ (cl-letf (((symbol-function 'cj/--ai-term-default-direction) (lambda (&rest _) 'below)))
+ (let ((code-buf (get-buffer-create code-name))
+ (main-buf (get-buffer-create main-name))
+ (agent-buf (get-buffer-create agent-name)))
+ (set-window-buffer (selected-window) code-buf)
+ (let* ((main-win (split-window (selected-window) nil 'below))
+ (agent-win (split-window main-win nil 'below)))
+ (set-window-buffer main-win main-buf)
+ (set-window-buffer agent-win agent-buf)
+ (should (= (count-windows) 3))
+ (let ((display-buffer-alist (cj/--ai-term-display-rule-list)))
+ (select-window agent-win)
+ (cj/test--call-as-gui #'cj/ai-term) ; off -> code | main
+ (should (= (count-windows) 2))
+ (should-not (member agent-name (cj/test--displayed-buffer-names)))
+ (cj/test--call-as-gui #'cj/ai-term) ; on -> back to 3 windows
+ (should (= (count-windows) 3))
+ (let ((bufs (cj/test--displayed-buffer-names)))
+ (should (member agent-name bufs))
+ (should (member code-name bufs))
+ (should (member main-name bufs))))))))
+ (when (get-buffer code-name) (kill-buffer code-name))
+ (when (get-buffer main-name) (kill-buffer main-name))
+ (cj/test--kill-agent-buffers))))
+
(provide 'test-ai-term--reuse-edge-window)
;;; test-ai-term--reuse-edge-window.el ends here