Skip to content

Commit 8182026

Browse files
committed
fix(pipeline): run the external-import guard after route classification
The DeusData#1355 guard dropped the call before the emitters ran, so it did not only remove the fabricated CALLS edge it is meant to remove: it also skipped the route, HTTP, CONFIG and URL classification that happens inside emit_classified_edge / emit_service_edge. A PR that claims to touch nothing but weak same-name CALLS edges was silently costing Route nodes, and with them every HANDLES edge that pass_route_nodes.c later bridges onto those routes. The shape is not hypothetical. A route registration whose router is a dependency is exactly a bare call bound by a package specifier: the resolved QN carries the router library name, emit_classified_edge reads it as CBM_SVC_ROUTE_REG, and the first argument is path-shaped. On a 66-file TypeScript fixture main mints __route__ANY__/orders and the guard removed it, on both resolvers. The fix is the seam the DeusData#592/DeusData#606 member guard already uses, for the same reason and with the same comment: join the predicate to drop_plain_call and let the emitter decide. Only the plain-CALLS fall-through is suppressed, so the fabricated edge still goes and every service edge stays main-identical. The two resolvers keep identical gates, as the notes in both files require. The new pipeline test asserts both halves on both resolvers: the Route node survives, and a second bare call from the same external package in the same file is still cut, so the first assertion cannot pass by the guard having been disarmed. Signed-off-by: Yyunozor <yyunozor@icloud.com>
1 parent 138a622 commit 8182026

3 files changed

Lines changed: 131 additions & 21 deletions

File tree

‎src/pipeline/pass_calls.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,22 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
634634
* flag is set only for Python — this gate MUST match pass_parallel.c's
635635
* exactly, for the same divergence reason noted above. */
636636
bool suppress_weak_local_binding = lang == CBM_LANG_PYTHON;
637+
/* #1355: `import { eq } from "drizzle-orm"` binds `eq` to a package that is
638+
* not in the indexed tree, so a project-wide same-name guess must not turn
639+
* `eq(...)` into a CALLS edge to an unrelated project `eq`. Joined to
640+
* drop_plain_call for the reason spelled out above: dropping the call here
641+
* would also skip route/HTTP/CONFIG classification, and a route
642+
* registration reached through a static import (`import static
643+
* spark.Spark.get` + `get("/x", handler)`) is exactly a bare call bound by
644+
* a package specifier. Suppressing only the plain-CALLS fall-through keeps
645+
* every Route node and service edge main-identical. */
637646
bool drop_plain_call =
638647
cbm_suppress_weak_member_match(suppress_weak_member, call->is_method, res.strategy) ||
639648
cbm_suppress_weak_local_binding_call(suppress_weak_local_binding,
640-
call->callee_is_locally_bound, res.strategy);
649+
call->callee_is_locally_bound, res.strategy) ||
650+
cbm_suppress_external_import_shadow(call->callee_name, res.strategy, file_imports, imp_keys,
651+
imp_count, cbm_pipeline_get_pkgmap(),
652+
cbm_pipeline_get_nsmap());
641653

642654
/* Service-pattern HTTP/ASYNC calls to an EXTERNAL client library (e.g.
643655
* `requests.get("/api/orders/{id}")`) resolve to a QN containing the library
@@ -669,16 +681,6 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
669681
if (cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
670682
return 0;
671683
}
672-
/* #1355: `import { eq } from "drizzle-orm"` binds `eq` to a package that is
673-
* not in the indexed tree, so a project-wide same-name guess must not turn
674-
* `eq(...)` into a CALLS edge to an unrelated project `eq`. Placed with the
675-
* #725 guard, after the service-pattern bypasses above, so no HTTP/route
676-
* edge can be lost to it. */
677-
if (cbm_suppress_external_import_shadow(call->callee_name, res.strategy, file_imports, imp_keys,
678-
imp_count, cbm_pipeline_get_pkgmap(),
679-
cbm_pipeline_get_nsmap())) {
680-
return 0;
681-
}
682684
emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys, imp_vals,
683685
imp_count, drop_plain_call);
684686
return SKIP_ONE;

‎src/pipeline/pass_parallel.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,10 +2499,18 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
24992499
/* Bare-call local-binding suppression — see the note in pass_calls.c.
25002500
* This gate MUST stay identical to the one there. */
25012501
bool suppress_weak_local_binding = lang == CBM_LANG_PYTHON;
2502+
/* #1355: same guard as pass_calls.c, and joined to drop_plain_call for
2503+
* the same reason — a `continue` here would also skip route/HTTP/CONFIG
2504+
* classification, and a static-import route registration is a bare call
2505+
* bound by a package specifier. Suppress only the plain-CALLS
2506+
* fall-through so every Route node stays main-identical. */
25022507
bool drop_plain_call =
25032508
cbm_suppress_weak_member_match(suppress_weak_member, call->is_method, res.strategy) ||
25042509
cbm_suppress_weak_local_binding_call(suppress_weak_local_binding,
2505-
call->callee_is_locally_bound, res.strategy);
2510+
call->callee_is_locally_bound, res.strategy) ||
2511+
cbm_suppress_external_import_shadow(call->callee_name, res.strategy, &result->imports,
2512+
imp_keys, imp_count, cbm_pipeline_get_pkgmap(),
2513+
cbm_pipeline_get_nsmap());
25062514

25072515
/* Service-pattern HTTP/ASYNC client call (`requests.get(url)`): the
25082516
* service signal lives in the callee_name. The registry can mis-resolve
@@ -2573,15 +2581,6 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
25732581
* CALLS edge across a language boundary. */
25742582
continue;
25752583
}
2576-
if (target_node && source_node->id != target_node->id &&
2577-
cbm_suppress_external_import_shadow(call->callee_name, res.strategy, &result->imports,
2578-
imp_keys, imp_count, cbm_pipeline_get_pkgmap(),
2579-
cbm_pipeline_get_nsmap())) {
2580-
/* #1355: same guard as pass_calls.c — a bare call bound by an
2581-
* external package import must not become a CALLS edge to an
2582-
* unrelated project symbol of the same name. */
2583-
continue;
2584-
}
25852584
if (!target_node || source_node->id == target_node->id) {
25862585
/* HTTP/ASYNC calls to an EXTERNAL client library (`requests.get(url)`)
25872586
* resolve to an unindexed QN (target_node == NULL), but their edge

‎tests/test_pipeline.c‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5348,6 +5348,114 @@ TEST(pipeline_external_import_shadow_keeps_declared_package_issue1355) {
53485348
PASS();
53495349
}
53505350

5351+
/* #1355: the guard must suppress ONLY the plain-CALLS fall-through, never the
5352+
* route/HTTP/CONFIG classification that runs inside the emitters. A bare call
5353+
* bound by a package import is exactly the shape a route registration takes
5354+
* when the router is a dependency, and dropping it before classification costs
5355+
* the Route node and every HANDLES edge downstream of it. Same reasoning, and
5356+
* the same drop_plain_call seam, as the #592/#606 member guard. */
5357+
static void write_route_shadow_fixture(const char *dir, int pad_files) {
5358+
/* The project symbols the guess would bind to. The file name puts "express"
5359+
* in their qualified names, which is what makes the resolved QN classify as
5360+
* a route registration — the same substring match main uses on real trees. */
5361+
write_temp_file(dir, "app/express-routes.ts",
5362+
"export function regGet(path: string, handler: unknown): string {\n"
5363+
" return path;\n"
5364+
"}\n"
5365+
"export function regSpec(label: string): string {\n"
5366+
" return label;\n"
5367+
"}\n");
5368+
/* Both names come from a package outside the tree. `regGet` carries a
5369+
* path-shaped first argument, so it is a route registration; `regSpec` is
5370+
* an ordinary fabricated edge and must still go. */
5371+
write_temp_file(dir, "app/server.ts",
5372+
"import { regGet, regSpec } from 'vendor-router';\n"
5373+
"export function boot(): string {\n"
5374+
" return regGet('/orders', () => 'ok') + regSpec('case');\n"
5375+
"}\n");
5376+
for (int i = 0; i < pad_files; i++) {
5377+
char name[64];
5378+
char body[128];
5379+
snprintf(name, sizeof(name), "app/pad_%02d.ts", i);
5380+
snprintf(body, sizeof(body), "export function routePad%02d(): number { return %d; }\n", i,
5381+
i);
5382+
write_temp_file(dir, name, body);
5383+
}
5384+
}
5385+
5386+
static int assert_route_shadow_contract(const char *dir, const char *db_name) {
5387+
char db_path[512];
5388+
snprintf(db_path, sizeof(db_path), "%s/%s", dir, db_name);
5389+
cbm_pipeline_t *p = cbm_pipeline_new(dir, db_path, CBM_MODE_FULL);
5390+
if (!p) {
5391+
return 1;
5392+
}
5393+
if (cbm_pipeline_run(p) != 0) {
5394+
cbm_pipeline_free(p);
5395+
return 2;
5396+
}
5397+
const char *project = cbm_pipeline_project_name(p);
5398+
cbm_store_t *s = cbm_store_open_path(db_path);
5399+
if (!s) {
5400+
cbm_pipeline_free(p);
5401+
return 3;
5402+
}
5403+
int rc = 0;
5404+
/* (1) the Route node survives the guard. RED when the guard returns before
5405+
* the emitter: main mints __route__ANY__/orders here and the published
5406+
* guard lost it, together with every HANDLES edge that hangs off it. */
5407+
if (count_nodes_named(s, project, "/orders") < 1) {
5408+
rc = 4;
5409+
}
5410+
/* (2) the fabricated plain-CALLS edge in the same file is still removed, so
5411+
* (1) cannot pass by the guard having been disarmed. */
5412+
if (rc == 0 && cross_file_call_exists(s, project, "boot", "regSpec")) {
5413+
rc = 5;
5414+
}
5415+
cbm_store_close(s);
5416+
cbm_pipeline_free(p);
5417+
return rc;
5418+
}
5419+
5420+
TEST(pipeline_external_import_shadow_keeps_route_registration_issue1355) {
5421+
char tmp[256];
5422+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_route_import_shadow_XXXXXX");
5423+
if (!cbm_mkdtemp(tmp)) {
5424+
FAIL("tmpdir");
5425+
}
5426+
write_route_shadow_fixture(tmp, EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD);
5427+
5428+
const char *old_workers = getenv("CBM_WORKERS");
5429+
char *saved_workers = old_workers ? strdup(old_workers) : NULL;
5430+
const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
5431+
char *saved_single = old_single ? strdup(old_single) : NULL;
5432+
5433+
cbm_setenv("CBM_INDEX_SINGLE_THREAD", "1", 1);
5434+
int sequential = assert_route_shadow_contract(tmp, "route-sequential.db");
5435+
5436+
cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");
5437+
cbm_setenv("CBM_WORKERS", "4", 1);
5438+
int parallel = assert_route_shadow_contract(tmp, "route-parallel.db");
5439+
5440+
if (saved_workers) {
5441+
cbm_setenv("CBM_WORKERS", saved_workers, 1);
5442+
free(saved_workers);
5443+
} else {
5444+
cbm_unsetenv("CBM_WORKERS");
5445+
}
5446+
if (saved_single) {
5447+
cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);
5448+
free(saved_single);
5449+
} else {
5450+
cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");
5451+
}
5452+
th_rmtree(tmp);
5453+
5454+
ASSERT_EQ(sequential, 0);
5455+
ASSERT_EQ(parallel, 0);
5456+
PASS();
5457+
}
5458+
53515459
TEST(pipeline_tsjs_receiver_parallel_keeps_service_edges) {
53525460
char tmp[256];
53535461
snprintf(tmp, sizeof(tmp), "/tmp/cbm_tsjs_par_XXXXXX");
@@ -13699,6 +13807,7 @@ SUITE(pipeline) {
1369913807
RUN_TEST(pipeline_external_import_shadow_not_bound_to_local_homonym_issue1355);
1370013808
RUN_TEST(pipeline_external_import_shadow_keeps_workspace_sibling_issue1355);
1370113809
RUN_TEST(pipeline_external_import_shadow_keeps_declared_package_issue1355);
13810+
RUN_TEST(pipeline_external_import_shadow_keeps_route_registration_issue1355);
1370213811
RUN_TEST(pipeline_parallel_python_cross_only_dunder_gets_synthetic_carrier);
1370313812
RUN_TEST(pipeline_parallel_rust_cross_only_macro_hidden_gets_synthetic_carrier);
1370413813
RUN_TEST(pipeline_arg_url_rejects_non_http_slash_arguments);

0 commit comments

Comments
 (0)