name: Fuzz (quick smoke)

on:
  push:
    branches: [main]
    tags: ["v*.*.*"]
    paths:
      - "fuzz/**"
      - "src/**"
      - "Cargo.toml"
  pull_request:
    paths:
      - "fuzz/**"
      - "src/**"
      - "Cargo.toml"
  workflow_dispatch: # manual trigger when you need a long run

jobs:
  fuzz:
    runs-on: ubuntu-latest
    timeout-minutes: 12
    strategy:
      fail-fast: false
      matrix:
        target: [clone, expose, mut, parsing, serde]

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

      - name: Install Rust nightly
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: nightly

      - name: Cache cargo registry + target dir
        uses: Swatinem/rust-cache@v2

      - name: Install cargo-fuzz
        run: cargo install cargo-fuzz

      - name: Quick smoke test – ${{ matrix.target }} (90 s)
        run: |
          cargo +nightly fuzz run ${{ matrix.target }} -- \
            -fork=1 \
            -max_total_time=90 \
            -timeout=30

      - name: Upload crash artifacts (only on failure)
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: fuzz-crash-${{ matrix.target }}-${{ github.run_id }}
          path: fuzz/artifacts/${{ matrix.target }}/**
          retention-days: 7
