|
121 | 121 | (alist-get 'tools tools-result)))) |
122 | 122 | (should (member "eval_elisp" tool-names))))) |
123 | 123 |
|
| 124 | +(ert-deftest ai-code-test-mcp-tools-list-warns-eval-elisp-is-unrestricted () |
| 125 | + "Eval tool metadata should warn about unrestricted side effects." |
| 126 | + (let ((ai-code-mcp-server-tools nil) |
| 127 | + (ai-code-mcp-debug-tools-enabled t) |
| 128 | + (ai-code-mcp-debug-tools-enable-eval-elisp t)) |
| 129 | + (let* ((tools-result (ai-code-mcp-dispatch "tools/list")) |
| 130 | + (eval-tool (seq-find |
| 131 | + (lambda (tool) |
| 132 | + (equal "eval_elisp" (alist-get 'name tool))) |
| 133 | + (alist-get 'tools tools-result))) |
| 134 | + (description (alist-get 'description eval-tool))) |
| 135 | + (should eval-tool) |
| 136 | + (should (string-match-p "arbitrary Emacs Lisp" description)) |
| 137 | + (should (string-match-p "side effects" description))))) |
| 138 | + |
124 | 139 | (ert-deftest ai-code-test-mcp-eval-elisp-uses-target-buffer () |
125 | 140 | "Eval should run against the requested buffer context." |
126 | 141 | (let ((ai-code-mcp-server-tools nil) |
|
197 | 212 | (when (buffer-live-p buffer) |
198 | 213 | (kill-buffer buffer))))) |
199 | 214 |
|
| 215 | +(ert-deftest ai-code-test-mcp-eval-elisp-survives-killed-target-buffer () |
| 216 | + "Eval should still return JSON when the target buffer is killed." |
| 217 | + (let ((ai-code-mcp-server-tools nil) |
| 218 | + (ai-code-mcp-debug-tools-enabled t) |
| 219 | + (ai-code-mcp-debug-tools-enable-eval-elisp t) |
| 220 | + (buffer (generate-new-buffer " *ai-code-mcp-eval-kill*"))) |
| 221 | + (let ((payload |
| 222 | + (unwind-protect |
| 223 | + (ai-code-test-mcp-debug-tools--read-json-payload |
| 224 | + (ai-code-mcp-dispatch |
| 225 | + "tools/call" |
| 226 | + `((name . "eval_elisp") |
| 227 | + (arguments . ((code . "(kill-buffer (current-buffer))") |
| 228 | + (buffer_name . ,(buffer-name buffer))))))) |
| 229 | + (when (buffer-live-p buffer) |
| 230 | + (kill-buffer buffer))))) |
| 231 | + (should (equal t (alist-get 'ok payload))) |
| 232 | + (should (equal "t" (alist-get 'value_repr payload))) |
| 233 | + (should-not (alist-get 'context_after payload))))) |
| 234 | + |
200 | 235 | (ert-deftest ai-code-test-mcp-get-variable-value-returns-bound-variable () |
201 | 236 | "Variable value tool should stringify the requested Emacs variable." |
202 | 237 | (let ((ai-code-mcp-server-tools nil) |
|
516 | 551 | (when (fboundp (intern-soft func-name)) |
517 | 552 | (fmakunbound (intern func-name)))))) |
518 | 553 |
|
| 554 | +(ert-deftest ai-code-test-readme-documents-eval-elisp-debug-options () |
| 555 | + "README should mention the eval_elisp debugging options." |
| 556 | + (with-temp-buffer |
| 557 | + (insert-file-contents "README.org") |
| 558 | + (dolist (option '("=capture_messages=" "=include_backtrace=")) |
| 559 | + (goto-char (point-min)) |
| 560 | + (should (search-forward option nil t))))) |
| 561 | + |
519 | 562 | (provide 'test_ai-code-mcp-debug-tools) |
520 | 563 |
|
521 | 564 | ;;; test_ai-code-mcp-debug-tools.el ends here |
0 commit comments