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

Function idx853_supervised_autowatch_check

tests/test_mcp.c:22988–23060  ·  view source on GitHub ↗

helper used only by the POSIX fork harness below */

Source from the content-addressed store, hash-verified

22986
22987#ifndef _WIN32 /* helper used only by the POSIX fork harness below */
22988static int idx853_supervised_autowatch_check(const char *repo_dir, const char *cache_dir) {
22989 /* Become a supervisor host with the kill switch OFF — the real prod MCP
22990 * server's state. Done in the FORKED CHILD only (see harness) so the parent
22991 * test-runner's process-wide host mark stays clear (#845 invariant). Bound the
22992 * worker so a stuck spawn cannot run long under the fork+alarm net. */
22993 cbm_index_supervisor_mark_host();
22994 cbm_unsetenv("CBM_INDEX_SUPERVISOR");
22995 cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1);
22996 cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1);
22997
22998 cbm_config_t *cfg = cbm_config_open(cache_dir);
22999 cbm_store_t *wstore = cbm_store_open_memory();
23000 cbm_watcher_t *watcher = wstore ? cbm_watcher_new(wstore, NULL, NULL) : NULL;
23001 if (!cfg || !watcher) {
23002 if (watcher) {
23003 cbm_watcher_free(watcher);
23004 }
23005 if (wstore) {
23006 cbm_store_close(wstore);
23007 }
23008 if (cfg) {
23009 cbm_config_close(cfg);
23010 }
23011 return IDX853_SETUP_FAIL;
23012 }
23013 /* auto_index=true → maybe_auto_index launches autoindex_thread for the fresh
23014 * project; auto_watch=false → the gate this guard exercises. */
23015 cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true");
23016 cbm_config_set(cfg, CBM_CONFIG_AUTO_WATCH, "false");
23017
23018 /* detect_session derives session_root/session_project from the cwd. */
23019 char old_cwd[1024];
23020 if (!cbm_getcwd(old_cwd, sizeof(old_cwd)) || cbm_chdir(repo_dir) != 0) {
23021 cbm_watcher_free(watcher);
23022 cbm_store_close(wstore);
23023 cbm_config_close(cfg);
23024 return IDX853_SETUP_FAIL;
23025 }
23026
23027 int spawns_before = cbm_index_supervisor_spawn_count();
23028 int code = IDX853_SETUP_FAIL;
23029
23030 cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
23031 if (srv) {
23032 cbm_mcp_server_set_watcher(srv, watcher);
23033 cbm_mcp_server_set_config(srv, cfg);
23034 char *resp = cbm_mcp_server_handle(
23035 srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}");
23036 free(resp);
23037 /* free() joins the autoindex thread → the supervised worker has finished
23038 * and the registration decision (buggy or gated) has executed. */
23039 cbm_mcp_server_free(srv);
23040
23041 int spawns_after = cbm_index_supervisor_spawn_count();
23042 int watch_count = cbm_watcher_watch_count(watcher);
23043
23044 if (spawns_after == spawns_before) {
23045 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