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
Add smoke tests to Docker test infra + CI pipeline
Martin Vogel20814e8b27c7
diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.shindex 9df13351c..47e30149d 100755--- a/scripts/smoke-test.sh+++ b/scripts/smoke-test.sh@@ -177,15 +177,23 @@ 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 check it exits within 5 seconds-timeout 5 "$BINARY" < "$SHUTDOWN_TMPDIR/input.jsonl" > /dev/null 2>&1 || true-EXIT_CODE=$?-rm -rf "$SHUTDOWN_TMPDIR"--if [ "$EXIT_CODE" -eq 124 ]; then+# 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"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)@@ -337,5 +345,89 @@ echo "OK: Content-Length framing works (OpenCode compatible)"rm -f "$MCP_CL_INPUT" "$MCP_CL_OUTPUT" "$MCP_TOOL_INPUT" "$MCP_TOOL_OUTPUT"+echo ""+echo "=== Phase 6: CLI subcommands ==="++# 6a: install --dry-run -y+echo "--- Phase 6a: install --dry-run ---"+INSTALL_OUT=$("$BINARY" install --dry-run -y 2>&1)+if ! echo "$INSTALL_OUT" | grep -qi 'install\|skill\|mcp\|agent'; then+ echo "FAIL: install --dry-run produced unexpected output"+ echo "$INSTALL_OUT"+ exit 1+fi+if ! echo "$INSTALL_OUT" | grep -qi 'dry-run'; then+ echo "FAIL: install --dry-run did not indicate dry-run mode"+ exit 1+fi+echo "OK: install --dry-run completed"++# 6b: uninstall --dry-run -y+echo "--- Phase 6b: uninstall --dry-run ---"+UNINSTALL_OUT=$("$BINARY" uninstall --dry-run -y 2>&1)+if ! echo "$UNINSTALL_OUT" | grep -qi 'uninstall\|remov'; then+ echo "FAIL: uninstall --dry-run produced unexpected output"+ echo "$UNINSTALL_OUT"+ exit 1+fi+echo "OK: uninstall --dry-run completed"++# 6c: update --dry-run --standard -y+echo "--- Phase 6c: update --dry-run ---"+UPDATE_OUT=$("$BINARY" update --dry-run --standard -y 2>&1)+if ! echo "$UPDATE_OUT" | grep -qi 'dry-run'; then+ echo "FAIL: update --dry-run did not indicate dry-run mode"+ echo "$UPDATE_OUT"+ exit 1+fi+if ! echo "$UPDATE_OUT" | grep -qi 'standard'; then+ echo "FAIL: update --dry-run did not respect --standard flag"+ exit 1+fi+echo "OK: update --dry-run --standard completed"++# 6d: config set/get/reset round-trip+echo "--- Phase 6d: config set/get/reset ---"+"$BINARY" config set auto_index true 2>/dev/null+CONFIG_VAL=$("$BINARY" config get auto_index 2>/dev/null)+if ! echo "$CONFIG_VAL" | grep -q 'true'; then+ echo "FAIL: config get auto_index returned '$CONFIG_VAL', expected 'true'"+ exit 1+fi+"$BINARY" config reset auto_index 2>/dev/null+echo "OK: config set/get/reset round-trip"++echo ""+echo "=== Phase 7: MCP advanced tool calls ==="++# 7a: search_code via MCP (graph-augmented v2)+echo "--- Phase 7a: search_code via MCP ---"+MCP_SC_INPUT=$(mktemp)+MCP_SC_OUTPUT=$(mktemp)+cat > "$MCP_SC_INPUT" << SCEOF+{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"smoke","version":"1.0"}}}+{"jsonrpc":"2.0","method":"notifications/initialized"}+{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"index_repository","arguments":{"repo_path":"$TMPDIR","mode":"fast"}}}+{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_code","arguments":{"pattern":"compute","mode":"compact","limit":3}}}+{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"get_code_snippet","arguments":{"qualified_name":"compute"}}}+SCEOF++mcp_run "$MCP_SC_INPUT" "$MCP_SC_OUTPUT" 30++if ! grep -q '"id":3' "$MCP_SC_OUTPUT"; then+ echo "FAIL: search_code response (id:3) missing"+ exit 1+fi+echo "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"+ exit 1+fi+echo "OK: get_code_snippet via MCP"++rm -f "$MCP_SC_INPUT" "$MCP_SC_OUTPUT"+echo ""echo "=== smoke-test: ALL PASSED ==="diff --git a/src/cli/cli.c b/src/cli/cli.cindex e6cd9d970..487af98bf 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -258,17 +258,34 @@ int cbm_copy_file(const char *src, const char *dst) {return rc == 0 ? 0 : -1;}-/* Replace a binary file: unlink first (handles read-only existing files),- * then create with the given data and permissions. */+/* Replace a binary file. Unlinks the old file first (handles read-only and+ * running binaries on Unix where unlink succeeds on open files). On all+ * platforms, the caller should tell the user to restart after update. */int cbm_replace_binary(const char *path, const unsigned char *data, int len, int mode) {if (!path || !data || len <= 0) {return -1;}- /* Remove existing file first — handles the case where the old binary- * has no write permission (e.g., 0500). unlink() only requires write- * permission on the parent directory, not the file itself. */- (void)cbm_unlink(path);+ /* Remove existing file if it exists. On Unix, unlink works even if the+ * binary is running (inode stays alive until the process exits). On Windows,+ * unlink fails on running .exe — rename it aside as fallback. */+ struct stat st_check;+ if (stat(path, &st_check) == 0) {+ /* File exists — remove or rename it */+ if (cbm_unlink(path) != 0) {+#ifdef _WIN32+ /* Windows: can't unlink running .exe — rename aside */+ char old_path[1024];+ snprintf(old_path, sizeof(old_path), "%s.old", path);+ (void)cbm_unlink(old_path);+ if (rename(path, old_path) != 0) {+ return -1;+ }+#else+ return -1;+#endif+ }+ }#ifndef _WIN32int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, (mode_t)mode);@@ -281,6 +298,7 @@ int cbm_replace_binary(const char *path, const unsigned char *data, int len, intreturn -1;}#else+ (void)mode;FILE *f = fopen(path, "wb");if (!f) {return -1;@@ -2705,6 +2723,18 @@ int cbm_cmd_uninstall(int argc, char **argv) {int cbm_cmd_update(int argc, char **argv) {parse_auto_answer(argc, argv);+ bool dry_run = false;+ int variant_flag = 0; /* 0 = ask, 1 = standard, 2 = ui */+ for (int i = 0; i < argc; i++) {+ if (strcmp(argv[i], "--dry-run") == 0) {+ dry_run = true;+ } else if (strcmp(argv[i], "--standard") == 0) {+ variant_flag = 1;+ } else if (strcmp(argv[i], "--ui") == 0) {+ variant_flag = 2;+ }+ }+const char *home = cbm_get_home_dir();if (!home) {fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n");@@ -2734,29 +2764,39 @@ int cbm_cmd_update(int argc, char **argv) {printf("Found %d existing index(es) that must be rebuilt after update:\n", index_count);cbm_list_indexes(home);printf("\n");- if (!prompt_yn("Delete these indexes and continue with update?")) {- printf("Update cancelled.\n");- return 1;+ if (!dry_run) {+ if (!prompt_yn("Delete these indexes and continue with update?")) {+ printf("Update cancelled.\n");+ return 1;+ }+ int removed = cbm_remove_indexes(home);+ printf("Removed %d index(es).\n\n", removed);+ } else {+ printf("(dry-run — indexes would be deleted)\n\n");}- int removed = cbm_remove_indexes(home);- printf("Removed %d index(es).\n\n", removed);}- /* Step 2: Ask for UI variant */- printf("Which binary variant do you want?\n");- printf(" 1) standard — MCP server only\n");- printf(" 2) ui — MCP server + embedded graph visualization\n");- printf("Choose (1/2): ");- (void)fflush(stdout);-- char choice[16];- if (!fgets(choice, sizeof(choice), stdin)) {- fprintf(stderr, "error: failed to read input\n");- return 1;+ /* Step 2: Determine variant (--standard / --ui flags skip interactive prompt) */+ bool want_ui = false;+ if (variant_flag == 1) {+ want_ui = false;+ } else if (variant_flag == 2) {+ want_ui = true;+ } else {+ printf("Which binary variant do you want?\n");+ printf(" 1) standard — MCP server only\n");+ printf(" 2) ui — MCP server + embedded graph visualization\n");+ printf("Choose (1/2): ");+ (void)fflush(stdout);++ char choice[16];+ if (!fgets(choice, sizeof(choice), stdin)) {+ fprintf(stderr, "error: failed to read input\n");+ return 1;+ }+ want_ui = (choice[0] == '2');}// NOLINTNEXTLINE(readability-implicit-bool-conversion)- bool want_ui = (choice[0] == '2') ? true : false;- // NOLINTNEXTLINE(readability-implicit-bool-conversion)const char *variant = want_ui ? "ui-" : "";// NOLINTNEXTLINE(readability-implicit-bool-conversion)const char *variant_label = want_ui ? "ui" : "standard";@@ -2779,9 +2819,23 @@ int cbm_cmd_update(int argc, char **argv) {os, arch, ext);}- printf("\nDownloading %s binary for %s/%s ...\n", variant_label, os, arch);+ if (dry_run) {+ printf("\nWould download %s binary for %s/%s ...\n", variant_label, os, arch);+ } else {+ printf("\nDownloading %s binary for %s/%s ...\n", variant_label, os, arch);+ }printf(" %s\n", url);+ if (dry_run) {+ printf("\n(dry-run — skipping download, extraction, and binary replacement)\n");+ printf(" target: %s/.local/bin/codebase-memory-mcp\n", home);+ printf(" variant: %s\n", variant_label);+ printf(" os/arch: %s/%s\n", os, arch);+ printf("\nUpdate dry-run complete.\n");+ (void)variant;+ return 0;+ }+/* Step 4: Download using curl */char tmp_archive[256];snprintf(tmp_archive, sizeof(tmp_archive), "%s/cbm-update.%s", cbm_tmpdir(), ext);@@ -2897,6 +2951,7 @@ int cbm_cmd_update(int argc, char **argv) {printf("\nAll project indexes were cleared. They will be rebuilt\n");printf("automatically when you next use the MCP server.\n");+ printf("\nPlease restart your MCP client to use the new binary.\n");(void)variant;return 0;}diff --git a/test-infrastructure/Dockerfile b/test-infrastructure/Dockerfileindex 57a288e06..bb7c6202a 100644--- a/test-infrastructure/Dockerfile+++ b/test-infrastructure/Dockerfile@@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \gcc g++ make \zlib1g-dev \pkg-config \+ python3-minimal \&& rm -rf /var/lib/apt/lists/*WORKDIR /srcdiff --git a/test-infrastructure/docker-compose.yml b/test-infrastructure/docker-compose.ymlindex 3aed3ebbb..cd2763240 100644--- a/test-infrastructure/docker-compose.yml+++ b/test-infrastructure/docker-compose.yml@@ -72,6 +72,33 @@ services:WINEDEBUG=-all wine64 build/c/test-runner.exe &&echo '=== Windows test: OK ==='+ # ── Smoke test (build + run smoke-test.sh) ──────────────────+ smoke:+ build:+ context: ..+ dockerfile: test-infrastructure/Dockerfile+ platform: linux/arm64+ volumes:+ - ..:/src+ entrypoint: ["/bin/bash", "-c"]+ command:+ - |+ scripts/build.sh CC=gcc CXX=g++ &&+ scripts/smoke-test.sh ./build/c/codebase-memory-mcp++ smoke-amd64:+ build:+ context: ..+ dockerfile: test-infrastructure/Dockerfile+ platform: linux/amd64+ volumes:+ - ..:/src+ entrypoint: ["/bin/bash", "-c"]+ command:+ - |+ scripts/build.sh CC=gcc CXX=g++ &&+ scripts/smoke-test.sh ./build/c/codebase-memory-mcp+# ── Lint ────────────────────────────────────────────────────lint:build:diff --git a/test-infrastructure/run.sh b/test-infrastructure/run.shindex fd08432d1..c07129ef2 100755--- a/test-infrastructure/run.sh+++ b/test-infrastructure/run.sh@@ -26,6 +26,8 @@ case "${1:-full}" inecho "=== Linux arm64: test + build ==="$COMPOSE run --rm test$COMPOSE run --rm build+ echo "=== Linux arm64: smoke test ==="+ $COMPOSE run --rm smokeecho "=== Windows: cross-compile ==="$COMPOSE run --rm build-windowsecho "=== All passed ==="@@ -38,6 +40,10 @@ case "${1:-full}" inecho "=== Linux arm64: production build (-O2 -Werror) ==="$COMPOSE run --rm build;;+ smoke)+ echo "=== Linux arm64: smoke test (build + run all 7 phases) ==="+ $COMPOSE run --rm smoke+ ;;windows)echo "=== Windows: cross-compile (mingw-w64) ==="$COMPOSE run --rm build-windows@@ -48,12 +54,14 @@ case "${1:-full}" in$COMPOSE run --rm build-amd64;;all)- echo "=== Linux arm64: test + build ==="+ echo "=== Linux arm64: test + build + smoke ==="$COMPOSE run --rm test$COMPOSE run --rm build- echo "=== Linux amd64: test + build ==="+ $COMPOSE run --rm smoke+ echo "=== Linux amd64: test + build + smoke ==="$COMPOSE run --rm test-amd64$COMPOSE run --rm build-amd64+ $COMPOSE run --rm smoke-amd64echo "=== Windows: cross-compile ==="$COMPOSE run --rm build-windowsecho "=== All platforms passed ==="@@ -67,7 +75,7 @@ case "${1:-full}" in$COMPOSE run --rm --entrypoint bash test;;*)- echo "Usage: $0 {full|test|build|windows|amd64|all|lint|shell}"+ echo "Usage: $0 {full|test|build|smoke|windows|amd64|all|lint|shell}"exit 1;;esac