name: Tests

on:
  push:
    branches: [main, master, recovery/integration-lab]
  pull_request:
    branches: [main, master]

jobs:
  test:
    runs-on: ubuntu-latest

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

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
          cache: 'pip'

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libta-lib0-dev

      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install pytest pytest-cov

      - name: Syntax check
        run: |
          python -m py_compile src/*.py
          python -m py_compile src/brokers/*.py

      - name: Run critical test suites
        working-directory: .
        run: |
          pytest tests/test_strategy_execution.py \
                 tests/test_execution_loop.py \
                 tests/test_paper_persistence.py \
                 tests/test_backtest_determinism.py \
                 tests/test_brokers.py \
                 -v --tb=short

      - name: Run broker abstraction tests
        working-directory: .
        run: |
          pytest tests/test_brokers.py -v --tb=short

  lint:
    runs-on: ubuntu-latest

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

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install linting tools
        run: |
          python -m pip install --upgrade pip
          pip install ruff

      - name: Check code style
        run: |
          ruff check src/ --select=E,F --ignore=E501,E402,F401 || true
        continue-on-error: true
