Mercurial
comparison seobeo/tests/seobeo_sse_server_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 | 609d3c6aff4e |
| children |
comparison
equal
deleted
inserted
replaced
| 259:667156fcd3e3 | 260:1f9877b637e9 |
|---|---|
| 60 return -1; | 60 return -1; |
| 61 } | 61 } |
| 62 return socket_fd; | 62 return socket_fd; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void send_request(int socket_fd, const char *path) | 65 static void send_request( |
| 66 int socket_fd, | |
| 67 const char *method, | |
| 68 const char *path, | |
| 69 const char *body) | |
| 66 { | 70 { |
| 67 char request[512]; | 71 char request[512]; |
| 72 size_t body_length = body ? strlen(body) : 0; | |
| 68 int length = snprintf( | 73 int length = snprintf( |
| 69 request, | 74 request, |
| 70 sizeof(request), | 75 sizeof(request), |
| 71 "GET %s HTTP/1.1\r\n" | 76 "%s %s HTTP/1.1\r\n" |
| 72 "Host: 127.0.0.1\r\n" | 77 "Host: 127.0.0.1\r\n" |
| 78 "Content-Length: %zu\r\n" | |
| 73 "Connection: keep-alive\r\n" | 79 "Connection: keep-alive\r\n" |
| 74 "\r\n", | 80 "\r\n" |
| 75 path); | 81 "%s", |
| 82 method, | |
| 83 path, | |
| 84 body_length, | |
| 85 body ? body : ""); | |
| 76 assert(length > 0 && (size_t)length < sizeof(request)); | 86 assert(length > 0 && (size_t)length < sizeof(request)); |
| 77 assert(send(socket_fd, request, (size_t)length, 0) == length); | 87 assert(send(socket_fd, request, (size_t)length, 0) == length); |
| 78 } | 88 } |
| 79 | 89 |
| 80 static size_t receive_until( | 90 static size_t receive_until( |
| 138 snprintf(port_text, sizeof(port_text), "%d", port); | 148 snprintf(port_text, sizeof(port_text), "%d", port); |
| 139 pid_t server = start_server(argv[1], port_text); | 149 pid_t server = start_server(argv[1], port_text); |
| 140 | 150 |
| 141 int event_socket = connect_to(port); | 151 int event_socket = connect_to(port); |
| 142 assert(event_socket >= 0); | 152 assert(event_socket >= 0); |
| 143 send_request(event_socket, "/events"); | 153 send_request(event_socket, "GET", "/events", NULL); |
| 144 char events[4096] = {0}; | 154 char events[4096] = {0}; |
| 145 receive_until( | 155 receive_until( |
| 146 event_socket, | 156 event_socket, |
| 147 events, | 157 events, |
| 148 sizeof(events), | 158 sizeof(events), |
| 149 "data: later\n\n"); | 159 "data: later\n\n"); |
| 150 assert(strstr(events, "HTTP/1.1 200 OK\r\n")); | 160 assert(strstr(events, "HTTP/1.1 200 OK\r\n")); |
| 151 assert(strstr(events, "Content-Type: text/event-stream\r\n")); | 161 assert(strstr(events, "Content-Type: text/event-stream\r\n")); |
| 152 assert(strstr(events, "data: connected\n\n")); | 162 assert(strstr(events, "data: connected\n\n")); |
| 153 | 163 |
| 164 int post_socket = connect_to(port); | |
| 165 assert(post_socket >= 0); | |
| 166 send_request( | |
| 167 post_socket, | |
| 168 "POST", | |
| 169 "/events/builds", | |
| 170 "deploy=release"); | |
| 171 char post_events[4096] = {0}; | |
| 172 receive_until( | |
| 173 post_socket, | |
| 174 post_events, | |
| 175 sizeof(post_events), | |
| 176 "data: topic=builds body=deploy=release\n\n"); | |
| 177 assert(strstr(post_events, "HTTP/1.1 200 OK\r\n")); | |
| 178 assert(strstr(post_events, "Content-Type: text/event-stream\r\n")); | |
| 179 | |
| 180 int wrong_method_socket = connect_to(port); | |
| 181 assert(wrong_method_socket >= 0); | |
| 182 send_request( | |
| 183 wrong_method_socket, | |
| 184 "PUT", | |
| 185 "/events/builds", | |
| 186 NULL); | |
| 187 char wrong_method[1024] = {0}; | |
| 188 receive_until( | |
| 189 wrong_method_socket, | |
| 190 wrong_method, | |
| 191 sizeof(wrong_method), | |
| 192 "\r\n\r\n"); | |
| 193 assert(strstr(wrong_method, "HTTP/1.1 404 Not Found\r\n")); | |
| 194 | |
| 154 int health_socket = connect_to(port); | 195 int health_socket = connect_to(port); |
| 155 assert(health_socket >= 0); | 196 assert(health_socket >= 0); |
| 156 send_request(health_socket, "/health"); | 197 send_request(health_socket, "GET", "/health", NULL); |
| 157 assert(shutdown(health_socket, SHUT_WR) == 0); | 198 assert(shutdown(health_socket, SHUT_WR) == 0); |
| 158 char health[1024] = {0}; | 199 char health[1024] = {0}; |
| 159 receive_until(health_socket, health, sizeof(health), "\r\n\r\nok"); | 200 receive_until(health_socket, health, sizeof(health), "\r\n\r\nok"); |
| 160 assert(strstr(health, "HTTP/1.1 200 OK\r\n")); | 201 assert(strstr(health, "HTTP/1.1 200 OK\r\n")); |
| 161 | 202 |
| 162 close(health_socket); | 203 close(health_socket); |
| 204 close(wrong_method_socket); | |
| 205 close(post_socket); | |
| 163 close(event_socket); | 206 close(event_socket); |
| 164 kill(server, SIGTERM); | 207 kill(server, SIGTERM); |
| 165 waitpid(server, NULL, 0); | 208 waitpid(server, NULL, 0); |
| 166 printf("Seobeo SSE server integration test passed\n"); | 209 printf("Seobeo SSE server integration test passed\n"); |
| 167 return 0; | 210 return 0; |