# Real API Smoke Testing

This smoke test hits real Convertrilo infrastructure with a real API key. It is meant for staging or a dedicated test account.

## Required Environment

```bash
export CONVERTRILO_API_URL="https://api.convertrilo.com"
export CONVERTRILO_API_KEY="cvr_..."
```

By default, the smoke test only checks `/tokens/balance` so it does not spend tokens.

## Run Balance Check

```bash
pnpm run smoke:api
```

## Run A Real Encode

This submits a small 480p H.264 on-demand encode and polls until success, failure, cancellation, or timeout.

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
pnpm run smoke:api
```

## Smoke Modes

The default mode is `url`: URL source in, internal CDN output out.

```bash
export CONVERTRILO_SMOKE_MODE=url
```

Custom S3 output using the user's saved S3 credential:

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
export CONVERTRILO_SMOKE_MODE=output-s3
export CONVERTRILO_SMOKE_OUTPUT_S3_KEY="convertrilo-smoke/output.mp4"
pnpm run smoke:api
```

S3 folder/prefix source ingest using the user's saved S3 credential:

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
export CONVERTRILO_SMOKE_MODE=source-s3-folder
export CONVERTRILO_SMOKE_SOURCE_S3_PREFIX="qwe/"
pnpm run smoke:api
```

Google Drive output requires a saved service-account credential:

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
export CONVERTRILO_SMOKE_MODE=output-google-drive
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_CREDENTIAL_ID="..."
pnpm run smoke:api
```

Google Drive folder source ingest requires the saved credential ID and folder IDs:

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
export CONVERTRILO_SMOKE_MODE=source-google-drive-folder
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_OUTPUT_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_CREDENTIAL_ID="..."
pnpm run smoke:api
```

Create the credential through `POST /ondemand/credentials/google-drive`, then share the source folder as Reader and output folder as Writer with the returned `clientEmail`.

Optional knobs:

```bash
export CONVERTRILO_SMOKE_SOURCE_URL="https://example.com/sample.mp4"
export CONVERTRILO_SMOKE_S3_CREDENTIAL_ID="optional-saved-credential-id"
export CONVERTRILO_SMOKE_TIMEOUT_MS=600000
export CONVERTRILO_SMOKE_POLL_INTERVAL_MS=5000
```

Use a dedicated test API key with the scopes `jobs:create`, `jobs:read`, and
`jobs:cancel`. Add `credentials:manage` only when the smoke test reads a saved
S3 credential secret via `CONVERTRILO_SMOKE_S3_CREDENTIAL_ID`.

## Release Smoke Matrix

Run this matrix after backend/API deploys that touch jobs, storage integrations, workers, or webhooks.

Start with common environment:

```bash
export CONVERTRILO_API_URL="https://api.convertrilo.com"
export CONVERTRILO_API_KEY="cvr_..."
export CONVERTRILO_SMOKE_RUN_ENCODE=true
```

URL source to Convertrilo CDN:

```bash
export CONVERTRILO_SMOKE_MODE=url
pnpm run smoke:api
```

URL source to customer S3-compatible output:

```bash
export CONVERTRILO_SMOKE_MODE=output-s3
export CONVERTRILO_SMOKE_OUTPUT_S3_KEY="convertrilo-smoke/output-$(date +%s).mp4"
pnpm run smoke:api
```

S3 folder source to customer S3-compatible output:

```bash
export CONVERTRILO_SMOKE_MODE=source-s3-folder
export CONVERTRILO_SMOKE_SOURCE_S3_PREFIX="test/"
export CONVERTRILO_SMOKE_OUTPUT_S3_PREFIX="convertrilo-smoke/folder-output-$(date +%s)/"
export CONVERTRILO_SMOKE_MAX_FOLDER_JOBS=1
pnpm run smoke:api
```

URL source to Google Drive output with a saved service account:

```bash
export CONVERTRILO_SMOKE_MODE=output-google-drive
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_OUTPUT_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_CREDENTIAL_ID="..."
pnpm run smoke:api
```

Google Drive folder source to Google Drive output with a saved service account:

```bash
export CONVERTRILO_SMOKE_MODE=source-google-drive-folder
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_OUTPUT_FOLDER_ID="..."
export CONVERTRILO_SMOKE_GOOGLE_DRIVE_CREDENTIAL_ID="..."
export CONVERTRILO_SMOKE_MAX_FOLDER_JOBS=1
pnpm run smoke:api
```

Managed webhook delivery with a real terminal `job.completed` event:

```bash
export CONVERTRILO_SMOKE_WEBHOOK_URL="https://api.convertrilo.com/smoke/webhooks/convertrilo/$SMOKE_WEBHOOK_RECEIVER_TOKEN"
export CONVERTRILO_SMOKE_RUN_ENCODE=true
pnpm run smoke:webhooks
```

The owned smoke receiver is enabled only when `SMOKE_WEBHOOK_RECEIVER_TOKEN` is configured on the API server. It returns 204 for matching tokens, logs minimal delivery metadata, and stores no webhook body. If it is not configured, use a receiver you control or an intentionally disposable test receiver for smoke testing only.

## Run Webhook Delivery History Smoke

This creates a temporary managed webhook, sends a `webhook.test` event, verifies
`GET /webhooks/{id}/deliveries`, and deletes the temporary webhook.

```bash
export CONVERTRILO_API_URL="https://api.convertrilo.com"
export CONVERTRILO_API_KEY="cvr_..."
pnpm run smoke:webhooks
```

By default it uses `https://httpbingo.org/status/204` as the receiver. To use your
own receiver:

```bash
export CONVERTRILO_SMOKE_WEBHOOK_URL="https://your-app.com/webhooks/convertrilo"
pnpm run smoke:webhooks
```

To also submit a real encode and verify a terminal job webhook delivery:

```bash
export CONVERTRILO_SMOKE_RUN_ENCODE=true
pnpm run smoke:webhooks
```

The API key must be able to manage webhooks and create/read jobs for the encode mode.
