@@ -944,10 +944,201 @@ TEST(cross_repo_caller_without_local_handler_keeps_cross_http_issue1459) {
944944 PASS ();
945945}
946946
947+ static bool cross_repo_seed_server_route (const cross_repo_fixture_t * fixture ,
948+ const char * target_project , const char * method ,
949+ const char * route_path , const char * handler_name ) {
950+ char target_path [512 ];
951+ if (!cross_repo_project_path (fixture , target_project , target_path , sizeof (target_path ))) {
952+ return false;
953+ }
954+ cbm_store_t * target = cbm_store_open_path (target_path );
955+ if (!target ) {
956+ return false;
957+ }
958+ bool ok = cbm_store_upsert_project (target , target_project , fixture -> cache ) == CBM_STORE_OK ;
959+ char target_route_qn [256 ];
960+ char handler_qn [256 ];
961+ char route_name [128 ];
962+ snprintf (target_route_qn , sizeof (target_route_qn ), "__route__%s__%s" , method , route_path );
963+ snprintf (handler_qn , sizeof (handler_qn ), "%s.%s" , target_project , handler_name );
964+ snprintf (route_name , sizeof (route_name ), "%s %s" , method , route_path );
965+
966+ cbm_node_t target_route = {.project = target_project ,
967+ .label = "Route" ,
968+ .name = route_name ,
969+ .qualified_name = target_route_qn ,
970+ .file_path = "server.java" };
971+ cbm_node_t handler = {.project = target_project ,
972+ .label = "Function" ,
973+ .name = handler_name ,
974+ .qualified_name = handler_qn ,
975+ .file_path = "server.java" };
976+ int64_t target_route_id = ok ? cbm_store_upsert_node (target , & target_route ) : 0 ;
977+ int64_t handler_id = ok ? cbm_store_upsert_node (target , & handler ) : 0 ;
978+ cbm_edge_t handles = {.project = target_project ,
979+ .source_id = handler_id ,
980+ .target_id = target_route_id ,
981+ .type = "HANDLES" };
982+ ok = ok && target_route_id > 0 && handler_id > 0 && cbm_store_insert_edge (target , & handles ) > 0 ;
983+ cbm_store_close (target );
984+ return ok ;
985+ }
986+
987+ static bool cross_repo_seed_client_call (const cross_repo_fixture_t * fixture ,
988+ const char * source_project , const char * caller_name ,
989+ const char * callee_name , const char * url_path ,
990+ const char * method ) {
991+ char source_path [512 ];
992+ if (!cross_repo_project_path (fixture , source_project , source_path , sizeof (source_path ))) {
993+ return false;
994+ }
995+ cbm_store_t * source = cbm_store_open_path (source_path );
996+ if (!source ) {
997+ return false;
998+ }
999+ bool ok = cbm_store_upsert_project (source , source_project , fixture -> cache ) == CBM_STORE_OK ;
1000+ char caller_qn [256 ];
1001+ char local_route_qn [256 ];
1002+ char edge_props [512 ];
1003+ snprintf (caller_qn , sizeof (caller_qn ), "%s.%s" , source_project , caller_name );
1004+ snprintf (local_route_qn , sizeof (local_route_qn ), "__route__%s__%s" , method ? method : "ANY" ,
1005+ url_path );
1006+ if (method ) {
1007+ snprintf (edge_props , sizeof (edge_props ),
1008+ "{\"callee\":\"%s\",\"url_path\":\"%s\",\"method\":\"%s\"}" , callee_name ,
1009+ url_path , method );
1010+ } else {
1011+ snprintf (edge_props , sizeof (edge_props ),
1012+ "{\"callee\":\"%s\",\"url_path\":\"%s\"}" , callee_name , url_path );
1013+ }
1014+ cbm_node_t caller = {.project = source_project ,
1015+ .label = "Function" ,
1016+ .name = caller_name ,
1017+ .qualified_name = caller_qn ,
1018+ .file_path = "item.service.ts" };
1019+ cbm_node_t local_route = {.project = source_project ,
1020+ .label = "Route" ,
1021+ .name = url_path ,
1022+ .qualified_name = local_route_qn ,
1023+ .file_path = "item.service.ts" };
1024+ int64_t caller_id = ok ? cbm_store_upsert_node (source , & caller ) : 0 ;
1025+ int64_t local_route_id = ok ? cbm_store_upsert_node (source , & local_route ) : 0 ;
1026+ cbm_edge_t http_call = {.project = source_project ,
1027+ .source_id = caller_id ,
1028+ .target_id = local_route_id ,
1029+ .type = "HTTP_CALLS" ,
1030+ .properties_json = edge_props };
1031+ ok = ok && caller_id > 0 && local_route_id > 0 && cbm_store_insert_edge (source , & http_call ) > 0 ;
1032+ cbm_store_close (source );
1033+ return ok ;
1034+ }
1035+
1036+ static int cross_repo_count_edges_like (const cross_repo_fixture_t * fixture , const char * project ,
1037+ const char * edge_type , const char * pattern ) {
1038+ char path [512 ];
1039+ if (!cross_repo_project_path (fixture , project , path , sizeof (path ))) {
1040+ return -1 ;
1041+ }
1042+ cbm_store_t * store = cbm_store_open_path_query (path );
1043+ if (!store ) {
1044+ return -1 ;
1045+ }
1046+ sqlite3_stmt * s = NULL ;
1047+ int count = -1 ;
1048+ if (sqlite3_prepare_v2 (
1049+ cbm_store_get_db (store ),
1050+ "SELECT COUNT(*) FROM edges WHERE project = ?1 AND type = ?2 AND properties LIKE ?3" ,
1051+ -1 , & s , NULL ) == SQLITE_OK ) {
1052+ sqlite3_bind_text (s , 1 , project , -1 , SQLITE_STATIC );
1053+ sqlite3_bind_text (s , 2 , edge_type , -1 , SQLITE_STATIC );
1054+ sqlite3_bind_text (s , 3 , pattern , -1 , SQLITE_STATIC );
1055+ if (sqlite3_step (s ) == SQLITE_ROW ) {
1056+ count = sqlite3_column_int (s , 0 );
1057+ }
1058+ sqlite3_finalize (s );
1059+ }
1060+ cbm_store_close (store );
1061+ return count ;
1062+ }
1063+
1064+ /* #2768: Angular HttpClient calls must match cross-repo routes with exact HTTP verbs.
1065+ * When client makes GET requests to /items/list, /items/42, and /items/job/10,
1066+ * and the server defines overlapping routes:
1067+ * DELETE /items/{id} (seeded first in DB)
1068+ * GET /items/{id} (seeded second in DB)
1069+ * POST /items/{parentId}/{id} (seeded first in DB)
1070+ * GET /items/job/{jobId} (seeded second in DB)
1071+ * the fuzzy route matcher must enforce method compatibility, linking the GET calls
1072+ * to their respective GET endpoints and never to DELETE or POST endpoints.
1073+ * getItem and getJob are seeded WITHOUT a method property (an edge written by an
1074+ * index that did not record the verb): the matcher must infer GET from the
1075+ * callee's verb suffix, or the method-less fuzzy match lands on the DELETE / POST
1076+ * route seeded first. getItems keeps its explicit "GET". */
1077+ TEST (cross_repo_angular_http_client_exact_verb_matching_issue2768 ) {
1078+ cross_repo_fixture_t fixture ;
1079+ bool setup = cross_repo_fixture_begin (& fixture ) &&
1080+ /* Target server with overlapping endpoints */
1081+ cross_repo_seed_server_route (& fixture , "api-2768" , "GET" , "/items/list" ,
1082+ "handle_list_items" ) &&
1083+ cross_repo_seed_server_route (& fixture , "api-2768" , "DELETE" , "/items/{}" ,
1084+ "handle_delete_item" ) &&
1085+ cross_repo_seed_server_route (& fixture , "api-2768" , "GET" , "/items/{}" ,
1086+ "handle_get_item" ) &&
1087+ cross_repo_seed_server_route (& fixture , "api-2768" , "POST" , "/items/{}/{}" ,
1088+ "handle_post_nested_item" ) &&
1089+ cross_repo_seed_server_route (& fixture , "api-2768" , "GET" , "/items/job/{}" ,
1090+ "handle_get_job" ) &&
1091+ /* Angular client making GET requests */
1092+ cross_repo_seed_client_call (& fixture , "angular-2768" , "getItems" ,
1093+ "this.http.get" , "/items/list" , "GET" ) &&
1094+ cross_repo_seed_client_call (& fixture , "angular-2768" , "getItem" ,
1095+ "this.http.get" , "/items/42" , NULL ) &&
1096+ cross_repo_seed_client_call (& fixture , "angular-2768" , "getJob" ,
1097+ "this.http.get" , "/items/job/10" , NULL );
1098+ if (!setup ) {
1099+ cross_repo_fixture_end (& fixture );
1100+ FAIL ("failed to seed issue 2768 fixture" );
1101+ }
1102+
1103+ const char * target = "api-2768" ;
1104+ cbm_cross_repo_result_t fwd = cbm_cross_repo_match ("angular-2768" , & target , 1 );
1105+ ASSERT_FALSE (fwd .failed );
1106+ ASSERT_EQ (fwd .http_edges , 3 );
1107+
1108+ /* Assert that client CROSS_HTTP_CALLS edges are linked to GET handlers, not DELETE or POST */
1109+ ASSERT_EQ (cross_repo_count_edges_like (& fixture , "angular-2768" , "CROSS_HTTP_CALLS" ,
1110+ "%handle_delete_item%" ),
1111+ 0 );
1112+ ASSERT_EQ (cross_repo_count_edges_like (& fixture , "angular-2768" , "CROSS_HTTP_CALLS" ,
1113+ "%handle_post_nested_item%" ),
1114+ 0 );
1115+ ASSERT_EQ (cross_repo_count_edges_like (& fixture , "angular-2768" , "CROSS_HTTP_CALLS" ,
1116+ "%handle_list_items%" ),
1117+ 1 );
1118+ ASSERT_EQ (cross_repo_count_edges_like (& fixture , "angular-2768" , "CROSS_HTTP_CALLS" ,
1119+ "%handle_get_item%" ),
1120+ 1 );
1121+ ASSERT_EQ (cross_repo_count_edges_like (& fixture , "angular-2768" , "CROSS_HTTP_CALLS" ,
1122+ "%handle_get_job%" ),
1123+ 1 );
1124+
1125+ /* Reverse pass */
1126+ const char * consumer = "angular-2768" ;
1127+ cbm_cross_repo_result_t rev = cbm_cross_repo_match ("api-2768" , & consumer , 1 );
1128+ ASSERT_FALSE (rev .failed );
1129+ ASSERT_EQ (rev .http_edges , 3 );
1130+
1131+ cross_repo_fixture_end (& fixture );
1132+ cbm_cross_repo_result_free (& fwd );
1133+ cbm_cross_repo_result_free (& rev );
1134+ PASS ();
1135+ }
1136+
9471137SUITE (cross_repo ) {
9481138 RUN_TEST (cross_repo_caller_local_handler_blocks_cross_http_issue1459 );
9491139 RUN_TEST (cross_repo_methodless_call_to_local_get_route_blocks_cross_http_issue1459 );
9501140 RUN_TEST (cross_repo_caller_without_local_handler_keeps_cross_http_issue1459 );
1141+ RUN_TEST (cross_repo_angular_http_client_exact_verb_matching_issue2768 );
9511142 RUN_TEST (cross_repo_accepts_project_with_missed_shadow_row_issue1609 );
9521143 RUN_TEST (cross_repo_null_target_fails_without_dereference );
9531144 RUN_TEST (cross_repo_wildcard_keeps_projects_containing_internal_tokens );
0 commit comments