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-infra: give each leg its own build dir so parallel legs never collide

Martin Vogel593d1268133e
diff --git a/scripts/build.sh b/scripts/build.sh
index 8d9dad383..71d1c8120 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -33,9 +33,12 @@ done
# shellcheck source=env.sh
source "$ROOT/scripts/env.sh"
-# Parse remaining arguments
+# Parse remaining arguments. BUILD_DIR is tracked for the clean step below so
+# containerized legs can build in their own directory instead of deleting and
+# clobbering the host's native build/c artifacts.
WITH_UI=false
VERSION=""
+BUILD_DIR="build/c"
EXTRA_MAKE_ARGS=()
prev_arg=""
@@ -55,6 +58,10 @@ for arg in "$@"; do
;;
--arch|--arch=*)
;; # already handled
+ BUILD_DIR=*)
+ BUILD_DIR="${arg#BUILD_DIR=}"
+ EXTRA_MAKE_ARGS+=("$arg")
+ ;;
CC=*|CXX=*)
export "${arg}"
EXTRA_MAKE_ARGS+=("$arg")
@@ -85,7 +92,7 @@ echo " ui=$WITH_UI version=${VERSION:-dev}"
verify_compiler "$CC"
# Step 1: Clean C build artifacts only (not node_modules — npm ci handles that)
-rm -rf "$ROOT/build/c"
+rm -rf "${ROOT:?}/${BUILD_DIR}"
# Step 2: Build (Makefile applies $ARCHFLAGS for the target arch on macOS)
if $WITH_UI; then
@@ -96,4 +103,4 @@ else
CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"
fi
-echo "=== Build complete: build/c/codebase-memory-mcp ==="
+echo "=== Build complete: ${BUILD_DIR}/codebase-memory-mcp ==="
diff --git a/scripts/clean.sh b/scripts/clean.sh
index ea9e15976..1d0128c74 100755
--- a/scripts/clean.sh
+++ b/scripts/clean.sh
@@ -11,10 +11,14 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
-echo "=== Cleaning build artifacts ==="
+# Containerized legs build in their own directory (BUILD_DIR env) so a
+# container clean never deletes the host's native build/c mid-build.
+BUILD_DIR="${BUILD_DIR:-build/c}"
+
+echo "=== Cleaning build artifacts ($BUILD_DIR) ==="
# C build artifacts
-rm -rf "$ROOT/build/c"
+rm -rf "${ROOT:?}/${BUILD_DIR}"
# Frontend build artifacts
rm -rf "$ROOT/graph-ui/dist"
diff --git a/scripts/test.sh b/scripts/test.sh
index 93a2b745b..a992be2a9 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -38,13 +38,17 @@ done
# shellcheck source=env.sh
source "$ROOT/scripts/env.sh"
-# Forward CC/CXX and collect make-passthrough args
+# Forward CC/CXX and collect make-passthrough args. BUILD_DIR is honored for
+# the explicit target path below so containerized legs can build in their own
+# directory instead of clobbering the host's native build/c artifacts.
MAKE_ARGS=""
+BUILD_DIR="build/c"
for arg in "$@"; do
case "$arg" in
CC=*|CXX=*) export "${arg}" ;;
--arch|--arch=*) ;; # already handled
arm64|x86_64) ;; # already handled
+ BUILD_DIR=*) BUILD_DIR="${arg#BUILD_DIR=}"; MAKE_ARGS="$MAKE_ARGS $arg" ;;
*=*) MAKE_ARGS="$MAKE_ARGS $arg" ;; # forward any VAR=VAL to make
esac
done
@@ -66,15 +70,15 @@ bash "$ROOT/tests/test_security_fuzz_harness.sh"
# Verify compiler supports target arch
verify_compiler "$CC"
-# Step 1: Clean
-scripts/clean.sh
+# Step 1: Clean (scoped to this leg's build directory)
+BUILD_DIR="$BUILD_DIR" scripts/clean.sh
# Step 2 + 3: Build, then run every suite as parallel processes (identical
# gate quality — see the ZERO-LOSS CONTRACT in scripts/run-tests-parallel.sh:
# the suite set is enumerated from the runner itself and union-guarded, and
# pass/fail/skip totals aggregate to the same numbers as the sequential run).
# CBM_TEST_SEQUENTIAL=1 restores the single-process runner.
-make -j"$NPROC" -f Makefile.cbm build/c/test-runner $MAKE_ARGS
+make -j"$NPROC" -f Makefile.cbm "$BUILD_DIR/test-runner" $MAKE_ARGS
if [ "${CBM_TEST_SEQUENTIAL:-0}" = "1" ]; then
make -f Makefile.cbm test $MAKE_ARGS
else
diff --git a/test-infrastructure/docker-compose.yml b/test-infrastructure/docker-compose.yml
index 4245f489c..6d28d91ac 100644
--- a/test-infrastructure/docker-compose.yml
+++ b/test-infrastructure/docker-compose.yml
@@ -25,7 +25,7 @@ services:
environment:
CCACHE_DIR: /root/.ccache
CCACHE_MAXSIZE: 1500M
- command: ["CC=gcc", "CXX=g++"]
+ command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-arm64"]
test-amd64:
build:
@@ -39,7 +39,7 @@ services:
environment:
CCACHE_DIR: /root/.ccache
CCACHE_MAXSIZE: 1500M
- command: ["CC=gcc", "CXX=g++"]
+ command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-amd64"]
# ── Linux production build (-O2 -Werror) ───────────────────
build:
@@ -50,7 +50,7 @@ services:
volumes:
- ..:/src
entrypoint: ["scripts/build.sh"]
- command: ["CC=gcc", "CXX=g++"]
+ command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-arm64"]
build-amd64:
build:
@@ -60,7 +60,7 @@ services:
volumes:
- ..:/src
entrypoint: ["scripts/build.sh"]
- command: ["CC=gcc", "CXX=g++"]
+ command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-amd64"]
# ── Windows cross-compile + test (llvm-mingw + Wine) ────────
build-windows:
@@ -79,12 +79,13 @@ services:
volumes:
- ..:/src
command: >-
- make -j4 -f Makefile.cbm clean-c &&
- make -j4 -f Makefile.cbm build/c/test-runner
+ make -j4 -f Makefile.cbm clean-c BUILD_DIR=build/win-cross &&
+ make -j4 -f Makefile.cbm build/win-cross/test-runner
+ BUILD_DIR=build/win-cross
CC=x86_64-w64-mingw32-clang
CXX=x86_64-w64-mingw32-clang++ &&
echo '=== Running tests under Wine ===' &&
- WINEDEBUG=-all wine64 build/c/test-runner.exe &&
+ WINEDEBUG=-all wine64 build/win-cross/test-runner.exe &&
echo '=== Windows test: OK ==='
# ── Smoke test (build + run smoke-test.sh) ──────────────────
@@ -98,8 +99,8 @@ services:
entrypoint: ["/bin/bash", "-c"]
command:
- |
- scripts/build.sh CC=gcc CXX=g++ &&
- scripts/smoke-test.sh ./build/c/codebase-memory-mcp
+ scripts/build.sh CC=gcc CXX=g++ BUILD_DIR=build/linux-arm64 &&
+ scripts/smoke-test.sh ./build/linux-arm64/codebase-memory-mcp
smoke-amd64:
build:
@@ -111,8 +112,8 @@ services:
entrypoint: ["/bin/bash", "-c"]
command:
- |
- scripts/build.sh CC=gcc CXX=g++ &&
- scripts/smoke-test.sh ./build/c/codebase-memory-mcp
+ scripts/build.sh CC=gcc CXX=g++ BUILD_DIR=build/linux-amd64 &&
+ scripts/smoke-test.sh ./build/linux-amd64/codebase-memory-mcp
# ── Windows smoke (cross-compile + Wine) ──────────────────
smoke-windows:
@@ -125,9 +126,9 @@ services:
entrypoint: ["/bin/bash", "-c"]
command:
- |
- scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ &&
- mv build/c/codebase-memory-mcp build/c/codebase-memory-mcp.exe 2>/dev/null || true &&
- WINEDEBUG=-all scripts/smoke-test.sh ./build/c/codebase-memory-mcp.exe
+ scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ BUILD_DIR=build/win-cross &&
+ mv build/win-cross/codebase-memory-mcp build/win-cross/codebase-memory-mcp.exe 2>/dev/null || true &&
+ WINEDEBUG=-all scripts/smoke-test.sh ./build/win-cross/codebase-memory-mcp.exe
# ── Windows soak (cross-compile + Wine) ───────────────────
soak-windows:
@@ -140,9 +141,9 @@ services:
entrypoint: ["/bin/bash", "-c"]
command:
- |
- scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ &&
- mv build/c/codebase-memory-mcp build/c/codebase-memory-mcp.exe 2>/dev/null || true &&
- CBM_DIAGNOSTICS=1 WINEDEBUG=-all scripts/soak-test.sh ./build/c/codebase-memory-mcp.exe 10
+ scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ BUILD_DIR=build/win-cross &&
+ mv build/win-cross/codebase-memory-mcp build/win-cross/codebase-memory-mcp.exe 2>/dev/null || true &&
+ CBM_DIAGNOSTICS=1 WINEDEBUG=-all scripts/soak-test.sh ./build/win-cross/codebase-memory-mcp.exe 10
# ── Linux portable (Alpine musl static) ────────────────────
test-portable:
@@ -153,7 +154,7 @@ services:
volumes:
- ..:/src
entrypoint: ["bash", "scripts/test.sh"]
- command: ["CC=gcc", "CXX=g++"]
+ command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/alpine"]
build-portable:
build:
@@ -163,7 +164,7 @@ services:
volumes:
- ..:/src
entrypoint: ["bash", "scripts/build.sh"]
- command: ["CC=gcc", "CXX=g++", "STATIC=1"]
+ command: ["CC=gcc", "CXX=g++", "STATIC=1", "BUILD_DIR=build/alpine"]
smoke-portable:
build:
@@ -175,10 +176,10 @@ services:
entrypoint: ["bash", "-c"]
command:
- |
- scripts/build.sh CC=gcc CXX=g++ STATIC=1 &&
- file build/c/codebase-memory-mcp | grep -q "statically linked" &&
+ scripts/build.sh CC=gcc CXX=g++ STATIC=1 BUILD_DIR=build/alpine &&
+ file build/alpine/codebase-memory-mcp | grep -q "statically linked" &&
echo "=== Verified: statically linked ===" &&
- scripts/smoke-test.sh ./build/c/codebase-memory-mcp
+ scripts/smoke-test.sh ./build/alpine/codebase-memory-mcp
# ── Lint ────────────────────────────────────────────────────
lint:
@@ -187,6 +188,7 @@ services:
dockerfile: test-infrastructure/Dockerfile.lint
volumes:
- ..:/src
+ command: ["--ci", "CLANG_FORMAT=clang-format-20"]
volumes:
cbm-ccache-arm64: