;;; test-ai-vterm--f9-in-vterm.el --- F9 reaches Emacs from inside an agent buffer -*- lexical-binding: t; -*- ;;; Commentary: ;; vterm binds .. to `vterm--self-insert', so a plain typed ;; while point is in an agent buffer is sent to the terminal program instead ;; of toggling the agent -- which is exactly the case when the agent buffer ;; fills the frame. `ai-vterm.el' re-binds the F9 family in `vterm-mode-map'. ;; These tests load real vterm so `vterm-mode-map' exists, then confirm the ;; bindings landed (and the global ones are still there). ;;; Code: (require 'ert) (require 'package) (setq package-user-dir (expand-file-name "elpa" user-emacs-directory)) (package-initialize) (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) (require 'vterm) (require 'ai-vterm) (ert-deftest test-ai-vterm-f9-bound-in-vterm-mode-map () "Normal: in `vterm-mode-map' runs the agent toggle, not `vterm--self-insert'." (should (eq (keymap-lookup vterm-mode-map "") #'cj/ai-vterm))) (ert-deftest test-ai-vterm-f9-family-bound-in-vterm-mode-map () "Normal: the C-/M-/C-S- F9 variants are bound in `vterm-mode-map' too. `M-' and `C-S-' both close an agent via `cj/ai-vterm-close'." (should (eq (keymap-lookup vterm-mode-map "C-") #'cj/ai-vterm-pick-project)) (should (eq (keymap-lookup vterm-mode-map "M-") #'cj/ai-vterm-close)) (should (eq (keymap-lookup vterm-mode-map "C-S-") #'cj/ai-vterm-close))) (ert-deftest test-ai-vterm-f9-not-self-insert-in-vterm () "Boundary: vterm's default -> `vterm--self-insert' was overridden." (should-not (eq (keymap-lookup vterm-mode-map "") 'vterm--self-insert))) (ert-deftest test-ai-vterm-f9-still-bound-globally () "Normal: the global F9 family bindings are intact. `' toggles the ai-vterm agent window; `C-' picks a project agent; `M-' and `C-S-' close an agent via `cj/ai-vterm-close'." (should (eq (lookup-key (current-global-map) (kbd "")) #'cj/ai-vterm)) (should (eq (lookup-key (current-global-map) (kbd "C-")) #'cj/ai-vterm-pick-project)) (should (eq (lookup-key (current-global-map) (kbd "M-")) #'cj/ai-vterm-close)) (should (eq (lookup-key (current-global-map) (kbd "C-S-")) #'cj/ai-vterm-close))) (provide 'test-ai-vterm--f9-in-vterm) ;;; test-ai-vterm--f9-in-vterm.el ends here