Turn per-user token quota off by default; keep code for later

This commit is contained in:
2026-08-21 12:51:29 -07:00
parent f1200b7d79
commit fac6e7f356
4 changed files with 54 additions and 39 deletions

View File

@@ -29,12 +29,12 @@ If either command fails, install Docker before you continue.
APP_USERS=tester:test-password-123,tester2:test-password-456
RATE_LIMIT_MAX=5
RATE_LIMIT_WINDOW_MS=60000
TOKEN_LIMIT_PER_USER=2000
TOKEN_USAGE_FILE=./data/token-usage.json
```
4. Save the file.
Use a personal or trial API key here, not the company-billed key. Keep the company key for the real deployment. `APP_USERS` sets up two logins so you can confirm each person gets a separate quota. `RATE_LIMIT_MAX=5` with a 60 second window makes the rate limit easy to trigger on purpose. `TOKEN_LIMIT_PER_USER=2000` is deliberately low, so you can hit the daily quota in a couple of clicks instead of a couple hundred.
Use a personal or trial API key here, not the company-billed key. Keep the company key for the real deployment. `APP_USERS` sets up two logins so you can confirm each person gets their own. `RATE_LIMIT_MAX=5` with a 60 second window makes the rate limit easy to trigger on purpose.
`TOKEN_LIMIT_PER_USER` is left out of this file on purpose: the per-user daily token quota ships off by default (see Step 9, optional). Leave it out unless you specifically want to test that feature.
`.env` is not tracked by Git. Docker Compose reads it automatically because `docker-compose.yml` lists it under `env_file`.
@@ -92,18 +92,22 @@ Use a personal or trial API key here, not the company-billed key. Keep the compa
2. Confirm the next click returns a rate-limit message instead of a normal draft or a silent failure.
3. Wait for the time window to pass, then confirm the button works again.
## Step 9: Test the per-user token quota
## Step 9 (optional): Test the per-user token quota
1. Log in as `tester` and click the AI draft button once or twice, until the response reports a quota error instead of a draft. With `TOKEN_LIMIT_PER_USER=2000`, this takes one or two clicks.
2. Confirm the error names `tester`, the tokens used, the limit, and a countdown to the reset.
3. Open a new private or incognito browser window and log in as `tester2` instead.
4. Confirm `tester2` can still click the AI draft button. Each named user has a separate quota.
5. Run this command to view the usage file directly:
Skip this step for a normal test run. The quota ships off by default; this is only for confirming the feature still works if you turn it back on.
1. Add `TOKEN_LIMIT_PER_USER=2000` to `.env` and restart: `docker compose up -d --build`.
2. Log in as `tester` and click the AI draft button once or twice, until the response reports a quota error instead of a draft.
3. Confirm the error names `tester`, the tokens used, the limit, and a countdown to the reset.
4. Open a new private or incognito browser window and log in as `tester2` instead.
5. Confirm `tester2` can still click the AI draft button. Each named user has a separate quota.
6. Run this command to view the usage file directly:
```
cat data/token-usage.json
```
6. Confirm it lists a separate entry for each user who made a call, with today's date and a token count.
7. Run `docker compose restart`, then confirm `tester` is still blocked. The quota survives a restart because `data` is a mounted volume.
7. Confirm it lists a separate entry for each user who made a call, with today's date and a token count.
8. Run `docker compose restart`, then confirm `tester` is still blocked. The quota survives a restart because `data` is a mounted volume.
9. Remove `TOKEN_LIMIT_PER_USER` from `.env` and restart again to turn it back off.
## Step 10: Stop the container