Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix: stabilize cross-platform daemon smoke
Martin Vogel4693b625e035
diff --git a/scripts/security-fuzz.sh b/scripts/security-fuzz.shindex 9d74a175e..a396f609f 100755--- a/scripts/security-fuzz.sh+++ b/scripts/security-fuzz.sh@@ -79,6 +79,29 @@ test_payload() {fi}+# Mutating operations are session-owned and intentionally cancel on EOF. Keep+# stdin open until the invalid-path response and a subsequent ping arrive so+# this case tests robustness without racing the disconnect contract.+test_invalid_index_interactive() {+ local name="index nonexistent path"+ TOTAL=$((TOTAL + 1))+ local tmpoutput="$FUZZ_TMPDIR/output_${TOTAL}.jsonl"+ local ec=0++ HOME="$FUZZ_HOME" CBM_CACHE_DIR="$FUZZ_CACHE" \+ python3 "$(dirname "$0")/test_mcp_interactive.py" "$BINARY" \+ --scenario invalid-index --repo-path /nonexistent/path/abc123 \+ --response-timeout 30 --exit-timeout 15 > "$tmpoutput" 2>&1 || ec=$?++ if [[ $ec -eq 0 ]]; then+ PASS=$((PASS + 1))+ else+ echo "FAIL: $name — interactive session failed"+ sed -n '1,20p' "$tmpoutput"+ FAIL=$((FAIL + 1))+ fi+}+echo ""echo "--- Malformed JSON ---"@@ -124,7 +147,7 @@ test_payload "path traversal in qualified_name" '{"jsonrpc":"2.0","id":2,"methodtest_payload "shell injection in file_pattern" '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_code","arguments":{"pattern":"test","file_pattern":"*.py'\'' ; cat /etc/passwd #"}}}'# index_repository with non-existent path (should return error, not crash)-test_payload "index nonexistent path" '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"index_repository","arguments":{"repo_path":"/nonexistent/path/abc123"}}}'+test_invalid_index_interactive# Negative/zero values for numeric paramstest_payload "negative limit" '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_graph","arguments":{"name_pattern":"test","limit":-1}}}'diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.shindex 9aa15e814..04e6225f5 100755--- a/scripts/smoke-test.sh+++ b/scripts/smoke-test.sh@@ -559,30 +559,15 @@ fiecho ""echo "=== Phase 4: security checks ==="-# 4a: Clean shutdown — binary must exit within 5 seconds after EOF+# 4a: Clean shutdown — wait through bounded cold bootstrap, then require the+# initialized frontend to exit promptly after EOF.echo "Testing clean shutdown..."-SHUTDOWN_TMPDIR=$(mktemp -d)-cat > "$SHUTDOWN_TMPDIR/input.jsonl" << 'JSONL'-{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}-JSONL--# Run binary with EOF and wait up to 5 seconds (portable — no `timeout` needed)-"$BINARY" < "$SHUTDOWN_TMPDIR/input.jsonl" > /dev/null 2>&1 &-SHUTDOWN_PID=$!-SHUTDOWN_WAITED=0-while kill -0 "$SHUTDOWN_PID" 2>/dev/null && [ "$SHUTDOWN_WAITED" -lt 5 ]; do- sleep 1- SHUTDOWN_WAITED=$((SHUTDOWN_WAITED + 1))-done-if kill -0 "$SHUTDOWN_PID" 2>/dev/null; then- kill "$SHUTDOWN_PID" 2>/dev/null || true- wait "$SHUTDOWN_PID" 2>/dev/null || true- rm -rf "$SHUTDOWN_TMPDIR"- echo "FAIL: binary did not exit within 5 seconds after EOF"+if ! python3 "$REPO_ROOT/scripts/test_mcp_interactive.py" \+ "$BINARY" --scenario initialize --repo-path "$TMPDIR" \+ --response-timeout 30 --exit-timeout 8 > /dev/null; then+ echo "FAIL: initialized binary did not exit within 8 seconds after EOF"exit 1fi-wait "$SHUTDOWN_PID" 2>/dev/null || true-rm -rf "$SHUTDOWN_TMPDIR"echo "OK: clean shutdown"# 4b: No residual processes (skip on Windows/MSYS2 where pgrep may not work)@@ -912,9 +897,9 @@ if ! grep -q '"id":3' "$MCP_SC_OUTPUT"; thenfiecho "OK: search_code v2 via MCP"-# 7b: get_code_snippet via MCP-if ! grep -q '"id":4' "$MCP_SC_OUTPUT"; then- echo "FAIL: get_code_snippet response (id:4) missing"+# 7b: search_graph discovery + get_code_snippet via MCP+if ! grep -q '"id":4' "$MCP_SC_OUTPUT" || ! grep -q '"id":5' "$MCP_SC_OUTPUT"; then+ echo "FAIL: search_graph/get_code_snippet response (id:4 or id:5) missing"exit 1fiecho "OK: get_code_snippet via MCP"diff --git a/scripts/test_mcp_interactive.py b/scripts/test_mcp_interactive.pyindex f0c81ef55..5421bd514 100644--- a/scripts/test_mcp_interactive.py+++ b/scripts/test_mcp_interactive.py@@ -65,6 +65,7 @@ def wait_response(responses: "queue.Queue[dict[str, Any]]",request_id: int,timeout: float,+ accept_tool_error: bool = False,) -> dict[str, Any]:deadline = time.monotonic() + timeoutwhile True:@@ -81,14 +82,23 @@ def wait_response(raise SmokeFailure(f"timed out waiting for MCP response id={request_id}") from errorif message.get("id") != request_id:continue+ if "result" not in message and "error" not in message:+ # An echoed request is not a JSON-RPC response and must never count+ # as proof that the server dispatched the request.+ continueif "error" in message:raise SmokeFailure(f"MCP response id={request_id} returned JSON-RPC error: {message['error']!r}")result = message.get("result")- if isinstance(result, dict) and result.get("isError") is True:+ if (+ isinstance(result, dict)+ and result.get("isError") is True+ and not accept_tool_error+ ):+ rendered = json.dumps(message, separators=(",", ":"), ensure_ascii=False)raise SmokeFailure(- f"MCP tool response id={request_id} reported isError=true"+ f"MCP tool response id={request_id} reported isError=true: {rendered}")return message@@ -100,6 +110,7 @@ def request(method: str,params: dict[str, Any],timeout: float,+ accept_tool_error: bool = False,) -> dict[str, Any]:send(process,@@ -110,7 +121,7 @@ def request("params": params,},)- return wait_response(process, responses, request_id, timeout)+ return wait_response(process, responses, request_id, timeout, accept_tool_error)def run_scenario(@@ -125,7 +136,30 @@ def run_scenario(process,{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}},)- request(+ if scenario == "initialize":+ return+ if scenario == "invalid-index":+ invalid_index_response = request(+ process,+ responses,+ 2,+ "tools/call",+ {+ "name": "index_repository",+ "arguments": {"repo_path": repo_path, "mode": "fast"},+ },+ timeout,+ accept_tool_error=True,+ )+ invalid_index_result = invalid_index_response.get("result")+ if (+ not isinstance(invalid_index_result, dict)+ or invalid_index_result.get("isError") is not True+ ):+ raise SmokeFailure("index_repository unexpectedly accepted a nonexistent path")+ request(process, responses, 3, "ping", {}, timeout)+ return+ index_response = request(process,responses,2,@@ -136,13 +170,21 @@ def run_scenario(},timeout,)+ index_result = index_response.get("result")+ structured = index_result.get("structuredContent") if isinstance(index_result, dict) else None+ project = structured.get("project") if isinstance(structured, dict) else None+ if not isinstance(project, str) or not project:+ raise SmokeFailure("index_repository response did not identify the indexed project")if scenario == "roundtrip":request(process,responses,3,"tools/call",- {"name": "search_graph", "arguments": {"name_pattern": "compute"}},+ {+ "name": "search_graph",+ "arguments": {"project": project, "name_pattern": "compute"},+ },timeout,)return@@ -153,18 +195,57 @@ def run_scenario("tools/call",{"name": "search_code",- "arguments": {"pattern": "compute", "mode": "compact", "limit": 3},+ "arguments": {+ "project": project,+ "pattern": "compute",+ "mode": "compact",+ "limit": 3,+ },},timeout,)- request(+ discovery_response = request(process,responses,4,"tools/call",+ {+ "name": "search_graph",+ "arguments": {+ "project": project,+ "name_pattern": "compute",+ "format": "json",+ "limit": 1,+ },+ },+ timeout,+ )+ discovery_result = discovery_response.get("result")+ discovery_structured = (+ discovery_result.get("structuredContent")+ if isinstance(discovery_result, dict)+ else None+ )+ matches = (+ discovery_structured.get("results")+ if isinstance(discovery_structured, dict)+ else None+ )+ qualified_name = (+ matches[0].get("qualified_name")+ if isinstance(matches, list) and matches and isinstance(matches[0], dict)+ else None+ )+ if not isinstance(qualified_name, str) or not qualified_name:+ raise SmokeFailure("search_graph did not discover compute's qualified name")+ request(+ process,+ responses,+ 5,+ "tools/call",{"name": "get_code_snippet",- "arguments": {"qualified_name": "compute"},+ "arguments": {"project": project, "qualified_name": qualified_name},},timeout,)@@ -184,7 +265,11 @@ def stop_process(process: subprocess.Popen[bytes]) -> None:def main() -> int:parser = argparse.ArgumentParser()parser.add_argument("binary")- parser.add_argument("--scenario", choices=("roundtrip", "advanced"), required=True)+ parser.add_argument(+ "--scenario",+ choices=("initialize", "invalid-index", "roundtrip", "advanced"),+ required=True,+ )parser.add_argument("--repo-path", required=True)parser.add_argument("--response-timeout", type=float, default=30.0)parser.add_argument("--exit-timeout", type=float, default=15.0)diff --git a/src/cli/cli.c b/src/cli/cli.cindex 9d351beee..4d2364a4e 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -1264,6 +1264,7 @@ static int cli_activation_transaction_finalize_close(return cli_activation_transaction_abort(transaction_io);}+#ifndef _WIN32static void cli_activation_transaction_finalize_committed_or_fail_stop(cbm_activation_transaction_t **transaction_io, const char *component) {if (!transaction_io || !*transaction_io) {@@ -1296,6 +1297,7 @@ static int cli_activation_transaction_commit_removal(cbm_activation_transaction_? CLI_OK: CLI_ERR;}+#endifstatic bool cli_activation_transaction_expected_build(cbm_activation_transaction_t *transaction,cli_binary_validator_t *validator) {diff --git a/tests/test_security_fuzz_harness.sh b/tests/test_security_fuzz_harness.shindex b9bb78707..f4ea1583d 100644--- a/tests/test_security_fuzz_harness.sh+++ b/tests/test_security_fuzz_harness.sh@@ -52,7 +52,11 @@ printf '%s\t%s\n' "${HOME-}" "${CBM_CACHE_DIR-}" >> "$CBM_FUZZ_ENV_PROBE"while IFS= read -r line; doid=$(printf '%s\n' "$line" | sed -n 's/.*"id"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p')if [[ -n "$id" ]]; then- printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id"+ if [[ "$line" == *'"name":"index_repository"'* ]]; then+ printf '{"jsonrpc":"2.0","id":%s,"result":{"isError":true}}\n' "$id"+ else+ printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id"+ fifidoneEOF