Skip to content

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.

test(pipeline): bind the Go selector guard on the parallel resolver

Martin Vogel7528ec06fe7d
diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c
index cbfa4ec5d..bfc2e330e 100644
--- a/src/pipeline/registry.c
+++ b/src/pipeline/registry.c
@@ -750,19 +750,23 @@ bool cbm_suppress_weak_local_binding_call(bool enabled, bool callee_is_locally_b
bool cbm_go_suppress_weak_method_match(bool is_go, bool is_method, const char *strategy,
double confidence) {
- if (!is_go || !is_method || !strategy || !strategy[0]) {
- return false;
- }
/* Go analog of the TS/JS guard above, same failure class: a selector call
* whose receiver the Go LSP could not type reaches the registry and a bare
* short-name strategy binds it to an arbitrary same-named project symbol
* (`f.Close()` on an os.File -> a project `Close`, suffix_match over 15
- * candidates). Unlike the TS/JS list, field_type_hint is KEPT: a Go struct
- * field carries a declared type, so the parallel resolver's field-type
- * hint is receiver-aware for Go (lrp_go_s8_field_type_hint), not a
- * heuristic. */
- if (strcmp(strategy, "suffix_match") == 0 || strcmp(strategy, "fuzzy") == 0) {
- return true;
+ * candidates). Built on the shared drop-list so "weak" means one thing
+ * for every guard; Go narrows it in two places only. */
+ if (!is_go || !is_method || !weak_short_name_strategy(strategy)) {
+ return false;
+ }
+ /* field_type_hint is KEPT for Go: a Go struct field carries a declared
+ * type, so the parallel resolver's field-type hint is receiver-aware for
+ * Go (lrp_go_s8_field_type_hint), not a heuristic. */
+ if (strcmp(strategy, "field_type_hint") == 0) {
+ return false;
+ }
+ if (strcmp(strategy, "unique_name") != 0) {
+ return true; /* suffix_match, fuzzy */
}
/* unique_name is dropped only when PENALIZED: resolve_name_lookup scales
* CONF_UNIQUE_NAME by DEFAULT_CONFIDENCE exactly when the lone candidate
@@ -772,7 +776,7 @@ bool cbm_go_suppress_weak_method_match(bool is_go, bool is_method, const char *s
* file has no imports, e.g. a same-package call) and must be kept —
* dropping it kills genuinely-typed lone-candidate calls that never
* enter the field-type-hint upgrade (candidate_count == 1). */
- return strcmp(strategy, "unique_name") == 0 && confidence < CONF_UNIQUE_NAME;
+ return confidence < CONF_UNIQUE_NAME;
}
/* Import-binding counterpart of the parameter guard above (#2127). An import
diff --git a/tests/test_extraction.c b/tests/test_extraction.c
index 41a796ce8..13b03aa37 100644
--- a/tests/test_extraction.c
+++ b/tests/test_extraction.c
@@ -6886,8 +6886,8 @@ TEST(extract_perl_method_call_flags_is_method) {
PASS();
}
-/* Languages OUTSIDE the is_method flag set (only Perl and TS/JS/TSX set it) must
- * be unaffected: a Go method call never sets is_method. */
+/* Languages OUTSIDE the is_method flag set (Perl, Python, TS/JS/TSX and Go set
+ * it) must be unaffected: a Rust method call never sets is_method. */
TEST(extract_flag_exempt_method_call_not_flagged_is_method) {
/* Rust is flag-exempt: only Perl, Python, TS/JS and Go set is_method.
* Guards the blast radius of the receiver-aware flags for every other
diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c
index 4da054b14..d413aa9bb 100644
--- a/tests/test_pipeline.c
+++ b/tests/test_pipeline.c
@@ -8650,13 +8650,11 @@ TEST(pipeline_html_embedded_member_call_stays_unbound) {
PASS();
}
-TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
- char tmp[256];
- snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");
- if (!cbm_mkdtemp(tmp)) {
- FAIL("tmpdir");
- }
-
+/* Fixture for the #1906 Go selector-guard probes (sequential and parallel
+ * twins). pad_files > 0 adds filler Go files to push the index over
+ * MIN_FILES_FOR_PARALLEL, because the guard is wired into both resolvers
+ * (pass_calls.c and pass_parallel.c) and each needs its own probe. */
+static void write_go_receiver_fixture(const char *tmp, int pad_files) {
/* go.mod makes project imports resolvable — real Go repos always have one,
* and import reachability (the unique_name penalty) depends on it. */
write_temp_file(tmp, "go.mod", "module example.com/myapp\n\ngo 1.22\n");
@@ -8715,6 +8713,22 @@ TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
"func CallsLocal() int { return localHelper() }\n"
"\n"
"func UsesUtil() string { return util.Tag() }\n");
+ for (int i = 0; i < pad_files; i++) {
+ char name[64];
+ char body[128];
+ snprintf(name, sizeof(name), "filler/filler%d.go", i);
+ snprintf(body, sizeof(body), "package filler\n\nfunc Filler%d() int { return %d }\n", i, i);
+ write_temp_file(tmp, name, body);
+ }
+}
+
+TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ write_go_receiver_fixture(tmp, 0);
char db_path[512];
snprintf(db_path, sizeof(db_path), "%s/go_recv.db", tmp);
@@ -8743,6 +8757,55 @@ TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
PASS();
}
+/* Parallel twin of the test above. The guard is wired into pass_parallel.c as
+ * well as pass_calls.c, but the four-file fixture only ever runs the
+ * sequential resolver, so the parallel hunk was bound by no test. Real
+ * repositories take the parallel path: >= MIN_FILES_FOR_PARALLEL (50) files
+ * plus CBM_WORKERS=4 force it, the shape of
+ * pipeline_python_receiver_parallel_suppresses_weak_method_edges. Same
+ * both-directions pin as the sequential test. */
+TEST(pipeline_go_receiver_parallel_suppresses_weak_method_edge) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_par_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ write_go_receiver_fixture(tmp, 52);
+
+ char *old_workers = getenv("CBM_WORKERS");
+ char *saved = old_workers ? strdup(old_workers) : NULL;
+ cbm_setenv("CBM_WORKERS", "4", 1);
+
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/go_recv_par.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(cbm_pipeline_run(p), 0);
+ const char *project = cbm_pipeline_project_name(p);
+
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+
+ /* NEGATIVE: the stdlib *os.File Close must not bind the project method. */
+ ASSERT_FALSE(cross_file_call_exists(s, project, "FileLen", "Close"));
+ /* POSITIVE: typed same-package, bare local and import-qualified calls
+ * survive the parallel resolver too. */
+ ASSERT_TRUE(cross_file_call_exists(s, project, "Boot", "Close"));
+ ASSERT_TRUE(cross_file_call_exists(s, project, "CallsLocal", "localHelper"));
+ ASSERT_TRUE(cross_file_call_exists(s, project, "UsesUtil", "Tag"));
+
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ if (saved) {
+ cbm_setenv("CBM_WORKERS", saved, 1);
+ free(saved);
+ } else {
+ cbm_unsetenv("CBM_WORKERS");
+ }
+ th_rmtree(tmp);
+ PASS();
+}
+
/* Fixture for the #1928 cross-language reference-guard probes (sequential and
* parallel twins). pad_files > 0 adds filler files to push the index over the
* parallel-pipeline threshold, since USAGE/WRITES/READS have one resolver per
@@ -23707,6 +23770,7 @@ SUITE(pipeline) {
RUN_TEST(pipeline_python_receiver_keeps_specific_unique_name_member_call);
RUN_TEST(pipeline_html_embedded_member_call_stays_unbound);
RUN_TEST(pipeline_go_receiver_suppresses_weak_method_edge);
+ RUN_TEST(pipeline_go_receiver_parallel_suppresses_weak_method_edge);
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c);
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);
RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);
diff --git a/tests/test_registry.c b/tests/test_registry.c
index e25ba369e..a6fbd6201 100644
--- a/tests/test_registry.c
+++ b/tests/test_registry.c
@@ -1673,6 +1673,16 @@ TEST(weak_call_guards_share_one_drop_list) {
strategies[i], member, binding);
}
ASSERT_EQ(member, binding);
+ /* The Go selector guard builds on the same list and narrows it in
+ * exactly one place at a penalized confidence (0.75 * 0.5): it keeps
+ * field_type_hint. Any other drift from the shared list fails here. */
+ bool go = cbm_go_suppress_weak_method_match(true, true, strategies[i], 0.375);
+ bool go_expected = member && strcmp(strategies[i], "field_type_hint") != 0;
+ if (go != go_expected) {
+ printf(" Go drop-list divergence on strategy \"%s\": go=%d expected=%d\n",
+ strategies[i], go, go_expected);
+ }
+ ASSERT_EQ(go, go_expected);
}
PASS();
}