diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-ai-vterm--record-mru.el | 48 | ||||
| -rw-r--r-- | tests/test-ai-vterm--show-or-create.el | 9 | ||||
| -rw-r--r-- | tests/test-ai-vterm--sort-candidates.el | 27 | ||||
| -rw-r--r-- | tests/test-ai-vterm--tmux-session-name.el | 20 |
4 files changed, 94 insertions, 10 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 diff --git a/tests/test-ai-vterm--show-or-create.el b/tests/test-ai-vterm--show-or-create.el index 0a3dbde5..01083f84 100644 --- a/tests/test-ai-vterm--show-or-create.el +++ b/tests/test-ai-vterm--show-or-create.el @@ -57,8 +57,10 @@ VARS is a plist of capture variable names: :calls, :strings, :returns, (kill-buffer name))) (ert-deftest test-ai-vterm--show-or-create-creates-when-buffer-missing () - "Normal: no existing buffer -> vterm called once, launch cmd sent." - (let ((name "agent [normal-create-test]")) + "Normal: no existing buffer -> vterm called once, launch cmd sent, the +project recorded at the front of the MRU list." + (let ((name "agent [normal-create-test]") + (cj/--ai-vterm-mru nil)) (test-ai-vterm--cleanup name) (unwind-protect (test-ai-vterm--with-mock-vterm (:calls calls :strings strings @@ -68,7 +70,8 @@ VARS is a plist of capture variable names: :calls, :strings, :returns, (should (equal strings (list (cj/--ai-vterm-launch-command "/tmp/some-project")))) (should (= returns 1)) - (should (equal ddir "/tmp/some-project"))) + (should (equal ddir "/tmp/some-project")) + (should (equal (car cj/--ai-vterm-mru) "/tmp/some-project"))) (test-ai-vterm--cleanup name)))) (ert-deftest test-ai-vterm--show-or-create-displays-existing-when-process-live () 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-")) diff --git a/tests/test-ai-vterm--tmux-session-name.el b/tests/test-ai-vterm--tmux-session-name.el index 8d9220eb..073dc312 100644 --- a/tests/test-ai-vterm--tmux-session-name.el +++ b/tests/test-ai-vterm--tmux-session-name.el @@ -5,8 +5,10 @@ ;; the project's basename, so reopening the agent 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. +;; down to AI-vterm's own sessions. The basename is sanitized to a form +;; tmux won't re-mangle: runs of whitespace become hyphens, and `.' / `:' +;; (which tmux disallows in session names and silently rewrites to `_') +;; become `_' up front so the computed name matches the real session. ;;; Code: @@ -27,11 +29,19 @@ (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)." +(ert-deftest test-ai-vterm--tmux-session-name-dots-become-underscores () + "Boundary: tmux disallows `.' in session names and rewrites it to `_', +so the basename's dots are sanitized to `_' up front -- `.emacs.d' must +yield `aiv-_emacs_d', matching the session tmux actually creates." (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/.emacs.d") - "aiv-.emacs.d")))) + "aiv-_emacs_d")))) + +(ert-deftest test-ai-vterm--tmux-session-name-colon-becomes-underscore () + "Boundary: `:' is also disallowed by tmux in session names -> `_'." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) + (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/a:b") + "aiv-a_b")))) (ert-deftest test-ai-vterm--tmux-session-name-space-becomes-hyphen () "Boundary: a space in the basename is replaced with a hyphen." |
