Skip to content

Commit cdb7a29

Browse files
committed
fix(pipeline): exclude project identity from service patterns
Signed-off-by: DavidHLP <[email protected]>
1 parent f25f8b3 commit cdb7a29

6 files changed

Lines changed: 55 additions & 24 deletions

File tree

‎internal/cbm/service_patterns.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,17 @@ cbm_svc_kind_t cbm_service_pattern_match(const char *resolved_qn) {
11701170
return result;
11711171
}
11721172

1173+
cbm_svc_kind_t cbm_service_pattern_match_in_project(const char *resolved_qn, const char *name,
1174+
const char *project_name) {
1175+
if (resolved_qn && project_name && project_name[0]) {
1176+
size_t len = strlen(project_name);
1177+
if (strncmp(resolved_qn, project_name, len) == 0 && resolved_qn[len] == '.') {
1178+
resolved_qn += len + 1;
1179+
}
1180+
}
1181+
return cbm_service_pattern_match_named(resolved_qn, name);
1182+
}
1183+
11731184
cbm_svc_kind_t cbm_service_pattern_match_named(const char *resolved_qn, const char *name) {
11741185
if (!resolved_qn || !name) {
11751186
return cbm_service_pattern_match(resolved_qn);

‎internal/cbm/service_patterns.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void cbm_service_patterns_init(void);
3535
* "project.venv.requests.api.get"). Import-alias transparent. */
3636
cbm_svc_kind_t cbm_service_pattern_match(const char *resolved_qn);
3737
cbm_svc_kind_t cbm_service_pattern_match_named(const char *resolved_qn, const char *name);
38+
/* For graph-qualified symbols: project identity is not library evidence. */
39+
cbm_svc_kind_t cbm_service_pattern_match_in_project(const char *resolved_qn, const char *name,
40+
const char *project_name);
3841

3942
/* True for a bare, unqualified call to the native `fetch()` API. Deliberately
4043
* NOT part of the substring tables above: those are matched unconditionally

‎src/pipeline/pass_calls.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,11 @@ static bool emit_classified_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
852852
const char **imp_keys, const char **imp_vals, int imp_count,
853853
bool suppress_plain_calls, const char *route_mount,
854854
CBMLanguage lang) {
855-
cbm_svc_kind_t svc =
856-
cbm_service_pattern_match_named(res->qualified_name, target ? target->name : NULL);
855+
cbm_svc_kind_t svc = cbm_service_pattern_match_in_project(
856+
res->qualified_name, target ? target->name : NULL,
857+
target && res->qualified_name && strcmp(target->qualified_name, res->qualified_name) == 0
858+
? ctx->project_name
859+
: NULL);
857860
if (svc == CBM_SVC_ROUTE_REG && route_reg_path(call, lang) != NULL) {
858861
return handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals,
859862
imp_count, route_mount, lang);
@@ -1387,12 +1390,15 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBM
13871390
* the missing target must NOT drop the call — otherwise no HTTP_CALLS edge
13881391
* is written and cross-repo matching finds nothing (#523). Emit directly
13891392
* when the call carries a URL/topic first argument. */
1390-
if (calls_emit_service_call(ctx, call, source_node,
1391-
cbm_service_pattern_match(res.qualified_name), &res, evidence)) {
1393+
const cbm_gbuf_node_t *target_node = cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name);
1394+
if (calls_emit_service_call(
1395+
ctx, call, source_node,
1396+
cbm_service_pattern_match_in_project(res.qualified_name, NULL,
1397+
target_node ? ctx->project_name : NULL),
1398+
&res, evidence)) {
13921399
return SKIP_ONE;
13931400
}
13941401

1395-
const cbm_gbuf_node_t *target_node = cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name);
13961402
if (!target_node || source_node->id == target_node->id) {
13971403
return 0;
13981404
}

‎src/pipeline/pass_parallel.c‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,12 +2866,15 @@ static void emit_trpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, cons
28662866
static bool emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
28672867
const cbm_gbuf_node_t *target, const CBMCall *call,
28682868
const cbm_resolution_t *res, const char *module_qn,
2869-
const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,
2870-
const char **imp_keys, const char **imp_vals, int imp_count,
2871-
bool suppress_plain_calls, const char *route_mount,
2872-
CBMLanguage lang) {
2873-
cbm_svc_kind_t svc =
2874-
cbm_service_pattern_match_named(res->qualified_name, target ? target->name : NULL);
2869+
const char *project_name, const cbm_registry_t *registry,
2870+
const cbm_gbuf_t *main_gbuf, const char **imp_keys,
2871+
const char **imp_vals, int imp_count, bool suppress_plain_calls,
2872+
const char *route_mount, CBMLanguage lang) {
2873+
cbm_svc_kind_t svc = cbm_service_pattern_match_in_project(
2874+
res->qualified_name, target ? target->name : NULL,
2875+
target && res->qualified_name && strcmp(target->qualified_name, res->qualified_name) == 0
2876+
? project_name
2877+
: NULL);
28752878
const char *arg = call->first_string_arg;
28762879

28772880
/* Also detect route registration by callee name suffix alone (handles unresolved
@@ -3620,8 +3623,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
36203623
.strategy = "service_pattern"};
36213624
site_evidence->calls_emitted |=
36223625
emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &svc_res,
3623-
module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
3624-
imp_count, false, route_mount, lang);
3626+
module_qn, rc->project_name, rc->registry, rc->main_gbuf,
3627+
imp_keys, imp_vals, imp_count, false, route_mount, lang);
36253628
continue;
36263629
}
36273630
}
@@ -3643,8 +3646,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
36433646
site_evidence->candidate_qn = count == SKIP_ONE ? target->qualified_name : NULL;
36443647
site_evidence->calls_emitted |=
36453648
emit_service_edge(ws->local_edge_buf, source_node, target, call, &selected,
3646-
module_qn, rc->registry, rc->main_gbuf, imp_keys,
3647-
imp_vals, imp_count, false, route_mount, lang);
3649+
module_qn, rc->project_name, rc->registry, rc->main_gbuf,
3650+
imp_keys, imp_vals, imp_count, false, route_mount, lang);
36483651
ws->calls_resolved++;
36493652
}
36503653
continue;
@@ -3680,8 +3683,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
36803683
* route/HTTP/service classification is unchanged. */
36813684
site_evidence->calls_emitted |=
36823685
emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &fake_res,
3683-
module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
3684-
imp_count, true, route_mount, lang);
3686+
module_qn, rc->project_name, rc->registry, rc->main_gbuf,
3687+
imp_keys, imp_vals, imp_count, true, route_mount, lang);
36853688
} else if (cbm_service_pattern_is_global_fetch(call->callee_name)) {
36863689
/* Native `fetch()` (#856): only the global API once resolution
36873690
* has failed to find a local/imported `fetch`. Call the low-level
@@ -3790,19 +3793,21 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
37903793
(u[0] == '/' || strstr(u, "://") != NULL ||
37913794
(psvc == CBM_SVC_ASYNC && strlen(u) > PP_ESC_SPACE));
37923795
if (url_or_topic) {
3793-
site_evidence->calls_emitted |= emit_service_edge(
3794-
ws->local_edge_buf, source_node, NULL, call, &res, module_qn, rc->registry,
3795-
rc->main_gbuf, imp_keys, imp_vals, imp_count, false, route_mount, lang);
3796+
site_evidence->calls_emitted |=
3797+
emit_service_edge(ws->local_edge_buf, source_node, NULL, call, &res,
3798+
module_qn, rc->project_name, rc->registry, rc->main_gbuf,
3799+
imp_keys, imp_vals, imp_count, false, route_mount, lang);
37963800
ws->calls_resolved++;
37973801
}
37983802
}
37993803
continue;
38003804
}
38013805
site_evidence->candidate_qn = target_node->qualified_name;
38023806
_rc_t0 = extract_now_ns();
3803-
site_evidence->calls_emitted |= emit_service_edge(
3804-
ws->local_edge_buf, source_node, target_node, call, &res, module_qn, rc->registry,
3805-
rc->main_gbuf, imp_keys, imp_vals, imp_count, drop_plain_call, route_mount, lang);
3807+
site_evidence->calls_emitted |=
3808+
emit_service_edge(ws->local_edge_buf, source_node, target_node, call, &res, module_qn,
3809+
rc->project_name, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
3810+
imp_count, drop_plain_call, route_mount, lang);
38063811
atomic_fetch_add_explicit(&rc->time_ns_rc_emit, extract_now_ns() - _rc_t0,
38073812
memory_order_relaxed);
38083813
ws->calls_resolved++;

‎tests/test_infrascan.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ TEST(infrascan_service_pattern_match_rejects_ids_inside_words) {
184184
};
185185
ASSERT_EQ(svc_case_mismatches(cases), 0);
186186
ASSERT_EQ(cbm_service_pattern_match_named("proj.worker.run(_:Alamofire)", "run"), CBM_SVC_NONE);
187+
ASSERT_EQ(cbm_service_pattern_match_in_project("Dio.src.nav.navigateTo", "navigateTo", "Dio"),
188+
CBM_SVC_NONE);
189+
ASSERT_EQ(cbm_service_pattern_match_in_project("Dio.src.axios.get", "get", "Dio"),
190+
CBM_SVC_HTTP);
191+
ASSERT_EQ(cbm_service_pattern_match_in_project("axios.get", NULL, "Dio"), CBM_SVC_HTTP);
192+
ASSERT_EQ(cbm_service_pattern_match_in_project("Dio.client.get", "get", "Di"), CBM_SVC_HTTP);
187193
ASSERT_EQ(cbm_service_pattern_match_named("proj.Alamofire.request(_:String)", "request"),
188194
CBM_SVC_HTTP);
189195
/* A field whose name contains a call keeps its complete QN. */

‎tests/test_pipeline.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16065,7 +16065,7 @@ TEST(pipeline_arg_url_skips_client_navigation) {
1606516065
free(saved_single);
1606616066
FAIL("save environment");
1606716067
}
16068-
char tmp[256] = "/tmp/cbm_arg_url_nav_XXXXXX";
16068+
char tmp[256] = "/tmp/cbm_arg_url_nav_Dio_XXXXXX";
1606916069
if (!cbm_mkdtemp(tmp)) {
1607016070
free(saved_workers);
1607116071
free(saved_single);

0 commit comments

Comments
 (0)