test(mcp): cover classic-mode tools list (CBM_TOOL_MODE=classic)

The merged cbm_mcp_tools_list (src/mcp/mcp.c:868) defaults to streamlined mode
when srv is NULL, so tests/test_mcp.c:mcp_tools_list only exercised the 3
consolidated tools. The classic-mode path (CBM_TOOL_MODE=classic, mcp.c:876)
that emits all 15 TOOLS[] split tools had no test — the MERGE-TODO flagged at
tests/test_mcp.c:172.

Add mcp_tools_list_classic_mode: setenv("CBM_TOOL_MODE","classic"), capture the
list, then unsetenv BEFORE any ASSERT so a failed assertion cannot leak the
classic setting into sibling tests (which expect the streamlined default). Assert
the classic split tools (index_repository, search_graph, query_graph) are present
and the streamlined-only consolidated search_code_graph + the _hidden_tools
progressive-disclosure hint are absent. Registered in suite_mcp.

Full suite: 5981 passed / 2 failed (the 2 are the deferred B1 incremental races,
unrelated to this test).

Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
This commit is contained in:
Andrew Hundt
2026-06-24 18:01:42 -04:00
parent e494cee91a
commit aff5df33f9
+23
View File
@@ -185,6 +185,28 @@ TEST(mcp_tools_list) {
PASS();
}
TEST(mcp_tools_list_classic_mode) {
/* Classic mode (CBM_TOOL_MODE=classic) emits the original 15 split tools,
* not the streamlined consolidated set. The env var is read at call time
* (src/mcp/mcp.c:870), so set it, capture the list, then unset it BEFORE any
* ASSERT — a failed assert must not leak the classic setting into sibling
* tests (which expect the streamlined default). */
setenv("CBM_TOOL_MODE", "classic", 1);
char *json = cbm_mcp_tools_list(NULL);
unsetenv("CBM_TOOL_MODE");
ASSERT_NOT_NULL(json);
/* Classic split tools are present (TOOLS[] in mcp.c). */
ASSERT_NOT_NULL(strstr(json, "\"index_repository\""));
ASSERT_NOT_NULL(strstr(json, "\"search_graph\""));
ASSERT_NOT_NULL(strstr(json, "\"query_graph\""));
/* The streamlined-only consolidated tool + progressive-disclosure hint are
* NOT emitted in classic mode. */
ASSERT_NULL(strstr(json, "\"search_code_graph\""));
ASSERT_NULL(strstr(json, "_hidden_tools"));
free(json);
PASS();
}
TEST(mcp_tools_array_schemas_have_items) {
/* VS Code 1.112+ rejects array schemas without "items" (see
* https://github.com/microsoft/vscode/issues/248810).
@@ -2269,6 +2291,7 @@ SUITE(mcp) {
/* MCP protocol helpers */
RUN_TEST(mcp_initialize_response);
RUN_TEST(mcp_tools_list);
RUN_TEST(mcp_tools_list_classic_mode);
RUN_TEST(mcp_tools_array_schemas_have_items);
RUN_TEST(mcp_text_result);
RUN_TEST(mcp_text_result_error);