|
| 1 | +# Agent instructions for this project |
| 2 | + |
| 3 | +## Package manager |
| 4 | +- Use `pnpm` for all package management |
| 5 | + |
| 6 | +## Setup and Commands |
| 7 | + |
| 8 | +### Initial Setup Checklist |
| 9 | +1. Create a `.env` file in the project root (loaded via `dotenv/config`) |
| 10 | +2. Verify all required environment variables are set and non-empty: |
| 11 | + - `VRCHAT_EMAIL` |
| 12 | + - `VRCHAT_USERNAME` |
| 13 | + - `VRCHAT_PASSWORD` |
| 14 | + - `VRCHAT_TOTP_SECRET` |
| 15 | + - `VRCHAT_FRIEND_ID` |
| 16 | + - `VRCHAT_GROUP_ID` |
| 17 | + - **If any variable is missing, empty, or malformed, stop immediately and print the exact variable names that must be set before any test run.** |
| 18 | +3. Before every local test run, execute `pnpm test:clean` first. Do not reuse any existing `data/state/` or AVA cache from a previous run. (CI does this automatically.) |
| 19 | +4. Execute `pnpm get-spec` to download the latest `openapi-internal+legacy.yaml` to `openapi.yaml` (CI does this automatically). |
| 20 | + |
| 21 | +### Available Commands |
| 22 | +- `pnpm test` — run all tests (AVA; serial mode configured in `ava.config.js`) |
| 23 | +- `pnpm fast-fail` — stop on first failure |
| 24 | +- `pnpm type-check` — TypeScript type check |
| 25 | +- `pnpm test:clean` — clear `data/state` and AVA cache (`pwsh ./scripts/clean.ps1`) |
| 26 | +- `pnpm get-spec` — download latest `openapi-internal+legacy.yaml` to `openapi.yaml` |
| 27 | + |
| 28 | +## Project purpose |
| 29 | +Integration-test suite against the live VRChat API. Downloads the latest `openapi-internal+legacy.yaml` from vrchatapi/specification releases, then validates actual API responses against the schema. |
| 30 | + |
| 31 | +## Test structure |
| 32 | +- Test files in `tests/*.ts`, run in the order defined by `tests/_order.json`: authentication → users → worlds → instances → avatars (then alphabetical) |
| 33 | +- All tests are serial (`ava --serial`) |
| 34 | +- Tests share state via `data/state/` (files on disk — cookies, session data, cached values) |
| 35 | +- Test results recorded as markdown to `data/requests/` |
| 36 | + |
| 37 | +## Running tests |
| 38 | + |
| 39 | +### Authentication and Error Handling |
| 40 | +- Auth flow: login with Basic auth → 2FA TOTP → verify → cookie-based reuse |
| 41 | +- Rate-limit protection: 200ms between requests, exponential backoff up to 10 retries on 429 |
| 42 | +- **If login fails, TOTP verification fails, or cookie-based reuse cannot be established, abort the run immediately with a clear error message and do not continue with partial state.** |
| 43 | + |
| 44 | +## Test patterns |
| 45 | +- `testOperation` macro (from `_utilities.ts`) handles: parameter injection, schema validation (`@exodus/schemasafe` lax mode), response logging |
| 46 | +- `unstable: true | string[]` — marks response values that change every run (timestamps, versions, etc.) |
| 47 | +- `sensitive: true` — redacts the entire response body |
| 48 | +- `test.todo(...)` — placeholder for unimplemented endpoints |
| 49 | +- Use `test.before(failUnauthenticated)` in files that need a logged-in user |
| 50 | + |
| 51 | +## Key files |
| 52 | +- `tests/_utilities.ts` — core test framework (fetch, schema validation, request/response recorder) |
| 53 | +- `tests/_consts.ts` — env vars, shared constants like `tupperUserId`, `defaultAvatarId` |
| 54 | +- `tests/_cache.ts` — file-based state and caching, sensitive/unstable value tracking |
| 55 | +- `tests/_users.ts` — shared unstable key lists (e.g. `unstableUserKeys`) |
| 56 | +- `ava.config.js` — AVA config with serial mode, custom test ordering via `_order.json`, tsx loader |
| 57 | +- `scripts/clean.ps1` — clears `data/state/` and AVA cache for a fresh run (`pnpm test:clean`) |
| 58 | +- `scripts/get-spec.ps1` — downloads latest `openapi-internal+legacy.yaml` to `openapi.yaml` |
| 59 | +- `openapi.yaml` (in `.gitignore`) — downloaded at test time by CI or `scripts/get-spec.ps1` |
| 60 | +- `data/` — ignored except for `data/requests/` (test output committed by CI) |
| 61 | + |
| 62 | +## CI |
| 63 | +GitHub Actions runs daily (or manual dispatch). Downloads spec via curl+jq, clears `data/state/`, runs `ava --serial`, commits updated `data/requests/` back to repo. |
0 commit comments