Skip to content

Commit d3059ef

Browse files
committed
fix(pipeline): classify capitalized Axios calls as HTTP clients
With `import Axios from "axios"`, a common convention in TypeScript projects, every `Axios.get/post/put/delete(url)` client call was indexed as a route registration. The result was a `CALLS {via: route_registration}` edge to a Route node instead of an HTTP_CALLS edge. The client's request paths therefore posed as server routes, and no HTTP call site existed to match a handler. microsoft/Game-Control-Puzzle-Event-Administration-Tools has all 69 of its client calls in this shape. Root cause: service-pattern matching is case-sensitive by design, so that "requests" cannot match "Requests" or "myrequests". The HTTP library table knew only the lowercase id `axios`. `Axios.get` therefore matched no library, on either resolver. Resolution came back empty, because an external package is never indexed. The call then fell through to the callee-suffix fallback, which treats any `<x>.get/post/...(path)` as a route registration. Fix: add `Axios` next to `axios` in the HTTP library table. The table already pairs case variants of one library (`Dio`/`dio`, `Guzzle`/`guzzle`, `OkHttp`/`okhttp3`). The existing identifier-boundary rule applies unchanged: - `Axios.get` and `AxiosInstance.get` (axios's own instance type) match; - a lowercase continuation such as `Axiosphere` does not. Express/Koa/Fastify registrations such as `router.get(path, handler)` are untouched. Proof (release binary, macOS arm64, microsoft/Game-Control-Puzzle-Event-Administration-Tools @4fe23196, before -> after): - route_registration CALLS 69 -> 0; all 69 were `Axios.*` calls in client/. - All 69 reappear as typed HTTP_CALLS from the same caller to the same Route QN (`__route__PUT__/api/admin/users/{}`), and no typed HTTP_CALLS edge is lost. - HTTP_CALLS 4 -> 142. Besides the 69 typed calls, 69 are the method-less arg_url twins that fix/http-typed-call-no-url-twin removes, and 4 are the existing `isOnPage` arg_url edges. - CALLS 868 -> 799. - SEMANTICALLY_RELATED 83 -> 174, deterministic across two runs of each binary. The semantic pass tokenizes CALLS-neighbour names, and the fake registration edges had fed each service function's URL path into its vector. Without them, the 69 `Axios` wrapper functions read as related. Five sampled calls were checked against the client source, including admin/users/service.ts:44 `Axios.put(`/api/admin/users/${participantId}/ ${eventInstanceId}`)` -> `__route__PUT__/api/admin/users/{}/{}`. On the pending ASP.NET route stack (fix/aspnet-route-case-inrepo, 8e734ee5), together with the arg_url twin fix, the reclassified calls reach their C# handlers: - typed HTTP_CALLS 0 -> 69; - DATA_FLOWS 0 -> 66, and HANDLES 94 -> 106 (+12 case_fold); - sampled links match their controller source, for example `Axios.put(`/api/admin/users/${participantId}`)` -> `[Route("api/admin/users")] [HttpPut("{participantId}")] UpdateUserInfo`; - the 3 calls left unlinked carry a query string in the URL literal. Tests: RED 3/3 before the fix, green after, RED again on revert. - pipeline_capitalized_axios_import_is_http_client (parallel resolver) and its _sequential twin: `import Axios from "axios"` with Axios.get, .post and .delete gives 0 route registrations and exactly one typed HTTP_CALLS per call, while an Express `router.get` registration in the same project stays a registration. - infrascan service-pattern tables: `Axios.get`, `Axios.post` and `AxiosInstance.get` classify as HTTP, and `geo.Axiosphere.map` stays NONE. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 1f9b4db commit d3059ef

3 files changed

Lines changed: 157 additions & 0 deletions

File tree

‎internal/cbm/service_patterns.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ static const lib_pattern_t http_libraries[] = {
4141

4242
/* JavaScript / TypeScript */
4343
{"axios", CBM_SVC_HTTP, NULL},
44+
/* `import Axios from "axios"`: the capitalized default-import binding
45+
* (also axios's own Axios / AxiosInstance types). Matching is
46+
* case-sensitive, so without this entry `Axios.get(url)` fell through to
47+
* the `.get` route-suffix fallback and became a route registration. */
48+
{"Axios", CBM_SVC_HTTP, NULL},
4449
{"superagent", CBM_SVC_HTTP, NULL},
4550
{"needle", CBM_SVC_HTTP, NULL},
4651
{"node-fetch", CBM_SVC_HTTP, NULL},

‎tests/test_infrascan.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ TEST(infrascan_service_pattern_match_rejects_ids_inside_words) {
113113
{"gqlalchemy.Memgraph.execute", CBM_SVC_NONE},
114114
{"celeryconfig.broker_url", CBM_SVC_NONE},
115115
{"kafkaesque.story.tell", CBM_SVC_NONE},
116+
/* "Axios" glued to a lowercase continuation */
117+
{"geo.Axiosphere.map", CBM_SVC_NONE},
116118
{NULL, CBM_SVC_NONE},
117119
};
118120
ASSERT_EQ(svc_case_mismatches(cases), 0);
@@ -136,6 +138,11 @@ TEST(infrascan_service_pattern_match_keeps_real_library_qns) {
136138
{"package:dio/dio.dart", CBM_SVC_HTTP},
137139
{"dio.Dio.get", CBM_SVC_HTTP},
138140
{"pkg.net.curl.get", CBM_SVC_HTTP},
141+
/* axios under a capitalized default-import binding
142+
* (`import Axios from "axios"`) and axios's own instance type */
143+
{"Axios.get", CBM_SVC_HTTP},
144+
{"Axios.post", CBM_SVC_HTTP},
145+
{"AxiosInstance.get", CBM_SVC_HTTP},
139146
{"curl_exec", CBM_SVC_HTTP},
140147
{"surf.get", CBM_SVC_HTTP},
141148
{"hyper.Client.request", CBM_SVC_HTTP},

‎tests/test_pipeline.c‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,35 @@ static int named_edge_count(cbm_store_t *s, const char *project, const char *edg
13141314
return matches;
13151315
}
13161316

1317+
/* HTTP_CALLS edges out of the function `source_name` whose Route target's
1318+
* qualified name contains `route_qn_part` (e.g. "__route__GET__"). */
1319+
static int http_calls_to_route(cbm_store_t *s, const char *project, const char *source_name,
1320+
const char *route_qn_part) {
1321+
cbm_edge_t *edges = NULL;
1322+
int edge_count = 0;
1323+
if (cbm_store_find_edges_by_type(s, project, "HTTP_CALLS", &edges, &edge_count) !=
1324+
CBM_STORE_OK) {
1325+
return -1;
1326+
}
1327+
int matches = 0;
1328+
for (int i = 0; i < edge_count; i++) {
1329+
cbm_node_t source = {0};
1330+
cbm_node_t target = {0};
1331+
int source_ok = cbm_store_find_node_by_id(s, edges[i].source_id, &source) == CBM_STORE_OK;
1332+
int target_ok = cbm_store_find_node_by_id(s, edges[i].target_id, &target) == CBM_STORE_OK;
1333+
if (source_ok && target_ok && source.name && target.qualified_name &&
1334+
strcmp(source.name, source_name) == 0 && strstr(target.qualified_name, route_qn_part)) {
1335+
matches++;
1336+
}
1337+
cbm_node_free_fields(&source);
1338+
cbm_node_free_fields(&target);
1339+
}
1340+
if (edges) {
1341+
cbm_store_free_edges(edges, edge_count);
1342+
}
1343+
return matches;
1344+
}
1345+
13171346
/* Like named_edge_count, but distinguish same-named targets by their source
13181347
* file. Semantic-control fixtures intentionally keep the exported short name
13191348
* identical in two modules so a project-wide unique-name fallback cannot make
@@ -6267,6 +6296,120 @@ TEST(pipeline_tsjs_receiver_parallel_keeps_service_edges) {
62676296
PASS();
62686297
}
62696298

6299+
/* Route-registration CALLS edges (via=route_registration) out of the function
6300+
* `source_name`. */
6301+
static int route_registrations_from(cbm_store_t *s, const char *project, const char *source_name) {
6302+
cbm_edge_t *edges = NULL;
6303+
int edge_count = 0;
6304+
if (cbm_store_find_edges_by_type(s, project, "CALLS", &edges, &edge_count) != CBM_STORE_OK) {
6305+
return -1;
6306+
}
6307+
int matches = 0;
6308+
for (int i = 0; i < edge_count; i++) {
6309+
cbm_node_t source = {0};
6310+
int source_ok = cbm_store_find_node_by_id(s, edges[i].source_id, &source) == CBM_STORE_OK;
6311+
if (source_ok && source.name && strcmp(source.name, source_name) == 0 &&
6312+
edges[i].properties_json &&
6313+
strstr(edges[i].properties_json, "\"via\":\"route_registration\"")) {
6314+
matches++;
6315+
}
6316+
cbm_node_free_fields(&source);
6317+
}
6318+
if (edges) {
6319+
cbm_store_free_edges(edges, edge_count);
6320+
}
6321+
return matches;
6322+
}
6323+
6324+
/* `import Axios from "axios"` -- the default-import binding capitalized, a
6325+
* common convention -- must classify `Axios.get/post/delete(url)` as HTTP
6326+
* client calls exactly like `axios.*`. The library table matched only the
6327+
* lowercase id, so the calls fell through to the `.get`/`.post` route-suffix
6328+
* fallback and became route REGISTRATIONS: on
6329+
* microsoft/Game-Control-Puzzle-Event-Administration-Tools all 69 client
6330+
* calls masqueraded as server Routes. A real Express registration in the same
6331+
* project stays a registration. `fillers` > 0 forces the parallel resolver,
6332+
* 0 keeps the sequential one; both classify through the same table. */
6333+
static int capitalized_axios_case(int fillers) {
6334+
char tmp[256];
6335+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_axios_cap_XXXXXX");
6336+
if (!cbm_mkdtemp(tmp)) {
6337+
FAIL("tmpdir");
6338+
}
6339+
6340+
write_temp_file(tmp, "src/service.ts",
6341+
"import Axios from \"axios\";\n"
6342+
"export function getSettings(eventId: string) {\n"
6343+
" return Axios.get(`/api/admin/events/${eventId}/settings`);\n"
6344+
"}\n"
6345+
"export function addUser(eventId: string, participant: unknown) {\n"
6346+
" return Axios.post(`/api/admin/users/${eventId}`, participant);\n"
6347+
"}\n"
6348+
"export function removeUser(id: string) {\n"
6349+
" return Axios.delete(`/api/admin/users/${id}`);\n"
6350+
"}\n");
6351+
write_temp_file(tmp, "src/server.ts",
6352+
"function listUsers(req: unknown, res: unknown) {}\n"
6353+
"export function mount(router: any) {\n"
6354+
" router.get('/api/admin/users', listUsers);\n"
6355+
"}\n");
6356+
for (int i = 0; i < fillers; i++) {
6357+
char name[64];
6358+
char body[128];
6359+
snprintf(name, sizeof(name), "src/filler%d.ts", i);
6360+
snprintf(body, sizeof(body), "export function filler%d(): number {\n return %d;\n}\n", i,
6361+
i);
6362+
write_temp_file(tmp, name, body);
6363+
}
6364+
6365+
char *old_workers = getenv("CBM_WORKERS");
6366+
char *saved = old_workers ? strdup(old_workers) : NULL;
6367+
cbm_setenv("CBM_WORKERS", "4", 1);
6368+
6369+
char db_path[512];
6370+
snprintf(db_path, sizeof(db_path), "%s/axios_cap.db", tmp);
6371+
cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
6372+
ASSERT_NOT_NULL(p);
6373+
ASSERT_EQ(cbm_pipeline_run(p), 0);
6374+
const char *project = cbm_pipeline_project_name(p);
6375+
6376+
cbm_store_t *s = cbm_store_open_path(db_path);
6377+
ASSERT_NOT_NULL(s);
6378+
6379+
static const struct {
6380+
const char *caller;
6381+
const char *typed_route;
6382+
} client[] = {{"getSettings", "__route__GET__"},
6383+
{"addUser", "__route__POST__"},
6384+
{"removeUser", "__route__DELETE__"}};
6385+
for (size_t i = 0; i < sizeof(client) / sizeof(client[0]); i++) {
6386+
ASSERT_EQ(route_registrations_from(s, project, client[i].caller), 0);
6387+
ASSERT_EQ(http_calls_to_route(s, project, client[i].caller, client[i].typed_route), 1);
6388+
}
6389+
/* Control: the server-side registration is untouched. */
6390+
ASSERT_EQ(route_registrations_from(s, project, "mount"), 1);
6391+
ASSERT_EQ(http_calls_to_route(s, project, "mount", "__route__"), 0);
6392+
6393+
cbm_store_close(s);
6394+
cbm_pipeline_free(p);
6395+
if (saved) {
6396+
cbm_setenv("CBM_WORKERS", saved, 1);
6397+
free(saved);
6398+
} else {
6399+
cbm_unsetenv("CBM_WORKERS");
6400+
}
6401+
th_rmtree(tmp);
6402+
PASS();
6403+
}
6404+
6405+
TEST(pipeline_capitalized_axios_import_is_http_client) {
6406+
return capitalized_axios_case(52);
6407+
}
6408+
6409+
TEST(pipeline_capitalized_axios_import_is_http_client_sequential) {
6410+
return capitalized_axios_case(0);
6411+
}
6412+
62706413
/* Python bare-call local-binding suppression, sequential path. The bare-call
62716414
* counterpart of the receiver guard above: `run` is a PARAMETER, so `run()`
62726415
* cannot be the module-level `run` and must not bind SatoriLive.run.
@@ -15348,6 +15491,8 @@ SUITE(pipeline) {
1534815491
RUN_TEST(pipeline_go_bare_ref_never_binds_field);
1534915492
RUN_TEST(pipeline_go_bare_ref_never_binds_field_parallel);
1535015493
RUN_TEST(pipeline_tsjs_receiver_parallel_keeps_service_edges);
15494+
RUN_TEST(pipeline_capitalized_axios_import_is_http_client);
15495+
RUN_TEST(pipeline_capitalized_axios_import_is_http_client_sequential);
1535115496
RUN_TEST(pipeline_python_receiver_parallel_suppresses_weak_method_edges);
1535215497
RUN_TEST(pipeline_python_bare_local_binding_suppresses_weak_edge);
1535315498
RUN_TEST(pipeline_python_bare_local_binding_parallel_suppresses_weak_edge);

0 commit comments

Comments
 (0)