# E2E Tests

This folder contains lightweight end-to-end tests that run against a **running** `gh-server` instance.

E2E tests commonly use:
- shell scripts (`bash` + `curl`) for simple HTTP flows
- the repo's main language (Go here) for richer assertions and reuse
- Node/Python for API-driven integration suites

In this repo, we use **bash + curl + jq** for minimal dependencies and easy local debugging.

## Usage

Start the server first (in another terminal):

```bash
make run-bg
```

Run all e2e scripts:

```bash
make test-e2e
```

`make test-e2e` enumerates every top-level `e2e/*.sh` script except `run.sh`, `lib.sh`, and `helpers.sh`. Scripts under subdirectories such as `e2e/benchmark/` are not included in the default run.

Run a single script:

```bash
make test-e2e SCRIPT=code-search-e2e
```

Notes:
- `code-search-e2e` requires TiDB running and tests code search indexing, query behavior, and qualifier handling.

Override base URL (if not on port 80) or curl flags:

```bash
make test-e2e E2E_BASE_URL="https://github.localhost:8080"
```

Run the aggregate API performance benchmark against any environment:

```bash
E2E_TOKEN="$TOKEN" make test-e2e SCRIPT=benchmark/client-aggregate-performance E2E_BASE_URL="http://127.0.0.1:8080"
E2E_TOKEN="$TOKEN" make test-e2e SCRIPT=benchmark/client-aggregate-performance E2E_BASE_URL="https://git.staging.clawmem.ai"
E2E_TOKEN="$TOKEN" make test-e2e SCRIPT=benchmark/client-aggregate-performance E2E_BASE_URL="https://git.clawmem.ai"
```

Optional benchmark inputs:
- `E2E_PERF_REPO=owner/repo` chooses the repository target. Otherwise the first visible repo is used.
- `E2E_PERF_ORG=org` chooses the org management target. Otherwise the first visible org is used.
- `E2E_PERF_ISSUE_NUMBER=123` chooses the issue thread target. Otherwise the first issue in the repo is used.
- `E2E_PERF_WIKI_SLUGS=home,guides/setup` chooses wiki pages for batch comparison. Otherwise the first wiki pages are discovered.
- `E2E_PERF_ITERATIONS=10` changes measured iterations.

## Test Scripts

| Script | Description | Requirements |
|--------|-------------|--------------|
| `code-search-e2e.sh` | Code search indexing, query behavior, and qualifier checks | TiDB, Go |
| `vector-search-e2e.sh` | Vector/semantic search E2E tests | TiDB, Go, mock embedding server |
| `org-collaboration-governance.sh` | Explicit org creation, org invite acceptance, outside collaborator lifecycle, and permission-alias canonicalization flow | Running server, `ADMIN_TOKEN`, `MEMBER_TOKEN`, `OUTSIDER_TOKEN` |
| `oidc-provider-flow.sh` | Generic OIDC callback, lookup, repeated-login, and token-validity flow using the mock discovery server | Running server with `OIDC_PROVIDER`, `OIDC_ISSUER`, `OIDC_CLIENT_ID`, `OIDC_ALLOW_INSECURE_HTTP=1`; mock OIDC server |

## Benchmark Scripts

| Script | Description | Requirements |
|--------|-------------|--------------|
| `benchmark/client-aggregate-performance.sh` | Wall-clock comparison between legacy client call chains and aggregate APIs | Running server, `E2E_TOKEN`/`ADMIN_TOKEN`/`TEST_TOKEN`/`GH_TOKEN`, explicit `SCRIPT=benchmark/client-aggregate-performance` |
