|
1163 | 1163 | (is (match? {:found? true :chat-id chat-id :title "My Opus thread"} result)) |
1164 | 1164 | (is (match? {:config-updated [{:chat {:select-model "anthropic/claude-opus-4" |
1165 | 1165 | :variants [] |
1166 | | - :select-variant nil}}]} |
| 1166 | + :select-variant nil}} |
| 1167 | + {:chat {:select-trust false}}]} |
1167 | 1168 | (h/messages)))))) |
1168 | 1169 |
|
1169 | | - (testing "Opening a chat with no stored :model does not emit config/updated" |
| 1170 | + (testing "Opening a chat with no stored :model only emits trust config/updated" |
1170 | 1171 | (h/reset-components!) |
1171 | 1172 | (let [chat-id "no-model"] |
1172 | 1173 | (swap! (h/db*) assoc-in [:chats chat-id] |
1173 | 1174 | {:id chat-id |
1174 | 1175 | :messages [{:role "user" :content [{:type :text :text "hi"}]}]}) |
1175 | 1176 | (f.chat/open-chat! {:chat-id chat-id} (h/db*) (h/messenger) (h/config)) |
1176 | | - (is (nil? (:config-updated (h/messages)))))) |
| 1177 | + (is (match? {:config-updated [{:chat {:select-trust false}}]} |
| 1178 | + (h/messages))))) |
1177 | 1179 |
|
1178 | | - (testing "Opening a chat with a stale stored :model does not emit config/updated" |
| 1180 | + (testing "Opening a chat with a stale stored :model only emits trust config/updated" |
1179 | 1181 | (h/reset-components!) |
1180 | 1182 | (let [chat-id "stale-model"] |
1181 | 1183 | ;; Opus not in (:models db), so the UI dropdown must not jump to a ghost. |
|
1184 | 1186 | :model "anthropic/claude-opus-4" |
1185 | 1187 | :messages [{:role "user" :content [{:type :text :text "hi"}]}]}) |
1186 | 1188 | (f.chat/open-chat! {:chat-id chat-id} (h/db*) (h/messenger) (h/config)) |
1187 | | - (is (nil? (:config-updated (h/messages))))))) |
| 1189 | + (is (match? {:config-updated [{:chat {:select-trust false}}]} |
| 1190 | + (h/messages)))))) |
| 1191 | + |
| 1192 | +(deftest open-chat-restores-selected-trust-test |
| 1193 | + (testing "Opening a trusted chat emits config/updated select-trust true (#426)" |
| 1194 | + (h/reset-components!) |
| 1195 | + (let [chat-id "trusted"] |
| 1196 | + (swap! (h/db*) assoc-in [:chats chat-id] |
| 1197 | + {:id chat-id |
| 1198 | + :title "YOLO thread" |
| 1199 | + :trust true |
| 1200 | + :messages [{:role "user" :content [{:type :text :text "hi"}]}]}) |
| 1201 | + (f.chat/open-chat! {:chat-id chat-id} (h/db*) (h/messenger) (h/config)) |
| 1202 | + (is (match? {:config-updated [{:chat {:select-trust true}}]} |
| 1203 | + (h/messages))))) |
| 1204 | + |
| 1205 | + (testing "Opening a non-trusted chat emits config/updated select-trust false (#426)" |
| 1206 | + (h/reset-components!) |
| 1207 | + (let [chat-id "secured"] |
| 1208 | + ;; Pre-seed last-config-notified so the diff actually picks up false. |
| 1209 | + (swap! (h/db*) assoc :last-config-notified {:chat {:select-trust true}}) |
| 1210 | + (swap! (h/db*) assoc-in [:chats chat-id] |
| 1211 | + {:id chat-id |
| 1212 | + :trust false |
| 1213 | + :messages [{:role "user" :content [{:type :text :text "hi"}]}]}) |
| 1214 | + (f.chat/open-chat! {:chat-id chat-id} (h/db*) (h/messenger) (h/config)) |
| 1215 | + (is (match? {:config-updated [{:chat {:select-trust false}}]} |
| 1216 | + (h/messages))))) |
| 1217 | + |
| 1218 | + (testing "Opening a chat with no :trust key normalizes to false (#426)" |
| 1219 | + (h/reset-components!) |
| 1220 | + (let [chat-id "legacy"] |
| 1221 | + (swap! (h/db*) assoc :last-config-notified {:chat {:select-trust true}}) |
| 1222 | + (swap! (h/db*) assoc-in [:chats chat-id] |
| 1223 | + {:id chat-id |
| 1224 | + :messages [{:role "user" :content [{:type :text :text "hi"}]}]}) |
| 1225 | + (f.chat/open-chat! {:chat-id chat-id} (h/db*) (h/messenger) (h/config)) |
| 1226 | + (is (match? {:config-updated [{:chat {:select-trust false}}]} |
| 1227 | + (h/messages)))))) |
1188 | 1228 |
|
1189 | 1229 |
|
0 commit comments