jin 0.1.0

Approximate Nearest Neighbor Search: HNSW, DiskANN, IVF-PQ, ScaNN, quantization
Documentation
name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: -Dwarnings

# Testing strategy grounded in real-world ANN library issues:
# - hnswlib #635: M vs Mcurmax bug in neighbor selection
# - hnswlib #626: Use-after-free in deletion
# - hnswlib #592: Vector not normalized for cosine distance  
# - hnswlib #608: Issues after deleting vectors
# - faiss #4295: Integer overflow on large datasets
# - usearch #405: Quantization issues with i8 + inner product
# See TESTING.md for full details

jobs:
  # Primary test suite (x86)
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --check

      - name: Clippy (strict)
        run: cargo clippy --no-default-features --features hnsw --all-targets -- -D clippy::correctness

      - name: Build
        run: cargo build --no-default-features --features hnsw

      - name: Test (unit + integration)
        run: cargo test --no-default-features --features hnsw

      - name: Property tests
        run: cargo test --no-default-features --features hnsw property_

      - name: Build (with persistence)
        run: cargo build --no-default-features --features "hnsw,persistence"

  # ARM native testing (M1/M2 - tests NEON code paths)
  test-arm:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Build (ARM)
        run: cargo build --no-default-features --features hnsw

      - name: Test (ARM)
        run: cargo test --no-default-features --features hnsw

  # MSRV check
  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.80.0
      - uses: Swatinem/rust-cache@v2

      - name: Check MSRV
        run: |
          rm -f Cargo.lock  # v4 lock requires Cargo 1.83+
          cargo check --no-default-features --features hnsw

  # Cross-compilation check for different targets
  cross-compile:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - aarch64-unknown-linux-gnu
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2

      - name: Check ${{ matrix.target }}
        run: cargo check --target ${{ matrix.target }} --no-default-features --features hnsw

  # Recall regression detection
  recall-regression:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Build release
        run: cargo build --release --no-default-features --features hnsw

      - name: Run recall benchmark
        run: |
          cargo run --release --example 02_measure_recall --no-default-features --features hnsw 2>&1 | tee recall_output.txt
          # Fail if recall@10 drops below 80% at ef=100
          # This catches issues like hnswlib #635 (wrong M parameter)
          if ! grep -q "recall" recall_output.txt; then
            echo "Recall test did not run properly"
            exit 1
          fi

  # Regression tests for known bugs
  regression:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Run regression tests
        run: cargo test --test regression_known_bugs --no-default-features --features hnsw

  # Documentation build
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Build docs
        run: cargo doc --no-default-features --features hnsw --no-deps
        env:
          RUSTDOCFLAGS: -Dwarnings