@ultimat3/cli 31.45.0 → 31.47.0
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/CLAUDE.md +1 -1
- package/README.md +1 -1
- package/package.json +29 -29
- package/src/affected.ts +3 -2
- package/src/app-config-load.ts +8 -5
- package/src/app-mcp.ts +2 -5
- package/src/app-runtime.ts +4 -4
- package/src/cmd-cache.ts +8 -4
- package/src/cmd-deploy-compose.ts +11 -12
- package/src/cmd-deploy-helm.ts +5 -8
- package/src/cmd-exercise-spec.ts +2 -2
- package/src/cmd-exercise.ts +7 -19
- package/src/cmd-new.ts +4 -3
- package/src/cmd-planned.ts +11 -76
- package/src/cmd-shot-matrix.ts +3 -2
- package/src/cmd-token.ts +11 -3
- package/src/codemods/ci-weekly-schedule.ts +61 -0
- package/src/codemods/index.ts +2 -0
- package/src/codemods/vendored-guards.ts +3 -5
- package/src/codemods/verify-floor-skips.ts +4 -6
- package/src/codemods/verify-floor-steps.ts +4 -3
- package/src/db-seed.ts +3 -2
- package/src/dispatch.ts +2 -11
- package/src/duplicate-packages.ts +4 -4
- package/src/exercise-findings.ts +4 -3
- package/src/exercise-floor.ts +1 -1
- package/src/exercise-seed.ts +34 -0
- package/src/fix-command.ts +2 -3
- package/src/flag-reads.ts +6 -3
- package/src/generate-files.ts +10 -6
- package/src/gitignore.ts +4 -3
- package/src/guards-built-in.ts +3 -6
- package/src/guards.ts +5 -8
- package/src/island-bundle.ts +3 -2
- package/src/island-sources.ts +4 -3
- package/src/island-states-load.ts +4 -3
- package/src/island-store.ts +3 -2
- package/src/json-merge.ts +8 -6
- package/src/lint-findings.ts +4 -7
- package/src/mcp-errors.ts +1 -1
- package/src/messages.ts +1 -0
- package/src/prerender-out.ts +4 -3
- package/src/publish-closure.ts +4 -6
- package/src/pwa-manifest-locales.ts +5 -8
- package/src/registry.ts +0 -7
- package/src/root-env.ts +3 -2
- package/src/runtime-admin.ts +2 -4
- package/src/runtime-keys.ts +5 -2
- package/src/static-report.ts +5 -8
- package/src/templates/github/ci-schedule.ts +86 -0
- package/src/templates/github/ci.yml.ts +6 -8
- package/src/templates/github/dependabot.yml.ts +6 -1
- package/src/templates/invite-tests.ts +43 -6
- package/src/templates/invite.ts +12 -14
- package/src/templates/scaffold-docs.ts +1 -0
- package/src/templates/shapes/overlay.ts +4 -7
- package/src/templates/sign-in-action-tests.ts +71 -21
- package/src/templates/sign-in-password.ts +9 -5
- package/src/templates/sign-in-shared.ts +7 -15
- package/src/upgrade-guards-baseline.ts +3 -5
- package/src/verify-merge-skips.ts +2 -4
- package/src/verify-merge.ts +13 -8
- package/src/verify-part-step.ts +5 -7
- package/src/worker-bundle.ts +4 -2
- package/wiki/Actions.md +69 -5
- package/wiki/Agents.md +13 -0
- package/wiki/Auth.md +4 -0
- package/wiki/Batching-And-Preloading.md +77 -3
- package/wiki/CLI-Reference.md +18 -5
- package/wiki/Caching-And-Invalidation.md +76 -23
- package/wiki/Client-Navigation.md +2 -0
- package/wiki/Configuration.md +17 -4
- package/wiki/Entities-And-Migrations.md +168 -6
- package/wiki/FAQ.md +1 -1
- package/wiki/Feature-Flags.md +3 -0
- package/wiki/Getting-Started.md +27 -1
- package/wiki/Jobs-And-Workflows.md +70 -13
- package/wiki/Known-Gaps.md +58 -49
- package/wiki/MCP-And-AI.md +43 -3
- package/wiki/Mail.md +6 -0
- package/wiki/Migrations-And-Backfills.md +13 -0
- package/wiki/Money.md +20 -1
- package/wiki/N-Plus-One-Detection.md +31 -1
- package/wiki/Notify.md +13 -2
- package/wiki/PWA-And-Offline.md +34 -4
- package/wiki/Policies-And-Authz.md +27 -5
- package/wiki/Queries-And-Live-Queries.md +41 -4
- package/wiki/Realtime.md +22 -0
- package/wiki/Resource-Management.md +6 -1
- package/wiki/Routes-And-Render-Modes.md +54 -6
- package/wiki/SEO.md +24 -2
- package/wiki/Scheduled-Tasks.md +29 -11
- package/wiki/Scraping.md +33 -2
- package/wiki/Static-Assets.md +1 -0
- package/wiki/Storage-And-Uploads.md +8 -1
- package/wiki/Testing.md +120 -13
- package/wiki/The-Eight-Primitives.md +125 -6
- package/wiki/Timezones-And-Dates.md +13 -5
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-02-First-Feature.md +6 -0
- package/wiki/Tutorial-03-Auth-And-Admin.md +8 -0
- package/wiki/Tutorial-04-Jobs-And-Realtime.md +40 -2
- package/wiki/Tutorial-06-Growing-Up.md +1 -2
- package/wiki/UI-Components.md +14 -5
- package/wiki/Upgrading.md +42 -4
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// The tests `x g invite` writes beside its files: the link shape on its own, then each action RUN
|
|
2
2
|
// inside a real request context over the app's migrated database, so the paths a person takes —
|
|
3
|
-
// refused, invited, joined, replayed, removed — are what is held.
|
|
3
|
+
// refused, invited, joined, replayed, removed — are what is held. A browser's own form is posted
|
|
4
|
+
// through the pipeline as well (`formPostSource`), so each 303 is the action's `native:` answer.
|
|
5
|
+
|
|
6
|
+
import { formPostSource } from './sign-in-action-tests';
|
|
4
7
|
|
|
5
8
|
const DATABASE = `// A template restore is ~0.5 s; its first build (initdb plus every migration) is what this bounds.
|
|
6
9
|
const BOOT_MS = 120_000;
|
|
@@ -15,7 +18,7 @@ afterAll(() => setDbClient(undefined));`;
|
|
|
15
18
|
const SHARED_IMPORTS = `import { migratedDatabase } from '@ultimat3/cli';
|
|
16
19
|
import { type Actor, runWithContext } from '@ultimat3/core';
|
|
17
20
|
import { setDbClient } from '@ultimat3/db';
|
|
18
|
-
import { asCtx, defineHttpConfig, requestContext } from '@ultimat3/http';
|
|
21
|
+
import { asCtx, defineHttpConfig, httpServer, requestContext } from '@ultimat3/http';
|
|
19
22
|
import { testActor } from '@ultimat3/policy';
|
|
20
23
|
import { afterAll, beforeAll, expect, reusableDatabase, unitTest } from '@ultimat3/testing';`;
|
|
21
24
|
|
|
@@ -36,7 +39,9 @@ const postAs = (
|
|
|
36
39
|
return { output, request };
|
|
37
40
|
};
|
|
38
41
|
|
|
39
|
-
const target = ${action}.named('${action}')
|
|
42
|
+
const target = ${action}.named('${action}');
|
|
43
|
+
|
|
44
|
+
${formPostSource(true)}`;
|
|
40
45
|
|
|
41
46
|
/** Org ids are uuids: \`x_users.org_id\` is one. */
|
|
42
47
|
const ORGS = `const ORG = '00000000-0000-4000-8000-0000000000a1';
|
|
@@ -75,8 +80,9 @@ unitTest('an invite is the declared member-invite purpose and lives a week', ()
|
|
|
75
80
|
export const inviteMemberTest =
|
|
76
81
|
(): string => `// inviteMember, run inside a real request over the app's migrated database: an actor without the
|
|
77
82
|
// grant is refused, and one holding it mails a single-use link into their own org.
|
|
83
|
+
import { toRoute } from '@ultimat3/action';
|
|
78
84
|
${SHARED_IMPORTS}
|
|
79
|
-
import { INVITE_ACCEPT_PATH } from '../invite';
|
|
85
|
+
import { INVITE_ACCEPT_PATH, INVITES_PATH } from '../invite';
|
|
80
86
|
import { inviteMember } from './invite-member';
|
|
81
87
|
|
|
82
88
|
${DATABASE}
|
|
@@ -133,15 +139,27 @@ unitTest('with no APP_URL declared nothing is mailed', async ({ mail, runJobs })
|
|
|
133
139
|
await runJobs.drain();
|
|
134
140
|
expect(mail.lastTo('nobody@example.com')).toBeUndefined();
|
|
135
141
|
});
|
|
142
|
+
|
|
143
|
+
// \`mail\` named so the fixture installs the test mail driver the pipeline's send reaches.
|
|
144
|
+
unitTest('a browser posting the invite form is sent back', async ({ mail, runJobs }) => {
|
|
145
|
+
const inviter = testActor('inviter', { orgId: ORG, permissions: ['member:invite'] }).actor;
|
|
146
|
+
await withAppUrl('https://invites.example', async () => {
|
|
147
|
+
const { landed } = await formPost({ email: 'form@example.com' }, inviter);
|
|
148
|
+
expect(landed).toEqual({ status: 303, location: INVITES_PATH });
|
|
149
|
+
});
|
|
150
|
+
await runJobs.drain();
|
|
151
|
+
expect(mail.lastTo('form@example.com')).toBeDefined();
|
|
152
|
+
});
|
|
136
153
|
`;
|
|
137
154
|
|
|
138
155
|
export const acceptInviteTest =
|
|
139
156
|
(): string => `// acceptInvite, run inside a real request over the app's migrated database: anonymous is refused,
|
|
140
157
|
// the invited account joins and its session is rotated, and the spent link never works again.
|
|
158
|
+
import { toRoute } from '@ultimat3/action';
|
|
141
159
|
import { login, register } from '@ultimat3/auth';
|
|
142
160
|
${SHARED_IMPORTS}
|
|
143
161
|
import { appAuth } from '../auth';
|
|
144
|
-
import { memberInvite } from '../invite';
|
|
162
|
+
import { AFTER_JOIN, memberInvite } from '../invite';
|
|
145
163
|
import { acceptInvite } from './accept-invite';
|
|
146
164
|
|
|
147
165
|
${DATABASE}
|
|
@@ -186,15 +204,28 @@ unitTest('a link for one org redeems in no other', async () => {
|
|
|
186
204
|
expect(refused).toBeUltimateError('X_UNAUTHENTICATED');
|
|
187
205
|
expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBeNull();
|
|
188
206
|
});
|
|
207
|
+
|
|
208
|
+
unitTest('a browser accepting from the invite page is sent on into the app', async () => {
|
|
209
|
+
const user = await register(appAuth(), { email: 'form-join@example.com', password: PASSWORD });
|
|
210
|
+
const { token } = await memberInvite.invite(appAuth(), silent, {
|
|
211
|
+
orgId: ORG,
|
|
212
|
+
email: 'form-join@example.com',
|
|
213
|
+
locale: 'en',
|
|
214
|
+
});
|
|
215
|
+
const { landed } = await formPost({ orgId: ORG, token }, testActor(user.id).actor);
|
|
216
|
+
expect(landed).toEqual({ status: 303, location: AFTER_JOIN });
|
|
217
|
+
expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBe(ORG);
|
|
218
|
+
});
|
|
189
219
|
`;
|
|
190
220
|
|
|
191
221
|
export const revokeInviteTest =
|
|
192
222
|
(): string => `// revokeInvite, run inside a real request over the app's migrated database: an actor without the
|
|
193
223
|
// grant is refused, and an inviter removes a joined member from their own org.
|
|
224
|
+
import { toRoute } from '@ultimat3/action';
|
|
194
225
|
import { register } from '@ultimat3/auth';
|
|
195
226
|
${SHARED_IMPORTS}
|
|
196
227
|
import { appAuth } from '../auth';
|
|
197
|
-
import { memberInvite } from '../invite';
|
|
228
|
+
import { INVITES_PATH, memberInvite } from '../invite';
|
|
198
229
|
import { revokeInvite } from './revoke-invite';
|
|
199
230
|
|
|
200
231
|
${DATABASE}
|
|
@@ -225,4 +256,10 @@ unitTest('a joined member is removed from the inviter org, never from another',
|
|
|
225
256
|
expect(output.memberRemoved).toBe(true);
|
|
226
257
|
expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBeNull();
|
|
227
258
|
});
|
|
259
|
+
|
|
260
|
+
unitTest('a browser revoking from the invites page is sent back to it', async () => {
|
|
261
|
+
const inviter = testActor('inviter', { orgId: ORG, permissions: ['member:invite'] }).actor;
|
|
262
|
+
const { landed } = await formPost({ email: 'never-invited@example.com' }, inviter);
|
|
263
|
+
expect(landed).toEqual({ status: 303, location: INVITES_PATH });
|
|
264
|
+
});
|
|
228
265
|
`;
|
package/src/templates/invite.ts
CHANGED
|
@@ -43,7 +43,6 @@ const moduleSource = (
|
|
|
43
43
|
// actions beside this file are the app's policy over it.
|
|
44
44
|
${catalogImport(module)}import { defineMemberInvite, type MailSender } from '@ultimat3/auth';
|
|
45
45
|
import { EnvMissingError } from '@ultimat3/core';
|
|
46
|
-
import { setRedirect, useRequestHeader } from '@ultimat3/http';
|
|
47
46
|
import { blocks, defineMail, send, t } from '@ultimat3/mail';
|
|
48
47
|
|
|
49
48
|
/** A week: long enough to survive a holiday, short enough that a stale inbox is not a door. */
|
|
@@ -100,12 +99,6 @@ export const inviteLink =
|
|
|
100
99
|
url.search = new URLSearchParams({ orgId, token }).toString();
|
|
101
100
|
return url.href;
|
|
102
101
|
};
|
|
103
|
-
|
|
104
|
-
/** A browser that posted the native form gets a 303; an agent posting JSON gets the path as data. */
|
|
105
|
-
export const landAt = (path: string): string => {
|
|
106
|
-
if ((useRequestHeader('accept') ?? '').includes('text/html')) setRedirect(path);
|
|
107
|
-
return path;
|
|
108
|
-
};
|
|
109
102
|
`;
|
|
110
103
|
|
|
111
104
|
const policySource =
|
|
@@ -140,7 +133,7 @@ const inviteMemberSource =
|
|
|
140
133
|
import { action, t } from '@ultimat3/action';
|
|
141
134
|
import { authForbidden } from '@ultimat3/auth';
|
|
142
135
|
import { appAuth } from '../auth';
|
|
143
|
-
import { appOrigin, INVITES_PATH, inviteLink, inviteMailer,
|
|
136
|
+
import { appOrigin, INVITES_PATH, inviteLink, inviteMailer, memberInvite } from '../invite';
|
|
144
137
|
import { canInvite } from '../policy';
|
|
145
138
|
|
|
146
139
|
export const inviteMember = action({
|
|
@@ -149,6 +142,8 @@ export const inviteMember = action({
|
|
|
149
142
|
policy: canInvite,
|
|
150
143
|
// Mailing a person is a browser operation here; an app that wants it as a tool exposes it.
|
|
151
144
|
mcp: { expose: false },
|
|
145
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
146
|
+
native: { success: (output) => output.next },
|
|
152
147
|
async handle({ input, ctx }) {
|
|
153
148
|
const orgId = ctx.actor.orgId;
|
|
154
149
|
if (typeof orgId !== 'string' || orgId === '') {
|
|
@@ -160,7 +155,7 @@ export const inviteMember = action({
|
|
|
160
155
|
locale: ctx.locale,
|
|
161
156
|
link: inviteLink(appOrigin(), orgId),
|
|
162
157
|
});
|
|
163
|
-
return { ok: true, next:
|
|
158
|
+
return { ok: true, next: INVITES_PATH };
|
|
164
159
|
},
|
|
165
160
|
});
|
|
166
161
|
`;
|
|
@@ -175,7 +170,7 @@ import { isAnonymous } from '@ultimat3/core';
|
|
|
175
170
|
import { useRequestContext, useRequestCookie } from '@ultimat3/http';
|
|
176
171
|
import { allow } from '@ultimat3/policy';
|
|
177
172
|
import { appAuth } from '../auth';
|
|
178
|
-
import { AFTER_JOIN,
|
|
173
|
+
import { AFTER_JOIN, memberInvite } from '../invite';
|
|
179
174
|
|
|
180
175
|
export const acceptInvite = action({
|
|
181
176
|
input: t.object({ orgId: t.uuid, token: t.string.min(1).max(256) }),
|
|
@@ -184,6 +179,8 @@ export const acceptInvite = action({
|
|
|
184
179
|
// the handler refuses an anonymous caller before it reads it.
|
|
185
180
|
policy: allow('invite-link'),
|
|
186
181
|
mcp: { expose: false },
|
|
182
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
183
|
+
native: { success: (output) => output.next },
|
|
187
184
|
async handle({ input, ctx }) {
|
|
188
185
|
if (isAnonymous(ctx.actor)) throw authUnauthenticated('POST acceptInvite');
|
|
189
186
|
const auth = appAuth();
|
|
@@ -199,7 +196,7 @@ export const acceptInvite = action({
|
|
|
199
196
|
if (joined.cookie !== undefined) {
|
|
200
197
|
useRequestContext('acceptInvite').headers.append('set-cookie', joined.cookie);
|
|
201
198
|
}
|
|
202
|
-
return { ok: true, next:
|
|
199
|
+
return { ok: true, next: AFTER_JOIN };
|
|
203
200
|
},
|
|
204
201
|
});
|
|
205
202
|
`;
|
|
@@ -210,7 +207,7 @@ const revokeInviteSource =
|
|
|
210
207
|
import { action, t } from '@ultimat3/action';
|
|
211
208
|
import { authForbidden } from '@ultimat3/auth';
|
|
212
209
|
import { appAuth } from '../auth';
|
|
213
|
-
import { INVITES_PATH,
|
|
210
|
+
import { INVITES_PATH, memberInvite } from '../invite';
|
|
214
211
|
import { canInvite } from '../policy';
|
|
215
212
|
|
|
216
213
|
export const revokeInvite = action({
|
|
@@ -218,6 +215,8 @@ export const revokeInvite = action({
|
|
|
218
215
|
output: t.object({ ok: t.boolean, next: t.string, memberRemoved: t.boolean }),
|
|
219
216
|
policy: canInvite,
|
|
220
217
|
mcp: { expose: false },
|
|
218
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
219
|
+
native: { success: (output) => output.next },
|
|
221
220
|
async handle({ input, ctx }) {
|
|
222
221
|
const orgId = ctx.actor.orgId;
|
|
223
222
|
if (typeof orgId !== 'string' || orgId === '') {
|
|
@@ -228,8 +227,7 @@ export const revokeInvite = action({
|
|
|
228
227
|
email: input.email,
|
|
229
228
|
reason: \`revokeInvite by \${ctx.actor.id}\`,
|
|
230
229
|
});
|
|
231
|
-
|
|
232
|
-
return { ok: true, next, memberRemoved: revoked.memberRemoved };
|
|
230
|
+
return { ok: true, next: INVITES_PATH, memberRemoved: revoked.memberRemoved };
|
|
233
231
|
},
|
|
234
232
|
});
|
|
235
233
|
`;
|
|
@@ -184,6 +184,7 @@ with \`X_DB_DRIFT\`, and that is the fix it names.
|
|
|
184
184
|
| \`.mcp.json\` | MCP client config: the dev tools, \`bunx @ultimat3/cli mcp serve --transport stdio\` |
|
|
185
185
|
| \`apps/web/mcp.ts\` | the app's own \`POST /mcp\`: exposed actions, behind a bearer token |
|
|
186
186
|
| \`.github/workflows/ci.yml\` | on push and pull request: \`bun run verify plan\` cuts the gate into parts, each runner runs \`bun run setup\` then its \`bun run verify --only …\`, and \`bun run verify merge\` folds them into the one verdict |
|
|
187
|
+
| \`.github/workflows/ci.yml\`, weekly | the same gate on the default branch, so a quiet repository still learns the world moved; a red run keeps one issue open until the next green one |
|
|
187
188
|
| \`.github/workflows/image.yml\` | after a green \`ci\` on the default branch: \`docker/Dockerfile\` to \`ghcr.io\`, tagged \`sha-<7>\`, always on \`ubuntu-latest\` (bash and Docker). \`ci.yml\` runs on \`vars.CI_RUNNER\`, default \`ubuntu-latest\` |
|
|
188
189
|
`;
|
|
189
190
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// catalog keys it drops, in-place edits, and files it adds. Never a second scaffold, so every fix to
|
|
3
3
|
// the default reaches every shape on the next release.
|
|
4
4
|
|
|
5
|
-
import { assert } from '@ultimat3/core';
|
|
5
|
+
import { assert, isJsonObject } from '@ultimat3/core';
|
|
6
6
|
import type { GeneratedFile, NameSet } from '../naming';
|
|
7
7
|
|
|
8
8
|
/** One in-place edit of a scaffold file: `find` must occur exactly once, or the overlay is stale. */
|
|
@@ -34,20 +34,17 @@ const CATALOG = 'packages/i18n/catalogs/en.json';
|
|
|
34
34
|
/** A stale overlay is the framework's bug, never the app's: the shape tests name which one. */
|
|
35
35
|
const FIX = 'bun test ./packages/cli/src/templates/shapes';
|
|
36
36
|
|
|
37
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
38
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
39
|
-
|
|
40
37
|
/** The catalog with each dotted key's subtree removed, re-serialised the way `catalogJson` does. */
|
|
41
38
|
export function dropCatalogKeys(contents: string, keys: readonly string[]): string {
|
|
42
39
|
const catalog: unknown = JSON.parse(contents);
|
|
43
|
-
assert(
|
|
40
|
+
assert(isJsonObject(catalog), `${CATALOG} is not a JSON object`, FIX);
|
|
44
41
|
for (const key of keys) {
|
|
45
42
|
const segments = key.split('.');
|
|
46
43
|
const leaf = segments.pop() ?? '';
|
|
47
44
|
let node: unknown = catalog;
|
|
48
|
-
for (const segment of segments) node =
|
|
45
|
+
for (const segment of segments) node = isJsonObject(node) ? node[segment] : undefined;
|
|
49
46
|
assert(
|
|
50
|
-
|
|
47
|
+
isJsonObject(node) && Object.hasOwn(node, leaf),
|
|
51
48
|
`a shape drops catalog key ${key}, which the base scaffold no longer writes`,
|
|
52
49
|
FIX,
|
|
53
50
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// The tests `x g sign-in` writes for its actions: each handler
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// The tests `x g sign-in` writes for its actions: each handler run in a real request context over
|
|
2
|
+
// the app's migrated database, so refused, signed in, second factor owed and signed out are held.
|
|
3
|
+
// `destroySessionTest` is both shapes'; the other two are the password shape's. A browser's own
|
|
4
|
+
// form is posted through the pipeline (`formPostSource`): its 303 is the action's `native:`.
|
|
5
5
|
|
|
6
6
|
/** The app's migrated database installed under `db()` for the file, as `page-db.test.ts` does. */
|
|
7
7
|
const DATABASE = `// A template restore is ~0.5 s; its first build (initdb plus every migration) is what this bounds.
|
|
@@ -18,10 +18,45 @@ afterAll(() => setDbClient(undefined));`;
|
|
|
18
18
|
const SHARED_IMPORTS = `import { migratedDatabase } from '@ultimat3/cli';
|
|
19
19
|
import { runWithContext } from '@ultimat3/core';
|
|
20
20
|
import { setDbClient } from '@ultimat3/db';
|
|
21
|
-
import { asCtx, defineHttpConfig, requestContext } from '@ultimat3/http';
|
|
21
|
+
import { asCtx, defineHttpConfig, httpServer, requestContext } from '@ultimat3/http';
|
|
22
22
|
import { afterAll, beforeAll, expect, reusableDatabase, unitTest } from '@ultimat3/testing';
|
|
23
23
|
import { appAuth } from '../auth';`;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* \`formPost\`: \`target\` posted the way a browser's own \`<form method="post">\` posts it — through
|
|
27
|
+
* the pipeline, so the 303 is what the action's \`native:\` answers. \`actor\` adds the signed-in
|
|
28
|
+
* caller an \`authenticate\` hook would resolve; without it the caller is anonymous.
|
|
29
|
+
*/
|
|
30
|
+
export const formPostSource = (actor: boolean): string => {
|
|
31
|
+
// Biome's layout: the two-parameter list fits on one line, the three-parameter one does not.
|
|
32
|
+
const signature = actor
|
|
33
|
+
? '(\n fields: Record<string, string>,\n actor: Actor,\n headers: Record<string, string> = {},\n)'
|
|
34
|
+
: '(fields: Record<string, string>, headers: Record<string, string> = {})';
|
|
35
|
+
const hooks = actor ? '\n hooks: { authenticate: () => actor },' : '';
|
|
36
|
+
return `/** \`target\` posted as a browser's own form, through the pipeline: its \`native:\` answers. */
|
|
37
|
+
const formPost = async ${signature} => {
|
|
38
|
+
const route = toRoute(target);
|
|
39
|
+
const server = httpServer({
|
|
40
|
+
routes: [route],
|
|
41
|
+
config: defineHttpConfig({ dev: true, rateLimit: { scope: 'process' } }),${hooks}
|
|
42
|
+
});
|
|
43
|
+
const response = await server.fetch(
|
|
44
|
+
new Request(\`https://app.test\${route.path}\`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: {
|
|
47
|
+
accept: 'text/html',
|
|
48
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
49
|
+
origin: 'https://app.test',
|
|
50
|
+
...headers,
|
|
51
|
+
},
|
|
52
|
+
body: new URLSearchParams(fields),
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
const landed = { status: response.status, location: response.headers.get('location') };
|
|
56
|
+
return { response, landed };
|
|
57
|
+
};`;
|
|
58
|
+
};
|
|
59
|
+
|
|
25
60
|
/** The request the pipeline would build, the action run inside it, and both handed back. */
|
|
26
61
|
const requestOf = (
|
|
27
62
|
path: string,
|
|
@@ -41,6 +76,7 @@ const requestOf = (
|
|
|
41
76
|
export const createSessionTest =
|
|
42
77
|
(): string => `// createSession, run inside a real request over the app's migrated database: a wrong password is
|
|
43
78
|
// refused, a right one sets the session cookie, and a second factor still owed holds the challenge.
|
|
79
|
+
import { toRoute } from '@ultimat3/action';
|
|
44
80
|
import { generateTotpSecret, register, saveTotpSecret } from '@ultimat3/auth';
|
|
45
81
|
${SHARED_IMPORTS}
|
|
46
82
|
import { MFA_CHALLENGE_COOKIE, SECOND_FACTOR_PATH } from '../sign-in-challenge';
|
|
@@ -53,10 +89,12 @@ const target = createSession.named('createSession');
|
|
|
53
89
|
const PASSWORD = 'a long scaffold test passphrase';
|
|
54
90
|
|
|
55
91
|
/** One POST, as the pipeline hands it to the action: the response headers come back with it. */
|
|
56
|
-
const post = async (input: Parameters<typeof target>[0]
|
|
57
|
-
${requestOf('/auth/sign-in',
|
|
92
|
+
const post = async (input: Parameters<typeof target>[0]) => {
|
|
93
|
+
${requestOf('/auth/sign-in', "{ accept: 'application/json' }", 'target(input, { ctx })')}
|
|
58
94
|
};
|
|
59
95
|
|
|
96
|
+
${formPostSource(false)}
|
|
97
|
+
|
|
60
98
|
/** A person who can sign in, under an address no other test in this file uses. */
|
|
61
99
|
const person = (email: string) => register(appAuth(), { email, password: PASSWORD });
|
|
62
100
|
|
|
@@ -91,12 +129,11 @@ unitTest('the right password sets the session cookie and lands where it was goin
|
|
|
91
129
|
expect(request.redirect).toBeUndefined();
|
|
92
130
|
});
|
|
93
131
|
|
|
94
|
-
unitTest('a browser posting the form is sent on with a 303', async () => {
|
|
132
|
+
unitTest('a browser posting the form is sent on with a 303 and the session', async () => {
|
|
95
133
|
await person('form@example.com');
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
expect(
|
|
99
|
-
expect(request.redirect).toEqual({ location: AFTER_SIGN_IN, status: 303 });
|
|
134
|
+
const { response, landed } = await formPost({ email: 'form@example.com', password: PASSWORD });
|
|
135
|
+
expect(landed).toEqual({ status: 303, location: AFTER_SIGN_IN });
|
|
136
|
+
expect(sets(response, appAuth().sessions.policy.cookieName)).toBe(true);
|
|
100
137
|
});
|
|
101
138
|
|
|
102
139
|
unitTest('a second factor still owed holds the challenge and sets no session', async () => {
|
|
@@ -112,6 +149,7 @@ unitTest('a second factor still owed holds the challenge and sets no session', a
|
|
|
112
149
|
export const confirmSessionTest =
|
|
113
150
|
(): string => `// confirmSession, run inside a real request over the app's migrated database: with no challenge
|
|
114
151
|
// held it refuses, a wrong code is refused, and the held challenge plus the right code signs in.
|
|
152
|
+
import { toRoute } from '@ultimat3/action';
|
|
115
153
|
import {
|
|
116
154
|
generateTotpSecret,
|
|
117
155
|
login,
|
|
@@ -138,6 +176,8 @@ ${requestOf(
|
|
|
138
176
|
)}
|
|
139
177
|
};
|
|
140
178
|
|
|
179
|
+
${formPostSource(false)}
|
|
180
|
+
|
|
141
181
|
/** A person with a second factor, and the cookie holding the challenge the first leg sealed. */
|
|
142
182
|
const challenged = async (email: string) => {
|
|
143
183
|
const user = await register(appAuth(), { email, password: PASSWORD });
|
|
@@ -182,11 +222,19 @@ unitTest('the held challenge and the right code sign in, and drop the challenge'
|
|
|
182
222
|
// Cleared, an empty value: the challenge is spent, and a reload starts the sign-in over.
|
|
183
223
|
expect(lines.some((line) => line.startsWith(\`\${MFA_CHALLENGE_COOKIE}=;\`))).toBe(true);
|
|
184
224
|
});
|
|
225
|
+
|
|
226
|
+
unitTest('a browser posting the second-factor form is sent on with a 303', async () => {
|
|
227
|
+
const { secret, cookie } = await challenged('second-form@example.com');
|
|
228
|
+
const code = totpCode(secret, totpStep(new Date()));
|
|
229
|
+
const { landed } = await formPost({ code, next: '/posts' }, { cookie });
|
|
230
|
+
expect(landed).toEqual({ status: 303, location: '/posts' });
|
|
231
|
+
});
|
|
185
232
|
`;
|
|
186
233
|
|
|
187
234
|
export const destroySessionTest =
|
|
188
235
|
(): string => `// destroySession, run inside a real request over the app's migrated database: a live session is
|
|
189
236
|
// revoked, and a caller with none still signs out — cleared, and landed at the home page.
|
|
237
|
+
import { toRoute } from '@ultimat3/action';
|
|
190
238
|
import { login, register } from '@ultimat3/auth';
|
|
191
239
|
${SHARED_IMPORTS}
|
|
192
240
|
import { destroySession } from './destroy-session';
|
|
@@ -196,14 +244,16 @@ ${DATABASE}
|
|
|
196
244
|
const target = destroySession.named('destroySession');
|
|
197
245
|
|
|
198
246
|
/** One sign-out POST carrying \`cookie\`, as the pipeline hands it to the action. */
|
|
199
|
-
const signOut = async (
|
|
247
|
+
const signOut = async (cookie?: string) => {
|
|
200
248
|
${requestOf(
|
|
201
249
|
'/auth/sign-out',
|
|
202
|
-
|
|
250
|
+
"{ accept: 'application/json', ...(cookie === undefined ? {} : { cookie }) }",
|
|
203
251
|
"target({ confirm: 'sign-out' }, { ctx })",
|
|
204
252
|
)}
|
|
205
253
|
};
|
|
206
254
|
|
|
255
|
+
${formPostSource(false)}
|
|
256
|
+
|
|
207
257
|
unitTest('destroySession is a declared action off the MCP surface', () => {
|
|
208
258
|
expect(target.kind).toBe('action');
|
|
209
259
|
expect(target.describe().name).toBe('destroySession');
|
|
@@ -220,18 +270,18 @@ unitTest('a live session is revoked, and a second sign-out finds nothing to revo
|
|
|
220
270
|
await register(appAuth(), { email: 'leaving@example.com', password });
|
|
221
271
|
const { token } = await login(appAuth(), { email: 'leaving@example.com', password });
|
|
222
272
|
const cookie = \`\${appAuth().sessions.policy.cookieName}=\${token}\`;
|
|
223
|
-
const { output } = await signOut(
|
|
273
|
+
const { output } = await signOut(cookie);
|
|
224
274
|
expect(output).toEqual({ ok: true, next: '/', revoked: true });
|
|
225
|
-
expect((await signOut(
|
|
275
|
+
expect((await signOut(cookie)).output.revoked).toBe(false);
|
|
226
276
|
});
|
|
227
277
|
|
|
228
278
|
unitTest('with no session it still signs out, and a browser lands at the home page', async () => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
expect(
|
|
279
|
+
expect((await signOut()).output).toEqual({ ok: true, next: '/', revoked: false });
|
|
280
|
+
const { response, landed } = await formPost({ confirm: 'sign-out' });
|
|
281
|
+
expect(landed).toEqual({ status: 303, location: '/' });
|
|
232
282
|
// The expired session cookie and the cleared browser state, whether or not a session existed.
|
|
233
283
|
const expired = \`\${appAuth().sessions.policy.cookieName}=;\`;
|
|
234
|
-
expect(
|
|
235
|
-
expect(
|
|
284
|
+
expect(response.headers.getSetCookie().some((line) => line.startsWith(expired))).toBe(true);
|
|
285
|
+
expect(response.headers.get('clear-site-data')).not.toBeNull();
|
|
236
286
|
});
|
|
237
287
|
`;
|
|
@@ -74,7 +74,7 @@ import { useRequestContext } from '@ultimat3/http';
|
|
|
74
74
|
import { allow } from '@ultimat3/policy';
|
|
75
75
|
import { appAuth } from '../auth';
|
|
76
76
|
import { challengeOf, holdChallenge, SECOND_FACTOR_PATH } from '../sign-in-challenge';
|
|
77
|
-
import {
|
|
77
|
+
import { NEXT_PARAM, nextPath } from '../sign-in-flow';
|
|
78
78
|
|
|
79
79
|
export const createSession = action({
|
|
80
80
|
input: t.object({
|
|
@@ -86,6 +86,8 @@ export const createSession = action({
|
|
|
86
86
|
// Public by declaration: signing in is the one operation nobody holds a permission for yet.
|
|
87
87
|
policy: allow('public'),
|
|
88
88
|
mcp: { expose: false },
|
|
89
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
90
|
+
native: { success: (output) => output.next },
|
|
89
91
|
async handle({ input }) {
|
|
90
92
|
const request = useRequestContext('createSession');
|
|
91
93
|
try {
|
|
@@ -95,7 +97,7 @@ export const createSession = action({
|
|
|
95
97
|
ip: request.ip,
|
|
96
98
|
});
|
|
97
99
|
request.headers.append('set-cookie', signedIn.cookie);
|
|
98
|
-
return { ok: true, next:
|
|
100
|
+
return { ok: true, next: nextPath(input[NEXT_PARAM]), secondFactor: false };
|
|
99
101
|
} catch (error) {
|
|
100
102
|
const challenge = challengeOf(error);
|
|
101
103
|
if (challenge === null) throw error;
|
|
@@ -106,7 +108,7 @@ export const createSession = action({
|
|
|
106
108
|
next === undefined
|
|
107
109
|
? SECOND_FACTOR_PATH
|
|
108
110
|
: \`\${SECOND_FACTOR_PATH}?\${NEXT_PARAM}=\${encodeURIComponent(nextPath(next))}\`;
|
|
109
|
-
return { ok: false, next:
|
|
111
|
+
return { ok: false, next: then, secondFactor: true };
|
|
110
112
|
}
|
|
111
113
|
},
|
|
112
114
|
});
|
|
@@ -121,7 +123,7 @@ import { useRequestContext } from '@ultimat3/http';
|
|
|
121
123
|
import { allow } from '@ultimat3/policy';
|
|
122
124
|
import { appAuth } from '../auth';
|
|
123
125
|
import { dropChallenge, heldChallenge } from '../sign-in-challenge';
|
|
124
|
-
import {
|
|
126
|
+
import { NEXT_PARAM, nextPath } from '../sign-in-flow';
|
|
125
127
|
|
|
126
128
|
export const confirmSession = action({
|
|
127
129
|
input: t.object({
|
|
@@ -131,6 +133,8 @@ export const confirmSession = action({
|
|
|
131
133
|
output: t.object({ ok: t.boolean, next: t.string }),
|
|
132
134
|
policy: allow('public'),
|
|
133
135
|
mcp: { expose: false },
|
|
136
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
137
|
+
native: { success: (output) => output.next },
|
|
134
138
|
async handle({ input }) {
|
|
135
139
|
const request = useRequestContext('confirmSession');
|
|
136
140
|
const challenge = heldChallenge();
|
|
@@ -138,7 +142,7 @@ export const confirmSession = action({
|
|
|
138
142
|
const signedIn = await completeMfa(appAuth(), challenge, input.code, { ip: request.ip });
|
|
139
143
|
dropChallenge();
|
|
140
144
|
request.headers.append('set-cookie', signedIn.cookie);
|
|
141
|
-
return { ok: true, next:
|
|
145
|
+
return { ok: true, next: nextPath(input[NEXT_PARAM]) };
|
|
142
146
|
},
|
|
143
147
|
});
|
|
144
148
|
`;
|
|
@@ -56,10 +56,10 @@ export const arrayLiteral = (prefix: string, items: readonly string[], suffix: s
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
const flowSource =
|
|
59
|
-
(): string => `// Where a signed-in browser goes
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
import { NEXT_PARAM, nextAfterSignIn
|
|
59
|
+
(): string => `// Where a signed-in browser goes. The destination is a FIXED path or a same-origin \`?next=\`: the
|
|
60
|
+
// endpoint that hands out a session is the classic open redirect, and \`nextAfterSignIn\` is the
|
|
61
|
+
// framework's one check for it. Each action returns it as \`next\`; its \`native:\` lands there.
|
|
62
|
+
import { NEXT_PARAM, nextAfterSignIn } from '@ultimat3/http';
|
|
63
63
|
|
|
64
64
|
/** Where a browser lands with no \`?next=\`. The app's to move. */
|
|
65
65
|
export const AFTER_SIGN_IN = '/dashboard';
|
|
@@ -70,15 +70,6 @@ export { NEXT_PARAM };
|
|
|
70
70
|
/** A same-origin path to go to next, or the fallback. Never another origin. */
|
|
71
71
|
export const nextPath = (raw: string | undefined, fallback = AFTER_SIGN_IN): string =>
|
|
72
72
|
nextAfterSignIn(raw, fallback);
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* A browser that posted the native form gets a 303 to where it was going; an agent that posted
|
|
76
|
-
* JSON gets the same path as data. One operation, two audiences — \`setRedirect\` is that seam.
|
|
77
|
-
*/
|
|
78
|
-
export const landAt = (path: string): string => {
|
|
79
|
-
if ((useRequestHeader('accept') ?? '').includes('text/html')) setRedirect(path);
|
|
80
|
-
return path;
|
|
81
|
-
};
|
|
82
73
|
`;
|
|
83
74
|
|
|
84
75
|
const flowTest =
|
|
@@ -104,7 +95,6 @@ import { logout, signOutHeaders } from '@ultimat3/auth';
|
|
|
104
95
|
import { useRequestContext, useRequestCookie } from '@ultimat3/http';
|
|
105
96
|
import { allow } from '@ultimat3/policy';
|
|
106
97
|
import { appAuth } from '../auth';
|
|
107
|
-
import { landAt } from '../sign-in-flow';
|
|
108
98
|
|
|
109
99
|
export const destroySession = action({
|
|
110
100
|
// A native form with no field posts no body, and an action's input is an object: the form
|
|
@@ -113,6 +103,8 @@ export const destroySession = action({
|
|
|
113
103
|
output: t.object({ ok: t.boolean, next: t.string, revoked: t.boolean }),
|
|
114
104
|
policy: allow('public'),
|
|
115
105
|
mcp: { expose: false },
|
|
106
|
+
// A browser's own form lands where the output says; fetch and the typed client read \`next\`.
|
|
107
|
+
native: { success: (output) => output.next },
|
|
116
108
|
async handle() {
|
|
117
109
|
const auth = appAuth();
|
|
118
110
|
const token = useRequestCookie(auth.sessions.policy.cookieName);
|
|
@@ -121,7 +113,7 @@ export const destroySession = action({
|
|
|
121
113
|
for (const [name, value] of signOutHeaders({ session: auth.sessions.policy })) {
|
|
122
114
|
response.append(name, value);
|
|
123
115
|
}
|
|
124
|
-
return { ok: true, next:
|
|
116
|
+
return { ok: true, next: '/', revoked };
|
|
125
117
|
},
|
|
126
118
|
});
|
|
127
119
|
`;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// why: Bun exposes no path-join primitive; `x.verify.json` sits at the app root.
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
+
import { isJsonObject } from '@ultimat3/core';
|
|
7
8
|
import { parseJson } from './upgrade-registry';
|
|
8
9
|
import { VERIFY_FLOOR_FILE } from './verify-floor';
|
|
9
10
|
import { GUARD_BASELINE_FIELD } from './verify-guard-baseline';
|
|
@@ -11,9 +12,6 @@ import { GUARD_BASELINE_FIELD } from './verify-guard-baseline';
|
|
|
11
12
|
/** The floor's bytes before the write, or null when there was no file: what a rollback restores. */
|
|
12
13
|
export type FloorPrior = string | null;
|
|
13
14
|
|
|
14
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
15
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
16
|
* Writes `guardBaseline[name] = findings`; the prior bytes, or undefined when it refused. No file
|
|
19
17
|
* is a floor requiring no step, so the one written changes nothing but the baseline.
|
|
@@ -26,9 +24,9 @@ export async function writeGuardBaseline(
|
|
|
26
24
|
const file = Bun.file(join(root, VERIFY_FLOOR_FILE));
|
|
27
25
|
const prior = (await file.exists()) ? await file.text() : null;
|
|
28
26
|
const payload = prior === null ? { steps: [] } : parseJson(prior);
|
|
29
|
-
if (!
|
|
27
|
+
if (!isJsonObject(payload)) return undefined;
|
|
30
28
|
const current = payload[GUARD_BASELINE_FIELD];
|
|
31
|
-
if (current !== undefined && !
|
|
29
|
+
if (current !== undefined && !isJsonObject(current)) return undefined;
|
|
32
30
|
if (current !== undefined && Object.hasOwn(current, name)) return undefined;
|
|
33
31
|
const next = { ...payload, [GUARD_BASELINE_FIELD]: { ...(current ?? {}), [name]: findings } };
|
|
34
32
|
await Bun.write(file, `${JSON.stringify(next, null, 2)}\n`);
|
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
// with the reason the summed shard counts give, and the same not-strict warning a whole run
|
|
3
3
|
// prints. Split from `verify-merge.ts`, which folds the verdict; this folds the reasons.
|
|
4
4
|
|
|
5
|
+
import { isJsonObject } from '@ultimat3/core';
|
|
5
6
|
import type { StepResult } from './output';
|
|
6
7
|
import type { VerifyFloor } from './verify-floor';
|
|
7
8
|
import { ranNothingReason } from './verify-skip-reason';
|
|
8
9
|
import { skipWhy } from './verify-strict';
|
|
9
10
|
|
|
10
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
11
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
|
-
|
|
13
11
|
/** A part document's `data.skipReasons`, string values only; absent when it carries none. */
|
|
14
12
|
export const readPartSkipReasons = (
|
|
15
13
|
data: Record<string, unknown>,
|
|
16
14
|
): Readonly<Record<string, string>> | undefined => {
|
|
17
15
|
const raw = data['skipReasons'];
|
|
18
|
-
if (!
|
|
16
|
+
if (!isJsonObject(raw)) return undefined;
|
|
19
17
|
const reasons = Object.entries(raw).filter(
|
|
20
18
|
(entry): entry is [string, string] => typeof entry[1] === 'string',
|
|
21
19
|
);
|