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.

fix(perl): eliminate false-positive Perl CALLS edges (builtins, framework method calls, config strings) (#477)

Shane McCarron92b4506cd570
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.h
index cc3607ee3..7b89bd4fa 100644
--- a/internal/cbm/cbm.h
+++ b/internal/cbm/cbm.h
@@ -236,6 +236,7 @@ typedef struct {
int loop_depth; // enclosing loop nesting at the call site
int branch_depth; // enclosing branch nesting at the call site
int start_line; // 1-based source line of the call (for def range-match)
+ bool is_method; // Perl-only: arrow/method call ($obj->m). Default false.
} CBMCall;
typedef struct {
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 98b924b8c..583fbe6d7 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -355,6 +355,40 @@ static char *extract_swift_callee(CBMArena *a, TSNode node, const char *source,
return NULL;
}
+// A Perl sub/method name is an identifier: it starts with a letter or '_',
+// contains only [A-Za-z0-9_] plus the '::' package separator, and is never a
+// string/config literal. tree-sitter-perl mis-parses config lines in .cgi /
+// heredoc-heavy files into call-shaped nodes whose "callee" is a dotted config
+// token (e.g. "log4perl.appender.File.utf8"); rejecting non-identifier text
+// here stops those from becoming bogus CALLS edges. Any '.', whitespace, quote,
+// or '/' disqualifies the token.
+static bool perl_is_identifier_callee(const char *name) {
+ if (!name || !name[0]) {
+ return false;
+ }
+ unsigned char c0 = (unsigned char)name[0];
+ if (!(isalpha(c0) || c0 == '_')) {
+ return false;
+ }
+ for (const char *p = name; *p; p++) {
+ unsigned char c = (unsigned char)*p;
+ if (isalnum(c) || c == '_') {
+ continue;
+ }
+ if (c == ':') {
+ // Only the '::' package separator is allowed: require an adjacent
+ // pair, and reject a lone ':', ':::', or a trailing '::'.
+ if (p[1] != ':' || p[2] == ':' || p[2] == '\0') {
+ return false;
+ }
+ p++; // consume the second ':'; the loop's p++ moves past the pair
+ continue;
+ }
+ return false; // '.', space, quote, '/', etc. → not a sub/method name
+ }
+ return true;
+}
+
// Callee extraction for scripting languages (Elixir, Perl, PHP, Kotlin, MATLAB).
static char *extract_scripting_callee(CBMArena *a, TSNode node, const char *source,
CBMLanguage lang, const char *nk) {
@@ -367,7 +401,24 @@ static char *extract_scripting_callee(CBMArena *a, TSNode node, const char *sour
return NULL;
}
if (lang == CBM_LANG_PERL && ts_node_child_count(node) > 0) {
- return cbm_node_text(a, ts_node_child(node, 0), source);
+ // Pull the actual sub/method name token rather than blindly taking
+ // child(0). Grammar (verified against the vendored parser):
+ // method_call_expression : field `method` ($obj->m / Class->m)
+ // function_call_expression : field `function` (foo(); name with '.'
+ // from a config-string misparse lands here)
+ // ambiguous_function_call_expression : field `function`
+ // func1op_call_expression : builtin keyword as child(0) (no field)
+ TSNode name_node = ts_node_child_by_field_name(node, TS_FIELD("method"));
+ if (ts_node_is_null(name_node)) {
+ name_node = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ }
+ if (ts_node_is_null(name_node)) {
+ name_node = ts_node_child(node, 0);
+ }
+ char *pn = cbm_node_text(a, name_node, source);
+ // Reject anything that is not a bare Perl sub/method identifier (config
+ // strings, quoted literals, paths) so no spurious CALLS edge is emitted.
+ return perl_is_identifier_callee(pn) ? pn : NULL;
}
if (lang == CBM_LANG_PHP) {
TSNode func_node = ts_node_child_by_field_name(node, TS_FIELD("function"));
@@ -1134,6 +1185,14 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walk
call.loop_depth = state->loop_depth; // enclosing loop nesting at this call
call.branch_depth = state->branch_depth; // enclosing branch nesting at this call
call.start_line = (int)ts_node_start_point(node).row + TS_LINE_OFFSET;
+ // Perl-only: flag arrow/method calls ($obj->m / Class->m). The
+ // generic short-name resolver cannot place a method without a known
+ // receiver type, so the call-resolution pass suppresses those edges.
+ // Default false for every other language (struct is zero-init).
+ if (ctx->language == CBM_LANG_PERL &&
+ strcmp(ts_node_type(node), "method_call_expression") == 0) {
+ call.is_method = true;
+ }
TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
if (!ts_node_is_null(args)) {
diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c
index 68d2afadd..26d25b3d8 100644
--- a/internal/cbm/lang_specs.c
+++ b/internal/cbm/lang_specs.c
@@ -585,7 +585,7 @@ static const char *perl_func_types[] = {"subroutine_declaration_statement", NULL
static const char *perl_module_types[] = {"source_file", NULL};
static const char *perl_call_types[] = {"ambiguous_function_call_expression",
"function_call_expression", "func1op_call_expression",
- NULL};
+ "method_call_expression", NULL};
static const char *perl_import_types[] = {"use_statement", "require_statement", "require", NULL};
static const char *perl_branch_types[] = {"if_statement", "unless_statement", "for_statement",
"foreach_statement", "while_statement", NULL};
diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.c
index 15d691d3a..25beb8844 100644
--- a/src/pipeline/pass_calls.c
+++ b/src/pipeline/pass_calls.c
@@ -336,7 +336,7 @@ static const cbm_gbuf_node_t *calls_find_source(cbm_pipeline_ctx_t *ctx, const c
static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
const CBMResolvedCallArray *lsp_calls, const char *rel,
const char *module_qn, const char **imp_keys, const char **imp_vals,
- int imp_count) {
+ int imp_count, CBMLanguage lang) {
const cbm_gbuf_node_t *source_node = calls_find_source(ctx, rel, call->enclosing_func_qn);
if (!source_node) {
return 0;
@@ -366,6 +366,19 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
if (!res.qualified_name || res.qualified_name[0] == '\0') {
return 0;
}
+
+ /* Perl call-graph noise guard (#476). Perl has no LSP resolver, so the
+ * generic registry chain is the only resolver; for builtins (push/shift/
+ * keys/...) and method calls ($obj->m with an unresolved receiver), a *weak*
+ * cross-file short-name match to a project sub sharing the name is almost
+ * always a false positive. Suppress only those weak matches; KEEP the
+ * high-confidence same_module / import_map strategies so a genuine
+ * same-file or imported call to a builtin-named sub still resolves. Gated
+ * to Perl — other languages are unaffected. */
+ if (cbm_perl_suppress_generic_match(lang == CBM_LANG_PERL, call->is_method, call->callee_name,
+ res.strategy)) {
+ return 0;
+ }
const cbm_gbuf_node_t *target_node = cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name);
if (!target_node || source_node->id == target_node->id) {
return 0;
@@ -440,7 +453,7 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *file
}
total_calls++;
if (resolve_single_call(ctx, call, &result->resolved_calls, rel, module_qn, imp_keys,
- imp_vals, imp_count)) {
+ imp_vals, imp_count, files[i].language)) {
resolved++;
} else {
unresolved++;
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 180ee85f7..a3c256308 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -1693,7 +1693,7 @@ static void lsp_idx_free_key(const char *key, void *value, void *ud) {
/* Resolve calls for one file and emit CALLS/HTTP_CALLS/ASYNC_CALLS edges. */
static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFileResult *result,
const char *rel, const char *module_qn, const char **imp_keys,
- const char **imp_vals, int imp_count) {
+ const char **imp_vals, int imp_count, CBMLanguage lang) {
/* Build a per-file hash index of resolved_calls keyed by
* "caller_qn|callee_short" for O(1) lookup. cbm_pipeline_find_lsp_
* resolution would otherwise do an O(N) linear scan over
@@ -1803,6 +1803,19 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
atomic_fetch_add_explicit(&rc->time_ns_rc_hint, extract_now_ns() - _rc_t0,
memory_order_relaxed);
+ /* Perl call-graph noise guard (#476), mirroring the sequential pass
+ * (pass_calls.c). Perl has no LSP resolver; for builtins (push/shift/
+ * keys/...) and method calls ($obj->m, unresolved receiver), suppress
+ * only WEAK cross-file short-name matches and keep the high-confidence
+ * same_module / import_map strategies so a genuine same-file or
+ * imported call to a builtin-named sub still resolves. Placed after the
+ * field-type hint so a hint cannot re-introduce a suppressed edge.
+ * Gated to Perl — other languages are unaffected. */
+ if (cbm_perl_suppress_generic_match(lang == CBM_LANG_PERL, call->is_method,
+ call->callee_name, res.strategy)) {
+ continue;
+ }
+
if (!res.qualified_name || res.qualified_name[0] == '\0') {
if (cbm_service_pattern_route_method(call->callee_name) != NULL) {
cbm_resolution_t fake_res = {.qualified_name = call->callee_name,
@@ -2328,7 +2341,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
/* ── CALLS resolution ──────────────────────────────────── */
_ph_t0 = extract_now_ns();
- resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count);
+ resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang);
atomic_fetch_add_explicit(&rc->time_ns_calls, extract_now_ns() - _ph_t0,
memory_order_relaxed);
diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h
index 1aa5ab5f7..ae7d125a2 100644
--- a/src/pipeline/pipeline.h
+++ b/src/pipeline/pipeline.h
@@ -167,6 +167,19 @@ void cbm_registry_resolve_cache_end(void);
/* Check if a qualified name exists in the registry. */
bool cbm_registry_exists(const cbm_registry_t *r, const char *qn);
+/* True if `name` is one of the curated Perl core builtins (perlfunc). Used by
+ * the call-resolution passes to suppress generic-resolver CALLS edges from Perl
+ * builtin invocations (push/shift/keys/...) to project subs that merely share
+ * the name. Perl-scoped: callers gate on the file language. */
+bool cbm_perl_is_builtin(const char *name);
+
+/* Decide whether a resolved Perl call edge is generic-resolver noise to drop
+ * (#476): true only for Perl, only for a builtin/method call, and only when the
+ * match used a weak short-name strategy — high-confidence same_module/import_map
+ * matches are kept. Pure; unit-tested in test_registry.c. */
+bool cbm_perl_suppress_generic_match(bool is_perl, bool is_method, const char *callee_name,
+ const char *strategy);
+
/* Get the label of a qualified name, or NULL if not found. */
const char *cbm_registry_label_of(const cbm_registry_t *r, const char *qn);
diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c
index 6533e9e27..2bf3f2176 100644
--- a/src/pipeline/registry.c
+++ b/src/pipeline/registry.c
@@ -356,6 +356,73 @@ static cbm_resolution_t empty_result(void) {
return r;
}
+/* ── Perl builtin guard (#459 follow-up: call-graph noise) ──────────
+ * Curated subset of perlfunc core builtins. When a Perl CALL resolves
+ * only by the generic short-name matcher (no LSP, no import, after the
+ * same-module/name-lookup chain), a builtin name like `push`/`shift`/
+ * `keys` must NOT be wired to a project sub that merely shares the name
+ * — that is virtually always a false positive. A genuine intra-project
+ * call is resolved by earlier (LSP/textual) stages before this guard.
+ * MUST stay sorted ASCII-ascending for bsearch. */
+static const char *const PERL_BUILTINS[] = {
+ "abs", "atan2", "binmode", "bless", "caller", "chdir", "chmod", "chomp",
+ "chop", "chown", "chr", "chroot", "close", "closedir", "cos", "defined",
+ "delete", "die", "do", "each", "eof", "eval", "exec", "exists",
+ "exit", "fork", "gmtime", "goto", "grep", "hex", "index", "int",
+ "join", "keys", "last", "lc", "lcfirst", "length", "local", "localtime",
+ "log", "lstat", "map", "mkdir", "my", "next", "oct", "open",
+ "opendir", "ord", "our", "pop", "pos", "print", "printf", "push",
+ "quotemeta", "rand", "read", "readdir", "readline", "redo", "ref", "rename",
+ "require", "return", "reverse", "rindex", "rmdir", "say", "scalar", "seek",
+ "shift", "sin", "sleep", "sort", "splice", "split", "sprintf", "sqrt",
+ "srand", "stat", "substr", "system", "time", "uc", "ucfirst", "undef",
+ "unlink", "unshift", "values", "wantarray", "warn", "write",
+};
+
+static int perl_builtin_cmp(const void *key, const void *elem) {
+ return strcmp((const char *)key, *(const char *const *)elem);
+}
+
+/* True if `name` is one of the curated Perl core builtins. Used to suppress
+ * generic-resolver CALLS edges from Perl builtin invocations to project subs
+ * that happen to share the builtin's name. Perl-scoped: callers gate on the
+ * file language so no other language's resolution is affected. */
+bool cbm_perl_is_builtin(const char *name) {
+ if (!name || !name[0]) {
+ return false;
+ }
+ return bsearch(name, PERL_BUILTINS, sizeof(PERL_BUILTINS) / sizeof(PERL_BUILTINS[0]),
+ sizeof(PERL_BUILTINS[0]), perl_builtin_cmp) != NULL;
+}
+
+/* Decide whether a *resolved* Perl call edge is generic-resolver noise that
+ * should be suppressed (#476). Returns true only for Perl, only for a builtin
+ * invocation or a method call, and only when the registry landed the match via
+ * a WEAK short-name strategy. High-confidence import/same-module strategies
+ * (same_module, import_map, import_map_suffix) are KEPT so a genuine same-file
+ * or imported call to a builtin-named sub still resolves — only the weak
+ * short-name guesses (suffix_match, unique_name) are dropped. `strategy` is the
+ * cbm_resolution_t.strategy of a non-empty match;
+ * NULL/empty (no match) returns false. Pure + side-effect-free so the
+ * suppression contract is unit-testable without a full pipeline. */
+bool cbm_perl_suppress_generic_match(bool is_perl, bool is_method, const char *callee_name,
+ const char *strategy) {
+ if (!is_perl) {
+ return false;
+ }
+ if (!(is_method || cbm_perl_is_builtin(callee_name))) {
+ return false;
+ }
+ if (!strategy || !strategy[0]) {
+ return false;
+ }
+ if (strcmp(strategy, "same_module") == 0 || strcmp(strategy, "import_map") == 0 ||
+ strcmp(strategy, "import_map_suffix") == 0) {
+ return false; /* high-confidence import/same-module match — keep the genuine edge */
+ }
+ return true; /* weak short-name match (suffix_match / unique_name / …) → drop */
+}
+
/* ── Lifecycle ──────────────────────────────────────────────────── */
cbm_registry_t *cbm_registry_new(void) {
diff --git a/tests/test_extraction.c b/tests/test_extraction.c
index 0308372c1..4bad219ba 100644
--- a/tests/test_extraction.c
+++ b/tests/test_extraction.c
@@ -2814,6 +2814,114 @@ TEST(complexity_access_depth_and_params) {
PASS();
}
+/* ═══════════════════════════════════════════════════════════════════
+ * Perl call-graph noise (#459 follow-up)
+ * ═══════════════════════════════════════════════════════════════════ */
+
+/* Count calls whose callee_name is exactly `name` (has_call is substring). */
+static int count_calls_exact(CBMFileResult *r, const char *name) {
+ int n = 0;
+ for (int i = 0; i < r->calls.count; i++) {
+ if (r->calls.items[i].callee_name && strcmp(r->calls.items[i].callee_name, name) == 0)
+ n++;
+ }
+ return n;
+}
+
+/* (b) A dotted config string must never be extracted as a callee. */
+TEST(extract_perl_config_string_not_a_callee) {
+ CBMFileResult *r = extract("package C;\n"
+ "sub run {\n"
+ " my $cfg = { \"log4perl.appender.File.utf8\" => 1 };\n"
+ " helper();\n"
+ "}\n"
+ "sub helper { return 1; }\n"
+ "1;\n",
+ CBM_LANG_PERL, "t", "app.pl");
+ ASSERT_NOT_NULL(r);
+ ASSERT_FALSE(r->has_error);
+ /* No callee may contain a '.' (config/string tokens are rejected). */
+ for (int i = 0; i < r->calls.count; i++) {
+ ASSERT_TRUE(strchr(r->calls.items[i].callee_name, '.') == NULL);
+ }
+ /* (d) The genuine intra-file function call is still extracted. */
+ ASSERT_TRUE(count_calls_exact(r, "helper") >= 1);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* (a) A Perl builtin call is extracted as a non-method callee. Suppression of
+ * the resulting CALLS edge happens in the resolver (see test_registry.c /
+ * end-to-end); extraction itself keeps the bare builtin token. */
+TEST(extract_perl_builtin_call_is_function_not_method) {
+ CBMFileResult *r = extract("package B;\n"
+ "sub run {\n"
+ " my @x;\n"
+ " push @x, 1;\n"
+ " keys %h;\n"
+ "}\n"
+ "1;\n",
+ CBM_LANG_PERL, "t", "b.pl");
+ ASSERT_NOT_NULL(r);
+ ASSERT_FALSE(r->has_error);
+ /* push / keys are extracted (they are valid identifiers) ... */
+ ASSERT_TRUE(has_call(r, "push"));
+ /* ... and crucially are NOT flagged as method calls. */
+ for (int i = 0; i < r->calls.count; i++) {
+ ASSERT_FALSE(r->calls.items[i].is_method);
+ }
+ cbm_free_result(r);
+ PASS();
+}
+
+/* (c) An arrow/method call is extracted with is_method=true so the resolver
+ * can suppress generic short-name matching for it. */
+TEST(extract_perl_method_call_flags_is_method) {
+ CBMFileResult *r = extract("package M;\n"
+ "sub run {\n"
+ " my $self = shift;\n"
+ " $self->commit();\n"
+ " $dbh->commit();\n"
+ " helper();\n"
+ "}\n"
+ "sub helper { return 1; }\n"
+ "1;\n",
+ CBM_LANG_PERL, "t", "m.pl");
+ ASSERT_NOT_NULL(r);
+ ASSERT_FALSE(r->has_error);
+ /* Every "commit" call is a method call (is_method set). */
+ int commit_calls = 0;
+ for (int i = 0; i < r->calls.count; i++) {
+ if (strcmp(r->calls.items[i].callee_name, "commit") == 0) {
+ commit_calls++;
+ ASSERT_TRUE(r->calls.items[i].is_method);
+ }
+ /* The genuine function call is NOT a method. */
+ if (strcmp(r->calls.items[i].callee_name, "helper") == 0) {
+ ASSERT_FALSE(r->calls.items[i].is_method);
+ }
+ }
+ ASSERT_TRUE(commit_calls >= 1);
+ /* (d) genuine intra-file function call still extracted. */
+ ASSERT_TRUE(count_calls_exact(r, "helper") >= 1);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* Other languages must be unaffected: a JS method call never sets is_method
+ * (the flag is Perl-only). */
+TEST(extract_non_perl_method_call_not_flagged_is_method) {
+ CBMFileResult *r =
+ extract("function run(o){ o.commit(); helper(); }\n", CBM_LANG_JAVASCRIPT, "t", "x.js");
+ ASSERT_NOT_NULL(r);
+ ASSERT_FALSE(r->has_error);
+ for (int i = 0; i < r->calls.count; i++) {
+ ASSERT_FALSE(r->calls.items[i].is_method);
+ }
+ cbm_free_result(r);
+ PASS();
+}
+
/* ═══════════════════════════════════════════════════════════════════
* Suite
* ═══════════════════════════════════════════════════════════════════ */
@@ -2822,6 +2930,12 @@ SUITE(extraction) {
/* Initialize extraction library */
cbm_init();
+ /* Perl call-graph noise (#459 follow-up) */
+ RUN_TEST(extract_perl_config_string_not_a_callee);
+ RUN_TEST(extract_perl_builtin_call_is_function_not_method);
+ RUN_TEST(extract_perl_method_call_flags_is_method);
+ RUN_TEST(extract_non_perl_method_call_not_flagged_is_method);
+
/* R box-module imports + member calls */
RUN_TEST(extract_r_box_use_imports_issue218);
RUN_TEST(extract_r_dollar_call_issue219);
diff --git a/tests/test_registry.c b/tests/test_registry.c
index 2c2181a09..46cfc3d8c 100644
--- a/tests/test_registry.c
+++ b/tests/test_registry.c
@@ -626,6 +626,60 @@ TEST(fuzzy_no_import_map_passthrough) {
PASS();
}
+/* ── Perl builtin guard (#459 follow-up: call-graph noise) ───────── */
+
+TEST(perl_builtin_set_recognizes_core_builtins) {
+ /* Representative core builtins from across the sorted set. */
+ ASSERT_TRUE(cbm_perl_is_builtin("push"));
+ ASSERT_TRUE(cbm_perl_is_builtin("shift"));
+ ASSERT_TRUE(cbm_perl_is_builtin("keys"));
+ ASSERT_TRUE(cbm_perl_is_builtin("sprintf"));
+ ASSERT_TRUE(cbm_perl_is_builtin("abs")); /* first element */
+ ASSERT_TRUE(cbm_perl_is_builtin("write")); /* last element */
+ ASSERT_TRUE(cbm_perl_is_builtin("wantarray"));
+ PASS();
+}
+
+TEST(perl_builtin_set_rejects_project_subs) {
+ /* Genuine project sub names and edge inputs must NOT be flagged. */
+ ASSERT_FALSE(cbm_perl_is_builtin("helper"));
+ ASSERT_FALSE(cbm_perl_is_builtin("process_request"));
+ ASSERT_FALSE(cbm_perl_is_builtin("Push")); /* case-sensitive */
+ ASSERT_FALSE(cbm_perl_is_builtin(""));
+ ASSERT_FALSE(cbm_perl_is_builtin(NULL));
+ PASS();
+}
+
+TEST(perl_suppress_drops_weak_builtin_and_method_matches) {
+ /* #476: a builtin/method call that landed via a WEAK short-name strategy is
+ * generic-resolver noise and must be suppressed. */
+ ASSERT_TRUE(cbm_perl_suppress_generic_match(true, false, "push", "suffix_match"));
+ ASSERT_TRUE(cbm_perl_suppress_generic_match(true, false, "keys", "unique_name"));
+ ASSERT_TRUE(cbm_perl_suppress_generic_match(true, true, "commit", "suffix_match"));
+ ASSERT_TRUE(cbm_perl_suppress_generic_match(true, true, "log", "unique_name"));
+ PASS();
+}
+
+TEST(perl_suppress_keeps_high_confidence_and_genuine_calls) {
+ /* #476: high-confidence strategies are kept so a genuine same-file/imported
+ * call to a builtin-named sub still resolves (criterion d). */
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, false, "log", "same_module"));
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, false, "open", "import_map"));
+ /* import_map_suffix is a genuine import resolution (conf 0.85), not a weak
+ * short-name guess — a '::'-qualified call resolved this way must be kept. */
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, true, "Foo::Bar::m", "import_map_suffix"));
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, true, "commit", "same_module"));
+ /* A genuine non-builtin function call is never suppressed (edge survives). */
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, false, "helper", "suffix_match"));
+ /* Non-Perl languages are never affected. */
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(false, false, "push", "suffix_match"));
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(false, true, "commit", "suffix_match"));
+ /* No match (NULL/empty strategy) → nothing to suppress. */
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, false, "push", NULL));
+ ASSERT_FALSE(cbm_perl_suppress_generic_match(true, true, "commit", ""));
+ PASS();
+}
+
/* ── Suite ─────────────────────────────────────────────────────── */
SUITE(registry) {
@@ -684,4 +738,10 @@ SUITE(registry) {
RUN_TEST(fuzzy_resolve_confidence_distance);
RUN_TEST(fuzzy_penalty_unreachable_import);
RUN_TEST(fuzzy_no_import_map_passthrough);
+
+ /* Perl builtin guard */
+ RUN_TEST(perl_builtin_set_recognizes_core_builtins);
+ RUN_TEST(perl_builtin_set_rejects_project_subs);
+ RUN_TEST(perl_suppress_drops_weak_builtin_and_method_matches);
+ RUN_TEST(perl_suppress_keeps_high_confidence_and_genuine_calls);
}