aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-ai-vterm--launch-command.el61
-rw-r--r--tests/test-ai-vterm--show-or-create.el8
-rw-r--r--tests/test-ai-vterm--tmux-session-name.el43
3 files changed, 109 insertions, 3 deletions
diff --git a/tests/test-ai-vterm--launch-command.el b/tests/test-ai-vterm--launch-command.el
new file mode 100644
index 00000000..c6b7ac2b
--- /dev/null
+++ b/tests/test-ai-vterm--launch-command.el
@@ -0,0 +1,61 @@
+;;; test-ai-vterm--launch-command.el --- Tests for cj/--ai-vterm-launch-command -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The launch command is what gets typed into a fresh vterm shell to bring
+;; up Claude inside a per-project tmux session. The session is named after
+;; the project basename so a second F9 on the same project reattaches to
+;; the running Claude rather than spawning a new one. The trailing
+;; `exec bash' keeps the tmux window alive if Claude exits, leaving the
+;; session intact for recovery.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'ai-vterm)
+
+(ert-deftest test-ai-vterm--launch-command-uses-new-session-attach ()
+ "Normal: starts with `tmux new-session -A' so existing sessions reattach."
+ (let ((cj/ai-vterm-claude-command "claude"))
+ (should (string-prefix-p
+ "tmux new-session -A "
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-includes-session-name ()
+ "Normal: the session name comes from the basename helper."
+ (let ((cj/ai-vterm-claude-command "claude"))
+ (should (string-match-p
+ " -s foo "
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-includes-start-directory ()
+ "Normal: `-c <dir>' so the new session's first window starts in DIR."
+ (let ((cj/ai-vterm-claude-command "claude"))
+ (should (string-match-p
+ " -c /code/foo "
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-includes-claude-command ()
+ "Normal: the configured claude command is in the launched shell command."
+ (let ((cj/ai-vterm-claude-command "claude --some-flag"))
+ (should (string-match-p
+ "claude --some-flag"
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-tails-with-exec-bash ()
+ "Boundary: `exec bash' tails so the tmux window survives Claude exiting."
+ (let ((cj/ai-vterm-claude-command "claude"))
+ (should (string-match-p
+ "exec bash"
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-handles-spaces-in-basename ()
+ "Boundary: a basename with whitespace becomes hyphenated before quoting."
+ (let ((cj/ai-vterm-claude-command "claude"))
+ (should (string-match-p
+ " -s my-work "
+ (cj/--ai-vterm-launch-command "/code/my work")))))
+
+(provide 'test-ai-vterm--launch-command)
+;;; test-ai-vterm--launch-command.el ends here
diff --git a/tests/test-ai-vterm--show-or-create.el b/tests/test-ai-vterm--show-or-create.el
index 28e0faeb..3faf5f03 100644
--- a/tests/test-ai-vterm--show-or-create.el
+++ b/tests/test-ai-vterm--show-or-create.el
@@ -57,7 +57,7 @@ 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, claude cmd sent."
+ "Normal: no existing buffer -> vterm called once, launch cmd sent."
(let ((name "claude [normal-create-test]"))
(test-ai-vterm--cleanup name)
(unwind-protect
@@ -65,7 +65,8 @@ VARS is a plist of capture variable names: :calls, :strings, :returns,
:returns returns :default-dir ddir)
(cj/--ai-vterm-show-or-create "/tmp/some-project" name)
(should (equal calls (list name)))
- (should (equal strings (list cj/ai-vterm-claude-command)))
+ (should (equal strings
+ (list (cj/--ai-vterm-launch-command "/tmp/some-project"))))
(should (= returns 1))
(should (equal ddir "/tmp/some-project")))
(test-ai-vterm--cleanup name))))
@@ -98,7 +99,8 @@ VARS is a plist of capture variable names: :calls, :strings, :returns,
:returns returns :default-dir _ddir)
(cj/--ai-vterm-show-or-create "/tmp/dead" name)
(should (equal calls (list name)))
- (should (equal strings (list cj/ai-vterm-claude-command)))
+ (should (equal strings
+ (list (cj/--ai-vterm-launch-command "/tmp/dead"))))
(should (= returns 1))
(should-not (buffer-live-p stale)))))
(test-ai-vterm--cleanup name))))
diff --git a/tests/test-ai-vterm--tmux-session-name.el b/tests/test-ai-vterm--tmux-session-name.el
new file mode 100644
index 00000000..9d56040e
--- /dev/null
+++ b/tests/test-ai-vterm--tmux-session-name.el
@@ -0,0 +1,43 @@
+;;; test-ai-vterm--tmux-session-name.el --- Tests for cj/--ai-vterm-tmux-session-name -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The tmux session name is derived from the project's basename so that
+;; reopening Claude on the same project (e.g. after an Emacs crash)
+;; reattaches to the same tmux session rather than spawning a new one.
+;; Whitespace in the basename gets converted to 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: a typical project path yields its basename."
+ (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo")
+ "foo")))
+
+(ert-deftest test-ai-vterm--tmux-session-name-trailing-slash ()
+ "Boundary: trailing slash collapses before basename extraction."
+ (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo/")
+ "foo")))
+
+(ert-deftest test-ai-vterm--tmux-session-name-dot-prefix-dir ()
+ "Boundary: dot-prefix dirs preserve the dot (tmux accepts dots)."
+ (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/.emacs.d")
+ ".emacs.d")))
+
+(ert-deftest test-ai-vterm--tmux-session-name-space-becomes-hyphen ()
+ "Boundary: a space in the basename is replaced with a hyphen."
+ (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/my work")
+ "my-work")))
+
+(ert-deftest test-ai-vterm--tmux-session-name-multiple-spaces-collapse ()
+ "Boundary: a run of whitespace collapses to a single hyphen."
+ (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/a b\tc")
+ "a-b-c")))
+
+(provide 'test-ai-vterm--tmux-session-name)
+;;; test-ai-vterm--tmux-session-name.el ends here