name: CI
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest  # Gitea runner on NAS
    steps:
      - uses: actions/checkout@v4

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

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

      - name: Run tests
        run: cargo test --workspace
        working-directory: products/01-llm-cost-router

      - name: Clippy
        run: cargo clippy --workspace -- -D warnings
        working-directory: products/01-llm-cost-router

      - name: Format check
        run: cargo fmt --check
        working-directory: products/01-llm-cost-router

  ui-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Install deps
        run: npm ci
        working-directory: products/01-llm-cost-router/ui

      - name: Type check
        run: npx tsc --noEmit
        working-directory: products/01-llm-cost-router/ui

      - name: Build
        run: npm run build
        working-directory: products/01-llm-cost-router/ui
