Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
test(mcp): give the #1115 store-switch coverage its own test
Martin Vogel2e7244fe4ccf
diff --git a/tests/test_mcp.c b/tests/test_mcp.cindex 4b858250c..ce22116b8 100644--- a/tests/test_mcp.c+++ b/tests/test_mcp.c@@ -5914,7 +5914,7 @@ TEST(tool_query_graph_prefix_directory_recovers_rows_beyond_raw_estimate) {PASS();}-TEST(tool_list_projects_stays_complete_across_store_switches_issue1115) {+TEST(tool_list_projects_tree_uses_one_stable_header_and_keeps_json_direct) {char cache[256];snprintf(cache, sizeof(cache), "%s/cbm-list-lean-XXXXXX", cbm_tmpdir());ASSERT_NOT_NULL(cbm_mkdtemp(cache));@@ -5971,6 +5971,97 @@ TEST(tool_list_projects_stays_complete_across_store_switches_issue1115) {bool tree_not_duplicated = tree_response && !strstr(tree_response, "structuredContent");bool page_truthful = page && strstr(page, "projects: 5") && strstr(page, "returned: 5") &&strstr(page, "has_more: true") && strstr(page, "next_offset: 5");+ bool json_direct = false;+ bool json_structured = json_response && strstr(json_response, "structuredContent");+ yyjson_doc *doc = json ? yyjson_read(json, strlen(json), 0) : NULL;+ if (doc) {+ yyjson_val *projects = yyjson_obj_get(yyjson_doc_get_root(doc), "projects");+ yyjson_val *first = projects ? yyjson_arr_get_first(projects) : NULL;+ json_direct = projects && yyjson_arr_size(projects) == PROJECTS && first &&+ yyjson_obj_get(first, "name") && yyjson_obj_get(first, "root_path") &&+ yyjson_obj_get(first, "nodes") && yyjson_obj_get(first, "edges") &&+ yyjson_obj_get(first, "size_bytes") && !strstr(json, "rows_refs");+ yyjson_doc_free(doc);+ }++ free(identity);+ free(identity_response);+ free(tree);+ free(tree_response);+ free(json);+ free(json_response);+ free(page);+ free(page_response);+ cbm_mcp_server_free(srv);+ restore_cache_dir(saved_cache_copy);+ free(saved_cache_copy);+ for (int i = 0; i < PROJECTS; i++) {+ char project[32];+ snprintf(project, sizeof(project), "lean-project-%02d", i);+ cleanup_project_db(cache, project);+ }+ cbm_rmdir(cache);++ ASSERT_TRUE(tree_shape);+ ASSERT_TRUE(identity_lean);+ ASSERT_TRUE(tree_is_leaner);+ ASSERT_TRUE(tree_not_duplicated);+ ASSERT_TRUE(page_truthful);+ ASSERT_TRUE(json_direct);+ ASSERT_TRUE(json_structured);+ PASS();+}++/* #1115: with more indexed projects than were resident at once, the+ * least-recently-used one answered "project not found or not indexed" from+ * index_status, and list_projects and index_status disagreed in the same+ * session. The server keeps one project store open and switches it whenever a+ * call names another project, so twelve projects visited one after another+ * force a switch on every step and each visit is the first touch of a project+ * that is not resident. Every project must resolve through index_status and a+ * query, and list_projects must report all twelve before and after the+ * switches. */+TEST(tool_project_discovery_agrees_across_store_switches_issue1115) {+ char cache[256];+ snprintf(cache, sizeof(cache), "%s/cbm-switch-1115-XXXXXX", cbm_tmpdir());+ ASSERT_NOT_NULL(cbm_mkdtemp(cache));+ const char *saved_cache = getenv("CBM_CACHE_DIR");+ char *saved_cache_copy = saved_cache ? strdup(saved_cache) : NULL;+ cbm_setenv("CBM_CACHE_DIR", cache, 1);++ enum { PROJECTS = 12 };+ for (int i = 0; i < PROJECTS; i++) {+ char project[32];+ char db_path[512];+ char root_path[512];+ snprintf(project, sizeof(project), "lean-project-%02d", i);+ snprintf(db_path, sizeof(db_path), "%s/%s.db", cache, project);+ snprintf(root_path, sizeof(root_path),+ "/workspaces/organization/shared/services/lean-project-%02d", i);+ cbm_store_t *store = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(store);+ ASSERT_EQ(cbm_store_upsert_project(store, project, root_path), CBM_STORE_OK);+ cbm_node_t node = {.project = project,+ .label = "Function",+ .name = "entry",+ .qualified_name = "shared.module.entry",+ .file_path = "src/main.c",+ .start_line = 1,+ .end_line = 1};+ ASSERT_GT(cbm_store_upsert_node(store, &node), 0);+ cbm_store_close(store);+ }++ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);+ ASSERT_NOT_NULL(srv);+ char *pre_switch_response = cbm_mcp_handle_tool(srv, "list_projects", "{\"limit\":50}");+ char *pre_switch = extract_text_content(pre_switch_response);+ bool list_complete_before_switches = pre_switch && strstr(pre_switch, "total: 12") &&+ strstr(pre_switch, "lean-project-00") &&+ strstr(pre_switch, "lean-project-11");+ free(pre_switch);+ free(pre_switch_response);+bool projects_resolve_after_switches = true;for (int i = PROJECTS - 1; i >= 0; i--) {char project[32];@@ -5986,8 +6077,7 @@ TEST(tool_list_projects_stays_complete_across_store_switches_issue1115) {free(status);free(status_response);- snprintf(args, sizeof(args), "{\"project\":\"%s\",\"name_pattern\":\"entry\"}",- project);+ snprintf(args, sizeof(args), "{\"project\":\"%s\",\"name_pattern\":\"entry\"}", project);char *search_response = cbm_mcp_handle_tool(srv, "search_graph", args);char *search = extract_text_content(search_response);if (!search || !strstr(search, "entry")) {@@ -5998,32 +6088,12 @@ TEST(tool_list_projects_stays_complete_across_store_switches_issue1115) {}char *post_switch_response = cbm_mcp_handle_tool(srv, "list_projects", "{\"limit\":50}");char *post_switch = extract_text_content(post_switch_response);- bool list_complete_after_switches =- post_switch && strstr(post_switch, "total: 12") && strstr(post_switch, "lean-project-00") &&- strstr(post_switch, "lean-project-11");+ bool list_complete_after_switches = post_switch && strstr(post_switch, "total: 12") &&+ strstr(post_switch, "lean-project-00") &&+ strstr(post_switch, "lean-project-11");free(post_switch);free(post_switch_response);- bool json_direct = false;- bool json_structured = json_response && strstr(json_response, "structuredContent");- yyjson_doc *doc = json ? yyjson_read(json, strlen(json), 0) : NULL;- if (doc) {- yyjson_val *projects = yyjson_obj_get(yyjson_doc_get_root(doc), "projects");- yyjson_val *first = projects ? yyjson_arr_get_first(projects) : NULL;- json_direct = projects && yyjson_arr_size(projects) == PROJECTS && first &&- yyjson_obj_get(first, "name") && yyjson_obj_get(first, "root_path") &&- yyjson_obj_get(first, "nodes") && yyjson_obj_get(first, "edges") &&- yyjson_obj_get(first, "size_bytes") && !strstr(json, "rows_refs");- yyjson_doc_free(doc);- }- free(identity);- free(identity_response);- free(tree);- free(tree_response);- free(json);- free(json_response);- free(page);- free(page_response);cbm_mcp_server_free(srv);restore_cache_dir(saved_cache_copy);free(saved_cache_copy);@@ -6034,15 +6104,9 @@ TEST(tool_list_projects_stays_complete_across_store_switches_issue1115) {}cbm_rmdir(cache);- ASSERT_TRUE(tree_shape);- ASSERT_TRUE(identity_lean);- ASSERT_TRUE(tree_is_leaner);- ASSERT_TRUE(tree_not_duplicated);- ASSERT_TRUE(page_truthful);+ ASSERT_TRUE(list_complete_before_switches);ASSERT_TRUE(projects_resolve_after_switches);ASSERT_TRUE(list_complete_after_switches);- ASSERT_TRUE(json_direct);- ASSERT_TRUE(json_structured);PASS();}@@ -25105,7 +25169,8 @@ SUITE(mcp) {RUN_TEST(tool_query_graph_budget_bounds_first_row_and_json_escaping);RUN_TEST(tool_query_graph_prefix_directory_is_lossless_and_json_stays_direct);RUN_TEST(tool_query_graph_prefix_directory_recovers_rows_beyond_raw_estimate);- RUN_TEST(tool_list_projects_stays_complete_across_store_switches_issue1115);+ RUN_TEST(tool_list_projects_tree_uses_one_stable_header_and_keeps_json_direct);+ RUN_TEST(tool_project_discovery_agrees_across_store_switches_issue1115);RUN_TEST(tool_list_projects_preserves_root_beyond_one_kib);RUN_TEST(tool_index_status_no_project);RUN_TEST(tool_ingest_traces_stores_observed_calls);