Skip to content

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.

test(repro): fix harness include + #408 comment; add #571, #523, #546

Martin Vogela8e274ce047d
diff --git a/Makefile.cbm b/Makefile.cbm
index e0b395bbe..abb2d0224 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -400,7 +400,10 @@ TEST_REPRO_SRCS = \
tests/repro/repro_issue382.c \
tests/repro/repro_issue408.c \
tests/repro/repro_issue56.c \
- tests/repro/repro_issue480.c
+ tests/repro/repro_issue480.c \
+ tests/repro/repro_issue571.c \
+ tests/repro/repro_issue523.c \
+ tests/repro/repro_issue546.c
ALL_TEST_SRCS =$(TEST_FOUNDATION_SRCS) $(TEST_EXTRACTION_SRCS) $(TEST_STORE_SRCS) $(TEST_CYPHER_SRCS) $(TEST_MCP_SRCS) $(TEST_DISCOVER_SRCS) $(TEST_GRAPH_BUFFER_SRCS) $(TEST_PIPELINE_SRCS) $(TEST_WATCHER_SRCS) $(TEST_LZ4_SRCS) $(TEST_ZSTD_SRCS) $(TEST_ARTIFACT_SRCS) $(TEST_SQLITE_WRITER_SRCS) $(TEST_GO_LSP_SRCS) $(TEST_C_LSP_SRCS) $(TEST_PHP_LSP_SRCS) $(TEST_CS_LSP_SRCS) $(TEST_CS_LSP_BENCH_SRCS) $(TEST_SCOPE_SRCS) $(TEST_TYPE_REP_SRCS) $(TEST_PY_LSP_SRCS) $(TEST_PY_LSP_BENCH_SRCS) $(TEST_PY_LSP_STRESS_SRCS) $(TEST_PY_LSP_SCALE_SRCS) $(TEST_TS_LSP_SRCS) $(TEST_JAVA_LSP_SRCS) $(TEST_KOTLIN_LSP_SRCS) $(TEST_RUST_LSP_SRCS) $(TEST_TRACES_SRCS) $(TEST_CLI_SRCS) $(TEST_MEM_SRCS) $(TEST_UI_SRCS) $(TEST_HTTPD_SRCS) $(TEST_SECURITY_SRCS) $(TEST_YAML_SRCS) $(TEST_SIMHASH_SRCS) $(TEST_STACK_OVERFLOW_SRCS) $(TEST_INTEGRATION_SRCS)
diff --git a/tests/repro/repro_harness.h b/tests/repro/repro_harness.h
index 827ec96c0..74f513040 100644
--- a/tests/repro/repro_harness.h
+++ b/tests/repro/repro_harness.h
@@ -19,6 +19,7 @@
#include "cbm.h"
#include <mcp/mcp.h>
#include <store/store.h>
+#include <pipeline/pipeline.h> /* cbm_project_name_from_path */
#include <string.h>
#include <stdlib.h>
diff --git a/tests/repro/repro_issue408.c b/tests/repro/repro_issue408.c
index f7bf13aa0..00bd5e4a7 100644
--- a/tests/repro/repro_issue408.c
+++ b/tests/repro/repro_issue408.c
@@ -29,7 +29,7 @@
*
* Expected (correct) behaviour:
* Indexing a minimal monorepo:
- * root/package.json { "workspaces": ["packages/*"] }
+ * root/package.json { "workspaces": ["packages/<glob>"] }
* packages/a/package.json { "name": "@org/a", "main": "index.js" }
* packages/a/index.js export function fromA() { return 1; }
* packages/b/package.json { "name": "@org/b", "main": "index.js" }
diff --git a/tests/repro/repro_issue523.c b/tests/repro/repro_issue523.c
new file mode 100644
index 000000000..9ea60fb40
--- /dev/null
+++ b/tests/repro/repro_issue523.c
@@ -0,0 +1,231 @@
+/*
+ * repro_issue523.c — Reproduce-first case for issue #523.
+ *
+ * BUG: "cross-repo-intelligence returns 0 edges for a byte-identical call/route"
+ *
+ * Root cause (pass_calls.c::resolve_single_call):
+ *
+ * When a Python client uses `import requests` and calls
+ * `requests.get("/api/orders/{id}")`, the `requests` package is an external
+ * pip dependency whose source is NOT present in the indexed tree.
+ * `cbm_registry_resolve` resolves the callee name to a candidate QN
+ * containing "requests", but `cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name)`
+ * returns NULL — the node does not exist in the graph because `requests` was
+ * never indexed. The guard at pass_calls.c::resolve_single_call line ~406:
+ *
+ * const cbm_gbuf_node_t *target_node = cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name);
+ * if (!target_node || source_node->id == target_node->id)
+ * return 0; ← call is SILENTLY DROPPED
+ *
+ * causes the call to be silently dropped before it ever reaches
+ * `emit_classified_edge` / `emit_http_async_edge`. No HTTP_CALLS edge is
+ * created in the client project DB.
+ *
+ * Without an HTTP_CALLS edge in the client DB, `match_http_routes` in
+ * pass_cross_repo.c finds nothing to iterate over, and `cbm_cross_repo_match`
+ * returns http_edges == 0 — even when the server project has a perfectly
+ * matching Route node (byte-identical path, correct method) and a HANDLES
+ * edge pointing to the handler function.
+ *
+ * Expected (correct) behaviour:
+ * A call to an external HTTP client library (e.g. `requests.get`) with a
+ * URL/path first argument MUST produce an HTTP_CALLS edge in the client
+ * project DB, even when the library's source is not indexed. The linker
+ * should detect the service-pattern match on the resolved QN substring
+ * ("requests") and emit the edge before consulting the node graph.
+ * Subsequently, `cbm_cross_repo_match` must produce at least one
+ * CROSS_HTTP_CALLS edge linking the client caller to the server route handler
+ * when the client url_path (canonicalized) matches the server Route QN.
+ *
+ * Actual (buggy) behaviour:
+ * cbm_cross_repo_match returns http_edges == 0. The assertion below is RED.
+ *
+ * Companion: pass_calls.c (sequential path) and pass_parallel.c (parallel path)
+ * both share the same guard; fixing one requires fixing both.
+ *
+ * Note on parallel pipeline:
+ * HTTP_CALLS edges are produced on BOTH the sequential (< 50 files) and
+ * parallel (>= 50 files) pipeline paths, so this test uses a small fixture
+ * (< 50 files) and exercises the sequential path. The parallel path has the
+ * same root cause and is covered by the same fix (pass_parallel.c::
+ * finalize_and_emit has an identical unindexed-node guard).
+ */
+
+#include "test_framework.h"
+#include "repro_harness.h"
+#include "pipeline/pass_cross_repo.h"
+
+#include <stdio.h>
+#include <string.h>
+
+/* ── Fixture files ───────────────────────────────────────────────────────── */
+
+/*
+ * CLIENT SERVICE (order-client):
+ * Uses the real `requests` library imported at the top of the file.
+ * The `requests` package is NOT present in the indexed tree (no vendored
+ * source, no stub) — this is exactly the real-world multi-service scenario.
+ * The caller function `fetch_order` makes a GET request to the byte-identical
+ * path "/api/orders/{id}" that the server registers.
+ *
+ * WHY this triggers the bug:
+ * cbm_registry_resolve("requests.get", …) returns a candidate QN that
+ * contains "requests" (service-pattern match → CBM_SVC_HTTP), BUT
+ * cbm_gbuf_find_by_qn returns NULL for that QN because no `requests` node
+ * was ever inserted into the graph buffer. resolve_single_call returns 0,
+ * the call is dropped, and no HTTP_CALLS edge is created.
+ */
+static const RFile client_files[] = {
+ {
+ "client/orders.py",
+ "import requests\n"
+ "\n"
+ "\n"
+ "BASE_URL = \"http://order-service:8080\"\n"
+ "\n"
+ "\n"
+ "def fetch_order(order_id):\n"
+ " \"\"\"Fetch a single order from the order service.\"\"\"\n"
+ " return requests.get(\"/api/orders/{id}\", params={\"id\": order_id})\n"
+ "\n"
+ "\n"
+ "def list_orders():\n"
+ " \"\"\"Fetch all orders from the order service.\"\"\"\n"
+ " return requests.get(\"/api/orders\")\n"
+ },
+};
+enum { N_CLIENT_FILES = (int)(sizeof(client_files) / sizeof(client_files[0])) };
+
+/*
+ * SERVER SERVICE (order-service):
+ * A minimal Flask application that defines the route handler for the path
+ * the client calls. The path "/api/orders/{id}" is byte-identical to the
+ * client's call argument. Flask uses `{id}` parameter syntax; the extractor
+ * mints a Route node with QN `__route__GET__/api/orders/{}` (canonicalized
+ * via cbm_route_canon_path). A HANDLES edge links the Route to `get_order`.
+ */
+static const RFile server_files[] = {
+ {
+ "server/app.py",
+ "from flask import Flask, jsonify\n"
+ "\n"
+ "app = Flask(__name__)\n"
+ "\n"
+ "\n"
+ "@app.get(\"/api/orders/{id}\")\n"
+ "def get_order(order_id):\n"
+ " \"\"\"Return a single order by id.\"\"\"\n"
+ " return jsonify({\"id\": order_id, \"status\": \"ok\"})\n"
+ "\n"
+ "\n"
+ "@app.get(\"/api/orders\")\n"
+ "def list_orders():\n"
+ " \"\"\"Return all orders.\"\"\"\n"
+ " return jsonify({\"orders\": []})\n"
+ },
+};
+enum { N_SERVER_FILES = (int)(sizeof(server_files) / sizeof(server_files[0])) };
+
+/* ── Reproduction test ───────────────────────────────────────────────────── */
+
+/*
+ * TEST: repro_issue523_crossrepo_http_calls_edge
+ *
+ * Steps:
+ * 1. Index the CLIENT service — expect HTTP_CALLS >= 1 (currently 0: RED
+ * because unindexed `requests` causes the call to be dropped).
+ * 2. Index the SERVER service — expect Route nodes >= 1 (this side is GREEN;
+ * Flask decorator extraction is correct).
+ * 3. Run cbm_cross_repo_match(client_project, [server_project], 1).
+ * 4. Assert result.http_edges >= 1 — this is the cross-repo edge count.
+ * Currently 0 because step 1 yields no HTTP_CALLS to match.
+ *
+ * The assertion at step 4 is the canonical RED line. Steps 1 and 3 are
+ * diagnostic: step 1 prints the http_calls count so the fix can be verified
+ * independently; step 3 fails fast if the server was not indexed correctly.
+ */
+TEST(repro_issue523_crossrepo_http_calls_edge) {
+ /* ── Index client service ─────────────────────────────────── */
+ RProj client;
+ cbm_store_t *client_store =
+ rh_index_files(&client, client_files, N_CLIENT_FILES);
+ ASSERT_NOT_NULL(client_store);
+
+ int client_http = rh_count_edges(client_store, client.project, "HTTP_CALLS");
+ fprintf(stderr,
+ " [523] client HTTP_CALLS=%d "
+ "(expected>=1; 0=bug: requests not indexed → call dropped)\n",
+ client_http);
+
+ cbm_store_close(client_store);
+ client_store = NULL; /* re-opened inside cbm_cross_repo_match via cache dir */
+
+ /* ── Index server service ─────────────────────────────────── */
+ RProj server;
+ cbm_store_t *server_store =
+ rh_index_files(&server, server_files, N_SERVER_FILES);
+ ASSERT_NOT_NULL(server_store);
+
+ int server_routes = rh_count_label(server_store, server.project, "Route");
+ fprintf(stderr,
+ " [523] server Route nodes=%d (expected>=2; 0=extractor broken)\n",
+ server_routes);
+ /* Server-side extraction is correct — if this fails the test environment is
+ * broken, not the cross-repo linker. Fail fast with a clear message. */
+ if (server_routes < 1) {
+ cbm_store_close(server_store);
+ rh_cleanup(&client, NULL);
+ rh_cleanup(&server, server_store);
+ FAIL("server route extraction broken — test environment issue, not issue #523");
+ }
+
+ cbm_store_close(server_store);
+ server_store = NULL; /* re-opened bidirectionally inside cbm_cross_repo_match */
+
+ /* ── Cross-repo match ─────────────────────────────────────── */
+ /*
+ * cbm_cross_repo_match opens both project DBs from the cache directory
+ * (the same $HOME/.cache/codebase-memory-mcp/<project>.db paths that
+ * rh_open_indexed wrote). It iterates HTTP_CALLS edges in the client DB
+ * and looks for matching Route QNs in the server DB.
+ *
+ * Correct: http_edges >= 1 (at least one edge for /api/orders/{id}).
+ * Buggy: http_edges == 0 (no HTTP_CALLS in client → nothing to match).
+ */
+ const char *server_project = server.project;
+ cbm_cross_repo_result_t result =
+ cbm_cross_repo_match(client.project, &server_project, 1);
+
+ fprintf(stderr,
+ " [523] cross_repo http_edges=%d "
+ "(expected>=1; 0=bug confirmed: issue #523)\n",
+ result.http_edges);
+
+ /* ── Cleanup ──────────────────────────────────────────────── */
+ rh_cleanup(&client, NULL);
+ rh_cleanup(&server, NULL);
+
+ /*
+ * WHY RED: result.http_edges == 0 on current code.
+ *
+ * The root cause is in resolve_single_call (pass_calls.c ~line 405):
+ * cbm_gbuf_find_by_qn returns NULL for the `requests` QN (not indexed).
+ * The function returns 0 before reaching emit_classified_edge.
+ * No HTTP_CALLS edge is written to the client DB.
+ * match_http_routes in pass_cross_repo.c finds no HTTP_CALLS to iterate.
+ * cbm_cross_repo_match returns http_edges = 0.
+ *
+ * The fix must allow emit_http_async_edge to fire for service-pattern
+ * matches even when the resolved target node is absent from the graph buffer
+ * (i.e., skip the cbm_gbuf_find_by_qn guard for CBM_SVC_HTTP / CBM_SVC_ASYNC
+ * calls, or create a synthetic stub node so the guard passes).
+ */
+ ASSERT_GTE(result.http_edges, 1);
+
+ PASS();
+}
+
+/* ── Suite ───────────────────────────────────────────────────────────────── */
+SUITE(repro_issue523) {
+ RUN_TEST(repro_issue523_crossrepo_http_calls_edge);
+}
diff --git a/tests/repro/repro_issue546.c b/tests/repro/repro_issue546.c
new file mode 100644
index 000000000..b88daa4fc
--- /dev/null
+++ b/tests/repro/repro_issue546.c
@@ -0,0 +1,266 @@
+/*
+ * repro_issue546.c — Reproduce-first case for OPEN bug #546.
+ *
+ * Issue: #546 — "trace_path / reverse-dependency returns an INCOMPLETE caller
+ * set when a symbol is duplicated by an ambient .d.ts declaration
+ * (callers silently split by import style)"
+ *
+ * Root cause (graph layer — node identity / dedup across the ambient declaration):
+ * When a TypeScript symbol is BOTH defined in a real .ts source file AND
+ * re-declared (body-less, signature only) in an ambient .d.ts shim file,
+ * the indexer creates TWO distinct Function nodes for the same logical symbol
+ * (one rooted at the .ts implementation, one rooted at the .d.ts stub).
+ *
+ * CALLS edges from consumers are then partitioned across the two nodes based
+ * on which import form each consumer used:
+ * - consumer importing via relative path ("./scroll") → CALLS edge targets
+ * the IMPLEMENTATION node (packages/widget/src/scroll.ts)
+ * - consumer importing via path alias ("@widget") → CALLS edge targets
+ * the .d.ts STUB node (app/types/widget-shim.d.ts)
+ *
+ * trace_path resolves the symbol name to EXACTLY ONE of the two nodes (the
+ * first one returned by cbm_store_find_nodes_by_name) and BFS-traverses only
+ * that node's inbound CALLS edges. The callers whose edges point to the OTHER
+ * node are silently omitted from the result. There is no warning that the
+ * symbol resolved to multiple nodes and the caller set is therefore partial.
+ *
+ * Expected (correct) behaviour:
+ * trace_path(function_name="alignToEdge", direction="inbound") must return
+ * ALL callers, regardless of which import style they used:
+ * {"callers": [{name: "internalConsumer", ...}, {name: "externalConsumer", ...}]}
+ * Both "internalConsumer" AND "externalConsumer" must appear in the response.
+ *
+ * Actual (buggy) behaviour:
+ * Only ONE of the two callers appears in the "callers" array. The other is
+ * silently dropped because its CALLS edge points to the sibling node (the
+ * other representation of the same logical symbol) that trace_path did not
+ * select as its BFS root.
+ *
+ * Why RED on current code:
+ * The final assertion checks that BOTH caller names appear in the trace_path
+ * JSON response. On buggy code, trace_path picks one of the two Function
+ * nodes for "alignToEdge" as its BFS root; the inbound CALLS edges of the
+ * OTHER node are never visited; one caller name is absent from the JSON;
+ * the strstr check for the missing name returns NULL →
+ * ASSERT_NOT_NULL(strstr(resp, "...")) FAILS → RED.
+ *
+ * Precondition strategy:
+ * Before driving trace_path, the test checks that BOTH callers produced
+ * at least one CALLS edge each (total CALLS edges ≥ 2). If this precondition
+ * fires RED it flags an extraction failure (TS CALLS extraction not working),
+ * not the #546 traversal bug. Separation keeps the root cause unambiguous.
+ *
+ * TS CALLS extraction reliability note:
+ * TypeScript CALLS extraction is confirmed reliable for simple intra-package
+ * call expressions by existing integration tests (test_extraction.c and the
+ * regression suite). The known risk here is the path-alias import form
+ * ("@widget") — the extractor may or may not resolve the alias and produce
+ * a CALLS edge for externalConsumer. If the precondition (total CALLS ≥ 2)
+ * fires first, the alias resolution is the cause, not the #546 split.
+ * A secondary precondition after the main assertion ensures that even if only
+ * one CALLS edge is produced (alias unresolved), the test is still RED for
+ * the right reason: incomplete caller set.
+ *
+ * Fix location (not implemented here):
+ * Either in cbm_store_find_nodes_by_name / cbm_store_bfs (union traversal
+ * across all nodes sharing name+signature), or in the pipeline dedup step
+ * where body-less .d.ts stub nodes should be merged/aliased into their
+ * implementation counterpart rather than stored as separate graph nodes.
+ */
+
+#include <foundation/compat.h>
+#include "test_framework.h"
+#include "repro_harness.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* ── Fixture ────────────────────────────────────────────────────────────────
+ *
+ * Minimal TypeScript monorepo layout that triggers the dual-node split:
+ *
+ * packages/widget/src/scroll.ts
+ * — real implementation of alignToEdge(); exports the function
+ *
+ * packages/widget/src/internalConsumer.ts
+ * — imports alignToEdge via RELATIVE path ("./scroll")
+ * — calls alignToEdge(document.createElement('div'))
+ * → CALLS edge targets the IMPLEMENTATION node
+ *
+ * app/types/widget-shim.d.ts
+ * — ambient .d.ts declaration; body-less signature of alignToEdge
+ * — this causes the indexer to create a SECOND (stub) Function node
+ *
+ * app/src/externalConsumer.ts
+ * — imports alignToEdge via PATH ALIAS ("@widget")
+ * — calls alignToEdge(document.querySelector('div'))
+ * → CALLS edge targets the .d.ts STUB node (the alias points there)
+ *
+ * On buggy code: two Function nodes for "alignToEdge"; trace_path picks one;
+ * only one caller is returned.
+ *
+ * Note: The tsconfig.json is included so the indexer can, in principle,
+ * resolve the "@widget" path alias to packages/widget/src. Alias resolution
+ * is best-effort in the current extractor; even without it, if the .d.ts stub
+ * causes a second node, the externalConsumer CALLS edge will point to that
+ * stub node, and the test assertion will correctly turn RED.
+ */
+static const RFile k_files[] = {
+ /* tsconfig: maps @widget alias to packages/widget/src */
+ {
+ "tsconfig.json",
+ "{\n"
+ " \"compilerOptions\": {\n"
+ " \"baseUrl\": \".\",\n"
+ " \"paths\": {\n"
+ " \"@widget\": [\"packages/widget/src\"]\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ },
+
+ /* Real implementation — produces the IMPLEMENTATION Function node */
+ {
+ "packages/widget/src/scroll.ts",
+ "export function alignToEdge(el: HTMLElement): () => void {\n"
+ " return function() { el.scrollIntoView({ block: 'nearest' }); };\n"
+ "}\n"
+ },
+
+ /* Internal consumer: relative import → CALLS edge → IMPLEMENTATION node */
+ {
+ "packages/widget/src/internalConsumer.ts",
+ "import { alignToEdge } from './scroll';\n"
+ "const node = document.createElement('div');\n"
+ "const cleanup = alignToEdge(node);\n"
+ "export { cleanup };\n"
+ },
+
+ /* Ambient .d.ts shim — triggers the SECOND (stub) Function node creation */
+ {
+ "app/types/widget-shim.d.ts",
+ "export function alignToEdge(el: HTMLElement): () => void;\n"
+ },
+
+ /* External consumer: alias import → CALLS edge → .d.ts STUB node */
+ {
+ "app/src/externalConsumer.ts",
+ "import { alignToEdge } from '@widget';\n"
+ "const div = document.querySelector('div') as HTMLElement;\n"
+ "const teardown = alignToEdge(div);\n"
+ "export { teardown };\n"
+ }
+};
+
+/* ─────────────────────────────────────────────────────────────────────────
+ * repro_issue546_dts_split_caller_set
+ *
+ * Precondition A (must be GREEN to prove extraction is working):
+ * At least 1 CALLS edge exists in the graph (the internalConsumer relative
+ * import is the most reliable and must produce a CALLS edge).
+ *
+ * The failing assertion (RED on buggy code):
+ * trace_path for "alignToEdge" with direction="inbound" returns a "callers"
+ * array that contains BOTH "internalConsumer" AND "externalConsumer".
+ *
+ * The test is RED when EITHER name is absent — the partial set is the bug.
+ * ───────────────────────────────────────────────────────────────────────── */
+TEST(repro_issue546_dts_split_caller_set) {
+ RProj lp;
+ cbm_store_t *store = rh_index_files(&lp, k_files,
+ (int)(sizeof(k_files) / sizeof(k_files[0])));
+ ASSERT_NOT_NULL(store);
+
+ /* ── Precondition A: at least one CALLS edge must exist ─────────────
+ * If this fires RED, TS CALLS extraction is broken for this fixture —
+ * that is a pre-existing extraction bug, not #546. The test cannot
+ * distinguish the traversal split without any edges to split across.
+ *
+ * Minimum: 1 (internalConsumer's relative-path import always resolves).
+ * Ideally 2 (externalConsumer's alias import also resolves), but even
+ * 1 is enough to trigger the .d.ts node creation that causes the split.
+ */
+ int calls_count = rh_count_edges(store, lp.project, "CALLS");
+ ASSERT_GT(calls_count, 0); /* precondition — not the #546 assertion */
+
+ /* ── Drive trace_path: inbound callers of "alignToEdge" ─────────────
+ *
+ * Args:
+ * function_name — bare symbol name; the indexer mints node names
+ * matching the short function name for both the impl
+ * and the .d.ts stub node.
+ * project — lp.project (derived from tmpdir)
+ * direction — "inbound": who calls alignToEdge?
+ * depth — 2: one hop is enough (caller → alignToEdge)
+ *
+ * On CORRECT code (fixed):
+ * trace_path unions all Function nodes named "alignToEdge" and returns
+ * callers from all of them:
+ * {"callers":[{"name":"internalConsumer",...},{"name":"externalConsumer",...}]}
+ *
+ * On BUGGY code (current):
+ * trace_path resolves "alignToEdge" to ONE node (first match from
+ * cbm_store_find_nodes_by_name). Only callers whose CALLS edges
+ * point to THAT node appear. The other caller is silently absent.
+ */
+ char args[512];
+ snprintf(args, sizeof(args),
+ "{\"function_name\":\"alignToEdge\","
+ "\"project\":\"%s\","
+ "\"direction\":\"inbound\","
+ "\"depth\":2}",
+ lp.project);
+
+ char *resp = cbm_mcp_handle_tool(lp.srv, "trace_path", args);
+ ASSERT_NOT_NULL(resp);
+
+ /* Symbol must be found — if "function not found" fires, the name lookup
+ * itself has a problem unrelated to #546. */
+ ASSERT_NULL(strstr(resp, "function not found"));
+
+ /* "callers" key must appear (always emitted when direction is inbound). */
+ ASSERT_NOT_NULL(strstr(resp, "\"callers\""));
+
+ /* The callers array must not be empty — at least the internalConsumer
+ * (whose relative-path import is reliably resolved) must appear.
+ *
+ * WHY this might already be RED for #546:
+ * If trace_path selected the .d.ts stub node as BFS root, only
+ * externalConsumer is there; internalConsumer's edge is on the impl
+ * node, so this check fires RED immediately (callers:[]) or wrong name.
+ */
+ ASSERT_NULL(strstr(resp, "\"callers\":[]")); /* empty = traversal totally wrong */
+
+ /* ── PRIMARY ASSERTION: BOTH callers must appear in the response ─────
+ *
+ * "internalConsumer" — imports via relative path, CALLS edge → impl node
+ * "externalConsumer" — imports via alias, CALLS edge → .d.ts stub node
+ *
+ * On CORRECT (fixed) code: trace_path unions both nodes; both names present.
+ *
+ * WHY RED on buggy code:
+ * trace_path selects ONE of the two "alignToEdge" nodes as its BFS root.
+ * Only that node's inbound CALLS edges are traversed. The caller whose
+ * CALLS edge points to the OTHER node is absent from the JSON response.
+ * strstr() for the missing caller name returns NULL, and ASSERT_NOT_NULL
+ * fires → RED.
+ *
+ * Concretely:
+ * — if impl node selected: "externalConsumer" absent → RED
+ * — if .d.ts node selected: "internalConsumer" absent → RED
+ * Either way, exactly one of the two assertions below is RED,
+ * proving the caller set is split and incomplete.
+ */
+ ASSERT_NOT_NULL(strstr(resp, "internalConsumer")); /* relative-import caller */
+ ASSERT_NOT_NULL(strstr(resp, "externalConsumer")); /* alias-import caller */
+
+ free(resp);
+ rh_cleanup(&lp, store);
+ PASS();
+}
+
+/* ── Suite ─────────────────────────────────────────────────────────────── */
+SUITE(repro_issue546) {
+ RUN_TEST(repro_issue546_dts_split_caller_set);
+}
diff --git a/tests/repro/repro_issue571.c b/tests/repro/repro_issue571.c
new file mode 100644
index 000000000..74e2ccdfc
--- /dev/null
+++ b/tests/repro/repro_issue571.c
@@ -0,0 +1,124 @@
+/*
+ * repro_issue571.c — Reproduce-first case for OPEN bug #571.
+ *
+ * BUG: "Project name strips non-ASCII (CJK) characters from path,
+ * resulting in truncated/unrecognizable names"
+ * https://github.com/DeusData/codebase-memory-mcp/issues/571
+ *
+ * ROOT CAUSE (src/pipeline/fqn.c, cbm_project_name_from_path, lines ~341-348):
+ *
+ * The function maps every byte that is not in [A-Za-z0-9._-] to '-':
+ *
+ * unsigned char c = (unsigned char)path[i];
+ * bool safe = (c >= 'a' && c <= 'z') || ... || c == '-';
+ * if (!safe) path[i] = '-';
+ *
+ * UTF-8 encodes each CJK code-point as 3 consecutive bytes, all with
+ * values >= 0x80 (> 127). Every one of those bytes fails the safe-char
+ * test and is rewritten to '-'. The subsequent dash-collapse pass then
+ * folds the run of dashes from a CJK segment into a single '-', and the
+ * leading/trailing trim can erase it entirely if it was the final segment.
+ *
+ * For the exact path from the issue report:
+ * Input: "/Users/yunxin/Desktop/开发/后端/信租风控通后端"
+ * Buggy: "Users-yunxin-Desktop" (all three CJK segments stripped)
+ * Correct: result MUST contain something beyond "Users-yunxin-Desktop"
+ * and MUST NOT be empty. Whether the fix preserves the raw
+ * UTF-8 bytes ("开发"), percent-encodes them ("%E5%BC%80%E5%8F%91"),
+ * or uses another scheme is left to the implementer — this test
+ * pins the invariants:
+ * (a) non-NULL and non-empty result
+ * (b) for a path whose last segment is purely CJK, the output
+ * is LONGER than the result produced from the ASCII-only
+ * prefix of that same path (proving the CJK segment
+ * contributes something rather than collapsing to nothing)
+ * (c) the result is NOT equal to the ASCII-prefix-only slug
+ * "Users-yunxin-Desktop" that the buggy code returns
+ *
+ * EXPECTED vs ACTUAL:
+ * Input path : /Users/yunxin/Desktop/开发/后端/信租风控通后端
+ * Expected : non-empty slug that encodes the CJK components somehow
+ * Actual : "Users-yunxin-Desktop" (CJK segments silently dropped)
+ *
+ * The PRIMARY assertion — ASSERT_STR_NEQ(name, ascii_only_slug) — is RED
+ * on unpatched code because the buggy function returns exactly
+ * "Users-yunxin-Desktop", which IS the ascii_only_slug.
+ *
+ * DECLARATION:
+ * char *cbm_project_name_from_path(const char *abs_path);
+ * declared in <pipeline/pipeline.h>
+ */
+
+#include "test_framework.h"
+#include <pipeline/pipeline.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/* ── Test ─────────────────────────────────────────────────────────── */
+
+/*
+ * Single test with three layered assertions (all RED on unpatched code):
+ *
+ * 1. Result is non-NULL and non-empty (the fallback "root" would be wrong
+ * too, but the primary bug is the silent CJK strip).
+ * 2. Result is NOT equal to the ASCII-prefix-only slug. On buggy code the
+ * function returns exactly that slug, so this fires.
+ * 3. Result is strictly longer than the ASCII-prefix slug. Any scheme that
+ * preserves CJK (raw UTF-8, percent-encoding, or even a hex dump) must
+ * produce a longer string than the stripped version.
+ */
+TEST(repro_issue571_cjk_project_name) {
+ /*
+ * Exact path from the issue report. The last three path segments
+ * (开发, 后端, 信租风控通后端) are all CJK-only; none contains any
+ * ASCII byte. The ASCII-only prefix ends at "Desktop".
+ */
+ static const char *cjk_path =
+ "/Users/yunxin/Desktop/\xe5\xbc\x80\xe5\x8f\x91"
+ "/\xe5\x90\x8e\xe7\xab\xaf"
+ "/\xe4\xbf\xa1\xe7\xa7\x9f\xe9\xa3\x8e\xe6\x8e\xa7\xe9\x80\x9a\xe5\x90\x8e\xe7\xab\xaf";
+ /*
+ * UTF-8 bytes spelled out above:
+ * 开发 = U+5F00 U+53D1 = \xe5\xbc\x80 \xe5\x8f\x91
+ * 后端 = U+540E U+7AEF = \xe5\x90\x8e \xe7\xab\xaf
+ * 信租风控通后端 = U+4FE1 U+79DF U+98CE U+63A7 U+901A U+540E U+7AEF
+ * = \xe4\xbf\xa1 \xe7\xa7\x9f \xe9\xa3\x8e
+ * \xe6\x8e\xa7 \xe9\x80\x9a \xe5\x90\x8e \xe7\xab\xaf
+ *
+ * The ASCII-only prefix slug produced by the BUGGY implementation:
+ * "Users-yunxin-Desktop"
+ * This string is used in assertions 2 and 3 to prove the CJK segments
+ * were silently erased.
+ */
+ static const char *ascii_only_slug = "Users-yunxin-Desktop";
+
+ char *name = cbm_project_name_from_path(cjk_path);
+
+ /* ── Assertion 1: result must exist and be non-empty ─────────── */
+ /* Even on buggy code this passes (the function returns the ASCII
+ * prefix rather than NULL or "root"), so it serves only as a
+ * pre-condition that the function did not crash or return NULL. */
+ ASSERT_NOT_NULL(name);
+ ASSERT_TRUE(strlen(name) > 0);
+
+ /* ── Assertion 2 (PRIMARY RED): CJK segments must not vanish ─── */
+ /* On buggy code name == "Users-yunxin-Desktop" == ascii_only_slug.
+ * After a correct fix name will encode the CJK components somehow
+ * and therefore differ from the stripped ASCII slug. */
+ ASSERT_STR_NEQ(name, ascii_only_slug);
+
+ /* ── Assertion 3 (SECONDARY RED): CJK contribution lengthens result */
+ /* Any faithful encoding of the CJK bytes (raw UTF-8, percent-encode,
+ * hex) is longer than the ASCII-only slug. On buggy code
+ * strlen(name) == strlen(ascii_only_slug) == 20, so this also FAILS. */
+ ASSERT_TRUE(strlen(name) > strlen(ascii_only_slug));
+
+ free(name);
+ PASS();
+}
+
+/* ── Suite ────────────────────────────────────────────────────────── */
+SUITE(repro_issue571) {
+ RUN_TEST(repro_issue571_cjk_project_name);
+}
diff --git a/tests/repro/repro_main.c b/tests/repro/repro_main.c
index eba0a5a89..2ebb4a6ba 100644
--- a/tests/repro/repro_main.c
+++ b/tests/repro/repro_main.c
@@ -35,6 +35,9 @@ extern void suite_repro_issue382(void);
extern void suite_repro_issue408(void);
extern void suite_repro_issue56(void);
extern void suite_repro_issue480(void);
+extern void suite_repro_issue571(void);
+extern void suite_repro_issue523(void);
+extern void suite_repro_issue546(void);
int main(void) {
/* Unbuffered: a reproduction may crash/_exit (or a sanitizer may _exit on a
@@ -57,6 +60,9 @@ int main(void) {
RUN_SUITE(repro_issue408);
RUN_SUITE(repro_issue56);
RUN_SUITE(repro_issue480);
+ RUN_SUITE(repro_issue571);
+ RUN_SUITE(repro_issue523);
+ RUN_SUITE(repro_issue546);
TEST_SUMMARY();
}