diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 13:27:26 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 13:27:26 -0500 |
| commit | c14d6c8d0f669d694dd765d6f592ce6eb72c50f5 (patch) | |
| tree | 26c45c9f9f77129a8440019a6825a24a1eea028d /tests/test-ai-vterm--sort-candidates.el | |
| parent | de8659c61e47787c635ad9a6184fcef655ae89d2 (diff) | |
| download | dotemacs-c14d6c8d0f669d694dd765d6f592ce6eb72c50f5.tar.gz dotemacs-c14d6c8d0f669d694dd765d6f592ce6eb72c50f5.zip | |
feat(ai-vterm): order the project picker by most-recently-used
The picker's active group (projects with a live tmux session) used to sort alphabetically. It now leads with projects opened this session, most-recent first, then the rest of the active group alpha, then the no-session group alpha. An in-session list (`cj/--ai-vterm-mru'), pushed to the front by `cj/--ai-vterm-show-or-create' on every open, drives the order. An empty list reproduces the old alphabetical behavior.
I also pulled in a fix: `cj/--ai-vterm-tmux-session-name' now sanitizes `.' and `:' in the basename to `_'. tmux disallows those chars in session names and silently rewrites them, so `.emacs.d' really runs in session `aiv-_emacs_d', not `aiv-.emacs.d'. The computed name never matched, so `.emacs.d' was wrongly treated as having no session and landed in the no-session picker group. (A crash-recovery would also spawn a duplicate instead of reattaching.) Sanitizing the same way tmux does keeps the names in sync.
Diffstat (limited to 'tests/test-ai-vterm--sort-candidates.el')
| -rw-r--r-- | tests/test-ai-vterm--sort-candidates.el | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/test-ai-vterm--sort-candidates.el b/tests/test-ai-vterm--sort-candidates.el index 5e3d760a..26953604 100644 --- a/tests/test-ai-vterm--sort-candidates.el +++ b/tests/test-ai-vterm--sort-candidates.el @@ -3,8 +3,10 @@ ;;; Commentary: ;; The project picker lists candidates with a live tmux session first ;; (so an agent that survived an Emacs crash is easy to get back to), -;; then everything else. Within each group the order is alphabetical -;; by abbreviated path. +;; then everything else. Within the active group, projects opened this +;; session (`cj/--ai-vterm-mru') lead, most-recent first; the rest of the +;; active group, and the whole no-session group, sort alphabetically by +;; abbreviated path. With an empty MRU it's just active-first-then-alpha. ;;; Code: @@ -40,6 +42,27 @@ "Boundary: no candidates -> nil." (should (null (cj/--ai-vterm-sort-candidates nil '("aiv-foo"))))) +(ert-deftest test-ai-vterm--sort-candidates-active-group-mru-first () + "Normal: within the active group, recently-opened projects lead in MRU +order; active dirs not opened this session fall after them alpha; the +no-session group trails, alpha." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-") + (cj/--ai-vterm-mru '("/c/baz" "/c/foo"))) + (should (equal (cj/--ai-vterm-sort-candidates + '("/c/foo" "/c/bar" "/c/baz" "/c/qux") + '("aiv-foo" "aiv-bar" "aiv-baz")) + '("/c/baz" "/c/foo" "/c/bar" "/c/qux"))))) + +(ert-deftest test-ai-vterm--sort-candidates-mru-does-not-bump-inactive () + "Boundary: an MRU dir whose tmux session has died sorts alpha in the +no-session group, not at the top." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-") + (cj/--ai-vterm-mru '("/c/zed"))) + (should (equal (cj/--ai-vterm-sort-candidates + '("/c/foo" "/c/zed" "/c/bar") + '("aiv-foo")) + '("/c/foo" "/c/bar" "/c/zed"))))) + (ert-deftest test-ai-vterm--session-active-p-matches-by-derived-name () "Normal: a dir is active when its derived session name is in the set." (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) |
