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

Function th_ui_index_probe

tests/test_httpd.c:1923–1958  ·  view source on GitHub ↗

Boot a server with the recording executor, POST one /api/index request, * wait for the worker only when the route accepted the job, read * /api/index-status and stop the server. Everything observed lands in the * probe so the caller asserts after teardown. */

Source from the content-addressed store, hash-verified

1921 * /api/index-status and stop the server. Everything observed lands in the
1922 * probe so the caller asserts after teardown. */
1923static void th_ui_index_probe(th_ui_index_probe_t *probe, const char *root_path,
1924 const char *project_name) {
1925 memset(probe, 0, sizeof(*probe));
1926 atomic_init(&probe->executor.calls, 0);
1927 probe->status = -1;
1928 th_server_t ts;
1929 ts.srv = cbm_http_server_new(0);
1930 if (!ts.srv) {
1931 return;
1932 }
1933 cbm_http_server_set_index_executor(ts.srv, th_ui_index_executor, &probe->executor);
1934 if (th_server_thread_start(&ts.tid, ts.srv) != 0) {
1935 (void)cbm_http_server_free(ts.srv);
1936 return;
1937 }
1938 int port = cbm_http_server_port(ts.srv);
1939 char body[8192];
1940 snprintf(body, sizeof(body), "{\"root_path\":\"%s\",\"project_name\":\"%s\"}", root_path,
1941 project_name);
1942 char request[8192 + 256];
1943 snprintf(request, sizeof(request),
1944 "POST /api/index HTTP/1.1\r\nContent-Type: application/json\r\n"
1945 "Content-Length: %zu\r\n\r\n%s",
1946 strlen(body), body);
1947 if (th_http(port, request, probe->response, sizeof(probe->response)) > 0) {
1948 probe->status = th_status(probe->response);
1949 }
1950 if (probe->status == 202) {
1951 probe->executor_called = th_wait_atomic_int(&probe->executor.calls, 1, 2000);
1952 }
1953 char status_request[128];
1954 snprintf(status_request, sizeof(status_request),
1955 "GET /api/index-status HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n\r\n", port);
1956 (void)th_http(port, status_request, probe->index_status, sizeof(probe->index_status));
1957 th_server_stop(&ts);
1958}
1959
1960TEST(ui_server_index_start_refuses_root_outside_allowed) {
1961 char *tmp = th_mktempdir("cbm_httpd_index_bound");

Callers 1

test_httpd.cFile · 0.85

Calls 9

cbm_http_server_newFunction · 0.85
th_server_thread_startFunction · 0.85
cbm_http_server_freeFunction · 0.85
cbm_http_server_portFunction · 0.85
th_httpFunction · 0.85
th_statusFunction · 0.85
th_wait_atomic_intFunction · 0.85
th_server_stopFunction · 0.85

Tested by

no test coverage detected