helper used only by the POSIX fork harness below */
| 4729 | |
| 4730 | #ifndef _WIN32 /* helper used only by the POSIX fork harness below */ |
| 4731 | static int idx853_supervised_autowatch_check(const char *repo_dir, const char *cache_dir) { |
| 4732 | /* Become a supervisor host with the kill switch OFF — the real prod MCP |
| 4733 | * server's state. Done in the FORKED CHILD only (see harness) so the parent |
| 4734 | * test-runner's process-wide host mark stays clear (#845 invariant). Bound the |
| 4735 | * worker so a stuck spawn cannot run long under the fork+alarm net. */ |
| 4736 | cbm_index_supervisor_mark_host(); |
| 4737 | cbm_unsetenv("CBM_INDEX_SUPERVISOR"); |
| 4738 | cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1); |
| 4739 | cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1); |
| 4740 | |
| 4741 | cbm_config_t *cfg = cbm_config_open(cache_dir); |
| 4742 | cbm_store_t *wstore = cbm_store_open_memory(); |
| 4743 | cbm_watcher_t *watcher = wstore ? cbm_watcher_new(wstore, NULL, NULL) : NULL; |
| 4744 | if (!cfg || !watcher) { |
| 4745 | if (watcher) { |
| 4746 | cbm_watcher_free(watcher); |
| 4747 | } |
| 4748 | if (wstore) { |
| 4749 | cbm_store_close(wstore); |
| 4750 | } |
| 4751 | if (cfg) { |
| 4752 | cbm_config_close(cfg); |
| 4753 | } |
| 4754 | return IDX853_SETUP_FAIL; |
| 4755 | } |
| 4756 | /* auto_index=true → maybe_auto_index launches autoindex_thread for the fresh |
| 4757 | * project; auto_watch=false → the gate this guard exercises. */ |
| 4758 | cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true"); |
| 4759 | cbm_config_set(cfg, CBM_CONFIG_AUTO_WATCH, "false"); |
| 4760 | |
| 4761 | /* detect_session derives session_root/session_project from the cwd. */ |
| 4762 | char old_cwd[1024]; |
| 4763 | if (!cbm_getcwd(old_cwd, sizeof(old_cwd)) || cbm_chdir(repo_dir) != 0) { |
| 4764 | cbm_watcher_free(watcher); |
| 4765 | cbm_store_close(wstore); |
| 4766 | cbm_config_close(cfg); |
| 4767 | return IDX853_SETUP_FAIL; |
| 4768 | } |
| 4769 | |
| 4770 | int spawns_before = cbm_index_supervisor_spawn_count(); |
| 4771 | int code = IDX853_SETUP_FAIL; |
| 4772 | |
| 4773 | cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL); |
| 4774 | if (srv) { |
| 4775 | cbm_mcp_server_set_watcher(srv, watcher); |
| 4776 | cbm_mcp_server_set_config(srv, cfg); |
| 4777 | char *resp = cbm_mcp_server_handle( |
| 4778 | srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}"); |
| 4779 | free(resp); |
| 4780 | /* free() joins the autoindex thread → the supervised worker has finished |
| 4781 | * and the registration decision (buggy or gated) has executed. */ |
| 4782 | cbm_mcp_server_free(srv); |
| 4783 | |
| 4784 | int spawns_after = cbm_index_supervisor_spawn_count(); |
| 4785 | int watch_count = cbm_watcher_watch_count(watcher); |
| 4786 | |
| 4787 | if (spawns_after == spawns_before) { |
| 4788 | code = IDX853_NO_SPAWN; /* supervised branch never ran — not a valid probe */ |
no test coverage detected