Skip to content

Commit c957a1b

Browse files
author
Kang Tu
committed
fix: Address PR review feedback and fix pre-existing test failures
Add explicit (require 'ai-code-change) to ai-code-discussion.el and gate TODO routing on buffer-file-name to prevent errors in unsaved buffers. Fix claude-code multiline test by mocking MCP agent launch, and fix capf test by adding ai-code-git require and magit-git-lines mock to test repo macro.
1 parent 3fc7b17 commit c957a1b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

ai-code-discussion.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
(require 'ai-code-input)
1515
(require 'ai-code-prompt-mode)
16+
(require 'ai-code-change)
1617

1718
(declare-function ai-code-read-string "ai-code-input")
1819
(declare-function ai-code--insert-prompt "ai-code-prompt-mode")
@@ -21,8 +22,6 @@
2122
(declare-function ai-code--ensure-files-directory "ai-code-prompt-mode")
2223
(declare-function ai-code--git-root "ai-code-file" (&optional dir))
2324
(declare-function ai-code--format-repo-context-info "ai-code-file")
24-
(declare-function ai-code--detect-todo-info "ai-code-change" (region-active))
25-
(declare-function ai-code-implement-todo "ai-code-change" (arg &optional default-action))
2625

2726
(defvar ai-code--repo-context-info)
2827

@@ -110,7 +109,8 @@ Argument ARG is the prefix argument."
110109
(let ((clipboard-context (when arg (ai-code--get-clipboard-text))))
111110
(ai-code--ask-question-dired clipboard-context)))
112111
(t
113-
(let ((todo-info (ai-code--detect-todo-info (region-active-p))))
112+
(let ((todo-info (when buffer-file-name
113+
(ai-code--detect-todo-info (region-active-p)))))
114114
(if todo-info
115115
(ai-code-implement-todo arg "Ask question")
116116
(let ((clipboard-context (when arg (ai-code--get-clipboard-text))))

test/test_ai-code-claude-code.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
((symbol-function 'ai-code-backends-infra--resolve-start-command)
2626
(lambda (&rest _args)
2727
(list :command "claude")))
28+
((symbol-function 'ai-code-mcp-agent-prepare-launch)
29+
(lambda (&rest _args) nil))
2830
((symbol-function 'ai-code-backends-infra--toggle-or-create-session)
2931
(lambda (&rest args)
3032
(cl-destructuring-bind

test/test_ai-code-prompt-mode.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
(require 'ert)
1212
(require 'ai-code-prompt-mode)
13+
(require 'ai-code-git)
1314
(require 'magit)
1415
(require 'cl-lib)
1516

@@ -36,7 +37,12 @@ and ensures everything is cleaned up afterward."
3637
(with-temp-file outside-file (insert "content"))
3738
;; Execute test body with mocks
3839
(cl-letf (((symbol-function 'magit-toplevel) (lambda (&optional dir) git-root))
39-
((symbol-function 'ai-code--git-root) (lambda (&optional dir) git-root)))
40+
((symbol-function 'ai-code--git-root) (lambda (&optional dir) git-root))
41+
((symbol-function 'magit-git-lines)
42+
(lambda (&rest _args)
43+
(let ((default-directory git-root))
44+
(mapcar (lambda (f) (file-relative-name f git-root))
45+
(directory-files-recursively git-root ""))))))
4046
,@body))
4147
;; Teardown: Clean up dummy files and directories
4248
(when (file-exists-p mock-file-in-repo) (delete-file mock-file-in-repo))

0 commit comments

Comments
 (0)