Skip to content

Commit 995760b

Browse files
authored
Merge pull request DeusData#1617 from SunneeYang/agent/fix-coverage-truncated-ignored
fix(mcp): preserve exact-path coverage when ignored records truncate
2 parents 1beb6d8 + a8283e9 commit 995760b

2 files changed

Lines changed: 79 additions & 5 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,8 @@ static void coverage_add_row_json(yyjson_mut_doc *doc, yyjson_mut_val *array,
42134213

42144214
static const char *coverage_status(const cbm_coverage_row_t *rows, int count,
42154215
const char *requested_path, const char *recording_status,
4216-
bool generation_matches, bool lookup_ok) {
4216+
bool generation_matches, bool lookup_ok,
4217+
bool exact_path_verified) {
42174218
if (!lookup_ok) {
42184219
return "coverage_unavailable";
42194220
}
@@ -4241,7 +4242,10 @@ static const char *coverage_status(const cbm_coverage_row_t *rows, int count,
42414242
}
42424243
}
42434244
}
4244-
if (!generation_matches || !recording_status || strcmp(recording_status, "complete") != 0) {
4245+
bool recording_complete = recording_status && strcmp(recording_status, "complete") == 0;
4246+
bool truncated_exact_path_verified =
4247+
exact_path_verified && recording_status && strcmp(recording_status, "truncated") == 0;
4248+
if (!generation_matches || (!recording_complete && !truncated_exact_path_verified)) {
42454249
return "coverage_unavailable";
42464250
}
42474251
return "no_recorded_issue";
@@ -4358,9 +4362,12 @@ static char *handle_check_index_coverage(cbm_mcp_server_t *srv, const char *args
43584362
bool outside = false;
43594363
const char *freshness = coverage_path_freshness(
43604364
store, project, have_project ? proj.root_path : NULL, rel, &outside);
4361-
const char *status = outside ? "outside_project"
4362-
: coverage_status(rows, row_count, rel, recording_status,
4363-
generation_matches, lookup_ok);
4365+
bool exact_path_verified =
4366+
have_meta && meta.hash_records_complete && strcmp(freshness, "metadata_match") == 0;
4367+
const char *status =
4368+
outside ? "outside_project"
4369+
: coverage_status(rows, row_count, rel, recording_status,
4370+
generation_matches, lookup_ok, exact_path_verified);
43644371
yyjson_mut_obj_add_strcpy(doc, item, "status", status);
43654372
yyjson_mut_obj_add_strcpy(doc, item, "freshness", freshness);
43664373
yyjson_mut_obj_add_strcpy(doc, item, "recommended_action",

‎tests/test_mcp.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,72 @@ static int write_coverage_meta(cbm_store_t *store, const char *generation,
25312531
return cbm_store_coverage_replace_ex(store, "test-project", NULL, 0, &meta);
25322532
}
25332533

2534+
TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_issue1613) {
2535+
char tmp[256];
2536+
cbm_mcp_server_t *srv = setup_snippet_server(tmp, sizeof(tmp));
2537+
ASSERT_NOT_NULL(srv);
2538+
cbm_store_t *store = cbm_mcp_server_store(srv);
2539+
ASSERT_NOT_NULL(store);
2540+
char source_path[512];
2541+
snprintf(source_path, sizeof(source_path), "%s/project/main.go", tmp);
2542+
struct stat source_stat;
2543+
ASSERT_EQ(stat(source_path, &source_stat), 0);
2544+
#ifdef __APPLE__
2545+
int64_t source_mtime_ns =
2546+
((int64_t)source_stat.st_mtimespec.tv_sec * (int64_t)CBM_NSEC_PER_SEC) +
2547+
(int64_t)source_stat.st_mtimespec.tv_nsec;
2548+
#elif defined(_WIN32)
2549+
int64_t source_mtime_ns =
2550+
(int64_t)source_stat.st_mtime * (int64_t)CBM_NSEC_PER_SEC;
2551+
#else
2552+
int64_t source_mtime_ns =
2553+
((int64_t)source_stat.st_mtim.tv_sec * (int64_t)CBM_NSEC_PER_SEC) +
2554+
(int64_t)source_stat.st_mtim.tv_nsec;
2555+
#endif
2556+
ASSERT_EQ(cbm_store_upsert_file_hash(store, "test-project", "main.go", "",
2557+
source_mtime_ns, source_stat.st_size),
2558+
CBM_STORE_OK);
2559+
cbm_project_t project = {0};
2560+
ASSERT_EQ(cbm_store_get_project(store, "test-project", &project), CBM_STORE_OK);
2561+
cbm_coverage_meta_t meta = {
2562+
.generation = project.indexed_at,
2563+
.index_mode = "fast",
2564+
.recorded_at = "2026-07-12T00:00:00Z",
2565+
.recording_status = "truncated",
2566+
.ignored_files_stored = 2000,
2567+
.ignored_files_total = 2001,
2568+
.coverage_version = 1,
2569+
.hash_records_complete = true,
2570+
};
2571+
ASSERT_EQ(cbm_store_coverage_replace_ex(store, "test-project", NULL, 0, &meta),
2572+
CBM_STORE_OK);
2573+
cbm_project_free_fields(&project);
2574+
2575+
char *response = cbm_mcp_handle_tool(
2576+
srv, "check_index_coverage",
2577+
"{\"project\":\"test-project\",\"paths\":[\"main.go\"],\"scopes\":[\".\"]}");
2578+
ASSERT_NOT_NULL(response);
2579+
char *inner = extract_text_content(response);
2580+
ASSERT_NOT_NULL(inner);
2581+
yyjson_doc *doc = yyjson_read(inner, strlen(inner), 0);
2582+
ASSERT_NOT_NULL(doc);
2583+
yyjson_val *root = yyjson_doc_get_root(doc);
2584+
yyjson_val *path = yyjson_arr_get(yyjson_obj_get(root, "paths"), 0);
2585+
ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(path, "status")), "no_recorded_issue");
2586+
ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(path, "freshness")), "metadata_match");
2587+
ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(path, "recommended_action")),
2588+
"use_graph_with_best_effort_caveat");
2589+
yyjson_val *scope = yyjson_arr_get(yyjson_obj_get(root, "scopes"), 0);
2590+
ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(scope, "status")), "coverage_unavailable");
2591+
2592+
yyjson_doc_free(doc);
2593+
free(inner);
2594+
free(response);
2595+
cbm_mcp_server_free(srv);
2596+
cleanup_snippet_dir(tmp);
2597+
PASS();
2598+
}
2599+
25342600
TEST(tool_check_index_coverage_rejects_stale_generation) {
25352601
char tmp[256];
25362602
cbm_mcp_server_t *srv = setup_snippet_server(tmp, sizeof(tmp));
@@ -10611,6 +10677,7 @@ SUITE(mcp) {
1061110677
RUN_TEST(tool_check_index_coverage_finds_path_beyond_status_cap);
1061210678
RUN_TEST(tool_check_index_coverage_reports_paths_scopes_and_ranges);
1061310679
RUN_TEST(tool_check_index_coverage_preserves_multiple_scope_labels);
10680+
RUN_TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_issue1613);
1061410681
RUN_TEST(tool_check_index_coverage_rejects_stale_generation);
1061510682
RUN_TEST(tool_check_index_coverage_requires_source_when_file_metadata_changed);
1061610683
RUN_TEST(tool_check_index_coverage_surfaces_lookup_errors);

0 commit comments

Comments
 (0)