diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 05:17:44 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 05:17:44 -0500 |
| commit | ca7015486d230192e94c51c0e5d014fc83a7a35f (patch) | |
| tree | 2e06df454a3915ea6074e697fc64f6981fe0177e /tests/test-ai-vterm--tmux-session-name.el | |
| parent | 364d69dc6f9be5d310c0ac1f0c69c31b08d82821 (diff) | |
| download | dotemacs-ca7015486d230192e94c51c0e5d014fc83a7a35f.tar.gz dotemacs-ca7015486d230192e94c51c0e5d014fc83a7a35f.zip | |
feat(ai-vterm): surface surviving tmux sessions in the project picker
Each project's tmux session is now named `<cj/ai-vterm-tmux-session-prefix><basename>` (default `aiv-`), so `tmux ls` can be filtered to AI-vterm's own sessions. After an Emacs crash the C-F9 project picker reads `tmux list-sessions`, matches surviving sessions back to their directories, and sorts those to the top: `[detached]` when only the tmux session is alive, `[running]` when a vterm buffer exists. The rest follow alphabetically. With tmux missing or no server running, it falls back to a plain alphabetical list. The picker's collection is a completion table that pins display order so Vertico doesn't re-sort and undo the active-first grouping.
The prefix is a new `defcustom` rather than `claude-`, which collides with hand-rolled tmux sessions. Sessions named before this change use the bare basename and won't be matched afterward. One `tmux kill-server` clears any orphans.
Diffstat (limited to 'tests/test-ai-vterm--tmux-session-name.el')
| -rw-r--r-- | tests/test-ai-vterm--tmux-session-name.el | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/tests/test-ai-vterm--tmux-session-name.el b/tests/test-ai-vterm--tmux-session-name.el index 9d56040ed..44c20a8be 100644 --- a/tests/test-ai-vterm--tmux-session-name.el +++ b/tests/test-ai-vterm--tmux-session-name.el @@ -1,11 +1,12 @@ ;;; test-ai-vterm--tmux-session-name.el --- Tests for cj/--ai-vterm-tmux-session-name -*- lexical-binding: t; -*- ;;; Commentary: -;; The tmux session name is derived from the project's basename so that -;; reopening Claude on the same project (e.g. after an Emacs crash) -;; reattaches to the same tmux session rather than spawning a new one. -;; Whitespace in the basename gets converted to hyphens so the name is -;; safe to pass on a tmux command line. +;; The tmux session name is `cj/ai-vterm-tmux-session-prefix' followed by +;; the project's basename, so reopening Claude on the same project (e.g. +;; after an Emacs crash) reattaches to the same tmux session rather than +;; spawning a new one -- and the prefix lets `tmux ls' output be filtered +;; down to AI-vterm's own sessions. Whitespace in the basename becomes +;; hyphens so the name is safe to pass on a tmux command line. ;;; Code: @@ -15,29 +16,40 @@ (require 'ai-vterm) (ert-deftest test-ai-vterm--tmux-session-name-normal-project () - "Normal: a typical project path yields its basename." - (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo") - "foo"))) + "Normal: basename gets the configured prefix." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo") + "aiv-foo")))) (ert-deftest test-ai-vterm--tmux-session-name-trailing-slash () "Boundary: trailing slash collapses before basename extraction." - (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo/") - "foo"))) + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo/") + "aiv-foo")))) (ert-deftest test-ai-vterm--tmux-session-name-dot-prefix-dir () "Boundary: dot-prefix dirs preserve the dot (tmux accepts dots)." - (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/.emacs.d") - ".emacs.d"))) + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/.emacs.d") + "aiv-.emacs.d")))) (ert-deftest test-ai-vterm--tmux-session-name-space-becomes-hyphen () "Boundary: a space in the basename is replaced with a hyphen." - (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/my work") - "my-work"))) + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/my work") + "aiv-my-work")))) (ert-deftest test-ai-vterm--tmux-session-name-multiple-spaces-collapse () "Boundary: a run of whitespace collapses to a single hyphen." - (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/a b\tc") - "a-b-c"))) + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/a b\tc") + "aiv-a-b-c")))) + +(ert-deftest test-ai-vterm--tmux-session-name-honors-custom-prefix () + "Normal: a non-default prefix is what gets prepended." + (let ((cj/ai-vterm-tmux-session-prefix "em-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo") + "em-foo")))) (provide 'test-ai-vterm--tmux-session-name) ;;; test-ai-vterm--tmux-session-name.el ends here |
