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

Function idx832_supervised_route_check

tests/test_mcp.c:9090–9141  ·  view source on GitHub ↗

helper used only by the POSIX fork harness below */

Source from the content-addressed store, hash-verified

9088
9089#ifndef _WIN32 /* helper used only by the POSIX fork harness below */
9090static int idx832_supervised_route_check(const char *repo_dir) {
9091 /* Become a supervisor host with the kill switch OFF — exactly the real MCP
9092 * server's state. Done in the FORKED CHILD only (see the harness) so the
9093 * parent test-runner's process-wide host mark stays clear and the #845
9094 * unmarked-embedder guard is unaffected. Bound the recovery loop + worker
9095 * quiet-timeout so a stuck child cannot run long under the fork+alarm net. */
9096 cbm_index_supervisor_mark_host();
9097 cbm_unsetenv("CBM_INDEX_SUPERVISOR");
9098 cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1);
9099 cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1);
9100
9101 int spawns_before = cbm_index_supervisor_spawn_count();
9102 char *resp = cbm_mcp_index_run_supervised_path(repo_dir);
9103 int spawns_after = cbm_index_supervisor_spawn_count();
9104
9105 if (spawns_after == spawns_before) {
9106 free(resp);
9107 return IDX832_NO_SPAWN; /* the discriminating assertion: RED in-process */
9108 }
9109 if (!resp) {
9110 return IDX832_NULL_RESP;
9111 }
9112 bool indexed = response_contains_json_fragment(resp, "\"status\":\"indexed\"");
9113 free(resp);
9114 if (!indexed) {
9115 return IDX832_NOT_INDEXED;
9116 }
9117
9118 /* Store-level proof the worker child did real work: the Function node it wrote
9119 * must be queryable from a fresh server reading the DB the child produced. */
9120 char *project = cbm_project_name_from_path(repo_dir);
9121 cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
9122 if (!srv) {
9123 free(project);
9124 return IDX832_SERVER_FAIL;
9125 }
9126 int code = IDX832_OK;
9127 if (project) {
9128 char q[512];
9129 snprintf(q, sizeof(q),
9130 "{\"project\":\"%s\",\"name_pattern\":\"idx832_fn\",\"label\":\"Function\"}",
9131 project);
9132 char *sr = cbm_mcp_handle_tool(srv, "search_graph", q);
9133 if (!sr || !strstr(sr, "idx832_fn")) {
9134 code = IDX832_NOT_INDEXED;
9135 }
9136 free(sr);
9137 }
9138 cbm_mcp_server_free(srv);
9139 free(project);
9140 return code;
9141}
9142#endif /* !_WIN32 */
9143
9144TEST(index_bg_paths_route_through_supervisor_issue832) {

Callers 1

test_mcp.cFile · 0.85

Calls 10

cbm_unsetenvFunction · 0.85
cbm_setenvFunction · 0.85
cbm_mcp_server_newFunction · 0.85
cbm_mcp_handle_toolFunction · 0.85
cbm_mcp_server_freeFunction · 0.85

Tested by

no test coverage detected