|
536 | 536 | (:config-updated (h/messages)))) |
537 | 537 | (is (= session-defaults (:last-config-notified (h/db))))))) |
538 | 538 |
|
| 539 | +(deftest delete-chat-command-test |
| 540 | + (testing "no confirm asks for confirmation for the current chat" |
| 541 | + (h/reset-components!) |
| 542 | + (swap! (h/db*) assoc :chats {"chat-b" {:id "chat-b" :messages []}}) |
| 543 | + (let [result (f.commands/handle-command! "delete-chat" [] (command-context "chat-b"))] |
| 544 | + (is (= :chat-messages (:type result))) |
| 545 | + (is (string/includes? (get-in result [:chats "chat-b" :messages 0 :content 0 :text]) |
| 546 | + "Run `/delete-chat confirm` to proceed.")))) |
| 547 | + |
| 548 | + (testing "confirm deletes the current chat" |
| 549 | + (h/reset-components!) |
| 550 | + (swap! (h/db*) assoc :chats {"chat-b" {:id "chat-b" :messages []}}) |
| 551 | + (is (= {:type :delete-chat :target-chat-id "chat-b" :text nil} |
| 552 | + (f.commands/handle-command! "delete-chat" ["confirm"] (command-context "chat-b"))))) |
| 553 | + |
| 554 | + (testing "chat-id arg resolves like the /resume listing" |
| 555 | + (h/reset-components!) |
| 556 | + (swap! (h/db*) assoc :chats {"chat-a" {:id "chat-a" :created-at 1 :title "First" :messages []} |
| 557 | + "chat-b" {:id "chat-b" :created-at 2 :messages []} |
| 558 | + "chat-c" {:id "chat-c" :created-at 3 :title "Third" :messages []}}) |
| 559 | + (let [ask (f.commands/handle-command! "delete-chat" ["2"] (command-context "chat-b")) |
| 560 | + result (f.commands/handle-command! "delete-chat" ["2" "confirm"] (command-context "chat-b"))] |
| 561 | + (is (string/includes? (get-in ask [:chats "chat-b" :messages 0 :content 0 :text]) |
| 562 | + "Run `/delete-chat 2 confirm` to proceed.")) |
| 563 | + (is (= {:type :delete-chat :target-chat-id "chat-c" :text "Deleted chat: Third"} |
| 564 | + result)))) |
| 565 | + |
| 566 | + (testing "a literal chat id is accepted" |
| 567 | + (h/reset-components!) |
| 568 | + (swap! (h/db*) assoc :chats {"chat-a" {:id "chat-a" :created-at 1 :title "First" :messages []} |
| 569 | + "chat-b" {:id "chat-b" :created-at 2 :messages []}}) |
| 570 | + (is (= {:type :delete-chat :target-chat-id "chat-a" :text "Deleted chat: First"} |
| 571 | + (f.commands/handle-command! "delete-chat" ["chat-a" "confirm"] (command-context "chat-b"))))) |
| 572 | + |
| 573 | + (testing "unknown chat id" |
| 574 | + (h/reset-components!) |
| 575 | + (swap! (h/db*) assoc :chats {"chat-b" {:id "chat-b" :messages []}}) |
| 576 | + (let [result (f.commands/handle-command! "delete-chat" ["9" "confirm"] (command-context "chat-b"))] |
| 577 | + (is (string/includes? (get-in result [:chats "chat-b" :messages 0 :content 0 :text]) |
| 578 | + "Chat ID not found.")))) |
| 579 | + |
| 580 | + (testing "refuses deleting another chat with a running prompt" |
| 581 | + (h/reset-components!) |
| 582 | + (swap! (h/db*) assoc :chats {"chat-a" {:id "chat-a" :created-at 1 :title "Busy" :status :running :messages []} |
| 583 | + "chat-b" {:id "chat-b" :created-at 2 :messages []}}) |
| 584 | + (let [result (f.commands/handle-command! "delete-chat" ["1" "confirm"] (command-context "chat-b"))] |
| 585 | + (is (string/includes? (get-in result [:chats "chat-b" :messages 0 :content 0 :text]) |
| 586 | + "has a running prompt")))) |
| 587 | + |
| 588 | + (testing "stale running status of an index-only chat does not block deletion" |
| 589 | + (h/reset-components!) |
| 590 | + (swap! (h/db*) assoc :chats {"chat-a" {:id "chat-a" :created-at 1 :title "Stale" :status :running :index-only? true} |
| 591 | + "chat-b" {:id "chat-b" :created-at 2 :messages []}}) |
| 592 | + (is (= {:type :delete-chat :target-chat-id "chat-a" :text "Deleted chat: Stale"} |
| 593 | + (f.commands/handle-command! "delete-chat" ["1" "confirm"] (command-context "chat-b")))))) |
| 594 | + |
539 | 595 | (deftest rules-command-test |
540 | 596 | (testing "/rules shows static and path-scoped rules separately with filter metadata" |
541 | 597 | (with-redefs [f.rules/all-rules (fn [_config _roots agent full-model] |
|
0 commit comments