# Yemaya Load Tests

k6 suites that assert the Yemaya creative-studio SLOs from
`docs/performance/baselines.md §3`.

| Script                       | Exercises                                               | SLO gate                                |
| ---------------------------- | ------------------------------------------------------- | --------------------------------------- |
| `studio-edit-load.js`        | `PATCH /v1/projects/:id` at interactive cadence         | studio edit p95 ≤ 150 ms                |
| `asset-upload-load.js`       | Register → bytes → `/assets/:id/complete`               | end-to-end upload commit p95 ≤ 2,000 ms |
| `collaboration-sync-load.js` | `POST /v1/collaboration/sessions/join` + presence PATCH | presence update p95 ≤ 250 ms            |

## Run locally

```bash
docker compose -f docker/docker-compose.dev.yml up -d

# Studio edit round-trip
k6 run testing/performance/k6/yemaya/studio-edit-load.js

# Asset upload (default 10 MB per asset for CI-friendly runs)
k6 run testing/performance/k6/yemaya/asset-upload-load.js

# Multi-user collaboration fan-out
k6 run testing/performance/k6/yemaya/collaboration-sync-load.js
```

## Environment variables

| Var                          | Default                   | Purpose                                                          |
| ---------------------------- | ------------------------- | ---------------------------------------------------------------- |
| `YEMAYA_API_URL`             | `http://localhost:3001`   | Yemaya API origin                                                |
| `JWT_SECRET`                 | `yemaya-load-test-secret` | HS256 secret for load-test tokens                                |
| `YEMAYA_EDITS_PER_ITER`      | `3`                       | PATCH ops per VU iteration (keystroke-style batching)            |
| `YEMAYA_ASSET_SIZE_BYTES`    | `10485760` (10 MB)        | Per-asset upload size. Set to `104857600` for the 100 MB budget. |
| `YEMAYA_UPLOAD_BUFFER_KB`    | `256`                     | Chunk size when streaming bytes to the signed upload URL         |
| `YEMAYA_HEARTBEATS_PER_ITER` | `5`                       | Presence heartbeats per collaboration iteration                  |

## Why 10 MB by default instead of 100 MB

The documented SLO is for uploads up to 100 MB. CI runners can't reliably push
that volume through a shared load-test instance, so the default is 10 MB and the
2 s p95 budget is still the ceiling. For the full 100 MB validation run, set
`YEMAYA_ASSET_SIZE_BYTES=104857600` on a dedicated perf runner — the budget does
not change.

## What counts as a regression

Any `thresholds` block failing in any of the three scripts. k6 exits non-zero
and CI fails. Budget changes require touching both the `thresholds` in
`config.js` and the corresponding row in `docs/performance/baselines.md §3`.
