|
121 | 121 | (let [result (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :tool-prepare event-data)] |
122 | 122 |
|
123 | 123 | (is (match? {:status :preparing |
124 | | - :actions [:send-toolCallPrepare :init-decision-reason]} |
| 124 | + :actions [:init-tool-call-state :send-toolCallPrepare]} |
125 | 125 | result) |
126 | 126 | "Expected return value to show :preparing status and send toolCallPrepare action") |
127 | 127 |
|
|
218 | 218 | (let [result (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :tool-run run-event-data)] |
219 | 219 |
|
220 | 220 | (is (match? {:status :check-approval |
221 | | - :actions [:init-approval-promise :send-toolCallRun]} |
| 221 | + :actions [:init-arguments :init-approval-promise :send-toolCallRun]} |
222 | 222 | result) |
223 | 223 | "Expected next state to be :check-approval with actions of :init-approval-promise and :send-toolCallRun") |
224 | 224 |
|
|
273 | 273 | ;; Step 2: :preparing -> :check-approval |
274 | 274 | (let [result (#'f.chat/transition-tool-call! db* chat-ctx tool-call-id :tool-run run-event-data)] |
275 | 275 | (is (match? {:status :check-approval |
276 | | - :actions [:init-approval-promise :send-toolCallRun]} |
| 276 | + :actions [:init-arguments :init-approval-promise :send-toolCallRun]} |
277 | 277 | result) |
278 | 278 | "Expected transition to :check-approval with init promise and send run actions") |
279 | 279 |
|
|
517 | 517 | (#'f.chat/transition-tool-call! db* chat-ctx "tool-rejected" :stop-requested)) |
518 | 518 | "Expected exception as already rejected tool calls cannot be stopped")))))) |
519 | 519 |
|
| 520 | +;; TODO: This test and the previous test seem to be testing similar things. Clean up. |
520 | 521 | (deftest transition-tool-call-stop-transitions-test |
521 | 522 | (testing "Stop transitions from various states" |
522 | 523 | (h/reset-components!) |
|
600 | 601 | "Expected system message to contain 'stopped' text") |
601 | 602 |
|
602 | 603 | (is (< 0 (count tool-reject-messages)) |
603 | | - "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"))))) |
604 | 612 |
|
605 | 613 | (deftest test-stop-prompt-message-count |
606 | 614 | ;; Test that stop-prompt sends appropriate number of messages |
|
629 | 637 | (h/reset-components!) |
630 | 638 | (let [db* (h/db*) |
631 | 639 | chat-id "test-chat" |
632 | | - 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)] |
633 | 643 |
|
634 | 644 | (swap! db* assoc-in [:chats chat-id] |
635 | 645 | {:status :running |
636 | 646 | :current-request-id "req-123"}) |
637 | 647 |
|
638 | | - (#'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 |
639 | 649 | {:name "list_files" :origin "filesystem" :arguments-text "{}"}) |
640 | | - |
| 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}}) |
641 | 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}})) |
642 | 662 |
|
643 | 663 | (let [chat-messages (:chat-content-received (h/messages)) |
644 | | - message-types (map #(get-in % [:content :type]) chat-messages)] |
645 | | - (is (some #{:toolCallRejected} message-types) |
646 | | - "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"))))) |
647 | 672 |
|
648 | 673 | (deftest test-stop-prompt-with-non-running-chat |
649 | 674 | ;; Test stop-prompt behavior when chat is not running. |
|
0 commit comments