|
4 | 4 | [clojure.string :as string] |
5 | 5 | [clojure.test :refer [deftest is testing]] |
6 | 6 | [eca.features.chat :as f.chat] |
| 7 | + [eca.features.chat.lifecycle :as lifecycle] |
7 | 8 | [eca.features.prompt :as f.prompt] |
8 | 9 | [eca.features.tools :as f.tools] |
9 | 10 | [eca.features.tools.mcp :as f.mcp] |
|
588 | 589 | {"foo" 42 "bar" "yo"})) |
589 | 590 | (is (match? |
590 | 591 | @invoked? |
591 | | - [[{:role :user :content "test"}] :mcp-prompt test-chat-ctx])))))) |
| 592 | + [[{:role :user :content "test"}] :mcp-prompt test-chat-ctx]))))) |
| 593 | + |
| 594 | + (testing "shows error message and finishes chat when get-prompt! returns error-message" |
| 595 | + (let [test-chat-ctx {:db* (atom {})} |
| 596 | + sent-content (atom nil) |
| 597 | + finished-status (atom nil)] |
| 598 | + (with-redefs [f.mcp/all-prompts (fn [_] |
| 599 | + [{:name "failing-prompt" :arguments [{:name "arg1"}]}]) |
| 600 | + f.prompt/get-prompt! (fn [_ _ _] |
| 601 | + {:error-message "MCP error getting prompt: code=-32603 message=Invalid required argument: arg1"}) |
| 602 | + lifecycle/send-content! (fn [_ctx _role content] |
| 603 | + (reset! sent-content content)) |
| 604 | + lifecycle/finish-chat-prompt! (fn [status _ctx] |
| 605 | + (reset! finished-status status))] |
| 606 | + (#'f.chat/send-mcp-prompt! {:prompt "failing-prompt" :args ["val1"]} test-chat-ctx) |
| 607 | + (is (= :text (:type @sent-content))) |
| 608 | + (is (string/includes? (:text @sent-content) "MCP error getting prompt")) |
| 609 | + (is (= :idle @finished-status))))) |
| 610 | + |
| 611 | + (testing "shows error message and finishes chat when get-prompt! returns nil" |
| 612 | + (let [test-chat-ctx {:db* (atom {})} |
| 613 | + sent-content (atom nil) |
| 614 | + finished-status (atom nil)] |
| 615 | + (with-redefs [f.mcp/all-prompts (fn [_] |
| 616 | + [{:name "nil-prompt" :arguments []}]) |
| 617 | + f.prompt/get-prompt! (fn [_ _ _] nil) |
| 618 | + lifecycle/send-content! (fn [_ctx _role content] |
| 619 | + (reset! sent-content content)) |
| 620 | + lifecycle/finish-chat-prompt! (fn [status _ctx] |
| 621 | + (reset! finished-status status))] |
| 622 | + (#'f.chat/send-mcp-prompt! {:prompt "nil-prompt" :args []} test-chat-ctx) |
| 623 | + (is (= :text (:type @sent-content))) |
| 624 | + (is (string/includes? (:text @sent-content) "No response from prompt")) |
| 625 | + (is (= :idle @finished-status)))))) |
592 | 626 |
|
593 | 627 | (deftest message->decision-test |
594 | 628 | (testing "plain prompt message" |
|
0 commit comments