From e15bd1df8c742fd797d40efc9109bbd9e42f5f15 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Sun, 8 Jun 2025 12:02:29 -0400 Subject: [PATCH] refactor: Centralize test flags and commands in Makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add TEST_FLAGS variable for single-threaded test execution - Create verbose targets for CI usage - Update pre-commit hooks to use make targets - Update CI workflow to use make targets - This ensures consistency between local and CI test execution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/ci.yml | 22 ++++++---------------- .pre-commit-config.yaml | 10 +++++----- Makefile | 25 ++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d406b4b..2bf8050 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,17 +44,7 @@ jobs: with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - - name: Setup cargo config for cross-compilation - run: | - mkdir -p .cargo - cat > .cargo/config.toml << 'EOF' - [target.x86_64-unknown-linux-musl] - linker = "x86_64-linux-musl-gcc" - - [target.aarch64-unknown-linux-musl] - linker = "aarch64-linux-gnu-gcc" - EOF - - name: Verify cross-compilation setup (Unix) + - name: Verify cross-compilation setup run: | echo "Installed targets:" rustup target list --installed @@ -71,11 +61,11 @@ jobs: echo "Cargo config:" cat .cargo/config.toml || echo "No cargo config found" - name: Build - run: cargo build --verbose + run: make build-verbose - name: Run unit tests - run: cargo test --verbose -- --test-threads=1 + run: make test-verbose - name: Run e2e tests - run: cargo test --test '*' --verbose -- --test-threads=1 + run: make test-e2e-verbose fmt: name: Rustfmt @@ -88,7 +78,7 @@ jobs: toolchain: stable components: rustfmt - name: Check formatting - run: cargo fmt -- --check + run: make check-fmt clippy: name: Clippy @@ -101,7 +91,7 @@ jobs: toolchain: stable components: clippy - name: Run clippy - run: cargo clippy -- -D warnings + run: make lint security-audit: name: Security Audit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6dff23..fec58ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,35 +4,35 @@ repos: hooks: - id: rustfmt name: rustfmt - entry: cargo fmt -- --check + entry: make check-fmt language: system types: [rust] pass_filenames: false - id: clippy name: clippy - entry: cargo clippy -- -D warnings + entry: make lint language: system types: [rust] pass_filenames: false - id: cargo-check name: cargo check - entry: cargo check + entry: make check-code language: system types: [rust] pass_filenames: false - id: cargo-test name: cargo test - entry: cargo test -- --test-threads=1 + entry: make test-unit language: system types: [rust] pass_filenames: false - id: cargo-test-e2e name: cargo e2e tests - entry: cargo test --test '*' -- --test-threads=1 + entry: make test-e2e language: system types: [rust] pass_filenames: false diff --git a/Makefile b/Makefile index 9a58feb..2c48d98 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,16 @@ -.PHONY: test test-unit test-e2e build run clean fmt lint +.PHONY: test test-unit test-e2e build run clean fmt lint check-fmt check test-verbose + +# Test flags - run single-threaded to avoid env var races +TEST_FLAGS := -- --test-threads=1 # Build the project build: cargo build +# Build verbosely +build-verbose: + cargo build --verbose + # Run the project run: cargo run @@ -11,13 +18,21 @@ run: # Run all tests test: test-unit test-e2e +# Run all tests verbosely (for CI) +test-verbose: + cargo test --verbose $(TEST_FLAGS) + # Run unit tests only test-unit: - cargo test --lib --bins + cargo test --lib --bins $(TEST_FLAGS) # Run e2e tests only test-e2e: - cargo test --test '*' + cargo test --test '*' $(TEST_FLAGS) + +# Run e2e tests verbosely (for CI) +test-e2e-verbose: + cargo test --test '*' --verbose $(TEST_FLAGS) # Clean build artifacts clean: @@ -35,5 +50,9 @@ lint: check-fmt: cargo fmt -- --check +# Check code (for pre-commit) +check-code: + cargo check + # Run all checks (format, lint, test) check: check-fmt lint test