Files
codebase-memory-mcp/scripts/test.sh
T
Kris Williams 1aaa8297f3 fix(build): make scripts/build.sh work under Nix on macOS
verify_compiler() in scripts/env.sh ran `file` on the clang path and
grepped for arm64/universal. Nix's clang is a bash wrapper script, so
`file` reports "ASCII text executable" and the check falsely concluded
"x86_64 only", aborting before any compile. Replace it with a capability
probe: compile + link a trivial program for the target -arch and trust
the result — correct for wrapper scripts (Nix, ccache) and cross-compilers.

Make arch targeting explicit and toolchain-agnostic: export
ARCHFLAGS="-arch <arch>" from env.sh and fold it into CC/CXX in
Makefile.cbm via `override`, so it reaches every compile and link
(including the vendored objects) and survives a command-line CC=
override. This replaces the `arch -<arch> make` prefix, which cannot
work with Nix's fixed-target clang. Drop the now-redundant ARCH_PREFIX
from build/test/lint/repro.

Refs #705.

Signed-off-by: Kris Williams <115474+kriswill@users.noreply.github.com>
2026-06-30 09:05:45 -07:00

85 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# test.sh — Clean build + run all C tests with ASan + UBSan.
#
# Usage:
# scripts/test.sh # Auto-detect everything
# scripts/test.sh --arch x86_64 # Force x86_64 build
# scripts/test.sh CC=gcc-14 CXX=g++-14 # Override compiler
#
# This script is the SINGLE source of truth for running tests.
# Used identically in local development and CI workflows.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
# Parse --arch flag before sourcing env.sh
for arg in "$@"; do
case "$arg" in
--arch) :;; # next arg is the value, handled below
arm64|x86_64)
# Check if previous arg was --arch
if [[ "${prev_arg:-}" == "--arch" ]]; then
export CBM_ARCH="$arg"
fi
;;
esac
prev_arg="$arg"
done
# Also support --arch=value
for arg in "$@"; do
case "$arg" in
--arch=*) export CBM_ARCH="${arg#--arch=}" ;;
esac
done
# shellcheck source=env.sh
source "$ROOT/scripts/env.sh"
# Forward CC/CXX and collect make-passthrough args
MAKE_ARGS=""
for arg in "$@"; do
case "$arg" in
CC=*|CXX=*) export "${arg}" ;;
--arch|--arch=*) ;; # already handled
arm64|x86_64) ;; # already handled
*=*) MAKE_ARGS="$MAKE_ARGS $arg" ;; # forward any VAR=VAL to make
esac
done
print_env "test.sh"
# Verify compiler supports target arch
verify_compiler "$CC"
# Step 1: Clean
scripts/clean.sh
# Step 2 + 3: Build and run tests (Makefile applies $ARCHFLAGS on macOS)
make -j"$NPROC" -f Makefile.cbm test $MAKE_ARGS
# Step 4: C++ large-TU index-hang regression guard (#410). Runs the PROD binary
# in a subprocess with a wall-clock timeout — a hang must fail, not block the run.
# Opt-in via CBM_RUN_HANG_TEST=1 (it needs the prod binary, which the ASan unit
# run above does not build). Skipped by default so the fast unit run stays fast.
if [ "${CBM_RUN_HANG_TEST:-0}" = "1" ]; then
echo "=== Step 4: C++ index-hang regression (#410) ==="
bash "$ROOT/tests/test_cpp_index_hang.sh"
fi
# Step 5: Parent-death watchdog regression (#406/#407). Builds the prod stdio
# binary and verifies it self-exits when its launching parent is killed.
echo "=== Step 5: parent-death watchdog regression (#406/#407) ==="
make -j"$NPROC" -f Makefile.cbm cbm $MAKE_ARGS
bash "$ROOT/tests/test_parent_watchdog.sh"
# Step 6: security-strings URL allow-list regression. The MSYS2 CLANG64 toolchain
# bakes its package-tracker URL into the static Windows .exe; the binary string
# audit must allow-list it (Windows-only — Linux smoke never saw it).
echo "=== Step 6: security-strings allow-list regression ==="
bash "$ROOT/tests/test_security_strings_allowlist.sh"
echo "=== All tests passed ==="