blob: 8d9220ebdd615f2b5f3d60b5a3fa4ac96fb08aa7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
;;; test-ai-vterm--tmux-session-name.el --- Tests for cj/--ai-vterm-tmux-session-name -*- lexical-binding: t; -*-
;;; Commentary:
;; The tmux session name is `cj/ai-vterm-tmux-session-prefix' followed by
;; 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.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'ai-vterm)
(ert-deftest test-ai-vterm--tmux-session-name-normal-project ()
"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."
(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)."
(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."
(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."
(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
|