|
601 | 601 | "Expected system message to contain 'stopped' text") |
602 | 602 |
|
603 | 603 | (is (< 0 (count tool-reject-messages)) |
604 | | - "Expected at least one toolCallRejected notification to be sent for active tool calls"))))) |
| 604 | + "Expected at least one toolCallRejected notification to be sent for active tool calls") |
| 605 | + |
| 606 | + (is (every? (comp :id :content) tool-reject-messages) |
| 607 | + "Expected every toolCallRejected message to have an :id") |
| 608 | + (is (every? (comp :name :content) tool-reject-messages) |
| 609 | + "Expected every toolCallRejected message to have a :name") |
| 610 | + (is (every? (comp :origin :content) tool-reject-messages) |
| 611 | + "Expected every toolCallRejected message to have an :origin"))))) |
605 | 612 |
|
606 | 613 | (deftest test-stop-prompt-message-count |
607 | 614 | ;; Test that stop-prompt sends appropriate number of messages |
|
630 | 637 | (h/reset-components!) |
631 | 638 | (let [db* (h/db*) |
632 | 639 | chat-id "test-chat" |
633 | | - chat-ctx {:chat-id chat-id :request-id "req-123" :messenger (h/messenger)}] |
| 640 | + tool-call-id "tool-call-1" |
| 641 | + chat-ctx {:chat-id chat-id :request-id "req-123" :messenger (h/messenger)} |
| 642 | + approved?* (promise)] |
634 | 643 |
|
635 | 644 | (swap! db* assoc-in [:chats chat-id] |
636 | 645 | {:status :running |
637 | 646 | :current-request-id "req-123"}) |
638 | 647 |
|
639 | | - (#'f.chat/transition-tool-call! db* chat-ctx "tool-1" :tool-prepare |
| 648 | + (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :tool-prepare |
640 | 649 | {:name "list_files" :origin "filesystem" :arguments-text "{}"}) |
641 | | - |
| 650 | + (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :tool-run |
| 651 | + {:approved?* approved?* |
| 652 | + :name "list_files" |
| 653 | + :origin "filesystem" |
| 654 | + :arguments {"id" 123 "value" 42}}) |
642 | 655 | (f.chat/prompt-stop {:chat-id chat-id} db* (h/messenger)) |
| 656 | + (when-not @approved?* |
| 657 | + (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :send-reject |
| 658 | + {:approved?* approved?* |
| 659 | + :name "list_files" |
| 660 | + :origin "filesystem" |
| 661 | + :arguments {"id" 123 "value" 42}})) |
643 | 662 |
|
644 | 663 | (let [chat-messages (:chat-content-received (h/messages)) |
645 | | - message-types (map #(get-in % [:content :type]) chat-messages)] |
646 | | - (is (some #{:toolCallRejected} message-types) |
647 | | - "Expected toolCallRejected notifications when stopping with active tool calls"))))) |
| 664 | + tool-call-rejected-messages (filter #(= :toolCallRejected (get-in % [:content :type])) |
| 665 | + chat-messages)] |
| 666 | + |
| 667 | + (is (< 0 (count tool-call-rejected-messages)) |
| 668 | + "Expected toolCallRejected notifications when stopping with active tool calls") |
| 669 | + |
| 670 | + (is (some #(get-in % [:content :arguments] %) tool-call-rejected-messages) |
| 671 | + "Expected at least one toolCallRejected message to include non-nil :arguments"))))) |
648 | 672 |
|
649 | 673 | (deftest test-stop-prompt-with-non-running-chat |
650 | 674 | ;; Test stop-prompt behavior when chat is not running. |
|
0 commit comments