# Bellona Load Tests

k6 suites that assert the Bellona engine-bridge SLOs from
`docs/performance/baselines.md §3`. Routes match the OpenAPI-owned contract in
`libs/bellona/client/src/api/generated.ts`.

| Script             | Exercises                                                                   | SLO gate                                                                        |
| ------------------ | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `bridge-load.js`   | Full session → build → status poll → export → end-session per iter          | session start p95 ≤ 250 ms, build start p95 ≤ 500 ms, export start p95 ≤ 400 ms |
| `build-hotpath.js` | High-rate `GET /v1/builds/:id` (+ a slice of `/logs`) against seeded builds | status p95 ≤ 150 ms, logs p95 ≤ 500 ms                                          |

## Run locally

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

# End-to-end bridge flow
k6 run testing/performance/k6/bellona/bridge-load.js

# Hot-path polling (status/logs)
k6 run testing/performance/k6/bellona/build-hotpath.js
```

## Environment variables

| Var                          | Default                    | Purpose                                                 |
| ---------------------------- | -------------------------- | ------------------------------------------------------- |
| `BELLONA_API_URL`            | `http://localhost:3006`    | Bellona build-api origin                                |
| `JWT_SECRET`                 | `bellona-load-test-secret` | HS256 secret for load-test tokens                       |
| `BELLONA_HOTPATH_RPS`        | `80`                       | Hot-path sustained RPS                                  |
| `BELLONA_HOTPATH_SEED_COUNT` | `8`                        | How many builds the hot-path suite seeds before ramping |
| `BELLONA_HOTPATH_LOGS_RATIO` | `0.15`                     | Fraction of hot-path iterations that also fetch logs    |

## What counts as a regression

k6 exits non-zero if any `thresholds` block fails. The thresholds in `config.js`
encode the baselines directly — update both `config.js` and
`docs/performance/baselines.md §3` when adjusting.

## Why sessions are opened and closed on every iteration

The bridge-load scenario intentionally spans the full session lifecycle per VU
iteration: opening/closing is cheap relative to build start, and keeping one
long-lived session per VU hides session-start regressions. The hot-path scenario
is the place to pay the amortisation — it seeds fewer ids and hammers the read
path.
