
  test-in-docker:
    name: Integration Tests (Docker)
    runs-on: ubuntu-latest
    needs: [backend-lint, frontend-lint]

    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build development images
        run: docker compose -f docker-compose.dev.yml build

      - name: Start services
        run: docker compose -f docker-compose.dev.yml up -d

      - name: Wait for services to be healthy
        run: |
          timeout 90 bash -c 'until docker compose -f docker-compose.dev.yml ps | grep -q "healthy"; do sleep 2; done'

      - name: Run backend tests in container
        run: |
          docker compose -f docker-compose.dev.yml exec -T backend pytest --cov

      - name: Run frontend tests in container
        run: |
          docker compose -f docker-compose.dev.yml exec -T frontend npm run test

      - name: Collect logs on failure
        if: failure()
        run: docker compose -f docker-compose.dev.yml logs

      - name: Tear down
        if: always()
        run: docker compose -f docker-compose.dev.yml down -v
