name: Tests

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

# Runs in timmy-time:latest — tox, ruff, and all deps are pre-installed.
# Rebuild the image only when poetry.lock changes:
#   docker build -t timmy-time:latest .

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Lint (ruff via tox)
        run: tox -e lint

  test:
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v4
      - name: Run tests (via tox)
        env:
          OLLAMA_URL: "http://127.0.0.1:1"
        run: tox -e ci
      - name: Test summary
        if: always()
        run: |
          if [ -f reports/junit.xml ]; then
            python3 -c "
          import xml.etree.ElementTree as ET
          root = ET.parse('reports/junit.xml').getroot()
          t,f,e,s = (root.attrib.get(k,'0') for k in ('tests','failures','errors','skipped'))
          print(f'Tests: {t} | Failures: {f} | Errors: {e} | Skipped: {s}')
          "
          fi
