name: CI — P1 Route (Rust)
on:
  push:
    branches: [main]
    paths: ['products/01-llm-cost-router/**']
  pull_request:
    paths: ['products/01-llm-cost-router/**']

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        run: |
          git clone --depth=1 http://192.168.86.11:3005/jarvis/dd0c.git $GITHUB_WORKSPACE || true

      - name: Install Rust
        run: |
          if ! command -v rustc &>/dev/null; then
            curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
            export PATH="$HOME/.cargo/bin:$PATH"
          fi
          rustc --version && cargo --version

      - name: Run tests
        run: |
          export PATH="$HOME/.cargo/bin:$PATH"
          cd $GITHUB_WORKSPACE/products/01-llm-cost-router && cargo test --workspace

      - name: Clippy
        run: |
          export PATH="$HOME/.cargo/bin:$PATH"
          cd $GITHUB_WORKSPACE/products/01-llm-cost-router && cargo clippy --workspace -- -D warnings

      - name: Format check
        run: |
          export PATH="$HOME/.cargo/bin:$PATH"
          cd $GITHUB_WORKSPACE/products/01-llm-cost-router && cargo fmt --check
