Skip to content

Commit 2ecf202

Browse files
committed
fix(routes): keep every overload's decorator route on both resolvers (DeusData#1692)
An ASP.NET MVC GET form action and its POST submit share one method name, so both overloads collapse into one Method node whose merged properties keep only one route. The parallel resolver emitted each definition's route at node creation and kept both; the sequential one rebuilt decorator routes from the merged properties afterwards and kept only the last. On six ASP.NET corpora the sequential run lost 28 HANDLES edges this way. Both resolvers now call cbm_pipeline_emit_def_route() per definition at node creation (the parallel block moved into it unchanged), so the venues agree. The later decorator-route pass still skips handlers it already has. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 753df46 commit 2ecf202

5 files changed

Lines changed: 65 additions & 17 deletions

File tree

‎src/pipeline/pass_definitions.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ static void process_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *def, const
452452
if (props != stack) {
453453
cbm_free(CBM_MEM_CLASS_GBUF_STRING, props);
454454
}
455+
/* Per definition, like pass_parallel.c: overloads sharing this QN each keep
456+
* their own route (the merged node properties hold only one of them). */
457+
if (node_id > 0) {
458+
cbm_pipeline_emit_def_route(ctx->gbuf, node_id, def, def_rel);
459+
}
455460
/* Registry membership is defined ONCE by cbm_label_is_registry_symbol
456461
* (helpers.c): callables + type-like containers (INHERITS/IMPLEMENTS/method/
457462
* field resolution), Variable/Field (READS/WRITES resolution), and Table/View

‎src/pipeline/pass_parallel.c‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -779,23 +779,7 @@ static void insert_def_into_gbuf(extract_worker_state_t *ws, const cbm_stem_mark
779779
cbm_free(CBM_MEM_CLASS_GBUF_STRING, props);
780780
}
781781
ws->nodes_created++;
782-
if (def->route_path && def->route_path[0] != '\0') {
783-
const char *rm = def->route_method ? def->route_method : "ANY";
784-
char route_qn[CBM_ROUTE_QN_SIZE];
785-
char cpath[CBM_SZ_256];
786-
snprintf(route_qn, sizeof(route_qn), "__route__%s__%s", rm,
787-
cbm_route_canon_path(def->route_path, cpath, sizeof(cpath)));
788-
char rprops[CBM_SZ_256];
789-
snprintf(rprops, sizeof(rprops), "{\"method\":\"%s\",\"source\":\"decorator\"}", rm);
790-
int64_t route_id =
791-
cbm_gbuf_upsert_node(ws->local_gbuf, "Route", def->route_path, route_qn,
792-
def->file_path ? def->file_path : fi->rel_path, 0, 0, rprops);
793-
char hprops[CBM_SZ_512];
794-
char esc_h[CBM_SZ_512];
795-
cbm_json_escape(esc_h, sizeof(esc_h), def->qualified_name);
796-
snprintf(hprops, sizeof(hprops), "{\"handler\":\"%s\"}", esc_h);
797-
cbm_gbuf_insert_edge(ws->local_gbuf, func_id, route_id, "HANDLES", hprops);
798-
}
782+
cbm_pipeline_emit_def_route(ws->local_gbuf, func_id, def, fi->rel_path);
799783
}
800784

801785
static void log_extract_fail(int pos, uint64_t ms, const char *path) {

‎src/pipeline/pass_route_nodes.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,27 @@ static void match_infra_routes(cbm_gbuf_t *gb) {
395395
}
396396
}
397397

398+
void cbm_pipeline_emit_def_route(cbm_gbuf_t *gb, int64_t func_id, const CBMDefinition *def,
399+
const char *rel) {
400+
if (!def->route_path || def->route_path[0] == '\0') {
401+
return;
402+
}
403+
const char *rm = def->route_method ? def->route_method : "ANY";
404+
char route_qn[CBM_ROUTE_QN_SIZE];
405+
char cpath[CBM_SZ_256];
406+
snprintf(route_qn, sizeof(route_qn), "__route__%s__%s", rm,
407+
cbm_route_canon_path(def->route_path, cpath, sizeof(cpath)));
408+
char rprops[CBM_SZ_256];
409+
snprintf(rprops, sizeof(rprops), "{\"method\":\"%s\",\"source\":\"decorator\"}", rm);
410+
int64_t route_id = cbm_gbuf_upsert_node(gb, "Route", def->route_path, route_qn,
411+
def->file_path ? def->file_path : rel, 0, 0, rprops);
412+
char hprops[CBM_SZ_512];
413+
char esc_h[CBM_SZ_512];
414+
cbm_json_escape(esc_h, sizeof(esc_h), def->qualified_name);
415+
snprintf(hprops, sizeof(hprops), "{\"handler\":\"%s\"}", esc_h);
416+
cbm_gbuf_insert_edge(gb, func_id, route_id, "HANDLES", hprops);
417+
}
418+
398419
/* Phase 2a: Ensure all functions with route_path properties have Route+HANDLES edges.
399420
* During incremental indexing, only changed files get Route nodes from extraction.
400421
* This pass scans ALL Function/Method nodes and creates missing Route+HANDLES. */

‎src/pipeline/pipeline_internal.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ void cbm_pxc_test_import_probe_fail_after(int successful_allocations);
284284

285285
/* cbm_route_canon_path: cbm.h (route_path.c). */
286286

287+
/* A definition's decorator route (def->route_path, e.g. an ASP.NET [HttpGet("x")]
288+
* action): upsert its Route node and the definition -> Route HANDLES edge. Both
289+
* resolvers call it per DEFINITION at node creation (pass_parallel.c,
290+
* pass_definitions.c), so overloads sharing one QN -- a GET form action and its
291+
* POST submit -- each keep their route; the merged node properties hold only one
292+
* of them. Defined in pass_route_nodes.c. */
293+
void cbm_pipeline_emit_def_route(cbm_gbuf_t *gb, int64_t func_id, const CBMDefinition *def,
294+
const char *rel);
295+
287296
/* A file and the directory beside it share a stem (`pkg/foo.sh` beside
288297
* `pkg/foo/`): the file's Module QN equals the directory's Folder QN, and the
289298
* graph buffer keeps only the Folder. One side yields:

‎tests/test_edge_types_probe.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,34 @@ static int et_handles_exact(const EtFile *files, int nfiles, const EtHandles *wa
12081208
return et_handles_exact_routes(files, nfiles, want, parallel, NULL);
12091209
}
12101210

1211+
/* ASP.NET Core MVC (#1692): a GET form action and its POST submit share one
1212+
* method name, so both overloads collapse into one Method node whose merged
1213+
* properties keep only one route. The parallel resolver emitted each
1214+
* definition's route at node creation and kept both; the sequential one rebuilt
1215+
* routes from the merged properties afterwards and kept only the last (28
1216+
* HANDLES on 6 ASP.NET corpora, 2026-10-18). Both venues keep both. */
1217+
TEST(handles_aspnet_overload_verbs_both_venues_issue1692) {
1218+
static const EtHandles want[] = {{"AccountController.Login", "/Account/login"},
1219+
{"AccountController.Login", "/Account/login"},
1220+
{NULL, NULL}};
1221+
static const char *const route_qns[] = {"__route__GET__/Account/login",
1222+
"__route__POST__/Account/login", NULL};
1223+
static const EtFile f[] = {
1224+
{"Controllers/AccountController.cs",
1225+
"using Microsoft.AspNetCore.Mvc;\n\n"
1226+
"namespace Shop.Web.Controllers\n{\n"
1227+
" [Route(\"[controller]\")]\n"
1228+
" public class AccountController : Controller\n {\n"
1229+
" [HttpGet(\"login\")]\n"
1230+
" public IActionResult Login() { return View(); }\n\n"
1231+
" [HttpPost(\"login\")]\n"
1232+
" public IActionResult Login(LoginModel model) { return Redirect(\"/\"); }\n"
1233+
" }\n}\n"}};
1234+
ASSERT_TRUE(et_handles_exact_routes(f, 1, want, 0, route_qns));
1235+
ASSERT_TRUE(et_handles_exact_routes(f, 1, want, 1, route_qns));
1236+
PASS();
1237+
}
1238+
12111239
/* #1146: Laravel's two class-based handler forms —
12121240
* Route::get('/x', [UserController::class, 'show']) (controller method)
12131241
* Route::get('/x', GetCurrentUserController::class) (invokable: __invoke)
@@ -2721,6 +2749,7 @@ SUITE(edge_types_probe) {
27212749
RUN_TEST(handles_aspnet_route_tokens_issue1692);
27222750
RUN_TEST(handles_aspnet_override_constraints_issue1692);
27232751
RUN_TEST(handles_aspnet_non_controller_control_issue1692);
2752+
RUN_TEST(handles_aspnet_overload_verbs_both_venues_issue1692);
27242753
RUN_TEST(handles_laravel_php);
27252754
RUN_TEST(handles_laravel_facade_routes_issue952);
27262755
RUN_TEST(handles_laravel_facade_no_junk_routes_issue952);

0 commit comments

Comments
 (0)