name: Test Python SDK

on:
  workflow_call:
    inputs:
      E2B_DOMAIN:
        required: false
        type: string
        default: ''
    secrets:
      E2B_API_KEY:
        required: true

permissions:
  contents: read

jobs:
  test:
    defaults:
      run:
        working-directory: ./packages/python-sdk
        shell: bash
    name: Python SDK - Build and test (${{ matrix.os }})
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-22.04, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Parse .tool-versions
        uses: wistia/parse-tool-versions@v2.1.1
        with:
          filename: '.tool-versions'
          uppercase: 'true'
          prefix: 'tool_version_'

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '${{ env.TOOL_VERSION_PYTHON }}'

      - name: Install and configure Poetry
        uses: snok/install-poetry@v1
        with:
          version: '${{ env.TOOL_VERSION_POETRY }}'
          virtualenvs-create: true
          virtualenvs-in-project: true
          installer-parallel: true

      - name: Install dependencies
        run: poetry install

      - name: Test build
        run: poetry build

      - name: Run tests
        run: poetry run pytest --verbose --numprocesses=4
        env:
          E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
          E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
