|
458 | 458 | "recent-chat" {:id "recent-chat" |
459 | 459 | :created-at two-days-ago |
460 | 460 | :messages [{:role "user" :content "hello"}]} |
| 461 | + "old-but-active" {:id "old-but-active" |
| 462 | + :created-at fifteen-days-ago |
| 463 | + :updated-at two-days-ago |
| 464 | + :messages [{:role "user" :content "hi again"}]} |
| 465 | + "stale-updated" {:id "stale-updated" |
| 466 | + :created-at fifteen-days-ago |
| 467 | + :updated-at fifteen-days-ago |
| 468 | + :messages [{:role "user" :content "bye"}]} |
461 | 469 | "no-timestamp" {:id "no-timestamp" |
462 | 470 | :messages [{:role "user" :content "hey"}]}}})] |
463 | | - (doseq [id ["old-chat" "recent-chat" "no-timestamp"]] |
| 471 | + (doseq [id ["old-chat" "recent-chat" "old-but-active" "stale-updated" "no-timestamp"]] |
464 | 472 | (db/save-chat! @db* id nil)) |
465 | | - (testing "deletes old chats (memory + file), keeps recent and chats without created-at" |
| 473 | + (testing "deletes stale chats (memory + file), keeps recently updated and chats without timestamps" |
466 | 474 | (db/cleanup-old-chats! db* nil 14) |
467 | 475 | (is (nil? (get-in @db* [:chats "old-chat"])) |
468 | 476 | "Chat older than 14 days should be removed") |
469 | 477 | (is (some? (get-in @db* [:chats "recent-chat"])) |
470 | 478 | "Chat newer than 14 days should be kept") |
| 479 | + (is (some? (get-in @db* [:chats "old-but-active"])) |
| 480 | + "Chat created long ago but updated recently should be kept") |
| 481 | + (is (nil? (get-in @db* [:chats "stale-updated"])) |
| 482 | + "Chat not updated for more than 14 days should be removed") |
471 | 483 | (is (some? (get-in @db* [:chats "no-timestamp"])) |
472 | 484 | "Chat without created-at should be kept") |
473 | | - (is (= #{"old-chat"} (:deleted-chat-ids @db*)) |
| 485 | + (is (= #{"old-chat" "stale-updated"} (:deleted-chat-ids @db*)) |
474 | 486 | "Removed chat ids are tombstoned so index merges cannot resurrect them") |
475 | 487 | (is (not (fs/exists? (chat-cache-file workspaces "old-chat"))) |
476 | 488 | "old chat's cache file is deleted") |
| 489 | + (is (not (fs/exists? (chat-cache-file workspaces "stale-updated"))) |
| 490 | + "stale chat's cache file is deleted") |
477 | 491 | (is (fs/exists? (chat-cache-file workspaces "recent-chat"))) |
478 | | - (is (= #{"recent-chat" "no-timestamp"} (set (keys (read-index workspaces))))))) |
| 492 | + (is (= #{"recent-chat" "old-but-active" "no-timestamp"} (set (keys (read-index workspaces))))))) |
479 | 493 | (finally (fs/delete-tree tmpdir)))))) |
480 | 494 |
|
481 | 495 | (deftest cleanup-old-chats-no-op-test |
|
0 commit comments