MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ui_health_matches

Function ui_health_matches

tests/test_httpd.c:2816–2851  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2814}
2815
2816static bool ui_health_matches(th_server_t *server, const char *project, const char *status,
2817 const char *indexed_at, bool registered, bool running) {
2818 char request[512], response[4096];
2819 snprintf(request, sizeof(request), "GET /api/project-health?name=%s HTTP/1.1\r\n\r\n", project);
2820 int length = th_http(cbm_http_server_port(server->srv), request, response, sizeof(response));
2821 if (length <= 0 || th_status(response) != 200)
2822 return false;
2823 const char *body = strstr(response, "\r\n\r\n");
2824 if (!body)
2825 return false;
2826 body += 4;
2827 yyjson_doc *doc = yyjson_read(body, strlen(body), 0);
2828 if (!doc)
2829 return false;
2830 yyjson_val *root = yyjson_doc_get_root(doc);
2831 yyjson_val *actual_status = yyjson_obj_get(root, "status");
2832 yyjson_val *timestamp = yyjson_obj_get(root, "indexed_at");
2833 yyjson_val *watch = yyjson_obj_get(root, "watch_registered");
2834 yyjson_val *loop = yyjson_obj_get(root, "watcher_running");
2835 bool matches = yyjson_is_str(actual_status) &&
2836 strcmp(yyjson_get_str(actual_status), status) == 0 && yyjson_is_bool(watch) &&
2837 yyjson_get_bool(watch) == registered && yyjson_is_bool(loop) &&
2838 yyjson_get_bool(loop) == running;
2839 matches = matches && (indexed_at ? yyjson_is_str(timestamp) &&
2840 strcmp(yyjson_get_str(timestamp), indexed_at) == 0
2841 : yyjson_is_null(timestamp));
2842 if (strcmp(status, "healthy") == 0) {
2843 matches = matches && yyjson_is_int(yyjson_obj_get(root, "nodes")) &&
2844 yyjson_get_int(yyjson_obj_get(root, "nodes")) == 0 &&
2845 yyjson_is_int(yyjson_obj_get(root, "edges")) &&
2846 yyjson_get_int(yyjson_obj_get(root, "edges")) == 0 &&
2847 yyjson_get_int(yyjson_obj_get(root, "size_bytes")) > 0;
2848 }
2849 yyjson_doc_free(doc);
2850 return matches;
2851}
2852
2853TEST(ui_server_project_health_timestamp_and_no_watcher) {
2854 ui_delete_fixture_t fx;

Callers 1

test_httpd.cFile · 0.85

Calls 3

th_httpFunction · 0.85
cbm_http_server_portFunction · 0.85
th_statusFunction · 0.85

Tested by

no test coverage detected