Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# ---------------------------------------------------------------------------
# Server
# ---------------------------------------------------------------------------
# Bind address and HTTP port.
HOST=0.0.0.0
# Bind address and HTTP port. The template binds to loopback only: set
# HOST=0.0.0.0 to reach the dashboard from other machines, but only behind a
# reverse proxy with TLS and a changed dashboard password.
HOST=127.0.0.1
PORT=20125
# Pino log level: trace | debug | info | warn | error | fatal.
LOG_LEVEL=info
# Maximum request body in bytes (base64 media payloads need room).
BODY_LIMIT=134217728
# Only read by src/server.ts (not by src/config.ts): set it to "production" from
# the runner/process manager when serving a built release. When unset the server
# keeps development behaviour (pretty logs).
# NODE_ENV=production

# ---------------------------------------------------------------------------
# Storage
Expand All @@ -18,7 +24,9 @@ DATA_DIR=./data
# ---------------------------------------------------------------------------
# Security
# ---------------------------------------------------------------------------
# Only used when the dashboard password hash is first created.
# Only used when the dashboard password hash is first created. The built-in
# default is 123456: replace it immediately after the first login
# (Settings -> Security), or set this before the database is created.
# DASHBOARD_PASSWORD=123456
# HMAC secret for dashboard session cookies. When empty, a secret is generated
# once and stored in <DATA_DIR>/.secret. When set, the environment value wins on
Expand Down
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

## Verification

- [ ] `pnpm verify` — the CI-mirroring gate (typecheck → unit tests → docs drift → build → e2e)
- [ ] `pnpm typecheck`
- [ ] `pnpm test`
- [ ] `pnpm check:docs` (env vars, routes, settings **and** `.env.example`/documented defaults)
- [ ] `pnpm check:env-example`
- [ ] `pnpm build`
- [ ] `pnpm test:e2e`
- [ ] Manual check against a real provider (`pnpm test:live`) — or N/A
Expand All @@ -23,5 +26,7 @@
- [ ] Commit messages and the PR title follow [Conventional Commits](../CONTRIBUTING.md#commit-message-convention)
- [ ] No secrets, API keys, database files or `.env` files are included
- [ ] `docs/SPEC.md` updated when the gateway/admin contract changed
- [ ] `.env.example` updated for any new environment variable (checked by `pnpm check:docs`)
- [ ] Streaming pass-through fidelity preserved (no body reshaping beyond documented `x_opencode` stripping)
- [ ] Dashboard changes keep dark/light parity
- [ ] Enforcement scripts were not weakened (`check:docs`, commit linter, e2e single-log-row assertions)
30 changes: 22 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ jobs:
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
run: |
# A brand-new branch can push with an all-zero "before" sha; fall back to the
# default range instead of failing the range check.
if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
BASE_SHA=""
fi
if [ -z "$BASE_SHA" ] || [ -z "$HEAD_SHA" ]; then
node scripts/check-commit-messages.mjs
# A brand-new branch can push with an all-zero "before" sha. Linting the
# default range then may check nothing while reporting success, so the fallback
# lints the pushed commit explicitly (and fails if it cannot be read).
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
echo "no usable base sha; linting the pushed commit ${HEAD_SHA} via --single"
node scripts/check-commit-messages.mjs --single "$HEAD_SHA"
else
node scripts/check-commit-messages.mjs "$BASE_SHA" "$HEAD_SHA" "${PR_TITLE:-}"
fi
Expand Down Expand Up @@ -82,9 +81,21 @@ jobs:
run: pnpm test

- name: Documentation drift
# Fails while SPEC.md/API.md and the code disagree (env vars, routes, settings).
# Fails while SPEC.md/API.md and the code disagree (env vars, routes, settings)
# and while .env.example / documented defaults disagree with src/config.ts.
run: pnpm check:docs

- name: Env template parity
run: pnpm check:env-example

- name: Negative self-tests (the enforcement scripts must still fail on bad input)
# Each self-test builds throw-away fixtures and exits non-zero when a bad case is
# wrongly accepted, so a silently disabled check cannot pass CI.
run: |
pnpm exec tsx scripts/check-docs.ts --self-test
pnpm exec tsx scripts/check-env-example.ts --self-test
node scripts/check-commit-messages.mjs --self-test

build-and-e2e:
name: Build & e2e
runs-on: ubuntu-latest
Expand Down Expand Up @@ -113,7 +124,10 @@ jobs:
# The e2e suite boots src/index.ts through tsx; this proves dist/ actually runs.
run: |
DATA_DIR="$(mktemp -d)"
# Keep the smoke test off the checkout and the developer/runner data dir.
WEB_DIST_DIR="$PWD/web/dist"
PORT=20198 HOST=127.0.0.1 LOG_LEVEL=warn NODE_ENV=production \
DATA_DIR="$DATA_DIR" WEB_DIST_DIR="$WEB_DIST_DIR" \
node dist/src/index.js > "$RUNNER_TEMP/smoke.log" 2>&1 &
SERVER_PID=$!
READY=0
Expand Down
59 changes: 51 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,66 @@ React 19 + Tailwind CSS 4. Default port **20125**.
pnpm install # install dependencies (Node 22+, pnpm 10+; see .nvmrc)
pnpm dev # API with watch (port 20125, serves web/dist)
pnpm dev:web # dashboard dev server (proxies /admin and /v1)
pnpm verify # one local gate mirroring CI (typecheck → test → check:docs → build → test:e2e)
pnpm verify --fast # same gate without build + test:e2e (pre-commit loop)
pnpm typecheck # server + web + tests/scripts type checks (tsconfig.test.json)
pnpm test # vitest unit suite
pnpm check:docs # doc-drift check: env vars, routes, settings vs docs/SPEC.md + docs/API.md
pnpm check:docs # doc-drift check: env vars, routes, settings vs docs/SPEC.md + docs/API.md + .env.example
pnpm check:env-example # .env.example ↔ src/config.ts parity + documented-default comparison
pnpm test:e2e # full acceptance: real server + deterministic mock upstreams
pnpm test:live # smoke test against a real provider (skips on upstream 429)
pnpm build # tsc -> dist/ and vite -> web/dist/
pnpm start # run the compiled server (node dist/src/index.js)
pnpm exec tsx scripts/screenshots.ts --strict # headless Chrome UI check; fails (not SKIP) without Chrome
```

Script env knobs: `E2E_PORT`/`E2E_MOCK_A_PORT`/`E2E_MOCK_B_PORT` (e2e, defaults 20197/20196/20195),
`MOCK_PORT`/`MOCK_NAME`/`MOCK_KEY` (mock upstream), `LIVE_PORT`/`LIVE_UPSTREAM`/`LIVE_KEY`/`LIVE_MODEL`/
`LIVE_VISION_MODEL` (live check), `CHROME_PATH` (screenshots). `pnpm lint:commits` runs the commit-message
linter against `origin/main..HEAD`.
Negative self-tests (they build throw-away fixtures and must reject every bad case; CI runs
them in the `Lint & test` job):

Before opening a PR run at least:
`pnpm typecheck && pnpm test && pnpm check:docs && pnpm build && pnpm test:e2e`.
```bash
pnpm self-test:docs # check-docs + check-env-example fixtures
pnpm self-test:commits # commit-linter fixtures
pnpm exec tsx scripts/check-docs.ts --self-test
pnpm exec tsx scripts/check-env-example.ts --self-test
node scripts/check-commit-messages.mjs --self-test
```

Commit linting locally:

```bash
pnpm lint:commits # origin/main..HEAD
node scripts/check-commit-messages.mjs <base-sha> <head-sha> "<pr title>"
node scripts/check-commit-messages.mjs --single <sha> # lint exactly one commit
node scripts/check-commit-messages.mjs --self-test
```

### Script env knobs

Every knob read by a script (this list is complete; defaults in parentheses):

| Script | Knob | Meaning |
| --- | --- | --- |
| `scripts/e2e.ts` | `E2E_PORT` (20197) | Gateway port of the main harness |
| `scripts/e2e.ts` | `E2E_MOCK_A_PORT` (20196) | Mock upstream A port |
| `scripts/e2e.ts` | `E2E_MOCK_B_PORT` (20195) | Mock upstream B port |
| `scripts/e2e.ts` | `E2E_ALT_PORT` | Fixed port for the auxiliary SSRF/brute-force server (default: a free ephemeral port) |
| `scripts/mock-upstream.ts` | `MOCK_PORT` (20196) | Mock upstream port (`pnpm mock`) |
| `scripts/mock-upstream.ts` | `MOCK_NAME` (`mock`) | Provider/model name the mock advertises |
| `scripts/mock-upstream.ts` | `MOCK_KEY` (`sk-dummy-123`) | API key the mock expects |
| `scripts/live-check.ts` | `LIVE_PORT` (20194) | Router port for the live check |
| `scripts/live-check.ts` | `LIVE_UPSTREAM` (fallback `E2E_UPSTREAM`, default `http://127.0.0.1:20123/v1`) | Real provider base URL |
| `scripts/live-check.ts` | `LIVE_KEY` (fallback `E2E_UPSTREAM_KEY`, default `sk-dummy-123`) | Real provider API key |
| `scripts/live-check.ts` | `LIVE_MODEL` (`opencode/flint-40b-free`) | Chat/responses model under test |
| `scripts/live-check.ts` | `LIVE_VISION_MODEL` (`opencode/hy4-flash-free`) | Vision model under test |
| `scripts/screenshots.ts` | `CHROME_PATH` | Chrome/Chromium binary (default: the macOS Chrome path) |

`scripts/screenshots.ts` flags: `--out <dir>` (`./tmp/screenshots`), `--port <n>` (20193),
`--mockPort <n>` (20192), `--cdpPort <n>` (9333), `--strict` (fail instead of skipping when
Chrome is unusable). No CI job runs this harness — it needs a browser and is explicitly
deferred (see `README.md` → Verification).

Before opening a PR run `pnpm verify` (or at least
`pnpm typecheck && pnpm test && pnpm check:docs && pnpm build && pnpm test:e2e`).

## Layout

Expand All @@ -70,7 +113,7 @@ Before opening a PR run at least:
| `src/gateway/` | `/v1/*` auth, rotation, pass-through proxy, `/v1/models` |
| `src/admin/` | `/admin/api/*` (auth, providers, models, keys, logs, settings), scheduler |
| `web/` | React 19 + Tailwind dashboard (Vite root, builds to `web/dist`) |
| `scripts/` | e2e, live check, mock upstream, commit-message linter, doc-drift checker, screenshots |
| `scripts/` | e2e, live check, mock upstream, commit-message linter, doc-drift + `.env.example` checkers, `verify.ts` gate, screenshots |
| `tests/` | vitest unit tests (incl. `tooling.test.ts` for the repo scripts) |
| `docs/` | `SPEC.md` (contract), `API.md` (gateway reference), screenshots |
| `.github/workflows/` | CI |
Expand Down
19 changes: 16 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ because tooling generates them. The linter fails when an explicitly supplied bas
commits (an empty check must not pass), and CI lints pushes to `main` in addition to pull requests. Squash
merges use the PR title, which is why the title must follow the same format.

Optional local helper:
Optional local helpers:

```bash
pnpm lint:commits # origin/main..HEAD
node scripts/check-commit-messages.mjs origin/main HEAD "feat(gateway): my change"
node scripts/check-commit-messages.mjs --single "$(git rev-parse HEAD)" # lint one commit
node scripts/check-commit-messages.mjs --self-test # prove the rules still reject bad input
```

## Pull request flow
Expand All @@ -109,14 +112,21 @@ pull request that passes the required checks.
1. Branch from `main` using a descriptive name, e.g. `feat/provider-rotation`,
`fix/dashboard-session`, `docs/api-reference`.
2. Make focused commits (the linter checks each one; keep history clean).
3. Run the full verification locally:
3. Run the full verification locally — `pnpm verify` runs exactly these stages in order
and stops at the first failure (`pnpm verify --fast` skips `build` + `test:e2e`):
```bash
pnpm verify
# equivalent one-by-one:
pnpm typecheck
pnpm test
pnpm check:docs
pnpm check:docs # also checks .env.example and the documented defaults
pnpm check:env-example
pnpm build
pnpm test:e2e
```
The enforcement scripts have negative self-tests (`pnpm self-test:docs`,
`pnpm self-test:commits`, or the `--self-test` flags); they must exit 0 and must exit
non-zero when a fixture is deliberately broken. CI runs them in `Lint & test`.
4. Push the branch and open a PR:
```bash
git push -u origin feat/provider-rotation
Expand All @@ -131,6 +141,9 @@ pull request that passes the required checks.
A PR that changes the gateway contract, the database schema or the admin API must also
update `docs/SPEC.md` and call the change out in the PR description. New env vars, routes or
`DEFAULT_SETTINGS` keys must be documented or `pnpm check:docs` fails — fix the docs, never the checker.
That check also compares `.env.example` with the env vars read under `src/**` and the defaults
documented in `docs/SPEC.md` with the code defaults, so a new variable needs an `.env.example`
entry as well.

## Reporting bugs / requesting features

Expand Down
Loading
Loading