blob: 246e70a3f386dd79017729a641d501468abc1ddf (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
;;; test-ai-term--launch-command.el --- Tests for cj/--ai-term-launch-command -*- lexical-binding: t; -*-
;;; Commentary:
;; The launch command is what gets typed into a fresh ghostel shell to bring
;; up the agent inside a per-project tmux session. The session is named
;; `cj/ai-term-tmux-session-prefix' + the project basename, so a second
;; F9 on the same project reattaches to the running agent rather than
;; spawning a new one, and `tmux ls' output can be filtered to AI-term's
;; own sessions. The trailing `exec bash' keeps the tmux window alive if
;; the agent exits, leaving the session intact for recovery.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'ai-term)
(ert-deftest test-ai-term--launch-command-uses-new-session-attach ()
"Normal: starts with `tmux new-session -A' so existing sessions reattach."
(let ((cj/ai-term-agent-command "agent"))
(should (string-prefix-p
"tmux new-session -A "
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-includes-prefixed-session-name ()
"Normal: the session name is the prefixed form from the name helper."
(let ((cj/ai-term-agent-command "agent")
(cj/ai-term-tmux-session-prefix "aiv-"))
(should (string-match-p
" -s aiv-foo "
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-names-window ()
"Normal: `-n <window-name>' so the agent window is named distinctly."
(let ((cj/ai-term-agent-command "agent")
(cj/ai-term-tmux-window-name "ai"))
(should (string-match-p
" -n ai "
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-honors-custom-window-name ()
"Boundary: a non-default window name is what `-n' gets."
(let ((cj/ai-term-agent-command "agent")
(cj/ai-term-tmux-window-name "agent"))
(should (string-match-p
" -n agent "
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-includes-start-directory ()
"Normal: `-c <dir>' so the new session's first window starts in DIR."
(let ((cj/ai-term-agent-command "agent"))
(should (string-match-p
" -c /code/foo "
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-includes-agent-command ()
"Normal: the configured agent command is in the launched shell command.
The inner command is passed through `shell-quote-argument', so spaces
are escaped (`\\\\ ') -- the regex below accepts either form."
(let ((cj/ai-term-agent-command "agent --some-flag"))
(should (string-match-p
"agent\\(\\\\\\)? --some-flag"
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-tails-with-exec-bash ()
"Boundary: `exec bash' tails so the tmux window survives the agent exiting.
Accepts the post-`shell-quote-argument' shape (`exec\\\\ bash')."
(let ((cj/ai-term-agent-command "agent"))
(should (string-match-p
"exec\\(\\\\\\)? bash"
(cj/--ai-term-launch-command "/code/foo")))))
(ert-deftest test-ai-term--launch-command-survives-single-quote-in-agent ()
"Normal: a user-customized agent command containing a single quote
shouldn't break the shell parse. `shell-quote-argument' produces a
valid shell token regardless of the embedded quote shape -- the
escaping is implementation-detail, so we assert the literal words
\"hi\" and \"there\" both appear (the space between them may be
escaped as \\\\ )."
(let ((cj/ai-term-agent-command "agent --say 'hi there'"))
(let ((cmd (cj/--ai-term-launch-command "/code/foo")))
(should (string-match-p "hi\\(\\\\\\)? there" cmd)))))
(ert-deftest test-ai-term--launch-command-handles-spaces-in-basename ()
"Boundary: a basename with whitespace becomes hyphenated before quoting."
(let ((cj/ai-term-agent-command "agent")
(cj/ai-term-tmux-session-prefix "aiv-"))
(should (string-match-p
" -s aiv-my-work "
(cj/--ai-term-launch-command "/code/my work")))))
(provide 'test-ai-term--launch-command)
;;; test-ai-term--launch-command.el ends here
|