name: E2E (pi-ai Azure OpenAI and Anthropic)

# This suite spends tokens against two external providers and is intentionally
# opt-in. It has no push, pull_request, schedule, or workflow_call trigger.
on:
  workflow_dispatch:
    inputs:
      azure_openai_model:
        description: Azure OpenAI model from pi-ai's installed catalog
        required: true
        default: gpt-5.5
        type: string
      anthropic_model:
        description: Anthropic model from pi-ai's installed catalog
        required: true
        default: claude-opus-4-8
        type: string

permissions:
  contents: read

env:
  # CI runs must never report to the production telemetry endpoint baked
  # into apps/cli/cordis.yml (AppCLIEntry disables the row when set).
  DSH_TELEMETRY_DISABLED: '1'

jobs:
  e2e:
    runs-on: ubuntu-latest
    name: Azure OpenAI Responses + Anthropic Messages
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v6

      - uses: pnpm/action-setup@v4

      - uses: actions/setup-node@v6
        with:
          node-version: 24
          cache: pnpm

      - name: Install (immutable)
        run: pnpm install --frozen-lockfile

      # The tests self-skip locally when a credential is absent. A manually
      # dispatched CI run must fail instead of reporting an all-skipped green.
      - name: Preflight (require provider API keys)
        env:
          AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY_EXTERNAL }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY_EXTERNAL }}
        run: |
          set -euo pipefail
          missing=0
          for name in AZURE_OPENAI_API_KEY ANTHROPIC_API_KEY; do
            if [ -z "${!name:-}" ]; then
              echo "::error::${name} is empty. Configure the corresponding *_EXTERNAL repository secret."
              missing=1
            fi
          done
          exit "$missing"

      - name: E2E tests (real Azure OpenAI and Anthropic APIs)
        env:
          AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY_EXTERNAL }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY_EXTERNAL }}
          DSH_PI_AI_OPENAI_MODEL: ${{ inputs.azure_openai_model }}
          DSH_PI_AI_OPENAI_BASE_URL: https://openai-routerhub-resource.services.ai.azure.com/api/projects/openai/openai/v1
          DSH_PI_AI_ANTHROPIC_MODEL: ${{ inputs.anthropic_model }}
          DSH_E2E_MAX_WORKERS: 2
        run: >-
          pnpm exec vitest run --config vitest.e2e.config.ts
          packages/llm/llm-pi-ai/tests/provider-apis.e2e.ts
