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
test(repro): cross-file + trace reproductions for #408, #56, #480
Martin Vogela84c59c27ae4
diff --git a/Makefile.cbm b/Makefile.cbmindex 99d2956fd..e0b395bbe 100644--- a/Makefile.cbm+++ b/Makefile.cbm@@ -397,7 +397,10 @@ TEST_REPRO_SRCS = \tests/repro/repro_extraction.c \tests/repro/repro_issue495.c \tests/repro/repro_issue521.c \- tests/repro/repro_issue382.c+ tests/repro/repro_issue382.c \+ tests/repro/repro_issue408.c \+ tests/repro/repro_issue56.c \+ tests/repro/repro_issue480.cALL_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_issue408.c b/tests/repro/repro_issue408.cnew file mode 100644index 000000000..f7bf13aa0--- /dev/null+++ b/tests/repro/repro_issue408.c@@ -0,0 +1,170 @@+/*+ * repro_issue408.c — Reproduce-first case for OPEN bug #408.+ *+ * Issue #408: "package.json `workspaces` cross-repo IMPORTS still produce+ * zero edges"+ *+ * Root cause (pass_pkgmap.c / pipeline.c):+ * In a Yarn/Lerna-style JS/TS monorepo, `packages/b` imports a sibling by+ * its declared package name (`import { x } from '@org/a'`). pass_pkgmap.c+ * is supposed to:+ * 1. Walk the repo filesystem for package.json manifests (cbm_pkgmap_scan_repo).+ * 2. Parse each sibling package.json, mapping its `"name"` field to its+ * entry-point QN (parse_package_json → pkg_entries_push).+ * 3. On import resolution (cbm_pipeline_resolve_module), perform an exact+ * lookup of `"@org/a"` in the pkgmap hash table to obtain the sibling's+ * QN, then produce an IMPORTS edge to that node.+ *+ * The reporter's debug trace (macOS arm64, v0.7.0) shows that the pkgmap+ * pass never emits any `pkgmap.*` log lines:+ * pipeline.done nodes=12 edges=9 elapsed_ms=71+ * — zero IMPORTS edges despite a bare-specifier workspace import. The+ * maintainer confirmed: on macOS/Linux cbm_pkgmap_scan_repo may resolve+ * workspace names at the manifest-parse level (cbm_pkgmap_try_parse), but+ * the resolved entry-QN is never matched against the in-graph node produced+ * by indexing `packages/a/index.js`. The mismatch means the exact-lookup+ * in cbm_pipeline_resolve_module (step 3) silently falls through to+ * default (unresolved) QN resolution, and no cross-package IMPORTS edge is+ * ever produced.+ *+ * Expected (correct) behaviour:+ * Indexing a minimal monorepo:+ * root/package.json { "workspaces": ["packages/*"] }+ * 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" }+ * packages/b/index.js import { fromA } from '@org/a';+ * export function useA() { return fromA(); }+ * must produce AT LEAST ONE IMPORTS edge in the graph.+ * (The only possible target of `import … from '@org/a'` is the sibling+ * package — there are no relative imports in this fixture.)+ *+ * Actual (buggy) behaviour:+ * rh_count_edges(store, project, "IMPORTS") == 0+ * The assertion ASSERT_GTE(imports, 1) FAILS → RED.+ *+ * Why STRONGER than the existing weak test+ * (`contract_edge_workspaces_imports_issue408` in tests/test_lang_contract.c):+ *+ * The existing test asserts `edge_present(f, 5, "IMPORTS", 1)`, which+ * succeeds whenever ANY IMPORTS edge exists in the indexed project. In the+ * original test_lang_contract.c fixture this is satisfied trivially by a+ * relative import or a self-import resolved within a single package — the+ * cross-package bare-specifier resolution is never exercised.+ *+ * This repro fixture is DESIGNED so the only source of IMPORTS edges is the+ * bare-specifier cross-package import in packages/b/index.js:+ * import { fromA } from '@org/a';+ * Neither packages/a/index.js nor packages/b/index.js contains any+ * relative import ("./…") or intra-package import. Therefore:+ * rh_count_edges(..., "IMPORTS") >= 1+ * is ONLY satisfiable if the cross-package workspace resolution succeeded.+ * On current (buggy) code this count is 0, so the assertion is RED.+ *+ * In addition, the fixture omits `"dependencies"` from packages/b/package.json+ * on purpose: workspace resolution must be driven purely by the monorepo+ * `"workspaces"` glob, not by an explicit `dependencies` field — matching+ * the reporter's minimal repro from the issue comments.+ */++#include "test_framework.h"+#include "repro_harness.h"++/* ── Test ──────────────────────────────────────────────────────────── */++/*+ * repro_issue408_workspace_crosspkg_import+ *+ * Indexes a minimal Yarn-style JS monorepo where packages/b imports+ * sibling packages/a by its package.json `"name"` (@org/a). This is+ * a PURE CROSS-PACKAGE bare-specifier import: no relative imports exist+ * anywhere in the fixture. Therefore the only possible source of an+ * IMPORTS edge is the workspace-resolved @org/a reference.+ *+ * RED if:+ * • rh_count_edges(store, project, "IMPORTS") == 0+ * (workspace resolution did not produce a cross-package IMPORTS edge)+ */+TEST(repro_issue408_workspace_crosspkg_import) {+ /*+ * Fixture layout mirrors the reporter's /tmp/cbm-issue408-repro tree+ * (issue #408 comment, macOS arm64 canonical repro). Five files:+ *+ * package.json — root workspace manifest; workspaces glob+ * packages/a/package.json — sibling A's manifest; name = "@org/a"+ * packages/a/index.js — sibling A; exports fromA (no imports)+ * packages/b/package.json — sibling B's manifest; name = "@org/b"+ * packages/b/index.js — sibling B; bare-specifier import of @org/a+ *+ * Note: packages/b/package.json deliberately omits "dependencies" so+ * that workspace resolution cannot be driven by that field.+ *+ * Note: neither .js file contains any relative import; the ONLY import+ * statement is `import { fromA } from '@org/a'` in packages/b/index.js.+ * Therefore rh_count_edges(..., "IMPORTS") >= 1 is satisfied ONLY if+ * the cross-package workspace bare-specifier resolution worked.+ */+ static const RFile files[] = {+ /* Root workspace manifest */+ {+ "package.json",+ "{\"name\":\"monorepo-root\",\"private\":true,"+ "\"workspaces\":[\"packages/*\"]}\n"+ },+ /* Sibling A — the imported package */+ {+ "packages/a/package.json",+ "{\"name\":\"@org/a\",\"version\":\"1.0.0\","+ "\"main\":\"index.js\"}\n"+ },+ {+ "packages/a/index.js",+ "export function fromA() {\n"+ " return 1;\n"+ "}\n"+ },+ /* Sibling B — the importing package; NO relative imports */+ {+ "packages/b/package.json",+ "{\"name\":\"@org/b\",\"version\":\"1.0.0\","+ "\"main\":\"index.js\"}\n"+ },+ {+ "packages/b/index.js",+ "import { fromA } from '@org/a';\n"+ "\n"+ "export function useA() {\n"+ " return fromA();\n"+ "}\n"+ }+ };++ RProj lp;+ cbm_store_t *store = rh_index_files(&lp, files, 5);+ ASSERT_NOT_NULL(store);++ /*+ * Count ALL IMPORTS edges in the project graph.+ *+ * Because this fixture contains ONLY one import statement and it is a+ * bare-specifier workspace reference (`import { fromA } from '@org/a'`),+ * the count is:+ * ≥ 1 → cross-package workspace resolution worked (correct behaviour)+ * 0 → workspace resolution is broken (bug #408, RED)+ *+ * On current (unfixed) code, pass_pkgmap resolves "@org/a" to a QN that+ * does not match any graph node, so cbm_pipeline_resolve_import_node+ * falls through to default resolution, producing zero IMPORTS edges.+ * This assertion therefore FAILS → RED.+ */+ int imports = rh_count_edges(store, lp.project, "IMPORTS");+ ASSERT_GTE(imports, 1);++ rh_cleanup(&lp, store);+ PASS();+}++/* ── Suite ──────────────────────────────────────────────────────────── */+SUITE(repro_issue408) {+ RUN_TEST(repro_issue408_workspace_crosspkg_import);+}diff --git a/tests/repro/repro_issue480.c b/tests/repro/repro_issue480.cnew file mode 100644index 000000000..3ba9a1492--- /dev/null+++ b/tests/repro/repro_issue480.c@@ -0,0 +1,173 @@+/*+ * repro_issue480.c — Reproduce-first case for OPEN bug #480.+ *+ * Issue: #480 — "trace_path returns empty for all functions despite+ * traversable CALLS edges (v0.8.1, macOS arm64)"+ *+ * Root cause (identified by maintainer DeusData + reporter halindrome):+ * handle_trace_call_path() calls cbm_store_find_nodes_by_name() to locate+ * the start node for BFS. On the affected build, the name-to-node lookup+ * returns node_count == 0 for EVERY function name — even names that the+ * graph clearly contains (confirmed by query_graph Cypher returning the same+ * function with 5–8 inbound CALLS edges). The fallback to+ * cbm_store_find_node_by_qn() also returns nothing, so the handler exits+ * with a "function not found" error OR (when the node IS found by name)+ * the BFS start-node id does not match any edge endpoint stored in the+ * graph, so cbm_store_bfs() returns visited_count == 0 and the "callers"+ * / "callees" JSON arrays are serialised empty.+ *+ * The split: query_graph Cypher (direct SQL) traverses the same edges+ * correctly, while trace_path (BFS via start-node id) yields nothing.+ * This isolates the bug to trace_path's own start-node lookup or to how+ * the resolved node id is passed to cbm_store_bfs(), NOT to edge creation.+ *+ * Expected (correct) behaviour:+ * After indexing a two-function Python file where caller() calls callee(),+ * trace_path for "callee" with direction="inbound" must return a non-empty+ * "callers" array that contains a node named "caller".+ *+ * Actual (buggy) behaviour:+ * trace_path returns {"function":"callee","direction":"inbound","callers":[]}+ * — an empty "callers" array — even though CALLS edges exist in the graph+ * and are walkable via query_graph.+ *+ * Why RED on current code:+ * The precondition assertion (CALLS edges > 0) passes because edge creation+ * is correct. The subsequent assertion that resp contains the string+ * "\"caller\"" (the caller function's name embedded in the callers array)+ * FAILS because cbm_store_bfs() finds no hops from the resolved start node.+ *+ * How this isolates the traversal bug from an extraction bug:+ * If CALLS edges were the problem, rh_count_edges(store, …, "CALLS") would+ * return 0 and the ASSERT_GT precondition would fire RED — visibly flagging+ * an extraction failure instead. By asserting the precondition GREEN and+ * the trace_path result RED, we prove the edges exist and the fault lies+ * exclusively in trace_path's traversal layer.+ *+ * Fix location (not implemented here):+ * cbm_store_find_nodes_by_name() or cbm_store_bfs() in+ * src/store/store.c — the node id returned by name lookup must match+ * the source/target ids stored in the edges table.+ */++#include <foundation/compat.h>+#include "test_framework.h"+#include "repro_harness.h"++#include <string.h>+#include <stdlib.h>+#include <stdio.h>++/* ── Fixture ────────────────────────────────────────────────────────────────+ *+ * Two Python functions in one file:+ *+ * def callee():+ * return 42+ *+ * def caller():+ * return callee()+ *+ * Python has proven reliable CALLS extraction (test_extraction.c:python_calls+ * asserts calls.count > 0 for a simpler fixture; the integration suite's+ * main.py fixture yields CALLS edges that are visible via query_graph).+ * caller() → callee() is a simple, unambiguous intra-file call: the extractor+ * sees exactly one callee() call expression inside caller(), so the graph+ * must have ≥ 1 CALLS edge after indexing.+ */+static const RFile k_files[] = {+ {+ "main.py",+ "def callee():\n"+ " return 42\n"+ "\n"+ "def caller():\n"+ " return callee()\n"+ }+};++/* ─────────────────────────────────────────────────────────────────────────+ * repro_issue480_trace_path_nonempty_with_calls+ *+ * Precondition (must be GREEN to prove this is a traversal bug):+ * rh_count_edges(store, project, "CALLS") > 0+ *+ * The failing assertion (RED on buggy code):+ * The "callers" array in the trace_path response is non-empty and contains+ * the string "caller" (the name of the caller function).+ * ───────────────────────────────────────────────────────────────────────── */+TEST(repro_issue480_trace_path_nonempty_with_calls) {+ 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: extraction must have produced ≥ 1 CALLS edge ──────+ * If this fires RED, the fixture or language has an extraction bug —+ * that is a different problem from #480. Switch to a different+ * language fixture (e.g. Go utils.go with Multiply→Add) in that case. */+ int calls_count = rh_count_edges(store, lp.project, "CALLS");+ ASSERT_GT(calls_count, 0);++ /* ── Invoke trace_path for "callee" with direction="inbound" ─────────+ *+ * Args match the trace_path schema (required: function_name, project):+ * function_name — bare name "callee"; also tested by the reporter with+ * the fully-qualified name, both yield empty on buggy code+ * project — lp.project (derived from tmpdir by cbm_project_name_from_path)+ * direction — "inbound": ask for callers of callee()+ * depth — 2: enough to reach one hop (caller → callee)+ *+ * Expected response shape (correct):+ * {"function":"callee","direction":"inbound","callers":[{"name":"caller",...},...]}+ *+ * Buggy response shape:+ * {"function":"callee","direction":"inbound","callers":[]}+ * (or: {"error":"function not found",...} if the name lookup fails entirely)+ */+ char args[512];+ snprintf(args, sizeof(args),+ "{\"function_name\":\"callee\","+ "\"project\":\"%s\","+ "\"direction\":\"inbound\","+ "\"depth\":2}",+ lp.project);++ char *resp = cbm_mcp_handle_tool(lp.srv, "trace_path", args);+ ASSERT_NOT_NULL(resp);++ /* The response must NOT be a "function not found" error.+ * If the name lookup itself fails, this fires first and pinpoints the+ * start-node lookup as the breakage site. */+ ASSERT_NULL(strstr(resp, "function not found"));++ /* The "callers" key must appear — it is always emitted when direction+ * includes "inbound" (even as an empty array), confirming we reached+ * the BFS step. */+ ASSERT_NOT_NULL(strstr(resp, "\"callers\""));++ /* The "callers" array must be NON-EMPTY: the string "caller" must+ * appear inside the response as the name of the calling function.+ *+ * WHY RED on buggy code:+ * cbm_store_bfs() starts from nodes[sel].id but that id does not+ * resolve to any edge endpoint in the graph, so visited_count == 0.+ * bfs_to_json_array() serialises an empty JSON array [].+ * strstr(resp, "\"caller\"") returns NULL → ASSERT_NOT_NULL fails.+ *+ * The two-part check below distinguishes the two bug symptoms:+ * 1. empty array → "callers\":[]" present, no "\"caller\"" entry+ * 2. name missing → "callers" array populated with wrong names+ * Either way the final assertion is the one that must turn RED. */+ ASSERT_NULL(strstr(resp, "\"callers\":[]")); /* empty array = traversal bug */+ ASSERT_NOT_NULL(strstr(resp, "\"caller\"")); /* caller name in results */++ free(resp);+ rh_cleanup(&lp, store);+ PASS();+}++/* ── Suite ─────────────────────────────────────────────────────────────── */+SUITE(repro_issue480) {+ RUN_TEST(repro_issue480_trace_path_nonempty_with_calls);+}diff --git a/tests/repro/repro_issue56.c b/tests/repro/repro_issue56.cnew file mode 100644index 000000000..4da2938df--- /dev/null+++ b/tests/repro/repro_issue56.c@@ -0,0 +1,232 @@+/*+ * repro_issue56.c — Reproduce-first case for OPEN bug #56.+ *+ * Bug #56: "Cross-crate call graphs stop at boundaries" (Rust)+ *+ * ROOT CAUSE (pipeline / Rust LSP path):+ * The tree-sitter-only Rust extractor has no access to Cargo metadata+ * at extraction time, so when it sees `crate_a::helper()` inside+ * crate_b, it records a raw call-site for the path but has no registry+ * entry for `crate_a::helper` — only the definitions in the *same file*+ * were seeded. The LSP resolver therefore cannot match the call-site to+ * a callee QN across the crate boundary, and the resulting+ * CBMResolvedCall is either absent or marked with low confidence and+ * discarded. When the pipeline writes graph edges for this project, no+ * CALLS edge is minted for the cross-crate call — the call graph stops+ * at the crate edge.+ *+ * v0.8.1 added a hybrid-LSP Rust path that "materially improves" this+ * (issue comment, maintainer 2026-06-25), but the reporter was asked to+ * retest; the issue remains OPEN because no retest confirming resolution+ * was provided. The workspace-member wiring test+ * (rustlsp_extra_cargo_wires_workspace_member in test_rust_lsp.c) only+ * exercises the *single-file LSP* layer with a manually-parsed manifest;+ * it does NOT verify that the full production pipeline (rh_index_files →+ * cbm_pipeline → graph store) persists a cross-crate CALLS edge for a+ * real multi-file Cargo workspace fixture. That gap is what this test+ * fills.+ *+ * FIXTURE:+ * A minimal Cargo workspace with two crates:+ *+ * [workspace Cargo.toml] — workspace root, declares members+ * crate_a/Cargo.toml — library crate "crate_a"+ * crate_a/src/lib.rs — exposes `pub fn helper() {}`+ * crate_b/Cargo.toml — binary crate "crate_b", depends on crate_a+ * crate_b/src/main.rs — calls `crate_a::helper()` from `fn run()`+ *+ * The ONLY possible cross-file CALLS edge in this fixture is:+ * crate_b::run → crate_a::helper+ * (there are no intra-crate calls because `helper` is defined in crate_a+ * and called from crate_b).+ *+ * EXPECTED (correct) behaviour:+ * After indexing the workspace through the production MCP pipeline, the+ * graph store must contain at least one CALLS edge whose callee QN+ * resolves into the `crate_a` namespace. Specifically:+ * rh_count_edges(store, project, "CALLS") >= 1+ * and the single edge present crosses the crate boundary+ * (crate_b caller → crate_a callee).+ *+ * ACTUAL (buggy) behaviour:+ * The pipeline extracts both files, but the cross-crate path+ * `crate_a::helper` in crate_b/src/main.rs is not resolved to a graph+ * node in crate_a because Cargo workspace member metadata is not+ * plumbed into the per-file extraction phase. Result: zero CALLS edges+ * in the store. The ASSERT_GTE(calls, 1) below FAILS → RED.+ *+ * WHY THIS IS RED ON CURRENT CODE (even post-v0.8.1):+ * The rustlsp_extra_cargo_wires_workspace_member unit test exercises only+ * the LSP layer (cbm_run_rust_lsp_with_manifest called with a parsed+ * CBMCargoManifest) and confirms the resolver *can* route+ * `engine::boot()` to `engine.boot` when given the manifest explicitly.+ * BUT: the production pipeline's per-file extraction path+ * (cbm_extract_file → cbm_run_rust_lsp) does NOT receive a pre-parsed+ * workspace manifest — it only gets the individual file's content.+ * Cross-crate definition seeding (registering crate_a's functions as+ * project-level defs so crate_b's calls can match them) requires the+ * pipeline to:+ * 1. parse the workspace Cargo.toml before per-file extraction,+ * 2. index all member crates together to build a cross-crate def+ * registry, and+ * 3. pass that combined registry into each per-file cbm_extract_file+ * call (or run a post-extraction link pass).+ * Steps 2–3 are not implemented in the production pipeline as of v0.8.1;+ * the LSP manifests are only used in the unit-test call path. Therefore+ * a real workspace indexed through index_repository produces 0 CALLS+ * edges for cross-crate calls, and this test remains RED.+ *+ * UNCERTAINTY:+ * If v0.8.1's hybrid-LSP path already plumbs the workspace manifest into+ * the production pipeline, this test may go GREEN unexpectedly — which+ * would be the correct outcome (bug fixed). The test is intentionally+ * written to go GREEN when the fix lands, so it doubles as the permanent+ * regression guard.+ */++#include "test_framework.h"+#include "repro_harness.h"++#include <string.h>++/* ── Test ───────────────────────────────────────────────────────────────── */++/*+ * repro_issue56_cross_crate_calls+ *+ * Index a minimal two-crate Cargo workspace through the production+ * rh_index_files pipeline and assert that the cross-crate CALLS edge+ * (crate_b::run → crate_a::helper) is present in the graph store.+ *+ * RED condition:+ * rh_count_edges(store, project, "CALLS") == 0 (no edge was minted).+ *+ * This test is RED on current code because the production pipeline does+ * not plumb workspace-member metadata into per-file Rust extraction, so+ * cross-crate call resolution always drops to zero edges.+ */+TEST(repro_issue56_cross_crate_calls) {+ /*+ * Workspace root Cargo.toml — declares two members so the pipeline+ * (and any cargo-metadata-aware path) can discover the crate layout.+ */+ static const char workspace_toml[] =+ "[workspace]\n"+ "members = [\"crate_a\", \"crate_b\"]\n"+ "resolver = \"2\"\n";++ /*+ * crate_a: a library crate that exposes a single public function.+ * Path: crate_a/Cargo.toml+ */+ static const char crate_a_toml[] =+ "[package]\n"+ "name = \"crate_a\"\n"+ "version = \"0.1.0\"\n"+ "edition = \"2021\"\n";++ /*+ * crate_a/src/lib.rs — the callee lives here.+ * There are NO calls inside this file, so any CALLS edge in the graph+ * MUST cross the crate boundary.+ */+ static const char crate_a_lib_rs[] =+ "/// A simple helper function exposed by crate_a.\n"+ "pub fn helper() {\n"+ " // intentionally empty — we just need the definition\n"+ "}\n";++ /*+ * crate_b: a binary crate that depends on crate_a.+ * Path: crate_b/Cargo.toml+ */+ static const char crate_b_toml[] =+ "[package]\n"+ "name = \"crate_b\"\n"+ "version = \"0.1.0\"\n"+ "edition = \"2021\"\n"+ "\n"+ "[dependencies]\n"+ "crate_a = { path = \"../crate_a\" }\n";++ /*+ * crate_b/src/main.rs — the caller.+ * `run()` calls `crate_a::helper()` across the crate boundary.+ * This is the only call-site in the entire fixture.+ */+ static const char crate_b_main_rs[] =+ "fn run() {\n"+ " crate_a::helper();\n"+ "}\n"+ "\n"+ "fn main() {\n"+ " run();\n"+ "}\n";++ static const RFile files[] = {+ { "Cargo.toml", workspace_toml },+ { "crate_a/Cargo.toml", crate_a_toml },+ { "crate_a/src/lib.rs", crate_a_lib_rs },+ { "crate_b/Cargo.toml", crate_b_toml },+ { "crate_b/src/main.rs", crate_b_main_rs },+ };+ static const int nfiles = (int)(sizeof(files) / sizeof(files[0]));++ RProj lp;+ cbm_store_t *store = rh_index_files(&lp, files, nfiles);+ ASSERT_NOT_NULL(store);++ /*+ * Count all CALLS edges in the project graph.+ *+ * The fixture is constructed so that the ONLY possible CALLS edge is+ * the cross-crate one:+ *+ * crate_b::run → crate_a::helper (cross-crate, the bug)+ * crate_b::main → crate_b::run (intra-crate, should also+ * resolve, but is secondary)+ *+ * On FIXED code: calls >= 1 (at minimum the cross-crate edge exists)+ * On BUGGY code: calls == 0 (cross-crate resolution fails; the+ * intra-crate main→run call may or may not+ * resolve depending on whether single-file+ * intra-crate calls work — see note below)+ *+ * NOTE on the intra-crate main→run edge:+ * `main` and `run` live in the same file (crate_b/src/main.rs).+ * Single-file intra-crate calls ARE expected to work even on buggy+ * code (they don't need cross-crate metadata). If the intra-crate+ * edge is minted, the test would pass trivially without proving the+ * cross-crate fix. To make the assertion specifically about the+ * cross-crate case, we assert calls >= 2 — requiring BOTH the+ * intra-crate main→run AND the cross-crate run→crate_a::helper edge.+ * If only the intra-crate edge works, calls == 1, and this assertion+ * still FAILS (RED), which is the correct signal: cross-crate+ * resolution is still missing.+ *+ * Rationale for the ">= 2" threshold:+ * calls == 0 → both intra- and cross-crate broken (very buggy)+ * calls == 1 → only intra-crate works; cross-crate still broken (RED)+ * calls >= 2 → both edges present; bug is fixed (GREEN)+ */+ int calls = rh_count_edges(store, lp.project, "CALLS");++ /*+ * PRIMARY ASSERTION — RED if cross-crate CALLS edge is absent.+ *+ * On current (buggy) code: cross-crate resolution drops the+ * crate_a::helper call, so `calls` is 0 or 1 (at most the intra-crate+ * main→run edge). Either way, this ASSERT_GTE fails → RED.+ *+ * On fixed code: both edges are minted → calls >= 2 → GREEN.+ */+ ASSERT_GTE(calls, 2);++ rh_cleanup(&lp, store);+ PASS();+}++/* ── Suite ──────────────────────────────────────────────────────────────── */+SUITE(repro_issue56) {+ RUN_TEST(repro_issue56_cross_crate_calls);+}diff --git a/tests/repro/repro_main.c b/tests/repro/repro_main.cindex babf1bb03..eba0a5a89 100644--- a/tests/repro/repro_main.c+++ b/tests/repro/repro_main.c@@ -32,6 +32,9 @@ extern void suite_repro_extraction(void);extern void suite_repro_issue495(void);extern void suite_repro_issue521(void);extern void suite_repro_issue382(void);+extern void suite_repro_issue408(void);+extern void suite_repro_issue56(void);+extern void suite_repro_issue480(void);int main(void) {/* Unbuffered: a reproduction may crash/_exit (or a sanitizer may _exit on a@@ -51,6 +54,9 @@ int main(void) {RUN_SUITE(repro_issue495);RUN_SUITE(repro_issue521);RUN_SUITE(repro_issue382);+ RUN_SUITE(repro_issue408);+ RUN_SUITE(repro_issue56);+ RUN_SUITE(repro_issue480);TEST_SUMMARY();}