diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-09 12:00:30 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-09 12:00:30 -0500 |
| commit | a29ac8d9f31443279ba5897b13cf5cda49519975 (patch) | |
| tree | c138750b0c5ed15afa5f78555d8ab35129e141b1 /tests | |
| parent | 554b32db5da9630fa24fb2abf3f93f21b03ff7a0 (diff) | |
| download | dotemacs-a29ac8d9f31443279ba5897b13cf5cda49519975.tar.gz dotemacs-a29ac8d9f31443279ba5897b13cf5cda49519975.zip | |
feat(ai-vterm): show [running] in picker and F9 redisplays last-used
The C-F9 project picker now flags projects whose claude buffer is alive with a " [running]" suffix on the abbreviated path. I added `cj/--ai-vterm-format-candidate` to compute the display name and routed the picker through it. Before the change, the picker showed every candidate identically, so you couldn't tell at a glance whether picking a project would attach to an existing session or start a fresh one.
F9 with two or more alive claude buffers used to open the project picker. That meant after toggling claude-A off, opening claude-B via C-F9, then toggling B off, the next F9 dropped into a picker rather than redisplaying B (the one you just toggled off). I renamed `redisplay-single` to `redisplay-recent` in `cj/--ai-vterm-dispatch` and broadened the trigger from "exactly one alive" to "one or more alive". F9 now redisplays the MRU claude buffer, so it consistently means "toggle THE claude I was last using". The project picker stays explicit on C-F9 for "start a different project", and M-F9 still picks among existing claudes.
2 new tests for the indicator (`format-candidate` flagged + unflagged), 2 dispatch tests renamed to match the new contract. 80 ai-vterm tests pass. Full make test green.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-ai-vterm--dispatch.el | 22 | ||||
| -rw-r--r-- | tests/test-ai-vterm--pick-project.el | 21 |
2 files changed, 34 insertions, 9 deletions
diff --git a/tests/test-ai-vterm--dispatch.el b/tests/test-ai-vterm--dispatch.el index 3c0ae766..030b200d 100644 --- a/tests/test-ai-vterm--dispatch.el +++ b/tests/test-ai-vterm--dispatch.el @@ -2,10 +2,10 @@ ;;; Commentary: ;; The dispatch helper is a pure decision function used by F9. -;; Returns one of (toggle-off . WIN), (redisplay-single . BUF), +;; Returns one of (toggle-off . WIN), (redisplay-recent . BUF), ;; or (pick-project) based on whether a claude buffer is currently -;; displayed and how many alive claude buffers exist. Tests mock the -;; two underlying helpers so the dispatch logic can be exercised +;; displayed and whether any alive claude buffers exist. Tests mock +;; the two underlying helpers so the dispatch logic can be exercised ;; without touching real windows. ;;; Code: @@ -30,8 +30,8 @@ (should (equal (cj/--ai-vterm-dispatch) (cons 'toggle-off sentinel-win)))))) -(ert-deftest test-ai-vterm--dispatch-no-window-single-buffer-returns-redisplay () - "Normal: no displayed claude, exactly one alive buffer -> redisplay-single." +(ert-deftest test-ai-vterm--dispatch-no-window-single-buffer-returns-redisplay-recent () + "Normal: no displayed claude, one alive buffer -> redisplay-recent + buffer." (test-ai-vterm--dispatch-cleanup) (let ((b1 (get-buffer-create "claude [single]"))) (unwind-protect @@ -40,11 +40,14 @@ ((symbol-function 'cj/--ai-vterm-claude-buffers) (lambda () (list b1)))) (should (equal (cj/--ai-vterm-dispatch) - (cons 'redisplay-single b1)))) + (cons 'redisplay-recent b1)))) (kill-buffer b1)))) -(ert-deftest test-ai-vterm--dispatch-no-window-multiple-buffers-returns-pick-project () - "Normal: no displayed claude, 2+ alive buffers -> pick-project." +(ert-deftest test-ai-vterm--dispatch-no-window-multiple-buffers-returns-redisplay-recent () + "Normal: no displayed claude, 2+ alive buffers -> redisplay-recent + MRU. +F9 redisplays the most-recently-selected claude (head of buffer-list +order) rather than opening the project picker, so the user toggles +THE claude they were last using. Other claudes are reachable via M-F9." (test-ai-vterm--dispatch-cleanup) (let ((b1 (get-buffer-create "claude [a]")) (b2 (get-buffer-create "claude [b]"))) @@ -53,7 +56,8 @@ (lambda (&optional _frame) nil)) ((symbol-function 'cj/--ai-vterm-claude-buffers) (lambda () (list b1 b2)))) - (should (equal (cj/--ai-vterm-dispatch) '(pick-project)))) + (should (equal (cj/--ai-vterm-dispatch) + (cons 'redisplay-recent b1)))) (kill-buffer b1) (kill-buffer b2)))) diff --git a/tests/test-ai-vterm--pick-project.el b/tests/test-ai-vterm--pick-project.el index 6fa2d185..fd5295bf 100644 --- a/tests/test-ai-vterm--pick-project.el +++ b/tests/test-ai-vterm--pick-project.el @@ -44,5 +44,26 @@ (cj/--ai-vterm-pick-project) (should (equal (caar received-collection) "~/code/foo"))))) +(ert-deftest test-ai-vterm--format-candidate-flags-running-project () + "Normal: a path whose claude buffer has a live process gets a [running] suffix." + (let* ((path (expand-file-name "~/code/already-running")) + (buffer-name (cj/--ai-vterm-buffer-name path)) + (buf (get-buffer-create buffer-name))) + (unwind-protect + (cl-letf (((symbol-function 'cj/--ai-vterm-process-live-p) + (lambda (b) (eq b buf)))) + (should (equal (cj/--ai-vterm-format-candidate path) + (format "%s [running]" (abbreviate-file-name path))))) + (kill-buffer buf)))) + +(ert-deftest test-ai-vterm--format-candidate-omits-flag-when-not-running () + "Boundary: a path with no buffer or no live process -> plain abbreviated path." + (let ((path (expand-file-name "~/code/not-running"))) + ;; Make sure no claude buffer exists for this path. + (let ((bn (cj/--ai-vterm-buffer-name path))) + (when (get-buffer bn) (kill-buffer bn))) + (should (equal (cj/--ai-vterm-format-candidate path) + (abbreviate-file-name path))))) + (provide 'test-ai-vterm--pick-project) ;;; test-ai-vterm--pick-project.el ends here |
