@somewhere-cloud/cli 0.38.155 → 0.38.157

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 (142) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/commands/docs.js +1 -1
  3. package/dist/lib/bundle.js +286 -188
  4. package/dist/lib/bundle.js.map +3 -3
  5. package/npm-shrinkwrap.json +2 -2
  6. package/package.json +2 -3
  7. package/dist/docs/adopt.md +0 -39
  8. package/dist/docs/analytics.md +0 -161
  9. package/dist/docs/api-reference.md +0 -339
  10. package/dist/docs/api-surface.md +0 -2067
  11. package/dist/docs/app-mcp.md +0 -162
  12. package/dist/docs/architecture-patterns.md +0 -334
  13. package/dist/docs/auth-client.md +0 -531
  14. package/dist/docs/billing.md +0 -76
  15. package/dist/docs/browser.md +0 -639
  16. package/dist/docs/calendar.md +0 -298
  17. package/dist/docs/changes.md +0 -323
  18. package/dist/docs/cli.md +0 -407
  19. package/dist/docs/common-mistakes.md +0 -199
  20. package/dist/docs/connect-agent.md +0 -72
  21. package/dist/docs/cors.md +0 -114
  22. package/dist/docs/cron.md +0 -167
  23. package/dist/docs/database-engine.md +0 -167
  24. package/dist/docs/declared-data.md +0 -1656
  25. package/dist/docs/declared-files.md +0 -475
  26. package/dist/docs/deploy-intelligence.md +0 -188
  27. package/dist/docs/deploy.md +0 -733
  28. package/dist/docs/design-system.md +0 -273
  29. package/dist/docs/dev-environments.md +0 -496
  30. package/dist/docs/domain-ownership.md +0 -31
  31. package/dist/docs/domains.md +0 -370
  32. package/dist/docs/feedback.md +0 -88
  33. package/dist/docs/file-tools.md +0 -116
  34. package/dist/docs/functions.md +0 -489
  35. package/dist/docs/getting-started.md +0 -238
  36. package/dist/docs/github.md +0 -95
  37. package/dist/docs/google-calendar.md +0 -212
  38. package/dist/docs/groups.md +0 -836
  39. package/dist/docs/guarantees.md +0 -58
  40. package/dist/docs/handled-for-you.md +0 -224
  41. package/dist/docs/inspect.md +0 -171
  42. package/dist/docs/limits.md +0 -68
  43. package/dist/docs/live-data.md +0 -197
  44. package/dist/docs/live.md +0 -92
  45. package/dist/docs/local-dev.md +0 -30
  46. package/dist/docs/migration-supabase.md +0 -58
  47. package/dist/docs/payments.md +0 -1102
  48. package/dist/docs/portability.md +0 -194
  49. package/dist/docs/postgres.md +0 -301
  50. package/dist/docs/pricing-comparison.md +0 -42
  51. package/dist/docs/pricing.md +0 -39
  52. package/dist/docs/project-groups.md +0 -107
  53. package/dist/docs/projects.md +0 -380
  54. package/dist/docs/recipe-ai-agent.md +0 -112
  55. package/dist/docs/recipe-ai-features.md +0 -227
  56. package/dist/docs/recipe-ai-receipts.md +0 -783
  57. package/dist/docs/recipe-background-jobs.md +0 -369
  58. package/dist/docs/recipe-booking.md +0 -348
  59. package/dist/docs/recipe-csv-import.md +0 -390
  60. package/dist/docs/recipe-ecommerce.md +0 -127
  61. package/dist/docs/recipe-email.md +0 -282
  62. package/dist/docs/recipe-escalation.md +0 -133
  63. package/dist/docs/recipe-file-uploads.md +0 -159
  64. package/dist/docs/recipe-import-app.md +0 -110
  65. package/dist/docs/recipe-login.md +0 -457
  66. package/dist/docs/recipe-multi-chat.md +0 -198
  67. package/dist/docs/recipe-paid-api.md +0 -161
  68. package/dist/docs/recipe-pdfs.md +0 -205
  69. package/dist/docs/recipe-push-notifications.md +0 -107
  70. package/dist/docs/recipe-seo.md +0 -200
  71. package/dist/docs/recipe-signed-in-app.md +0 -330
  72. package/dist/docs/render.md +0 -99
  73. package/dist/docs/rooms.md +0 -554
  74. package/dist/docs/sdk.md +0 -287
  75. package/dist/docs/sdks.md +0 -24
  76. package/dist/docs/search.md +0 -199
  77. package/dist/docs/security-model.md +0 -168
  78. package/dist/docs/setup.md +0 -212
  79. package/dist/docs/smoke.md +0 -102
  80. package/dist/docs/speed.md +0 -298
  81. package/dist/docs/sql-compatibility.md +0 -96
  82. package/dist/docs/sw.agent.md +0 -248
  83. package/dist/docs/sw.ai.md +0 -1291
  84. package/dist/docs/sw.auth.md +0 -1811
  85. package/dist/docs/sw.billing.md +0 -171
  86. package/dist/docs/sw.db.md +0 -2128
  87. package/dist/docs/sw.email.md +0 -661
  88. package/dist/docs/sw.endpoint.md +0 -187
  89. package/dist/docs/sw.env.md +0 -303
  90. package/dist/docs/sw.fetch.md +0 -115
  91. package/dist/docs/sw.fs.md +0 -424
  92. package/dist/docs/sw.groups.md +0 -836
  93. package/dist/docs/sw.image.md +0 -69
  94. package/dist/docs/sw.jobs.md +0 -520
  95. package/dist/docs/sw.logs.md +0 -61
  96. package/dist/docs/sw.mail.md +0 -106
  97. package/dist/docs/sw.notifications.md +0 -78
  98. package/dist/docs/sw.push.md +0 -161
  99. package/dist/docs/sw.rateLimit.md +0 -67
  100. package/dist/docs/sw.web.md +0 -128
  101. package/dist/docs/tasks.md +0 -269
  102. package/dist/docs/test.md +0 -220
  103. package/dist/docs/tool-reference-account.md +0 -7
  104. package/dist/docs/tool-reference-ai.md +0 -121
  105. package/dist/docs/tool-reference-analytics.md +0 -37
  106. package/dist/docs/tool-reference-api.md +0 -19
  107. package/dist/docs/tool-reference-artifacts.md +0 -35
  108. package/dist/docs/tool-reference-auth.md +0 -163
  109. package/dist/docs/tool-reference-browser.md +0 -114
  110. package/dist/docs/tool-reference-code.md +0 -26
  111. package/dist/docs/tool-reference-connect.md +0 -21
  112. package/dist/docs/tool-reference-cron.md +0 -48
  113. package/dist/docs/tool-reference-db.md +0 -282
  114. package/dist/docs/tool-reference-domains.md +0 -107
  115. package/dist/docs/tool-reference-email.md +0 -55
  116. package/dist/docs/tool-reference-env.md +0 -19
  117. package/dist/docs/tool-reference-feedback.md +0 -56
  118. package/dist/docs/tool-reference-fs.md +0 -265
  119. package/dist/docs/tool-reference-github.md +0 -57
  120. package/dist/docs/tool-reference-groups.md +0 -85
  121. package/dist/docs/tool-reference-help.md +0 -29
  122. package/dist/docs/tool-reference-jobs.md +0 -39
  123. package/dist/docs/tool-reference-live.md +0 -48
  124. package/dist/docs/tool-reference-logs.md +0 -16
  125. package/dist/docs/tool-reference-payments.md +0 -44
  126. package/dist/docs/tool-reference-project.md +0 -706
  127. package/dist/docs/tool-reference-push.md +0 -78
  128. package/dist/docs/tool-reference-rate-limit.md +0 -18
  129. package/dist/docs/tool-reference-search.md +0 -68
  130. package/dist/docs/tool-reference-security.md +0 -42
  131. package/dist/docs/tool-reference-smoke.md +0 -17
  132. package/dist/docs/tool-reference-stock-photos.md +0 -20
  133. package/dist/docs/tool-reference-tasks.md +0 -73
  134. package/dist/docs/tool-reference-telegram.md +0 -32
  135. package/dist/docs/tool-reference-usage.md +0 -9
  136. package/dist/docs/tool-reference-web.md +0 -71
  137. package/dist/docs/tool-reference-webhooks.md +0 -9
  138. package/dist/docs/troubleshooting.md +0 -411
  139. package/dist/docs/typed-functions.md +0 -94
  140. package/dist/docs/verify-before-deploy.md +0 -67
  141. package/dist/docs/vs-supabase.md +0 -75
  142. package/dist/docs/vs-vercel.md +0 -103
@@ -1,639 +0,0 @@
1
- # Test, observe and troubleshoot
2
-
3
- `somewhere verify` drives your live app in a real browser at desktop and phone
4
- size. It reports each step, console errors and failed requests, and keeps
5
- screenshots. Logs, runtime errors and analytics come from the same project,
6
- so after a check you can read what happened without wiring any tooling.
7
-
8
- ## Check one real journey, including a refusal
9
-
10
- Test what a user actually does, plus one thing they must not be able to do.
11
- This flow opens the starter already signed in as a managed test user of
12
- the project, then confirms that a signed-out visitor is refused. It uses the
13
- `/api/account` function from **Auth**. Save it as `flows/journey.json`:
14
-
15
- ```json
16
- {
17
- "actors": { "ana": { "auth": { "user_id": "<test-app-user-id>" } }, "visitor": {} },
18
- "journey": [
19
- { "as": "ana", "path": "/", "actions": [
20
- { "expect": { "selector": ".topbar", "visible": true } },
21
- { "eval": "fetch('/api/account').then((r) => r.status)" }
22
- ], "expect_requests": [{ "path": "/api/account", "status": 200 }] },
23
- { "as": "visitor", "path": "/", "actions": [
24
- { "eval": "fetch('/api/account').then((r) => r.status)" }
25
- ], "expect_requests": [{ "path": "/api/account", "status": 401 }] }
26
- ]
27
- }
28
- ```
29
-
30
- ```bash
31
- echo "flows/" >> .somewhereignore # keep test credentials off the live site
32
- somewhere verify --flow flows/journey.json
33
- ```
34
-
35
- The final line is JSON with `outcome` and `counts`. Exit 0 means the flow
36
- passed, 1 means a named check failed, and 2 means verification or cleanup
37
- could not finish. For unconfirmed cleanup, the report names the browsers
38
- or test users that may remain.
39
- `expect_requests` lists the answers the flow intends. Here, 401 for the
40
- signed-out visitor counts as a pass. A declared request must be seen with that
41
- status (its `path` matches by substring), or the step fails. A refused
42
- request you did not declare still fails the run's network check. Declare a
43
- refusal only when the flow is meant to be refused; an unexpected 4xx or 5xx is an
44
- app failure to fix, not to declare. Running more than one actor needs a
45
- claimed account and a credential allowed to keep named browser sessions.
46
- Project-scoped CLI logins refuse this multi-actor journey; a fresh one-user
47
- flow can use its approved project scope.
48
-
49
- `auth: { user_id }` takes the id of a managed test user of this project;
50
- other ids answer `AUTH_INVALID_CREDS`, so sign real accounts in through your UI.
51
- In a several-user flow, declare the actor as `{ "test_user": true }` instead and
52
- `verify` creates the test user for you (CLI 0.37.46 or later; see *Several users
53
- in one run*). Otherwise create test users (1–5 per call, up to 25 live per
54
- project, each expiring after 24 hours) with
55
- `somewhere api POST /v1/auth/test-users -d '{"project_id":"<project>","count":2}'`
56
- and use each `identities[].user.id`. They are created verified, with no
57
- password, so they skip the signup/login UI and email verification. To test
58
- those genuine flows, sign up through your UI as
59
- `<name>@<subdomain>.test.somewhere.site` (see *When signup or login is the
60
- behavior under test*); that mail lands in the test inbox, never externally.
61
-
62
- Run the flow against your deployed app. While you develop, `somewhere dev`
63
- serves the frontend from your machine and sends its `/api` requests to the
64
- deployed project, so data you save locally is written to production.
65
-
66
- To check that one user cannot see another's data, run two signed-in actors:
67
- `somewhere docs browser --section several-users-in-one-run` (MCP:
68
- `docs({ topic: 'browser', section: 'several-users-in-one-run' })`).
69
-
70
- ## Read what happened
71
-
72
- Browser actions use `[{"fill":"#email","value":"a@b.co"}]`;
73
- `--flow` wraps them as `{"actions":[{"fill":"#email","value":"a@b.co"}]}`.
74
- For a large journey, create a private directory outside the app root with
75
- `mkdir -p ../verify-reports`, then run
76
- `somewhere verify --flow flow.json --out ../verify-reports/journey.json`. This
77
- writes the full report (including evaluation values and screenshot links) to a
78
- new owner-only file and prints only a bounded summary. Add `--json` for a
79
- machine-readable summary. Without `--out`, `--json` retains the complete
80
- report on stdout. Keep full report files private.
81
-
82
- ```bash
83
- somewhere logs --tail 20 # recent log lines
84
- somewhere logs --level error --since 1h # only errors from the last hour
85
- somewhere logs --function /api/account # one route
86
- somewhere errors # recent runtime failures with stack and path
87
- ```
88
-
89
- In a function, write your own entries with `sw.logs.info`, `warn` or
90
- `error`. They show in the same stream. Read the failure first, then change
91
- code. `somewhere deploy-check --run /api/hello` exercises a public handler without
92
- publishing. The CLI check sends a signed-out request, so an account handler
93
- that requires sign-in returns `401 AUTH_REQUIRED`. To check that handler while
94
- signed in, use `somewhere browser --path /api/account --auth-user <app-user-id>`
95
- against the deployed app with a managed test user. Read an error response's
96
- `hint` field when present. `troubleshooting` maps common codes to fixes.
97
-
98
- ## Count what users do
99
-
100
- Track a product event from a function, after the action it describes:
101
-
102
- ```ts
103
- // api/events.ts — records an allowed product event for the signed-in user
104
- const ALLOWED_EVENTS = new Set(['onboarding_completed', 'note_shared']);
105
-
106
- export default async function events(
107
- request: Request,
108
- sw: SomewhereRuntimeContext,
109
- ): Promise<Response> {
110
- if (request.method !== 'POST') {
111
- return new Response('Use POST.', { status: 405, headers: { Allow: 'POST' } });
112
- }
113
-
114
- const user = await sw.auth.fromRequest(request);
115
- if (!user) return Response.json({ error: 'Sign in.' }, { status: 401 });
116
-
117
- const input: unknown = await request.json().catch(() => null);
118
- const event = typeof input === 'object' && input !== null && 'event' in input ? input.event : undefined;
119
- if (typeof event !== 'string' || !ALLOWED_EVENTS.has(event)) {
120
- return Response.json({ error: 'Unknown event.' }, { status: 400 });
121
- }
122
-
123
- const result = await sw.analytics.track(event, { properties: { source: 'app' } });
124
- // When consent blocks recording, the result carries the reason.
125
- const reason = 'reason' in result ? result.reason : undefined;
126
- return Response.json(result.recorded ? { recorded: true } : { recorded: false, reason });
127
- }
128
- ```
129
-
130
- `analytics_query({ project_id, event, group_by: 'day' })` returns counts.
131
- Page views are counted on the server without a tracking script. Keep
132
- personal data out of `properties`.
133
-
134
- **Consent.** By default, collection runs without a consent prompt. Setting
135
- `analytics_consent: { mode: "required", policy_version: "v1" }` with
136
- `project_update` adds a same-origin Accept/Reject banner, and the platform
137
- collects page views and `sw.analytics.track` events only after the visitor
138
- accepts that exact policy version. Changing `policy_version` asks every
139
- visitor again. Without a matching acceptance, `track` returns
140
- `recorded: false` with the reason (`consent_pending`, `consent_declined`
141
- or `consent_unavailable`), and the example returns both. The platform
142
- enforces the policy as soon as you set it. Functions forward the visitor's
143
- choice and skip blocked events once the app is deployed on the current
144
- runtime; an ordinary deploy does that (`deploy` →
145
- `optional-analytics-consent`). Consent mode covers the platform's own
146
- collection; your privacy policy should describe what your app tracks.
147
-
148
- ## More on testing and observing
149
-
150
- | Need | Where |
151
- |---|---|
152
- | Flow actions, sessions, several users, limits | `browser` → `drive-a-flow-add-actions`, `several-users-in-one-run`, `limits` |
153
- | Checks before publishing | `verify-before-deploy` |
154
- | Scheduled health checks | `smoke` |
155
- | Writing and reading logs; log retention | `sw.logs` → `write-logs`, `reading-logs`, `retention` |
156
- | Reading error logs, codes and hints | `troubleshooting` → `how-to-read-your-error-logs`, `all-api-errors-include-a-hint-field` |
157
- | Analytics tracking and queries | `analytics` |
158
- | Consent mode details | `deploy` → `optional-analytics-consent` |
159
- | Local development | `local-dev` |
160
-
161
- ## The browser tool and its routes
162
-
163
- `browser` opens your DEPLOYED app in a real headless browser so you can
164
- SEE it, INSPECT it, and DRIVE it — one tool for the whole loop of "what
165
- does my app look like, is it healthy, and does it actually work?"
166
-
167
- The MCP `browser` tool selects the appropriate REST route. For direct HTTP,
168
- use `POST /v1/browser/test` for page inspection and actions, and
169
- `POST /v1/render/screenshot` for raw `html` (or `/v1/render/pdf` for PDF).
170
- The page-test route does not render HTML snippets. Every report includes
171
- `timing` in milliseconds: `admission_wait_ms`, `browser_acquire_ms` (with
172
- `browser_reused`), `page_setup_ms`, `start_navigation_ms`, `actions_ms`
173
- and `total_ms`, plus `auth_ms` when `auth: { user_id }` signed a user in. Multi-viewport flows belong
174
- to `somewhere verify --flow` or MCP `site_verify`; a page-test request uses
175
- one `viewport`, not `viewports`.
176
-
177
- For the complete verification loop, run `somewhere verify --url <live-or-local-url> --flow flow.json` or MCP `site_verify`. The exact flow object is `{ "actions": [{ "fill": "#name", "value": "Potluck" }, { "click": "#save" }, { "expect": { "selector": "#status", "text": "Saved" } }], "expect_requests": [{ "path": "/api/private", "status": 401 }], "visible_only": true, "viewports": ["desktop", "mobile"] }`; omit it for a page load, health report, and both screenshots. Every viewport gets a fresh browser that closes inside the call, including when a step fails. The viewport runs happen concurrently. If your flow writes data, prefer the sequential several-user journey below with existing controlled test users; two viewport runs signed in as the same person share that person’s data.
178
-
179
- - **Eyes** — a screenshot of the page.
180
- - **Ears** — console errors, page errors, and failed network requests
181
- (a backend 500 shows here even when the page looks fine).
182
- - **Hands** — click / fill / assert your way through a real flow.
183
-
184
- `run_code` proves a function's backend; `browser` proves the rendered
185
- UI. The report includes action results, page errors, failed requests, and
186
- screenshots. Read `data.passed` in the REST response, not just HTTP status
187
- or the outer `ok` field: a completed check can report a failing app or a
188
- requested capture that could not be produced. Read the step and screenshot
189
- errors for the cause.
190
-
191
- The principle: **act by selector, verify by signals, screenshot small +
192
- last.** You wrote the DOM, so target elements directly — don't guess at
193
- pixel coordinates like a computer-use agent staring at a stranger's
194
- screen.
195
-
196
- ## Just look (omit steps)
197
-
198
- Omit `steps` and you get a small screenshot, the console/network
199
- signals, AND the data-testid map + an interactive-element outline (tag,
200
- id, testid, text, selector) — the handles you can act on, instead of
201
- reverse-engineering selectors from scraped HTML. Every entry also carries
202
- `visible` (false for hidden/display:none/visibility:hidden/aria-hidden,
203
- or a zero-size box) and, when true, `disabled` — so a control that a
204
- signed-out visitor cannot actually operate reads that way in the outline
205
- itself, no follow-up probing required:
206
-
207
- browser({ project_id: 'my-saas' })
208
- // → { console_errors, page_errors, failed_requests,
209
- // screenshots: [{ label: 'page', fs_path: '/_browser_tests/.../00-page.jpg' }],
210
- // dom_outline: [{ tag:'button', testid:'submit', text:'Log in', selector:'[data-testid="submit"]', visible: true },
211
- // { tag:'button', testid:'delete-user', text:'Delete', selector:'[data-testid="delete-user"]', visible: false }, ...],
212
- // testid_map: { submit: '[data-testid="submit"]', ... }, final_url, passed }
213
-
214
- For a quick screenshot of your app, this IS the call — a url or
215
- project_id with no steps. An explicit `include` list selects the report
216
- sections instead of the default DOM map; include `"dom"` to retain it.
217
-
218
- ## Capture any page, or render raw HTML
219
-
220
- You can look at any public page and you can photograph it. What you cannot do
221
- is operate it: actions, `eval` and signed-in sessions run only against the
222
- origins of an authorized project of yours. Navigation off those origins during
223
- such a run is REFUSED before the request is made — the run stops and reports
224
- the refusal as evidence, rather than quietly continuing with fewer powers.
225
-
226
- This bounds who the browser may act AS, not what your app may talk to. Your
227
- project's own pages keep making their ordinary outbound requests — API calls,
228
- assets, third-party scripts — exactly as they do for any visitor.
229
-
230
- Use `browser` to capture a public page or render raw HTML:
231
-
232
- // Any public third-party page — pass a url with NO project_id:
233
- browser({ url: 'https://example.com' })
234
-
235
- // Render a raw HTML snippet straight to an image (e.g. an OG card):
236
- browser({ html: '<h1 style="color:red">Hello</h1>', width: 1200, height: 630 })
237
- // → { content_type: 'image/png', size_bytes, base64 }
238
-
239
- // …or save the snippet straight to the project file store:
240
- browser({ html: '<div>…</div>', project_id: 'my-app', storage: '/og/card.png' })
241
- // → { storage_path: '/og/card.png', size_bytes }
242
-
243
- The MCP tool routes `html` to the renderer; direct HTTP callers use
244
- `POST /v1/render/screenshot` with the same HTML fields, not the page-test route.
245
- `html` mode skips navigation/steps/DOM-map — it just returns the picture.
246
- `width` / `height` / `wait_for` tune it. With `project_id`, the
247
- `url` must belong to that project. To look at another public site, omit
248
- `project_id` — and that run is inspection and capture only.
249
-
250
- ## Drive a flow (add actions)
251
-
252
- Driving a page is a project capability. Supply `project_id`, and every
253
- action — including `eval` — runs against that project's own origins. The
254
- platform enforces this wherever this action shape is accepted: an action that
255
- would navigate outside those origins is refused before it is attempted, and
256
- the run reports that refusal instead of proceeding.
257
-
258
- `actions` is the one shared action shape used by the MCP tool, a CLI
259
- `--actions` JSON file, and `verify --flow`'s `actions` field. Each item
260
- has exactly one action key; selector-taking actions put the selector directly
261
- under that key:
262
-
263
- ```json
264
- [
265
- { "fill": "#email", "value": "a@b.co" },
266
- { "select": "#plan", "value": "pro" },
267
- { "click": "button[type=submit]" },
268
- { "wait": ".dashboard" },
269
- { "expect": { "selector": ".welcome", "text": "Hi", "visible": true, "count": 1 } },
270
- { "eval": "document.title" }
271
- ]
272
- ```
273
-
274
- `wait` is a CSS selector (waited for up to 15 s) or non-negative milliseconds.
275
- A fixed wait longer than 45000 ms is refused with an error naming the step,
276
- never shortened: split a longer pause into several waits (each counts toward
277
- `budget_ms`) or wait for a condition. A condition wait's own `timeout` is
278
- at most 45000 ms. `expect` requires
279
- `selector` plus at least one of `text`, `value`, `visible`, or `count`. Actions
280
- stop on the first failure by default; in the `browser` tool,
281
- `continue_on_failure: true` runs the remaining actions too (`verify --flow`
282
- does not accept it). `text` succeeds when any visible match contains the
283
- requested case-sensitive DOM text and its rendered text matches ignoring case.
284
- Hidden text alone does not pass. `value` and `visible` check the first element
285
- matching the selector; `count` checks all matches of the selector, even when
286
- `text` is also given, so `count: 0` together with `text` can never pass.
287
- `visible: false` passes only when a matching element exists and is hidden; if
288
- nothing matches, it fails. To assert that an element is absent, use `count: 0`
289
- alone, with a selector narrow enough to match only that element. `verify`
290
- waits up to 15 s for each `expect`. Target a unique element
291
- when asserting a particular record. Expanded `steps` remain accepted for existing
292
- callers, but new flows use `actions`. A screenshot action needs a label,
293
- for example `{ "screenshot": "after-save" }`.
294
- `{ "goto": "/path" }` navigates within the app (a path starting with `/`;
295
- absolute, scheme-relative and relative values are refused).
296
- Add `"frame": "name | url-substring | child-index | css-selector"` to an action
297
- to run it inside an iframe; its wait, expect, eval and screenshot then observe
298
- that frame (CLI 0.37.58 or later forwards it).
299
- `{ "upload": "#file", "fs_path": "/uploads/big.mp4", "type": "video/mp4" }`
300
- puts a file already stored in the project's files into a file input (optional
301
- `name` and `type`; up to 50 MB per call, streamed into the page), while
302
- `"file"` carries inline base64 or a data URL up to 10 MB; send exactly one.
303
-
304
- Native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`) never
305
- stall a run: each one is dismissed by default and listed in the report's
306
- `dialogs` with its type, its message (credentials redacted), the answer sent,
307
- and `handled`: `accepted` or `dismissed` once the browser confirmed it,
308
- `unconfirmed` if the call ended first, `failed` if it was refused. To accept
309
- one, put `{ "dialog": "accept" }` right before the action that opens it; add
310
- `"text"` to answer a prompt. `{ "dialog": "dismiss" }` states the default
311
- explicitly. An answer applies once, in the same call, to the next dialog opened
312
- by a page this run may act on; a dialog from any other frame is dismissed and
313
- the answer stays queued. One that no dialog used is listed in
314
- `dialog_actions_unused`. A
315
- dismissed `beforeunload` keeps the page, so the navigation that triggered it
316
- fails. An HTML `<dialog>` element is ordinary page content: click it as usual.
317
-
318
- ## Logged-in flows
319
-
320
- browser({ project_id: 'my-saas', auth: { user_id: 'usr_123' }, actions: [...] })
321
-
322
- Mints a 1-hour session for that app user (audited) and injects it before
323
- navigation, so authed pages work. Requires a project, and the seeded
324
- credentials are scoped to that project's origins — they are not handed to any
325
- other origin the page loads from, and a navigation that would leave those
326
- origins is refused rather than followed. There is no way to seed a session for
327
- a site you do not own.
328
-
329
- ## Reading the result
330
-
331
- `{ console_errors, page_errors, failed_requests, steps:[{step, ok,
332
- error?, duration_ms}], screenshots:[{label, fs_path}], final_url, passed }`
333
-
334
- `passed` requires successful steps and request expectations, no page
335
- errors, and no unexpected failed requests. It can be false even when every
336
- step succeeded. Console messages are additional diagnostic evidence; inspect
337
- them too. A failing run attempts to return `rendered_text` and a screenshot
338
- labelled `failure`; unavailable evidence is reported without hiding the
339
- original failure. Explicit `capture: false` or `screenshot: false` skips
340
- the automatic failure screenshot. With `continue_on_failure`, final evidence shows
341
- the state after the remaining actions, not necessarily the first failure.
342
-
343
- ## Screenshots — small by default
344
-
345
- Screenshots are tuned for cheap vision tokens: ~800px wide JPEG at
346
- quality 70. Need pixel precision? Override per run:
347
-
348
- browser({ project_id: 'my-saas', screenshot: { width: 1280, format: 'png' } })
349
-
350
- Fields: width (default 800, never upscaled past the viewport), format
351
- ('jpeg' default | 'png'), quality (1–100, jpeg only, default 70). The
352
- override applies to the no-steps page shot and every screenshot step.
353
- On an actions run, `capture` or `screenshot` also requests a final capture.
354
-
355
- With a project, each capture is saved to the project's files: the result gives
356
- its `fs_path` and, beside it, a signed `url` to open. On a page shot with no
357
- steps, `inline: true` also returns the image as `inline_base64`. Without a
358
- project, the capture comes back as `inline_base64`; `store: true` returns a
359
- temporary `scratch_url` instead.
360
-
361
- ## Keep one browser across calls (session_id)
362
-
363
- Checking a whole flow? Prefer ONE `somewhere verify --flow` call (above): it
364
- runs every step, opens a fresh browser per viewport and closes it inside the
365
- call, so it never holds a session.
366
-
367
- To keep a page open between calls instead, name a session: MCP
368
- `browser({ project_id, url, session_id: "checkout", actions })` or CLI
369
- `--session checkout`. The same name in the same project continues on the same
370
- page. Another project can use that name for its own separate browser.
371
-
372
- A call without `session_id` is one-shot and needs no cleanup. Named sessions
373
- share the account's limit of 10 live sessions, the same on every plan
374
- (`browser_sessions` in `GET /v1/pricing`); an account runs at most 10
375
- browser runs at once.
376
- Close your project's session when you are done:
377
- `browser({ project_id: "my-app", session_id: "checkout", close: true })`, or
378
- `somewhere browser --project my-app --close checkout`. A bare
379
- `browser({ session_id: "checkout" })` closes only a session without a project.
380
- If other projects hold the remaining slots, the limit error says when to retry;
381
- it does not tell you to close their sessions.
382
-
383
- A named session keeps its cookies and page after a failed step; a page
384
- crash, a page that leaves your app, or a call that ends in an error or an
385
- unknown outcome closes it. It ends after 5
386
- minutes idle or 10 minutes in total. A call under that name within 24 hours of its launch
387
- reports `session_note`: a fresh, signed-out browser was started. With the
388
- CLI, `--url` only sets where a new session starts; move a live session with
389
- `--path` or a `goto` action.
390
-
391
-
392
- ## Several users in one run
393
-
394
- A flow file with `actors` and `journey` checks what several signed-in
395
- people see, each in their own browser:
396
- `somewhere verify --project <project> --flow flow.json`. This one runs on the
397
- starter from `somewhere init --name my-app --features private-data` with two
398
- `test_user` actors, which `verify` creates for this run. Alice saves a note,
399
- an empty Bob account sees none of Alice's notes, and Alice checks her list on a
400
- phone. The seeded session skips signup/login UI; it does not test passwords,
401
- verification email. Test those genuine journeys separately when
402
- relevant, rather than creating a new email/account for every data check.
403
-
404
- ```json
405
- {
406
- "actors": { "alice": { "test_user": true }, "bob": { "test_user": true } },
407
- "journey": [
408
- { "as": "alice", "path": "/", "actions": [
409
- { "wait": "#note-title" },
410
- { "fill": "#note-title", "value": "Alice's note" },
411
- { "click": "form:has(#note-title) button[type=submit]" },
412
- { "expect": { "selector": ".note__title", "text": "Alice's note" } }
413
- ] },
414
- { "as": "bob", "path": "/", "actions": [
415
- { "expect": { "selector": ".empty__title", "text": "No notes yet." } }
416
- ] },
417
- { "as": "alice", "path": "/", "viewport": "mobile", "actions": [
418
- { "expect": { "selector": ".note__title", "text": "Alice's note" } }
419
- ] }
420
- ]
421
- }
422
- ```
423
-
424
- - `actors`: 1–3 names; each is its own browser. `{}` starts signed out;
425
- `{ "auth": { "user_id": "…" } }` signs in as a managed test user of the
426
- project. Seeds go only to that actor, only on its first segment.
427
- - `{ "test_user": true }` (CLI 0.37.46 or later; not combined with `auth` or
428
- other seeds): before the first segment `verify` creates one verified test user
429
- per such actor with a single `POST /v1/auth/test-users` call, and starts no
430
- browser if that fails. Each actor signs in once, in its own browser. When the
431
- run ends, `verify` asks the platform to delete those users;
432
- `--keep-test-users` keeps them (test users expire 24 hours after creation).
433
- The report's `test_users` lists each actor's `user_id` and `email`
434
- and a cleanup `status` of `deleted`, `kept` or `unconfirmed`.
435
- - `--keep-actors` (CLI 0.37.66 or later): after a fully passed run, `verify`
436
- keeps each actor's signed-in browser and test user, keyed to this project
437
- folder, flow file and cast. The next run of the same flow file reconnects to
438
- them and re-signs in, so it skips test-user creation, browser startup and
439
- cleanup.
440
- - Each run still navigates every actor to its first segment's path and runs
441
- the same checks. Cookies, storage and app data the actors created carry
442
- over, so checks must not assume an empty account. A pass on a kept browser
443
- is a warm recheck, not fresh first-load evidence.
444
- - Any failed, stopped or unconfirmed run cleans up exactly as without the
445
- flag. One run per kept flow at a time.
446
- - `--close-actors` closes the kept browsers and deletes the kept test users
447
- for this project in this folder. Kept browsers close after 5 minutes without
448
- use, and at the latest 10 minutes after they started; the next run then
449
- starts fresh and says so on stderr.
450
- - A run that cannot reconnect (new or renamed flow file, or a changed cast)
451
- says so on stderr.
452
- - `--resume-page` (with `--keep-actors`; CLI 0.37.69 or later): an explicit
453
- stateful warm continuation, like reusing a Playwright page.
454
- - An actor whose first segment starts at exactly the page path the last
455
- passed run left it on keeps that page (no reload).
456
- - A different actor, flow, project or start path, a start path with a query,
457
- or a kept browser that has ended loads normally.
458
- - The kept page may run code from before the latest deploy. The report lists
459
- `keep_actors.resumed_pages`, and a resumed run is not evidence for the
460
- latest release: verify a deploy without `--resume-page`.
461
- - `journey`: 1–12 segments, run in order, each
462
- `{ as, path?, actions?, expect_requests?, viewport?, visible_only? }`. A later
463
- segment for the same actor continues in that actor's browser; its `path`
464
- becomes a leading `{ "goto": "/path" }` (counted in its 30 actions).
465
- - `{ "parallel": [segment, segment] }` (CLI 0.37.46 or later) runs 2–3
466
- segments by different actors at the same time, for example one waits for a
467
- message while another sends it. Each keeps its own browser; groups cannot be
468
- nested, a group starts together or not at all, and its segments count toward
469
- the 12-segment limit.
470
- - `viewport` belongs to that segment (`desktop` by default, `mobile`, or
471
- `{ label, width, height }`): the journey runs once, not once per viewport,
472
- because it changes app data. The report's `layout` line flags contrast,
473
- horizontal overflow and tap targets.
474
- - A request a user should be refused passes only when declared in that
475
- segment's `expect_requests` (e.g. `{ "path": "/api/admin", "status": 403 }`;
476
- a refused generated-client update or delete is `/__sw/data` 404) and seen. The first failing segment stops the run; the verdict names the
477
- segment, actor, step and viewport, and later segments are reported not run.
478
- - Limits: 3 actors, 12 segments, 30 actions per segment, 120 in total, up to
479
- 180 s per
480
- segment, 10 minutes per journey. Each segment is one browser run against your
481
- plan's browser limits. Hosted apps only.
482
- - Browser time is reserved before a run: its `budget_ms` plus 45 s of startup
483
- headroom, and for a segment that keeps its actor's browser, up to 300 s that
484
- browser may idle afterwards (525 s for a verify segment). A run is charged
485
- its own time. A kept browser's idle time is charged until the next segment
486
- reuses it, the run closes it, or the browser service reports it closed; one
487
- nothing confirms stays charged at the full 300 s. Unused reserved time is
488
- returned when the run ends. A refusal is
489
- `BROWSER_DAILY_LIMIT` (429) with `data: { reason, used, limit, requested,
490
- unconfirmed }`, where `reason` is `duration_exhausted` and `unconfirmed`
491
- is the part of `used` only held for runs or kept browsers whose end is not
492
- yet confirmed;
493
- `BROWSER_SESSION_LIMIT` means too many runs at once.
494
- - Needs a claimed account and permission to keep named browser sessions.
495
- A temporary account is refused `CLAIM_ACCOUNT_REQUIRED`; a project-scoped
496
- CLI login is refused `SESSION_SCOPE_FORBIDDEN` for these persistent sessions.
497
- Fresh one-user flows can run within the CLI login's approved project scope.
498
- - When the run ends or is interrupted, cleanup attempts to close every actor's
499
- browser within a 20-second budget. A close that cannot be confirmed (for
500
- example a segment still running when the budget ran out) is listed as
501
- `unconfirmed` in `cleanup`, and the platform closes idle browsers
502
- within 5 minutes. An actor
503
- idle longer than that between its segments has lost its browser: the run
504
- fails at that segment rather than continuing signed out.
505
- - The journey writes through the app like its users do; nothing is cleared.
506
- Full schema: `somewhere verify --schema`. MCP `site_verify` takes only the
507
- one-user form; chain `browser({ session_id })` calls instead.
508
-
509
- ### When signup or login is the behavior under test
510
-
511
- Use signed-out actors (`{}`) and drive the real app forms. Authenticate each
512
- actor once, then use later segments for that actor to check the next state; its
513
- browser keeps the session. Replace these selectors and paths with your app's
514
- actual UI. Use controlled test addresses and the test inbox if the app requires
515
- email verification: a flow cannot read the inbox, so run
516
- `somewhere email test-inbox <address>` between flows and use the code or
517
- link in the next flow. A seeded
518
- `auth: { user_id }` actor above proves signed-in app behavior, not signup or
519
- login.
520
-
521
- ```json
522
- {
523
- "actors": { "alice": {}, "bob": {} },
524
- "journey": [
525
- { "as": "alice", "path": "/signup", "actions": [
526
- { "fill": "#email", "value": "alice@<project>.test.somewhere.site" },
527
- { "fill": "#password", "value": "<test-password>" },
528
- { "click": "#sign-up" },
529
- { "expect": { "selector": "#signed-in", "visible": true } }
530
- ] },
531
- { "as": "bob", "path": "/signin", "actions": [
532
- { "fill": "#email", "value": "bob@<project>.test.somewhere.site" },
533
- { "fill": "#password", "value": "<test-password>" },
534
- { "click": "#sign-in" },
535
- { "expect": { "selector": "#signed-in", "visible": true } }
536
- ] },
537
- { "as": "alice", "path": "/board", "actions": [
538
- { "fill": "#item-title", "value": "Shared plan" },
539
- { "click": "#create-item" },
540
- { "expect": { "selector": "#item-title-display", "text": "Shared plan" } }
541
- ] },
542
- { "as": "bob", "path": "/board", "actions": [
543
- { "expect": { "selector": "#item-title-display", "text": "Shared plan" } }
544
- ] }
545
- ]
546
- }
547
- ```
548
-
549
- Wait for the visible result of each click with `expect`, rather than adding
550
- fixed delays. Keep test credentials in a local ignored flow file, never in
551
- deployed app source. The example checks one possible shared-board app; it does
552
- not grant Bob access or create an account for him. Each segment makes one
553
- browser-test request, including segments that resume an actor; grouping
554
- consecutive steps for the same actor into one segment uses fewer daily runs
555
- without skipping those steps or their outcome checks.
556
-
557
- ## Local Playwright and agent-browser (CLI 0.37.63+)
558
-
559
- Pick by the job, not by a default:
560
-
561
- - `somewhere verify`: no local browser. It creates its own managed test
562
- users for the run (`test_user` actors, above) and reports every step's
563
- console and network checks.
564
- - Playwright on your machine: repeatable test files, native gestures, several
565
- tabs, network control.
566
- - agent-browser: exploring the app interactively from an agent.
567
-
568
- Both local tools sign in from the same prepared test users. In the linked
569
- project folder:
570
-
571
- ```bash
572
- somewhere test-users prepare alice bob
573
- ```
574
-
575
- This creates preverified test users and writes
576
- `.somewhere/test/<actor>.state.json` (a standard Playwright storageState) and
577
- `manifest.json`. The folder is private and gitignored, holds each actor's app
578
- session and never your developer key. Only the app's production origin is
579
- supported.
580
-
581
- ```ts
582
- const context = await browser.newContext({ storageState: '.somewhere/test/alice.state.json' });
583
- // … the test …
584
- await context.storageState({ path: '.somewhere/test/alice.state.json' });
585
- ```
586
-
587
- ```bash
588
- # Set PROJECT to your app's subdomain.
589
- agent-browser --state .somewhere/test/alice.state.json open "https://${PROJECT}.somewhere.site"
590
- agent-browser state save .somewhere/test/alice.state.json
591
- ```
592
-
593
- Save the state back after every run, as above. The app refreshes the short
594
- access token, and its first refresh rotates the session, so a file that was not
595
- saved back stops signing in. Import with `--state` at launch; with
596
- agent-browser 0.39.1, `state load` before a browser exists fails.
597
-
598
- The state from `prepare` starts with a session that ends an hour later. A
599
- refresh during a run renews it, and the saved-back state carries the renewed
600
- cookies, so a state you keep saving back goes on working past that hour. Do not
601
- rely on expiry to end it: run `cleanup` when you are done.
602
-
603
- A prepared actor is not evidence that signup or email verification works. To
604
- test those, use a fresh address and read only mail sent after its checkpoint:
605
-
606
- ```bash
607
- somewhere test-users address --json # { address, checkpoint }
608
- # sign up in the app with that address, then:
609
- somewhere test-users inbox <address> --since <checkpoint> --wait 10000 --json
610
- ```
611
-
612
- `inbox` returns the newest message after the checkpoint with its
613
- `verification_code`; it never returns older mail and never resends
614
- (`TEST_INBOX_NO_NEW_MESSAGE`). The magic link is printed only with
615
- `--json --include-link`, or written privately with `--link-out`.
616
-
617
- ```bash
618
- somewhere test-users cleanup
619
- ```
620
-
621
- Cleanup deletes the test users this folder prepared, with their sessions, and
622
- the local state files, then writes `.somewhere/test/cleanup-receipt.json`. A
623
- copy of a state file signs nobody in once its short access token (up to a
624
- minute) has expired.
625
- App rows, files and stored test mail those users created are kept; a user who
626
- signed up through your app is not a prepared test user and is not removed. For
627
- full isolation, use a disposable project and delete it.
628
- ## Limits
629
- - At most 30 actions and a default 60-second action budget.
630
- - Account run, duration, and concurrency limits apply. A refusal supplies the
631
- limit and retry information; it is not a failed app assertion.
632
- - Project-backed runs require access to that project. Screenshots stored in
633
- project files also use its file allowance and write limits.
634
- - Temporary accounts may test their own project and cannot retain a browser
635
- session.
636
- - Signed-in accounts may inspect and screenshot other public websites;
637
- temporary accounts stay within their own project, as above. On either,
638
- actions, `eval` and seeded sessions are available only against an
639
- authorized project's own origins.