Skip to content

Commit 8ca8393

Browse files
committed
fix(store): keep unresolved_calls rows out of the missed graph
The "<project>::missed" shadow graph lists the files the indexer did not fully cover. unresolved_calls rows describe files that were indexed; their call evidence is reported by check_index_coverage and trace_path. The miss-graph builder skipped only not_indexed_* rows, so every file with an unresolved call became a missed File node: on a Prometheus checkout the shadow graph grew from 30 nodes / 29 edges to 961 / 960. A file with both a parse_partial and an unresolved_calls row also lost its parse_partial node, because rows arrive ordered by (rel_path, kind) and the File upsert keeps the later one. Treat unresolved_calls like not_indexed_* in all three places the builder filters rows: the failure fingerprint, the failure count that decides whether a shadow graph exists at all, and the per-row loop. store_coverage_shadow_excludes_unresolved_calls covers a project whose only rows are unresolved_calls (no shadow project), a file with both kinds (its parse_partial node survives), and the fingerprint (equal to the same failure rows without the evidence). Reverting each filter on its own turns its check red. Signed-off-by: Martin Vogel <[email protected]>
1 parent 24bd38c commit 8ca8393

3 files changed

Lines changed: 127 additions & 8 deletions

File tree

‎src/store/store.c‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,6 +4516,18 @@ static void cov_json_escape(char *dst, size_t dstsz, const char *src) {
45164516
* {kind, detail}. Queryable via query_graph(graph="missed") with zero
45174517
* cypher-engine changes; the real project's graph gains no rows. Derived
45184518
* data — rebuilt from the authoritative (post-prune) table contents. */
4519+
/* Coverage kinds that never materialize in the miss graph. not_indexed_*
4520+
* rows are by-design exclusions, not failures. unresolved_calls rows (#2265)
4521+
* describe files that WERE indexed; their call evidence is reported by
4522+
* check_index_coverage and trace_path, and as a File row it would also
4523+
* replace a parse_partial row for the same path (rows arrive ordered by
4524+
* rel_path, kind, and the File upsert keeps the last one). */
4525+
static bool cov_kind_outside_miss_graph(const char *kind) {
4526+
static const char by_design_prefix[] = "not_indexed";
4527+
return strncmp(kind, by_design_prefix, sizeof(by_design_prefix) - 1) == 0 ||
4528+
strcmp(kind, "unresolved_calls") == 0;
4529+
}
4530+
45194531
/* Fingerprint of the FAILURE rows the shadow graph derives from. When the
45204532
* set is unchanged since the last rebuild, the wipe-and-rebuild (tens of
45214533
* thousands of node/edge upserts probing the full-size nodes index -- a
@@ -4527,7 +4539,7 @@ static void cov_failure_fingerprint(const cbm_coverage_row_t *rows, int count,
45274539
cbm_sha256_ctx sha;
45284540
cbm_sha256_init(&sha);
45294541
for (int i = 0; i < count; i++) {
4530-
if (!rows[i].kind || strncmp(rows[i].kind, "not_indexed", 11) == 0) {
4542+
if (!rows[i].kind || cov_kind_outside_miss_graph(rows[i].kind)) {
45314543
continue;
45324544
}
45334545
const char *rel = rows[i].rel_path ? rows[i].rel_path : "";
@@ -4626,11 +4638,11 @@ static int cov_rebuild_shadow_graph(cbm_store_t *s, const char *project) {
46264638
return CBM_STORE_OK;
46274639
}
46284640
/* Only FAILURE rows materialize in the miss graph; a project whose only
4629-
* coverage rows are by-design not_indexed_* entries gets NO graph (not
4630-
* even a bare root node). */
4641+
* coverage rows are by-design not_indexed_* entries or unresolved_calls
4642+
* evidence gets NO graph (not even a bare root node). */
46314643
int failure_count = 0;
46324644
for (int i = 0; i < count; i++) {
4633-
if (!rows[i].kind || strncmp(rows[i].kind, "not_indexed", 11) != 0) {
4645+
if (!rows[i].kind || !cov_kind_outside_miss_graph(rows[i].kind)) {
46344646
failure_count++;
46354647
}
46364648
}
@@ -4671,8 +4683,10 @@ static int cov_rebuild_shadow_graph(cbm_store_t *s, const char *project) {
46714683
}
46724684
/* The missed graph shows FAILURES ("we did not manage") only —
46734685
* by-design not_indexed_* rows stay out of it, so the UI's
4674-
* report-an-edge-case callout never fires for gitignored paths. */
4675-
if (rows[i].kind && strncmp(rows[i].kind, "not_indexed", 11) == 0) {
4686+
* report-an-edge-case callout never fires for gitignored paths, and
4687+
* unresolved_calls rows stay out so a parse_partial row for the same
4688+
* file keeps its File node. */
4689+
if (rows[i].kind && cov_kind_outside_miss_graph(rows[i].kind)) {
46764690
continue;
46774691
}
46784692
char pathbuf[CBM_SZ_1K];

‎src/store/store.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,11 @@ int cbm_store_observed_lookup(cbm_store_t *s, const char *project, const char *c
860860
void cbm_store_coverage_meta_clear(cbm_coverage_meta_t *meta);
861861

862862
/* Name of the derived miss-graph shadow project ("<project>::missed").
863-
* cbm_store_coverage_replace materializes the coverage rows as a file-
863+
* cbm_store_coverage_replace materializes the coverage FAILURE rows as a file-
864864
* structure graph (Project → Folder → File{kind, detail}) under this project
865865
* name — queryable via the normal cypher path without touching the real
866-
* project's graph. */
866+
* project's graph. By-design not_indexed_* rows and unresolved_calls evidence
867+
* stay out of it. */
867868
void cbm_store_coverage_shadow_project(char *dst, size_t dstsz, const char *project);
868869

869870
void cbm_store_free_coverage(cbm_coverage_row_t *rows, int count);

‎tests/test_store_nodes.c‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,109 @@ TEST(store_coverage_replace_rolls_back_when_shadow_rebuild_fails) {
26032603
PASS();
26042604
}
26052605

2606+
/* Copy store_meta's shadow fingerprint for `project` into `out` ("" if absent). */
2607+
static void coverage_shadow_fp(cbm_store_t *s, const char *project, char *out, size_t cap) {
2608+
out[0] = '\0';
2609+
char key[256];
2610+
snprintf(key, sizeof(key), "coverage_shadow_fp:%s", project);
2611+
sqlite3_stmt *stmt = NULL;
2612+
if (sqlite3_prepare_v2(cbm_store_get_db(s), "SELECT v FROM store_meta WHERE k = ?1;", -1, &stmt,
2613+
NULL) != SQLITE_OK) {
2614+
return;
2615+
}
2616+
sqlite3_bind_text(stmt, 1, key, -1, SQLITE_TRANSIENT);
2617+
if (sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_text(stmt, 0)) {
2618+
snprintf(out, cap, "%s", (const char *)sqlite3_column_text(stmt, 0));
2619+
}
2620+
sqlite3_finalize(stmt);
2621+
}
2622+
2623+
/* #2265: unresolved_calls rows describe files that WERE indexed, so they stay
2624+
* out of the "<project>::missed" graph like by-design not_indexed_* rows:
2625+
* (a) a project whose only rows are unresolved_calls gets no shadow graph,
2626+
* (b) a file with parse_partial AND unresolved_calls keeps its parse_partial
2627+
* File node (the later unresolved_calls row used to replace it), and
2628+
* (c) the shadow fingerprint ignores unresolved_calls rows, so the skip gate
2629+
* and store_meta match a project without them. */
2630+
TEST(store_coverage_shadow_excludes_unresolved_calls) {
2631+
cbm_store_t *s = cbm_store_open_memory();
2632+
ASSERT_NOT_NULL(s);
2633+
const char *only = "cov-unres-only";
2634+
const char *mixed = "cov-unres-mixed";
2635+
const char *plain = "cov-unres-plain";
2636+
ASSERT_EQ(cbm_store_upsert_project(s, only, "/tmp/cov-unres-only"), CBM_STORE_OK);
2637+
ASSERT_EQ(cbm_store_upsert_project(s, mixed, "/tmp/cov-unres-mixed"), CBM_STORE_OK);
2638+
ASSERT_EQ(cbm_store_upsert_project(s, plain, "/tmp/cov-unres-plain"), CBM_STORE_OK);
2639+
ASSERT_EQ(cbm_store_upsert_file_hash(s, only, "src/a.go", "", 1, 1), CBM_STORE_OK);
2640+
ASSERT_EQ(cbm_store_upsert_file_hash(s, only, "src/b.go", "", 2, 2), CBM_STORE_OK);
2641+
ASSERT_EQ(cbm_store_upsert_file_hash(s, mixed, "src/both.go", "", 3, 3), CBM_STORE_OK);
2642+
ASSERT_EQ(cbm_store_upsert_file_hash(s, mixed, "lib/calls.go", "", 4, 4), CBM_STORE_OK);
2643+
ASSERT_EQ(cbm_store_upsert_file_hash(s, plain, "src/both.go", "", 3, 3), CBM_STORE_OK);
2644+
2645+
/* (a) Only unresolved_calls (plus a by-design row): no shadow project. */
2646+
cbm_coverage_row_t only_rows[] = {
2647+
{.rel_path = "src/a.go", .kind = "unresolved_calls", .detail = "[{\"candidate\":\"a.f\"}]"},
2648+
{.rel_path = "src/b.go", .kind = "unresolved_calls", .detail = "[{\"candidate\":\"b.g\"}]"},
2649+
{.rel_path = "vendor", .kind = "not_indexed_dir", .detail = "excluded subtree"},
2650+
};
2651+
ASSERT_EQ(cbm_store_coverage_replace(s, only, only_rows, 3), CBM_STORE_OK);
2652+
cbm_coverage_row_t *got = NULL;
2653+
int n = 0;
2654+
ASSERT_EQ(cbm_store_coverage_get(s, only, &got, &n), CBM_STORE_OK);
2655+
ASSERT_EQ(n, 3); /* the table keeps the evidence; only the view skips it */
2656+
cbm_store_free_coverage(got, n);
2657+
ASSERT_EQ(cbm_store_count_nodes(s, "cov-unres-only::missed"), 0);
2658+
cbm_project_t shadow = {0};
2659+
ASSERT_EQ(cbm_store_get_project(s, "cov-unres-only::missed", &shadow), CBM_STORE_NOT_FOUND);
2660+
cbm_project_free_fields(&shadow);
2661+
2662+
/* (b) parse_partial + unresolved_calls on one path, and a second file
2663+
* with unresolved_calls only: the shadow holds exactly the parse_partial
2664+
* File node under src/. */
2665+
cbm_coverage_row_t mixed_rows[] = {
2666+
{.rel_path = "src/both.go", .kind = "parse_partial", .detail = "3-4"},
2667+
{.rel_path = "src/both.go",
2668+
.kind = "unresolved_calls",
2669+
.detail = "[{\"candidate\":\"both.h\"}]"},
2670+
{.rel_path = "lib/calls.go",
2671+
.kind = "unresolved_calls",
2672+
.detail = "[{\"candidate\":\"calls.k\"}]"},
2673+
};
2674+
ASSERT_EQ(cbm_store_coverage_replace(s, mixed, mixed_rows, 3), CBM_STORE_OK);
2675+
cbm_node_t *nodes = NULL;
2676+
int nc = 0;
2677+
ASSERT_EQ(cbm_store_find_nodes_by_label(s, "cov-unres-mixed::missed", "File", &nodes, &nc),
2678+
CBM_STORE_OK);
2679+
ASSERT_EQ(nc, 1);
2680+
ASSERT_STR_EQ(nodes[0].file_path, "src/both.go");
2681+
ASSERT_NOT_NULL(strstr(nodes[0].properties_json, "\"kind\":\"parse_partial\""));
2682+
ASSERT_NOT_NULL(strstr(nodes[0].properties_json, "\"detail\":\"3-4\""));
2683+
ASSERT_NULL(strstr(nodes[0].properties_json, "unresolved_calls"));
2684+
cbm_store_free_nodes(nodes, nc);
2685+
nodes = NULL;
2686+
nc = 0;
2687+
ASSERT_EQ(cbm_store_find_nodes_by_label(s, "cov-unres-mixed::missed", "Folder", &nodes, &nc),
2688+
CBM_STORE_OK);
2689+
ASSERT_EQ(nc, 1);
2690+
ASSERT_STR_EQ(nodes[0].name, "src");
2691+
cbm_store_free_nodes(nodes, nc);
2692+
2693+
/* (c) Same failure rows without the unresolved_calls evidence: the stored
2694+
* fingerprints match. */
2695+
cbm_coverage_row_t plain_row = {
2696+
.rel_path = "src/both.go", .kind = "parse_partial", .detail = "3-4"};
2697+
ASSERT_EQ(cbm_store_coverage_replace(s, plain, &plain_row, 1), CBM_STORE_OK);
2698+
char fp_mixed[128];
2699+
char fp_plain[128];
2700+
coverage_shadow_fp(s, mixed, fp_mixed, sizeof(fp_mixed));
2701+
coverage_shadow_fp(s, plain, fp_plain, sizeof(fp_plain));
2702+
ASSERT_TRUE(fp_plain[0] != '\0');
2703+
ASSERT_STR_EQ(fp_mixed, fp_plain);
2704+
2705+
cbm_store_close(s);
2706+
PASS();
2707+
}
2708+
26062709
SUITE(store_nodes) {
26072710
RUN_TEST(store_qn_suffix_is_literal);
26082711
RUN_TEST(store_qn_suffix_is_unbounded);
@@ -2612,6 +2715,7 @@ SUITE(store_nodes) {
26122715
RUN_TEST(store_coverage_meta_zero_row_truncation_and_delete);
26132716
RUN_TEST(store_coverage_replace_rejects_invalid_row_arguments);
26142717
RUN_TEST(store_coverage_replace_rolls_back_when_shadow_rebuild_fails);
2718+
RUN_TEST(store_coverage_shadow_excludes_unresolved_calls);
26152719
RUN_TEST(sql_label_allowlists_match_cbm_label_is_type_like);
26162720
RUN_TEST(sql_relation_labels_match_cbm_label_is_relation);
26172721
RUN_TEST(store_open_memory);

0 commit comments

Comments
 (0)