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(coverage): name the whole-file number for what it is, a range end (#963)
Joshua Richterf871178b8c92
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex d9f61ee2b..945c9cc99 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -6059,8 +6059,11 @@ static void add_coverage_report(yyjson_mut_doc *doc, yyjson_mut_val *root, cbm_syyjson_mut_val *fe = yyjson_mut_obj(doc);yyjson_mut_obj_add_strcpy(doc, fe, "path", rows[i].rel_path);yyjson_mut_obj_add_bool(doc, fe, "whole_file", true);+ /* The end of the range, not the length of the file. A grammar+ * can end an error node past the last line, so this number can+ * be larger than the file. See range_end_is_not_file_length. */const char *dash = rows[i].detail ? strchr(rows[i].detail, '-') : NULL;- yyjson_mut_obj_add_int(doc, fe, "lines", dash ? atoi(dash + 1) : 0);+ yyjson_mut_obj_add_int(doc, fe, "range_end", dash ? atoi(dash + 1) : 0);yyjson_mut_arr_add_val(pu_files, fe);}pu_n++;@@ -6370,8 +6373,8 @@ static void coverage_add_row_json(yyjson_mut_doc *doc, yyjson_mut_val *array,row->rel_path && strcmp(row->rel_path, requested_path) == 0 ? "exact" : "ancestor");}bool ranges_added = false;- if (row->kind && (strcmp(row->kind, "parse_partial") == 0 ||- strcmp(row->kind, "parse_unusable") == 0)) {+ if (row->kind &&+ (strcmp(row->kind, "parse_partial") == 0 || strcmp(row->kind, "parse_unusable") == 0)) {ranges_added = coverage_add_ranges(doc, item, row->detail);}/* A parse_partial detail such as "3-4,9" is byte-for-byte redundant once@@ -10124,13 +10127,13 @@ static void add_parse_partial_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,/* Attach the whole-file half of the coverage summary. Always emits a top-level* "parse_unusable_count" (0 on clean runs) so the CI coverage gate can read it* without parsing anything else. When files were flagged:- * "parse_unusable": {"files":[{path,lines,whole_file}..(<=50)], "count":N,+ * "parse_unusable": {"files":[{path,range_end,whole_file}..(<=50)], "count":N,* "truncated":bool, "note":"..."}** These files WERE indexed, exactly like parse_partial ones. The difference is* that their range covers 80% or more of the file, so the range is not worth- * printing — "lines" gives the size and "whole_file" says plainly that reading- * the ranges is the same as reading the file. */+ * printing — "range_end" gives the last line the range names and "whole_file"+ * says plainly that reading the ranges is the same as reading the file. */static void add_parse_unusable_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,const cbm_file_error_t *errs, int count) {int unusable = 0;@@ -10153,9 +10156,11 @@ static void add_parse_unusable_summary(yyjson_mut_doc *doc, yyjson_mut_val *rootyyjson_mut_val *fe = yyjson_mut_obj(doc);yyjson_mut_obj_add_strcpy(doc, fe, "path", errs[i].path ? errs[i].path : "");yyjson_mut_obj_add_bool(doc, fe, "whole_file", true);- /* The range string is "start-end"; its end line is the file length. */+ /* The end of the range, not the length of the file. A grammar can end+ * an error node past the last line, so this number can be larger than+ * the file. See range_end_is_not_file_length. */const char *dash = errs[i].reason ? strchr(errs[i].reason, '-') : NULL;- yyjson_mut_obj_add_int(doc, fe, "lines", dash ? atoi(dash + 1) : 0);+ yyjson_mut_obj_add_int(doc, fe, "range_end", dash ? atoi(dash + 1) : 0);yyjson_mut_arr_add_val(files, fe);shown++;}diff --git a/tests/test_index_resilience.c b/tests/test_index_resilience.cindex 78107953d..f804aebdb 100644--- a/tests/test_index_resilience.c+++ b/tests/test_index_resilience.c@@ -488,6 +488,94 @@ TEST(index_parse_partial_reported) {PASS();}+/* The whole-file class as index_status prints it, and what its number means.+ *+ * Each parse_unusable entry reports the END of the file's one range. The field+ * was called "lines", which reads as the length of the file, and the two are+ * not the same number — a grammar can end an error node past the last line,+ * which this repo has already seen (a 326-line PowerShell file whose range+ * ended at 327). "lines" also already means a definition's line span in the+ * rest of this response, so the old name collided as well.+ *+ * The end line is checked against the persisted coverage row rather than a+ * constant, so the test states the property and not a measurement. */+TEST(index_parse_unusable_names_the_range_end) {+ RProj lp;+ memset(&lp, 0, sizeof(lp));+ snprintf(lp.tmpdir, sizeof(lp.tmpdir), "/tmp/cbm_resil_XXXXXX");+ if (!cbm_mkdtemp(lp.tmpdir)) {+ FAIL("mkdtemp failed");+ }+ rh_to_fwd_slashes(lp.tmpdir);++ /* Python gets no C preprocessor refinement, so a root-level ERROR still+ * reports one range over the whole file — the parse_unusable class. */+ ri_write_text(lp.tmpdir, "unparseable.py", ")))\n((( \n]]] [[[\ndef x(:\n");+ ri_write_text(lp.tmpdir, "good.py", "def alpha():\n return 1\n");++ char *resp = NULL;+ cbm_store_t *store = ri_index_capture(&lp, &resp);+ if (!resp) {+ FAIL("no MCP response");+ }+ if (!store) {+ free(resp);+ FAIL("store did not open");+ }++ /* The end line the report should be naming, read from the persisted row. */+ cbm_coverage_row_t *rows = NULL;+ int cov_count = 0;+ ASSERT_EQ(cbm_store_coverage_get(store, lp.project, &rows, &cov_count), CBM_STORE_OK);+ int want_end = 0;+ for (int i = 0; i < cov_count; i++) {+ if (rows[i].rel_path && strstr(rows[i].rel_path, "unparseable.py") && rows[i].detail) {+ const char *dash = strchr(rows[i].detail, '-');+ if (dash) {+ want_end = atoi(dash + 1);+ }+ }+ }+ cbm_store_free_coverage(rows, cov_count);+ ASSERT_GT(want_end, 0);++ yyjson_doc *d = yyjson_read(resp, strlen(resp), 0);+ ASSERT_NOT_NULL(d);+ yyjson_val *sc = yyjson_obj_get(yyjson_doc_get_root(d), "structuredContent");+ ASSERT_NOT_NULL(sc);+ ASSERT_EQ(yyjson_get_int(yyjson_obj_get(sc, "parse_unusable_count")), 1);++ yyjson_val *pu = yyjson_obj_get(sc, "parse_unusable");+ ASSERT_NOT_NULL(pu);+ yyjson_val *files = yyjson_obj_get(pu, "files");+ ASSERT_NOT_NULL(files);+ int found = 0;+ size_t idx = 0;+ size_t fmax = 0;+ yyjson_val *fe = NULL;+ yyjson_arr_foreach(files, idx, fmax, fe) {+ const char *fp = yyjson_get_str(yyjson_obj_get(fe, "path"));+ /* The clean neighbour must not be listed at all. */+ ASSERT_NULL(fp ? strstr(fp, "good.py") : NULL);+ if (!fp || !strstr(fp, "unparseable.py")) {+ continue;+ }+ found = 1;+ yyjson_val *range_end = yyjson_obj_get(fe, "range_end");+ ASSERT_NOT_NULL(range_end);+ ASSERT_EQ(yyjson_get_int(range_end), want_end);+ ASSERT_TRUE(yyjson_get_bool(yyjson_obj_get(fe, "whole_file")));+ /* The old name is gone, not kept beside the new one. */+ ASSERT_NULL(yyjson_obj_get(fe, "lines"));+ }+ ASSERT_TRUE(found);++ yyjson_doc_free(d);+ free(resp);+ rh_cleanup(&lp, store);+ PASS();+}+/* INV(parse-partial-clears-on-fix, #963): the persisted coverage signal must* stay FRESH — after the broken file is fixed and the project re-indexed* (incremental route: the DB already exists), its parse_partial row is gone@@ -813,6 +901,7 @@ SUITE(index_resilience) {RUN_TEST(index_clean_run_no_logfile);RUN_TEST(index_parse_partial_reported);RUN_TEST(index_parse_partial_clears_on_fix);+ RUN_TEST(index_parse_unusable_names_the_range_end);RUN_TEST(index_not_indexed_by_design_reported);RUN_TEST(index_relative_repo_path_canonicalized);}