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

Function issue403_initialize_count_calls

tests/test_mcp.c:1959–1998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1957}
1958
1959static int issue403_initialize_count_calls(const char *session_root, bool approve_sensitive) {
1960 char *cache = th_mktempdir("cbm_mcp_403");
1961 if (!cache) {
1962 return -1;
1963 }
1964 const char *saved_cache = getenv("CBM_CACHE_DIR");
1965 char *saved_cache_copy = saved_cache ? strdup(saved_cache) : NULL;
1966 cbm_setenv("CBM_CACHE_DIR", cache, 1);
1967
1968 char err[1024];
1969 bool approved =
1970 !approve_sensitive || cbm_workspace_grant_add(cache, cbm_workspace_home_dir(), session_root,
1971 true, err, sizeof(err));
1972 cbm_config_t *cfg = approved ? cbm_config_open(cache) : NULL;
1973 cbm_mcp_server_t *srv = cfg ? cbm_mcp_server_new(NULL) : NULL;
1974 int calls = -2;
1975 if (srv) {
1976 cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX, "true");
1977 /* The hook proves entry to the count path; keep the actual discovery
1978 * call fail-closed so this unit test can never launch an index thread. */
1979 cbm_config_set(cfg, CBM_CONFIG_AUTO_INDEX_LIMIT, "-1");
1980 if (cbm_mcp_server_set_session_context(srv, session_root, NULL)) {
1981 calls = 0;
1982 cbm_mcp_server_set_config(srv, cfg);
1983 cbm_mcp_server_set_auto_index_count_test_hook(srv, issue403_count_started, &calls);
1984 char *response = cbm_mcp_server_handle(
1985 srv, "{\"jsonrpc\":\"2.0\",\"id\":403,\"method\":\"initialize\",\"params\":{}}");
1986 free(response);
1987 }
1988 cbm_mcp_server_free(srv);
1989 }
1990 if (cfg) {
1991 cbm_config_close(cfg);
1992 }
1993
1994 restore_cache_dir(saved_cache_copy);
1995 free(saved_cache_copy);
1996 th_cleanup(cache);
1997 return calls;
1998}
1999
2000TEST(mcp_issue403_sensitive_root_stops_before_discovery_count) {
2001 int sensitive =

Callers 1

test_mcp.cFile · 0.85

Calls 15

th_mktempdirFunction · 0.85
cbm_setenvFunction · 0.85
cbm_workspace_grant_addFunction · 0.85
cbm_workspace_home_dirFunction · 0.85
cbm_config_openFunction · 0.85
cbm_mcp_server_newFunction · 0.85
cbm_config_setFunction · 0.85
cbm_mcp_server_handleFunction · 0.85
cbm_mcp_server_freeFunction · 0.85

Tested by

no test coverage detected