# docker-compose.ci.yml — CI test runner for social-bot integration tests.
#
# Usage:
#   # Default: core CI tests (no GPU, mock sensors only)
#   docker compose -f docker/docker-compose.ci.yml up --exit-code-from test-runner
#
#   # Full tests with GPU (requires nvidia container runtime):
#   SOCIAL_TEST_FULL=1 \
#   docker compose -f docker/docker-compose.ci.yml \
#     --profile gpu up --exit-code-from test-runner
#
# Build image first:
#   docker compose -f docker/docker-compose.ci.yml build

version: "3.9"

# ── Shared env ────────────────────────────────────────────────────────────────
x-common-env: &common-env
  ROS_DOMAIN_ID: "108"
  PYTHONUNBUFFERED: "1"

services:
  # ── Core CI test runner (no GPU) ─────────────────────────────────────────────
  test-runner:
    build:
      context: ../../../../        # saltylab-firmware root
      dockerfile: jetson/ros2_ws/src/saltybot_social_tests/docker/Dockerfile.ci
    image: saltybot/social-tests-ci:latest
    container_name: social_tests_ci
    environment:
      <<: *common-env
      SOCIAL_TEST_FULL: "${SOCIAL_TEST_FULL:-0}"
      SOCIAL_TEST_SPEECH: "${SOCIAL_TEST_SPEECH:-0}"
      SOCIAL_STACK_RUNNING: "1"   # stack is started inside entrypoint
    command: >
      pytest
        /ros2_ws/src/saltybot_social_tests/test/
        -v
        --timeout=120
        --tb=short
        -m "not gpu_required and not full_stack"
        --junit-xml=/tmp/test-results/social-tests.xml
    volumes:
      - test-results:/tmp/test-results
    # No network_mode host needed — ROS2 uses shared memory loopback in container

  # ── GPU full-stack tests (Orin / CUDA host) ───────────────────────────────
  test-runner-gpu:
    extends:
      service: test-runner
    container_name: social_tests_ci_gpu
    environment:
      <<: *common-env
      SOCIAL_TEST_FULL: "1"
      SOCIAL_TEST_SPEECH: "1"
      SOCIAL_STACK_RUNNING: "1"
    command: >
      pytest
        /ros2_ws/src/saltybot_social_tests/test/
        -v
        --timeout=300
        --tb=short
        --junit-xml=/tmp/test-results/social-tests-gpu.xml
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    profiles:
      - gpu

volumes:
  test-results:
