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--record-mru.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--record-mru.el')
| -rw-r--r-- | tests/test-ai-vterm--record-mru.el | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-ai-vterm--record-mru.el b/tests/test-ai-vterm--record-mru.el new file mode 100644 index 00000000..16db4eea --- /dev/null +++ b/tests/test-ai-vterm--record-mru.el @@ -0,0 +1,48 @@ +;;; test-ai-vterm--record-mru.el --- Tests for the AI-vterm project MRU list -*- lexical-binding: t; -*- + +;;; Commentary: +;; `cj/--ai-vterm-record-mru' tracks which project dirs have been opened via +;; the launcher this session, most-recently-opened first, so the picker can +;; surface recently-used projects at the top of the active-sessions group. +;; `cj/--ai-vterm-mru-rank' reports a dir's position in that list (or nil). + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'ai-vterm) + +(ert-deftest test-ai-vterm--record-mru-pushes-to-front () + "Normal: a freshly recorded dir leads the list, newest first." + (let ((cj/--ai-vterm-mru nil)) + (cj/--ai-vterm-record-mru "/c/alpha") + (cj/--ai-vterm-record-mru "/c/beta") + (should (equal cj/--ai-vterm-mru '("/c/beta" "/c/alpha"))))) + +(ert-deftest test-ai-vterm--record-mru-dedups-and-moves-to-front () + "Normal: re-recording a dir moves it to the front with no duplicate." + (let ((cj/--ai-vterm-mru nil)) + (cj/--ai-vterm-record-mru "/c/alpha") + (cj/--ai-vterm-record-mru "/c/beta") + (cj/--ai-vterm-record-mru "/c/alpha") + (should (equal cj/--ai-vterm-mru '("/c/alpha" "/c/beta"))))) + +(ert-deftest test-ai-vterm--record-mru-normalizes-trailing-slash () + "Boundary: `/c/foo' and `/c/foo/' are the same MRU entry." + (let ((cj/--ai-vterm-mru nil)) + (cj/--ai-vterm-record-mru "/c/foo/") + (cj/--ai-vterm-record-mru "/c/foo") + (should (equal cj/--ai-vterm-mru '("/c/foo"))))) + +(ert-deftest test-ai-vterm--mru-rank-returns-index-or-nil () + "Normal/Boundary: rank is the list position; nil when the dir isn't there; +the lookup normalizes a trailing slash the same way `record-mru' does." + (let ((cj/--ai-vterm-mru '("/c/beta" "/c/alpha"))) + (should (= 0 (cj/--ai-vterm-mru-rank "/c/beta"))) + (should (= 1 (cj/--ai-vterm-mru-rank "/c/alpha"))) + (should (= 0 (cj/--ai-vterm-mru-rank "/c/beta/"))) + (should-not (cj/--ai-vterm-mru-rank "/c/gamma")))) + +(provide 'test-ai-vterm--record-mru) +;;; test-ai-vterm--record-mru.el ends here |
