helper used only by the POSIX fork harness below */
| 9181 | |
| 9182 | #ifndef _WIN32 /* helper used only by the POSIX fork harness below */ |
| 9183 | static int idx832_supervised_route_check(const char *repo_dir) { |
| 9184 | /* Become a supervisor host with the kill switch OFF — exactly the real MCP |
| 9185 | * server's state. Done in the FORKED CHILD only (see the harness) so the |
| 9186 | * parent test-runner's process-wide host mark stays clear and the #845 |
| 9187 | * unmarked-embedder guard is unaffected. Bound the recovery loop + worker |
| 9188 | * quiet-timeout so a stuck child cannot run long under the fork+alarm net. */ |
| 9189 | cbm_index_supervisor_mark_host(); |
| 9190 | cbm_unsetenv("CBM_INDEX_SUPERVISOR"); |
| 9191 | cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1); |
| 9192 | cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1); |
| 9193 | |
| 9194 | int spawns_before = cbm_index_supervisor_spawn_count(); |
| 9195 | char *resp = cbm_mcp_index_run_supervised_path(repo_dir); |
| 9196 | int spawns_after = cbm_index_supervisor_spawn_count(); |
| 9197 | |
| 9198 | if (spawns_after == spawns_before) { |
| 9199 | free(resp); |
| 9200 | return IDX832_NO_SPAWN; /* the discriminating assertion: RED in-process */ |
| 9201 | } |
| 9202 | if (!resp) { |
| 9203 | return IDX832_NULL_RESP; |
| 9204 | } |
| 9205 | bool indexed = response_contains_json_fragment(resp, "\"status\":\"indexed\""); |
| 9206 | free(resp); |
| 9207 | if (!indexed) { |
| 9208 | return IDX832_NOT_INDEXED; |
| 9209 | } |
| 9210 | |
| 9211 | /* Store-level proof the worker child did real work: the Function node it wrote |
| 9212 | * must be queryable from a fresh server reading the DB the child produced. */ |
| 9213 | char *project = cbm_project_name_from_path(repo_dir); |
| 9214 | cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL); |
| 9215 | if (!srv) { |
| 9216 | free(project); |
| 9217 | return IDX832_SERVER_FAIL; |
| 9218 | } |
| 9219 | int code = IDX832_OK; |
| 9220 | if (project) { |
| 9221 | char q[512]; |
| 9222 | snprintf(q, sizeof(q), |
| 9223 | "{\"project\":\"%s\",\"name_pattern\":\"idx832_fn\",\"label\":\"Function\"}", |
| 9224 | project); |
| 9225 | char *sr = cbm_mcp_handle_tool(srv, "search_graph", q); |
| 9226 | if (!sr || !strstr(sr, "idx832_fn")) { |
| 9227 | code = IDX832_NOT_INDEXED; |
| 9228 | } |
| 9229 | free(sr); |
| 9230 | } |
| 9231 | cbm_mcp_server_free(srv); |
| 9232 | free(project); |
| 9233 | return code; |
| 9234 | } |
| 9235 | #endif /* !_WIN32 */ |
| 9236 | |
| 9237 | TEST(index_bg_paths_route_through_supervisor_issue832) { |
no test coverage detected