|
32 | 32 | (is (= true (:compact-done? chat-state)) |
33 | 33 | "Should set compact-done? to true")))))) |
34 | 34 |
|
| 35 | + (testing "Successfully compacts an auto-compacting chat" |
| 36 | + (let [db* (h/db*) |
| 37 | + chat-id "test-chat-auto-compacting" |
| 38 | + test-summary "Auto-compacted summary"] |
| 39 | + (swap! db* assoc-in [:chats chat-id :auto-compacting?] true) |
| 40 | + (let [result ((get-in f.tools.chat/definitions ["compact_chat" :handler]) |
| 41 | + {"summary" test-summary} |
| 42 | + {:db* db* :chat-id chat-id}) |
| 43 | + chat-state (get-in @db* [:chats chat-id])] |
| 44 | + (is (false? (:error result))) |
| 45 | + (is (= test-summary (:last-summary chat-state))) |
| 46 | + (is (true? (:compact-done? chat-state)))))) |
| 47 | + |
35 | 48 | (testing "Handles empty summary" |
36 | 49 | (let [db* (h/db*) |
37 | 50 | chat-id "test-chat-456" |
|
50 | 63 | (is (= empty-summary (:last-summary chat-state))) |
51 | 64 | (is (= true (:compact-done? chat-state)))))))) |
52 | 65 |
|
53 | | -(deftest compact-chat-enabled-test |
54 | | - (testing "Tool is enabled when chat is compacting" |
55 | | - (let [db* (h/db*) |
56 | | - chat-id "test-chat-compacting"] |
57 | | - (swap! db* assoc-in [:chats chat-id :compacting?] true) |
58 | | - |
59 | | - (is (true? ((get-in f.tools.chat/definitions ["compact_chat" :enabled-fn]) |
60 | | - {:db @db* :chat-id chat-id}))))) |
61 | | - |
62 | | - (testing "Tool is disabled when chat is not compacting" |
63 | | - (let [db* (h/db*) |
64 | | - chat-id "test-chat-not-compacting"] |
65 | | - (swap! db* assoc-in [:chats chat-id :compacting?] false) |
66 | | - |
67 | | - (is (false? ((get-in f.tools.chat/definitions ["compact_chat" :enabled-fn]) |
68 | | - {:db @db* :chat-id chat-id}))))) |
69 | | - |
70 | | - (testing "Tool is disabled when compacting? is not set (defaults to false)" |
71 | | - (let [db* (h/db*) |
72 | | - chat-id "test-chat-no-compacting-key"] |
73 | | - ;; Don't set compacting? at all |
74 | | - |
75 | | - (is (false? ((get-in f.tools.chat/definitions ["compact_chat" :enabled-fn]) |
76 | | - {:db @db* :chat-id chat-id}))))) |
77 | | - |
78 | | - (testing "Tool is disabled when chat doesn't exist" |
79 | | - (let [db* (h/db*) |
80 | | - chat-id "non-existent-chat"] |
81 | | - |
82 | | - (is (false? ((get-in f.tools.chat/definitions ["compact_chat" :enabled-fn]) |
83 | | - {:db @db* :chat-id chat-id})))))) |
| 66 | +(deftest compact-chat-requires-active-compaction-test |
| 67 | + (let [db* (h/db*) |
| 68 | + chat-id "test-chat-not-compacting" |
| 69 | + handler (get-in f.tools.chat/definitions ["compact_chat" :handler])] |
| 70 | + (swap! db* assoc-in [:chats chat-id] {:id chat-id}) |
| 71 | + (let [before @db* |
| 72 | + result (handler {"summary" "Must not be stored"} |
| 73 | + {:db* db* :chat-id chat-id})] |
| 74 | + (is (match? {:error true |
| 75 | + :contents [{:type :text |
| 76 | + :text "Chat compaction is not active for this request. This tool is available only while chat compaction is in progress. To compact manually, the user must use the `/compact` command; compaction may also start automatically when context usage reaches the configured threshold."}]} |
| 77 | + result)) |
| 78 | + (is (= before @db*) |
| 79 | + "Inactive compact tool calls must not mutate chat state")))) |
84 | 80 |
|
85 | 81 | (deftest compact-chat-summary-fn-test |
86 | 82 | (testing "Summary function returns constant string" |
|
93 | 89 | (is (string? (:description tool-def)) "Should have a description") |
94 | 90 | (is (map? (:parameters tool-def)) "Should have parameters") |
95 | 91 | (is (or (fn? (:handler tool-def)) (var? (:handler tool-def))) "Should have a handler function or var") |
96 | | - (is (fn? (:enabled-fn tool-def)) "Should have an enabled-fn") |
| 92 | + (is (not (contains? tool-def :enabled-fn)) |
| 93 | + "Tool availability must not change the provider tool schema") |
97 | 94 | (is (fn? (:summary-fn tool-def)) "Should have a summary-fn"))) |
98 | 95 |
|
99 | 96 | (testing "Tool parameters schema is correct" |
|
0 commit comments