@somewhere-cloud/cli 0.38.86 → 0.38.88
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.
- package/CHANGELOG.md +9 -0
- package/dist/commands/deploy.js +19 -8
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/docs.js +4 -3
- package/dist/commands/docs.js.map +1 -1
- package/dist/lib/app-test.d.ts +125 -0
- package/dist/lib/app-test.js +267 -0
- package/dist/lib/app-test.js.map +1 -0
- package/dist/lib/deploy-tests.d.ts +6 -0
- package/dist/lib/deploy-tests.js +13 -4
- package/dist/lib/deploy-tests.js.map +1 -1
- package/dist/lib/form-auth.d.ts +83 -0
- package/dist/lib/form-auth.js +350 -0
- package/dist/lib/form-auth.js.map +1 -0
- package/dist/lib/init-agent-guide.d.ts +2 -2
- package/dist/lib/init-agent-guide.js +61 -84
- package/dist/lib/init-agent-guide.js.map +1 -1
- package/dist/lib/init-feature-template.js +10 -10
- package/dist/lib/init-green-template.js +0 -3
- package/dist/lib/init-green-template.js.map +1 -1
- package/dist/lib/init-test-template.d.ts +1 -1
- package/dist/lib/init-test-template.js +55 -139
- package/dist/lib/init-test-template.js.map +1 -1
- package/dist/lib/init-ui-kit.d.ts +2 -2
- package/dist/lib/init-ui-kit.js +2 -2
- package/dist/lib/playwright-fixtures.d.ts +10 -45
- package/dist/lib/playwright-fixtures.js +59 -328
- package/dist/lib/playwright-fixtures.js.map +1 -1
- package/dist/lib/test-reporter.d.ts +3 -1
- package/dist/lib/test-reporter.js +31 -50
- package/dist/lib/test-reporter.js.map +1 -1
- package/dist/lib/test-run.d.ts +1 -0
- package/dist/lib/test-run.js +14 -17
- package/dist/lib/test-run.js.map +1 -1
- package/dist/script.d.ts +3 -0
- package/dist/script.js +4 -0
- package/dist/script.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +6 -2
- package/dist/lib/test-ledger.d.ts +0 -73
- package/dist/lib/test-ledger.js +0 -261
- package/dist/lib/test-ledger.js.map +0 -1
|
@@ -8,35 +8,26 @@ Enough to start a typical app: declare access and use the browser client; docs a
|
|
|
8
8
|
| Requirement | Declaration below |
|
|
9
9
|
| --- | --- |
|
|
10
10
|
| Each user sees only their own rows | notes: owner() |
|
|
11
|
-
| Team: owner
|
|
12
|
-
| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; staff by verified emailDomain |
|
|
11
|
+
| Team: owner invites members; members read/write; creator or team owner deletes | tasks: anyOf(owner(), group()); sw.groups endpoints below |
|
|
12
|
+
| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; staff by verified emailDomain (or grantableBy) |
|
|
13
13
|
| Public pages from private drafts | pages: conditional publicRead |
|
|
14
14
|
| Share one record read-only | shared_notes/note_shares: read-only grant() |
|
|
15
15
|
|
|
16
16
|
db/schema.ts is declaration only: imports, constants/spreads, default schema;
|
|
17
17
|
no helpers/expressions. id() is random text; owner() stamps user_id. client.read
|
|
18
18
|
includes the key. Inside anyOf(), owner() takes only column/read: it stamps the
|
|
19
|
-
creator, not create/delete options;
|
|
20
|
-
refused)
|
|
19
|
+
creator, not create/delete options; group() gates placement (non-member create is
|
|
20
|
+
refused); inside anyOf an operation missing from roles allows no group role. Other fields: timestamp({ default: 'now' }), text({ nullable: true });
|
|
21
21
|
indexes: [['team_id']].
|
|
22
22
|
|
|
23
23
|
\`\`\`ts
|
|
24
|
-
import { schema, table, id, text, owner,
|
|
24
|
+
import { schema, table, id, text, owner, group, anyOf, parent, appRole, boolean, grant } from 'somewhere/db';
|
|
25
25
|
export default schema({
|
|
26
26
|
notes: table({ id: id(), title: text() }, { scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'], delete: true },
|
|
27
27
|
}),
|
|
28
|
-
|
|
29
|
-
scope:
|
|
30
|
-
|
|
31
|
-
}),
|
|
32
|
-
team_members: table({ id: id(), team_id: text(), user_id: text(), role: text() }, {
|
|
33
|
-
scope: serverOnly(), unique: [['team_id', 'user_id']],
|
|
34
|
-
}),
|
|
35
|
-
tasks: table({ id: id(), team_id: text({ references: 'teams' }), title: text() }, {
|
|
36
|
-
scope: anyOf(owner(), member({ group: 'team_id', membership: 'team_members',
|
|
37
|
-
member_user: 'user_id', member_group: 'team_id', operations: ['read', 'create', 'update'] }),
|
|
38
|
-
member({ group: 'team_id', membership: 'team_members', member_user: 'user_id',
|
|
39
|
-
member_group: 'team_id', where: { role: 'owner' }, operations: ['delete'] })),
|
|
28
|
+
tasks: table({ id: id(), team_id: text(), title: text() }, {
|
|
29
|
+
scope: anyOf(owner(), group({ column: 'team_id', roles: { read: ['owner', 'admin', 'member'],
|
|
30
|
+
create: ['owner', 'admin', 'member'], update: ['owner', 'admin', 'member'], delete: ['owner'] } })),
|
|
40
31
|
client: { read: ['id', 'team_id', 'title'], create: ['team_id', 'title'], update: ['title'], delete: true },
|
|
41
32
|
}),
|
|
42
33
|
tickets: table({ id: id(), subject: text() }, {
|
|
@@ -70,7 +61,8 @@ First choice, as above: emailDomain. The role holds once the person verifies an
|
|
|
70
61
|
at that domain; no grant code. An email ending alone proves nothing: anyone can sign up
|
|
71
62
|
as anyone@your-domain without owning that mailbox. Without verification, grant only from
|
|
72
63
|
something the visitor cannot choose, such as an invitation your app issued, checked inside
|
|
73
|
-
the sign-up route:
|
|
64
|
+
the sign-up route: single use, bound to one account, its link delivered only to that person:
|
|
65
|
+
somewhere docs sw.auth --section server-assigned-app-roles-setroles.
|
|
74
66
|
messages use parent(): owner() would hide staff replies from the customer.
|
|
75
67
|
Publish pages in an owner-checked endpoint. Share with caller-scoped
|
|
76
68
|
sw.db.insert('note_shares', { grantee_id, note_id }); it checks row ownership.
|
|
@@ -86,46 +78,42 @@ export async function save(title: string) {
|
|
|
86
78
|
export const list = (after?: string) => data.notes.list({ limit: 100, after });
|
|
87
79
|
\`\`\`
|
|
88
80
|
|
|
89
|
-
Teams
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
Teams are built-in groups: the platform keeps the team, invitations, roster, removal,
|
|
82
|
+
leaving, last owner. Starting a team needs a signed-in user; joining needs a verified
|
|
83
|
+
email (a password sign-up joins once it enters its emailed code). The browser cannot call
|
|
84
|
+
sw.groups: pass each call through an endpoint. A parent() child's delete follows the task
|
|
85
|
+
(creator or team owner), so "comment author or team owner deletes" is an endpoint.
|
|
86
|
+
Staff making others staff: appRoles { staff: { grantableBy: ['staff'] } } and
|
|
87
|
+
sw.groups.appRoles.grant(request, userId, 'staff') in an endpoint (never to oneself).
|
|
88
|
+
Complete apps and specs: somewhere docs sw.groups --section team-example or staff-example.
|
|
94
89
|
|
|
95
90
|
\`\`\`ts
|
|
96
|
-
// api/teams.ts
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
91
|
+
// api/teams.ts — GET my teams (completes invitations to me); POST starts one I own
|
|
92
|
+
const refusal = (e: { code: string; message: string; status: number }) =>
|
|
93
|
+
Response.json({ error: e.code, message: e.message }, { status: e.status });
|
|
94
|
+
export const GET = sw.endpoint({ auth: 'required', handler: async ({ request }, sw) => {
|
|
95
|
+
const page = await sw.groups.list(request, { limit: 100 });
|
|
96
|
+
return page.error ? refusal(page.error) : { teams: page.data.items, next_cursor: page.data.next_cursor };
|
|
97
|
+
} });
|
|
98
|
+
export default sw.endpoint({ auth: 'required', body: { name: 'string' }, handler: async ({ request, body }, sw) => {
|
|
99
|
+
const made = await sw.groups.create(request, { name: body.name });
|
|
100
|
+
return made.error ? refusal(made.error) : { id: made.data.id };
|
|
101
|
+
} });
|
|
108
102
|
\`\`\`
|
|
109
103
|
|
|
110
104
|
\`\`\`ts
|
|
111
|
-
// api/teams/[id]/
|
|
112
|
-
export default sw.endpoint({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!teams[0]) return Response.json({ error: 'Team owner required' }, { status: 403 });
|
|
117
|
-
const { users: [target] } = await sw.auth.server.listUsers({ emails: [body.email] });
|
|
118
|
-
if (!target) return Response.json({ error: 'Account not found' }, { status: 404 });
|
|
119
|
-
await sw.db.server.insert('team_members', {
|
|
120
|
-
id: crypto.randomUUID(), team_id: params.id, user_id: target.id, role: 'member',
|
|
121
|
-
}, { onConflict: 'ignore' });
|
|
122
|
-
return { ok: true };
|
|
123
|
-
},
|
|
124
|
-
});
|
|
105
|
+
// api/teams/[id]/invitations.ts — owners invite; others 403; a member's address 409 ALREADY_MEMBER
|
|
106
|
+
export default sw.endpoint({ auth: 'required', body: { email: 'string' }, handler: async ({ request, params, body }, sw) => {
|
|
107
|
+
const sent = await sw.groups.invite(request, params.id, { email: body.email, role: 'member', redirect_uri: '/' });
|
|
108
|
+
return sent.error ? Response.json({ error: sent.error.code }, { status: sent.error.status }) : { delivery: sent.data.delivery };
|
|
109
|
+
} });
|
|
125
110
|
\`\`\`
|
|
126
111
|
|
|
112
|
+
Same shape: sw.groups.get/members(request, id), remove(request, id, userId), leave(request, id)
|
|
113
|
+
(last owner: 409 LAST_OWNER), delete(request, id) by owners.
|
|
114
|
+
|
|
127
115
|
Do not hand-write access to app-read/write data: declare who may read/write it.
|
|
128
|
-
serverOnly() fits job/import/audit/counter state
|
|
116
|
+
serverOnly() fits job/import/audit/counter state.
|
|
129
117
|
Grant ledgers use owner() without browser writes. Undeclarable: arbitrary predicates
|
|
130
118
|
(e.g. expiry) or per-role writable fields (split tables or check that write).
|
|
131
119
|
|
|
@@ -150,26 +138,17 @@ headers: { 'content-type': 'application/json' }, body: JSON.stringify(values) })
|
|
|
150
138
|
Access cookies refresh automatically. Cookie-auth POST/PATCH/DELETE from scripts
|
|
151
139
|
need Origin equal to the app URL.
|
|
152
140
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Do not rerun a suite that is already green on this release.
|
|
141
|
+
Test with an ordinary Playwright script: the journeys you changed and your access boundaries.
|
|
142
|
+
Run it only after a successful deploy: npx @somewhere-cloud/cli deploy && node tests/app-check.mjs
|
|
143
|
+
(the starter's short example; one result file, and the exit code is the verdict). Rerun only to answer a question.
|
|
144
|
+
Helpers from @somewhere-cloud/cli/script (import or require): openAppTest() then app.signUp/signIn/signOut(page)
|
|
145
|
+
through your form, app.data(page, { table, operation, id, values, where }) as that person,
|
|
146
|
+
app.expectRefused(page, request, { allowed: ownerPage }), captureResponses, dataReady, launchOptions.
|
|
147
|
+
A rebuilt sign-in form keeps data-sw-auth="email", "password", "sign-up", "sign-in" on its controls,
|
|
148
|
+
or pass app.signUp(page, { form: { email, password, signUp, signIn } }) with your own selectors.
|
|
162
149
|
Deploy raw source, no frontend build; type errors stop upload.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
newUser() takes no chosen email. Test users are verified and visible to this project's server user lookup.
|
|
166
|
-
Email-domain role: signUp(page, { domain: 'staff.example' }), then verify(page, person); newPage() for a second person.
|
|
167
|
-
Refusals: await expectRefused(person, 'notes', { operation: 'update', id, values }, { allowed: owner }) or
|
|
168
|
-
expectRefused(person, 'POST /api/x', body, { allowed }). allowed is someone the same request succeeds for;
|
|
169
|
-
an empty list, a null get or a 404 counts as refused only then. person/allowed: page, newUser() or anonymous.
|
|
170
|
-
somewhere test --phone runs every test again at 390x844.
|
|
171
|
-
For the complete owner-adds-member-by-email test and its endpoints, run
|
|
172
|
-
somewhere docs test and follow Two users sharing through the app.
|
|
150
|
+
Email-domain role: app.signUp(page, { domain: 'staff.example' }), then app.verify(page, person).
|
|
151
|
+
The complete team spec, with removal and leaving: somewhere docs sw.groups --section team-example.
|
|
173
152
|
Diagnose with somewhere errors and somewhere logs.
|
|
174
153
|
|
|
175
154
|
On demand:
|
|
@@ -177,24 +156,22 @@ On demand:
|
|
|
177
156
|
|
|
178
157
|
## Testing shared access
|
|
179
158
|
|
|
180
|
-
With the
|
|
181
|
-
|
|
159
|
+
With the team endpoints above, the owner invites a fixture by email; test users are verified,
|
|
160
|
+
so its next GET /api/teams shows the team. A test user who still owns a team is not deleted:
|
|
161
|
+
delete the team last (api/teams/[id].ts DELETE: sw.groups.delete). Group calls take
|
|
162
|
+
about a second, so raise the timeout:
|
|
182
163
|
|
|
183
164
|
\`\`\`ts
|
|
184
165
|
// tests/team.spec.ts
|
|
185
|
-
import { test, expect
|
|
186
|
-
test(
|
|
187
|
-
|
|
188
|
-
const bob = await newUser();
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
expect(added.ok()).toBeTruthy();
|
|
195
|
-
const response = await data(bob.request, 'teams', { operation: 'get', id });
|
|
196
|
-
expect(response.ok()).toBeTruthy();
|
|
197
|
-
expect((await response.json()).data).toMatchObject({ id, name });
|
|
166
|
+
import { test, expect } from '@somewhere-cloud/cli/testing';
|
|
167
|
+
test.describe.configure({ timeout: 90_000 });
|
|
168
|
+
test('owner invites a second user by email', async ({ newUser }) => {
|
|
169
|
+
const [owner, bob] = await Promise.all([newUser(), newUser()]);
|
|
170
|
+
const { id } = await (await owner.request.post('/api/teams', { data: { name: 'Shared team' } })).json();
|
|
171
|
+
expect((await owner.request.post(\`/api/teams/\${id}/invitations\`, { data: { email: bob.email } })).ok()).toBeTruthy();
|
|
172
|
+
const { teams } = await (await bob.request.get('/api/teams')).json();
|
|
173
|
+
expect(teams).toContainEqual(expect.objectContaining({ id, role: 'member' }));
|
|
174
|
+
expect((await owner.request.delete(\`/api/teams/\${id}\`)).status()).toBe(204);
|
|
198
175
|
});
|
|
199
176
|
\`\`\`
|
|
200
177
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-agent-guide.js","sourceRoot":"","sources":["../../src/lib/init-agent-guide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG
|
|
1
|
+
{"version":3,"file":"init-agent-guide.js","sourceRoot":"","sources":["../../src/lib/init-agent-guide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6K7B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,UAAU,0DAA0D,CAAC;AAE9H,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C;;+EAE+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,wDAAwD,CAAC;AAE5F,6EAA6E;AAC7E,MAAM,CAAC,MAAM,WAAW,GAAG,0HAA0H,CAAC;AAEtJ,MAAM,CAAC,MAAM,cAAc,GAAG,uCAAuC,cAAc,KAAK,cAAc,KAAK,mBAAmB,KAAK,WAAW,IAAI,CAAC;AACnJ,MAAM,CAAC,MAAM,cAAc,GAAG,4CAA4C,CAAC"}
|
|
@@ -2133,7 +2133,7 @@ export function NotesBoard({ notes }: { notes: NotesController }) {
|
|
|
2133
2133
|
<p className={notes.notice?.tone === 'error' ? 'note-status error' : 'note-status'} role="status">{notes.notice?.text ?? ''}</p>
|
|
2134
2134
|
</form>
|
|
2135
2135
|
|
|
2136
|
-
<section aria-labelledby="notes-title" aria-busy={notes.status === 'loading'}>
|
|
2136
|
+
<section aria-labelledby="notes-title" aria-busy={notes.status === 'loading'} data-sw-data={notes.status}>
|
|
2137
2137
|
<h2 id="notes-title" className="section-title">Your notes</h2>
|
|
2138
2138
|
{notes.status === 'loading' ? <p className="muted" role="status">Loading notes…</p> : null}
|
|
2139
2139
|
{notes.status === 'error' ? (
|
|
@@ -2298,7 +2298,7 @@ export function NotesBoard({ notes }: { notes: NotesController }) {
|
|
|
2298
2298
|
{editing ? <button type="button" onClick={notes.cancelEdit}>Cancel</button> : null}
|
|
2299
2299
|
<p role="status">{notes.notice?.text ?? ''}</p>
|
|
2300
2300
|
</form>
|
|
2301
|
-
<h2>Your notes</h2>
|
|
2301
|
+
<h2 data-sw-data={notes.status}>Your notes</h2>
|
|
2302
2302
|
{notes.status === 'loading' ? <p role="status">Loading notes…</p> : null}
|
|
2303
2303
|
{notes.status === 'error' ? <Alert action={<button type="button" onClick={notes.reload}>Try again</button>}>{notes.loadError}</Alert> : null}
|
|
2304
2304
|
{notes.status === 'ready' && notes.notes.length === 0 ? <EmptyState title="No notes yet." /> : null}
|
|
@@ -3196,14 +3196,14 @@ export function createFeatureTemplate(selection, options) {
|
|
|
3196
3196
|
...starterTests({ privateData }),
|
|
3197
3197
|
{ path: '.gitignore', content: 'node_modules\ndist\nbuild\n.env\n# Generated from db/schema.ts by somewhere typecheck, dev and deploy.\n__somewhere_data.d.ts\n__somewhere_files.d.ts\n' },
|
|
3198
3198
|
{ path: 'AGENTS.md', content: INIT_AGENTS_MD.replace(/## Getting started[^]*?After edits:/, `## Testing
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3199
|
+
Test the journeys you changed and your access boundaries with an ordinary Playwright script.
|
|
3200
|
+
tests/app-check.mjs is a short example to change: npx somewhere deploy && node tests/app-check.mjs
|
|
3201
|
+
(after a successful deploy only; one result file, .somewhere/app-check.json; the exit code is the verdict).
|
|
3202
|
+
Helpers from @somewhere-cloud/cli/script (import or require): signUp/signIn/signOut through your form,
|
|
3203
|
+
data(page, { table, operation, id, values, where }) as that person, expectRefused with a positive control,
|
|
3204
|
+
captureResponses, dataReady (the list has loaded), launchOptions. A rebuilt sign-in form keeps
|
|
3205
|
+
data-sw-auth="email", "password", "sign-up", "sign-in" on its controls, or pass { form: { … } } selectors.
|
|
3206
|
+
Rerun only to answer a question. A pass means the checks you wrote passed; say what they do not cover.
|
|
3207
3207
|
|
|
3208
3208
|
After edits:`) },
|
|
3209
3209
|
{ path: 'CLAUDE.md', content: INIT_CLAUDE_MD },
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CLI_VERSION } from './version.js';
|
|
2
2
|
import { INIT_AGENTS_MD, INIT_CLAUDE_MD } from './init-agent-guide.js';
|
|
3
3
|
import { ASSET_TYPES_FILE } from './init-asset-types.js';
|
|
4
|
-
import { starterTests } from './init-test-template.js';
|
|
5
4
|
const PACKAGE_JSON = `{
|
|
6
5
|
"name": "somewhere-starter",
|
|
7
6
|
"private": true,
|
|
@@ -18,7 +17,6 @@ const PACKAGE_JSON = `{
|
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
19
|
"@somewhere-cloud/cli": "${CLI_VERSION}",
|
|
21
|
-
"@playwright/test": "1.65.0",
|
|
22
20
|
"@types/react": "19.2.2",
|
|
23
21
|
"@types/react-dom": "19.2.2",
|
|
24
22
|
"typescript": "5.9.3",
|
|
@@ -169,7 +167,6 @@ Deploy the raw source. The platform compiles it; do not create or deploy a
|
|
|
169
167
|
`;
|
|
170
168
|
export function createGreenTemplate() {
|
|
171
169
|
return [
|
|
172
|
-
...starterTests({ minimal: true }),
|
|
173
170
|
{ path: '.gitignore', content: 'node_modules\ndist\nbuild\n.env\n# Generated from db/schema.ts by somewhere typecheck, dev and deploy.\n__somewhere_data.d.ts\n__somewhere_files.d.ts\n' },
|
|
174
171
|
{ path: 'AGENTS.md', content: INIT_AGENTS_MD },
|
|
175
172
|
{ path: 'CLAUDE.md', content: INIT_CLAUDE_MD },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-green-template.js","sourceRoot":"","sources":["../../src/lib/init-green-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"init-green-template.js","sourceRoot":"","sources":["../../src/lib/init-green-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;+BAeU,WAAW;;;;;;;;;;CAUzC,CAAC;AAEF,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;CAchB,CAAC;AAEF,MAAM,SAAS,GAAG;;;CAGjB,CAAC;AAEF,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;CAmBd,CAAC;AAEF,MAAM,GAAG,GAAG;;;;;;;;;CASX,CAAC;AAEF,MAAM,OAAO,GAAG;;;;;;;CAOf,CAAC;AAEF,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBX,CAAC;AAEF,MAAM,IAAI,GAAG;;;;;;;;;;CAUZ,CAAC;AAEF,MAAM,MAAM,GAAG;;;;;;;;;;;;;;CAcd,CAAC;AAEF,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Bd,CAAC;AAEF,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,yJAAyJ,EAAE;QAC1L,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE;QAC9C,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE;QAC9C,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE;QACtC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE;QAC/C,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC5C;YACE,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,oUAAoU;SAC9U;QACD,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,EAAE;QACrC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE;QACvC,EAAE,IAAI,EAAE,0BAA0B,EAAE,OAAO,EAAE,OAAO,EAAE;QACtD,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE;QAC3C,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,EAAE;QACzC,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,2EAA2E,EAAE;QACvH,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE;QACzC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE;QAC5C,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InitScaffoldFile } from './init-scaffold.js';
|
|
2
|
+
/** The starter's example script (auth starters only; the minimal starter has no sign-in form). */
|
|
2
3
|
export declare function starterTests(options?: {
|
|
3
4
|
privateData?: boolean;
|
|
4
|
-
minimal?: boolean;
|
|
5
5
|
}): InitScaffoldFile[];
|
|
@@ -1,145 +1,61 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
// This app has no sign-in screens yet, so these steps use its auth route from the page.
|
|
20
|
-
// When you add a form, replace them with your form's steps: fill, submit.
|
|
21
|
-
const viaAuthRoute = (path: string): FormSteps => async (page, { email, password }) => {
|
|
22
|
-
if (page.url() === 'about:blank') await page.goto('/');
|
|
23
|
-
await page.evaluate(async ([path, body]) => {
|
|
24
|
-
const response = await fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
25
|
-
await response.text(); // read the answer, as a form would
|
|
26
|
-
}, [path, { email, password }] as const);
|
|
1
|
+
// One short, ordinary Playwright script an agent copies and changes, not a second test suite:
|
|
2
|
+
// nothing here is discovered by `somewhere test` (it runs tests/**/*.spec.ts only). The helpers come
|
|
3
|
+
// from @somewhere-cloud/cli/script and work the same from .mjs or .cjs.
|
|
4
|
+
const SCRIPT = (privateData) => `// tests/app-check.mjs — an ordinary Playwright script for this app: change the checks to match
|
|
5
|
+
// what you built. Run it after a successful deploy, never after a refused one:
|
|
6
|
+
// npx somewhere deploy && node tests/app-check.mjs
|
|
7
|
+
// It writes its result once to .somewhere/app-check.json; the exit code is the verdict.
|
|
8
|
+
// From a .cjs script: const { openAppTest } = require('@somewhere-cloud/cli/script');
|
|
9
|
+
import { chromium } from '@playwright/test';
|
|
10
|
+
import { openAppTest${privateData ? ', captureResponses, dataReady' : ''} } from '@somewhere-cloud/cli/script';
|
|
11
|
+
|
|
12
|
+
const app = await openAppTest(); // stops if this folder has changes the live release lacks
|
|
13
|
+
const browser = await chromium.launch(app.launchOptions());
|
|
14
|
+
// One person = one browser context, signed up through the app's own form (accounts are
|
|
15
|
+
// deleted by exact id in finish()).
|
|
16
|
+
const person = async () => {
|
|
17
|
+
const page = await browser.newPage({ baseURL: app.origin });
|
|
18
|
+
return { page, account: await app.signUp(page) };
|
|
27
19
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
.
|
|
20
|
+
try {
|
|
21
|
+
const [ana, ben] = await Promise.all([person(), person()]);
|
|
22
|
+
await app.check('the signed-in page shows the account', () => ana.page.getByText(ana.account.email).waitFor());
|
|
23
|
+
await app.check('sign out, then sign back in', async () => {
|
|
24
|
+
await app.signOut(ana.page);
|
|
25
|
+
await app.signIn(ana.page, ana.account);
|
|
26
|
+
});
|
|
27
|
+
${privateData ? ` await app.check('a note stays private to its owner', async () => {
|
|
28
|
+
const secret = 'private ' + crypto.randomUUID(); // a unique value: search for it, not a common word
|
|
29
|
+
await ana.page.getByLabel('Title').fill(secret);
|
|
30
|
+
await ana.page.getByRole('button', { name: 'Add note' }).click();
|
|
31
|
+
await ana.page.getByRole('heading', { name: secret }).waitFor();
|
|
32
|
+
const seen = captureResponses(ben.page);
|
|
33
|
+
await ben.page.reload();
|
|
34
|
+
await dataReady(ben.page); // the list has loaded, not merely "signed in"
|
|
35
|
+
const leaks = await seen.find(secret);
|
|
36
|
+
if (leaks.length) throw new Error('the other person received the note: ' + JSON.stringify(leaks));
|
|
37
|
+
const { data: [note] } = await app.data(ana.page, { table: 'notes', operation: 'list', where: { title: secret } });
|
|
38
|
+
await app.expectRefused(ben.page, { table: 'notes', operation: 'get', id: note.id }, { allowed: ana.page });
|
|
39
|
+
await app.expectRefused(ben.page, { table: 'notes', operation: 'update', id: note.id, values: { title: 'changed' } }, { allowed: ana.page });
|
|
40
|
+
await app.expectRefused(ben.page, { table: 'notes', operation: 'delete', id: note.id }, { allowed: ana.page });
|
|
41
|
+
});
|
|
42
|
+
` : ''} await app.check('at phone width nothing scrolls sideways', async () => {
|
|
43
|
+
await ana.page.setViewportSize({ width: 390, height: 844 });
|
|
44
|
+
await ana.page.reload();
|
|
45
|
+
await ana.page.getByText(ana.account.email).waitFor();
|
|
46
|
+
const wide = await ana.page.evaluate(() => [document.documentElement, ...document.querySelectorAll('body *')]
|
|
47
|
+
.filter((el) => el.scrollWidth > el.clientWidth + 1
|
|
48
|
+
&& (el === document.documentElement || ['auto', 'scroll'].includes(getComputedStyle(el).overflowX)))
|
|
49
|
+
.map((el) => el.tagName.toLowerCase() + (typeof el.className === 'string' && el.className ? '.' + el.className.split(' ')[0] : '')));
|
|
50
|
+
if (wide.length) throw new Error('scrolls sideways at 390 px: ' + wide.join(', '));
|
|
51
|
+
});
|
|
52
|
+
} finally {
|
|
53
|
+
await app.finish(); // confirms the release, deletes the accounts, writes the result once
|
|
54
|
+
await browser.close();
|
|
45
55
|
}
|
|
46
56
|
`;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// One pass at phone width. Adapt: do the app's main action here, as a person on a phone would.
|
|
50
|
-
test.use({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
|
|
51
|
-
${SIDEWAYS}
|
|
52
|
-
test('phone: ${privateData ? 'sign up, add a note and sign out' : 'sign up and sign out'}', async ({ page, signUp, signOut }) => {
|
|
53
|
-
const person = await signUp(page);
|
|
54
|
-
await expect(page.getByText(person.email)).toBeVisible();
|
|
55
|
-
expect(await scrollsSideways(page), 'these scroll sideways at 390 px').toEqual([]);
|
|
56
|
-
${privateData ? ` const title = 'phone ' + crypto.randomUUID();
|
|
57
|
-
await page.getByLabel('Title').fill(title);
|
|
58
|
-
await page.getByRole('button', { name: 'Add note' }).click();
|
|
59
|
-
await expect(page.getByRole('heading', { name: title })).toBeVisible();
|
|
60
|
-
` : ''} await signOut(page);
|
|
61
|
-
});
|
|
62
|
-
`;
|
|
63
|
-
const ROUTE_PHONE = `import { test, expect } from '@somewhere-cloud/cli/testing';
|
|
64
|
-
|
|
65
|
-
// One pass at phone width. Adapt: do the app's main action here, as a person on a phone would.
|
|
66
|
-
test.use({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
|
|
67
|
-
${SIDEWAYS}
|
|
68
|
-
test('phone: the page shows the greeting from its function', async ({ page }) => {
|
|
69
|
-
await page.goto('/');
|
|
70
|
-
await expect(page.getByText('Your full-stack app is ready.')).toBeVisible();
|
|
71
|
-
expect(await scrollsSideways(page), 'these scroll sideways at 390 px').toEqual([]);
|
|
72
|
-
});
|
|
73
|
-
`;
|
|
74
|
-
// Two people, one role-holder: the access journeys. In the private-data starter the first one runs
|
|
75
|
-
// against its notes; elsewhere both say exactly what to fill in and are skipped until then.
|
|
76
|
-
const ACCESS = (variant) => `import { test, expect, data, expectRefused } from '@somewhere-cloud/cli/testing';
|
|
77
|
-
|
|
78
|
-
// Adapt: a table whose rows belong to the person who made them, values to create one, and a change.
|
|
79
|
-
const OWNED = ${variant === 'notes'
|
|
80
|
-
? `{ table: 'notes', values: { title: 'private ' + crypto.randomUUID() }, change: { title: 'changed' } }`
|
|
81
|
-
: `{ table: '', values: {} as Record<string, unknown>, change: {} as Record<string, unknown> }`};
|
|
82
|
-
// Adapt: a role from appRoles in db/schema.ts, a table only that role may use, and values to create a row.
|
|
83
|
-
const ROLE = { role: '', table: '', values: {} as Record<string, unknown> };
|
|
84
|
-
|
|
85
|
-
test('one person cannot see or change another person\\'s rows', async ({ newUser }) => {
|
|
86
|
-
test.skip(!OWNED.table, 'Fill in OWNED at the top of tests/access.spec.ts');
|
|
87
|
-
const [owner, other] = await Promise.all([newUser(), newUser()]);
|
|
88
|
-
${variant === 'notes' ? ` // The owner adds the row through the app's own form.
|
|
89
|
-
await owner.page.goto('/');
|
|
90
|
-
await owner.page.getByLabel('Title').fill(OWNED.values.title);
|
|
91
|
-
await owner.page.getByRole('button', { name: 'Add note' }).click();
|
|
92
|
-
await expect(owner.page.getByRole('heading', { name: OWNED.values.title })).toBeVisible();
|
|
93
|
-
const listed = await data(owner.request, OWNED.table, { operation: 'list', where: { title: OWNED.values.title } });
|
|
94
|
-
const { id } = (await listed.json()).data[0];
|
|
95
|
-
// The other person's own list loads without it.
|
|
96
|
-
await other.page.goto('/');
|
|
97
|
-
await expect(other.page.getByText('No notes yet.')).toBeVisible();
|
|
98
|
-
` : ` const created = await data(owner.request, OWNED.table, { operation: 'create', values: OWNED.values });
|
|
99
|
-
expect(created.status()).toBe(200);
|
|
100
|
-
const { id } = (await created.json()).data;
|
|
101
|
-
`} // Every way the other person could reach the row is refused; the owner is the positive control.
|
|
102
|
-
await Promise.all([
|
|
103
|
-
expectRefused(other, OWNED.table, { operation: 'get', id }, { allowed: owner }),
|
|
104
|
-
expectRefused(other, OWNED.table, { operation: 'list', where: { id } }, { allowed: owner }),
|
|
105
|
-
expectRefused(other, OWNED.table, { operation: 'update', id, values: OWNED.change }, { allowed: owner }),
|
|
106
|
-
expectRefused(other, OWNED.table, { operation: 'delete', id }, { allowed: owner }),
|
|
107
|
-
]);
|
|
108
|
-
// Nothing they tried changed it.
|
|
109
|
-
const after = await data(owner.request, OWNED.table, { operation: 'get', id });
|
|
110
|
-
expect((await after.json()).data).toMatchObject(OWNED.values);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('a role-holder may use what a non-holder is refused', async ({ newUser }) => {
|
|
114
|
-
test.skip(!ROLE.role, 'Fill in ROLE at the top of tests/access.spec.ts');
|
|
115
|
-
const [holder, person] = await Promise.all([newUser({ role: ROLE.role }), newUser()]);
|
|
116
|
-
const created = await data(holder.request, ROLE.table, { operation: 'create', values: ROLE.values });
|
|
117
|
-
expect(created.status()).toBe(200);
|
|
118
|
-
const { id } = (await created.json()).data;
|
|
119
|
-
await Promise.all([
|
|
120
|
-
expectRefused(person, ROLE.table, { operation: 'get', id }, { allowed: holder }),
|
|
121
|
-
expectRefused(person, ROLE.table, { operation: 'create', values: ROLE.values }, { allowed: holder }),
|
|
122
|
-
expectRefused(person, ROLE.table, { operation: 'delete', id }, { allowed: holder }),
|
|
123
|
-
]);
|
|
124
|
-
expect((await (await data(holder.request, ROLE.table, { operation: 'get', id })).json()).data).toMatchObject(ROLE.values);
|
|
125
|
-
});
|
|
126
|
-
${variant === 'minimal' ? `
|
|
127
|
-
test('visitors cannot read the server-only greetings table', async ({ anonymous }) => {
|
|
128
|
-
await expectRefused(anonymous, 'greetings', { operation: 'list' });
|
|
129
|
-
});
|
|
130
|
-
` : ''}`;
|
|
57
|
+
/** The starter's example script (auth starters only; the minimal starter has no sign-in form). */
|
|
131
58
|
export function starterTests(options = {}) {
|
|
132
|
-
|
|
133
|
-
return [
|
|
134
|
-
{ path: 'tests/account.spec.ts', content: ROUTE_ACCOUNT },
|
|
135
|
-
{ path: 'tests/phone.spec.ts', content: ROUTE_PHONE },
|
|
136
|
-
{ path: 'tests/access.spec.ts', content: ACCESS('minimal') },
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
return [
|
|
140
|
-
{ path: 'tests/account.spec.ts', content: FORM_ACCOUNT },
|
|
141
|
-
{ path: 'tests/phone.spec.ts', content: FORM_PHONE(Boolean(options.privateData)) },
|
|
142
|
-
{ path: 'tests/access.spec.ts', content: ACCESS(options.privateData ? 'notes' : 'none') },
|
|
143
|
-
];
|
|
59
|
+
return [{ path: 'tests/app-check.mjs', content: SCRIPT(Boolean(options.privateData)) }];
|
|
144
60
|
}
|
|
145
61
|
//# sourceMappingURL=init-test-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-test-template.js","sourceRoot":"","sources":["../../src/lib/init-test-template.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"init-test-template.js","sourceRoot":"","sources":["../../src/lib/init-test-template.ts"],"names":[],"mappings":"AAEA,8FAA8F;AAC9F,qGAAqG;AACrG,wEAAwE;AAExE,MAAM,MAAM,GAAG,CAAC,WAAoB,EAAE,EAAE,CAAC;;;;;;sBAMnB,WAAW,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;EAiBtE,WAAW,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;CAef,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;CAcL,CAAC;AAEF,kGAAkG;AAClG,MAAM,UAAU,YAAY,CAAC,UAAqC,EAAE;IAClE,OAAO,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|