@lago-morph/create-prototype-app 0.1.0 → 0.2.0-rc02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +9 -2
  2. package/bin/create-prototype-app.js +26 -10
  3. package/lib/create.mjs +115 -2
  4. package/package.json +1 -1
  5. package/skill/SKILL.md +19 -26
  6. package/skill/VERSION +1 -0
  7. package/skill/examples/notes-sql.md +1 -1
  8. package/skill/examples/secrets.md +20 -1
  9. package/skill/examples/tests.md +109 -0
  10. package/skill/reference/configuration.md +4 -4
  11. package/skill/reference/current-user.md +10 -10
  12. package/skill/reference/deploying.md +6 -8
  13. package/skill/reference/files.md +1 -1
  14. package/skill/reference/http-and-validation.md +1 -1
  15. package/skill/reference/kv.md +1 -1
  16. package/skill/reference/local-development.md +2 -2
  17. package/skill/reference/log.md +1 -1
  18. package/skill/reference/owner-tasks.md +53 -67
  19. package/skill/reference/secrets.md +3 -3
  20. package/skill/reference/sql-and-migrations.md +3 -3
  21. package/skill/reference/testing/e2e.md +44 -0
  22. package/skill/reference/testing/failures.md +44 -0
  23. package/skill/reference/testing/fuzzing.md +28 -0
  24. package/skill/reference/testing/test-changes.md +42 -0
  25. package/skill/reference/testing.md +33 -22
  26. package/skill/reference/troubleshooting.md +12 -15
  27. package/skill/templates/FRAMEWORK-ISSUE.md +1 -1
  28. package/skill/templates/README.md +1 -1
  29. package/skill/templates/production-stage.json +1 -3
  30. package/template/.claude/settings.json +36 -0
  31. package/template/README.md +27 -66
  32. package/template/gitignore +3 -0
  33. package/template/package.json +10 -4
  34. package/template/playwright.config.ts +31 -0
  35. package/template/src/server/routes/notes.ts +1 -1
  36. package/template/src/server/signing.ts +4 -1
  37. package/template/tests/e2e/api/notes.spec.ts +74 -0
  38. package/template/tests/e2e/ui/account.spec.ts +22 -0
  39. package/template/tests/fuzz.test.ts +22 -0
  40. package/template/tests/signing.test.ts +16 -0
  41. package/template/tests/support/fuzz.test.ts +72 -0
  42. package/template/tests/support/fuzz.ts +88 -0
@@ -1,15 +1,13 @@
1
1
  # Deploying
2
2
 
3
- Read this when you deploy, smoke-test, stop, start or remove a stage on a cloud. Account setup, the API token, the email domain, secrets, sign-up and admins are in [owner-tasks.md](owner-tasks.md).
3
+ Read this when you deploy, smoke-test, stop, start or remove a stage on a cloud. Cloudflare setup (the one token), secrets, sign-in and admins are in [owner-tasks.md](owner-tasks.md).
4
4
 
5
- Commands run in the app's directory, with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` set ([owner-tasks.md](owner-tasks.md) §2). Each `npm run <command> -- …` is the same as `npx prototype-framework <command> …`. Behind an HTTPS proxy, put `NODE_USE_ENV_PROXY=1 ` in front of every cloud command; the command says so if it is needed.
6
-
7
- **Status in this phase:** every command on this page is **not yet verified on Cloudflare in this phase**. The framework's cloud commands have run only against a simulated Cloudflare. Only the Cloudflare API call that `stop` and `start` use (§4) was tried on a real Worker. AWS is a future release: this release deploys to Cloudflare only.
5
+ Commands run in the app's directory, after `npm run cloudflare-setup` has said everything is set up ([owner-tasks.md](owner-tasks.md) §2); each reads the token itself, from the environment or `~/.secrets/cloudflare`. Each `npm run <command> -- …` is the same as `npm exec --no -- prototype-framework <command> …`. Behind an HTTPS proxy, put `NODE_USE_ENV_PROXY=1 ` in front of every cloud command; the command says so if it is needed.
8
6
 
9
7
  ## 1. Test stages and production stages
10
8
 
11
- - A stage whose name starts with `test-` is a **test stage**. It uses `config/cloudflare/test.json`, has the mock login for tests beside email-and-password sign-in, keeps its mail in a test capture (never sent), holds no real data, and is removed after use.
12
- - Every other stage is a **production stage**, for example `prod`. It needs its own committed `config/cloudflare/<stage>.json` ([owner-tasks.md](owner-tasks.md) §5) and the account's email domain (§3 there). It has no mock: people sign up with email and password, and real mail is sent from `no-reply@<domain>`.
9
+ - A stage whose name starts with `test-` is a **test stage**. It uses `config/cloudflare/test.json`, has only the mock login for tests (no real sign-in), holds no real data, and is removed after use.
10
+ - Every other stage is a **production stage**, for example `prod`. It needs its own committed `config/cloudflare/<stage>.json` ([owner-tasks.md](owner-tasks.md) §5) and the account's auth app (§2 there). It has no mock: members of the owner's Cloudflare account sign in with Cloudflare.
13
11
  - A stage name is at most 20 lowercase letters, digits and hyphens. The stage's address is `https://<app>-<stage>.<subdomain>.workers.dev`.
14
12
 
15
13
  ## 2. Deploy and smoke-test a test stage
@@ -44,8 +42,8 @@ npm run smoke -- --target cloudflare --stage "$STAGE"
44
42
  npm run secrets -- set apiKey --target cloudflare --stage "$STAGE"
45
43
  npm run deploy -- --target cloudflare --stage "$STAGE"
46
44
  ```
47
- It prints the stage's address, its sign-in page and the sender address.
48
- 3. Sign up on the stage, then make yourself an admin with `admins grant` ([owner-tasks.md](owner-tasks.md) §6, §7). Admins change without a deploy.
45
+ It registers the stage with the auth app and prints the stage's address.
46
+ 3. Sign in on the stage ([owner-tasks.md](owner-tasks.md) §6). Admins are the account's administrators (§7 there); they change without a deploy.
49
47
 
50
48
  To change a production stage later (code or configuration), commit the change and run `deploy` again:
51
49
 
@@ -62,4 +62,4 @@ The ticket is the same JSON on every target: `{ url, method?, headers?, expiresA
62
62
 
63
63
  ## Stopping condition
64
64
 
65
- Stop reading when your server builds every file name itself, authorizes from your records, issues tickets with explicit content types, checks uploads with `head` before making them visible, serves content only through `downloadUrl`, and `npx prototype-framework verify` passes.
65
+ Stop reading when your server builds every file name itself, authorizes from your records, issues tickets with explicit content types, checks uploads with `head` before making them visible, serves content only through `downloadUrl`, and `npm run verify` passes.
@@ -88,4 +88,4 @@ API responses are never cached (`Cache-Control: no-store`); you need not set cac
88
88
 
89
89
  ## Stopping condition
90
90
 
91
- Stop reading when your route has a guard (or is deliberately open), validates its input, throws only the four codes above, returns a shared type, has a test, and `npx prototype-framework verify` passes. For storage inside the route, read only the reference for that capability.
91
+ Stop reading when your route has a guard (or is deliberately open), validates its input, throws only the four codes above, returns a shared type, has a test, and `npm run verify` passes. For storage inside the route, read only the reference for that capability.
@@ -38,4 +38,4 @@ KV behaves identically on every target; you never see where it is stored.
38
38
 
39
39
  ## Stopping condition
40
40
 
41
- Stop reading when every key your code builds has a fixed prefix plus trusted IDs, values stay under 4,096 bytes, `list` callers pass the cursor back with the same prefix, and `npx prototype-framework verify` passes.
41
+ Stop reading when every key your code builds has a fixed prefix plus trusted IDs, values stay under 4,096 bytes, `list` callers pass the cursor back with the same prefix, and `npm run verify` passes.
@@ -32,7 +32,7 @@ Then:
32
32
 
33
33
  ## Commands
34
34
 
35
- Run them in the app directory, as `npm run <command>` or `npx prototype-framework <command>`:
35
+ Run them in the app directory, as `npm run <command>` (flags after `--`) or `npm exec --no -- prototype-framework <command>` (never plain `npx`: before `npm install` it would fetch an unrelated package of that name from the registry):
36
36
 
37
37
  | Command | Does |
38
38
  | --- | --- |
@@ -70,4 +70,4 @@ Run them in the app directory, as `npm run <command>` or `npx prototype-framewor
70
70
 
71
71
  ## Stopping condition
72
72
 
73
- Stop reading when `npm run dev` serves your app at `http://localhost:<port>/`, you can log in with the mock, and `npx prototype-framework verify` passes. For deploying to a cloud, read [deploying.md](deploying.md).
73
+ Stop reading when `npm run dev` serves your app at `http://localhost:<port>/`, you can log in with the mock, and `npm run verify` passes. For deploying to a cloud, read [deploying.md](deploying.md).
@@ -51,4 +51,4 @@ On a connected test stage (`connectTestStage`) `logs()` throws: entries are in t
51
51
 
52
52
  ## Stopping condition
53
53
 
54
- Stop reading when your code logs what only it knows, without secrets or personal data, does not duplicate the framework's error entries, your error displays show the request ID, and `npx prototype-framework verify` passes.
54
+ Stop reading when your code logs what only it knows, without secrets or personal data, does not duplicate the framework's error entries, your error displays show the request ID, and `npm run verify` passes.
@@ -1,10 +1,8 @@
1
1
  # Owner tasks
2
2
 
3
- Read this when the app's owner (or an agent acting for them) must do something outside the code: set up the Cloudflare account, its token and its email domain, set secrets, create a production stage, sign up and sign in, make someone an admin, or keep costs down. Give the owner these steps as written. The owner does not read code.
3
+ Read this when the app's owner (or an agent acting for them) must do something outside the code: set up Cloudflare (one token, one command), set secrets, create a production stage, sign in, make someone an admin, or keep costs down. Give the owner these steps as written. The owner does not read code.
4
4
 
5
- Commands run in a terminal, in the app's directory, on macOS or Linux with Node 22.22.0. Replace `<…>` parts; `<domain>` is the account's email domain. Never paste a secret value into a command line, a file in the repository, or a chat.
6
-
7
- **Status in this phase.** The local steps are verified. The Cloudflare steps have run against a simulated Cloudflare, and the email setup once against the real account; treat the rest as **not yet verified on Cloudflare**. If a step fails, follow [troubleshooting.md](troubleshooting.md).
5
+ Commands run in a terminal, in the app's directory, on macOS or Linux with Node 22.22.0. Replace `<…>` parts. Never paste a secret value or a token into a command line, a file in the repository, or a chat.
8
6
 
9
7
  ## 1. Before anything else (once per checkout)
10
8
 
@@ -16,7 +14,7 @@ npm run build -w packages/framework
16
14
  cd apps/template
17
15
  ```
18
16
 
19
- An app made with the scaffolder already has the built framework. There, run `npm install` once in the app's directory.
17
+ An app made with `npm create` is already installed.
20
18
 
21
19
  Set the stage's name in `STAGE` once in each new terminal (`<stage>` is for example `test-abc` or `prod`):
22
20
 
@@ -24,36 +22,47 @@ Set the stage's name in `STAGE` once in each new terminal (`<stage>` is for exam
24
22
  STAGE='<stage>'
25
23
  ```
26
24
 
27
- ## 2. Cloudflare account and API tokens (once)
25
+ ## 2. Cloudflare: one token, one command
28
26
 
29
- 1. Sign up or log in at https://dash.cloudflare.com. The email domain must be a zone on this account, with Cloudflare DNS active (Websites → Add a site). Its mail need not be on Cloudflare: the framework uses the subdomain `t.<domain>` for test mail.
30
- 2. Copy your **Account ID** from the account's overview page (menu names here are not yet verified).
31
- 3. Create two **account API tokens**: Manage Account → Account API Tokens → Create Token → Create Custom Token. Account resources: this account only; zone resources: the email domain's zone. Copy each token when shown; Cloudflare shows it only once.
32
- - **Everyday token** `prototype-framework`, for every command but `setup-account`, including `stop`, `start` and the backup a production `remove` writes. Account: Workers Scripts Edit, Workers R2 Storage Edit, D1 Edit, Email Sending Read. Zone: Zone Read, Analytics Read. It cannot create tokens. It needs no Billing permission: if Cloudflare refuses a new database because the account has too many, the message names both plans' limits (put `PROTOTYPE_FRAMEWORK_CLOUDFLARE_PLAN=free` or `=paid` in front of the command to name yours).
33
- - **Setup token** `prototype-framework-setup`, for `setup-account` only (§3), used rarely. Account: Workers Scripts Edit, Workers R2 Storage Edit, Account API Tokens Edit, Email Sending Edit, Email Routing Addresses Edit. Zone: Email Routing Rules Edit, DNS Edit, Zone Settings Edit, Zone Read. Store it apart from the everyday token.
27
+ Any Cloudflare account works, on the free Workers plan too. No domain is needed. You need one Cloudflare API token and your account ID. The steps, in order:
34
28
 
35
- A command names any permission its token lacks.
36
- 4. In each new terminal, set both values; paste the everyday token when `read` waits, then press Enter (`read` keeps it out of your shell history):
29
+ 1. **Run the setup.** It prints no token value and does only what is missing:
37
30
  ```sh
38
- export CLOUDFLARE_ACCOUNT_ID='<your Account ID>'
39
- read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN
31
+ npm run cloudflare-setup
40
32
  ```
41
- 5. Check the token. The output must contain `"success":true`:
42
- ```sh
43
- curl -sS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/tokens/verify"
33
+ With no token yet, it prints this two-line template, where the lines go, the token's pre-filled link and the next prompt:
34
+ ```
35
+ CLOUDFLARE_API_TOKEN=
36
+ CLOUDFLARE_ACCOUNT_ID=
44
37
  ```
38
+ 2. **Make the token** `prototype-framework-cli` from that link, logged in to the dashboard. Its permissions and name are filled in; keep them (more is fine). Pick your account if asked and choose any end date, or none. Then Continue to summary, Create Token, and copy it: Cloudflare shows it only once. A token you already have with more permissions (an account admin token, say) works too. Your **account ID** is on the account's home page in the dashboard.
39
+ 3. **Fill in the two lines and put them in one place** (the environment wins when both are set):
40
+ - **On your computer:** the file `~/.secrets/cloudflare` in your home directory, then `chmod 600 ~/.secrets/cloudflare`. Every app, worktree and Claude Code session on the machine shares it. `CLOUDFLARE_SECRETS_FILE` names another path if you want one.
41
+ - **In a Claude Code cloud session:** the environment's settings (environment menu → Edit → Environment variables), the same two lines; then start a new session.
42
+ Never paste the token into the chat or into a file in the repository.
43
+ 4. **Run `npm run cloudflare-setup` again** (in Claude Code, say **"continue prototype setup"**). It says where each value came from (the variable or the file, never the value), checks the token's permissions, and sets the account up in one run: the admin app's client and the sign-in client with their secrets in Cloudflare's Secrets Store, the **admin app**, the account's **auth app** (it signs people in to every app) and the shared resources (§3). It ends with "Cloudflare setup is complete" and the next step, a `deploy` of a `test-` stage. Run again, it says everything is already set up.
45
44
 
46
- If a command says it needs `NODE_USE_ENV_PROXY=1`, you are behind an HTTPS proxy: put `NODE_USE_ENV_PROXY=1 ` in front of that command.
45
+ **The framework never deletes, rolls or changes your token.** It makes and replaces only the tokens it needs for itself (the file-signing token `prototype-r2-signing`). The admin app (its address is printed once) is optional: it has status and cleanup pages.
47
46
 
48
- ## 3. One-time account setup, with the email domain
47
+ **When setup stops** (exit status 1), it says what is missing with the link or command to use. Do that, then run it again; it exits 0 only when all is set up:
49
48
 
50
- Paste the **setup token** into `read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN` (§2), run, then set the everyday token again the same way:
49
+ | It says | Do this |
50
+ | --- | --- |
51
+ | no Cloudflare credential, or one of the two settings is not set | steps 2–3 |
52
+ | the token is not accepted or not active | make a token from the link (step 2) and replace `CLOUDFLARE_API_TOKEN` |
53
+ | the token lacks these permissions (named) | add them to the token in the dashboard (Manage account → Account API tokens → the token → Edit), or make a new one from the link |
54
+ | the token cannot read its own permissions | it lacks Account API Tokens Edit: add it, or make a new token from the link |
55
+ | the token cannot see the account `CLOUDFLARE_ACCOUNT_ID` names (accounts listed by name) | set `CLOUDFLARE_ACCOUNT_ID` to the right account's ID, or make the token on that account |
56
+ | the secrets file can be read by other users | `chmod 600 ~/.secrets/cloudflare` (a warning only) |
57
+ | `.env.cloudflare` or `CLOUDFLARE_BOOTSTRAP_TOKEN` is no longer used | move the token and account ID to `~/.secrets/cloudflare` (or the environment), then delete the old file or variable |
58
+ | a host is blocked | allow `api.cloudflare.com`, `*.r2.cloudflarestorage.com` and `*.workers.dev` in the environment's network access settings |
59
+ | an old `.env.cloudflare` is not ignored, or is tracked | setup adds the `.gitignore` line unless it holds `# keep-env-cloudflare-tracked`. Tracked: delete the tokens it held, `git rm --cached .env.cloudflare`, commit |
51
60
 
52
- ```sh
53
- npm run setup-account -- --target cloudflare --email-domain <domain>
54
- ```
61
+ The git warnings never stop a command. Setup also never touches a token whose ID is in `PROTOTYPE_FRAMEWORK_PROTECTED_TOKEN_IDS` (comma-separated).
62
+
63
+ ## 3. What the account setup creates
55
64
 
56
- This creates the shared resources once per account, including the file-signing credential every stage uses: the log bucket `prototype-logs`, the deploy-state bucket `sst-state`, the backup bucket `prototype-backups` (a removed production stage's data, kept 30 days), the `workers.dev` address, sending from `no-reply@<domain>`, and the test mailbox: mail to `sink+<tag>@t.<domain>` is stored for a day, so an agent can read it. When it creates the mailbox rule it waits about a minute, so the first test mail does not arrive before the rule. Running it again changes nothing. To change the domain later, run it with the new `--email-domain`. `deploy` never creates these resources; if they are missing, it tells you to run this command. An account set up before the backup bucket or the file-signing credential existed needs this command once more, with the setup token: `deploy` then names what is missing and tells you to run it. When that run replaces the file-signing credential, it says so: then redeploy every deployed stage (`npm run deploy -- --target cloudflare --stage <stage>`, with the everyday token), because each one keeps the old key, and its file uploads and downloads fail, until its next deploy.
65
+ `cloudflare-setup` creates, once per account: the admin app and the sign-in clients, the **auth app** with its database, the log bucket `prototype-logs`, the deploy-state bucket `sst-state`, the backup bucket `prototype-backups` (a removed production stage's data, kept 30 days), and the file-signing credential every stage uses, kept in Secrets Store. It records what it did in `framework/account.json` in `sst-state`. `deploy` never creates these resources; if they are missing, it says so. When setup replaces the file-signing credential, redeploy every deployed stage (`npm run deploy -- --target cloudflare --stage <stage>`): until then its file uploads and downloads fail. The admin app's Account setup page does the same and is optional.
57
66
 
58
67
  ## 4. Secrets
59
68
 
@@ -79,7 +88,7 @@ mkdir -p config/cloudflare
79
88
  cp ../../skill/templates/production-stage.json "config/cloudflare/$STAGE.json"
80
89
  ```
81
90
 
82
- Replace `REPLACE-WITH-THE-SENDER-NAME` with the display name of the sign-up and reset mail (or delete the `email` entry to use the app's name). `"values"` may set the app's configuration keys; ask the developer which. Then check, commit and deploy, setting the secrets the first deploy names ([deploying.md](deploying.md)):
91
+ `"values"` may set the app's configuration keys; ask the developer which. Then check, commit and deploy, setting the secrets the first deploy names ([deploying.md](deploying.md)):
83
92
 
84
93
  ```sh
85
94
  npm run build -- --target cloudflare --stage "$STAGE"
@@ -87,64 +96,41 @@ git add "config/cloudflare/$STAGE.json" && git commit -m "Add the values file of
87
96
  npm run deploy -- --target cloudflare --stage "$STAGE"
88
97
  ```
89
98
 
90
- The deploy prints the stage's address, its sign-in page and the sender address.
99
+ The deploy registers the stage with the auth app and prints its address. Without the account's auth app it names it and stops before creating anything: run `npm run cloudflare-setup` (§2) first.
91
100
 
92
- ## 6. Signing up and signing in
101
+ ## 6. Signing in
93
102
 
94
- **Anyone who signs up and verifies their address is a user.** No list decides who may log in.
103
+ **Only members of your Cloudflare account can sign in**, with their Cloudflare login. Anyone else is refused. No list in the app decides who may log in.
95
104
 
96
- 1. Open the stage's sign-in page (`<stage address>/api/auth/sign-in`; locally the app's login button). Choose "Create an account", and enter an email address, a password of 12 to 128 characters, and a display name.
97
- 2. Open the link in the "Confirm your email address" mail, and press the button.
98
- 3. Sign in. `<stage address>/api/auth/me` now shows `"level":"user"`.
105
+ 1. Open the stage's address and press the login button (or open `<stage address>/api/auth/login`).
106
+ 2. Sign in on Cloudflare's page, and allow the app to see your user details and memberships.
107
+ 3. You are back on the app. `<stage address>/api/auth/me` shows `"level":"user"` or `"level":"admin"`.
99
108
 
100
- Reading the mail without a mailbox (an agent, or local development):
101
-
102
- - **Locally** the mail is not sent; it is written to `.mail/`. Read the latest message to an address:
103
- ```sh
104
- npm run mail -- last --to '<address>'
105
- ```
106
- - **On Cloudflare**, sign up with a test address `sink+<tag>@t.<domain>` (`<tag>`: lowercase letters, digits, hyphens), then read it:
107
- ```sh
108
- npm run mail -- last --to 'sink+<tag>@t.<domain>' --target cloudflare
109
- ```
110
- - Without a browser, post the link's token (the value after `token=`) instead of pressing the button:
111
- ```sh
112
- curl -sS -X POST '<stage address>/api/auth/password/verify' -H 'Origin: <stage address>' -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"token":"<token>"}'
113
- ```
114
-
115
- A forgotten password: "Forgot your password?" on the sign-in page mails a reset link, valid for one hour. "Send a new confirmation link" there mails a new verification link.
109
+ To let someone sign in, invite them to the account (Manage Account → Members). A read-only role works, for example "HTTP Applications Read" (plan-v0.2.0 §2.1a). Locally and on `test-` stages there is no real sign-in: the login button signs in a test user.
116
110
 
117
111
  ## 7. Admins
118
112
 
119
- Admins hold the `admin` role in the stage's own database. Granting or revoking it needs no file edit, no commit and no deploy: it applies from the person's next request. The person must have signed up and verified their address on that stage first (§6).
120
-
121
- - **Grant** (on a production stage, repeat its name with `--confirm-production`):
122
- ```sh
123
- npm run admins -- grant '<address>' --target cloudflare --stage "$STAGE" --confirm-production "$STAGE"
124
- ```
125
- - **Revoke:** the same with `revoke`. The person is a user again.
126
- - **List** the stage's admins:
127
- ```sh
128
- npm run admins -- list --target cloudflare --stage "$STAGE" --confirm-production "$STAGE"
129
- ```
130
- - On a test stage, leave out `--confirm-production`. Locally, use `--target local` (no `--stage`); it works whether or not `npm run dev` runs.
113
+ **A member whose account role is "Super Administrator - All Privileges" or "Administrator" (PAR-413) is the app's admin**; every other member is a user. To make someone an admin, give them one of those roles in the dashboard (Manage Account → Members); to make them a user again, give them another role. No file edit, no commit and no deploy.
131
114
 
132
- It prints the account's user ID (as `/api/auth/me` shows it) and its roles, never a password or token. An address with no verified account is refused and nothing changes.
115
+ The apps learn a role change when the person **next signs in**, to any app on the account; their other open sessions pick it up within 5 minutes (PAR-425). Until then they keep their old level: ask them to log out and in again. Removing someone from the account stops new sign-ins, but a session they already have lasts until it expires (12 hours, PAR-250) or they log out.
133
116
 
134
- ## 8. Checking the real login (optional)
117
+ ## 8. Checking the real sign-in (optional)
135
118
 
136
- `npm run check-login -- --target cloudflare --stage "$STAGE"` signs up a fresh test address on a production stage, reads the real mail, verifies, signs in, grants and revokes `admin`, resets the password and checks the sign-in rate limit. It needs no input, prints no address or password, and writes an evidence record under `validation/`. It leaves one test account (with no role) on the stage.
119
+ `npm run check-login -- --target cloudflare --stage "$STAGE"` checks, on a production stage and with no sign-in, that the stage sends people to the auth app with its own address. It needs no input. The real sign-in itself needs a person: sign in once (§6).
137
120
 
138
121
  ## 9. Cost
139
122
 
140
- - Stopped or idle stages cost nothing for compute, but storage remains: the stage's D1 database and R2 file bucket, the shared `prototype-logs` bucket, and the `sst-state` bucket. Log entries are never deleted automatically. Test mail in the sink is deleted after a day.
141
- - On Cloudflare's free plan, D1 allows about **100,000 rows written per day** per account. The limit for reads is larger. When a limit is used up, database requests fail until it resets at 00:00 UTC.
142
- - Keep test stages small: a few rows of data, one test stage at a time, and `remove` it right after use. An account holds at most **10 D1 databases**, and a deploy that changes the schema briefly uses two per stage.
123
+ - Stopped or idle stages cost nothing for compute, but storage remains: the stage's D1 database and R2 file bucket, the shared `prototype-logs` bucket, the `sst-state` bucket, and the auth app's database. Log entries are never deleted automatically.
124
+ - Keep test stages small: a few rows of data, one test stage at a time, and `remove` it right after use. An account holds at most **10 D1 databases** (the auth app uses one), and a deploy that changes the schema briefly uses two per stage.
143
125
  - See [deploying.md](deploying.md) for deploy, stop/start and remove.
144
126
 
127
+ ## 10. Coming from 0.1.x
128
+
129
+ `npm run upgrade` to 0.2.0 says Cloudflare setup needs re-running. Once per account, do §2: put one token with the listed permissions (your old everyday token lacks some) and the account ID in `~/.secrets/cloudflare` or the environment, delete `.env.cloudflare`, and run `npm run cloudflare-setup`. Password accounts and sessions are gone, so everyone signs in again with Cloudflare; the old sign-in and test-mail tables are dropped on the next `dev` or `deploy`, and the app's own data stays. Remove `framework.email` from values files if you like: it is no longer used. The admin app's **Clean up v0.1.x email** page optionally removes the old email resources (sending domain, routing rules, test mailbox); nothing is removed automatically.
130
+
145
131
  ## Examples
146
132
 
147
- - [examples/configuration.md](../examples/configuration.md): the template's committed values files (`config/<target>/<stage>.json`), which hold the app's values and `framework.email`, and no admins.
133
+ - [examples/configuration.md](../examples/configuration.md): the template's committed values files (`config/<target>/<stage>.json`), which hold the app's values and no admins.
148
134
 
149
135
  ## Stopping condition
150
136
 
@@ -14,8 +14,8 @@ Values are not cached across requests (a value is reused only within one request
14
14
 
15
15
  A secret's value is read from standard input, never from a command-line argument or a file in the repository.
16
16
 
17
- - Local development: `printf '%s' 'the-value' | npx prototype-framework secrets set apiKey --target local --stage local`. It writes the git-ignored `.dev.vars` file and prints the name and location, never the value. `dev` also generates the framework's own local keys there on first start.
18
- - A cloud stage: `npx prototype-framework secrets set apiKey --target cloudflare --stage <stage>`, then type or paste the value and end input. On Cloudflare the stage's Worker must exist, so on a stage's first deploy `deploy` stops, names each unset secret, and asks you to set them and deploy again.
17
+ - Local development: `printf '%s' 'the-value' | npm run secrets -- set apiKey --target local --stage local`. It writes the git-ignored `.dev.vars` file and prints the name and location, never the value. `dev` also generates the framework's own local keys there on first start.
18
+ - A cloud stage: `npm run secrets -- set apiKey --target cloudflare --stage <stage>`, then type or paste the value and end input. On Cloudflare the stage's Worker must exist, so on a stage's first deploy `deploy` stops, names each unset secret, and asks you to set them and deploy again.
19
19
  - The owner's copy-and-paste steps for this are in [owner-tasks.md](owner-tasks.md).
20
20
 
21
21
  A deploy's health check fails when any declared secret has no value, so a secret the app declares must be set on every stage it is deployed to.
@@ -39,4 +39,4 @@ For a signed token such as a share link, copy the template's `src/server/signing
39
39
 
40
40
  ## Stopping condition
41
41
 
42
- Stop reading when every secret is declared in `secrets`, read only through `c.var.secrets.get`, never returned or logged, set on each stage with `secrets set`, given a value in tests, and `npx prototype-framework verify` passes.
42
+ Stop reading when every secret is declared in `secrets`, read only through `c.var.secrets.get`, never returned or logged, set on each stage with `secrets set`, given a value in tests, and `npm run verify` passes.
@@ -65,9 +65,9 @@ Build every write on the step's own `w`, never on `c.var.sql`; do not `await` in
65
65
  ## Migrations
66
66
 
67
67
  1. Change the tables in `src/server/schema.ts`.
68
- 2. Run `npm run generate-migration` (or `npx prototype-framework generate-migration --name <slug>`). It writes a pair of files, `migrations/sqlite/<nnnn>_<slug>.sql` and `migrations/postgres/<nnnn>_<slug>.sql`, plus snapshots under `meta/`, and records their checksums in `migrations/checksums.json`.
68
+ 2. Run `npm run generate-migration` (or `npm run generate-migration -- --name <slug>`). It writes a pair of files, `migrations/sqlite/<nnnn>_<slug>.sql` and `migrations/postgres/<nnnn>_<slug>.sql`, plus snapshots under `meta/`, and records their checksums in `migrations/checksums.json`.
69
69
  3. Commit all of them. Never edit a generated file. A migration that was never deployed to any cloud stage may be deleted (both files, their `meta/` snapshots) and generated again.
70
- 4. `npx prototype-framework verify` checks both histories give the same schema and that only supported changes are used.
70
+ 4. `npm run verify` checks both histories give the same schema and that only supported changes are used.
71
71
 
72
72
  Supported changes: add a table; add a column that is nullable or has a static default; drop a column; drop a table; add or drop an index or a unique constraint.
73
73
 
@@ -101,4 +101,4 @@ Locally, `dev` and `createTestApp` apply pending migrations. On a cloud, `deploy
101
101
 
102
102
  ## Stopping condition
103
103
 
104
- Stop reading when your tables use only the helpers above, your queries use only the allowed column, a migration pair has been generated and committed for every schema change, and `npx prototype-framework verify` passes on both dialects.
104
+ Stop reading when your tables use only the helpers above, your queries use only the allowed column, a migration pair has been generated and committed for every schema change, and `npm run verify` passes on both dialects.
@@ -0,0 +1,44 @@
1
+ # End-to-end tests
2
+
3
+ Read this when you add or change a flow (something a person or an operator does from start to finish), after a framework upgrade, or when an e2e test fails or must change.
4
+
5
+ ## What e2e covers
6
+
7
+ Every user-facing flow, on its **happy path**, its **expected errors** and its **edge cases**. A flow is not done until all three are covered end to end. When a flow changes, change its e2e tests in the same work; after `npm run upgrade`, run them and fix what the release changed. A change to an e2e test that passed before is listed with its reason like any other ([test-changes.md](test-changes.md)).
8
+
9
+ ## API first, a few UI tests
10
+
11
+ The template ships two Playwright projects (`playwright.config.ts`), against a local `dev` server that Playwright starts and stops:
12
+
13
+ - **`e2e-api`** (`tests/e2e/api/*.spec.ts`): most e2e tests. They drive the app's HTTP API with Playwright's `request` fixture, which needs no browser. `npm run verify` runs this project after the unit tests; `npm run test:e2e:api` runs it alone.
14
+ - **`e2e-ui`** (`tests/e2e/ui/*.spec.ts`): only what a browser alone shows: a page renders the data, the login button signs in, a file uploads or downloads from the page, a cookie is set. At most a few per flow; every other case of the flow is an API test. `npm run test:e2e:ui` runs it; only this project needs Chromium (`npm exec --no -- playwright install chromium` once, when the user agrees). If Chromium cannot be installed, report the UI run as `not-run` with the reason (hard rule 8) and do not declare the page done.
15
+
16
+ The config hides the server's own log. If the server does not start (Playwright times out waiting for it), run `npm run dev` to see why.
17
+
18
+ Write a spec from the flow, not from the code:
19
+
20
+ - Requests go to paths (`/api/notes`); the config sets the base URL and the `Origin` header the framework's forgery check needs.
21
+ - Sign in as a test identity with the authentication mock, which every local server has: `` await request.post("/api/auth/mock-login", { data: { level: "user", id: `e2e-${crypto.randomUUID()}` } }) ``. Use a fresh ID per test: local data is kept between runs, so never assert totals.
22
+ - Check status codes and `(await res.json()).error.code`, never messages.
23
+ - In UI specs, find elements by role and visible text (`page.getByRole("button", { name: "Log in" })`).
24
+ - Never wait in real time, and never test expiry here: use fake timers in-process ([../testing.md](../testing.md)).
25
+ - `playwright.config.ts` is part of the gate: a change to it that could run fewer tests or pass more easily (projects, `testIgnore`, `retries`, timeouts) is listed like a change to a once-green test ([test-changes.md](test-changes.md)).
26
+
27
+ ## Edge cases
28
+
29
+ Before writing a flow's tests, list its edge cases in the spec's header comment, and cover each that applies; for each prompt that does not apply, say why in a few words:
30
+
31
+ - **Boundaries:** empty, one, exactly at a documented limit, one past it. Locally only; on a cloud, keep data small.
32
+ - **Text:** Unicode, case and normalisation; `..`, `/` and percent-encoding in names; one name a prefix of another.
33
+ - **Order and time:** sort order and paging; expiry at and just past the limit (fake `Date`, in-process).
34
+ - **Access:** anonymous, user, admin, and another user's data.
35
+ - **Repetition:** repeated and concurrent requests; reuse of one-time links or tickets.
36
+ - **Failures:** an unavailable capability (in-process with `setUnavailable`); local versus cloud differences.
37
+
38
+ ## Examples
39
+
40
+ - [examples/tests.md](../../examples/tests.md): the template's tests, including its e2e specs.
41
+
42
+ ## Stopping condition
43
+
44
+ Stop reading when every flow you added or changed has API tests for its happy path, expected errors and listed edge cases, at most a few UI tests for what only a browser shows, and `npm run verify` (and `npm run test:e2e:ui` if you changed a page) passes.
@@ -0,0 +1,44 @@
1
+ # Diagnosing a failure
2
+
3
+ Read this when a test, `verify`, an e2e run, a build, a deploy or a smoke test fails, other than a test that is red on purpose during red/green, or when you are asked to diagnose, review or fix such a failure.
4
+
5
+ "Probably", "flaky" and "timing" are not causes without evidence. Never change a test or the code to make the failure go away before its cause is reviewed.
6
+
7
+ ## Who does what
8
+
9
+ Each role is its own subagent. None of them wrote the code that failed, and the reviewer never reviews a cause it found itself. The main session briefs them with file paths, not file contents, and they answer with short summaries; the details go in the record.
10
+
11
+ ## The record
12
+
13
+ One record per failure, in the app's repository: `test-records/root-causes/<yyyy-mm-dd>-<slug>.md`. Its sections, in this order:
14
+
15
+ 1. **Symptom**: the exact command and output.
16
+ 2. **Evidence**: logs (`.logs/`, or the stage's log entry for the `requestId`, [troubleshooting.md](../troubleshooting.md)), requests and responses, state, variations of the test that confirm or rule out each hypothesis, and a minimal reproduction.
17
+ 3. **Causal chain**, with the evidence for each link.
18
+ 4. **Alternatives ruled out.**
19
+ 5. **Proposed fix.**
20
+ 6. **Verification plan.**
21
+ 7. **Review**, which the reviewer writes. Until then the record says `Status: awaiting review`.
22
+
23
+ An unproven link means more evidence, never a guess.
24
+
25
+ ## Steps
26
+
27
+ 1. **Diagnose.** The diagnoser reproduces the failure, gathers the evidence and writes the record.
28
+ 2. **Review.** The reviewer checks that the evidence supports every link, that the alternatives are ruled out, and that the fix addresses the cause, not the symptom. Its verdict is `accepted` or `rejected`, with reasons. A rejected record goes back to step 1.
29
+ 3. **Fix, red then green.** A fixer adds the reproduction test, sees it fail, then fixes the code as the accepted record says, and sees it pass. Where the same defect is plainly in other code it is changing, it fixes and tests that too.
30
+ 4. **Re-check.** A subagent that changed nothing re-runs the affected tests and `npm run verify`, and checks that no test was skipped or weakened. Its verdict is the only pass.
31
+
32
+ ## Limits
33
+
34
+ - At most **3 attempts** (steps 1–4) per failure.
35
+ - Still open after 3 attempts: stop and tell the user, in plain words, what fails, what was tried, and the record's path.
36
+ - A suspected framework defect goes to `FRAMEWORK-ISSUE.md` (`SKILL.md` hard rules 6 and 7), with the record as its evidence.
37
+
38
+ ## Examples
39
+
40
+ - [examples/tests.md](../../examples/tests.md): the tests a reproduction test is added beside.
41
+
42
+ ## Stopping condition
43
+
44
+ Stop reading when the failure has an accepted record and its fix passed the re-check, or when it stopped at the limits and you told the user.
@@ -0,0 +1,28 @@
1
+ # Fuzzing a route input
2
+
3
+ Read this when a route takes input at a trust boundary (a name, a cursor, a return path, a code or token, a request body) and its example tests keep missing cases, or the same route has failed more than once.
4
+
5
+ ## Where it is worth it
6
+
7
+ Fuzzing is **local, limited and targeted**. Use it only where it finds what example tests would miss:
8
+
9
+ - a parser, validator or encoder at a trust boundary;
10
+ - especially a route with repeated failures (see its records under `test-records/root-causes/`).
11
+
12
+ Having a zod schema makes a route eligible, not required. Never fuzz every route, never run long or exhaustive runs, and never fuzz a deployed stage. Fuzzing never replaces the route's example tests ([../testing.md](../testing.md)).
13
+
14
+ ## The template's helper
15
+
16
+ `tests/support/fuzz.ts` drives a route from its zod schema with the `fast-check` package (pinned, hard rule 5): it sends generated bodies, both valid and invalid for the schema, and checks that the route never answers a server error, answers 400 `HTTP.INVALID_INPUT` when the schema rejects the body, and never answers it when the schema accepts the body (the route's own rules may still refuse it, for example with 404 or 409). Each use states its run count and fixed seed, with a one-line reason, so a run is small and repeatable and adds only seconds to `verify`. See `tests/fuzz.test.ts` for the template's one use.
17
+
18
+ ## A finding
19
+
20
+ A failing run prints the seed and the smallest body that fails. Treat it as any failure ([failures.md](failures.md)), and add that body as a plain example test before the fix.
21
+
22
+ ## Examples
23
+
24
+ - [examples/tests.md](../../examples/tests.md): the in-process tests the helper runs beside.
25
+
26
+ ## Stopping condition
27
+
28
+ Stop reading when you have decided the route does not qualify, or its fuzz test states its run count, seed and reason, passes in `npm run verify`, and any finding is a plain regression test.
@@ -0,0 +1,42 @@
1
+ # Test impact and changes to passing tests
2
+
3
+ Read this when a change needs new, changed or removed tests, or you are about to change, remove, skip or loosen a test that has passed before.
4
+
5
+ ## Test impact of every change
6
+
7
+ Before you change code, write down its test impact and then make it, in the same work, without being asked:
8
+
9
+ - the unit and in-process tests to add, change or remove;
10
+ - the e2e tests to add, change or remove ([e2e.md](e2e.md));
11
+ - any fuzz target affected ([fuzzing.md](fuzzing.md)).
12
+
13
+ When you report to the user, list the test impact and each change to an existing test with its reason code (below).
14
+
15
+ ## Changes to a once-green test
16
+
17
+ A test is **once-green** when it passed in this session or is on the app's main branch. This covers every layer: unit, in-process, e2e, smoke and fuzz.
18
+
19
+ - **What to list:** any change to its expected results or assertions, its removal, a skip (`.skip`, `.todo`, a condition that stops it running), a wider tolerance or timeout, or a renamed or merged test that checks less. List each one, grouped by reason code (below), when you report to the user.
20
+ - **Never weaken a test to pass.** A test you think is wrong is a failure to diagnose ([failures.md](failures.md)); the reason code is then `test-was-wrong`, citing the record.
21
+
22
+ ## Reason codes
23
+
24
+ Group the changes and give each group one code:
25
+
26
+ | Code | When | Cite |
27
+ | --- | --- | --- |
28
+ | `code-removed` | the code or feature it tests is gone | the user's request or the change that removed it |
29
+ | `behaviour-changed` | the app's intended behaviour changed | the requirement or the user's request |
30
+ | `test-was-wrong` | the test asserted the wrong thing | its root-cause record |
31
+ | `strengthened` | it now checks more | — |
32
+ | `refactor-only` | same checks, new shape | — |
33
+
34
+ A test weakened while the code it covers stayed the same needs a clear reason in the list; if you can't give one, it is a failure to diagnose ([failures.md](failures.md)).
35
+
36
+ ## Examples
37
+
38
+ - [examples/tests.md](../../examples/tests.md): the template's tests, which a change set extends.
39
+
40
+ ## Stopping condition
41
+
42
+ Stop reading when the change's test impact is written down and done, and every change to a once-green test is listed with its reason.
@@ -1,50 +1,61 @@
1
1
  # Testing
2
2
 
3
- Read this when you write or fix app tests, write the smoke test, test time-dependent behaviour, or need to know what `verify` and `smoke` run.
3
+ Read this when you write or fix app tests, write the smoke test or the e2e tests, test time-dependent behaviour, or need to know what `verify`, the e2e projects and `smoke` run.
4
4
 
5
- ## What runs your tests
5
+ ## How you work on tests
6
6
 
7
- - `npx prototype-framework verify` runs every `tests/**/*.test.ts` file (PAR-116) with Vitest twice, once on SQLite and once on Postgres, each in its own process, with 60 s test and hook timeouts. It fails if any test fails or if no test passed. Tests must need no network.
8
- - `npx prototype-framework smoke --target <t> --stage <s>` runs only `tests/smoke/**/*.test.ts`, against the running `dev` server (`--target local`) or against a deployed **test** stage (a stage whose name starts with `test-`). It refuses to run when tracked files differ from the last commit (the evidence record names the commit), writes an evidence record to `validation/<target>/<runId>.json` at the top of the git repository that holds the app (the app directory when the app is its own repository; commit the record with the run's commit), and prints the stage's log location for the day.
7
+ These hold for every change, without asking the user technical questions. Explain results to the user in plain words.
8
+
9
+ - **Red, green, refactor.** For app logic, write one failing test first, run it and see it fail for the expected reason, then write the code, then tidy up. Every fix starts with a test that reproduces the failure and fails.
10
+ - **State each change's test impact** and make the test changes in the same work: the unit, integration and e2e tests to add, change or remove, and any fuzz target ([testing/test-changes.md](testing/test-changes.md)).
11
+ - **Keep e2e current.** A flow is not done until its happy path, its expected errors and its edge cases are covered end to end. When a flow changes, and after a framework upgrade, update its e2e tests ([testing/e2e.md](testing/e2e.md)).
12
+ - **A failure is diagnosed before anything changes.** Any failure other than a test that is red on purpose gets an evidence-based root cause from a subagent that did not write the code, an independent review, and only then a red-green fix ([testing/failures.md](testing/failures.md)). "Flaky" or "timing" is not a cause without evidence.
13
+ - **Never skip, delete or weaken a test to get a pass.** Any change to a test that passed once (its expected results, its removal, a skip, a wider tolerance or timeout) is listed with its reason when you report ([testing/test-changes.md](testing/test-changes.md)).
14
+ - **Orchestrate.** The main session briefs subagents, in parallel where they touch different files, and keeps its own context small, unless the user says otherwise. Roles that must be separate: the code's author never diagnoses or reviews its own failure.
15
+ - **CI is the user's.** Installing or upgrading the framework never creates or changes the app's CI. You may suggest a CI change to the user, who decides. Apps have no commit hooks: run the checks yourself.
16
+
17
+ ## The layers
18
+
19
+ | Layer | What | Where | Runs with |
20
+ | --- | --- | --- | --- |
21
+ | Unit and integration | App logic and routes, in process, with real local storage on both SQL dialects | `tests/**/*.test.ts` | `npm run verify` |
22
+ | E2E, API | Each flow through the running app's HTTP API | `tests/e2e/api/*.spec.ts` | `npm run verify` (project `e2e-api`, no browser) |
23
+ | E2E, UI | What only a browser shows: page rendering, the login button, file transfer in the page, cookies; a few per flow | `tests/e2e/ui/*.spec.ts` | `npm run test:e2e:ui` (project `e2e-ui`, needs Chromium) |
24
+ | Fuzz | A route input at a trust boundary, from its zod schema, only where [testing/fuzzing.md](testing/fuzzing.md) says | `tests/**/*.test.ts` | `npm run verify` |
25
+ | Smoke | A short check on a deployed `test-` stage | `tests/smoke/**/*.test.ts` | `npm run smoke` |
26
+
27
+ - `npm run verify` runs every `tests/**/*.test.ts` file (PAR-116) with Vitest twice, once on SQLite and once on Postgres, each in its own process, with 60 s test and hook timeouts, then the `e2e-api` project against a local `dev` server it starts. It fails if any test fails or if no test passed. Tests need no network.
28
+ - `npm run smoke -- --target <t> --stage <s>` runs only `tests/smoke/**/*.test.ts`, against the running `dev` server (`--target local`) or against a deployed **test** stage. It refuses to run when tracked files differ from the last commit, writes an evidence record to `validation/<target>/<runId>.json` at the top of the git repository that holds the app (commit it with the run's commit), and prints the stage's log location for the day.
9
29
  - An app is not done on a cloud until its smoke test has passed on a deployed stage there.
10
- - Your tests and your smoke test reach the app only through its API; behaviour that exists only in the page (how text renders, the clipboard, an image displaying) is checked by the framework's browser tests, not the app's, so keep page text to `textContent` (`no-raw-html`), test the API side, and do not add a browser driver or raise this as a framework issue.
11
30
 
12
31
  ## In-process tests
13
32
 
14
33
  Import from `@lago-morph/prototype-framework/testing` (only in `tests/**`):
15
34
 
16
- - `await createTestApp(app, options?)` starts your app in the test process with fresh, empty storage and migrations applied. Options: `user` (identity for every request, default anonymous), `config` (override declared values; `framework` takes `{ admins?, users? }`), `secrets` (values), `unavailable` (e.g. `["sql"]`: every operation of that capability fails with its `*.UNAVAILABLE` code), `stubLoginProvider` (see [current-user.md](current-user.md)). Failures are simulated per capability, not per operation: `unavailable` holds from creation, and `t.setUnavailable([...])` replaces the set from the next request on (for `t` and every app made from it with `as`; `t.setUnavailable([])` makes everything available again; stored data is kept). So to test that a failed cleanup is logged and the request still succeeds, create the data first (for example a post with a stored photo), then call `t.setUnavailable(["files"])`, run the request that cleans up, and check its status and the `warn` entry in `t.logs()`. With one `try/catch` around the whole cleanup, as in the template-style code, every failure in it takes that path. `setUnavailable` is not available against a deployed stage.
35
+ - `await createTestApp(app, options?)` starts your app in the test process with fresh, empty storage and migrations applied. Options: `user` (identity for every request, default anonymous), `config` (override declared values), `secrets` (values), `unavailable` (e.g. `["sql"]`: every operation of that capability fails with its `*.UNAVAILABLE` code), `authAppLoginProvider` (see [current-user.md](current-user.md)). `t.setUnavailable([...])` replaces the unavailable set from the next request on (`[]` makes everything available again; stored data is kept), so a test can store data, make `files` unavailable, run the request that cleans up, and check its status and the `warn` entry in `t.logs()`. Not available against a deployed stage.
17
36
  - `await t.request("/api/notes", init?)` sends a request and returns a `Response`. Include `/api` in the path. For JSON bodies set `headers: { "content-type": "application/json" }` and `body: JSON.stringify(…)`. State-changing requests get the right `Origin` automatically.
18
- - `t.as(mockUsers.user("alice"))` returns a test app that sends requests as Alice and shares storage with `t`; use two of them to test that one user cannot see another's data. `mockUsers.admin(id?)` and `mockUsers.anonymous` likewise. In-process, `t` and every test app made from it with `as` share one app: disposing any of them disposes all, and later requests through any of them throw. Dispose them only at the end of the test, as the examples do. On a deployed stage, disposing one only logs it out.
19
- - `t.logs()` returns the log entries written so far ([log.md](log.md)).
20
- - `await t.dispose()` after each test (an `afterEach` that disposes every test app the test opened, as in the examples).
37
+ - `t.as(mockUsers.user("alice"))` returns a test app that sends requests as Alice and shares storage with `t`; use two of them to test that one user cannot see another's data. `mockUsers.admin(id?)` and `mockUsers.anonymous` likewise. `t` and every test app made from it share one app: dispose them only at the end of the test.
38
+ - `t.logs()` returns the log entries written so far ([log.md](log.md)). `await t.dispose()` after each test.
21
39
 
22
- What to test for each route: the success case with its body; anonymous (401 `AUTH.UNAUTHENTICATED`) and, for admin routes, a plain user (403 `AUTH.FORBIDDEN`); invalid input (400 `HTTP.INVALID_INPUT`); another user's data (not visible, usually 404 `HTTP.NOT_FOUND` or an empty list); and the error codes your route throws. Check error codes through `(await res.json()).error.code`, never through messages.
23
-
24
- Type response bodies with the shared types: `const body: NoteList = await res.json();`.
40
+ What to test for each route: the success case with its body; anonymous (401 `AUTH.UNAUTHENTICATED`) and, for admin routes, a plain user (403 `AUTH.FORBIDDEN`); invalid input (400 `HTTP.INVALID_INPUT`); another user's data (not visible, usually 404 `HTTP.NOT_FOUND` or an empty list); and the error codes your route throws. Check error codes through `(await res.json()).error.code`, never through messages. Type response bodies with the shared types: `const body: NoteList = await res.json();`.
25
41
 
26
42
  ## Time-dependent behaviour
27
43
 
28
- Expiry and other time checks (share-link expiry, "edited within an hour") are tested in-process with Vitest's fake timers, because the framework's own time checks run in the test process too: `vi.useFakeTimers({ toFake: ["Date"] })`, then `vi.setSystemTime(…)` or `vi.advanceTimersByTime(…)`, and `vi.useRealTimers()` afterwards. Fake only `Date`, as the framework's own session-expiry tests do, so other timers keep running. Never test expiry in the smoke test, and never wait in real time.
44
+ Expiry and other time checks are tested in-process with Vitest's fake timers: `vi.useFakeTimers({ toFake: ["Date"] })`, then `vi.setSystemTime(…)` or `vi.advanceTimersByTime(…)`, and `vi.useRealTimers()` afterwards. Fake only `Date`. Never test expiry in the smoke or e2e tests, and never wait in real time.
29
45
 
30
46
  ## The smoke test
31
47
 
32
- One file under `tests/smoke/` runs both ways:
33
-
34
- - Under `verify`, it is an ordinary in-process test (`createTestApp`).
35
- - Under `smoke`, `inject("prototypeFrameworkSmoke")` is `true` and it uses `connectTestStage()`, which connects to the stage `smoke` targets and logs in through the authentication mock.
48
+ One file under `tests/smoke/` runs both ways: under `verify` it is an ordinary in-process test (`createTestApp`); under `smoke`, `inject("prototypeFrameworkSmoke")` is `true` and it uses `connectTestStage()`, which connects to the stage `smoke` targets and logs in through the authentication mock.
36
49
 
37
50
  Keep it short: the health route (`GET /api/__framework/health` answers 204), one open route, and one write-then-read per capability your app depends on. Use a fresh mock user per run (`` mockUsers.user(`smoke-${crypto.randomUUID()}`) ``) because stage data is kept between runs; do not assert totals that earlier runs would change. `logs()` is not available against a stage. Copy the template's file and change the routes ([examples/tests.md](../examples/tests.md)).
38
51
 
39
- `t.request` sends only to the app: a URL on any other origin is refused before anything is sent, on both test apps, so the stage's session cookie never leaves the stage. An upload or download ticket a route returns is JSON `{ url, method?, headers?, expiresAt }` on every target. Locally and in-process its `url` is a path on the app, sent with `t.request(url, { method, headers, body })`; on a cloud it is an absolute signed storage URL, sent with plain `fetch(url, { method: ticket.method ?? "GET", headers: ticket.headers, body })` and no cookie. Choose with `/^\/(?![\/\\])/.test(ticket.url) ? t.request(…) : fetch(…)`, so `//host` and `/\host` URLs go to `fetch` too. Behind a proxy, `smoke` needs `NODE_USE_ENV_PROXY=1` for that `fetch`.
40
-
41
- To run it on a cloud, deploy a test stage first, for example `npx prototype-framework deploy --target cloudflare --stage test-1`, then `npx prototype-framework smoke --target cloudflare --stage test-1`, and remove the stage afterwards ([deploying.md](deploying.md)). Test stages use `config/<target>/test.json` and the authentication mock and hold no real data.
52
+ `t.request` sends only to the app; a URL on any other origin is refused. A ticket's `url` is a path on the app locally (send it with `t.request`) and an absolute signed storage URL on a cloud (send it with plain `fetch`, no cookie): choose with `/^\/(?![\/\\])/.test(ticket.url)`. Behind a proxy, `smoke` needs `NODE_USE_ENV_PROXY=1` for that `fetch`. To run it on a cloud, deploy a test stage, run `npm run smoke -- --target cloudflare --stage test-1`, then remove the stage ([deploying.md](deploying.md)).
42
53
 
43
54
  ## Failures
44
55
 
45
56
  - A test that passes on SQLite but fails on Postgres (or the reverse) uses something the portable subset does not promise: check ordering (end with the `id` column), NULL handling and text comparison ([sql-and-migrations.md](sql-and-migrations.md)).
46
57
  - A framework `error` entry printed to stderr during a test shows the real cause of a 500 response.
47
- - A failing deployed smoke test prints the method, path, status, error code and request ID; find the request's entry with [troubleshooting.md](troubleshooting.md).
58
+ - A failing deployed smoke test prints the method, path, status, error code and request ID; find the request's entry with [troubleshooting.md](troubleshooting.md). Then follow [testing/failures.md](testing/failures.md).
48
59
 
49
60
  ## Examples
50
61
 
@@ -52,4 +63,4 @@ To run it on a cloud, deploy a test stage first, for example `npx prototype-fram
52
63
 
53
64
  ## Stopping condition
54
65
 
55
- Stop reading when each route has tests for success, access level, invalid input and other users' data, the smoke test covers each capability you use, and `npx prototype-framework verify` passes on both dialects. For deploying and running the smoke test on a cloud, read [deploying.md](deploying.md).
66
+ Stop reading when each route has tests for success, access level, invalid input and other users' data, each flow has its e2e tests, the smoke test covers each capability you use, and `npm run verify` passes on both dialects. For a failure, an e2e test, a test change or fuzzing, read the one file under `testing/` linked above.