Skip to content

Commit b5c89ee

Browse files
committed
test(mcp): cover truncated ignored catalogs for exact paths
Signed-off-by: SunneeYang <sunnee.yang@gmail.com>
1 parent 2235af4 commit b5c89ee

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

‎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)