helper used only by the POSIX fork harness below */
| 21869 | |
| 21870 | #ifndef _WIN32 /* helper used only by the POSIX fork harness below */ |
| 21871 | static int idx832_supervised_route_check(const char *repo_dir) { |
| 21872 | /* Become a supervisor host with the kill switch OFF — exactly the real MCP |
| 21873 | * server's state. Done in the FORKED CHILD only (see the harness) so the |
| 21874 | * parent test-runner's process-wide host mark stays clear and the #845 |
| 21875 | * unmarked-embedder guard is unaffected. Bound the recovery loop + worker |
| 21876 | * quiet-timeout so a stuck child cannot run long under the fork+alarm net. */ |
| 21877 | cbm_index_supervisor_mark_host(); |
| 21878 | cbm_unsetenv("CBM_INDEX_SUPERVISOR"); |
| 21879 | cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1); |
| 21880 | cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1); |
| 21881 | |
| 21882 | int spawns_before = cbm_index_supervisor_spawn_count(); |
| 21883 | char *resp = cbm_mcp_index_run_supervised_path(repo_dir); |
| 21884 | int spawns_after = cbm_index_supervisor_spawn_count(); |
| 21885 | |
| 21886 | if (spawns_after == spawns_before) { |
| 21887 | free(resp); |
| 21888 | return IDX832_NO_SPAWN; /* the discriminating assertion: RED in-process */ |
| 21889 | } |
| 21890 | if (!resp) { |
| 21891 | return IDX832_NULL_RESP; |
| 21892 | } |
| 21893 | bool indexed = response_contains_json_fragment(resp, "\"status\":\"indexed\""); |
| 21894 | free(resp); |
| 21895 | if (!indexed) { |
| 21896 | return IDX832_NOT_INDEXED; |
| 21897 | } |
| 21898 | |
| 21899 | /* Store-level proof the worker child did real work: the Function node it wrote |
| 21900 | * must be queryable from a fresh server reading the DB the child produced. */ |
| 21901 | char *project = cbm_project_name_from_path(repo_dir); |
| 21902 | cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL); |
| 21903 | if (!srv) { |
| 21904 | free(project); |
| 21905 | return IDX832_SERVER_FAIL; |
| 21906 | } |
| 21907 | int code = IDX832_OK; |
| 21908 | if (project) { |
| 21909 | char q[512]; |
| 21910 | snprintf(q, sizeof(q), |
| 21911 | "{\"project\":\"%s\",\"name_pattern\":\"idx832_fn\",\"label\":\"Function\"}", |
| 21912 | project); |
| 21913 | char *sr = cbm_mcp_handle_tool(srv, "search_graph", q); |
| 21914 | if (!sr || !strstr(sr, "idx832_fn")) { |
| 21915 | code = IDX832_NOT_INDEXED; |
| 21916 | } |
| 21917 | free(sr); |
| 21918 | } |
| 21919 | cbm_mcp_server_free(srv); |
| 21920 | free(project); |
| 21921 | return code; |
| 21922 | } |
| 21923 | #endif /* !_WIN32 */ |
| 21924 | |
| 21925 | TEST(index_bg_paths_route_through_supervisor_issue832) { |
no test coverage detected