@@ -1592,6 +1592,35 @@ static int named_edge_count(cbm_store_t *s, const char *project, const char *edg
15921592 return matches;
15931593}
15941594
1595+ /* HTTP_CALLS edges out of the function `source_name` whose Route target's
1596+ * qualified name contains `route_qn_part` (e.g. "__route__GET__"). */
1597+ static int http_calls_to_route(cbm_store_t *s, const char *project, const char *source_name,
1598+ const char *route_qn_part) {
1599+ cbm_edge_t *edges = NULL;
1600+ int edge_count = 0;
1601+ if (cbm_store_find_edges_by_type(s, project, "HTTP_CALLS", &edges, &edge_count) !=
1602+ CBM_STORE_OK) {
1603+ return -1;
1604+ }
1605+ int matches = 0;
1606+ for (int i = 0; i < edge_count; i++) {
1607+ cbm_node_t source = {0};
1608+ cbm_node_t target = {0};
1609+ int source_ok = cbm_store_find_node_by_id(s, edges[i].source_id, &source) == CBM_STORE_OK;
1610+ int target_ok = cbm_store_find_node_by_id(s, edges[i].target_id, &target) == CBM_STORE_OK;
1611+ if (source_ok && target_ok && source.name && target.qualified_name &&
1612+ strcmp(source.name, source_name) == 0 && strstr(target.qualified_name, route_qn_part)) {
1613+ matches++;
1614+ }
1615+ cbm_node_free_fields(&source);
1616+ cbm_node_free_fields(&target);
1617+ }
1618+ if (edges) {
1619+ cbm_store_free_edges(edges, edge_count);
1620+ }
1621+ return matches;
1622+ }
1623+
15951624/* Like named_edge_count, but distinguish same-named targets by their source
15961625 * file. Semantic-control fixtures intentionally keep the exported short name
15971626 * identical in two modules so a project-wide unique-name fallback cannot make
@@ -6945,16 +6974,19 @@ TEST(pipeline_tsjs_receiver_parallel_keeps_service_edges) {
69456974 cbm_store_t *s = cbm_store_open_path(db_path);
69466975 ASSERT_NOT_NULL(s);
69476976
6948- /* (1) Genuine HTTP_CALLS survive under the guard (>= 3) :
6949- * - axios.get('/api/orders') -> 2 edges (recognized lib #523 callee bypass
6950- * + detect_url_in_args ), and
6977+ /* (1) Genuine HTTP_CALLS survive under the guard:
6978+ * - axios.get('/api/orders') -> 1 edge, typed GET (recognized lib #523
6979+ * callee bypass; no method-less arg-URL twin ), and
69516980 * - dev.load('/api/data') -> 1 edge via detect_url_in_args, which runs
6952- * unconditionally after emit_service_edge's branch even when the plain
6953- * fall-through is suppressed.
6981+ * after emit_service_edge's branch even when the plain fall-through is
6982+ * suppressed.
69546983 * dev.load is the class the predicate-duplicating guard lost: `.load` is not
69556984 * a route suffix and `dev` is not an HTTP lib, so it was dropped before
6956- * emit_service_edge ran (RED on that guard: only axios's 2). */
6957- ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 3);
6985+ * emit_service_edge ran (RED on that guard: only axios's edge). */
6986+ ASSERT_EQ(http_calls_to_route(s, project, "callApi", "__route__GET__"), 1);
6987+ ASSERT_EQ(http_calls_to_route(s, project, "callApi", "__route__"), 1);
6988+ ASSERT_EQ(http_calls_to_route(s, project, "callLoad", "__route__ANY__"), 1);
6989+ ASSERT_EQ(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 2);
69586990 /* (2) The verb-suffix + route-path member calls keep their route
69596991 * registrations (edge type CALLS -> a Route node named by the path). These
69606992 * classify as route_registration on main, NOT HTTP_CALLS — Option A preserves
@@ -7761,6 +7793,103 @@ TEST(pipeline_local_fetch_shadow_not_classified_as_http) {
77617793 PASS();
77627794}
77637795
7796+ /* A call the HTTP service patterns classify (axios, an axios.create instance)
7797+ * gets exactly ONE HTTP_CALLS edge, typed with the verb its callee names. The
7798+ * arg-URL heuristic (detect_url_in_args, via=arg_url) exists for calls the
7799+ * patterns do not know -- a local fetch wrapper such as callApi('/api/orders')
7800+ * -- and must not add a second, method-less __route__ANY__ edge for the same
7801+ * call site. On microsoft/healthcare-ai-model-evaluator 59 of 129 HTTP_CALLS
7802+ * were such twins, and the cross-repo matcher bound them to server handlers of
7803+ * any method. `fillers` > 0 forces the parallel resolver (the RED case); 0
7804+ * keeps the sequential one, which must agree. */
7805+ static int typed_http_no_url_twin_case(int fillers) {
7806+ char tmp[256];
7807+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_http_twin_XXXXXX");
7808+ if (!cbm_mkdtemp(tmp)) {
7809+ FAIL("tmpdir");
7810+ }
7811+
7812+ write_temp_file(tmp, "src/api.ts",
7813+ "import axios from 'axios';\n"
7814+ "const axiosInstance = axios.create({ baseURL: 'http://localhost:5000' });\n"
7815+ "export function getModel(id: string) {\n"
7816+ " return axiosInstance.get(`/api/models/${id}`);\n"
7817+ "}\n"
7818+ "export function addModel(body: unknown) {\n"
7819+ " return axiosInstance.post('/api/models', body);\n"
7820+ "}\n"
7821+ "export function removeModel(id: string) {\n"
7822+ " return axios.delete(`/api/models/${id}`);\n"
7823+ "}\n");
7824+ write_temp_file(tmp, "src/wrapper.ts",
7825+ "function callApi(path: string): Promise<Response> {\n"
7826+ " return fetch(path);\n"
7827+ "}\n"
7828+ "export function listOrders() {\n"
7829+ " return callApi('/api/orders');\n"
7830+ "}\n");
7831+ for (int i = 0; i < fillers; i++) {
7832+ char name[64];
7833+ char body[128];
7834+ snprintf(name, sizeof(name), "src/filler%d.ts", i);
7835+ snprintf(body, sizeof(body), "export function filler%d(): number {\n return %d;\n}\n", i,
7836+ i);
7837+ write_temp_file(tmp, name, body);
7838+ }
7839+
7840+ char *old_workers = getenv("CBM_WORKERS");
7841+ char *saved = old_workers ? strdup(old_workers) : NULL;
7842+ cbm_setenv("CBM_WORKERS", "4", 1);
7843+
7844+ char db_path[512];
7845+ snprintf(db_path, sizeof(db_path), "%s/http_twin.db", tmp);
7846+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
7847+ ASSERT_NOT_NULL(p);
7848+ ASSERT_EQ(cbm_pipeline_run(p), 0);
7849+ const char *project = cbm_pipeline_project_name(p);
7850+
7851+ cbm_store_t *s = cbm_store_open_path(db_path);
7852+ ASSERT_NOT_NULL(s);
7853+
7854+ static const struct {
7855+ const char *caller;
7856+ const char *typed_route;
7857+ } typed[] = {{"getModel", "__route__GET__"},
7858+ {"addModel", "__route__POST__"},
7859+ {"removeModel", "__route__DELETE__"}};
7860+ for (size_t i = 0; i < sizeof(typed) / sizeof(typed[0]); i++) {
7861+ /* The typed edge stays ... */
7862+ ASSERT_EQ(http_calls_to_route(s, project, typed[i].caller, typed[i].typed_route), 1);
7863+ /* ... and it is the only HTTP_CALLS edge of that call site. */
7864+ ASSERT_EQ(http_calls_to_route(s, project, typed[i].caller, "__route__ANY__"), 0);
7865+ ASSERT_EQ(http_calls_to_route(s, project, typed[i].caller, "__route__"), 1);
7866+ }
7867+ if (fillers > 0) {
7868+ /* Control: the heuristic still covers the call no pattern knows. The
7869+ * sequential resolver has no arg-URL heuristic yet (#2235). */
7870+ ASSERT_EQ(http_calls_to_route(s, project, "listOrders", "__route__ANY__"), 1);
7871+ }
7872+
7873+ cbm_store_close(s);
7874+ cbm_pipeline_free(p);
7875+ if (saved) {
7876+ cbm_setenv("CBM_WORKERS", saved, 1);
7877+ free(saved);
7878+ } else {
7879+ cbm_unsetenv("CBM_WORKERS");
7880+ }
7881+ th_rmtree(tmp);
7882+ PASS();
7883+ }
7884+
7885+ TEST(pipeline_typed_http_call_has_no_arg_url_twin) {
7886+ return typed_http_no_url_twin_case(52);
7887+ }
7888+
7889+ TEST(pipeline_typed_http_call_has_no_arg_url_twin_sequential) {
7890+ return typed_http_no_url_twin_case(0);
7891+ }
7892+
77647893/* ── Git history pass tests ─────────────────────────────────────── */
77657894
77667895TEST(githistory_is_trackable) {
@@ -16365,6 +16494,8 @@ SUITE(pipeline) {
1636516494 RUN_TEST(pipeline_swift_http_call_makes_route_issue1892);
1636616495 RUN_TEST(pipeline_native_fetch_parallel_classified_as_http_calls);
1636716496 RUN_TEST(pipeline_local_fetch_shadow_not_classified_as_http);
16497+ RUN_TEST(pipeline_typed_http_call_has_no_arg_url_twin);
16498+ RUN_TEST(pipeline_typed_http_call_has_no_arg_url_twin_sequential);
1636816499 /* Git history pass */
1636916500 RUN_TEST(githistory_is_trackable);
1637016501 RUN_TEST(githistory_compute_coupling);
0 commit comments