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

Function idx853_supervised_autowatch_check

tests/test_mcp.c:9766–9838  ·  view source on GitHub ↗

helper used only by the POSIX fork harness below */

Source from the content-addressed store, hash-verified

9764
9765#ifndef _WIN32 /* helper used only by the POSIX fork harness below */
9766static int idx853_supervised_autowatch_check(const char *repo_dir, const char *cache_dir) {
9767 /* Become a supervisor host with the kill switch OFF — the real prod MCP
9768 * server's state. Done in the FORKED CHILD only (see harness) so the parent
9769 * test-runner's process-wide host mark stays clear (#845 invariant). Bound the
9770 * worker so a stuck spawn cannot run long under the fork+alarm net. */
9771 cbm_index_supervisor_mark_host();
9772 cbm_unsetenv("CBM_INDEX_SUPERVISOR");
9773 cbm_setenv("CBM_INDEX_MAX_RESTARTS", "1", 1);
9774 cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "30", 1);
9775
9776 cbm_config_t *cfg = cbm_config_open(cache_dir);
9777 cbm_store_t *wstore = cbm_store_open_memory();
9778 cbm_watcher_t *watcher = wstore ? cbm_watcher_new(wstore, NULL, NULL) : NULL;
9779 if (!cfg || !watcher) {
9780 if (watcher) {
9781 cbm_watcher_free(watcher);
9782 }
9783 if (wstore) {
9784 cbm_store_close(wstore);
9785 }
9786 if (cfg) {
9787 cbm_config_close(cfg);
9788 }
9789 return IDX853_SETUP_FAIL;
9790 }
9791 /* auto_index=true → maybe_auto_index launches autoindex_thread for the fresh
9792 * project; auto_watch=false → the gate this guard exercises. */
9793 cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true");
9794 cbm_config_set(cfg, CBM_CONFIG_AUTO_WATCH, "false");
9795
9796 /* detect_session derives session_root/session_project from the cwd. */
9797 char old_cwd[1024];
9798 if (!cbm_getcwd(old_cwd, sizeof(old_cwd)) || cbm_chdir(repo_dir) != 0) {
9799 cbm_watcher_free(watcher);
9800 cbm_store_close(wstore);
9801 cbm_config_close(cfg);
9802 return IDX853_SETUP_FAIL;
9803 }
9804
9805 int spawns_before = cbm_index_supervisor_spawn_count();
9806 int code = IDX853_SETUP_FAIL;
9807
9808 cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
9809 if (srv) {
9810 cbm_mcp_server_set_watcher(srv, watcher);
9811 cbm_mcp_server_set_config(srv, cfg);
9812 char *resp = cbm_mcp_server_handle(
9813 srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}");
9814 free(resp);
9815 /* free() joins the autoindex thread → the supervised worker has finished
9816 * and the registration decision (buggy or gated) has executed. */
9817 cbm_mcp_server_free(srv);
9818
9819 int spawns_after = cbm_index_supervisor_spawn_count();
9820 int watch_count = cbm_watcher_watch_count(watcher);
9821
9822 if (spawns_after == spawns_before) {
9823 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