Skip to content

Commit 3aef1c0

Browse files
authored
Merge pull request DeusData#2464 from DeusData/fix/route-registration-before-xlang-suppression
fix(pipeline): route registrations survive the cross-language guard
2 parents 971afc0 + 124c5e2 commit 3aef1c0

3 files changed

Lines changed: 203 additions & 1 deletion

File tree

‎src/pipeline/pass_calls.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,19 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBM
893893
* Store.commit() call to a JS function named commit (or a Bash main
894894
* to a Python main). Drop that weak cross-language edge. */
895895
if (cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
896+
/* Refusing the binding leaves the callee unresolved, and an
897+
* unresolved route-registration callee is still a registration:
898+
* `Route::get('/x', ...)` beside a JS `get`, `app.get('/x', h)`
899+
* beside a Python `get`. Give it the same Route the #952
900+
* unresolved-callee fallback above mints, and nothing else. Dropping
901+
* the whole call lost every GET registration in a mixed-language repo
902+
* while POST (no `post` to collide with) survived. */
903+
if (cbm_service_pattern_route_method(call->callee_name) != NULL && call->first_string_arg &&
904+
call->first_string_arg[0] == '/') {
905+
handle_route_registration(ctx, call, source_node, module_qn, imp_keys, imp_vals,
906+
imp_count);
907+
return SKIP_ONE;
908+
}
896909
return 0;
897910
}
898911
emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys, imp_vals,

‎src/pipeline/pass_parallel.c‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,35 @@ static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
25962596
}
25972597
}
25982598

2599+
/* The #725 guard refuses a suffix_match binding across a language boundary,
2600+
* which leaves the callee unresolved. An unresolved callee the route
2601+
* classifier recognises is still a registration: `Route::get('/x', ...)`
2602+
* beside a JS `get`, `app.get('/x', h)` beside a Python `get`. Emit exactly
2603+
* the Route + CALLS + HANDLES that the unresolved-callee (callee_suffix)
2604+
* fallback in resolve_file_calls emits for it, classified by callee name the
2605+
* same way emit_service_edge classifies that fallback, and nothing else: no
2606+
* CALLS edge to the refused target and no URL-argument scan. Dropping the
2607+
* whole call lost every GET registration in a mixed-language repo while POST
2608+
* (no `post` to collide with) survived. Mirrors pass_calls.c. */
2609+
static void emit_xlang_refused_route(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
2610+
const CBMCall *call, const char *module_qn,
2611+
const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,
2612+
const char **imp_keys, const char **imp_vals, int imp_count) {
2613+
if (cbm_service_pattern_route_method(call->callee_name) == NULL) {
2614+
return;
2615+
}
2616+
cbm_svc_kind_t svc = cbm_service_pattern_match(call->callee_name);
2617+
if (svc != CBM_SVC_NONE && svc != CBM_SVC_ROUTE_REG) {
2618+
return;
2619+
}
2620+
const char *handler_ref = NULL;
2621+
const char *route_path = find_route_path_in_args(call, &handler_ref);
2622+
if (route_path) {
2623+
emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn, registry,
2624+
main_gbuf, imp_keys, imp_vals, imp_count);
2625+
}
2626+
}
2627+
25992628
/* Find the source node for an edge: enclosing function or file node. */
26002629
/* This worker's last file-node answer. The graph buffer is read-only for the
26012630
* whole of phase 4 and a file's rel_path pointer is stable within it, so the
@@ -3168,7 +3197,10 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
31683197
if (target_node && source_node->id != target_node->id &&
31693198
cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
31703199
/* #725: same guard as pass_calls.c — do not emit a suffix_match
3171-
* CALLS edge across a language boundary. */
3200+
* CALLS edge across a language boundary. A route registration
3201+
* behind the refused binding still gets its Route. */
3202+
emit_xlang_refused_route(ws->local_edge_buf, source_node, call, module_qn, rc->registry,
3203+
rc->main_gbuf, imp_keys, imp_vals, imp_count);
31723204
continue;
31733205
}
31743206
if (!target_node || source_node->id == target_node->id) {

‎tests/test_edge_types_probe.c‎

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,157 @@ TEST(override_go_interface) {
18241824
PASS();
18251825
}
18261826

1827+
/* ══════════════════════════════════════════════════════════════════
1828+
* ROUTE REGISTRATION vs the #725 cross-language guard.
1829+
*
1830+
* The route classifier recognises a registration by its callee
1831+
* (`Route::get`, `$router->get`, `app.get`) plus a path-shaped first
1832+
* argument. The registry still resolves the callee's bare name first, and in
1833+
* a mixed-language repo with imports it binds `get` by suffix_match to a
1834+
* same-named definition in ANOTHER language (a JS `get`, a Python `get`).
1835+
* The #725 guard rightly refuses that binding — but it dropped the whole
1836+
* call, before either resolver reached the route classification, so every
1837+
* GET registration vanished while POST (no `post` definition to collide
1838+
* with) survived: krayin/laravel-crm minted 1 of its 127 GET routes.
1839+
* The guard must keep dropping the false CALLS edge; the registration must
1840+
* survive. Each fixture also carries calls the guard must still drop.
1841+
* ══════════════════════════════════════════════════════════════════ */
1842+
1843+
/* Index `files` (padded onto the parallel path when `parallel`), then require
1844+
* the exact Route-name set `routes` AND zero CALLS edges into any definition
1845+
* named `get`: every `get` in these fixtures lives in a different language
1846+
* than its would-be callers, so any such edge is the binding #725 refuses. */
1847+
static int et_xlang_routes(const EtFile *files, int nfiles, bool parallel, const char **routes) {
1848+
EtProj lp;
1849+
cbm_store_t *store =
1850+
parallel ? et_index_parallel(&lp, files, nfiles) : et_index_files(&lp, files, nfiles);
1851+
cbm_node_t *nodes = NULL;
1852+
int node_count = 0;
1853+
int wanted = 0;
1854+
int ok = store != NULL;
1855+
while (routes[wanted]) {
1856+
wanted++;
1857+
}
1858+
if (!store || cbm_store_find_nodes_by_label(store, lp.project, "Route", &nodes, &node_count) !=
1859+
CBM_STORE_OK) {
1860+
ok = 0;
1861+
} else if (node_count != wanted) {
1862+
ok = 0;
1863+
}
1864+
for (int wi = 0; wi < wanted; wi++) {
1865+
int hit = 0;
1866+
for (int ni = 0; ni < node_count; ni++) {
1867+
if (nodes[ni].name && strcmp(nodes[ni].name, routes[wi]) == 0) {
1868+
hit = 1;
1869+
}
1870+
}
1871+
if (!hit) {
1872+
fprintf(stderr, " [ET-XLANG] missing Route %s\n", routes[wi]);
1873+
ok = 0;
1874+
}
1875+
}
1876+
if (!ok) {
1877+
fprintf(stderr, " [ET-XLANG] expected=%d actual=%d available:", wanted, node_count);
1878+
for (int ni = 0; ni < node_count; ni++) {
1879+
fprintf(stderr, " %s", nodes[ni].name ? nodes[ni].name : "<null>");
1880+
}
1881+
fprintf(stderr, "\n");
1882+
}
1883+
int false_calls = 0;
1884+
cbm_node_t *gets = NULL;
1885+
int get_count = 0;
1886+
if (store &&
1887+
cbm_store_find_nodes_by_name(store, lp.project, "get", &gets, &get_count) == CBM_STORE_OK) {
1888+
for (int gi = 0; gi < get_count; gi++) {
1889+
cbm_edge_t *in = NULL;
1890+
int in_count = 0;
1891+
if (cbm_store_find_edges_by_target_type(store, gets[gi].id, "CALLS", &in, &in_count) ==
1892+
CBM_STORE_OK) {
1893+
false_calls += in_count;
1894+
cbm_store_free_edges(in, in_count);
1895+
}
1896+
}
1897+
cbm_store_free_nodes(gets, get_count);
1898+
}
1899+
if (false_calls != 0) {
1900+
fprintf(stderr, " [ET-XLANG] %d cross-language CALLS into `get`\n", false_calls);
1901+
ok = 0;
1902+
}
1903+
cbm_store_free_nodes(nodes, node_count);
1904+
et_cleanup(&lp, store);
1905+
return ok;
1906+
}
1907+
1908+
/* Laravel: facade `Route::get` and `$router->get` beside two JS `get`
1909+
* definitions. Controls: POST is unchanged, and a bare PHP `get('/x')` (no
1910+
* route-registration callee) stays dropped — no Route, no CALLS into JS. */
1911+
static const EtFile et_xlang_laravel[] = {
1912+
{"app/Http/Controllers/LeadController.php",
1913+
"<?php\nnamespace App\\Http\\Controllers;\n\n"
1914+
"class LeadController\n{\n"
1915+
" public function index() { return []; }\n"
1916+
" public function store() { return []; }\n}\n"},
1917+
{"routes/web.php",
1918+
"<?php\nuse Illuminate\\Support\\Facades\\Route;\n"
1919+
"use App\\Http\\Controllers\\LeadController;\n\n"
1920+
"Route::get('/leads', [LeadController::class, 'index']);\n"
1921+
"Route::post('/leads/store', [LeadController::class, 'store']);\n"
1922+
"$router->get('/reports', [LeadController::class, 'index']);\n\n"
1923+
"function report_file() { return get('/files/report'); }\n"},
1924+
{"resources/js/http.js", "export function get(url) {\n return url;\n}\n"},
1925+
{"resources/js/store.js", "export class Store {\n get(key) {\n return key;\n }\n}\n"},
1926+
};
1927+
static const char *et_xlang_laravel_routes[] = {"/leads", "/leads/store", "/reports", NULL};
1928+
1929+
TEST(routes_laravel_get_survives_xlang_guard) {
1930+
ASSERT_TRUE(et_xlang_routes(et_xlang_laravel,
1931+
(int)(sizeof(et_xlang_laravel) / sizeof(et_xlang_laravel[0])),
1932+
false, et_xlang_laravel_routes));
1933+
PASS();
1934+
}
1935+
1936+
TEST(routes_laravel_get_survives_xlang_guard_parallel) {
1937+
ASSERT_TRUE(et_xlang_routes(et_xlang_laravel,
1938+
(int)(sizeof(et_xlang_laravel) / sizeof(et_xlang_laravel[0])),
1939+
true, et_xlang_laravel_routes));
1940+
PASS();
1941+
}
1942+
1943+
/* Express: `app.get` beside two Python `get` definitions. Controls: POST is
1944+
* unchanged; a member `memo.get(key)` (route suffix, no path) and a bare
1945+
* `get('/cache/key')` stay dropped — no Route, no CALLS into Python. */
1946+
static const EtFile et_xlang_express[] = {
1947+
{"web/server.js",
1948+
"const express = require('express');\n"
1949+
"const { health } = require('./handlers');\n\n"
1950+
"const app = express();\n\n"
1951+
"app.get('/health', health);\n"
1952+
"app.post('/items', health);\n\n"
1953+
"function readCache(memo, key) {\n"
1954+
" return memo.get(key) || get('/cache/key');\n"
1955+
"}\n"
1956+
"module.exports = { readCache };\n"},
1957+
{"web/handlers.js",
1958+
"function health(req, res) {\n return res;\n}\nmodule.exports = { health };\n"},
1959+
{"tools/cache.py", "def get(key):\n return key\n"},
1960+
{"tools/store.py", "class Store:\n def get(self, key):\n return key\n"},
1961+
};
1962+
static const char *et_xlang_express_routes[] = {"/health", "/items", NULL};
1963+
1964+
TEST(routes_express_get_survives_xlang_guard) {
1965+
ASSERT_TRUE(et_xlang_routes(et_xlang_express,
1966+
(int)(sizeof(et_xlang_express) / sizeof(et_xlang_express[0])),
1967+
false, et_xlang_express_routes));
1968+
PASS();
1969+
}
1970+
1971+
TEST(routes_express_get_survives_xlang_guard_parallel) {
1972+
ASSERT_TRUE(et_xlang_routes(et_xlang_express,
1973+
(int)(sizeof(et_xlang_express) / sizeof(et_xlang_express[0])),
1974+
true, et_xlang_express_routes));
1975+
PASS();
1976+
}
1977+
18271978
/* ══════════════════════════════════════════════════════════════════
18281979
* SUITE
18291980
* ══════════════════════════════════════════════════════════════════ */
@@ -1912,4 +2063,10 @@ SUITE(edge_types_probe) {
19122063

19132064
/* OVERRIDE — Go interface method override (parallel path) */
19142065
RUN_TEST(override_go_interface);
2066+
2067+
/* Route registration vs the #725 cross-language guard (both resolvers) */
2068+
RUN_TEST(routes_laravel_get_survives_xlang_guard);
2069+
RUN_TEST(routes_laravel_get_survives_xlang_guard_parallel);
2070+
RUN_TEST(routes_express_get_survives_xlang_guard);
2071+
RUN_TEST(routes_express_get_survives_xlang_guard_parallel);
19152072
}

0 commit comments

Comments
 (0)