services:
  # Backend unit tests
  backend-test:
    build:
      context: .
      dockerfile: Dockerfile.test
      target: backend-test
    container_name: bambuddy-backend-test
    volumes:
      - ./backend:/app/backend:ro
    environment:
      - TESTING=1
      - PYTHONUNBUFFERED=1

  # Frontend unit tests
  frontend-test:
    build:
      context: .
      dockerfile: Dockerfile.test
      target: frontend-test
    container_name: bambuddy-frontend-test
    volumes:
      - ./frontend/src:/app/frontend/src:ro
      - ./frontend/tests:/app/frontend/tests:ro

  # Integration test - full application
  integration:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: bambuddy-integration-test
    ports:
      - "8001:8000"
    environment:
      - TESTING=1
      - DATA_DIR=/app/data
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 10s
    volumes:
      - integration_test_data:/app/data

  # Integration test runner
  integration-test-runner:
    build:
      context: .
      dockerfile: Dockerfile.test
      target: backend-test
    container_name: bambuddy-integration-runner
    depends_on:
      integration:
        condition: service_healthy
    environment:
      - BAMBUDDY_TEST_URL=http://integration:8000
      - TESTING=1
    command: ["pytest", "backend/tests/integration/", "-v", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"]
    volumes:
      - ./backend:/app/backend:ro

volumes:
  integration_test_data:
