renacer 0.9.7

Pure Rust system call tracer with source-aware correlation for Rust binaries
Documentation
# Renacer Makefile
# Following bashrs and paiml-mcp-agent-toolkit patterns

.SUFFIXES:

.PHONY: help test coverage coverage-html coverage-clean mutants mutants-quick clean build release lint format check \
	tier1 tier2 tier3 chaos-test chaos-full check-regression fuzz benchmark install-llvm verify-llvm

# =============================================================================
# Installation & Dependencies
# =============================================================================

install-llvm: ## Install LLVM/Clang development libraries (for projects like decy)
	@echo "๐Ÿ”ง Installing LLVM/Clang development libraries..."
	@if [ -f /etc/debian_version ]; then \
		echo "๐Ÿ“ฆ Detected Debian/Ubuntu"; \
		sudo apt-get update; \
		sudo apt-get install -y llvm-14-dev libclang-14-dev clang-14 build-essential pkg-config; \
		echo "๐Ÿ”— Setting up LLVM environment variables..."; \
		if ! grep -q "LLVM_CONFIG_PATH" ~/.zshrc; then \
			echo 'export LLVM_CONFIG_PATH=/usr/bin/llvm-config-14' >> ~/.zshrc; \
		fi; \
		if ! grep -q "LIBCLANG_PATH" ~/.zshrc; then \
			echo 'export LIBCLANG_PATH=/usr/lib/llvm-14/lib' >> ~/.zshrc; \
		fi; \
		export LLVM_CONFIG_PATH=/usr/bin/llvm-config-14; \
		export LIBCLANG_PATH=/usr/lib/llvm-14/lib; \
		echo "โœ… LLVM/Clang libraries installed"; \
		echo "โš ๏ธ  Run 'source ~/.zshrc' to reload environment"; \
	elif [ -f /etc/redhat-release ]; then \
		echo "๐Ÿ“ฆ Detected RHEL/CentOS/Fedora"; \
		sudo yum install -y llvm-devel clang-devel || sudo dnf install -y llvm-devel clang-devel; \
		echo "โœ… LLVM/Clang libraries installed"; \
	elif [ "$$(uname)" = "Darwin" ]; then \
		echo "๐Ÿ“ฆ Detected macOS"; \
		brew install llvm; \
		echo "๐Ÿ”— Setting up LLVM environment variables..."; \
		if ! grep -q "LLVM_CONFIG_PATH" ~/.zshrc; then \
			echo 'export PATH="/usr/local/opt/llvm/bin:$$PATH"' >> ~/.zshrc; \
			echo 'export LDFLAGS="-L/usr/local/opt/llvm/lib"' >> ~/.zshrc; \
			echo 'export CPPFLAGS="-I/usr/local/opt/llvm/include"' >> ~/.zshrc; \
			echo 'export LIBCLANG_PATH=/usr/local/opt/llvm/lib' >> ~/.zshrc; \
		fi; \
		echo "โœ… LLVM/Clang libraries installed"; \
		echo "โš ๏ธ  Run 'source ~/.zshrc' to reload environment"; \
	else \
		echo "โŒ Unsupported platform. Please install LLVM/Clang manually."; \
		exit 1; \
	fi

verify-llvm: ## Verify LLVM/Clang installation
	@echo "๐Ÿ” Verifying LLVM/Clang installation..."
	@echo ""
	@if command -v llvm-config >/dev/null 2>&1 || command -v llvm-config-14 >/dev/null 2>&1; then \
		echo "โœ… LLVM found:"; \
		llvm-config-14 --version 2>/dev/null || llvm-config --version; \
	else \
		echo "โŒ LLVM not found"; \
	fi
	@echo ""
	@if [ -n "$$LLVM_CONFIG_PATH" ]; then \
		echo "โœ… LLVM_CONFIG_PATH: $$LLVM_CONFIG_PATH"; \
	else \
		echo "โš ๏ธ  LLVM_CONFIG_PATH not set"; \
	fi
	@echo ""
	@if [ -n "$$LIBCLANG_PATH" ]; then \
		echo "โœ… LIBCLANG_PATH: $$LIBCLANG_PATH"; \
		if [ -d "$$LIBCLANG_PATH" ]; then \
			echo "โœ… libclang directory exists"; \
			ls -la "$$LIBCLANG_PATH"/libclang.so* 2>/dev/null || echo "โš ๏ธ  libclang.so not found"; \
		else \
			echo "โŒ libclang directory does not exist"; \
		fi; \
	else \
		echo "โš ๏ธ  LIBCLANG_PATH not set"; \
	fi

# =============================================================================
# Testing & Quality
# =============================================================================

help: ## Show this help message
	@echo "Renacer - Pure Rust strace alternative"
	@echo ""
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-20s\033[0m %s\n", $$1, $$2}'

test: ## Run tests (fast, no coverage)
	@echo "๐Ÿงช Running tests..."
	@cargo test --quiet

test-fast: ## Run tests quickly with nextest (parallel, < 5min target)
	@echo "๐Ÿงช Running fast tests with nextest..."
	@if command -v cargo-nextest >/dev/null 2>&1; then \
		PROPTEST_CASES=25 RUST_TEST_THREADS=$$(nproc) cargo nextest run \
			--workspace \
			--status-level skip \
			--failure-output immediate; \
	else \
		echo "โš ๏ธ  cargo-nextest not found. Installing..."; \
		cargo install cargo-nextest; \
		PROPTEST_CASES=25 RUST_TEST_THREADS=$$(nproc) cargo nextest run \
			--workspace \
			--status-level skip \
			--failure-output immediate; \
	fi

coverage: ## Generate HTML coverage report and open in browser (max 10min target)
	@echo "๐Ÿ“Š Running comprehensive test coverage analysis..."
	@echo "๐Ÿ” Checking for cargo-llvm-cov..."
	@which cargo-llvm-cov > /dev/null 2>&1 || (echo "๐Ÿ“ฆ Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov --locked)
	@if ! rustup component list --installed | grep -q llvm-tools-preview; then \
		echo "๐Ÿ“ฆ Installing llvm-tools-preview..."; \
		rustup component add llvm-tools-preview; \
	fi
	@echo "๐Ÿ” Detecting GPU hardware..."
	@GPU_FEATURES=""; \
	if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1; then \
		echo "โœ… NVIDIA GPU detected - enabling gpu-tracing and cuda-tracing features"; \
		GPU_FEATURES="--features gpu-tracing,cuda-tracing"; \
		export CUDA_VISIBLE_DEVICES=0; \
	else \
		echo "โš ๏ธ  No NVIDIA GPU detected - running without GPU features"; \
		GPU_FEATURES=""; \
	fi; \
	echo "๐Ÿงน Cleaning old coverage data..."; \
	mkdir -p target/coverage/html; \
	echo "๐Ÿงช Phase 1: Running tests with instrumentation (reduced proptest cases)..."; \
	PROPTEST_CASES=20 RUST_TEST_THREADS=$$(nproc) timeout 600 cargo llvm-cov --no-report test --workspace $$GPU_FEATURES || true; \
	echo "๐Ÿ“Š Phase 2: Generating coverage reports..."; \
	cargo llvm-cov report --html --output-dir target/coverage/html || echo "โš ๏ธ  No coverage data generated"; \
	cargo llvm-cov report --lcov --output-path target/coverage/lcov.info || echo "โš ๏ธ  LCOV generation skipped"; \
	echo ""; \
	echo "๐Ÿ“Š Coverage Summary:"; \
	cargo llvm-cov report --summary-only || echo "Run 'cargo test' to generate coverage data first"; \
	echo ""; \
	echo "๐Ÿ“Š Coverage reports generated:"; \
	echo "- HTML: target/coverage/html/index.html"; \
	echo "- LCOV: target/coverage/lcov.info"; \
	echo ""; \
	xdg-open target/coverage/html/index.html 2>/dev/null || \
		open target/coverage/html/index.html 2>/dev/null || \
		echo "โœ… Open target/coverage/html/index.html in your browser"

coverage-html: coverage ## Alias for coverage

coverage-clean: ## Clean coverage artifacts
	@echo "๐Ÿงน Cleaning coverage artifacts..."
	@if command -v cargo-llvm-cov >/dev/null 2>&1; then \
		echo "โœ… Coverage artifacts cleaned!"; \
	else \
		echo "โš ๏ธ  cargo-llvm-cov not installed, skipping clean."; \
	fi

build: ## Build debug binary
	@echo "๐Ÿ”จ Building debug binary..."
	@cargo build

release: ## Build optimized release binary
	@echo "๐Ÿš€ Building release binary..."
	@cargo build --release
	@echo "โœ… Release binary: target/release/renacer"

lint: ## Run clippy linter
	@echo "๐Ÿ” Running clippy..."
	@cargo clippy -- -D warnings

format: ## Format code with rustfmt
	@echo "๐Ÿ“ Formatting code..."
	@cargo fmt

check: ## Type check without building
	@echo "โœ… Type checking..."
	@cargo check --all-targets --all-features

clean: ## Clean build artifacts
	@echo "๐Ÿงน Cleaning build artifacts..."
	@cargo clean
	@rm -rf target/coverage
	@echo "โœ… Clean completed!"

benchmark: ## Run performance benchmarks
	@echo "๐Ÿ“Š Running benchmarks..."
	@cargo test --test benchmark_vs_strace -- --nocapture --test-threads=1

mutants: ## Run mutation testing (full analysis)
	@echo "๐Ÿงฌ Running mutation testing..."
	@echo "๐Ÿ” Checking for cargo-mutants..."
	@which cargo-mutants > /dev/null 2>&1 || (echo "๐Ÿ“ฆ Installing cargo-mutants..." && cargo install cargo-mutants --locked)
	@echo "๐Ÿงฌ Running cargo-mutants (this may take several minutes)..."
	@cargo mutants --output target/mutants.out || echo "โš ๏ธ  Some mutants survived"
	@echo ""
	@echo "๐Ÿ“Š Mutation Testing Results:"
	@cat target/mutants.out/mutants.out 2>/dev/null || echo "Check target/mutants.out/ for detailed results"

mutants-quick: ## Run mutation testing (quick check on changed files only)
	@echo "๐Ÿงฌ Running quick mutation testing..."
	@echo "๐Ÿ” Checking for cargo-mutants..."
	@which cargo-mutants > /dev/null 2>&1 || (echo "๐Ÿ“ฆ Installing cargo-mutants..." && cargo install cargo-mutants --locked)
	@echo "๐Ÿงฌ Running cargo-mutants on uncommitted changes..."
	@cargo mutants --in-diff git:HEAD --output target/mutants-quick.out || echo "โš ๏ธ  Some mutants survived"
	@echo ""
	@echo "๐Ÿ“Š Quick Mutation Testing Results:"
	@cat target/mutants-quick.out/mutants.out 2>/dev/null || echo "Check target/mutants-quick.out/ for detailed results"

# =============================================================================
# Tiered TDD Workflow (from trueno patterns)
# =============================================================================

tier1: ## Tier 1: Fast tests (<5s) - unit tests, clippy, format
	@echo "๐Ÿƒ Tier 1: Fast tests (<5 seconds)..."
	@cargo fmt --check
	@cargo clippy -- -D warnings
	@cargo test --lib --quiet
	@echo "โœ… Tier 1 complete!"

tier2: tier1 ## Tier 2: Integration tests (<30s) - includes tier1
	@echo "๐Ÿƒ Tier 2: Integration tests (<30 seconds)..."
	@cargo test --tests --quiet
	@echo "โœ… Tier 2 complete!"

tier3: tier2 ## Tier 3: Full validation (<5m) - includes tier1+2, property tests
	@echo "๐Ÿƒ Tier 3: Full validation (<5 minutes)..."
	@cargo test --all-targets --all-features --quiet
	@echo "โœ… Tier 3 complete!"

# =============================================================================
# Chaos Engineering (Sprint 29 - Red-Team Profile)
# =============================================================================

chaos-test: ## Run chaos engineering tests (basic tier)
	@echo "๐Ÿ”ฅ Running chaos engineering tests..."
	@cargo test --features chaos-basic --quiet
	@echo "โœ… Chaos basic tests complete!"

chaos-full: ## Run full chaos engineering suite (requires chaos-full feature)
	@echo "๐Ÿ”ฅ Running full chaos engineering suite..."
	@cargo test --features chaos-full --quiet
	@echo "โœ… Full chaos tests complete!"

check-regression: ## Check for performance regressions (>5% threshold)
	@echo "๐Ÿ“Š Checking for performance regressions..."
	@ruchy scripts/check_regression.ruchy || echo "โš ๏ธ  Regression check failed or ruchy not found"

fuzz: ## Run fuzz testing targets
	@echo "๐ŸŽฒ Running fuzz tests..."
	@echo "๐Ÿ” Checking for cargo-fuzz..."
	@which cargo-fuzz > /dev/null 2>&1 || (echo "๐Ÿ“ฆ Installing cargo-fuzz..." && cargo install cargo-fuzz --locked)
	@cargo +nightly fuzz run filter_parser -- -max_total_time=60 || echo "โš ๏ธ  Fuzz testing requires nightly toolchain"

# =============================================================================
# Differential Testing (Oracle Problem)
# =============================================================================

diff-test: ## Run differential tests against strace
	@echo "๐Ÿ”ฌ Running differential tests (Renacer vs strace)..."
	@cargo test --test differential_strace_tests --quiet || echo "โš ๏ธ  Differential tests not yet implemented"