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

Function idx853_supervised_autowatch_check

tests/test_mcp.c:10007–10079  ·  view source on GitHub ↗

helper used only by the POSIX fork harness below */

Source from the content-addressed store, hash-verified

10005
10006#ifndef _WIN32 /* helper used only by the POSIX fork harness below */
10007static int idx853_supervised_autowatch_check(const char *repo_dir, const char *cache_dir) {
10008 /* Become a supervisor host with the kill switch OFF — the real prod MCP
10009 * server's state. Done in the FORKED CHILD only (see harness) so the parent
10010 * test-runner's process-wide host mark stays clear (#845 invariant). Bound the
10011 * worker so a stuck spawn cannot run long under the fork+alarm net. */
10012 cbm_index_supervisor_mark_host();
10013 cbm_unsetenv("CBM_INDEX_SUPERVISOR");
10014 cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1);
10015 cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1);
10016
10017 cbm_config_t *cfg = cbm_config_open(cache_dir);
10018 cbm_store_t *wstore = cbm_store_open_memory();
10019 cbm_watcher_t *watcher = wstore ? cbm_watcher_new(wstore, NULL, NULL) : NULL;
10020 if (!cfg || !watcher) {
10021 if (watcher) {
10022 cbm_watcher_free(watcher);
10023 }
10024 if (wstore) {
10025 cbm_store_close(wstore);
10026 }
10027 if (cfg) {
10028 cbm_config_close(cfg);
10029 }
10030 return IDX853_SETUP_FAIL;
10031 }
10032 /* auto_index=true → maybe_auto_index launches autoindex_thread for the fresh
10033 * project; auto_watch=false → the gate this guard exercises. */
10034 cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true");
10035 cbm_config_set(cfg, CBM_CONFIG_AUTO_WATCH, "false");
10036
10037 /* detect_session derives session_root/session_project from the cwd. */
10038 char old_cwd[1024];
10039 if (!cbm_getcwd(old_cwd, sizeof(old_cwd)) || cbm_chdir(repo_dir) != 0) {
10040 cbm_watcher_free(watcher);
10041 cbm_store_close(wstore);
10042 cbm_config_close(cfg);
10043 return IDX853_SETUP_FAIL;
10044 }
10045
10046 int spawns_before = cbm_index_supervisor_spawn_count();
10047 int code = IDX853_SETUP_FAIL;
10048
10049 cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
10050 if (srv) {
10051 cbm_mcp_server_set_watcher(srv, watcher);
10052 cbm_mcp_server_set_config(srv, cfg);
10053 char *resp = cbm_mcp_server_handle(
10054 srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}");
10055 free(resp);
10056 /* free() joins the autoindex thread → the supervised worker has finished
10057 * and the registration decision (buggy or gated) has executed. */
10058 cbm_mcp_server_free(srv);
10059
10060 int spawns_after = cbm_index_supervisor_spawn_count();
10061 int watch_count = cbm_watcher_watch_count(watcher);
10062
10063 if (spawns_after == spawns_before) {
10064 code = IDX853_NO_SPAWN; /* supervised branch never ran — not a valid probe */

Callers 1

test_mcp.cFile · 0.85

Calls 15

cbm_unsetenvFunction · 0.85
cbm_setenvFunction · 0.85
cbm_config_openFunction · 0.85
cbm_store_open_memoryFunction · 0.85
cbm_watcher_newFunction · 0.85
cbm_watcher_freeFunction · 0.85
cbm_store_closeFunction · 0.85
cbm_config_closeFunction · 0.85
cbm_config_setFunction · 0.85
cbm_mcp_server_newFunction · 0.85

Tested by

no test coverage detected