@ultimat3/cli 31.44.0 → 31.46.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.44.0",
3
+ "version": "31.46.0",
4
4
  "description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,34 +53,34 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@babel/core": "^8.0.10",
56
- "@ultimat3/action": "31.44.0",
57
- "@ultimat3/admin": "31.44.0",
58
- "@ultimat3/ai": "31.44.0",
59
- "@ultimat3/auth": "31.44.0",
60
- "@ultimat3/cache": "31.44.0",
61
- "@ultimat3/core": "31.44.0",
62
- "@ultimat3/db": "31.44.0",
63
- "@ultimat3/entity": "31.44.0",
64
- "@ultimat3/flags": "31.44.0",
65
- "@ultimat3/http": "31.44.0",
66
- "@ultimat3/i18n": "31.44.0",
67
- "@ultimat3/jobs": "31.44.0",
68
- "@ultimat3/mail": "31.44.0",
69
- "@ultimat3/manifest": "31.44.0",
70
- "@ultimat3/mcp": "31.44.0",
71
- "@ultimat3/money": "31.44.0",
72
- "@ultimat3/notify": "31.44.0",
73
- "@ultimat3/policy": "31.44.0",
74
- "@ultimat3/pwa": "31.44.0",
75
- "@ultimat3/query": "31.44.0",
76
- "@ultimat3/realtime": "31.44.0",
77
- "@ultimat3/render": "31.44.0",
78
- "@ultimat3/schema": "31.44.0",
79
- "@ultimat3/scraping": "31.44.0",
80
- "@ultimat3/seo": "31.44.0",
81
- "@ultimat3/storage": "31.44.0",
82
- "@ultimat3/testing": "31.44.0",
83
- "@ultimat3/time": "31.44.0",
56
+ "@ultimat3/action": "31.46.0",
57
+ "@ultimat3/admin": "31.46.0",
58
+ "@ultimat3/ai": "31.46.0",
59
+ "@ultimat3/auth": "31.46.0",
60
+ "@ultimat3/cache": "31.46.0",
61
+ "@ultimat3/core": "31.46.0",
62
+ "@ultimat3/db": "31.46.0",
63
+ "@ultimat3/entity": "31.46.0",
64
+ "@ultimat3/flags": "31.46.0",
65
+ "@ultimat3/http": "31.46.0",
66
+ "@ultimat3/i18n": "31.46.0",
67
+ "@ultimat3/jobs": "31.46.0",
68
+ "@ultimat3/mail": "31.46.0",
69
+ "@ultimat3/manifest": "31.46.0",
70
+ "@ultimat3/mcp": "31.46.0",
71
+ "@ultimat3/money": "31.46.0",
72
+ "@ultimat3/notify": "31.46.0",
73
+ "@ultimat3/policy": "31.46.0",
74
+ "@ultimat3/pwa": "31.46.0",
75
+ "@ultimat3/query": "31.46.0",
76
+ "@ultimat3/realtime": "31.46.0",
77
+ "@ultimat3/render": "31.46.0",
78
+ "@ultimat3/schema": "31.46.0",
79
+ "@ultimat3/scraping": "31.46.0",
80
+ "@ultimat3/seo": "31.46.0",
81
+ "@ultimat3/storage": "31.46.0",
82
+ "@ultimat3/testing": "31.46.0",
83
+ "@ultimat3/time": "31.46.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
@@ -0,0 +1,63 @@
1
+ // 31.45.0: ci.yml's `verify-part-*` upload keeps its document one day. The verdict job reads it in
2
+ // the same run, and GitHub's 90-day default let one adopter's parts fill the org's artifact quota
3
+ // until CI could not run. Keyed on the upload's `name:` line, not the template's exact bytes, so an
4
+ // upload the app reshaped still gets it; one already holding a `retention-days` is the app's.
5
+
6
+ import { CI_WORKFLOW_PATH } from '../templates/github/ci.yml';
7
+ import type { Codemod, CodemodResult } from './codemod';
8
+ import { readText } from './engine-edits';
9
+
10
+ /** What the template writes at the end of the upload's `with:`, at its 10-column indent. */
11
+ export const RETENTION_LINES = [
12
+ " # The verdict reads it in this run only: kept GitHub's 90 days, every push's parts",
13
+ " # pile up until the org's artifact storage quota stops CI from running at all.",
14
+ ' retention-days: 1',
15
+ '',
16
+ ].join('\n');
17
+
18
+ /** The stock upload's artifact name, at whatever indent the app's `with:` sits. */
19
+ const PART_NAME = /^( +)name: verify-part-\$\{\{ matrix\.part \}\}\s*$/;
20
+
21
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
22
+
23
+ const indentOf = (line: string): number => line.length - line.trimStart().length;
24
+
25
+ /** The `with:` block holding line `at`: the run of non-blank lines at its indent or deeper. */
26
+ const blockAround = (lines: readonly string[], at: number, indent: number): [number, number] => {
27
+ const inside = (line: string | undefined): boolean =>
28
+ line !== undefined && line.trim() !== '' && indentOf(line) >= indent;
29
+ let first = at;
30
+ while (inside(lines[first - 1])) first -= 1;
31
+ let last = at;
32
+ while (inside(lines[last + 1])) last += 1;
33
+ return [first, last];
34
+ };
35
+
36
+ const reindent = (indent: number): string[] =>
37
+ RETENTION_LINES.trimEnd()
38
+ .split('\n')
39
+ .map((line) => `${' '.repeat(indent)}${line.trimStart()}`);
40
+
41
+ export const codemod: Codemod = {
42
+ id: 'ci-artifact-retention',
43
+ since: '31.45.0',
44
+ summary: `${CI_WORKFLOW_PATH}: the verify-part-* upload the verdict reads in the same run keeps its document one day, never GitHub's 90`,
45
+ run: async (app) => {
46
+ const file = await readText(app, CI_WORKFLOW_PATH);
47
+ if (file === undefined) return NOTHING;
48
+ const lines = file.text.split('\n');
49
+ // Bottom-up, so an insert never shifts a block still to be read.
50
+ for (let at = lines.length - 1; at >= 0; at -= 1) {
51
+ const indent = PART_NAME.exec(lines[at] ?? '')?.[1]?.length;
52
+ if (indent === undefined) continue;
53
+ const [first, last] = blockAround(lines, at, indent);
54
+ const block = lines.slice(first, last + 1);
55
+ if (block.some((line) => line.trimStart().startsWith('retention-days:'))) continue;
56
+ lines.splice(last + 1, 0, ...reindent(indent));
57
+ }
58
+ const next = lines.join('\n');
59
+ if (next === file.text) return NOTHING;
60
+ await app.write(CI_WORKFLOW_PATH, file.restore(next));
61
+ return { changed: [CI_WORKFLOW_PATH], skipped: [] };
62
+ },
63
+ };
@@ -1,59 +1,143 @@
1
- // 31.43.0: the workflows `x new` writes run every action by commit SHA (`templates/github/
2
- // actions.ts`), and ci.yml's checkouts drop the job token before `bun install`. Each stock line is
3
- // swapped wherever it stands — every occurrence is the template's, so many is no guess — and a
4
- // file still holding a movable `actions/*` tag after the swap is the author's, reported whole.
1
+ // 31.43.0: `x new`'s workflows run every action by commit SHA (`templates/github/actions.ts`) and
2
+ // a checkout drops the job token before `bun install`. Line by line, so any tagged major moves
3
+ // (`@v5` included); a SHA or an action with no pin is never touched, and a line no edit reads
4
+ // safely (quoted, an inline `with:`) leaves the file the author's, with the diff.
5
5
 
6
6
  import { CACHE, CHECKOUT, DOWNLOAD_ARTIFACT, UPLOAD_ARTIFACT } from '../templates/github/actions';
7
7
  import { CI_WORKFLOW_PATH } from '../templates/github/ci.yml';
8
8
  import { IMAGE_WORKFLOW_PATH } from '../templates/github/image.yml';
9
9
  import type { Codemod, CodemodApp, CodemodResult } from './codemod';
10
10
  import { unifiedDiff } from './engine-diff';
11
- import type { SnippetEdit } from './engine-edits';
12
11
  import { mergeResults, readText } from './engine-edits';
13
12
 
14
- const SETUP_BUN = ' - uses: oven-sh/setup-bun@';
13
+ /** Each action this codemod pins, to the pin the template writes today. */
14
+ const PINS: Readonly<Record<string, string>> = {
15
+ checkout: CHECKOUT,
16
+ cache: CACHE,
17
+ 'upload-artifact': UPLOAD_ARTIFACT,
18
+ 'download-artifact': DOWNLOAD_ARTIFACT,
19
+ };
15
20
 
16
- /** ci.yml: each checkout is followed by setup-bun, so it has no `with:` of its own to collide. */
17
- export const CI_PINNED_EDITS: readonly SnippetEdit[] = [
18
- {
19
- from: ` - uses: actions/checkout@v7\n${SETUP_BUN}`,
20
- to: ` - uses: ${CHECKOUT}\n with:\n persist-credentials: false\n${SETUP_BUN}`,
21
- },
22
- { from: ' - uses: actions/cache@v6\n', to: ` - uses: ${CACHE}\n` },
23
- { from: ' - uses: actions/upload-artifact@v7\n', to: ` - uses: ${UPLOAD_ARTIFACT}\n` },
24
- {
25
- from: ' - uses: actions/download-artifact@v8\n',
26
- to: ` - uses: ${DOWNLOAD_ARTIFACT}\n`,
27
- },
28
- ];
21
+ const NAMES = Object.keys(PINS).join('|');
22
+ /** A step's `uses:` on a tag — `- uses:` or a later key of the step — in the one shape edited. */
23
+ const TAGGED = new RegExp(`^( *)(- )?uses: actions/(${NAMES})@v\\d+(?:\\.\\d+){0,2}[ \\t]*$`);
24
+ /** Any mention of a pinned action that is not a SHA: what must have read as TAGGED, or be refused. */
25
+ const MENTION = new RegExp(`actions/(?:${NAMES})@(?![0-9a-f]{40}(?![\\w-]))`);
26
+ const WITH = /^with:(.*)$/;
29
27
 
30
- /** image.yml: its checkout already set `persist-credentials: false`; only the pin moves. */
31
- export const IMAGE_PINNED_EDITS: readonly SnippetEdit[] = [
32
- { from: ' - uses: actions/checkout@v7\n', to: ` - uses: ${CHECKOUT}\n` },
33
- ];
28
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
34
29
 
35
- /** A GitHub-owned action still on a tag: what a stock file never holds once the edits ran. */
36
- const MOVABLE = /uses:\s*actions\/[\w./-]+@v\d[^\n]*$/m;
30
+ /** A line this codemod cannot edit safely, as its 1-based number and text. */
31
+ class Unsafe {
32
+ constructor(
33
+ readonly line: number,
34
+ readonly text: string,
35
+ ) {}
36
+ }
37
37
 
38
- const NOTHING: CodemodResult = { changed: [], skipped: [] };
38
+ const indentOf = (line: string): number => line.length - line.trimStart().length;
39
+ const isBlank = (line: string): boolean => line.trim() === '';
40
+
41
+ /** The step's lines around its `uses:` at `at`, as [first, last], keys at `keys` columns. */
42
+ const stepRange = (lines: readonly string[], at: number, keys: number, dashed: boolean) => {
43
+ let first = at;
44
+ if (!dashed) {
45
+ while (first > 0) {
46
+ const line = lines[first - 1] ?? '';
47
+ first -= 1;
48
+ if (indentOf(line) === keys - 2 && line.trimStart().startsWith('- ')) break;
49
+ if (!isBlank(line) && indentOf(line) < keys) return undefined;
50
+ }
51
+ }
52
+ let last = at;
53
+ for (let next = at + 1; next < lines.length; next += 1) {
54
+ const line = lines[next] ?? '';
55
+ if (isBlank(line)) continue;
56
+ if (indentOf(line) < keys) break;
57
+ last = next;
58
+ }
59
+ return [first, last] as const;
60
+ };
61
+
62
+ /** The lines a checkout's step needs inserted to drop the token, and where; Unsafe when unreadable. */
63
+ const persistInsert = (
64
+ lines: readonly string[],
65
+ at: number,
66
+ keys: number,
67
+ dashed: boolean,
68
+ ): { readonly after: number; readonly lines: readonly string[] } | Unsafe | undefined => {
69
+ const range = stepRange(lines, at, keys, dashed);
70
+ if (range === undefined) return new Unsafe(at + 1, lines[at] ?? '');
71
+ const [first, last] = range;
72
+ const own = (index: number): string => {
73
+ const line = lines[index] ?? '';
74
+ return indentOf(line) === keys || (index === first && dashed) ? line.trimStart() : '';
75
+ };
76
+ for (let index = first; index <= last; index += 1) {
77
+ const key = own(index).replace(/^- /, '');
78
+ const opened = WITH.exec(key);
79
+ if (opened === null) continue;
80
+ if (!/^\s*(?:#.*)?$/.test(opened[1] ?? '')) return new Unsafe(index + 1, lines[index] ?? '');
81
+ const children = lines.slice(index + 1, last + 1).filter((line) => !isBlank(line));
82
+ if (children.some((line) => line.trimStart().startsWith('persist-credentials:'))) return;
83
+ const inner = children[0] === undefined ? keys + 2 : indentOf(children[0]);
84
+ return { after: index, lines: [`${' '.repeat(inner)}persist-credentials: false`] };
85
+ }
86
+ const pad = ' '.repeat(keys);
87
+ return { after: at, lines: [`${pad}with:`, `${pad} persist-credentials: false`] };
88
+ };
89
+
90
+ /** `text` with every tagged pin moved and each moved checkout's token dropped, or the first Unsafe. */
91
+ function pinActions(text: string): string | Unsafe {
92
+ const lines = text.split('\n');
93
+ // Bottom-up, so an insert never shifts a line still to be read.
94
+ for (let at = lines.length - 1; at >= 0; at -= 1) {
95
+ const line = lines[at] ?? '';
96
+ const tagged = TAGGED.exec(line);
97
+ if (tagged === null) {
98
+ if (MENTION.test(line)) return new Unsafe(at + 1, line);
99
+ continue;
100
+ }
101
+ const [, lead = '', dash, name = ''] = tagged;
102
+ const keys = lead.length + (dash === undefined ? 0 : 2);
103
+ if (name === 'checkout') {
104
+ const insert = persistInsert(lines, at, keys, dash !== undefined);
105
+ if (insert instanceof Unsafe) return insert;
106
+ if (insert !== undefined) lines.splice(insert.after + 1, 0, ...insert.lines);
107
+ }
108
+ lines[at] = `${lead}${dash ?? ''}uses: ${PINS[name] ?? ''}`;
109
+ }
110
+ return lines.join('\n');
111
+ }
112
+
113
+ /** The template's own change, for a file it leaves to the author. */
114
+ const TEMPLATE_DIFF = (path: string): string =>
115
+ unifiedDiff(
116
+ path,
117
+ `${Object.keys(PINS)
118
+ .map((name) => ` - uses: actions/${name}@v<N>`)
119
+ .join('\n')}\n`,
120
+ `${Object.entries(PINS)
121
+ .map(([name, pin]) =>
122
+ name === 'checkout'
123
+ ? ` - uses: ${pin}\n with:\n persist-credentials: false`
124
+ : ` - uses: ${pin}`,
125
+ )
126
+ .join('\n')}\n`,
127
+ );
39
128
 
40
- async function pin(
41
- app: CodemodApp,
42
- path: string,
43
- edits: readonly SnippetEdit[],
44
- ): Promise<CodemodResult> {
129
+ async function pin(app: CodemodApp, path: string): Promise<CodemodResult> {
45
130
  const file = await readText(app, path);
46
131
  if (file === undefined) return NOTHING;
47
- const next = edits.reduce((source, edit) => source.replaceAll(edit.from, edit.to), file.text);
48
- if (MOVABLE.test(next)) {
49
- const side = (key: 'from' | 'to') => `${edits.map((edit) => edit[key]).join('\n')}\n`;
132
+ const next = pinActions(file.text);
133
+ if (next instanceof Unsafe) {
50
134
  return {
51
135
  changed: [],
52
136
  skipped: [
53
137
  {
54
138
  path,
55
- reason: `${path} runs an actions/* step by movable tag in a shape the scaffold never wrote (${MOVABLE.exec(next)?.[0].trim() ?? ''}), so the diff below is the template's change, to make by hand`,
56
- diff: unifiedDiff(path, side('from'), side('to')),
139
+ reason: `${path}:${String(next.line)} runs ${next.text.trim()} in a shape this codemod cannot edit safely (quoted, commented, an inline with:), so the diff below is the template's change, to make by hand`,
140
+ diff: TEMPLATE_DIFF(path),
57
141
  },
58
142
  ],
59
143
  };
@@ -68,8 +152,5 @@ export const codemod: Codemod = {
68
152
  since: '31.43.0',
69
153
  summary: `${CI_WORKFLOW_PATH}, ${IMAGE_WORKFLOW_PATH}: every actions/* step pinned by commit SHA, and ci.yml's checkouts keep no git credential`,
70
154
  run: async (app) =>
71
- mergeResults([
72
- await pin(app, CI_WORKFLOW_PATH, CI_PINNED_EDITS),
73
- await pin(app, IMAGE_WORKFLOW_PATH, IMAGE_PINNED_EDITS),
74
- ]),
155
+ mergeResults([await pin(app, CI_WORKFLOW_PATH), await pin(app, IMAGE_WORKFLOW_PATH)]),
75
156
  };
@@ -7,6 +7,7 @@ import { codemod as authenticatorSessionRefusal } from './authenticator-session-
7
7
  import { codemod as biomeNoDefaultExport } from './biome-no-default-export';
8
8
  import { codemod as bunfigIslandCoverage } from './bunfig-island-coverage';
9
9
  import { codemod as chartDashboard } from './chart-dashboard';
10
+ import { codemod as ciArtifactRetention } from './ci-artifact-retention';
10
11
  import { codemod as ciE2eBrowser } from './ci-e2e-browser';
11
12
  import { codemod as ciPinnedActions } from './ci-pinned-actions';
12
13
  import { codemod as ciServicesEnv } from './ci-services-env';
@@ -65,4 +66,5 @@ export const CODEMODS: readonly Codemod[] = [
65
66
  docsEnvGuard,
66
67
  testServices,
67
68
  ciPinnedActions,
69
+ ciArtifactRetention,
68
70
  ];
@@ -151,6 +151,9 @@ ${SETUP_STEPS}
151
151
  path: \${{ runner.temp }}/parts/\${{ matrix.part }}.json
152
152
  if-no-files-found: error
153
153
  overwrite: true
154
+ # The verdict reads it in this run only: kept GitHub's 90 days, every push's parts
155
+ # pile up until the org's artifact storage quota stops CI from running at all.
156
+ retention-days: 1
154
157
 
155
158
  # THE VERDICT: \`x verify merge\` is green only when the parts are provably the whole gate — every
156
159
  # step from exactly one part, every shard of a split over one corpus, each part green. It runs
@@ -71,6 +71,7 @@ export const RELEASED_GUARD_FORMS: Readonly<
71
71
  ['3b0u9i8hze00x', 'error'],
72
72
  ],
73
73
  'undeclared-env': [
74
+ ['13k4amuxgsnla', 'error'],
74
75
  ['1xkusngzbabza', 'error'],
75
76
  ['2jbihvbp83mb4', 'error'],
76
77
  ['3gsy96z8bgrrl', 'error'],
@@ -225,7 +225,8 @@ export function undeclaredEnv(files: readonly SourceFile[], config: string): rea
225
225
  findings.push({
226
226
  code: CODE,
227
227
  cause: \`\${file.path}:\${lineOf(text, match.index)} reads \${match[0]}, which app.config.ts does not declare — x env check never asks for it, so a deploy without it boots and fails at the first read\`,
228
- fix: \`add \${name}: { type: 'string', description: '…' } to envSchema in app.config.ts, read it as env.\${name} in \${file.path}, then: x env example\`,
228
+ // Second branch: a value \`bun build --define\` bakes in is no runtime env, and no deploy sets it.
229
+ fix: \`\${name}: { type: 'string', description: '…' }, // into envSchema in app.config.ts, read it as env.\${name} in \${file.path}, then: x env example. A build-time constant, not runtime env: declare const \${name}: string in a .d.ts, read \${name} in place of \${match[0]}, and bun build --define \${name}='"…"'\`,
229
230
  at: file.path,
230
231
  });
231
232
  }
@@ -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
  `;
@@ -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, landAt, memberInvite } from '../invite';
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: landAt(INVITES_PATH) };
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, landAt, memberInvite } from '../invite';
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: landAt(AFTER_JOIN) };
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, landAt, memberInvite } from '../invite';
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
- const next = landAt(INVITES_PATH);
232
- return { ok: true, next, memberRemoved: revoked.memberRemoved };
230
+ return { ok: true, next: INVITES_PATH, memberRemoved: revoked.memberRemoved };
233
231
  },
234
232
  });
235
233
  `;
@@ -29,7 +29,7 @@ import { verifyFloor } from './scaffold-verify-floor';
29
29
  * config as out of date on every `bun run lint`. A formatter is a build input: a floating range
30
30
  * is a `lint` step whose verdict depends on the day the app was installed.
31
31
  */
32
- const BIOME_VERSION = '2.6.3';
32
+ const BIOME_VERSION = '2.6.4';
33
33
 
34
34
  /**
35
35
  * The checker a scaffolded app typechecks with, and it must not lag the one the FRAMEWORK is built
@@ -1,7 +1,7 @@
1
- // The tests `x g sign-in` writes for its actions: each handler RUN inside a real request context,
2
- // over the app's migrated database (`migratedDatabase`, the framework tables included), so the
3
- // paths a person takes — refused, signed in, a second factor owed, signed out — are what is held.
4
- // `destroySessionTest` is both shapes'; the other two are the password shape's.
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], accept = 'application/json') => {
57
- ${requestOf('/auth/sign-in', '{ accept }', 'target(input, { ctx })')}
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 input = { email: 'form@example.com', password: PASSWORD };
97
- const { output, request } = await post(input, 'text/html');
98
- expect(output.next).toBe(AFTER_SIGN_IN);
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 (accept: string, cookie?: string) => {
247
+ const signOut = async (cookie?: string) => {
200
248
  ${requestOf(
201
249
  '/auth/sign-out',
202
- '{ accept, ...(cookie === undefined ? {} : { cookie }) }',
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('application/json', cookie);
273
+ const { output } = await signOut(cookie);
224
274
  expect(output).toEqual({ ok: true, next: '/', revoked: true });
225
- expect((await signOut('application/json', cookie)).output.revoked).toBe(false);
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
- const { output, request } = await signOut('text/html');
230
- expect(output).toEqual({ ok: true, next: '/', revoked: false });
231
- expect(request.redirect).toEqual({ location: '/', status: 303 });
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(request.headers.getSetCookie().some((line) => line.startsWith(expired))).toBe(true);
235
- expect(request.headers.get('clear-site-data')).not.toBeNull();
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 { landAt, NEXT_PARAM, nextPath } from '../sign-in-flow';
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: landAt(nextPath(input[NEXT_PARAM])), secondFactor: false };
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: landAt(then), secondFactor: true };
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 { landAt, NEXT_PARAM, nextPath } from '../sign-in-flow';
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: landAt(nextPath(input[NEXT_PARAM])) };
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, and the one browser/agent split every sign-in action makes. The
60
- // destination is a FIXED path or a same-origin \`?next=\`: the endpoint that hands out a session is
61
- // the classic open redirect, and \`nextAfterSignIn\` is the framework's one check for it.
62
- import { NEXT_PARAM, nextAfterSignIn, setRedirect, useRequestHeader } from '@ultimat3/http';
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: landAt('/'), revoked };
116
+ return { ok: true, next: '/', revoked };
125
117
  },
126
118
  });
127
119
  `;
package/wiki/Upgrading.md CHANGED
@@ -312,6 +312,10 @@ A setter still on a package's `.` barrel is `X_ADAPTER_PORT_INCOMPLETE` on the `
312
312
  | a `timestamp()` filter given zoneless ISO text reads it as UTC in both drivers (**31.44.0**); a Postgres whose session `TimeZone` was not UTC read it in that zone | to mean another zone, pass a `Date` or ISO text with its offset (`'2026-01-01T00:00:00+02:00'`) |
313
313
  | a required column with no default is added nullable and contracted to NOT NULL in the migration's non-transactional step (**31.44.0**), so a fresh or reset database migrates clean | a committed migration that still holds the old `-- backfill "c", then: … set not null;` comment: declare the column `.nullable()`, `x db gen "relax c"`, declare it required again, `x db gen "contract c"`, then `x db migrate`. A populated production table: ship `.nullable()` plus its `backfill()` first, then required |
314
314
  | two shipped guards change (**31.44.0**), built in: `undeclared-env` (`X_UNDECLARED_ENV`) also refuses a `defineEnv(` record anywhere in app source whose keys `envSchema` in `app.config.ts` does not declare; `untranslated-string` (`X_UNTRANSLATED_STRING`) ends its fix with `x verify --only boundaries`. A copy still in `guards/` keeps the old rule until `x upgrade` migrates it to the release after 31.43.0 | each `undeclared-env` finding names the keys to move into `envSchema`; then `x env example` |
315
+ | `x new`'s `ci.yml` uploads each `verify-part-*` document with `retention-days: 1` (**31.45.0**): the verdict job reads it in the same run, and GitHub's 90-day default let one adopter's parts fill the org's artifact storage quota until CI could not run | nothing: `x upgrade` applies codemod `ci-artifact-retention`; an upload that already sets `retention-days` is left as it is. Artifacts already stored keep their 90 days: delete them from the repository's Actions storage settings if the quota is already full |
316
+ | codemod `ci-pinned-actions` pins any tagged major of `actions/checkout`, `cache`, `upload-artifact` and `download-artifact` (**31.45.0**), and adds `persist-credentials: false` to each checkout it pins, inside the step's own `with:` when it has one; 31.43–31.44 skipped a workflow on another major (`actions/checkout@v5`) | nothing: `x doctor` names it as `X_UPGRADE_CODEMODS_PENDING`, and `x upgrade --json` applies it. A SHA-pinned line and an action with no pin are never touched |
317
+ | the shipped `undeclared-env` guard's fix changes (**31.45.0**), built in; its findings do not: `X_UNDECLARED_ENV` still opens with the `envSchema` line to paste, and adds a second branch for a build-time constant injected by `bun build --define process.env.X=…` (declare a global, `--define NAME=…`), which no deploy sets. A copy still in `guards/` keeps the old text until `x upgrade` migrates it to the release after 31.44.0 | nothing; for a `--define` constant, follow the second branch rather than declaring an env var |
318
+ | `x g sign-in --password` and `x g invite` declare `native: { success: (output) => output.next }` on their six actions and drop the `landAt()` helper (**31.46.0**); an app scaffolded before keeps its `landAt`, whose `setRedirect` still answers its forms with a 303 | nothing. Optional, to have one redirect path: on each action, add `native: { success: (output) => output.next }`, replace `landAt(x)` with `x`, delete `landAt` from `sign-in-flow.ts` / `invite.ts`, and move the test that asserted `request.redirect` to a form post through `httpServer({ routes: [toRoute(target)] }).fetch(…)` with `accept: text/html`, asserting `303` and the `Location` — a fresh `x g sign-in --password` writes that test. Then `x verify --only unit,manifest` |
315
319
 
316
320
  ## 29.x → 30.0.0, entry by entry
317
321