Mercurial
diff mrjunejune/test/conversation_store_test.c @ 260:1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
Integrate the production JRPG chat with Seobeo streaming, Deita persistence, and a Bazel-managed Copilot SDK and LiteLLM inference stack.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <mrjunejune@users.noreply.github.com> |
|---|---|
| date | Wed, 05 Aug 2026 09:19:41 -0700 |
| parents | |
| children | 04fee26ecce0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/conversation_store_test.c Wed Aug 05 09:19:41 2026 -0700 @@ -0,0 +1,123 @@ +#include "mrjunejune/conversation_store.h" + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int main(void) +{ + char database_path[] = "/tmp/mrjunejune-conversations-XXXXXX"; + int fd = mkstemp(database_path); + assert(fd >= 0); + close(fd); + + Conversation_Store *p_store = Conversation_Store_Create(database_path); + assert(p_store); + + char conversation_id[37]; + assert(Conversation_Store_Create_Conversation( + p_store, "First quest", conversation_id) == CONVERSATION_STORE_OK); + assert(strlen(conversation_id) == 36); + + Dowa_Arena *p_arena = Dowa_Arena_Create(16 * 1024); + Conversation_Record record; + assert(Conversation_Store_Get( + p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK); + assert(strcmp(record.id, conversation_id) == 0); + assert(strcmp(record.title, "First quest") == 0); + assert(Dowa_Array_Length(record.turns) == 0); + Dowa_Arena_Free(p_arena); + + assert(Conversation_Store_Update_Title( + p_store, conversation_id, "Renamed quest") == CONVERSATION_STORE_OK); + assert(Conversation_Store_Begin_Turn( + p_store, + conversation_id, + "request-1", + "Hello Epi") == CONVERSATION_STORE_OK); + assert(Conversation_Store_Begin_Turn( + p_store, + conversation_id, + "request-2", + "Overlapping") == CONVERSATION_STORE_CONFLICT); + assert(Conversation_Store_Complete_Turn( + p_store, + conversation_id, + "request-1", + "Hello traveler", + 12, + 4) == CONVERSATION_STORE_OK); + + assert(Conversation_Store_Begin_Turn( + p_store, + conversation_id, + "request-2", + "Try again") == CONVERSATION_STORE_OK); + assert(Conversation_Store_Fail_Turn( + p_store, + conversation_id, + "request-2", + "cancelled", + TRUE) == CONVERSATION_STORE_OK); + + p_arena = Dowa_Arena_Create(32 * 1024); + assert(Conversation_Store_Get( + p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK); + assert(strcmp(record.title, "Renamed quest") == 0); + assert(Dowa_Array_Length(record.turns) == 4); + assert(strcmp(record.turns[0].role, "user") == 0); + assert(strcmp(record.turns[0].content, "Hello Epi") == 0); + assert(strcmp(record.turns[1].role, "assistant") == 0); + assert(strcmp(record.turns[1].content, "Hello traveler") == 0); + assert(record.turns[1].input_tokens == 12); + assert(record.turns[1].output_tokens == 4); + assert(strcmp(record.turns[3].status, "aborted") == 0); + Dowa_Arena_Free(p_arena); + + assert(Conversation_Store_Begin_Turn( + p_store, + conversation_id, + "request-3", + "Interrupted") == CONVERSATION_STORE_OK); + Conversation_Store_Destroy(p_store); + p_store = Conversation_Store_Create(database_path); + assert(p_store); + assert(Conversation_Store_Begin_Turn( + p_store, + conversation_id, + "request-4", + "Recovered") == CONVERSATION_STORE_OK); + assert(Conversation_Store_Complete_Turn( + p_store, + conversation_id, + "request-4", + "Recovered answer", + 1, + 1) == CONVERSATION_STORE_OK); + + p_arena = Dowa_Arena_Create(32 * 1024); + assert(Conversation_Store_Get( + p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK); + assert(Dowa_Array_Length(record.turns) == 8); + assert(strcmp(record.turns[5].status, "failed") == 0); + assert(strcmp( + record.turns[5].error_message, + "Interrupted by server restart") == 0); + Dowa_Arena_Free(p_arena); + + assert(Conversation_Store_Delete( + p_store, conversation_id) == CONVERSATION_STORE_OK); + p_arena = Dowa_Arena_Create(4096); + assert(Conversation_Store_Get( + p_store, + conversation_id, + &record, + p_arena) == CONVERSATION_STORE_NOT_FOUND); + Dowa_Arena_Free(p_arena); + + Conversation_Store_Destroy(p_store); + unlink(database_path); + printf("Conversation store tests passed\n"); + return 0; +}