Skip to content

Commit 0714e46

Browse files
committed
fix: address self-review findings — keep node_degree CALLS-only
cbm_store_node_degree backs the MCP get_code_snippet callers/callees counts and the Cypher in_degree/out_degree virtual property, which are deliberately CALLS-scoped. Restore it to CALLS-only and scope the INHERITS/IMPLEMENTS broadening to cbm_store_search alone, which is the search_graph surface issue #558 is about. Adjust the new tests so node_degree assertions expect CALLS-only counts while the search_graph result assertions expect the broadened structural degree. Signed-off-by: Matt Van Horn <[email protected]>
1 parent 65b8425 commit 0714e46

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

‎src/store/store.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,8 +1789,7 @@ void cbm_store_node_degree(cbm_store_t *s, int64_t node_id, int *in_deg, int *ou
17891789
*in_deg = 0;
17901790
*out_deg = 0;
17911791

1792-
const char *in_sql = "SELECT COUNT(*) FROM edges WHERE target_id = ?1 AND "
1793-
"type IN ('CALLS', 'USAGE', 'INHERITS', 'IMPLEMENTS')";
1792+
const char *in_sql = "SELECT COUNT(*) FROM edges WHERE target_id = ?1 AND type = 'CALLS'";
17941793
sqlite3_stmt *stmt = NULL;
17951794
if (sqlite3_prepare_v2(s->db, in_sql, CBM_NOT_FOUND, &stmt, NULL) == SQLITE_OK) {
17961795
sqlite3_bind_int64(stmt, SKIP_ONE, node_id);
@@ -1800,8 +1799,7 @@ void cbm_store_node_degree(cbm_store_t *s, int64_t node_id, int *in_deg, int *ou
18001799
sqlite3_finalize(stmt);
18011800
}
18021801

1803-
const char *out_sql = "SELECT COUNT(*) FROM edges WHERE source_id = ?1 AND "
1804-
"type IN ('CALLS', 'USAGE', 'INHERITS', 'IMPLEMENTS')";
1802+
const char *out_sql = "SELECT COUNT(*) FROM edges WHERE source_id = ?1 AND type = 'CALLS'";
18051803
if (sqlite3_prepare_v2(s->db, out_sql, CBM_NOT_FOUND, &stmt, NULL) == SQLITE_OK) {
18061804
sqlite3_bind_int64(stmt, SKIP_ONE, node_id);
18071805
if (sqlite3_step(stmt) == SQLITE_ROW) {

‎tests/test_store_search.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,26 +274,23 @@ TEST(store_search_degree_counts_inherits) {
274274
ASSERT_GT(parent_id, 0);
275275

276276
const char *child_names[] = {"AttachmentDtoA", "AttachmentDtoB", "AttachmentDtoC"};
277-
const char *child_qns[] = {"test.AttachmentDtoA", "test.AttachmentDtoB",
278-
"test.AttachmentDtoC"};
277+
const char *child_qns[] = {"test.AttachmentDtoA", "test.AttachmentDtoB", "test.AttachmentDtoC"};
279278
for (int i = 0; i < 3; i++) {
280279
cbm_node_t child = {.project = "test",
281280
.label = "Class",
282281
.name = child_names[i],
283282
.qualified_name = child_qns[i]};
284283
int64_t child_id = cbm_store_upsert_node(s, &child);
285284
ASSERT_GT(child_id, 0);
286-
cbm_edge_t edge = {.project = "test",
287-
.source_id = child_id,
288-
.target_id = parent_id,
289-
.type = "INHERITS"};
285+
cbm_edge_t edge = {
286+
.project = "test", .source_id = child_id, .target_id = parent_id, .type = "INHERITS"};
290287
ASSERT_GT(cbm_store_insert_edge(s, &edge), 0);
291288
}
292289

293290
int in_deg = 0;
294291
int out_deg = 0;
295292
cbm_store_node_degree(s, parent_id, &in_deg, &out_deg);
296-
ASSERT_EQ(in_deg, 3);
293+
ASSERT_EQ(in_deg, 0);
297294
ASSERT_EQ(out_deg, 0);
298295

299296
cbm_search_params_t params = {
@@ -345,7 +342,7 @@ TEST(store_search_degree_calls_plus_inherits_no_double_count) {
345342
int out_deg = 0;
346343
cbm_store_node_degree(s, child_id, &in_deg, &out_deg);
347344
ASSERT_EQ(in_deg, 0);
348-
ASSERT_EQ(out_deg, 2);
345+
ASSERT_EQ(out_deg, 1);
349346

350347
cbm_search_params_t params = {
351348
.project = "test", .label = "Class", .min_degree = -1, .max_degree = -1};

0 commit comments

Comments
 (0)