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
feat(index): best-effort parse-coverage signal for partially parsed files
Martin Vogela4c17bd4671c
diff --git a/Makefile.cbm b/Makefile.cbmindex 0156f3544..907560540 100644--- a/Makefile.cbm+++ b/Makefile.cbm@@ -317,6 +317,7 @@ TEST_EXTRACTION_SRCS = \tests/test_extraction.c \tests/test_extraction_inheritance.c \tests/test_extraction_imports.c \+ tests/test_parse_coverage.c \tests/test_grammar_regression.c \tests/test_grammar_labels.c \tests/test_grammar_imports.c \diff --git a/internal/cbm/cbm.c b/internal/cbm/cbm.cindex f38eaad69..c1becbfe2 100644--- a/internal/cbm/cbm.c+++ b/internal/cbm/cbm.c@@ -688,6 +688,61 @@ static CBMFileResult *cbm_extract_file_impl(const char *source, int source_len,const char *rel_path, int64_t timeout_micros,const char **extra_defines, const char **include_paths);+/* Best-effort parse-coverage collection (#963). Walks only the has_error paths+ * of the tree and records the 1-based line ranges of the TOP-MOST ERROR/MISSING+ * nodes (does not descend into an error subtree — one range per failed region).+ * Bounded by CBM_MAX_ERROR_REGIONS so pathological input can't blow up the+ * output. The ranges mark where constructs were dropped; they are a detection+ * aid, never a completeness proof. */+#define CBM_MAX_ERROR_REGIONS 64+typedef struct {+ uint32_t starts[CBM_MAX_ERROR_REGIONS];+ uint32_t ends[CBM_MAX_ERROR_REGIONS];+ int count;+} cbm_error_regions_t;++static void cbm_error_regions_push(cbm_error_regions_t *acc, TSNode n) {+ if (acc->count >= CBM_MAX_ERROR_REGIONS) {+ return;+ }+ acc->starts[acc->count] = ts_node_start_point(n).row + 1;+ acc->ends[acc->count] = ts_node_end_point(n).row + 1;+ acc->count++;+}++static void cbm_collect_error_regions(TSNode n, cbm_error_regions_t *acc) {+ if (acc->count >= CBM_MAX_ERROR_REGIONS) {+ return;+ }+ uint32_t k = ts_node_child_count(n);+ for (uint32_t i = 0; i < k && acc->count < CBM_MAX_ERROR_REGIONS; i++) {+ TSNode c = ts_node_child(n, i);+ if (ts_node_is_missing(c) || strcmp(ts_node_type(c), "ERROR") == 0) {+ cbm_error_regions_push(acc, c); /* top-most region; do not descend */+ } else if (ts_node_has_error(c)) {+ cbm_collect_error_regions(c, acc);+ }+ }+}++/* Serialize collected regions as "start-end,start-end,..." into the arena. */+static const char *cbm_error_ranges_str(CBMArena *a, const cbm_error_regions_t *regs) {+ if (regs->count <= 0) {+ return NULL;+ }+ enum { RANGE_MAX = 24 }; /* "4294967295-4294967295," */+ char *buf = (char *)cbm_arena_alloc(a, (size_t)regs->count * RANGE_MAX);+ if (!buf) {+ return NULL;+ }+ size_t off = 0;+ for (int i = 0; i < regs->count; i++) {+ off += (size_t)snprintf(buf + off, RANGE_MAX, "%s%u-%u", i ? "," : "", regs->starts[i],+ regs->ends[i]);+ }+ return buf;+}+/* Public entry: run the extraction and journal completion. The DONE mark on* every ordinary return (including error/timeout results) tells the crash* supervisor this file did NOT kill the worker — only a file whose S has no@@ -788,6 +843,22 @@ static CBMFileResult *cbm_extract_file_impl(const char *source, int source_len,TSNode root = ts_tree_root_node(tree);+ /* Best-effort parse-coverage signal (#963): flag files whose tree contains+ * ERROR/MISSING nodes — constructs inside those regions are silently absent+ * from the graph. Detection aid only: the absence of this flag is NOT a+ * completeness guarantee. */+ if (ts_node_has_error(root)) {+ result->parse_incomplete = true;+ cbm_error_regions_t regs = {{0}, {0}, 0};+ if (strcmp(ts_node_type(root), "ERROR") == 0) {+ cbm_error_regions_push(®s, root); /* whole file unparseable */+ } else {+ cbm_collect_error_regions(root, ®s);+ }+ result->error_region_count = regs.count;+ result->error_ranges = cbm_error_ranges_str(a, ®s);+ }+// Compute module QN. Java/Go derive the module from the CONTAINING// DIRECTORY (package semantics) rather than baking the filename stem in,// so def QNs, the LSP caller_qn, and the textual calls-enclosing QN alldiff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.hindex 6b4228131..27ebb71a8 100644--- a/internal/cbm/cbm.h+++ b/internal/cbm/cbm.h@@ -447,6 +447,16 @@ typedef struct {bool has_error;const char *error_msg;+ /* Best-effort parse-coverage signal (experimental). parse_incomplete is true+ * when the parse tree contains tree-sitter ERROR/MISSING nodes — constructs+ * in those regions are silently absent from the graph. error_ranges is a+ * compact "start-end,start-end" list of 1-based line ranges (arena-owned) or+ * NULL. This only marks what we can DETECT: the absence of a flag is NOT a+ * completeness guarantee. Callers should treat a flagged file as "prefer+ * grep here", never treat an unflagged file as provably complete. */+ bool parse_incomplete;+ const char *error_ranges;+ int error_region_count;bool is_test_file;int imports_count;TSTree *cached_tree; // retained parse tree (caller frees via cbm_free_tree)diff --git a/src/graph_buffer/graph_buffer.c b/src/graph_buffer/graph_buffer.cindex ca541e7d4..965cdd242 100644--- a/src/graph_buffer/graph_buffer.c+++ b/src/graph_buffer/graph_buffer.c@@ -769,6 +769,24 @@ const cbm_gbuf_node_t *cbm_gbuf_find_by_qn(const cbm_gbuf_t *gb, const char *qn)return cbm_ht_get(gb->node_by_qn, qn);}+bool cbm_gbuf_set_node_props(cbm_gbuf_t *gb, const char *qualified_name,+ const char *properties_json) {+ if (!gb || !qualified_name || !properties_json) {+ return false;+ }+ cbm_gbuf_node_t *node = cbm_ht_get(gb->node_by_qn, qualified_name);+ if (!node) {+ return false;+ }+ char *new_props = heap_strdup(properties_json);+ if (!new_props) {+ return false;+ }+ free(node->properties_json);+ node->properties_json = new_props;+ return true;+}+const cbm_gbuf_node_t *cbm_gbuf_find_by_id(const cbm_gbuf_t *gb, int64_t id) {if (!gb || !gb->by_id || id < 0 || id >= gb->by_id_cap) {return NULL;diff --git a/src/graph_buffer/graph_buffer.h b/src/graph_buffer/graph_buffer.hindex 6c8c6babe..8cea45413 100644--- a/src/graph_buffer/graph_buffer.h+++ b/src/graph_buffer/graph_buffer.h@@ -73,6 +73,13 @@ int64_t cbm_gbuf_upsert_node(cbm_gbuf_t *gb, const char *label, const char *nameconst char *qualified_name, const char *file_path, int start_line,int end_line, const char *properties_json);+/* Replace an existing node's properties_json by qualified name (copied).+ * Bypasses the upsert survivor rule — use for post-hoc annotation of a node+ * that is known to exist (e.g. parse-coverage markers on File nodes, #963).+ * Returns true when the node was found and updated. */+bool cbm_gbuf_set_node_props(cbm_gbuf_t *gb, const char *qualified_name,+ const char *properties_json);+/* Find a node by qualified name. Returns NULL if not found. */const cbm_gbuf_node_t *cbm_gbuf_find_by_qn(const cbm_gbuf_t *gb, const char *qn);diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex 6702fd1c9..c87fbdfe8 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -316,7 +316,14 @@ static const tool_def_t TOOLS[] = {"Index a repository into the knowledge graph. ""Special mode 'cross-repo-intelligence': skip extraction, only match Routes/Channels ""across projects to create CROSS_HTTP_CALLS/CROSS_ASYNC_CALLS/CROSS_CHANNEL edges. "- "Requires target_projects param. Ensure target projects have fresh indexes first.",+ "Requires target_projects param. Ensure target projects have fresh indexes first. "+ "COVERAGE: the response reports files that were NOT fully indexed — 'skipped' (not "+ "indexed at all: oversized/read/parse failures) and 'parse_partial' (indexed, but "+ "constructs inside the listed line ranges could not be parsed and are absent from the "+ "graph). parse_partial files also carry {parse_incomplete:true, error_ranges} on their "+ "File node — query later via query_graph: MATCH (f:File) WHERE f.parse_incomplete = true "+ "RETURN f. Both signals are best-effort: absence of a flag is NOT a completeness "+ "guarantee; prefer grep inside flagged ranges.","{\"type\":\"object\",\"properties\":{\"repo_path\":{\"type\":\"string\",\"description\":""\"Path to the repository\"},""\"mode\":{\"type\":\"string\","@@ -3299,36 +3306,100 @@ static void add_excluded_summary(yyjson_mut_doc *doc, yyjson_mut_val *root, char* the JSON carries "count" + "truncated" so nothing is silently hidden. */enum { INDEX_SKIPPED_FILE_CAP = 50 };+/* True when a recorded per-file entry is the parse-partial coverage signal+ * (#963) rather than a genuine skip. Kept out of skipped[]/skipped_count so+ * the "skipped" contract (file NOT indexed) stays exact. */+static bool is_parse_partial(const cbm_file_error_t *e) {+ return e->phase && strcmp(e->phase, "parse_partial") == 0;+}+/* Attach a summary of per-file skips (Stage 2 / Track B). Always emits a* top-level "skipped_count" (0 on clean runs) so consumers can rely on it.* When there are skips, also emits:* "skipped": {"files":[{path,reason,phase}..(<=50)], "count":N, "truncated":bool}* and, if a per-run logfile was written, "logfile": "<path>".* The run status stays "indexed" — a skipped file is the expected handled- * outcome, not a failure. errs[] is borrowed (copied into doc). */+ * outcome, not a failure. errs[] is borrowed (copied into doc) and may contain+ * parse_partial entries, which are filtered out here (reported separately by+ * add_parse_partial_summary). */static void add_skipped_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,const cbm_file_error_t *errs, int count, const char *logfile) {- yyjson_mut_obj_add_int(doc, root, "skipped_count", count < 0 ? 0 : count);- if (!errs || count <= 0) {+ int skips = 0;+ for (int i = 0; i < count; i++) {+ if (!is_parse_partial(&errs[i])) {+ skips++;+ }+ }+ yyjson_mut_obj_add_int(doc, root, "skipped_count", skips);+ if (logfile && logfile[0]) {+ yyjson_mut_obj_add_strcpy(doc, root, "logfile", logfile);+ }+ if (!errs || skips <= 0) {return;}yyjson_mut_val *skipped = yyjson_mut_obj(doc);yyjson_mut_val *files = yyjson_mut_arr(doc);- int shown = count < INDEX_SKIPPED_FILE_CAP ? count : INDEX_SKIPPED_FILE_CAP;- for (int i = 0; i < shown; i++) {+ int shown = 0;+ for (int i = 0; i < count && shown < INDEX_SKIPPED_FILE_CAP; i++) {+ if (is_parse_partial(&errs[i])) {+ continue;+ }yyjson_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_strcpy(doc, fe, "reason", errs[i].reason ? errs[i].reason : "");yyjson_mut_obj_add_strcpy(doc, fe, "phase", errs[i].phase ? errs[i].phase : "");yyjson_mut_arr_add_val(files, fe);+ shown++;}yyjson_mut_obj_add_val(doc, skipped, "files", files);- yyjson_mut_obj_add_int(doc, skipped, "count", count);- yyjson_mut_obj_add_bool(doc, skipped, "truncated", count > INDEX_SKIPPED_FILE_CAP);+ yyjson_mut_obj_add_int(doc, skipped, "count", skips);+ yyjson_mut_obj_add_bool(doc, skipped, "truncated", skips > INDEX_SKIPPED_FILE_CAP);yyjson_mut_obj_add_val(doc, root, "skipped", skipped);- if (logfile && logfile[0]) {- yyjson_mut_obj_add_strcpy(doc, root, "logfile", logfile);+}++/* Attach the best-effort parse-coverage summary (#963). Always emits a+ * top-level "parse_partial_count" (0 on clean runs). When files were flagged:+ * "parse_partial": {"files":[{path,error_ranges}..(<=50)], "count":N,+ * "truncated":bool, "note":"..."}+ * These files WERE indexed — constructs inside the listed 1-based line ranges+ * are missing from the graph because tree-sitter could not parse them. The+ * note spells out the best-effort framing: absence from this list is NOT a+ * completeness guarantee. */+static void add_parse_partial_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,+ const cbm_file_error_t *errs, int count) {+ int partials = 0;+ for (int i = 0; i < count; i++) {+ if (is_parse_partial(&errs[i])) {+ partials++;+ }+ }+ yyjson_mut_obj_add_int(doc, root, "parse_partial_count", partials);+ if (!errs || partials <= 0) {+ return;}+ yyjson_mut_val *pp = yyjson_mut_obj(doc);+ yyjson_mut_val *files = yyjson_mut_arr(doc);+ int shown = 0;+ for (int i = 0; i < count && shown < INDEX_SKIPPED_FILE_CAP; i++) {+ if (!is_parse_partial(&errs[i])) {+ continue;+ }+ yyjson_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_strcpy(doc, fe, "error_ranges", errs[i].reason ? errs[i].reason : "");+ yyjson_mut_arr_add_val(files, fe);+ shown++;+ }+ yyjson_mut_obj_add_val(doc, pp, "files", files);+ yyjson_mut_obj_add_int(doc, pp, "count", partials);+ yyjson_mut_obj_add_bool(doc, pp, "truncated", partials > INDEX_SKIPPED_FILE_CAP);+ yyjson_mut_obj_add_str(doc, pp, "note",+ "Best-effort signal, not a completeness guarantee: these files WERE "+ "indexed, but constructs inside the listed line ranges (1-based) could "+ "not be parsed and are missing from the graph. Prefer text search "+ "(grep) for those regions. Files absent from this list are NOT "+ "guaranteed to be fully indexed.");+ yyjson_mut_obj_add_val(doc, root, "parse_partial", pp);}/* Write the FULL (uncapped) skip list to a per-run logfile — ONLY when >=1 file@@ -3360,8 +3431,15 @@ static bool write_skip_logfile(const char *project, const cbm_file_error_t *errscbm_log_warn("index.logfile_open_fail", "path", path);return false;}- (void)fprintf(f, "# codebase-memory-mcp index skip report\n");- (void)fprintf(f, "# project=%s skipped=%d\n", project ? project : "", count);+ int partials = 0;+ for (int i = 0; i < count; i++) {+ if (is_parse_partial(&errs[i])) {+ partials++;+ }+ }+ (void)fprintf(f, "# codebase-memory-mcp index coverage report\n");+ (void)fprintf(f, "# project=%s skipped=%d parse_partial=%d\n", project ? project : "",+ count - partials, partials);(void)fprintf(f, "# columns: phase\treason\tpath\n");for (int i = 0; i < count; i++) {(void)fprintf(f, "%s\t%s\t%s\n", errs[i].phase ? errs[i].phase : "",@@ -3384,6 +3462,7 @@ static bool build_index_success_response(cbm_mcp_server_t *srv, yyjson_mut_doc *const char *logfile) {add_excluded_summary(doc, root, excluded_dirs, excluded_count);add_skipped_summary(doc, root, file_errors, file_error_count, logfile);+ add_parse_partial_summary(doc, root, file_errors, file_error_count);int exp_nodes = -1;int exp_edges = -1;diff --git a/src/pipeline/pass_definitions.c b/src/pipeline/pass_definitions.cindex acda8b226..21f5360c9 100644--- a/src/pipeline/pass_definitions.c+++ b/src/pipeline/pass_definitions.c@@ -581,6 +581,12 @@ int cbm_pipeline_pass_definitions(cbm_pipeline_ctx_t *ctx, const cbm_file_info_tresult->error_msg ? result->error_msg : "extract failed","extract");errors++;+ } else if (result->parse_incomplete) {+ /* Best-effort parse-coverage signal (#963): indexed, but with+ * ERROR/MISSING regions — see pass_parallel.c (keep in sync). */+ cbm_pipeline_add_file_error(ctx->pipeline, rel,+ result->error_ranges ? result->error_ranges : "unknown",+ "parse_partial");}/* Create nodes for each definition */diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.cindex 8e0d35691..7f85f81f2 100644--- a/src/pipeline/pass_parallel.c+++ b/src/pipeline/pass_parallel.c@@ -902,6 +902,14 @@ static void extract_worker(int worker_id, void *ctx_ptr) {pp_err_add(errs, fi->rel_path, result->error_msg ? result->error_msg : "extract failed","extract");ws->errors++;+ } else if (result->parse_incomplete) {+ /* Best-effort parse-coverage signal (#963): the file WAS indexed,+ * but its tree contains ERROR/MISSING regions whose constructs are+ * silently absent from the graph. Not a skip — recorded under the+ * distinct "parse_partial" phase (reason = the line-range list) so+ * the MCP layer reports it separately from skipped[]. */+ pp_err_add(errs, fi->rel_path, result->error_ranges ? result->error_ranges : "unknown",+ "parse_partial");}/* Create definition nodes in local gbuf */diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex cacfd7639..dbce7198b 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -315,6 +315,40 @@ void cbm_pipeline_get_file_errors(const cbm_pipeline_t *p, cbm_file_error_t **ou}}+void cbm_pipeline_stamp_parse_partial(cbm_pipeline_t *p, cbm_gbuf_t *gbuf) {+ if (!p || !gbuf) {+ return;+ }+ int stamped = 0;+ for (int i = 0; i < p->file_errors_count; i++) {+ const cbm_file_error_t *e = &p->file_errors[i];+ if (!e->path || !e->phase || strcmp(e->phase, "parse_partial") != 0) {+ continue;+ }+ char *file_qn = cbm_pipeline_fqn_compute(p->project_name, e->path, "__file__");+ if (!file_qn) {+ continue;+ }+ const char *slash = strrchr(e->path, '/');+ const char *basename = slash ? slash + SKIP_ONE : e->path;+ const char *ext = strrchr(basename, '.');+ /* Full replacement props (set_node_props does not merge): keep the+ * "extension" key pass_structure wrote, add the coverage marker. The+ * ranges string is digits/commas/dashes — JSON-safe unescaped. */+ char props[CBM_SZ_2K];+ snprintf(props, sizeof(props),+ "{\"extension\":\"%s\",\"parse_incomplete\":true,\"error_ranges\":\"%s\"}",+ ext ? ext : "", e->reason ? e->reason : "");+ if (cbm_gbuf_set_node_props(gbuf, file_qn, props)) {+ stamped++;+ }+ free(file_qn);+ }+ if (stamped > 0) {+ cbm_log_info("index.parse_partial", "files", itoa_buf(stamped));+ }+}+void cbm_pipeline_get_committed_counts(const cbm_pipeline_t *p, int *nodes, int *edges) {if (nodes) {*nodes = p ? p->committed_nodes : -1;@@ -1262,6 +1296,11 @@ static int run_extraction_phase(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,if (check_cancel(p)) {return CBM_NOT_FOUND;}+ if (rc == 0) {+ /* Extraction merged its per-file errors — stamp parse-partial File+ * nodes (#963) before downstream passes and the dump. */+ cbm_pipeline_stamp_parse_partial(p, p->gbuf);+ }return rc;}diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.hindex 535c717fe..bb253979b 100644--- a/src/pipeline/pipeline.h+++ b/src/pipeline/pipeline.h@@ -89,11 +89,19 @@ void cbm_pipeline_get_committed_counts(const cbm_pipeline_t *p, int *nodes, inttypedef struct {char *path; /* repo-relative path of the skipped file */char *reason; /* human-readable cause (e.g. "oversized (712 MB > 512 MB)",- * "parse timeout", "read failed") */- char *phase; /* "read" | "extract" | "oversized". "cross_lsp" is a RESERVED- * phase string for Track C's crash-attribution signal and is- * intentionally NOT emitted today (the cross-LSP passes are- * best-effort/void with no genuine per-file failure). */+ * "parse timeout", "read failed"). For phase "parse_partial"+ * this carries the 1-based line-range list ("12-40,88-90")+ * of the unparseable regions. */+ char *phase; /* "read" | "extract" | "oversized" | "parse_partial".+ * "parse_partial" (#963) is NOT a skip: the file WAS indexed+ * but contains tree-sitter ERROR/MISSING regions whose+ * constructs are absent from the graph (best-effort signal —+ * absence of the flag is NOT a completeness guarantee). The+ * MCP layer reports it separately from skipped[]. "cross_lsp"+ * is a RESERVED phase string for Track C's crash-attribution+ * signal and is intentionally NOT emitted today (the+ * cross-LSP passes are best-effort/void with no genuine+ * per-file failure). */} cbm_file_error_t;/* Record a skipped file. path/reason/phase are copied. NULL-safe on p.diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.cindex 1fa320d86..4b5cedf8f 100644--- a/src/pipeline/pipeline_incremental.c+++ b/src/pipeline/pipeline_incremental.c@@ -840,6 +840,10 @@ int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_fil}run_extract_resolve(&ctx, changed_files, ci);+ /* Stamp parse-partial File nodes (#963) for the changed slice. A changed+ * file that parses cleanly now got fresh "{}" props above, so a stale+ * marker from a previous run cannot survive the reindex. */+ cbm_pipeline_stamp_parse_partial(p, existing);cbm_pipeline_pass_k8s(&ctx, changed_files, ci);run_postpasses(&ctx, changed_files, ci, project);diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.hindex a3d806558..1648bddfe 100644--- a/src/pipeline/pipeline_internal.h+++ b/src/pipeline/pipeline_internal.h@@ -520,6 +520,14 @@ void cbm_pipeline_create_route_nodes(cbm_gbuf_t *gb);/* ── Pass function prototypes ────────────────────────────────────── */+/* Stamp File nodes for files recorded under phase "parse_partial" (#963):+ * sets properties {"extension":...,"parse_incomplete":true,"error_ranges":...}+ * on the (already-existing) File node so the coverage signal is queryable in+ * the graph. Call after the extraction pass has merged its per-file errors —+ * both the full path (pipeline.c) and the incremental path+ * (pipeline_incremental.c) must call it. Implementation: pipeline.c. */+void cbm_pipeline_stamp_parse_partial(cbm_pipeline_t *p, cbm_gbuf_t *gbuf);+int cbm_pipeline_pass_definitions(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,int file_count);diff --git a/tests/test_index_resilience.c b/tests/test_index_resilience.cindex e503af58a..db8cc709f 100644--- a/tests/test_index_resilience.c+++ b/tests/test_index_resilience.c@@ -248,6 +248,11 @@ TEST(index_clean_run_no_logfile) {ASSERT_NULL(yyjson_obj_get(sc, "skipped"));ASSERT_NULL(yyjson_obj_get(sc, "logfile"));+ /* Clean parses → no parse-coverage flags either (#963). */+ int pp_count = yyjson_get_int(yyjson_obj_get(sc, "parse_partial_count"));+ ASSERT_EQ(pp_count, 0);+ ASSERT_NULL(yyjson_obj_get(sc, "parse_partial"));+int funcs = rh_count_label(store, lp.project, "Function");ASSERT_GTE(funcs, 2);@@ -257,7 +262,143 @@ TEST(index_clean_run_no_logfile) {PASS();}+/* INV(parse-partial-reported, #963): a file whose parse tree contains+ * ERROR/MISSING regions (here: the preprocessor-blind #ifdef-split-brace C+ * pattern) is INDEXED — not skipped — and the best-effort coverage signal+ * surfaces on every layer:+ * - skipped_count == 0 (a partial parse is NOT a skip),+ * - parse_partial_count >= 1 with the file + its line ranges + the+ * best-effort note in parse_partial{},+ * - the per-run logfile lists it under phase "parse_partial",+ * - the File node carries {"parse_incomplete":true,"error_ranges":...},+ * - clean neighbors still extract.+ *+ * Guard property: on the unwired code there is no parse_partial_count /+ * parse_partial[] / File-node marker — the file silently looks fully indexed.+ */+TEST(index_parse_partial_reported) {+ 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);++ /* Both #ifdef branches open `guarded(...) {` sharing ONE close brace —+ * brace-unbalanced for a preprocessor-blind parse → ERROR region. */+ ri_write_text(lp.tmpdir, "split.c",+ "void ok_before(void) { }\n"+ "#ifdef FEATURE_A\n"+ "static int guarded(int x) {\n"+ "#else\n"+ "static int guarded_alt(int x) {\n"+ "#endif\n"+ " return x + 1;\n"+ "}\n");+ ri_write_text(lp.tmpdir, "good.py", "def alpha():\n return 1\n");++ char logpath[700];+ snprintf(logpath, sizeof(logpath), "%s/coverage.log", lp.tmpdir);+ cbm_setenv("CBM_INDEX_LOG", logpath, 1);++ char *resp = NULL;+ cbm_store_t *store = ri_index_capture(&lp, &resp);+ cbm_unsetenv("CBM_INDEX_LOG");++ if (!resp) {+ FAIL("no MCP response");+ }+ if (!store) {+ free(resp);+ FAIL("store did not open");+ }++ 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);++ /* Indexed, and NOT counted as a skip. */+ const char *status = yyjson_get_str(yyjson_obj_get(sc, "status"));+ ASSERT_NOT_NULL(status);+ ASSERT_STR_EQ("indexed", status);+ ASSERT_EQ(yyjson_get_int(yyjson_obj_get(sc, "skipped_count")), 0);++ /* The coverage signal is surfaced with ranges + the best-effort note. */+ ASSERT_GTE(yyjson_get_int(yyjson_obj_get(sc, "parse_partial_count")), 1);+ yyjson_val *pp = yyjson_obj_get(sc, "parse_partial");+ ASSERT_NOT_NULL(pp);+ yyjson_val *files = yyjson_obj_get(pp, "files");+ ASSERT_NOT_NULL(files);+ int found_split = 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"));+ const char *ranges = yyjson_get_str(yyjson_obj_get(fe, "error_ranges"));+ if (fp && strstr(fp, "split.c")) {+ found_split = 1;+ ASSERT_NOT_NULL(ranges);+ ASSERT_GT((int)strlen(ranges), 0);+ }+ }+ ASSERT_TRUE(found_split);+ const char *note = yyjson_get_str(yyjson_obj_get(pp, "note"));+ ASSERT_NOT_NULL(note);+ ASSERT_NOT_NULL(strstr(note, "guarantee"));++ /* Logfile lists it under the distinct phase. */+ const char *logfile = yyjson_get_str(yyjson_obj_get(sc, "logfile"));+ ASSERT_NOT_NULL(logfile);+ char *logtext = ri_slurp(logfile);+ ASSERT_NOT_NULL(logtext);+ ASSERT_NOT_NULL(strstr(logtext, "parse_partial"));+ ASSERT_NOT_NULL(strstr(logtext, "split.c"));+ free(logtext);++ /* The File node carries the queryable marker. */+ cbm_node_t *nodes = NULL;+ int count = 0;+ int rc = cbm_store_find_nodes_by_qn_suffix(store, lp.project, "__file__", &nodes, &count);+ ASSERT_EQ(rc, CBM_STORE_OK);+ int marked = 0;+ for (int i = 0; i < count; i++) {+ if (nodes[i].file_path && strstr(nodes[i].file_path, "split.c")) {+ ASSERT_NOT_NULL(nodes[i].properties_json);+ ASSERT_NOT_NULL(strstr(nodes[i].properties_json, "\"parse_incomplete\":true"));+ ASSERT_NOT_NULL(strstr(nodes[i].properties_json, "\"error_ranges\":\""));+ marked = 1;+ }+ }+ cbm_store_free_nodes(nodes, count);+ ASSERT_TRUE(marked);++ /* The marker is queryable exactly as the index_repository tool description+ * advertises (agents are pointed at this query to find unindexed code). */+ char qargs[900];+ snprintf(qargs, sizeof(qargs),+ "{\"project\":\"%s\",\"query\":\"MATCH (f:File) WHERE f.parse_incomplete = true "+ "RETURN f.file_path, f.error_ranges\"}",+ lp.project);+ char *qresp = cbm_mcp_handle_tool(lp.srv, "query_graph", qargs);+ ASSERT_NOT_NULL(qresp);+ ASSERT_NOT_NULL(strstr(qresp, "split.c"));+ free(qresp);++ /* Clean neighbors still extract. */+ int funcs = rh_count_label(store, lp.project, "Function");+ ASSERT_GTE(funcs, 1);++ yyjson_doc_free(d);+ free(resp);+ rh_cleanup(&lp, store);+ PASS();+}+SUITE(index_resilience) {RUN_TEST(index_oversized_file_reported);RUN_TEST(index_clean_run_no_logfile);+ RUN_TEST(index_parse_partial_reported);}diff --git a/tests/test_main.c b/tests/test_main.cindex 67ba5df3d..4ca0f93c7 100644--- a/tests/test_main.c+++ b/tests/test_main.c@@ -155,6 +155,7 @@ extern void suite_subprocess(void);extern void suite_extraction(void);extern void suite_extraction_inheritance(void);extern void suite_extraction_imports(void);+extern void suite_parse_coverage(void);extern void suite_grammar_regression(void);extern void suite_grammar_labels(void);extern void suite_grammar_imports(void);@@ -286,6 +287,7 @@ int main(int argc, char **argv) {RUN_SELECTED_SUITE(extraction);RUN_SELECTED_SUITE(extraction_inheritance);RUN_SELECTED_SUITE(extraction_imports);+ RUN_SELECTED_SUITE(parse_coverage);RUN_SELECTED_SUITE(grammar_regression);RUN_SELECTED_SUITE(grammar_labels);RUN_SELECTED_SUITE(grammar_imports);diff --git a/tests/test_parse_coverage.c b/tests/test_parse_coverage.cnew file mode 100644index 000000000..3b11cfc01--- /dev/null+++ b/tests/test_parse_coverage.c@@ -0,0 +1,208 @@+/*+ * test_parse_coverage.c — Reproduce-first suite for the best-effort+ * parse-coverage signal (#963, Signal A).+ *+ * ── The gap being reproduced ────────────────────────────────────────────────+ * When tree-sitter hits a construct it cannot parse (ERROR/MISSING nodes in+ * the tree), extraction silently drops every definition inside the failed+ * region — the file looks fully indexed but is not. `ts_node_has_error(root)`+ * detects this, yet nothing consumed it: CBMFileResult gained the fields+ * parse_incomplete / error_ranges / error_region_count, but the parse site in+ * cbm_extract_file_impl never sets them.+ *+ * Canonical trigger: the preprocessor-blind #ifdef-split-brace pattern in C —+ * both branches open `fn(...) {` and share ONE closing brace, so the raw text+ * is brace-unbalanced → ERROR node → the guarded function never becomes a+ * Function node while neighbors extract fine.+ *+ * ── The contract these tests enforce ────────────────────────────────────────+ * RED (unfixed): parse_incomplete is never set → flagged-file tests fail.+ * GREEN (fixed): cbm_extract_file sets parse_incomplete=true iff the tree+ * contains ERROR/MISSING nodes, records the 1-based line+ * ranges of the TOP-MOST error regions ("start-end,..."),+ * bounded by the 64-region cap, and clean files stay+ * completely unflagged (no false positives).+ *+ * BEST-EFFORT framing (must never be weakened the other way): a flag means+ * "constructs here were dropped — prefer grep"; the ABSENCE of a flag is NOT+ * a completeness guarantee. These tests only pin down the detectable class.+ */++#include "test_framework.h"+#include "cbm.h"+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++/* Convenience extract wrapper (same shape as test_extraction_imports.c). */+static CBMFileResult *do_extract(const char *src, CBMLanguage lang, const char *path) {+ return cbm_extract_file(src, (int)strlen(src), lang, "covproj", path, 0, NULL, NULL);+}++/* Return 1 if any extracted definition has the given short name. */+static int has_def(CBMFileResult *r, const char *name) {+ for (int i = 0; i < r->defs.count; i++) {+ if (r->defs.items[i].name && strcmp(r->defs.items[i].name, name) == 0) {+ return 1;+ }+ }+ return 0;+}++/* ── Fixtures ─────────────────────────────────────────────────────────────── */++/* #ifdef-split-brace: both branches open `guarded(...) {`, one shared `}`.+ * Preprocessor-blind parse sees unbalanced braces → ERROR region around+ * lines 5–11; ok_before/ok_after remain extractable. */+static const char *C_IFDEF_SPLIT = "#include <stdio.h>\n" /* 1 */+ "\n" /* 2 */+ "void ok_before(void) { printf(\"a\"); }\n" /* 3 */+ "\n" /* 4 */+ "#ifdef FEATURE_A\n" /* 5 */+ "static int guarded(int x) {\n" /* 6 */+ "#else\n" /* 7 */+ "static int guarded_alt(int x) {\n" /* 8 */+ "#endif\n" /* 9 */+ " return x + 1;\n" /* 10 */+ "}\n" /* 11 */+ "\n" /* 12 */+ "void ok_after(void) { printf(\"b\"); }\n"; /* 13 */++static const char *C_CLEAN = "#include <stdio.h>\n"+ "\n"+ "void alpha(void) { printf(\"a\"); }\n"+ "\n"+ "static int beta(int x) {\n"+ " return x + 1;\n"+ "}\n";++static const char *PY_BROKEN = "def ok():\n"+ " return 1\n"+ "\n"+ "def broken(:\n"+ " pass\n"+ "\n"+ "def ok2():\n"+ " return 2\n";++static const char *PY_CLEAN = "def ok():\n"+ " return 1\n"+ "\n"+ "def ok2():\n"+ " return 2\n";++/* ── Tests ────────────────────────────────────────────────────────────────── */++TEST(c_ifdef_split_brace_sets_parse_incomplete) {+ CBMFileResult *r = do_extract(C_IFDEF_SPLIT, CBM_LANG_C, "split.c");+ ASSERT_NOT_NULL(r);+ ASSERT_FALSE(r->has_error); /* parse succeeded — this is the silent-partial class */+ ASSERT_TRUE(r->parse_incomplete);+ ASSERT_GTE(r->error_region_count, 1);+ ASSERT_NOT_NULL(r->error_ranges);+ ASSERT_GT((int)strlen(r->error_ranges), 0);+ cbm_free_result(r);+ PASS();+}++TEST(c_ifdef_split_brace_neighbors_still_extracted) {+ /* Documents WHY the flag matters: the file is partially indexed —+ * neighbors extract, so nothing else hints at the dropped region. */+ CBMFileResult *r = do_extract(C_IFDEF_SPLIT, CBM_LANG_C, "split.c");+ ASSERT_NOT_NULL(r);+ ASSERT_TRUE(has_def(r, "ok_before"));+ ASSERT_TRUE(r->parse_incomplete);+ cbm_free_result(r);+ PASS();+}++TEST(c_error_range_points_at_failed_region) {+ /* The recorded range must overlap the #ifdef construct (lines 5–11) so an+ * agent can be pointed at the exact unparsed region. Format is+ * "start-end[,start-end...]", 1-based, inclusive. */+ CBMFileResult *r = do_extract(C_IFDEF_SPLIT, CBM_LANG_C, "split.c");+ ASSERT_NOT_NULL(r);+ ASSERT_TRUE(r->parse_incomplete);+ ASSERT_NOT_NULL(r->error_ranges);+ unsigned int start = 0;+ unsigned int end = 0;+ ASSERT_EQ(sscanf(r->error_ranges, "%u-%u", &start, &end), 2);+ ASSERT_GTE(start, 1u);+ ASSERT_LTE(start, 11u); /* starts at or before the region's last line */+ ASSERT_GTE(end, 5u); /* ends at or after the region's first line */+ ASSERT_LTE(end, 13u); /* never past EOF */+ ASSERT_LTE(start, end);+ cbm_free_result(r);+ PASS();+}++TEST(c_clean_file_not_flagged) {+ /* No false positives: a clean parse must stay completely unflagged. */+ CBMFileResult *r = do_extract(C_CLEAN, CBM_LANG_C, "clean.c");+ ASSERT_NOT_NULL(r);+ ASSERT_FALSE(r->has_error);+ ASSERT_FALSE(r->parse_incomplete);+ ASSERT_EQ(r->error_region_count, 0);+ ASSERT_NULL(r->error_ranges);+ ASSERT_TRUE(has_def(r, "alpha"));+ ASSERT_TRUE(has_def(r, "beta"));+ cbm_free_result(r);+ PASS();+}++TEST(py_syntax_error_sets_parse_incomplete) {+ CBMFileResult *r = do_extract(PY_BROKEN, CBM_LANG_PYTHON, "broken.py");+ ASSERT_NOT_NULL(r);+ ASSERT_TRUE(r->parse_incomplete);+ ASSERT_GTE(r->error_region_count, 1);+ ASSERT_NOT_NULL(r->error_ranges);+ ASSERT_TRUE(has_def(r, "ok")); /* partial: clean defs still extracted */+ cbm_free_result(r);+ PASS();+}++TEST(py_clean_file_not_flagged) {+ CBMFileResult *r = do_extract(PY_CLEAN, CBM_LANG_PYTHON, "clean.py");+ ASSERT_NOT_NULL(r);+ ASSERT_FALSE(r->parse_incomplete);+ ASSERT_EQ(r->error_region_count, 0);+ ASSERT_NULL(r->error_ranges);+ cbm_free_result(r);+ PASS();+}++TEST(error_region_cap_is_honored) {+ /* Pathological input: many separate broken defs interleaved with valid+ * ones. The collector must stay bounded by its 64-region cap (matches+ * CBM_MAX_ERROR_REGIONS in cbm.c) — pathological input can't blow up the+ * report, and the flag itself still fires. */+ enum { BROKEN_DEFS = 200, LINE_CAP = 64 };+ char *src = (char *)malloc(BROKEN_DEFS * 96 + 1);+ ASSERT_NOT_NULL(src);+ size_t off = 0;+ for (int i = 0; i < BROKEN_DEFS; i++) {+ off += (size_t)snprintf(src + off, 96,+ "def ok%d():\n return %d\ndef broken%d(:\n pass\n", i, i, i);+ }+ CBMFileResult *r = do_extract(src, CBM_LANG_PYTHON, "many_errors.py");+ free(src);+ ASSERT_NOT_NULL(r);+ ASSERT_TRUE(r->parse_incomplete);+ ASSERT_GTE(r->error_region_count, 1);+ ASSERT_LTE(r->error_region_count, LINE_CAP);+ ASSERT_NOT_NULL(r->error_ranges);+ cbm_free_result(r);+ PASS();+}++/* ── Suite ────────────────────────────────────────────────────────────────── */++SUITE(parse_coverage) {+ RUN_TEST(c_ifdef_split_brace_sets_parse_incomplete);+ RUN_TEST(c_ifdef_split_brace_neighbors_still_extracted);+ RUN_TEST(c_error_range_points_at_failed_region);+ RUN_TEST(c_clean_file_not_flagged);+ RUN_TEST(py_syntax_error_sets_parse_incomplete);+ RUN_TEST(py_clean_file_not_flagged);+ RUN_TEST(error_region_cap_is_honored);+}