Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix: exclude client navigation from inferred HTTP calls
Martin Vogeld97c0ce55bdc
diff --git a/internal/cbm/service_patterns.c b/internal/cbm/service_patterns.cindex 426bdafc0..7d428b8e3 100644--- a/internal/cbm/service_patterns.c+++ b/internal/cbm/service_patterns.c@@ -802,6 +802,62 @@ static bool callee_is_delimiter_or_filesystem_builder(const char *callee_name) {return strstr(callee_name, "os.path.join") != NULL || strstr(callee_name, "path.join") != NULL;}+/* Case-insensitive "text ends with suffix" over [text, text + len). */+static bool span_ends_with_ci(const char *text, size_t len, const char *suffix) {+ size_t sl = strlen(suffix);+ if (len < sl) {+ return false;+ }+ const char *tail = text + (len - sl);+ for (size_t i = 0; i < sl; i++) {+ char a = tail[i];+ if (a >= 'A' && a <= 'Z') {+ a = (char)(a - 'A' + 'a');+ }+ if (a != suffix[i]) {+ return false;+ }+ }+ return true;+}++bool cbm_service_pattern_is_client_navigation(bool js_family, const char *callee_name) {+ if (!js_family || !callee_name || !callee_name[0]) {+ return false;+ }+ const char *last_dot = strrchr(callee_name, '.');+ const char *method = last_dot ? last_dot + 1 : callee_name;+ size_t recv_len = last_dot ? (size_t)(last_dot - callee_name) : 0;+ /* Angular Router.navigate/navigateByUrl, Ionic NavController.navigateForward/+ * Back/Root, Nuxt navigateTo, react-router/Gatsby navigate — any receiver. */+ if (strcmp(method, "navigate") == 0 || strcmp(method, "navigateByUrl") == 0 ||+ strcmp(method, "navigateTo") == 0 || strcmp(method, "navigateForward") == 0 ||+ strcmp(method, "navigateBack") == 0 || strcmp(method, "navigateRoot") == 0) {+ return true;+ }+ /* History API: the URL is the third argument of pushState/replaceState. */+ if (strcmp(method, "pushState") == 0 || strcmp(method, "replaceState") == 0) {+ return true;+ }+ /* Bare SvelteKit goto, Next.js/Remix redirect helpers. */+ if (!last_dot && (strcmp(method, "goto") == 0 || strcmp(method, "redirect") == 0 ||+ strcmp(method, "permanentRedirect") == 0)) {+ return true;+ }+ /* Next.js / Vue router and react-router history objects: router.push,+ * this.$router.push, props.history.push, Router.prefetch. */+ if ((strcmp(method, "push") == 0 || strcmp(method, "replace") == 0 ||+ strcmp(method, "prefetch") == 0) &&+ (span_ends_with_ci(callee_name, recv_len, "router") ||+ span_ends_with_ci(callee_name, recv_len, "history"))) {+ return true;+ }+ /* Angular Location.go, window.location.assign / replace. */+ return (strcmp(method, "go") == 0 || strcmp(method, "assign") == 0 ||+ strcmp(method, "replace") == 0) &&+ span_ends_with_ci(callee_name, recv_len, "location");+}+static const char *strip_string_delimiters(const char *literal, char *buf, size_t buf_sz) {if (!literal || !literal[0]) {return NULL;diff --git a/internal/cbm/service_patterns.h b/internal/cbm/service_patterns.hindex 020ab429d..f06c85571 100644--- a/internal/cbm/service_patterns.h+++ b/internal/cbm/service_patterns.h@@ -49,6 +49,16 @@ bool cbm_service_pattern_is_global_fetch(const char *callee_name);* Rejects filesystem paths and non-HTTP string consumers. */bool cbm_service_pattern_is_http_route_literal(const char *literal, const char *callee_name);+/* True when a JS/TS-family call is client-side navigation rather than a+ * network request (#1250): Angular Router.navigate/navigateByUrl, Ionic navigation, Nuxt+ * navigateTo, react-router navigate, router/history push|replace|prefetch,+ * History pushState/replaceState, Location go|assign|replace, bare goto /+ * redirect / permanentRedirect. Its slash-prefixed argument is a client route,+ * so it must not mint an arg_url HTTP_CALLS edge. js_family is the caller's+ * FILE-language gate: false always returns false, so no other language's+ * recall is traded (suppressors stay per-language). */+bool cbm_service_pattern_is_client_navigation(bool js_family, const char *callee_name);+/* True when text that reached a path slot is a source comment rather than a* path: a block comment (slash-star … star-slash), a line comment (slash-slash* followed by a space), or any text with a line break. The wildcard routediff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.cindex 19393ac48..efc407934 100644--- a/src/pipeline/pass_parallel.c+++ b/src/pipeline/pass_parallel.c@@ -2472,9 +2472,23 @@ static bool arg_is_topic(const CBMCallArg *arg) {return false;}+/* File-language scope of the client-navigation heuristic (#1250): the JS/TS+ * family and the hosts that embed it. Kept explicit so changes to the+ * weak-member guard cannot broaden it. */+static bool pp_client_navigation_lang(CBMLanguage lang) {+ return lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX ||+ lang == CBM_LANG_ARKTS || lang == CBM_LANG_HTML || lang == CBM_LANG_VUE ||+ lang == CBM_LANG_SVELTE || lang == CBM_LANG_ASTRO;+}+/* Detect API paths in call arguments and create HTTP_CALLS edges. */static void detect_url_in_args(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call,- cbm_svc_kind_t svc) {+ cbm_svc_kind_t svc, bool js_family) {+ /* Only the generic argument heuristic is suppressed: explicit HTTP service+ * classification above this call still emits its edge. */+ if (cbm_service_pattern_is_client_navigation(js_family, call->callee_name)) {+ return;+ }/* A resolved alias may be ASYNC even when its source spelling is unknown.* Neither raw slash topics nor URL projections are HTTP evidence there. */if (svc == CBM_SVC_ASYNC || cbm_service_pattern_match(call->callee_name) == CBM_SVC_ASYNC) {@@ -2772,7 +2786,7 @@ static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,* __route__ANY__ twin of the typed edge, which cross-repo matching then* bound to server handlers of any method. */if (!http_edge_emitted) {- detect_url_in_args(gbuf, source, call, svc);+ detect_url_in_args(gbuf, source, call, svc, pp_client_navigation_lang(lang));}}diff --git a/tests/test_infrascan.c b/tests/test_infrascan.cindex 449998f02..e744d621e 100644--- a/tests/test_infrascan.c+++ b/tests/test_infrascan.c@@ -48,6 +48,62 @@ TEST(infrascan_http_route_literal_guard_rejects_filesystem_paths) {PASS();}+/* #1250: client-side navigation is recognised only in the JS/TS family; genuine+ * HTTP clients and route registrations are never mistaken for it, and with the+ * file-language gate off nothing is suppressed (no other language's recall). */+TEST(infrascan_client_navigation_is_js_family_only) {+ const char *nav[] = {"this.router.navigateByUrl",+ "this.router.navigate",+ "navigateTo",+ "navigate",+ "this.navCtrl.navigateForward",+ "this.navCtrl.navigateRoot",+ "this.navCtrl.navigateBack",+ "router.push",+ "this.$router.push",+ "Router.replace",+ "props.history.push",+ "browserHistory.replace",+ "router.prefetch",+ "history.pushState",+ "window.history.replaceState",+ "this.location.go",+ "window.location.assign",+ "location.replace",+ "goto",+ "redirect",+ "permanentRedirect"};+ for (size_t i = 0; i < sizeof(nav) / sizeof(nav[0]); i++) {+ ASSERT_TRUE(cbm_service_pattern_is_client_navigation(true, nav[i]));+ ASSERT_FALSE(cbm_service_pattern_is_client_navigation(false, nav[i]));+ }+ const char *http[] = {"fetch",+ "axios.get",+ "axios.post",+ "this.http.get",+ "this.http.post",+ "httpClient.put",+ "http",+ "api.patch",+ "router.get",+ "app.post",+ "items.push",+ "ky.get",+ "res.redirect",+ "client.go",+ "this.gotoApi",+ "$http.get",+ "navigateApi",+ "client.navigateRequest",+ "navigateToEndpoint"};+ for (size_t i = 0; i < sizeof(http) / sizeof(http[0]); i++) {+ ASSERT_FALSE(cbm_service_pattern_is_client_navigation(true, http[i]));+ }+ ASSERT_FALSE(cbm_service_pattern_is_client_navigation(true, NULL));+ ASSERT_FALSE(cbm_service_pattern_is_client_navigation(true, ""));+ PASS();+}+/* ── Service-pattern QN boundaries (distilled from PR #1245) ─────────* A library id must sit on an identifier boundary inside the QN. A raw* substring match classified "proj.plugin.loader" as gin ("gin.") and@@ -332,6 +388,7 @@ TEST(infrascan_http_calls_join_matching_handler_route) {SUITE(infrascan) {RUN_TEST(infrascan_http_route_literal_guard_rejects_filesystem_paths);RUN_TEST(infrascan_http_route_literal_guard_rejects_document_extensions);+ RUN_TEST(infrascan_client_navigation_is_js_family_only);RUN_TEST(infrascan_service_pattern_match_rejects_ids_inside_words);RUN_TEST(infrascan_service_pattern_match_keeps_real_library_qns);RUN_TEST(infrascan_route_nodes_skip_bad_http_url_paths);diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex 959c48bd3..ca4f35c03 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -9643,6 +9643,232 @@ TEST(pipeline_arg_url_rejects_document_file_paths) {PASS();}+/* A failed SQL query must never look like an absent false edge. */+static int navigation_probe_count(cbm_store_t *store, const char *sql, const char *project,+ const char *value, const char *source_name) {+ sqlite3_stmt *st = NULL;+ sqlite3 *db = cbm_store_get_db(store);+ if (!db || sqlite3_prepare_v2(db, sql, -1, &st, NULL) != SQLITE_OK) {+ sqlite3_finalize(st);+ return -1;+ }+ int count = -1;+ bool bound = sqlite3_bind_text(st, 1, project, -1, SQLITE_TRANSIENT) == SQLITE_OK &&+ sqlite3_bind_text(st, 2, value, -1, SQLITE_TRANSIENT) == SQLITE_OK;+ if (bound && source_name) {+ bound = sqlite3_bind_text(st, 3, source_name, -1, SQLITE_TRANSIENT) == SQLITE_OK;+ }+ if (bound && sqlite3_step(st) == SQLITE_ROW) {+ count = sqlite3_column_int(st, 0);+ if (sqlite3_step(st) != SQLITE_DONE) {+ count = -1;+ }+ }+ if (sqlite3_finalize(st) != SQLITE_OK) {+ count = -1;+ }+ return count;+}++/* #1250: exercise the generic URL heuristic with real extracted occurrences+ * and real source nodes. More than 50 files selects the parallel resolver.+ * HTTP clients, custom navigateApi wrappers, Python and ASYNC keep their edges. */+TEST(pipeline_arg_url_skips_client_navigation) {+ static const char page[] =+ "import axios from 'axios';\n"+ "import { get as navigate } from 'axios';\n"+ "import { navigateTo, http, navigateApi } from './nav';\n"+ "export class PaymentsPage {\n"+ " constructor(private router: any, private navCtrl: any, private location: any,\n"+ " private $router: any, private history: any) {}\n"+ " goPayments(): void { this.router.navigateByUrl('/payments/list'); }\n"+ " goBenefits(): void { this.navCtrl.navigateForward('/benefits/detail'); }\n"+ " goBack(): void { this.location.go('/orders/back'); }\n"+ " goVue(): void { this.$router.push('/dashboard/settings'); }\n"+ " goHist(): void { this.history.pushState(null, '', '/account/history'); }\n"+ " goWidget(id: string): void { navigateTo(`/widgetTypes/view/${id}`); }\n"+ " load(): unknown { return http('/api/customers'); }\n"+ " orders(): unknown { return axios.get('/api/orders'); }\n"+ " items(): unknown { return fetch('/api/items'); }\n"+ " custom(): unknown { return navigateApi('/api/navigation'); }\n"+ " explicitAlias(): unknown { return navigate('/api/alias'); }\n"+ " publish(): void { mqtt.publish('/tenant/events', 'payload'); }\n"+ "}\n";+ static const struct {+ const char *callee;+ const char *source;+ const char *path;+ } navigation[] = {+ {"this.router.navigateByUrl", "goPayments", "/payments/list"},+ {"this.navCtrl.navigateForward", "goBenefits", "/benefits/detail"},+ {"this.location.go", "goBack", "/orders/back"},+ {"this.$router.push", "goVue", "/dashboard/settings"},+ {"this.history.pushState", "goHist", "/account/history"},+ {"navigateTo", "goWidget", "/widgetTypes/view/{}"},+ };+ static const char edge_sql[] = "SELECT count(*) FROM edges e JOIN nodes s ON s.id=e.source_id "+ "WHERE e.project=?1 AND e.type='HTTP_CALLS' "+ "AND json_extract(e.properties,'$.url_path')=?2 AND s.name=?3";+ static const char route_sql[] =+ "SELECT count(*) FROM nodes WHERE project=?1 AND label='Route' AND name=?2";+ static const char source_sql[] =+ "SELECT count(*) FROM nodes WHERE project=?1 AND name=?2 AND file_path=?3";+ static const struct {+ const char *source;+ const char *path;+ } positive[] = {{"load", "/api/customers"},+ {"orders", "/api/orders"},+ {"items", "/api/items"},+ {"custom", "/api/navigation"},+ {"load_items", "/api/python/items"},+ {"explicitAlias", "/api/alias"}};++ int extracted[6] = {0};+ CBMFileResult *fr = cbm_extract_file(page, (int)strlen(page), CBM_LANG_TYPESCRIPT,+ "navigation_probe", "src/page.ts", 0, NULL, NULL);+ bool extraction_ok = fr && !fr->has_error;+ if (extraction_ok) {+ for (int c = 0; c < fr->calls.count; c++) {+ const CBMCall *call = &fr->calls.items[c];+ for (size_t i = 0; i < sizeof(navigation) / sizeof(navigation[0]); i++) {+ if (call->callee_name && strcmp(call->callee_name, navigation[i].callee) == 0 &&+ call->enclosing_func_qn && call->start_line > 0 &&+ call->site_end_byte > call->site_start_byte && call->arg_count > 0) {+ extracted[i]++;+ }+ }+ }+ }+ cbm_free_result(fr);++ const char *old_workers = getenv("CBM_WORKERS");+ const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *saved_single = old_single ? strdup(old_single) : NULL;+ if ((old_workers && !saved_workers) || (old_single && !saved_single)) {+ free(saved_workers);+ free(saved_single);+ FAIL("save environment");+ }+ char tmp[256] = "/tmp/cbm_arg_url_nav_XXXXXX";+ if (!cbm_mkdtemp(tmp)) {+ free(saved_workers);+ free(saved_single);+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "src/nav.ts",+ "export class AppRouter {\n"+ " navigateByUrl(url: string): void {}\n"+ " push(url: string): void {}\n"+ "}\n"+ "export class NavController {\n"+ " navigateForward(url: string): void {}\n"+ "}\n"+ "export class AppLocation { go(url: string): void {} }\n"+ "export class AppHistory {\n"+ " pushState(state: unknown, title: string, url: string): void {}\n"+ "}\n"+ "export function navigateTo(url: string): void {}\n"+ "export function http(url: string): unknown { return url; }\n"+ "export function navigateApi(url: string): unknown { return url; }\n");+ write_temp_file(tmp, "src/page.ts", page);+ write_temp_file(tmp, "src/py_client.py",+ "def navigate(url):\n return url\n"+ "def load_items():\n return navigate('/api/python/items')\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.ts", i);+ snprintf(body, sizeof(body), "export function filler%d(): number { return %d; }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ cbm_setenv("CBM_WORKERS", "4", 1);+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ const char *workers = getenv("CBM_WORKERS");+ bool configured =+ workers && strcmp(workers, "4") == 0 && getenv("CBM_INDEX_SINGLE_THREAD") == NULL;+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/arg_url_nav.db", tmp);+ cbm_pipeline_t *p = configured ? cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL) : NULL;+ int run_rc = p ? cbm_pipeline_run(p) : -1;+ cbm_store_t *store = run_rc == 0 ? cbm_store_open_path(db_path) : NULL;+ bool observed = store != NULL;+ int nav_edges[6], nav_routes[6], sources[6], good_edges[6];+ int files = -1, async_edges = -1, async_http = -1;+ for (size_t i = 0; i < 6; i++) {+ nav_edges[i] = nav_routes[i] = sources[i] = -1;+ }+ for (size_t i = 0; i < 6; i++) {+ good_edges[i] = -1;+ }+ if (store) {+ const char *project = cbm_pipeline_project_name(p);+ files = navigation_probe_count(store,+ "SELECT count(*) FROM nodes WHERE project=?1 AND label=?2",+ project, "File", NULL);+ for (size_t i = 0; i < 6; i++) {+ nav_edges[i] = navigation_probe_count(store, edge_sql, project, navigation[i].path,+ navigation[i].source);+ nav_routes[i] =+ navigation_probe_count(store, route_sql, project, navigation[i].path, NULL);+ sources[i] = navigation_probe_count(store, source_sql, project, navigation[i].source,+ "src/page.ts");+ }+ for (size_t i = 0; i < 6; i++) {+ good_edges[i] = navigation_probe_count(store, edge_sql, project, positive[i].path,+ positive[i].source);+ }+ async_edges = navigation_probe_count(+ store,+ "SELECT count(*) FROM edges e JOIN nodes s ON s.id=e.source_id "+ "JOIN nodes t ON t.id=e.target_id WHERE e.project=?1 AND e.type='ASYNC_CALLS' "+ "AND t.name=?2 AND s.name=?3",+ project, "/tenant/events", "publish");+ async_http = navigation_probe_count(store, edge_sql, project, "/tenant/events", "publish");+ cbm_store_close(store);+ }+ cbm_pipeline_free(p);+ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ if (saved_single) {+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ } else {+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ }+ const char *restored_workers = getenv("CBM_WORKERS");+ const char *restored_single = getenv("CBM_INDEX_SINGLE_THREAD");+ bool restored =+ (saved_workers ? restored_workers && strcmp(saved_workers, restored_workers) == 0+ : !restored_workers) &&+ (saved_single ? restored_single && strcmp(saved_single, restored_single) == 0+ : !restored_single);+ free(saved_workers);+ free(saved_single);+ th_rmtree(tmp);++ ASSERT_TRUE(extraction_ok);+ ASSERT_TRUE(configured);+ ASSERT_TRUE(restored);+ ASSERT_EQ(run_rc, 0);+ ASSERT_TRUE(observed);+ ASSERT_GTE(files, 55);+ for (size_t i = 0; i < 6; i++) {+ ASSERT_EQ(extracted[i], 1);+ ASSERT_EQ(sources[i], 1);+ ASSERT_EQ(nav_edges[i], 0);+ ASSERT_EQ(nav_routes[i], 0);+ }+ for (size_t i = 0; i < 6; i++) {+ ASSERT_GTE(good_edges[i], 1);+ }+ ASSERT_GTE(async_edges, 1);+ ASSERT_EQ(async_http, 0);+ PASS();+}+/* Native `fetch()` (#856), sequential path (< 50 files → pass_calls.c). A bare* unqualified call to the global fetch API has no import and no local* definition anywhere in this project, so registry resolution comes back@@ -21636,6 +21862,7 @@ SUITE(pipeline) {RUN_TEST(pipeline_parallel_python_cross_only_dunder_gets_synthetic_carrier);RUN_TEST(pipeline_parallel_rust_cross_only_macro_hidden_gets_synthetic_carrier);RUN_TEST(pipeline_arg_url_rejects_non_http_slash_arguments);+ RUN_TEST(pipeline_arg_url_skips_client_navigation);RUN_TEST(pipeline_ts_config_object_url_http_calls_issue2235);RUN_TEST(pipeline_arg_url_rejects_document_file_paths);RUN_TEST(pipeline_native_fetch_classified_as_http_calls);