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): crash + trace + gitignore reproductions for #627, #514, #510
Martin Vogel2534f3bb89c8
diff --git a/Makefile.cbm b/Makefile.cbmindex abb2d0224..02060f0c0 100644--- a/Makefile.cbm+++ b/Makefile.cbm@@ -403,7 +403,10 @@ TEST_REPRO_SRCS = \tests/repro/repro_issue480.c \tests/repro/repro_issue571.c \tests/repro/repro_issue523.c \- tests/repro/repro_issue546.c+ tests/repro/repro_issue546.c \+ tests/repro/repro_issue627.c \+ tests/repro/repro_issue514.c \+ tests/repro/repro_issue510.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_issue510.c b/tests/repro/repro_issue510.cnew file mode 100644index 000000000..a2e840ca7--- /dev/null+++ b/tests/repro/repro_issue510.c@@ -0,0 +1,133 @@+/*+ * repro_issue510.c — Reproduce-first case for OPEN bug #510.+ *+ * Issue: #510 — ".gitignore (non repo root) gaps and overrides"+ *+ * Root cause (discovered via discover.c):+ * cbm_discover_ex() loads the root .gitignore ONLY when a .git directory is+ * present at repo_path (is_git_repo gate, ~line 777). For a non-git-root+ * call (e.g. indexing pkg/ directly), is_git_repo = false and gitignore =+ * NULL. The nested-gitignore fallback also fails: try_load_nested_gitignore()+ * has the guard "if (frame->local_gi || frame->prefix[0] == '\0') return NULL"+ * (line 630). The initial walk frame always has prefix == "" (empty), so+ * prefix[0] == '\0' is true and the function returns NULL without even+ * stat-ing the .gitignore file. Result: the .gitignore sitting at the root+ * of the indexed directory is completely silently ignored, so every file+ * that it excludes gets indexed anyway.+ *+ * Expected (correct) behaviour:+ * When cbm_discover() is called on a directory that is NOT a git repo root+ * but DOES contain a .gitignore, that .gitignore MUST be honoured.+ * A file matching a pattern in that .gitignore must NOT appear in the+ * discovered file list.+ *+ * Actual (buggy) behaviour:+ * cbm_discover() returns the excluded file as a normal discovered file+ * because try_load_nested_gitignore() refuses to load .gitignore when+ * the walk frame prefix is empty (i.e. the indexed directory itself).+ *+ * Why RED on current code:+ * The fixture creates a directory WITHOUT a .git sub-directory (so the+ * is_git_repo gate stays false), writes a .gitignore containing "secret.py",+ * and writes secret.py + keep.py. After cbm_discover(), the loop below+ * checks that secret.py is NOT in the result. On the current code the+ * check FAILS because secret.py is present in the discovered list.+ *+ * Fix location (not implemented here):+ * src/discover/discover.c, function try_load_nested_gitignore():+ * Remove (or invert) the "frame->prefix[0] == '\0'" early-return guard so+ * that the function also loads .gitignore from the root indexed directory.+ * Additionally, cbm_discover_ex() should attempt to load a root .gitignore+ * even when the directory is not a git repo.+ */+#include <foundation/compat.h>+#include "test_framework.h"+#include "test_helpers.h"+#include "discover/discover.h"++#include <string.h>+#include <stdlib.h>+#include <stdio.h>++/* ── Fixture ────────────────────────────────────────────────────────────────+ *+ * Directory layout (NOT a git repo — no .git/ subdir):+ *+ * <tmpdir>/+ * .gitignore <- contains "secret.py"+ * secret.py <- should be EXCLUDED by .gitignore+ * keep.py <- should be INCLUDED (not matched by any pattern)+ *+ * Precondition check (to isolate the discovery layer from extraction):+ * The root .gitignore is parseable and matches "secret.py".+ * cbm_gitignore_matches(gi, "secret.py", false) == true.+ * This GREEN precondition proves the matcher itself is correct; if it+ * turns RED instead, the bug is in the matcher, not discovery.+ *+ * Primary assertion (RED on buggy code):+ * After cbm_discover(), "secret.py" must NOT appear in the file list.+ *+ * The test does NOT create a .git directory, mirroring the exact scenario+ * from issue #510 Repro 1-A: indexing a sub-package directly rather than+ * the repo root.+ */+TEST(repro_issue510_nested_gitignore_honored) {+ /* --- set up temp directory --- */+ char tmpdir[256];+ snprintf(tmpdir, sizeof(tmpdir), "%s/cbm_repro510_XXXXXX", cbm_tmpdir());+ ASSERT_NOT_NULL(cbm_mkdtemp(tmpdir));++ /* Write fixture files */+ ASSERT_EQ(0, th_write_file(TH_PATH(tmpdir, ".gitignore"), "secret.py\n"));+ ASSERT_EQ(0, th_write_file(TH_PATH(tmpdir, "secret.py"),+ "def secret(): return \"SECRET_TOKEN_111\"\n"));+ ASSERT_EQ(0, th_write_file(TH_PATH(tmpdir, "keep.py"),+ "def ok(): return 1\n"));++ /* --- Precondition: matcher itself handles the pattern correctly --- */+ cbm_gitignore_t *gi = cbm_gitignore_parse("secret.py\n");+ ASSERT_NOT_NULL(gi);+ /* If this assertion fails, the bug is in the gitignore matcher, not+ * in discovery — a different bug, not #510. */+ ASSERT_TRUE(cbm_gitignore_matches(gi, "secret.py", false));+ cbm_gitignore_free(gi);++ /* --- Run discovery on the directory (no .git present) --- */+ cbm_file_info_t *files = NULL;+ int count = 0;+ int rc = cbm_discover(tmpdir, NULL, &files, &count);+ ASSERT_EQ(0, rc);++ /* --- Primary assertion: secret.py must NOT be discovered --- */+ bool secret_found = false;+ bool keep_found = false;+ for (int i = 0; i < count; i++) {+ if (strcmp(files[i].rel_path, "secret.py") == 0) {+ secret_found = true;+ }+ if (strcmp(files[i].rel_path, "keep.py") == 0) {+ keep_found = true;+ }+ }+ cbm_discover_free(files, count);+ th_rmtree(tmpdir);++ /* keep.py is a valid Python file and MUST be discovered. */+ ASSERT_TRUE(keep_found);++ /*+ * RED assertion: secret.py matches the root .gitignore pattern and+ * must be excluded. On buggy code try_load_nested_gitignore() skips+ * the root frame (prefix == ""), so secret.py IS discovered and this+ * ASSERT_FALSE fires RED.+ */+ ASSERT_FALSE(secret_found);++ PASS();+}++/* ── Suite ──────────────────────────────────────────────────────────────── */++SUITE(repro_issue510) {+ RUN_TEST(repro_issue510_nested_gitignore_honored);+}diff --git a/tests/repro/repro_issue514.c b/tests/repro/repro_issue514.cnew file mode 100644index 000000000..738033c10--- /dev/null+++ b/tests/repro/repro_issue514.c@@ -0,0 +1,199 @@+/*+ * repro_issue514.c -- Reproduce-first case for OPEN bug #514.+ *+ * Issue: #514 -- "trace_path data_flow mode doesn't surface arg expressions;+ * NestJS DI patterns defeat ~70% of caller resolution"+ *+ * Sub-claim reproduced: (A) data_flow mode omits argument expressions.+ *+ * Why sub-claim A over sub-claim B (NestJS DI caller resolution):+ * (A) has a crisp binary assertion: the "e" field either appears in the JSON+ * output or it does not. (B) is a statistical claim (~70% failure rate) that+ * requires a NestJS-specific fixture and a headcount of resolved callers across+ * many call sites -- impossible to assert precisely in a unit test. (A) can+ * be reproduced with a small two-function Python fixture and one strstr check.+ *+ * Root cause:+ * The MCP schema for trace_path documents data_flow mode as "follow CALLS ++ * DATA_FLOWS with arg expressions" (mcp.c line 356-357 and 363-364). Argument+ * expressions at each call site ARE stored in the graph: pass_parallel.c::+ * append_args_json serializes each CBMCallArg as {"i":<index>,"e":"<expr>,...}+ * into the CALLS edge properties_json column. However,+ * bfs_to_json_array() (mcp.c ~line 2283) only emits the node fields (name,+ * qualified_name, hop, risk, is_test) from cbm_node_hop_t. The edge that+ * carried the arg expressions is NOT propagated by cbm_store_bfs() into the+ * cbm_traverse_result_t (cbm_edge_info_t carries only from_name, to_name,+ * type, confidence -- no properties_json). So even if the user requests+ * mode="data_flow", every hop in the response lacks the "args" field and the+ * individual arg expression text ("e") is permanently absent from the output.+ *+ * Expected (correct) behaviour:+ * After indexing a two-function Python file where caller() passes a compound+ * expression (payload_info + 1) to callee(), a trace_path call with+ * mode="data_flow" and direction="outbound" on "caller" must include the+ * argument expression text "payload_info" in the response JSON -- either in an+ * "args" array inside the hop object, or as a standalone "e" field.+ *+ * Actual (buggy) behaviour:+ * The response is:+ * {"function":"caller","direction":"outbound","mode":"data_flow",+ * "callees":[{"name":"callee","qualified_name":"...","hop":1}]}+ * The hop object contains NO "args" and NO "e"/"arg_expr" field.+ * strstr(resp, "payload_info") returns NULL.+ *+ * Why RED on current code:+ * The precondition assertion (CALLS edges >= 1) passes -- edge creation+ * and arg serialisation in pass_parallel.c are correct. The final+ * ASSERT_NOT_NULL(strstr(resp, "payload_info")) FAILS because+ * bfs_to_json_array() never reads or re-emits edge properties_json, so the+ * arg expression "payload_info" stored in the CALLS edge is permanently+ * discarded before it reaches the MCP JSON output.+ *+ * Fix location (not implemented here):+ * cbm_store_bfs() in src/store/store.c must propagate edge properties_json+ * into the cbm_traverse_result_t (extend cbm_edge_info_t or cbm_node_hop_t).+ * bfs_to_json_array() in src/mcp/mcp.c must then emit an "args" field when+ * mode == "data_flow" and the incoming edge has a non-empty args array.+ */++#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(x):+ * return x * 2+ *+ * def caller():+ * result = callee(payload_info + 1)+ * return result+ *+ * caller() passes the compound expression (payload_info + 1) as the first+ * positional argument to callee(). The extractor captures this as a CBMCallArg+ * with .expr == "payload_info + 1" (or a prefix thereof after sanitization).+ * append_args_json serializes it into the CALLS edge as:+ * {"args":[{"i":0,"e":"payload_info + 1"}]}+ *+ * The expression token "payload_info" is unique enough to identify in the+ * output: strstr(resp, "payload_info") is the assertion anchor.+ *+ * Python is used here because its CALLS extraction (including arg expressions)+ * is proven reliable -- see repro_issue480.c for the same fixture approach.+ */+static const RFile k_files[] = {+ {+ "service.py",+ "def callee(x):\n"+ " return x * 2\n"+ "\n"+ "def caller():\n"+ " result = callee(payload_info + 1)\n"+ " return result\n"+ }+};++/*+ * TEST: repro_issue514_data_flow_surfaces_arg_expr+ *+ * Precondition (must be GREEN to prove this is a data_flow surfacing bug):+ * rh_count_edges(store, project, "CALLS") >= 1+ * If this fires RED, the extractor has a regression unrelated to #514.+ *+ * Failing assertion (RED on current code):+ * strstr(resp, "payload_info") != NULL+ * i.e. the argument expression text must appear somewhere in the response.+ */+TEST(repro_issue514_data_flow_surfaces_arg_expr) {+ 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: at least one CALLS edge must exist after indexing.+ * If this fires RED the fixture is broken, not data_flow mode.+ * The caller() -> callee(payload_info + 1) call must produce one edge.+ */+ int calls_count = rh_count_edges(store, lp.project, "CALLS");+ fprintf(stderr,+ " [514] CALLS edges=%d (expected>=1; 0=extraction regression)\n",+ calls_count);+ ASSERT_GT(calls_count, 0);++ /*+ * Invoke trace_path with mode="data_flow", direction="outbound" on "caller".+ *+ * Args (matching the trace_path JSON schema in mcp.c ~line 355-374):+ * function_name -- "caller": the function that passes the argument+ * project -- lp.project: derived from the temp dir+ * direction -- "outbound": follow callees (caller -> callee)+ * depth -- 2: one hop is enough+ * mode -- "data_flow": the mode that promises arg expressions+ *+ * Expected response (correct):+ * {"function":"caller","direction":"outbound","mode":"data_flow",+ * "callees":[{"name":"callee","qualified_name":"...","hop":1,+ * "args":[{"i":0,"e":"payload_info + 1"}]}]}+ * -- or any JSON structure that includes the string "payload_info".+ *+ * Buggy response:+ * {"function":"caller","direction":"outbound","mode":"data_flow",+ * "callees":[{"name":"callee","qualified_name":"...","hop":1}]}+ * -- no "args", no "e", no "payload_info" anywhere.+ */+ char args[512];+ snprintf(args, sizeof(args),+ "{\"function_name\":\"caller\","+ "\"project\":\"%s\","+ "\"direction\":\"outbound\","+ "\"depth\":2,"+ "\"mode\":\"data_flow\"}",+ lp.project);++ char *resp = cbm_mcp_handle_tool(lp.srv, "trace_path", args);+ ASSERT_NOT_NULL(resp);++ fprintf(stderr, " [514] trace_path data_flow response: %.400s\n", resp);++ /* The response must not be an error -- the node must be found. */+ ASSERT_NULL(strstr(resp, "function not found"));++ /* The "callees" key must appear (direction=outbound always emits it). */+ ASSERT_NOT_NULL(strstr(resp, "\"callees\""));++ /* The callees array must be non-empty: "callee" must appear as a hop.+ * If this fires RED, the CALLS traversal is broken (separate from #514). */+ ASSERT_NULL(strstr(resp, "\"callees\":[]"));+ ASSERT_NOT_NULL(strstr(resp, "\"callee\""));++ /*+ * THE CORE ASSERTION FOR BUG #514:+ *+ * The argument expression "payload_info" (part of "payload_info + 1" passed+ * to callee()) must appear in the response JSON when mode="data_flow".+ *+ * WHY RED on current code:+ * bfs_to_json_array() (mcp.c ~line 2283) only emits cbm_node_hop_t fields+ * (name, qualified_name, hop). cbm_edge_info_t (store.h ~line 146) does+ * not carry properties_json, so the "e":"payload_info + 1" stored in the+ * CALLS edge never reaches the JSON output. strstr returns NULL.+ *+ * This assertion is the canonical RED line for bug #514.+ */+ ASSERT_NOT_NULL(strstr(resp, "payload_info"));++ free(resp);+ rh_cleanup(&lp, store);+ PASS();+}++/* ── Suite ─────────────────────────────────────────────────────────────────── */+SUITE(repro_issue514) {+ RUN_TEST(repro_issue514_data_flow_surfaces_arg_expr);+}diff --git a/tests/repro/repro_issue627.c b/tests/repro/repro_issue627.cnew file mode 100644index 000000000..43755574d--- /dev/null+++ b/tests/repro/repro_issue627.c@@ -0,0 +1,235 @@+/*+ * repro_issue627.c -- Reproduce-first case for OPEN bug #627.+ *+ * Issue: #627 -- "Crash when calling query_graph"+ * Reporter: zbynekwinkler+ *+ * EXACT CRASHING INPUT (from issue body):+ *+ * MATCH (f:Function)+ * WHERE NOT f.file_path CONTAINS 'ext'+ * AND NOT f.file_path CONTAINS 'Tests'+ * AND NOT f.file_path CONTAINS 'examples'+ * AND NOT f.name = 'main'+ * OPTIONAL MATCH (c)-[:CALLS]->(f)+ * WITH f, c+ * WHERE c IS NULL+ * RETURN f.name, f.qualified_name, f.file_path, f.start_line+ * ORDER BY f.file_path+ * LIMIT 50+ *+ * ROOT CAUSE (src/cypher/cypher.c, expand_additional_patterns + cross_join_with_rels):+ *+ * When executing the second pattern "OPTIONAL MATCH (c)-[:CALLS]->(f)",+ * expand_additional_patterns() (line ~4201) checks whether nodes[0] of the+ * second pattern (variable "c") is already bound. "c" is a NEW variable, so+ * start_bound=false and execution falls into the else branch (line ~4210).+ *+ * That branch calls scan_pattern_nodes() for "c" -- returning ALL nodes in the+ * graph (no label filter on "c") -- and then cross_join_with_rels() to combine+ * each candidate "c" with the existing "f" bindings.+ *+ * cross_join_with_rels() computes its pre-allocation as:+ *+ * malloc((*bind_count * extra_count * CYP_GROWTH_10 + 1) * sizeof(binding_t))+ *+ * All three operands are "int". With a graph of ~29 K nodes:+ * bind_count ~ 29 000 (Function nodes from the first MATCH after WHERE)+ * extra_count ~ 29 000 (ALL nodes scanned for unbound "c")+ * CYP_GROWTH_10 = 10+ *+ * 29000 * 29000 * 10 = 8 410 000 000 -- overflows signed 32-bit int, wrapping+ * to a small/negative value. cast to size_t this becomes a near-zero or+ * near-SIZE_MAX value. malloc returns either NULL (OOM) or a tiny block.+ * The subsequent loop writes new_bindings[new_count++] past the allocation+ * boundary, corrupting the heap -> SIGSEGV / SIGABRT.+ *+ * A secondary bug compounds the crash: even when the multiplication does NOT+ * overflow (small graphs), expand_additional_patterns() ignores the fact that+ * the second pattern's terminal node "f" IS ALREADY BOUND. process_edges()+ * (line ~2860) calls binding_set(&nb, "f", &found) unconditionally, overwriting+ * the caller's copy of "f" with whatever node the edge leads to, instead of+ * filtering to only edges whose target matches the already-bound "f". This+ * produces semantically wrong results: the final WHERE c IS NULL filter and+ * the RETURN f.name etc. operate on corrupted "f" bindings.+ *+ * EXPECTED (correct) behaviour:+ * query_graph returns -- without crashing -- the list of Function nodes that+ * have NO inbound CALLS edges (i.e. dead-code / uncalled functions). In our+ * fixture, "orphan_func" is defined but never called; "leaf_func" is called by+ * "caller_func". The correct result set must include "orphan_func" and must+ * NOT include "leaf_func".+ *+ * ACTUAL (buggy) behaviour:+ * On a graph with tens of thousands of nodes: SIGSEGV / SIGABRT (integer+ * overflow in the malloc size, heap OOB write).+ * On a small fixture: wrong result set due to overwritten "f" bindings; the+ * assertion that "orphan_func" appears in the result and "leaf_func" does not+ * fails.+ *+ * WHY RED on current code:+ * - The fork detects a crash signal (WIFSIGNALED) if it occurs.+ * ASSERT_FALSE(WIFSIGNALED(st)) fires when the child is killed by a signal.+ * - Even without a crash signal the result-content assertion is RED: because+ * expand_additional_patterns() misbinds "f", the query does not correctly+ * identify uncalled functions. "orphan_func" may be absent or "leaf_func"+ * may be present in the response, causing one of the content assertions to+ * fail -> RED.+ *+ * Fix location (NOT implemented here):+ * src/cypher/cypher.c -- expand_additional_patterns() must detect when the+ * TERMINAL node of the additional pattern is already bound (here "f") and drive+ * the join from that side (inbound edge scan from f), not by scanning all nodes+ * for "c". Additionally, process_edges() must check whether to_var is already+ * bound and, if so, only emit a match when the found node's id equals the+ * already-bound node's id. The malloc in cross_join_with_rels() must use+ * size_t arithmetic (not int) to avoid the overflow.+ */++#include <foundation/compat.h>+#include "test_framework.h"+#include "repro_harness.h"++#include <string.h>+#include <stdlib.h>+#include <stdio.h>++#if !defined(_WIN32)+#include <sys/wait.h>+#endif++/*+ * Fixture: three Python functions.+ *+ * leaf_func() -- called by caller_func(); has >= 1 inbound CALLS edge+ * caller_func() -- calls leaf_func(); has 0 inbound CALLS edges+ * orphan_func() -- never called; has 0 inbound CALLS edges+ *+ * A dead-code query ("find functions with no inbound CALLS edges") must+ * return both "caller_func" and "orphan_func" but NOT "leaf_func".+ *+ * We assert the narrower claim: "orphan_func" IN result AND "leaf_func" NOT IN+ * result. This is the minimal check that distinguishes correct behaviour from+ * the current buggy one (which either crashes or returns the wrong set).+ *+ * Python is chosen because Python CALLS extraction is confirmed reliable+ * (test_extraction.c validates it, and the regression suite's python fixtures+ * consistently produce CALLS edges).+ */+static const RFile k_files[] = {+ {+ "funcs.py",+ "def leaf_func():\n"+ " return 42\n"+ "\n"+ "def caller_func():\n"+ " return leaf_func()\n"+ "\n"+ "def orphan_func():\n"+ " return 99\n"+ }+};++/*+ * Dead-code Cypher query -- identical structure to the reporter's crashing query.+ * We omit the file_path / name filters (the fixture path can vary) so we test+ * the OPTIONAL MATCH + WITH + WHERE c IS NULL pattern in isolation.+ */+static const char k_query[] =+ "MATCH (f:Function) "+ "OPTIONAL MATCH (c)-[:CALLS]->(f) "+ "WITH f, c "+ "WHERE c IS NULL "+ "RETURN f.name, f.qualified_name, f.file_path, f.start_line "+ "ORDER BY f.name "+ "LIMIT 50";++/* --------------------------------------------------------------------------+ * repro_issue627_query_graph_no_crash+ *+ * Precondition: the indexer produced at least one CALLS edge (leaf_func+ * called by caller_func). If this fires RED the fixture or Python CALLS+ * extraction is broken -- unrelated to #627.+ *+ * Primary crash assertion (POSIX only):+ * Run query_graph in a forked child; assert WIFSIGNALED is false.+ * RED if the child is killed (SIGSEGV/SIGABRT from the heap OOB).+ *+ * Secondary correctness assertion (all platforms):+ * The result must include "orphan_func" (an uncalled function) and must+ * NOT include "leaf_func" (which has an inbound CALLS edge).+ * RED if the wrong-binding bug causes the result to be empty or inverted.+ * -------------------------------------------------------------------------- */+TEST(repro_issue627_query_graph_no_crash) {+ 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: caller_func -> leaf_func must have produced >= 1 CALLS edge.+ * If RED here, the fixture has an extraction problem, not a #627 symptom. */+ int calls_count = rh_count_edges(store, lp.project, "CALLS");+ ASSERT_GT(calls_count, 0);++ char args[1024];+ snprintf(args, sizeof(args),+ "{\"project\":\"%s\","+ "\"query\":\"%s\"}",+ lp.project, k_query);++#if !defined(_WIN32)+ /* ---- POSIX crash-isolation via fork ---------------------------------- */+ fflush(NULL);+ pid_t pid = fork();+ if (pid == 0) {+ /* Child: run query_graph; exit cleanly if no crash. */+ char *r = cbm_mcp_handle_tool(lp.srv, "query_graph", args);+ if (r)+ free(r);+ _exit(0);+ }++ int st = 0;+ (void)waitpid(pid, &st, 0);++ /* PRIMARY assertion: query_graph must NOT crash the process.+ * WHY RED on buggy code (large graphs):+ * integer overflow in cross_join_with_rels malloc size ->+ * heap OOB write -> child receives SIGSEGV or SIGABRT ->+ * WIFSIGNALED(st) is true -> ASSERT_FALSE fires. */+ ASSERT_FALSE(WIFSIGNALED(st));+#endif++ /* ---- Correctness assertion (all platforms) --------------------------- */+ /* Run the query in the parent to inspect the result content.+ * Even on small graphs where the crash does not occur, the wrong-binding+ * bug causes query_graph to return an incorrect result set. */+ char *resp = cbm_mcp_handle_tool(lp.srv, "query_graph", args);+ ASSERT_NOT_NULL(resp);++ /* Must not be an error response. */+ ASSERT_NULL(strstr(resp, "\"is_error\":true"));++ /* "orphan_func" has zero inbound CALLS edges -> must appear in the+ * dead-code result set.+ * WHY RED on buggy code: expand_additional_patterns scans ALL nodes+ * for "c", overwrites the already-bound "f" in each binding with the+ * CALLS-edge target, and the corrupted "f" bindings fail to identify+ * orphan_func as uncalled. strstr returns NULL -> ASSERT_NOT_NULL fails. */+ ASSERT_NOT_NULL(strstr(resp, "orphan_func"));++ /* "leaf_func" IS called by caller_func -> must NOT appear in the dead-code+ * result.+ * WHY RED on buggy code: the "f" binding corruption may let leaf_func+ * slip through the WHERE c IS NULL filter. */+ ASSERT_NULL(strstr(resp, "leaf_func"));++ free(resp);+ rh_cleanup(&lp, store);+ PASS();+}++/* ---- Suite --------------------------------------------------------------- */+SUITE(repro_issue627) {+ RUN_TEST(repro_issue627_query_graph_no_crash);+}diff --git a/tests/repro/repro_main.c b/tests/repro/repro_main.cindex 2ebb4a6ba..95564aff4 100644--- a/tests/repro/repro_main.c+++ b/tests/repro/repro_main.c@@ -38,6 +38,9 @@ extern void suite_repro_issue480(void);extern void suite_repro_issue571(void);extern void suite_repro_issue523(void);extern void suite_repro_issue546(void);+extern void suite_repro_issue627(void);+extern void suite_repro_issue514(void);+extern void suite_repro_issue510(void);int main(void) {/* Unbuffered: a reproduction may crash/_exit (or a sanitizer may _exit on a@@ -63,6 +66,9 @@ int main(void) {RUN_SUITE(repro_issue571);RUN_SUITE(repro_issue523);RUN_SUITE(repro_issue546);+ RUN_SUITE(repro_issue627);+ RUN_SUITE(repro_issue514);+ RUN_SUITE(repro_issue510);TEST_SUMMARY();}