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
Merge origin/main into fix/js-template-leading-substitution-url
Martin Vogelec960f1c6938
diff --cc tests/test_pipeline.cindex 7c8d61cbe,d9b327226..424996f96--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@@ -8789,239 -12019,188 +12019,222 @@@ TEST(pipeline_native_fetch_classified_aPASS();}- TEST(implements_no_match) {- /* Port of TestPassImplementsNoOverrideWithoutMatch.- * Interface requires Read+Write, struct only has Read → no edges. */- cbm_gbuf_t *gb = cbm_gbuf_new("test-proj", "/tmp/test");- ASSERT_NOT_NULL(gb);-- /* Interface "ReadWriter" with methods "Read" and "Write" */- int64_t iface_id = cbm_gbuf_upsert_node(gb, "Interface", "ReadWriter", "pkg.ReadWriter",- "pkg/rw.go", 1, 5, "{}");- int64_t read_id =- cbm_gbuf_upsert_node(gb, "Method", "Read", "pkg.ReadWriter.Read", "pkg/rw.go", 2, 2, "{}");- int64_t write_id = cbm_gbuf_upsert_node(gb, "Method", "Write", "pkg.ReadWriter.Write",- "pkg/rw.go", 3, 3, "{}");- cbm_gbuf_insert_edge(gb, iface_id, read_id, "DEFINES_METHOD", "{}");- cbm_gbuf_insert_edge(gb, iface_id, write_id, "DEFINES_METHOD", "{}");-- /* Struct "OnlyReader" with only "Read" (missing "Write") */- int64_t class_id = cbm_gbuf_upsert_node(gb, "Class", "OnlyReader", "pkg.OnlyReader",- "pkg/onlyreader.go", 1, 10, "{}");- int64_t or_read_id =- cbm_gbuf_upsert_node(gb, "Method", "Read", "pkg.OnlyReader.Read", "pkg/onlyreader.go", 2, 4,- "{\"receiver\":\"(o *OnlyReader)\"}");-- /* Run Go-style implements detection */- atomic_int cancelled = 0;- cbm_pipeline_ctx_t ctx = {- .project_name = "test-proj",- .repo_path = "/tmp/test",- .gbuf = gb,- .registry = NULL,- .cancelled = &cancelled,- };- int edges_created = cbm_pipeline_implements_go(&ctx);- ASSERT_EQ(edges_created, 0);++TEST(pipeline_native_fetch_template_base_url_makes_route) {++ char tmp[256];++ snprintf(tmp, sizeof(tmp), "/tmp/cbm_fetch_template_base_XXXXXX");++ if (!cbm_mkdtemp(tmp)) {++ FAIL("tmpdir");++ }+- /* Verify NO IMPLEMENTS edge */- const cbm_gbuf_edge_t **impl_edges = NULL;- int impl_count = 0;- cbm_gbuf_find_edges_by_source_type(gb, class_id, "IMPLEMENTS", &impl_edges, &impl_count);- ASSERT_EQ(impl_count, 0);++ write_temp_file(tmp, "src/api.ts",++ "const BASE_URL = \"http://payments:8080\";\n"++ "export async function createPayment(body: unknown) {\n"++ " return fetch(`${BASE_URL}/v1/payments`, { method: 'POST', body });\n"++ "}\n");+- /* Verify NO OVERRIDE edge */- const cbm_gbuf_edge_t **override_edges = NULL;- int override_count = 0;- cbm_gbuf_find_edges_by_source_type(gb, or_read_id, "OVERRIDE", &override_edges,- &override_count);- ASSERT_EQ(override_count, 0);++ char db_path[512];++ snprintf(db_path, sizeof(db_path), "%s/fetch_template_base.db", tmp);++ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);++ ASSERT_NOT_NULL(p);++ ASSERT_EQ(cbm_pipeline_run(p), 0);++ const char *project = cbm_pipeline_project_name(p);+- /* Suppress unused warnings */- (void)iface_id;- (void)read_id;- (void)write_id;++ cbm_store_t *s = cbm_store_open_path(db_path);++ ASSERT_NOT_NULL(s);++ int http_call_count = cbm_store_count_edges_by_type(s, project, "HTTP_CALLS");++ int matching_route_count =++ http_calls_to_route(s, project, "createPayment", "/v1/payments");+- cbm_gbuf_free(gb);++ cbm_store_close(s);++ cbm_pipeline_free(p);++ th_rmtree(tmp);++ ASSERT_EQ(http_call_count, 1);++ ASSERT_EQ(matching_route_count, 1);+ PASS();+}+- /* ── Usages pass tests (full pipeline integration) ──────────────── */-- /* Helper to create a temp dir with a single source file */- static char g_usages_tmpdir[256];-- static int setup_usages_repo(const char *filename, const char *content, const char *extra_file,- const char *extra_content) {- snprintf(g_usages_tmpdir, sizeof(g_usages_tmpdir), "/tmp/cbm_usage_XXXXXX");- if (!cbm_mkdtemp(g_usages_tmpdir))- return -1;+ /* #1892: Swift produced no Route node and no HTTP_CALLS edge, because the+ * Swift grammar has no "arguments" field and the generic lookup therefore read+ * no call arguments at all. Alamofire/URLSession were already in the service+ * pattern table; the URL simply never reached it. This is the Swift twin of+ * the TypeScript fetch case above. */+ /* The shape real Swift actually writes: the URL is built by a constructor and+ * force-unwrapped, so the literal is two levels below the argument list. This+ * is what issue #1892 reported from a real project. */+ TEST(pipeline_swift_nested_url_makes_route_issue1892) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_swiftnested_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }- /* Check if filename has subdirectory */- char path[512];- snprintf(path, sizeof(path), "%s/%s", g_usages_tmpdir, filename);+ write_temp_file(tmp, "Sources/Client.swift",+ "import Foundation\n"+ "final class Client {\n"+ " func listWidgets() {\n"+ " URLSession.shared.dataTask(with: "+ "URL(string: \"/api/v1/widgets\")!)\n"+ " }\n"+ "}\n");- /* Create subdirectories if needed */- char dir_path[512];- snprintf(dir_path, sizeof(dir_path), "%s", path);- char *last_slash = strrchr(dir_path, '/');- if (last_slash) {- *last_slash = '\0';- th_mkdir_p(dir_path);- }+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/swiftnested.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);- FILE *f = fopen(path, "w");- if (!f)- return -1;- fprintf(f, "%s", content);- fclose(f);+ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);- if (extra_file && extra_content) {- snprintf(path, sizeof(path), "%s/%s", g_usages_tmpdir, extra_file);- f = fopen(path, "w");- if (!f)- return -1;- fprintf(f, "%s", extra_content);- fclose(f);- }+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 1);- return 0;- }+ cbm_node_t *routes = NULL;+ int route_count = 0;+ cbm_store_find_nodes_by_label(s, project, "Route", &routes, &route_count);+ int widget_routes = 0;+ for (int i = 0; i < route_count; i++) {+ if (routes[i].qualified_name && strstr(routes[i].qualified_name, "/api/v1/widgets")) {+ widget_routes++;+ }+ }+ cbm_store_free_nodes(routes, route_count);+ ASSERT_GTE(widget_routes, 1);- static void teardown_usages_repo(void) {- if (g_usages_tmpdir[0])- rm_rf(g_usages_tmpdir);- g_usages_tmpdir[0] = '\0';+ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();}- /* #1277: typed instance fields of a Python class imported from another file.- * Counts CALLS edges caller -> callee (QN suffixes) whose properties name an- * LSP strategy. */- static int count_lsp_calls(cbm_store_t *s, const char *project, const char *caller_suffix,- const char *callee_suffix) {+ /* HANDLES edges from the function named `source_name` to Routes whose+ * qualified name equals `route_qn`. */+ static int handles_to_route(cbm_store_t *s, const char *project, const char *source_name,+ const char *route_qn) {cbm_edge_t *edges = NULL;int edge_count = 0;- cbm_store_find_edges_by_type(s, project, "CALLS", &edges, &edge_count);- int hits = 0;+ if (cbm_store_find_edges_by_type(s, project, "HANDLES", &edges, &edge_count) != CBM_STORE_OK) {+ return -1;+ }+ int matches = 0;for (int i = 0; i < edge_count; i++) {- cbm_node_t src = {0};- cbm_node_t tgt = {0};- if (cbm_store_find_node_by_id(s, edges[i].source_id, &src) == CBM_STORE_OK &&- cbm_store_find_node_by_id(s, edges[i].target_id, &tgt) == CBM_STORE_OK) {- size_t sl = strlen(src.qualified_name);- size_t tl = strlen(tgt.qualified_name);- size_t cs = strlen(caller_suffix);- size_t ts = strlen(callee_suffix);- if (sl >= cs && tl >= ts && strcmp(src.qualified_name + sl - cs, caller_suffix) == 0 &&- strcmp(tgt.qualified_name + tl - ts, callee_suffix) == 0 &&- edges[i].properties_json && strstr(edges[i].properties_json, "lsp")) {- hits++;- }+ cbm_node_t source = {0};+ cbm_node_t target = {0};+ int source_ok = cbm_store_find_node_by_id(s, edges[i].source_id, &source) == CBM_STORE_OK;+ int target_ok = cbm_store_find_node_by_id(s, edges[i].target_id, &target) == CBM_STORE_OK;+ if (source_ok && target_ok && source.name && target.qualified_name &&+ (!source_name || strcmp(source.name, source_name) == 0) &&+ strcmp(target.qualified_name, route_qn) == 0) {+ matches++;}- cbm_node_free_fields(&src);- cbm_node_free_fields(&tgt);+ cbm_node_free_fields(&source);+ cbm_node_free_fields(&target);}- if (edges)+ if (edges) {cbm_store_free_edges(edges, edge_count);- return hits;- }-- static int check_python_crossfile_typed_field_calls_issue1277(bool parallel) {- const char *contracts = "class Contract:\n"- " def process_batch(self) -> None:\n"- " ...\n";- const char *trainer = "from contracts import Contract\n\n"- "def make():\n"- " return None\n\n"- "class Trainer:\n"- " engine: Contract\n\n"- " def __init__(self, strategies: Contract) -> None:\n"- " self.strategies = strategies\n"- " self.typed: Contract = strategies\n"- " self.plain = make()\n";- const char *loop = "from trainer import Trainer\n\n"- "def run(trainer: Trainer) -> None:\n"- " strategies = trainer.strategies\n"- " strategies.process_batch()\n\n"- "def run_typed(trainer: Trainer) -> None:\n"- " trainer.typed.process_batch()\n\n"- "def run_classlevel(trainer: Trainer) -> None:\n"- " trainer.engine.process_batch()\n\n"- "def run_untyped(trainer: Trainer) -> None:\n"- " trainer.plain.process_batch()\n";- if (setup_usages_repo("contracts.py", contracts, "trainer.py", trainer) != 0) {- FAIL("failed to create temp dir");- }- char path[512];- snprintf(path, sizeof(path), "%s/loop.py", g_usages_tmpdir);- if (th_write_file(path, loop) != 0) {- teardown_usages_repo();- FAIL("failed to write loop.py");- }- if (parallel) {- /* Three semantic files plus 50 inert files exceed the production- * threshold for the fused parallel pipeline. */- for (int i = 0; i < 50; i++) {- snprintf(path, sizeof(path), "%s/field_pad_%02d.py", g_usages_tmpdir, i);- if (th_write_file(path, "field_padding = 0\n") != 0) {- teardown_usages_repo();- FAIL("failed to write parallel-selection fixture");- }- }}+ return matches;+ }- const char *old_workers = getenv("CBM_WORKERS");- char *saved_workers = old_workers ? strdup(old_workers) : NULL;- const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");- char *saved_single = old_single ? strdup(old_single) : NULL;- if ((old_workers && !saved_workers) || (old_single && !saved_single)) {- free(saved_workers);- free(saved_single);- teardown_usages_repo();- FAIL("failed to save pipeline environment");+ /* fastapi (2026-10-05): one binary indexed the same tree to 3,253 or to+ * 1,119,241 HANDLES edges. A prefix Route took the directory of whichever+ * registrar's CALLS edge came first (worker order) and linked every decorated+ * handler under it, with no filter for the root prefix `/`; every infra URL+ * then copied the handlers of the root route. Now: every registrar counts, a+ * root mount bridges nothing, and an infra URL matches a root route only of+ * its own service. */+ TEST(pipeline_route_prefix_bridge_is_order_free_and_root_bridges_nothing) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_routebridge_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");}- int pin_workers_rc = parallel ? cbm_setenv("CBM_WORKERS", "4", 1) : 0;- int pin_single_rc = parallel ? cbm_unsetenv("CBM_INDEX_SINGLE_THREAD") : 0;+ /* two apps mounted at the root and under /api, from two directories */+ write_temp_file(tmp, "svc/a/main.py",+ "from fastapi import FastAPI\n"+ "app = FastAPI()\n"+ "app.mount(\"/\", None)\n"+ "app.mount(\"/api\", None)\n"+ "\n"+ "@app.get(\"/items\")\n"+ "def read_items():\n"+ " return []\n");+ write_temp_file(tmp, "svc/a/api/routes.py",+ "from fastapi import APIRouter\n"+ "router = APIRouter()\n"+ "\n"+ "@router.get(\"/ax\")\n"+ "def api_a():\n"+ " return 1\n");+ write_temp_file(tmp, "svc/b/main.py",+ "from fastapi import FastAPI\n"+ "app = FastAPI()\n"+ "app.mount(\"/\", None)\n"+ "app.mount(\"/api\", None)\n"+ "app.mount(\"/c\", None)\n"+ "\n"+ "@app.get(\"/users\")\n"+ "def read_users():\n"+ " return []\n");+ write_temp_file(tmp, "svc/b/api/routes.py",+ "from fastapi import APIRouter\n"+ "router = APIRouter()\n"+ "\n"+ "@router.get(\"/by\")\n"+ "def api_b():\n"+ " return 2\n");+ /* a real root handler, and a documentation site's link to a chat server */+ write_temp_file(tmp, "web/site.py",+ "from flask import Flask\n"+ "app = Flask(__name__)\n"+ "\n"+ "@app.route(\"/\")\n"+ "def index():\n"+ " return \"ok\"\n"+ "\n"+ "@app.route(\"/c\")\n"+ "def contact():\n"+ " return \"c\"\n");+ write_temp_file(tmp, "mkdocs.yml",+ "site_name: demo\n"+ "extra:\n"+ " social:\n"+ " - icon: fontawesome/brands/discord\n"+ " link: https://discord.com/invite/abc123\n"+ " - icon: fontawesome/brands/github\n"+ " link: https://github.com/carol\n");char db_path[512];- snprintf(db_path, sizeof(db_path), "%s/test_1277.db", g_usages_tmpdir);- cbm_pipeline_t *p = pin_workers_rc == 0 && pin_single_rc == 0- ? cbm_pipeline_new(g_usages_tmpdir, db_path, CBM_MODE_FULL)- : NULL;- int run_rc = p ? cbm_pipeline_run(p) : -1;- cbm_store_t *s = run_rc == 0 ? cbm_store_open_path(db_path) : NULL;- bool store_opened = s != NULL;- int via_alias = -1, via_typed = -1, via_class = -1, via_untyped = -1;- if (s) {- const char *project = cbm_pipeline_project_name(p);- via_alias = count_lsp_calls(s, project, "loop.run", "contracts.Contract.process_batch");- via_typed =- count_lsp_calls(s, project, "loop.run_typed", "contracts.Contract.process_batch");- via_class =- count_lsp_calls(s, project, "loop.run_classlevel", "contracts.Contract.process_batch");- via_untyped = count_lsp_calls(s, project, "loop.run_untyped", "process_batch");- cbm_store_close(s);- }+ snprintf(db_path, sizeof(db_path), "%s/routebridge.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);- cbm_pipeline_free(p);- int restore_workers_rc =- saved_workers ? cbm_setenv("CBM_WORKERS", saved_workers, 1) : cbm_unsetenv("CBM_WORKERS");- int restore_single_rc = saved_single ? cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1)- : cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");- free(saved_workers);- free(saved_single);- teardown_usages_repo();+ /* decorator routes are untouched */+ ASSERT_EQ(handles_to_route(s, project, "read_items", "__route__GET__/items"), 1);+ ASSERT_EQ(handles_to_route(s, project, "index", "__route__ANY__/"), 1);+ /* a root mount names no part of a handler's path: nothing is bridged */+ ASSERT_EQ(handles_to_route(s, project, "read_items", "__route__ANY__/"), 0);+ ASSERT_EQ(handles_to_route(s, project, "read_users", "__route__ANY__/"), 0);+ /* /api is registered from both directories: both api handlers, whatever+ * order the registrations' CALLS edges landed in */+ ASSERT_EQ(handles_to_route(s, project, "api_a", "__route__ANY__/api"), 1);+ ASSERT_EQ(handles_to_route(s, project, "api_b", "__route__ANY__/api"), 1);+ /* a prefix and a URL path match on whole segments only: `c` is no segment+ * of svc/b/main.py, and `/c` is no route of github.com/carol */+ ASSERT_EQ(handles_to_route(s, project, "read_users", "__route__ANY__/c"), 0);+ ASSERT_EQ(handles_to_route(s, project, "contact", "__route__ANY__/c"), 1);+ ASSERT_EQ(handles_to_route(s, project, NULL, "__route__infra__https://github.com/carol"), 0);+ /* the chat link is no route of this repository's root handler */+ ASSERT_EQ(+ handles_to_route(s, project, NULL, "__route__infra__https://discord.com/invite/abc123"), 0);- ASSERT_EQ(pin_workers_rc, 0);- ASSERT_EQ(pin_single_rc, 0);- ASSERT_EQ(restore_workers_rc, 0);- ASSERT_EQ(restore_single_rc, 0);- ASSERT_EQ(run_rc, 0);- ASSERT_TRUE(store_opened);- ASSERT_EQ(via_alias, 1); /* self.x = <annotated __init__ parameter> */- ASSERT_EQ(via_typed, 1); /* self.x: T = ... */- ASSERT_EQ(via_class, 1); /* class-level x: T */- ASSERT_EQ(via_untyped, 0); /* control: no annotation, no guess */+ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);PASS();}@@@ -17705,9 -26548,9 +26582,10 @@@ SUITE(pipeline)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);+ RUN_TEST(pipeline_native_fetch_template_base_url_makes_route);RUN_TEST(pipeline_swift_nested_url_makes_route_issue1892);RUN_TEST(pipeline_swift_http_call_makes_route_issue1892);+ RUN_TEST(pipeline_route_prefix_bridge_is_order_free_and_root_bridges_nothing);RUN_TEST(pipeline_native_fetch_parallel_classified_as_http_calls);RUN_TEST(pipeline_local_fetch_shadow_not_classified_as_http);RUN_TEST(pipeline_typed_http_call_has_no_arg_url_twin);