Skip to content

Commit 124c5e2

Browse files
committed
fix(pipeline): route registrations survive the cross-language guard
Why: in a mixed-language repo the registry resolves the bare name of a route-registration callee (`Route::get`, `$router->get`, `app.get`) before either resolver classifies the call, and with imports in play it binds `get` by suffix_match to a same-named definition in another language (a JS `get`, a Python `get`). The DeusData#725 guard rightly refuses that binding, but it dropped the whole call, so the callee-suffix route classification never ran. Every GET registration vanished while POST/PUT/DELETE (nothing named `post` to collide with) survived: krayin/laravel-crm minted 1 GET Route for its 126 `Route::get` calls: all 126 were bound (suffix_match, 19 candidates) to `get` in a vendored Chart.js copy under resources/assets/js and refused. Fix: a refused binding leaves the callee unresolved, so at the DeusData#725 guard both resolvers now give a route-registration callee exactly the Route the unresolved-callee fallback mints for it, and nothing else. Sequential: the DeusData#952 fallback's predicate + handle_route_registration. Parallel: emit_xlang_refused_route classifies by callee the way emit_service_edge classifies the callee_suffix fallback and emits only emit_route_registration. The guard, its strategies and its per-language scope are unchanged: no CALLS edge to the refused target, no URL argument scan, every other refused call is still dropped. Proof (fresh index per run, macOS arm64, origin/main 1f9b4db): - krayin/laravel-crm 03ebedd7 with the pending Laravel slashless, handler and withRouting-prefix patches applied: GET Routes 1 -> 126, CALLS->Route 130 -> 257, HANDLES 1 -> 4. New GET CALLS per route file equal the `Route::get(` count in all 14 files; 0 edges removed; 0 new edges into non-Route nodes. - krayin on origin/main alone: GET 1 -> 2 (before the slashless patch only the two `Route::get('/', ...)` paths are classifiable). - Suppression intact: code CALLS unchanged (krayin 16,439; BookStack a09aa8aa 34,292) and cross-language suffix_match CALLS stay 0. - Side effect: PHP test-client verb calls (`$this->get('/x')`) that the guard had hidden now get the same route classification main already gives their unhidden siblings (BookStack +43 on 544, krayin +1). That classification is pre-existing and separate. Tests: edge_types_probe routes_laravel_get_survives_xlang_guard, routes_express_get_survives_xlang_guard and their _parallel twins. Each fixture also asserts that a bare or member `get` call bound across languages still yields no CALLS edge and no Route. RED 3x before, green after; reverting either resolver re-reds exactly its own two tests. Signed-off-by: Martin Vogel <[email protected]>
1 parent 1f9b4db commit 124c5e2

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
@@ -680,6 +680,19 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
680680
* Store.commit() call to a JS function named commit (or a Bash main
681681
* to a Python main). Drop that weak cross-language edge. */
682682
if (cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
683+
/* Refusing the binding leaves the callee unresolved, and an
684+
* unresolved route-registration callee is still a registration:
685+
* `Route::get('/x', ...)` beside a JS `get`, `app.get('/x', h)`
686+
* beside a Python `get`. Give it the same Route the #952
687+
* unresolved-callee fallback above mints, and nothing else. Dropping
688+
* the whole call lost every GET registration in a mixed-language repo
689+
* while POST (no `post` to collide with) survived. */
690+
if (cbm_service_pattern_route_method(call->callee_name) != NULL && call->first_string_arg &&
691+
call->first_string_arg[0] == '/') {
692+
handle_route_registration(ctx, call, source_node, module_qn, imp_keys, imp_vals,
693+
imp_count);
694+
return SKIP_ONE;
695+
}
683696
return 0;
684697
}
685698
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
@@ -2492,6 +2492,35 @@ static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
24922492
detect_url_in_args(gbuf, source, call);
24932493
}
24942494

2495+
/* The #725 guard refuses a suffix_match binding across a language boundary,
2496+
* which leaves the callee unresolved. An unresolved callee the route
2497+
* classifier recognises is still a registration: `Route::get('/x', ...)`
2498+
* beside a JS `get`, `app.get('/x', h)` beside a Python `get`. Emit exactly
2499+
* the Route + CALLS + HANDLES that the unresolved-callee (callee_suffix)
2500+
* fallback in resolve_file_calls emits for it, classified by callee name the
2501+
* same way emit_service_edge classifies that fallback, and nothing else: no
2502+
* CALLS edge to the refused target and no URL-argument scan. Dropping the
2503+
* whole call lost every GET registration in a mixed-language repo while POST
2504+
* (no `post` to collide with) survived. Mirrors pass_calls.c. */
2505+
static void emit_xlang_refused_route(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
2506+
const CBMCall *call, const char *module_qn,
2507+
const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,
2508+
const char **imp_keys, const char **imp_vals, int imp_count) {
2509+
if (cbm_service_pattern_route_method(call->callee_name) == NULL) {
2510+
return;
2511+
}
2512+
cbm_svc_kind_t svc = cbm_service_pattern_match(call->callee_name);
2513+
if (svc != CBM_SVC_NONE && svc != CBM_SVC_ROUTE_REG) {
2514+
return;
2515+
}
2516+
const char *handler_ref = NULL;
2517+
const char *route_path = find_route_path_in_args(call, &handler_ref);
2518+
if (route_path) {
2519+
emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn, registry,
2520+
main_gbuf, imp_keys, imp_vals, imp_count);
2521+
}
2522+
}
2523+
24952524
/* Find the source node for an edge: enclosing function or file node. */
24962525
/* This worker's last file-node answer. The graph buffer is read-only for the
24972526
* whole of phase 4 and a file's rel_path pointer is stable within it, so the
@@ -3025,7 +3054,10 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
30253054
if (target_node && source_node->id != target_node->id &&
30263055
cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
30273056
/* #725: same guard as pass_calls.c — do not emit a suffix_match
3028-
* CALLS edge across a language boundary. */
3057+
* CALLS edge across a language boundary. A route registration
3058+
* behind the refused binding still gets its Route. */
3059+
emit_xlang_refused_route(ws->local_edge_buf, source_node, call, module_qn, rc->registry,
3060+
rc->main_gbuf, imp_keys, imp_vals, imp_count);
30293061
continue;
30303062
}
30313063
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
@@ -1684,6 +1684,157 @@ TEST(override_go_interface) {
16841684
PASS();
16851685
}
16861686

1687+
/* ══════════════════════════════════════════════════════════════════
1688+
* ROUTE REGISTRATION vs the #725 cross-language guard.
1689+
*
1690+
* The route classifier recognises a registration by its callee
1691+
* (`Route::get`, `$router->get`, `app.get`) plus a path-shaped first
1692+
* argument. The registry still resolves the callee's bare name first, and in
1693+
* a mixed-language repo with imports it binds `get` by suffix_match to a
1694+
* same-named definition in ANOTHER language (a JS `get`, a Python `get`).
1695+
* The #725 guard rightly refuses that binding — but it dropped the whole
1696+
* call, before either resolver reached the route classification, so every
1697+
* GET registration vanished while POST (no `post` definition to collide
1698+
* with) survived: krayin/laravel-crm minted 1 of its 127 GET routes.
1699+
* The guard must keep dropping the false CALLS edge; the registration must
1700+
* survive. Each fixture also carries calls the guard must still drop.
1701+
* ══════════════════════════════════════════════════════════════════ */
1702+
1703+
/* Index `files` (padded onto the parallel path when `parallel`), then require
1704+
* the exact Route-name set `routes` AND zero CALLS edges into any definition
1705+
* named `get`: every `get` in these fixtures lives in a different language
1706+
* than its would-be callers, so any such edge is the binding #725 refuses. */
1707+
static int et_xlang_routes(const EtFile *files, int nfiles, bool parallel, const char **routes) {
1708+
EtProj lp;
1709+
cbm_store_t *store =
1710+
parallel ? et_index_parallel(&lp, files, nfiles) : et_index_files(&lp, files, nfiles);
1711+
cbm_node_t *nodes = NULL;
1712+
int node_count = 0;
1713+
int wanted = 0;
1714+
int ok = store != NULL;
1715+
while (routes[wanted]) {
1716+
wanted++;
1717+
}
1718+
if (!store || cbm_store_find_nodes_by_label(store, lp.project, "Route", &nodes, &node_count) !=
1719+
CBM_STORE_OK) {
1720+
ok = 0;
1721+
} else if (node_count != wanted) {
1722+
ok = 0;
1723+
}
1724+
for (int wi = 0; wi < wanted; wi++) {
1725+
int hit = 0;
1726+
for (int ni = 0; ni < node_count; ni++) {
1727+
if (nodes[ni].name && strcmp(nodes[ni].name, routes[wi]) == 0) {
1728+
hit = 1;
1729+
}
1730+
}
1731+
if (!hit) {
1732+
fprintf(stderr, " [ET-XLANG] missing Route %s\n", routes[wi]);
1733+
ok = 0;
1734+
}
1735+
}
1736+
if (!ok) {
1737+
fprintf(stderr, " [ET-XLANG] expected=%d actual=%d available:", wanted, node_count);
1738+
for (int ni = 0; ni < node_count; ni++) {
1739+
fprintf(stderr, " %s", nodes[ni].name ? nodes[ni].name : "<null>");
1740+
}
1741+
fprintf(stderr, "\n");
1742+
}
1743+
int false_calls = 0;
1744+
cbm_node_t *gets = NULL;
1745+
int get_count = 0;
1746+
if (store &&
1747+
cbm_store_find_nodes_by_name(store, lp.project, "get", &gets, &get_count) == CBM_STORE_OK) {
1748+
for (int gi = 0; gi < get_count; gi++) {
1749+
cbm_edge_t *in = NULL;
1750+
int in_count = 0;
1751+
if (cbm_store_find_edges_by_target_type(store, gets[gi].id, "CALLS", &in, &in_count) ==
1752+
CBM_STORE_OK) {
1753+
false_calls += in_count;
1754+
cbm_store_free_edges(in, in_count);
1755+
}
1756+
}
1757+
cbm_store_free_nodes(gets, get_count);
1758+
}
1759+
if (false_calls != 0) {
1760+
fprintf(stderr, " [ET-XLANG] %d cross-language CALLS into `get`\n", false_calls);
1761+
ok = 0;
1762+
}
1763+
cbm_store_free_nodes(nodes, node_count);
1764+
et_cleanup(&lp, store);
1765+
return ok;
1766+
}
1767+
1768+
/* Laravel: facade `Route::get` and `$router->get` beside two JS `get`
1769+
* definitions. Controls: POST is unchanged, and a bare PHP `get('/x')` (no
1770+
* route-registration callee) stays dropped — no Route, no CALLS into JS. */
1771+
static const EtFile et_xlang_laravel[] = {
1772+
{"app/Http/Controllers/LeadController.php",
1773+
"<?php\nnamespace App\\Http\\Controllers;\n\n"
1774+
"class LeadController\n{\n"
1775+
" public function index() { return []; }\n"
1776+
" public function store() { return []; }\n}\n"},
1777+
{"routes/web.php",
1778+
"<?php\nuse Illuminate\\Support\\Facades\\Route;\n"
1779+
"use App\\Http\\Controllers\\LeadController;\n\n"
1780+
"Route::get('/leads', [LeadController::class, 'index']);\n"
1781+
"Route::post('/leads/store', [LeadController::class, 'store']);\n"
1782+
"$router->get('/reports', [LeadController::class, 'index']);\n\n"
1783+
"function report_file() { return get('/files/report'); }\n"},
1784+
{"resources/js/http.js", "export function get(url) {\n return url;\n}\n"},
1785+
{"resources/js/store.js", "export class Store {\n get(key) {\n return key;\n }\n}\n"},
1786+
};
1787+
static const char *et_xlang_laravel_routes[] = {"/leads", "/leads/store", "/reports", NULL};
1788+
1789+
TEST(routes_laravel_get_survives_xlang_guard) {
1790+
ASSERT_TRUE(et_xlang_routes(et_xlang_laravel,
1791+
(int)(sizeof(et_xlang_laravel) / sizeof(et_xlang_laravel[0])),
1792+
false, et_xlang_laravel_routes));
1793+
PASS();
1794+
}
1795+
1796+
TEST(routes_laravel_get_survives_xlang_guard_parallel) {
1797+
ASSERT_TRUE(et_xlang_routes(et_xlang_laravel,
1798+
(int)(sizeof(et_xlang_laravel) / sizeof(et_xlang_laravel[0])),
1799+
true, et_xlang_laravel_routes));
1800+
PASS();
1801+
}
1802+
1803+
/* Express: `app.get` beside two Python `get` definitions. Controls: POST is
1804+
* unchanged; a member `memo.get(key)` (route suffix, no path) and a bare
1805+
* `get('/cache/key')` stay dropped — no Route, no CALLS into Python. */
1806+
static const EtFile et_xlang_express[] = {
1807+
{"web/server.js",
1808+
"const express = require('express');\n"
1809+
"const { health } = require('./handlers');\n\n"
1810+
"const app = express();\n\n"
1811+
"app.get('/health', health);\n"
1812+
"app.post('/items', health);\n\n"
1813+
"function readCache(memo, key) {\n"
1814+
" return memo.get(key) || get('/cache/key');\n"
1815+
"}\n"
1816+
"module.exports = { readCache };\n"},
1817+
{"web/handlers.js",
1818+
"function health(req, res) {\n return res;\n}\nmodule.exports = { health };\n"},
1819+
{"tools/cache.py", "def get(key):\n return key\n"},
1820+
{"tools/store.py", "class Store:\n def get(self, key):\n return key\n"},
1821+
};
1822+
static const char *et_xlang_express_routes[] = {"/health", "/items", NULL};
1823+
1824+
TEST(routes_express_get_survives_xlang_guard) {
1825+
ASSERT_TRUE(et_xlang_routes(et_xlang_express,
1826+
(int)(sizeof(et_xlang_express) / sizeof(et_xlang_express[0])),
1827+
false, et_xlang_express_routes));
1828+
PASS();
1829+
}
1830+
1831+
TEST(routes_express_get_survives_xlang_guard_parallel) {
1832+
ASSERT_TRUE(et_xlang_routes(et_xlang_express,
1833+
(int)(sizeof(et_xlang_express) / sizeof(et_xlang_express[0])),
1834+
true, et_xlang_express_routes));
1835+
PASS();
1836+
}
1837+
16871838
/* ══════════════════════════════════════════════════════════════════
16881839
* SUITE
16891840
* ══════════════════════════════════════════════════════════════════ */
@@ -1766,4 +1917,10 @@ SUITE(edge_types_probe) {
17661917

17671918
/* OVERRIDE — Go interface method override (parallel path) */
17681919
RUN_TEST(override_go_interface);
1920+
1921+
/* Route registration vs the #725 cross-language guard (both resolvers) */
1922+
RUN_TEST(routes_laravel_get_survives_xlang_guard);
1923+
RUN_TEST(routes_laravel_get_survives_xlang_guard_parallel);
1924+
RUN_TEST(routes_express_get_survives_xlang_guard);
1925+
RUN_TEST(routes_express_get_survives_xlang_guard_parallel);
17691926
}

0 commit comments

Comments
 (0)