ai-sandbox 0.2.1

Cross-platform AI tool sandbox security implementation
Documentation
# CI - Test
#
# Multi-platform test workflow for ai-sandbox
# Runs tests on Linux, macOS, and Windows

name: Test

on:
  push:
    branches: [main, master, develop, 'dev/*', 'feature/*', 'v*']
    tags: ['v*']
  pull_request:
    branches: [main, master, develop, 'feature/*']

  # 允许手动触发
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0

jobs:
  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        rust:
          - stable
          - beta
          - nightly
        exclude:
          # Skip beta/nightly on Windows for faster CI
          - os: windows-latest
            rust: beta
          - os: windows-latest
            rust: nightly

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: rustfmt, clippy

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo index
        uses: actions/cache@v4
        with:
          path: ~/.cargo/git
          key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo build
        uses: actions/cache@v4
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}-v2

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

      - name: Run clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Build
        run: cargo build --verbose
        env:
          RUST_BACKTRACE: 1

      - name: Run tests
        run: cargo test --verbose
        env:
          RUST_BACKTRACE: 1

      - name: Run functional tests
        run: cargo run --example functional_test
        env:
          RUST_BACKTRACE: 1

      - name: Run doc tests
        run: cargo test --doc --verbose

      - name: Build release
        run: cargo build --release --verbose

  # Platform-specific tests
  platform-specific:
    name: Platform Specific (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux-specific tests
          - os: ubuntu-latest
            target: linux
            features: ""
          # macOS-specific tests
          - os: macos-latest
            target: macos
            features: ""
          # Windows-specific tests
          - os: windows-latest
            target: windows
            features: ""

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: ~/.cargo
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-v2
          restore-keys: |
            ${{ runner.os }}-cargo-

      - name: Clean cargo build (Windows)
        if: runner.os == 'Windows'
        run: cargo clean

      - name: Build with specific features
        run: cargo build --verbose ${{ matrix.features }}
        env:
          CARGO_INCREMENTAL: 0

      - name: Run platform tests
        run: |
          echo "Running tests for ${{ matrix.target }}"
          cargo test --verbose

      - name: Run functional tests
        run: |
          echo "Running functional tests for ${{ matrix.target }}"
          cargo run --example functional_test

      - name: Test demo example (Unix)
        if: runner.os != 'Windows'
        run: |
          echo "Testing demo example (Unix)"
          cargo run --example demo -- 2>/dev/null || echo "Demo may require platform-specific setup"

      - name: Test demo example (Windows)
        if: runner.os == 'Windows'
        run: |
          echo "Testing demo example (Windows)"
          cargo run --example demo -- 2>$null || echo "Demo may require platform-specific setup"

  # Test on minimum Rust version
  minimum-version:
    name: Minimum Version (1.83)
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust 1.83
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.83.0

      - name: Check compilation
        run: cargo check --verbose

  # Security audit
  security-audit:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Run security audit
        uses: rustsec/audit-check@v2.0.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}