comparison 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
comparison
equal deleted inserted replaced
259:667156fcd3e3 260:1f9877b637e9
1 #include "mrjunejune/conversation_store.h"
2
3 #include <assert.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 int main(void)
9 {
10 char database_path[] = "/tmp/mrjunejune-conversations-XXXXXX";
11 int fd = mkstemp(database_path);
12 assert(fd >= 0);
13 close(fd);
14
15 Conversation_Store *p_store = Conversation_Store_Create(database_path);
16 assert(p_store);
17
18 char conversation_id[37];
19 assert(Conversation_Store_Create_Conversation(
20 p_store, "First quest", conversation_id) == CONVERSATION_STORE_OK);
21 assert(strlen(conversation_id) == 36);
22
23 Dowa_Arena *p_arena = Dowa_Arena_Create(16 * 1024);
24 Conversation_Record record;
25 assert(Conversation_Store_Get(
26 p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK);
27 assert(strcmp(record.id, conversation_id) == 0);
28 assert(strcmp(record.title, "First quest") == 0);
29 assert(Dowa_Array_Length(record.turns) == 0);
30 Dowa_Arena_Free(p_arena);
31
32 assert(Conversation_Store_Update_Title(
33 p_store, conversation_id, "Renamed quest") == CONVERSATION_STORE_OK);
34 assert(Conversation_Store_Begin_Turn(
35 p_store,
36 conversation_id,
37 "request-1",
38 "Hello Epi") == CONVERSATION_STORE_OK);
39 assert(Conversation_Store_Begin_Turn(
40 p_store,
41 conversation_id,
42 "request-2",
43 "Overlapping") == CONVERSATION_STORE_CONFLICT);
44 assert(Conversation_Store_Complete_Turn(
45 p_store,
46 conversation_id,
47 "request-1",
48 "Hello traveler",
49 12,
50 4) == CONVERSATION_STORE_OK);
51
52 assert(Conversation_Store_Begin_Turn(
53 p_store,
54 conversation_id,
55 "request-2",
56 "Try again") == CONVERSATION_STORE_OK);
57 assert(Conversation_Store_Fail_Turn(
58 p_store,
59 conversation_id,
60 "request-2",
61 "cancelled",
62 TRUE) == CONVERSATION_STORE_OK);
63
64 p_arena = Dowa_Arena_Create(32 * 1024);
65 assert(Conversation_Store_Get(
66 p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK);
67 assert(strcmp(record.title, "Renamed quest") == 0);
68 assert(Dowa_Array_Length(record.turns) == 4);
69 assert(strcmp(record.turns[0].role, "user") == 0);
70 assert(strcmp(record.turns[0].content, "Hello Epi") == 0);
71 assert(strcmp(record.turns[1].role, "assistant") == 0);
72 assert(strcmp(record.turns[1].content, "Hello traveler") == 0);
73 assert(record.turns[1].input_tokens == 12);
74 assert(record.turns[1].output_tokens == 4);
75 assert(strcmp(record.turns[3].status, "aborted") == 0);
76 Dowa_Arena_Free(p_arena);
77
78 assert(Conversation_Store_Begin_Turn(
79 p_store,
80 conversation_id,
81 "request-3",
82 "Interrupted") == CONVERSATION_STORE_OK);
83 Conversation_Store_Destroy(p_store);
84 p_store = Conversation_Store_Create(database_path);
85 assert(p_store);
86 assert(Conversation_Store_Begin_Turn(
87 p_store,
88 conversation_id,
89 "request-4",
90 "Recovered") == CONVERSATION_STORE_OK);
91 assert(Conversation_Store_Complete_Turn(
92 p_store,
93 conversation_id,
94 "request-4",
95 "Recovered answer",
96 1,
97 1) == CONVERSATION_STORE_OK);
98
99 p_arena = Dowa_Arena_Create(32 * 1024);
100 assert(Conversation_Store_Get(
101 p_store, conversation_id, &record, p_arena) == CONVERSATION_STORE_OK);
102 assert(Dowa_Array_Length(record.turns) == 8);
103 assert(strcmp(record.turns[5].status, "failed") == 0);
104 assert(strcmp(
105 record.turns[5].error_message,
106 "Interrupted by server restart") == 0);
107 Dowa_Arena_Free(p_arena);
108
109 assert(Conversation_Store_Delete(
110 p_store, conversation_id) == CONVERSATION_STORE_OK);
111 p_arena = Dowa_Arena_Create(4096);
112 assert(Conversation_Store_Get(
113 p_store,
114 conversation_id,
115 &record,
116 p_arena) == CONVERSATION_STORE_NOT_FOUND);
117 Dowa_Arena_Free(p_arena);
118
119 Conversation_Store_Destroy(p_store);
120 unlink(database_path);
121 printf("Conversation store tests passed\n");
122 return 0;
123 }