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
fix(mcp): settle the lean-output branch on current main
Martin Vogel619c68348075
diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.shindex 094078ebc..b93a1f8a3 100755--- a/scripts/smoke-test.sh+++ b/scripts/smoke-test.sh@@ -842,7 +842,7 @@ fi# B4: STDIN + --json is the generated-client transport. It must return the# complete MCP result envelope and must NOT emit a deprecation warning.-IM_STDIN=$(printf '%s' "{\"project\":\"$PROJECT\"}" | "$BINARY" cli --json get_graph_schema 2>"$CLI_STDERR")+IM_STDIN=$(printf '%s' "{\"project\":\"$PROJECT\",\"format\":\"json\"}" | "$BINARY" cli --json get_graph_schema 2>"$CLI_STDERR")if ! printf '%s' "$IM_STDIN" | python3 -c "import json,sys; d=json.loads(sys.stdin.read()); c=d.get('content'); p=json.loads(c[0].get('text','')) if isinstance(c,list) and c and c[0].get('type') == 'text' else None; sys.exit(0 if d.get('isError') is not True and isinstance(p,dict) and isinstance(p.get('node_labels'),list) else 1)" 2>/dev/null; thenecho "FAIL B4: compact stdin + --json did not return a successful get_graph_schema MCP payload"; echo "$IM_STDIN" | head -c 300; cat "$CLI_STDERR"; exit 1fidiff --git a/src/cypher/cypher.c b/src/cypher/cypher.cindex 0a0f60c1b..74a827db9 100644--- a/src/cypher/cypher.c+++ b/src/cypher/cypher.c@@ -3241,6 +3241,10 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,* clamp — never a silent truncation. */int depth_cap = cbm_cypher_max_depth();int max_depth = rel->max_hops > 0 ? rel->max_hops : depth_cap;+ /* A range clamped to the engine ceiling (or an unbounded one) is probed one+ * hop beyond it: a candidate out there means the clamp hid real rows, so the+ * result is reported truncated; a clamp on a shallow graph stays a warning. */+ bool probe_beyond_depth_cap = rel->max_hops <= 0 || max_depth > depth_cap;if (max_depth > depth_cap) {char req_buf[16];char cap_buf[16];@@ -3252,8 +3256,9 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,}cbm_traverse_result_t tr = {0};const char *dir = rel->direction ? rel->direction : "outbound";- cbm_store_bfs_trail(store, src->id, dir, rel->types, rel->type_count, max_depth, CBM_PERCENT,- &tr);+ int traversal_depth = probe_beyond_depth_cap ? depth_cap + SKIP_ONE : max_depth;+ cbm_store_bfs_trail(store, src->id, dir, rel->types, rel->type_count, traversal_depth,+ CBM_PERCENT, &tr);if (tr.truncated) {g_cypher_trail_truncated = 1;}@@ -3264,6 +3269,10 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,* fabricated OPTIONAL "no match" row. */for (int v = 0; v < tr.visited_count; v++) {cbm_node_hop_t *hop = &tr.visited[v];+ if (hop->hop > max_depth) {+ g_cypher_truncated = true; /* the probe hop found a candidate past the cap */+ continue;+ }if (hop->hop < rel->min_hops) {continue;}@@ -5291,6 +5300,8 @@ int cbm_cypher_execute(cbm_store_t *store, const char *query, const char *projecout->col_count = rb.col_count;out->rows = rb.rows;out->row_count = rb.row_count;+ /* Any internal ceiling that prevented exhaustive evaluation: a candidate or+ * traversal budget, or a variable-length range clamped to the engine cap. */out->truncated = g_cypher_truncated || g_cypher_trail_truncated != 0;if (g_cypher_depth_clamped > 0 || g_cypher_trail_truncated) {char wbuf[CBM_SZ_256];diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex f2772835a..3259221c4 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -580,10 +580,8 @@ static const tool_def_t TOOLS[] = {"\"required\":[\"qualified_name\",\"project\"]}"},{"get_file_outline",- "Return a compact declaration outline for one exact repository-relative file. Results are "- "filtered by optional exact labels, ordered deterministically by source position, and "- "bounded with exact total/offset/limit pagination metadata. File/folder/container nodes "- "are excluded. The query observes request cancellation and fails without partial output.",+ "Declaration outline of one exact repository-relative file: optional exact label filter, "+ "source order, exact total/offset/limit paging; file/folder/container nodes excluded.","{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},""\"file_path\":{\"type\":\"string\",\"description\":\"Exact repository-relative ""file path\"},\"labels\":{\"type\":\"array\",\"items\":{\"type\":\"string\"},"@@ -604,10 +602,9 @@ static const tool_def_t TOOLS[] = {"\"project\"]}"},{"compare_graphs",- "Compare two indexed project snapshots. Returns deterministic target-only additions and "- "base-only removals for stable node and edge identities using a bounded streaming merge. "- "Each result set is independently capped by limit and a fixed 512 KiB encoded-byte budget; "- "exact totals and truncation reasons are always reported.",+ "Compare two indexed snapshots: deterministic target-only additions and base-only "+ "removals of stable node/edge identities; each set capped by limit and a 512 KiB budget "+ "with exact totals and truncation reasons.","{\"type\":\"object\",\"properties\":{""\"base_project\":{\"type\":\"string\",\"minLength\":1},""\"target_project\":{\"type\":\"string\",\"minLength\":1},"@@ -1011,7 +1008,6 @@ const char *cbm_mcp_tool_name(int index) {return TOOLS[index].name;}-const char *cbm_mcp_tool_description(const char *tool_name) {if (!tool_name) {return NULL;@@ -2853,7 +2849,6 @@ static void add_project_record_json(yyjson_mut_doc *doc, yyjson_mut_val *arr,yyjson_mut_arr_add_val(arr, p);}-/* list_projects: scan cache directory for .db files.* Each project is a single .db file — no central registry needed. */static char *handle_list_projects(cbm_mcp_server_t *srv, const char *args) {@@ -2980,6 +2975,8 @@ static char *handle_list_projects(cbm_mcp_server_t *srv, const char *args) {yyjson_mut_obj_add_val(doc, root, "projects", arr);yyjson_mut_obj_add_int(doc, root, "total", record_count);+ yyjson_mut_obj_add_int(doc, root, "offset", offset);+ yyjson_mut_obj_add_int(doc, root, "limit", limit);yyjson_mut_obj_add_int(doc, root, "returned", end - start);yyjson_mut_obj_add_bool(doc, root, "has_more", end < record_count);if (end < record_count) {@@ -4382,7 +4379,6 @@ static void sg_toon_property_cell(cbm_sb_t *sb, yyjson_val *v) {}}-/* "start-end" line range, or empty when the node carries no line info. */static void sg_lines_str(char *out, size_t sz, int start, int end) {if (start > 0) {@@ -4945,6 +4941,10 @@ static char *sg_render_payload(bool json_format, const cbm_search_output_t *out,emit_search_results_tree_json(doc, root, out, fields, plan->fields_returned, store,relationship, plan->connected_returned, plan->returned);}+ } else {+ /* The structured shape stays stable for semantic-only calls: an empty+ * groups array rather than an absent structural section. */+ yyjson_mut_obj_add_val(doc, root, "groups", yyjson_mut_arr(doc));}if (semantic->present) {sg_emit_semantic_paging_json(doc, root, semantic, plan->semantic_returned);@@ -8202,13 +8202,14 @@ static void bfs_to_toon_table(cbm_sb_t *sb, const char *key, cbm_traverse_resultif (include_tests) {cols[ncols++] = "test";}- if (data_flow) {- cols[ncols++] = "args";- }+ /* Header order is the row order: strategy, confidence, then args (#1542). */if (include_evidence) {cols[ncols++] = "strategy";cols[ncols++] = "confidence";}+ if (data_flow) {+ cols[ncols++] = "args";+ }cbm_tree_table_header(sb, key, visible, cols, ncols);for (int i = 0; i < tr->visited_count; i++) {const char *fp = tr->visited[i].node.file_path;@@ -8228,17 +8229,6 @@ static void bfs_to_toon_table(cbm_sb_t *sb, const char *key, cbm_traverse_resultconst cbm_edge_info_t *predecessor = (data_flow || include_evidence)? trace_predecessor_edge(edge_ctx, &tr->visited[i]): NULL;- if (data_flow) {- size_t alen = 0;- const char *ea = trace_edge_args(predecessor, &alen);- if (ea && alen > 0) {- char *args = cbm_strndup(ea, alen);- cbm_tree_cell_str(sb, args ? args : "", false);- free(args);- } else {- cbm_tree_cell_str(sb, "", false);- }- }if (include_evidence) {const char *ev_class = NULL;double ev_conf = -1.0;@@ -8254,6 +8244,17 @@ static void bfs_to_toon_table(cbm_sb_t *sb, const char *key, cbm_traverse_resultcbm_tree_cell_str(sb, "-", false);}}+ if (data_flow) {+ size_t alen = 0;+ const char *ea = trace_edge_args(predecessor, &alen);+ if (ea && alen > 0) {+ char *args = cbm_strndup(ea, alen);+ cbm_tree_cell_str(sb, args ? args : "", false);+ free(args);+ } else {+ cbm_tree_cell_str(sb, "", false);+ }+ }cbm_tree_row_end(sb);}}@@ -8631,15 +8632,16 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_resultif (include_tests) {yyjson_mut_arr_add_str(doc, cols, "test");}- if (data_flow) {- yyjson_mut_arr_add_str(doc, cols, "args");- }- /* Keep declaration order identical to row emission below. Evidence is at- * the tail so enabling data_flow cannot put args under a strategy column. */+ /* Keep declaration order identical to row emission below: strategy,+ * confidence, then args (#1542) — enabling data_flow must never put args+ * under a strategy column. */if (include_evidence) {yyjson_mut_arr_add_str(doc, cols, "strategy");yyjson_mut_arr_add_str(doc, cols, "confidence");}+ if (data_flow) {+ yyjson_mut_arr_add_str(doc, cols, "args");+ }yyjson_mut_obj_add_val(doc, leg, "cols", cols);yyjson_mut_val *groups = yyjson_mut_arr(doc);yyjson_mut_val *cur_rows = NULL;@@ -8678,20 +8680,6 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_resultconst cbm_edge_info_t *predecessor = (data_flow || include_evidence)? trace_predecessor_edge(edge_ctx, &tr->visited[i]): NULL;- if (data_flow) {- size_t alen = 0;- const char *ea = trace_edge_args(predecessor, &alen);- if (ea && alen > 0) {- yyjson_mut_val *av = yyjson_mut_rawn(doc, ea, alen);- if (av) {- yyjson_mut_arr_add_val(row, av);- } else {- yyjson_mut_arr_add_str(doc, row, "");- }- } else {- yyjson_mut_arr_add_str(doc, row, "");- }- }if (include_evidence) {const char *ev_class = NULL;double ev_conf = -1.0;@@ -8711,6 +8699,20 @@ static yyjson_mut_val *bfs_to_tree_json(yyjson_mut_doc *doc, cbm_traverse_resultyyjson_mut_arr_add_null(doc, row);}}+ if (data_flow) {+ size_t alen = 0;+ const char *ea = trace_edge_args(predecessor, &alen);+ if (ea && alen > 0) {+ yyjson_mut_val *av = yyjson_mut_rawn(doc, ea, alen);+ if (av) {+ yyjson_mut_arr_add_val(row, av);+ } else {+ yyjson_mut_arr_add_str(doc, row, "");+ }+ } else {+ yyjson_mut_arr_add_str(doc, row, "");+ }+ }yyjson_mut_arr_add_val(cur_rows, row);}free(cur_group);@@ -11318,26 +11320,6 @@ static char *sanitize_utf8_lossy(const char *s) {return out;}-/* Fixed-width search buffers cannot grow invalid bytes into the three-byte- * replacement character. Preserve every valid UTF-8 sequence and replace an- * invalid byte in place with '?', keeping the result valid without losing- * non-ASCII identifiers, paths, comments, or source text. */-static void sanitize_utf8_inplace(char *s) {- if (!s) {- return;- }- unsigned char *p = (unsigned char *)s;- const unsigned char *end = p + strlen(s);- while (p < end) {- size_t n = utf8_sequence_len(p, end);- if (n > 0) {- p += n;- } else {- *p++ = '?';- }- }-}-/* Build an enriched snippet response for a resolved node. *//* Add a string array to a JSON object (no-op if count == 0). */static void add_string_array(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key,@@ -12194,8 +12176,10 @@ typedef struct {bool include_phase_timings;} search_metrics_t;+#ifdef CBM_ENABLE_TEST_SEAMS/* Test seams render synthetic rows without a live scan. */static const search_metrics_t zero_metrics = {0};+#endiftypedef struct {char *name;@@ -12444,7 +12428,6 @@ void cbm_search_code_build_grep_cmd(char *cmd, size_t cmd_sz, bool use_regex, bo#endif}-/* Build deduplicated file list from search results + raw matches. */static yyjson_mut_val *build_dedup_files_array(yyjson_mut_doc *doc, search_result_t *sr,int result_start, int output_count,@@ -12548,8 +12531,11 @@ static void attach_result_source(yyjson_mut_doc *doc, yyjson_mut_val *item, sear}char *source = read_file_lines(abs_path, s, e);if (source) {- sanitize_utf8_inplace(source);- yyjson_mut_obj_add_strcpy(doc, item, "source", source);+ char *safe_source = sanitize_utf8_lossy(source);+ if (safe_source) {+ yyjson_mut_obj_add_strcpy(doc, item, "source", safe_source);+ free(safe_source);+ }free(source);if (truncated) {yyjson_mut_obj_add_int(doc, item, "source_start", s);@@ -12564,8 +12550,11 @@ static void attach_result_source(yyjson_mut_doc *doc, yyjson_mut_val *item, sear}char *ctx = read_file_lines(abs_path, ctx_start, ctx_end);if (ctx) {- sanitize_utf8_inplace(ctx);- yyjson_mut_obj_add_strcpy(doc, item, "context", ctx);+ char *safe_context = sanitize_utf8_lossy(ctx);+ if (safe_context) {+ yyjson_mut_obj_add_strcpy(doc, item, "context", safe_context);+ free(safe_context);+ }yyjson_mut_obj_add_int(doc, item, "context_start", ctx_start);free(ctx);}@@ -13138,7 +13127,11 @@ static char *assemble_search_output(char *json = yy_doc_to_str(doc);if (json) {- sanitize_utf8_inplace(json);+ char *safe_json = sanitize_utf8_lossy(json);+ if (safe_json) {+ free(json);+ json = safe_json;+ }}yyjson_mut_doc_free(doc);@@ -13156,8 +13149,8 @@ static char *render_search_payload(search_result_t *sr, int sr_count, grep_matchint directory_output, int raw_limit, int directory_limit,int match_limit, int mode, int context_lines,int source_max_lines, const char *root_path, bool scan_saturated,- bool warn_literal_pipe, const search_metrics_t *metrics, bool budget_hit,- bool json_format) {+ bool warn_literal_pipe, const search_metrics_t *metrics,+ bool budget_hit, bool json_format) {if (mode == 0 && !json_format) {return assemble_search_output_toon(sr, sr_count, raw, raw_count, raw_content_truncated,gm_count, result_start, result_limit, output_count,@@ -13445,7 +13438,8 @@ char *cbm_mcp_render_raw_preview_for_testing(const char *content, bool content_ogrep_match_t raw = {.file = "fixture.raw", .line = 7};search_raw_preview(&raw, content, content_offset_set, content_offset, false, 0, 0);return render_search_payload(NULL, 0, &raw, 1, raw.content_truncated ? 1 : 0, 1, 0, 0, 0, 0, 1,- 0, 0, 1, 0, 0, 0, 0, 0, "", false, false, &zero_metrics, false, json_format);+ 0, 0, 1, 0, 0, 0, 0, 0, "", false, false, &zero_metrics, false,+ json_format);}#endif@@ -14394,7 +14388,10 @@ static char *handle_search_code(cbm_mcp_server_t *srv, const char *args) {srv->search_scan_command_override ? srv->search_scan_command_override : cmd;mcp_scan_cause_t scan_cause = mcp_run_shell_command_cancellable_bounded(srv, scan_command, output_path, scan_output_limit, scan_deadline_ms, true,- scan_deadline_latched, !scoped, &scan_result);+ scan_deadline_latched, /*exit_one_is_no_match=*/false, &scan_result);+ /* Both POSIX commands wrap grep and map its no-match status to 0, so any+ * non-zero exit (a failed find/sort, an unreadable operand, a broken+ * grep) is an incomplete scan and fails closed. */FILE *fp = NULL;const char *scan_message = NULL; /* MCP_SCAN_DEADLINE renders its own text */char limit_message[CBM_SZ_128];@@ -14408,7 +14405,8 @@ static char *handle_search_code(cbm_mcp_server_t *srv, const char *args) {scan_message = limit_message;} else if (scan_cause == MCP_SCAN_COMMAND_FAILURE ||scan_cause == MCP_SCAN_CONTAINED_COMMAND_FAILURE) {- scan_message = "search failed: the contained command could not complete";+ scan_message = "search failed before the complete result set was scanned: the "+ "contained command could not complete";} else if (scan_cause == MCP_SCAN_SUCCESS) {fp = cbm_fopen(output_path, "rb");if (!fp) {diff --git a/src/store/store.c b/src/store/store.cindex 5061fcd11..c36f00b44 100644--- a/src/store/store.c+++ b/src/store/store.c@@ -5792,6 +5792,8 @@ static int store_bfs(cbm_store_t *s, int64_t start_id, const char *direction,next_id = "e.target_id";}+ /* One extra row makes max_results saturation observable on both branches. */+ int probe_limit = max_results < INT_MAX ? max_results + SKIP_ONE : max_results;int cte_row_limit = 0;if (trail) {cte_row_limit = bfs_cte_row_limit_for_depth(max_results, max_depth);@@ -5820,7 +5822,7 @@ static int store_bfs(cbm_store_t *s, int64_t start_id, const char *direction,"FROM bfs JOIN nodes n ON n.id = bfs.node_id ""WHERE bfs.hop > 0 ORDER BY bfs.hop, n.id LIMIT %d;",(long long)start_id, next_id, join_cond, types_clause, max_depth,- cte_row_limit + SKIP_ONE, max_results);+ cte_row_limit + SKIP_ONE, probe_limit);} else {snprintf(sql, sizeof(sql),/* SHORTEST-PATH semantics: the UNION dedupes (node, hop) pairs.@@ -5843,9 +5845,7 @@ static int store_bfs(cbm_store_t *s, int64_t start_id, const char *direction,"GROUP BY n.id ""ORDER BY hop, n.id ""LIMIT %d;",- /* One extra row makes max_results saturation observable. */- (long long)start_id, next_id, join_cond, types_clause, max_depth,- max_results < INT_MAX ? max_results + SKIP_ONE : max_results);+ (long long)start_id, next_id, join_cond, types_clause, max_depth, probe_limit);}sqlite3_stmt *stmt = NULL;@@ -5898,7 +5898,7 @@ static int store_bfs(cbm_store_t *s, int64_t start_id, const char *direction,snprintf(limit_buf, sizeof(limit_buf), "%d", cte_row_limit);cbm_log_warn("cypher.trail_truncated", "cte_rows", limit_buf, "result", "partial");}- if (!trail && n > max_results) {+ if (n > max_results) {/* The extra probe row fired: drop it and report the ceiling honestly. */n = max_results;cbm_node_free_fields(&visited[n].node);diff --git a/tests/test_cli.c b/tests/test_cli.cindex 7bd937b40..c74faa204 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -7283,8 +7283,7 @@ TEST(cli_registry_routes_omp_via_profile_and_pi_coding_agent_dir) {FAIL("cbm_mkdtemp failed");const char *const env_names[] = {- "HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR",- "XDG_CONFIG_HOME", "APPDATA",+ "HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR", "XDG_CONFIG_HOME", "APPDATA",};char *saved_env[sizeof(env_names) / sizeof(env_names[0])];for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {@@ -7369,8 +7368,7 @@ TEST(cli_registry_routes_omp_via_profile_and_pi_coding_agent_dir) {relocated_plan && strstr(relocated_plan, "\"omp\"") &&test_json_string_array_contains(relocated_root, "config_files_planned",omp_relocated_mcp) &&- test_json_string_array_contains(relocated_root, "agent_files_planned",- omp_relocated_agent);+ test_json_string_array_contains(relocated_root, "agent_files_planned", omp_relocated_agent);yyjson_doc_free(relocated_doc);free(relocated_plan);cbm_unsetenv("PI_CODING_AGENT_DIR");@@ -7393,12 +7391,9 @@ TEST(cli_registry_routes_omp_via_profile_and_pi_coding_agent_dir) {/* None of the plan-only invocations may have written OMP-owned content. */struct stat state;bool plan_did_not_mutate =- (stat(omp_default_mcp, &state) != 0) &&- (stat(omp_default_agent, &state) != 0) &&- (stat(omp_profile_mcp, &state) != 0) &&- (stat(omp_profile_agent, &state) != 0) &&- (stat(omp_relocated_mcp, &state) != 0) &&- (stat(omp_relocated_agent, &state) != 0);+ (stat(omp_default_mcp, &state) != 0) && (stat(omp_default_agent, &state) != 0) &&+ (stat(omp_profile_mcp, &state) != 0) && (stat(omp_profile_agent, &state) != 0) &&+ (stat(omp_relocated_mcp, &state) != 0) && (stat(omp_relocated_agent, &state) != 0);for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {restore_test_env(env_names[i], saved_env[i]);@@ -7406,8 +7401,7 @@ TEST(cli_registry_routes_omp_via_profile_and_pi_coding_agent_dir) {test_rmdir_r(tmpdir);if (!default_plan_ok || !profile_plan_ok || !relocated_plan_ok || !fallback_plan_ok ||!plan_did_not_mutate) {- fprintf(stderr,- "omp diag default=%d profile=%d relocated=%d fallback=%d plan_clean=%d\n",+ fprintf(stderr, "omp diag default=%d profile=%d relocated=%d fallback=%d plan_clean=%d\n",default_plan_ok, profile_plan_ok, relocated_plan_ok, fallback_plan_ok,plan_did_not_mutate);FAIL("OMP must resolve ~/.omp/agent under the documented fallback, honor OMP_PROFILE "@@ -7417,15 +7411,14 @@ TEST(cli_registry_routes_omp_via_profile_and_pi_coding_agent_dir) {PASS();}-TEST(cli_registry_omp_named_profile_install_and_uninstall_preserve_user_content) {char tmpdir[256];snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-registry-omp-lifecycle-XXXXXX");if (!cbm_mkdtemp(tmpdir))FAIL("cbm_mkdtemp failed");- const char *const env_names[] = {"HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR",- "XDG_CONFIG_HOME", "APPDATA"};+ const char *const env_names[] = {+ "HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR", "XDG_CONFIG_HOME", "APPDATA"};char *saved_env[sizeof(env_names) / sizeof(env_names[0])];for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {saved_env[i] = save_test_env(env_names[i]);@@ -7466,22 +7459,22 @@ TEST(cli_registry_omp_named_profile_install_and_uninstall_preserve_user_content)install_rc == 0 && installed_mcp && strstr(installed_mcp, "codebase-memory-mcp") &&strstr(installed_mcp, binary_path) && installed_instructions &&strcmp(installed_instructions, user_instructions) == 0 &&- test_file_contains_all(skill_path,- (const char *const[]){"search_graph", "trace_path",- "Sessions and Subagents"},- 3U) &&+ test_file_contains_all(+ skill_path,+ (const char *const[]){"search_graph", "trace_path", "Sessions and Subagents"}, 3U) &&test_file_contains_all(scout_path,(const char *const[]){"autoloadSkills: [codebase-memory]",- "mcp__codebase_memory_mcp_search_graph"},+ "mcp__codebase_memory_mcp_search_graph"},2U) &&- test_file_contains_all(verify_path,- (const char *const[]){"read-summarize: false",- "mcp__codebase_memory_mcp_trace_path"},- 2U) &&- test_file_contains_all(auditor_path,- (const char *const[]){"autoloadSkills: [codebase-memory]",- "mcp__codebase_memory_mcp_check_index_coverage"},- 2U);+ test_file_contains_all(+ verify_path,+ (const char *const[]){"read-summarize: false", "mcp__codebase_memory_mcp_trace_path"},+ 2U) &&+ test_file_contains_all(+ auditor_path,+ (const char *const[]){"autoloadSkills: [codebase-memory]",+ "mcp__codebase_memory_mcp_check_index_coverage"},+ 2U);free(installed_mcp);free(installed_instructions);@@ -7494,12 +7487,12 @@ TEST(cli_registry_omp_named_profile_install_and_uninstall_preserve_user_content)char *preserved_instructions = read_test_file_alloc(instructions_path);char *preserved_verify = read_test_file_alloc(verify_path);char *mcp_after = read_test_file_alloc(mcp_path);- bool uninstalled =- uninstall_rc == 0 && preserved_instructions &&- strcmp(preserved_instructions, user_instructions) == 0 && preserved_verify &&- strcmp(preserved_verify, modified_verify) == 0 && stat(skill_path, &state) != 0 &&- stat(scout_path, &state) != 0 && stat(auditor_path, &state) != 0 &&- (!mcp_after || !strstr(mcp_after, "codebase-memory-mcp"));+ bool uninstalled = uninstall_rc == 0 && preserved_instructions &&+ strcmp(preserved_instructions, user_instructions) == 0 && preserved_verify &&+ strcmp(preserved_verify, modified_verify) == 0 &&+ stat(skill_path, &state) != 0 && stat(scout_path, &state) != 0 &&+ stat(auditor_path, &state) != 0 &&+ (!mcp_after || !strstr(mcp_after, "codebase-memory-mcp"));free(preserved_instructions);free(preserved_verify);free(mcp_after);@@ -7522,8 +7515,8 @@ TEST(cli_registry_omp_relocated_dry_run_is_non_mutating) {if (!cbm_mkdtemp(tmpdir))FAIL("cbm_mkdtemp failed");- const char *const env_names[] = {"HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR",- "XDG_CONFIG_HOME", "APPDATA"};+ const char *const env_names[] = {+ "HOME", "PATH", "OMP_PROFILE", "PI_CODING_AGENT_DIR", "XDG_CONFIG_HOME", "APPDATA"};char *saved_env[sizeof(env_names) / sizeof(env_names[0])];for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {saved_env[i] = save_test_env(env_names[i]);diff --git a/tests/test_cypher.c b/tests/test_cypher.cindex 899dd0fc3..d72c4857b 100644--- a/tests/test_cypher.c+++ b/tests/test_cypher.c@@ -810,9 +810,9 @@ TEST(cypher_exec_optional_saturated_does_not_fabricate_no_match) {/* The discriminator: C has 5 callees, so claiming it has none is a* fabrication. Pre-fix this is exactly what the saturated path emitted. */ASSERT_FALSE(saw_c);- /* Late filtering leaves fewer than max_rows output rows, but the earlier- * relationship materialization still saturated its candidate budget. */- ASSERT_TRUE(r.truncated);+ /* Relationship expansion materializes every matched row (a cap here once+ * falsified aggregates), so nothing was left unevaluated. */+ ASSERT_FALSE(r.truncated);cbm_cypher_result_free(&r);cbm_store_close(s);@@ -2151,9 +2151,10 @@ TEST(cypher_optional_match_target_still_allowed_issue1919) {TEST(cypher_with_alias_stays_in_scope_issue1919) {cbm_store_t *s = setup_cypher_store();cbm_cypher_result_t r = {0};- int rc = cbm_cypher_execute(- s, "MATCH (f:Function)-[:CALLS]->(g) WITH f.name AS caller, g AS callee RETURN caller, callee.name",- "test", 0, &r);+ int rc = cbm_cypher_execute(s,+ "MATCH (f:Function)-[:CALLS]->(g) WITH f.name AS caller, g AS "+ "callee RETURN caller, callee.name",+ "test", 0, &r);ASSERT_EQ(rc, 0);ASSERT_NULL(r.error);ASSERT_TRUE(r.row_count > 0);@@ -2871,9 +2872,10 @@ TEST(cypher_result_reports_max_rows_saturation) {PASS();}-/* An unlabeled scan has a max_rows*10 candidate budget. Aggregation can hide- * that loss behind one output row, so row_count alone cannot report it. */-TEST(cypher_result_reports_scan_saturation_before_aggregation) {+/* An unlabeled MATCH scans every candidate before aggregation: the count is+ * exact for any max_rows, and no internal ceiling is reported (a bounded scan+ * here once made count(*) depend on the requested row budget). */+TEST(cypher_result_unlabeled_scan_is_exhaustive_before_aggregation) {cbm_store_t *s = cbm_store_open_memory();cbm_store_upsert_project(s, "scan_sat", "/tmp/scan_sat");@@ -2891,8 +2893,8 @@ TEST(cypher_result_reports_scan_saturation_before_aggregation) {int rc = cbm_cypher_execute(s, "MATCH (n) RETURN count(*) AS n", "scan_sat", 1, &r);ASSERT_EQ(rc, 0);ASSERT_EQ(r.row_count, 1);- ASSERT_STR_EQ(r.rows[0][0], "10");- ASSERT_TRUE(r.truncated);+ ASSERT_STR_EQ(r.rows[0][0], "11");+ ASSERT_FALSE(r.truncated);cbm_cypher_result_free(&r);memset(&r, 0, sizeof(r));@@ -3176,8 +3178,8 @@ TEST(cypher_wide_with_refused_not_truncated) {char query[1024];int off = snprintf(query, sizeof(query), "MATCH (f:Function) WITH ");for (int i = 0; i < 20; i++) { /* 20 > CYP_MAX_VARS (16) */- off += snprintf(query + off, sizeof(query) - (size_t)off, "%sf.name AS c%d", i ? ", " : "",- i);+ off +=+ snprintf(query + off, sizeof(query) - (size_t)off, "%sf.name AS c%d", i ? ", " : "", i);}snprintf(query + off, sizeof(query) - (size_t)off, " RETURN *");@@ -4501,7 +4503,7 @@ SUITE(cypher) {RUN_TEST(cypher_edge_builtin_type_filter);RUN_TEST(cypher_apply_limit);RUN_TEST(cypher_result_reports_max_rows_saturation);- RUN_TEST(cypher_result_reports_scan_saturation_before_aggregation);+ RUN_TEST(cypher_result_unlabeled_scan_is_exhaustive_before_aggregation);RUN_TEST(cypher_result_reports_variable_length_candidate_saturation);/* Phase 1: Simple operators */RUN_TEST(cypher_lex_neq_operators);diff --git a/tests/test_mcp.c b/tests/test_mcp.cindex ae962e624..563eed0de 100644--- a/tests/test_mcp.c+++ b/tests/test_mcp.c@@ -1358,7 +1358,10 @@ TEST(mcp_metadata_byte_budget) {char *json = cbm_mcp_tools_list();ASSERT_NOT_NULL(json);- ASSERT_LT((int)strlen(json), 15 * 1024);+ /* 15 KiB covered the lean surface at the branch point; get_file_outline,+ * compare_graphs, manage_adr set_sections, and the search_code debug and+ * list_projects include_details parameters landed on main since. */+ ASSERT_LT((int)strlen(json), 18 * 1024);yyjson_doc *doc = yyjson_read(json, strlen(json), 0);ASSERT_NOT_NULL(doc);@@ -5555,7 +5558,8 @@ TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_char *response = cbm_mcp_handle_tool(srv, "check_index_coverage",- "{\"project\":\"test-project\",\"paths\":[\"main.go\"],\"scopes\":[\".\"]}");+ "{\"project\":\"test-project\",\"paths\":[\"main.go\"],\"scopes\":[\".\"],"+ "\"format\":\"json\"}");ASSERT_NOT_NULL(response);char *inner = extract_text_content(response);ASSERT_NOT_NULL(inner);@@ -6850,9 +6854,10 @@ TEST(tool_trace_path_unreadable_confidence_reports_not_recorded) {ASSERT_GT(cbm_store_insert_edge(st, &e), 0);char *ev = cbm_mcp_server_handle(- srv, "{\"jsonrpc\":\"2.0\",\"id\":93,\"method\":\"tools/call\","- "\"params\":{\"name\":\"trace_path\",\"arguments\":{\"function_name\":\"caller\","- "\"project\":\"badconf-proj\",\"direction\":\"outbound\",\"include_evidence\":true}}}");+ srv,+ "{\"jsonrpc\":\"2.0\",\"id\":93,\"method\":\"tools/call\","+ "\"params\":{\"name\":\"trace_path\",\"arguments\":{\"function_name\":\"caller\","+ "\"project\":\"badconf-proj\",\"direction\":\"outbound\",\"include_evidence\":true}}}");ASSERT_NOT_NULL(ev);char *ev_txt = extract_text_content(ev);ASSERT_NOT_NULL(ev_txt);@@ -7060,11 +7065,11 @@ TEST(tool_trace_path_edge_details_use_canonical_predecessor) {yyjson_val *row = trace_grouped_row_named(callers, "caller", NULL);ASSERT_NOT_NULL(row);ASSERT_EQ(yyjson_get_int(yyjson_arr_get(row, 1)), 1);- yyjson_val *args = yyjson_arr_get(row, 2);+ yyjson_val *args = yyjson_arr_get(row, 4);ASSERT_TRUE(yyjson_is_arr(args));ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(yyjson_arr_get(args, 0), "e")), "correct");- ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(row, 3)), "lsp");- ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(row, 4)) * 10.0), 9);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(row, 2)), "lsp");+ ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(row, 3)) * 10.0), 9);ASSERT_NULL(strstr(inner, "decoy"));yyjson_doc_free(doc);free(inner);@@ -7144,8 +7149,8 @@ TEST(tool_trace_path_evidence_columns_align_across_optional_modes) {"qn = qn_prefix == \"\" ? name : qn_prefix + \".\" + name");yyjson_val *cols = yyjson_obj_get(callees, "cols");ASSERT_NOT_NULL(cols);- static const char *const expected_cols[] = {"name", "hop", "risk", "test",- "args", "strategy", "confidence"};+ static const char *const expected_cols[] = {"name", "hop", "risk", "test",+ "strategy", "confidence", "args"};ASSERT_EQ(yyjson_arr_size(cols), sizeof(expected_cols) / sizeof(expected_cols[0]));for (size_t i = 0; i < sizeof(expected_cols) / sizeof(expected_cols[0]); i++) {ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(cols, i)), expected_cols[i]);@@ -7157,12 +7162,12 @@ TEST(tool_trace_path_evidence_columns_align_across_optional_modes) {ASSERT_EQ(yyjson_get_int(yyjson_arr_get(target_row, 1)), 1);ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(target_row, 2)), "CRITICAL");ASSERT_FALSE(yyjson_get_bool(yyjson_arr_get(target_row, 3)));- yyjson_val *target_args = yyjson_arr_get(target_row, 4);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(target_row, 4)), "lsp");+ ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(target_row, 5)) * 100.0), 95);+ yyjson_val *target_args = yyjson_arr_get(target_row, 6);ASSERT_TRUE(yyjson_is_arr(target_args));ASSERT_EQ(yyjson_arr_size(target_args), 1);ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(yyjson_arr_get(target_args, 0), "e")), "payload");- ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(target_row, 5)), "lsp");- ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(target_row, 6)) * 100.0), 95);const char *dotless_prefix = NULL;yyjson_val *dotless_row = trace_grouped_row_named(callees, "dotless_target", &dotless_prefix);@@ -7172,8 +7177,8 @@ TEST(tool_trace_path_evidence_columns_align_across_optional_modes) {ASSERT_EQ(yyjson_arr_size(dotless_row), yyjson_arr_size(cols));ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(dotless_row, 0)), "dotless_target");ASSERT_TRUE(yyjson_get_bool(yyjson_arr_get(dotless_row, 3)));- ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(dotless_row, 5)), "heuristic");- ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(dotless_row, 6)) * 10.0), 5);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_arr_get(dotless_row, 4)), "heuristic");+ ASSERT_EQ((int)(yyjson_get_real(yyjson_arr_get(dotless_row, 5)) * 10.0), 5);yyjson_doc_free(doc);free(inner);free(response);@@ -7214,7 +7219,7 @@ TEST(tool_trace_path_evidence_columns_align_across_optional_modes) {"\"mode\":\"data_flow\",\"include_tests\":true,\"include_evidence\":true}");inner = extract_text_content(response);ASSERT_NOT_NULL(inner);- ASSERT_NOT_NULL(strstr(inner, "(cols: qn hop test args strategy confidence)"));+ ASSERT_NOT_NULL(strstr(inner, "(cols: qn hop test strategy confidence args)"));ASSERT_NOT_NULL(strstr(inner, "lsp 0.95"));ASSERT_NOT_NULL(strstr(inner, "heuristic 0.5"));free(inner);@@ -8476,16 +8481,33 @@ TEST(search_code_fails_closed_when_complete_scan_is_impossible) {cbm_mcp_server_set_project(srv, project);ASSERT_EQ(cbm_store_upsert_project(store, project, tmp), CBM_STORE_OK);- /* The graph snapshot names a file that is no longer readable by grep.- * Returning zero exact matches would be a false completeness claim. */- cbm_node_t missing = {.project = project,- .label = "Function",- .name = "missing",- .qualified_name = "search-incomplete.missing",- .file_path = "missing.c",- .start_line = 1,- .end_line = 1};- ASSERT_GT(cbm_store_upsert_node(store, &missing), 0);+ /* The graph snapshot names a regular file that grep cannot read. Returning+ * zero exact matches would be a false completeness claim. (A path that no+ * longer exists, or is not a regular file, is deliberately NOT a scan+ * operand: the scoped file list skips it — see+ * search_code_scoped_scan_skips_non_regular_indexed_paths.) */+#ifdef _WIN32+ cbm_mcp_server_free(srv);+ ASSERT_EQ(th_rmtree(tmp), 0);+ SKIP("POSIX permission bits drive the unreadable-operand scenario");+#else+ if (geteuid() == 0) {+ cbm_mcp_server_free(srv);+ ASSERT_EQ(th_rmtree(tmp), 0);+ SKIP("root reads mode-0 files; the unreadable-operand scenario needs an unprivileged uid");+ }+ char unreadable_path[512];+ snprintf(unreadable_path, sizeof(unreadable_path), "%s/unreadable.c", tmp);+ ASSERT_EQ(th_write_file(unreadable_path, "int never_scanned(void) { return 0; }\n"), 0);+ ASSERT_EQ(chmod(unreadable_path, 0), 0);+ cbm_node_t unreadable = {.project = project,+ .label = "Function",+ .name = "never_scanned",+ .qualified_name = "search-incomplete.never_scanned",+ .file_path = "unreadable.c",+ .start_line = 1,+ .end_line = 1};+ ASSERT_GT(cbm_store_upsert_node(store, &unreadable), 0);char *response =cbm_mcp_handle_tool(srv, "search_code",@@ -8493,7 +8515,9 @@ TEST(search_code_fails_closed_when_complete_scan_is_impossible) {"\"format\":\"json\"}");ASSERT_NOT_NULL(response);ASSERT_NOT_NULL(strstr(response, "\"isError\":true"));- ASSERT_NOT_NULL(strstr(response, "complete result set was scanned"));+ ASSERT_NOT_NULL(strstr(response, "search failed"));+ (void)chmod(unreadable_path, 0644);+#endiffree(response);cbm_mcp_server_free(srv);@@ -8626,10 +8650,10 @@ TEST(search_code_scoped_file_pattern_is_busybox_portable) {ASSERT_TRUE(forced_length > 0 && (size_t)forced_length < sizeof(forced_path));ASSERT_EQ(cbm_setenv("PATH", forced_path, 1), 0);- char *response = cbm_mcp_handle_tool(- srv, "search_code",- "{\"pattern\":\"BUSYBOX_GREP_NEEDLE\",\"project\":\"search-busybox\","- "\"file_pattern\":\"*R&D*.c\",\"format\":\"json\"}");+ char *response =+ cbm_mcp_handle_tool(srv, "search_code",+ "{\"pattern\":\"BUSYBOX_GREP_NEEDLE\",\"project\":\"search-busybox\","+ "\"file_pattern\":\"*R&D*.c\",\"format\":\"json\"}");mcp_test_restore_env(&path_backup, 1U);char *inner = extract_text_content(response);bool portable_success = response && !strstr(response, "\"isError\":true") && inner &&@@ -9562,6 +9586,20 @@ TEST(search_code_match_locations_are_explicitly_bounded_and_expandable) {PASS();}+/* The search_code json row layout is column-ordered; find a cell by its+ * declared column name rather than by a fixed index. */+static yyjson_val *sc_json_cell(yyjson_val *root, yyjson_val *row, const char *column) {+ yyjson_val *cols = yyjson_obj_get(root, "cols");+ size_t n = cols ? yyjson_arr_size(cols) : 0;+ for (size_t i = 0; i < n; i++) {+ const char *name = yyjson_get_str(yyjson_arr_get(cols, i));+ if (name && strcmp(name, column) == 0) {+ return yyjson_arr_get(row, i);+ }+ }+ return NULL;+}+/* Regression guard: search_code full results must preserve valid UTF-8 source. */static bool is_valid_json_response(const char *json);@@ -9618,7 +9656,7 @@ TEST(search_code_full_preserves_utf8_source) {ASSERT_NOT_NULL(rows);ASSERT_TRUE(yyjson_arr_size(rows) > 0);yyjson_val *row = yyjson_arr_get(rows, 0);- yyjson_val *source_obj = yyjson_arr_get(row, 7);+ yyjson_val *source_obj = sc_json_cell(yyjson_doc_get_root(doc), row, "source");yyjson_val *source_val = yyjson_obj_get(source_obj, "source");ASSERT_NOT_NULL(source_val);ASSERT_STR_EQ(yyjson_get_str(source_val), source);@@ -9791,7 +9829,8 @@ TEST(search_code_invalid_utf8_still_returns_valid_json) {yyjson_val *rows = yyjson_obj_get(yyjson_doc_get_root(doc), "rows");ASSERT_NOT_NULL(rows);ASSERT_TRUE(yyjson_arr_size(rows) > 0);- yyjson_val *source_obj = yyjson_arr_get(yyjson_arr_get(rows, 0), 7);+ yyjson_val *source_obj =+ sc_json_cell(yyjson_doc_get_root(doc), yyjson_arr_get(rows, 0), "source");ASSERT_NOT_NULL(source_obj);const char *safe_source = yyjson_get_str(yyjson_obj_get(source_obj, "source"));ASSERT_NOT_NULL(safe_source);@@ -10600,6 +10639,25 @@ TEST(search_code_scoped_scan_skips_non_regular_indexed_paths) {.start_line = 1,.end_line = 1};ASSERT_GT(cbm_store_upsert_node(store, &missing_node), 0);+ /* Scoped scans list the project's canonical File nodes whenever it has+ * any, so the real sources need theirs too — as every indexed project+ * has — for the decoys above to be tested alongside them. */+ cbm_node_t handler_file = {.project = "prefilter-search",+ .label = "File",+ .name = "handler.go",+ .qualified_name = "prefilter-search.src.handler.go",+ .file_path = "src/handler.go",+ .start_line = 1,+ .end_line = 1};+ ASSERT_GT(cbm_store_upsert_node(store, &handler_file), 0);+ cbm_node_t vendor_file = {.project = "prefilter-search",+ .label = "File",+ .name = "other.go",+ .qualified_name = "prefilter-search.vendor.other.go",+ .file_path = "vendor/other.go",+ .start_line = 1,+ .end_line = 1};+ ASSERT_GT(cbm_store_upsert_node(store, &vendor_file), 0);char *response = cbm_mcp_handle_tool(srv, "search_code", "{\"pattern\":\"HandleRequest\",\"project\":\"prefilter-search\"}");@@ -12650,9 +12708,9 @@ TEST(tool_corrupt_store_cleanup_rechecks_generation_after_guard_wait) {};cbm_mcp_server_set_project_mutation_guard(srv, mcp_replacing_mutation_guard_begin,mcp_replacing_mutation_guard_end, &replacement);- char *resp = cbm_mcp_handle_tool(- srv, "manage_adr",- "{\"project\":\"guard-corrupt-recheck\",\"mode\":\"update\",\"content\":\"# ADR\\n\\nPending replacement.\"}");+ char *resp = cbm_mcp_handle_tool(srv, "manage_adr",+ "{\"project\":\"guard-corrupt-recheck\",\"mode\":\"update\","+ "\"content\":\"# ADR\\n\\nPending replacement.\"}");bool response_used_replacement =resp && !response_contains_json_fragment(resp, "\"isError\":true");free(resp);@@ -12727,9 +12785,9 @@ TEST(tool_corrupt_store_cleanup_preserves_existing_backup_and_uses_unique_name)mcp_mutation_guard_probe_t probe = {0};cbm_mcp_server_set_project_mutation_guard(srv, mcp_mutation_guard_probe_begin,mcp_mutation_guard_probe_end, &probe);- char *resp = cbm_mcp_handle_tool(- srv, "manage_adr",- "{\"project\":\"guard-corrupt-unique\",\"mode\":\"update\",\"content\":\"# ADR\\n\\nPending quarantine.\"}");+ char *resp = cbm_mcp_handle_tool(srv, "manage_adr",+ "{\"project\":\"guard-corrupt-unique\",\"mode\":\"update\","+ "\"content\":\"# ADR\\n\\nPending quarantine.\"}");free(resp);cbm_mcp_server_free(srv);@@ -12802,9 +12860,9 @@ TEST(tool_corrupt_store_cleanup_publish_failure_preserves_db_and_wal) {mcp_mutation_guard_probe_end, &guard);mcp_quarantine_hook_probe_t hook = {.deny_step = "before_snapshot_publish"};cbm_mcp_server_set_quarantine_test_hook(srv, mcp_quarantine_hook_probe, &hook);- char *resp = cbm_mcp_handle_tool(- srv, "manage_adr",- "{\"project\":\"guard-corrupt-publish-fail\",\"mode\":\"update\",\"content\":\"# ADR\\n\\nPending publish.\"}");+ char *resp = cbm_mcp_handle_tool(srv, "manage_adr",+ "{\"project\":\"guard-corrupt-publish-fail\",\"mode\":"+ "\"update\",\"content\":\"# ADR\\n\\nPending publish.\"}");bool db_unchanged = mcp_file_matches_snapshot(db_path, db_before, db_len);bool wal_unchanged = mcp_file_matches_snapshot(wal_path, wal_before, wal_len);@@ -12876,9 +12934,9 @@ TEST(tool_corrupt_store_cleanup_publishes_complete_wal_snapshot_before_delete) {mcp_mutation_guard_probe_end, &guard);mcp_quarantine_hook_probe_t hook = {.deny_step = "after_snapshot_publish"};cbm_mcp_server_set_quarantine_test_hook(srv, mcp_quarantine_hook_probe, &hook);- char *resp = cbm_mcp_handle_tool(- srv, "manage_adr",- "{\"project\":\"guard-corrupt-after-publish\",\"mode\":\"update\",\"content\":\"# ADR\\n\\nPending publish.\"}");+ char *resp = cbm_mcp_handle_tool(srv, "manage_adr",+ "{\"project\":\"guard-corrupt-after-publish\",\"mode\":"+ "\"update\",\"content\":\"# ADR\\n\\nPending publish.\"}");bool db_unchanged = mcp_file_matches_snapshot(db_path, db_before, db_len);bool wal_unchanged = mcp_file_matches_snapshot(wal_path, wal_before, wal_len);@@ -16760,9 +16818,14 @@ TEST(tool_resolve_store_by_internal_name_issue704) {char *page =cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":11,\"method\":\"tools/call\",""\"params\":{\"name\":\"list_projects\","- "\"arguments\":{\"offset\":0,\"limit\":1}}}");+ "\"arguments\":{\"offset\":0,\"limit\":1,"+ "\"format\":\"json\"}}}");ASSERT_NOT_NULL(page);- ASSERT_NOT_NULL(strstr(page, "\\\"total\\\":3"));+ /* total counts the projects the listing can actually return: alpha704 and+ * the drifted beta704. The 0-byte ghost is never a row, so it is not a+ * page either — a total that included it would leave has_more true on the+ * last page. */+ ASSERT_NOT_NULL(strstr(page, "\\\"total\\\":2"));ASSERT_NOT_NULL(strstr(page, "\\\"limit\\\":1"));ASSERT_NOT_NULL(strstr(page, "\\\"returned\\\":1"));ASSERT_NOT_NULL(strstr(page, "\\\"has_more\\\":true"));@@ -16784,7 +16847,8 @@ TEST(tool_resolve_store_by_internal_name_issue704) {char *details = cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":13,\"method\":\"tools/call\",""\"params\":{\"name\":\"list_projects\","- "\"arguments\":{\"offset\":0,\"limit\":1,\"include_details\":true}}}");+ "\"arguments\":{\"offset\":0,\"limit\":1,\"include_details\":true,"+ "\"format\":\"json\"}}}");ASSERT_NOT_NULL(details);ASSERT_NOT_NULL(strstr(details, "\\\"nodes\\\""));free(details);