helper used only by the POSIX fork harness below */
| 9857 | |
| 9858 | #ifndef _WIN32 /* helper used only by the POSIX fork harness below */ |
| 9859 | static int idx853_supervised_autowatch_check(const char *repo_dir, const char *cache_dir) { |
| 9860 | /* Become a supervisor host with the kill switch OFF — the real prod MCP |
| 9861 | * server's state. Done in the FORKED CHILD only (see harness) so the parent |
| 9862 | * test-runner's process-wide host mark stays clear (#845 invariant). Bound the |
| 9863 | * worker so a stuck spawn cannot run long under the fork+alarm net. */ |
| 9864 | cbm_index_supervisor_mark_host(); |
| 9865 | cbm_unsetenv("CBM_INDEX_SUPERVISOR"); |
| 9866 | cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1); |
| 9867 | cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1); |
| 9868 | |
| 9869 | cbm_config_t *cfg = cbm_config_open(cache_dir); |
| 9870 | cbm_store_t *wstore = cbm_store_open_memory(); |
| 9871 | cbm_watcher_t *watcher = wstore ? cbm_watcher_new(wstore, NULL, NULL) : NULL; |
| 9872 | if (!cfg || !watcher) { |
| 9873 | if (watcher) { |
| 9874 | cbm_watcher_free(watcher); |
| 9875 | } |
| 9876 | if (wstore) { |
| 9877 | cbm_store_close(wstore); |
| 9878 | } |
| 9879 | if (cfg) { |
| 9880 | cbm_config_close(cfg); |
| 9881 | } |
| 9882 | return IDX853_SETUP_FAIL; |
| 9883 | } |
| 9884 | /* auto_index=true → maybe_auto_index launches autoindex_thread for the fresh |
| 9885 | * project; auto_watch=false → the gate this guard exercises. */ |
| 9886 | cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true"); |
| 9887 | cbm_config_set(cfg, CBM_CONFIG_AUTO_WATCH, "false"); |
| 9888 | |
| 9889 | /* detect_session derives session_root/session_project from the cwd. */ |
| 9890 | char old_cwd[1024]; |
| 9891 | if (!cbm_getcwd(old_cwd, sizeof(old_cwd)) || cbm_chdir(repo_dir) != 0) { |
| 9892 | cbm_watcher_free(watcher); |
| 9893 | cbm_store_close(wstore); |
| 9894 | cbm_config_close(cfg); |
| 9895 | return IDX853_SETUP_FAIL; |
| 9896 | } |
| 9897 | |
| 9898 | int spawns_before = cbm_index_supervisor_spawn_count(); |
| 9899 | int code = IDX853_SETUP_FAIL; |
| 9900 | |
| 9901 | cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL); |
| 9902 | if (srv) { |
| 9903 | cbm_mcp_server_set_watcher(srv, watcher); |
| 9904 | cbm_mcp_server_set_config(srv, cfg); |
| 9905 | char *resp = cbm_mcp_server_handle( |
| 9906 | srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}"); |
| 9907 | free(resp); |
| 9908 | /* free() joins the autoindex thread → the supervised worker has finished |
| 9909 | * and the registration decision (buggy or gated) has executed. */ |
| 9910 | cbm_mcp_server_free(srv); |
| 9911 | |
| 9912 | int spawns_after = cbm_index_supervisor_spawn_count(); |
| 9913 | int watch_count = cbm_watcher_watch_count(watcher); |
| 9914 | |
| 9915 | if (spawns_after == spawns_before) { |
| 9916 | code = IDX853_NO_SPAWN; /* supervised branch never ran — not a valid probe */ |
no test coverage detected