create-ailk 0.34.1 → 0.36.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.
Files changed (139) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +37 -4
  3. package/component-catalog.md +11 -9
  4. package/dist/add-module.js +7 -2
  5. package/dist/derive-architecture.js +2 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/env-catalog.js +8 -0
  9. package/dist/module-architecture.js +9 -0
  10. package/dist/programmatic.js +5 -2
  11. package/dist/site-listing-path.d.ts +8 -0
  12. package/dist/site-listing-path.js +8 -0
  13. package/dist/surfaces.d.ts +20 -0
  14. package/dist/surfaces.js +32 -3
  15. package/dist/template-record.js +2 -0
  16. package/dist/topology.d.ts +4 -4
  17. package/dist/topology.js +104 -60
  18. package/dist/update.js +11 -0
  19. package/package.json +3 -3
  20. package/templates/.env.example +21 -0
  21. package/templates/apps/api/.env.example +7 -0
  22. package/templates/apps/api/CLAUDE.md +14 -9
  23. package/templates/apps/mcp/CLAUDE.md +18 -7
  24. package/templates/apps/web/.env.example +16 -0
  25. package/templates/apps/web/CLAUDE.md +46 -5
  26. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  27. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  28. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  29. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  30. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  31. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  32. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  33. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  34. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
  37. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
  38. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  39. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
  40. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
  41. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
  42. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
  43. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  44. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  45. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  46. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  47. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
  48. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
  51. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  53. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  54. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  55. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
  57. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
  58. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  59. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  60. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +43 -4
  61. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +23 -9
  62. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +15 -0
  63. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +74 -0
  64. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +34 -1
  65. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +257 -4
  66. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +72 -92
  67. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +2 -2
  68. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +164 -65
  69. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +100 -0
  70. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +99 -0
  71. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +415 -253
  72. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +113 -32
  73. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +16 -17
  74. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +284 -0
  75. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +52 -19
  76. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +402 -0
  77. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +100 -12
  78. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +153 -101
  79. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +36 -0
  80. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +121 -33
  81. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +27 -17
  82. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +91 -0
  83. package/templates/apps/web/app/[locale]/layout.tsx +42 -76
  84. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  85. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  86. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  87. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +189 -6
  88. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +101 -31
  89. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  90. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  91. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  92. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  93. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  94. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  95. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  96. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
  97. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  98. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  99. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  100. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  101. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  102. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  103. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  104. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +122 -0
  105. package/templates/apps/web/app/llms.txt/route.ts +14 -2
  106. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +98 -0
  107. package/templates/apps/web/app/sitemap.xml/route.ts +13 -2
  108. package/templates/apps/web/auth.ts +133 -6
  109. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  110. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  111. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  112. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  113. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  114. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  115. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  116. package/templates/apps/web/lib/account-config.ts +24 -9
  117. package/templates/apps/web/lib/auth-email.ts +62 -6
  118. package/templates/apps/web/lib/auth-env.ts +13 -0
  119. package/templates/apps/web/lib/auth-sms.ts +180 -0
  120. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  121. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  122. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  123. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  124. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  125. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  126. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  127. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  128. package/templates/apps/web/lib/site-header.ts +14 -1
  129. package/templates/apps/web/lib/site-listing.ts +7 -0
  130. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  131. package/templates/apps/web/lib/topology.generated.ts +39 -0
  132. package/templates/apps/web/messages/en.json +125 -21
  133. package/templates/apps/web/middleware.ts +34 -2
  134. package/templates/apps/web/security-headers.config.ts +21 -0
  135. package/versions.json +47 -47
  136. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  137. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  138. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  139. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -11,6 +11,11 @@
11
11
  * contact email on both pages, both `noindex`, and nothing throws; a
12
12
  * 404 is `notFound()`; one slug's read is shared for 15 seconds, and a
13
13
  * slug the schema refuses is never read.
14
+ *
15
+ * #11013 spec E (AC-1, AC-2) — the walk passes the frame's brand header and
16
+ * Esc exit in place of the back arrow; a multi-step magnet's landing is the
17
+ * takeover title page (`FlowFrame`, no bar, no header title) with its
18
+ * JSON-LD and metadata unchanged, while a one-step flow keeps today's hero.
14
19
  */
15
20
  import { render, screen } from "@testing-library/react";
16
21
  import type { FlowConfig } from "@working-theory/validation";
@@ -36,9 +41,34 @@ jest.mock("next/navigation", () => ({
36
41
 
37
42
  jest.mock("next-intl/server", () => ({
38
43
  __esModule: true,
39
- getTranslations: async () => (key: string) => key,
44
+ // Echoes the values, so an interpolated message (the Time line) is observable.
45
+ getTranslations: async () => (key: string, values?: Record<string, unknown>) =>
46
+ values === undefined
47
+ ? key
48
+ : `${key}:${Object.entries(values)
49
+ .map(([k, v]) => `${k}=${String(v)}`)
50
+ .join(",")}`,
40
51
  }));
41
52
 
53
+ // #11013 — the title page's frame, captured by props; its children render so
54
+ // the heading, the line, the button and the Time line are readable.
55
+ const mockFrame = jest.fn();
56
+ jest.mock("@working-theory/ui", () => {
57
+ const actual = jest.requireActual("@working-theory/ui");
58
+ const react = require("react");
59
+ return {
60
+ ...actual,
61
+ FlowFrame: (props: Record<string, unknown>) => {
62
+ mockFrame(props);
63
+ return react.createElement(
64
+ "div",
65
+ { "data-testid": "flow-frame", "data-takeover": String(props["takeover"] ?? false), "data-bar-mode": props["barMode"] },
66
+ props["children"] as ReactElement,
67
+ );
68
+ },
69
+ };
70
+ });
71
+
42
72
  // The hero section's data, drawn as plain landmarks the assertions read.
43
73
  jest.mock("@working-theory/ui/sections", () => {
44
74
  const react = require("react");
@@ -92,6 +122,7 @@ import {
92
122
  magnetStartMetadata,
93
123
  readMagnet,
94
124
  renderMagnetLanding,
125
+ renderMagnetLandingMetadata,
95
126
  renderMagnetStart,
96
127
  renderMagnetStartMetadata,
97
128
  } from "../magnet-page";
@@ -123,6 +154,25 @@ function config(withLanding = true): FlowConfig {
123
154
  } as FlowConfig;
124
155
  }
125
156
 
157
+ /** #11013 — a three-step flow (two questions and a message step), the takeover title page. */
158
+ function multiStep(withLanding = true, extraSteps: FlowConfig["steps"] = []): FlowConfig {
159
+ const base = config(withLanding);
160
+ return {
161
+ ...base,
162
+ steps: [
163
+ ...base.steps,
164
+ {
165
+ key: "q1",
166
+ type: "segmentation",
167
+ copy: { title: en("How often do you ship?") },
168
+ questions: [{ name: "cadence", options: [{ value: "weekly", label: en("Weekly") }] }],
169
+ },
170
+ { key: "note", type: "message", copy: { title: en("Nearly there") } },
171
+ ...extraSteps,
172
+ ],
173
+ } as FlowConfig;
174
+ }
175
+
126
176
  // One slug's read is shared for 15 seconds; each test starts an hour later.
127
177
  let clock = 1_800_000_000_000;
128
178
  jest.spyOn(Date, "now").mockImplementation(() => clock);
@@ -131,6 +181,7 @@ beforeEach(() => {
131
181
  clock += 60 * 60 * 1000;
132
182
  mockGet.mockReset();
133
183
  mockStepper.mockReset();
184
+ mockFrame.mockReset();
134
185
  mockGet.mockResolvedValue({ ok: true, body: config() });
135
186
  });
136
187
 
@@ -180,12 +231,13 @@ describe("the landing (#8840 D8, AC-4)", () => {
180
231
  });
181
232
 
182
233
  describe("the walk (#8840 D8, AC-4)", () => {
183
- it("renders a NavBackLink to the landing and the stepper on step 1", async () => {
234
+ it("renders the stepper on step 1 with the frame's exit to the landing, and no back arrow (#11013)", async () => {
184
235
  render(await renderMagnetStart({ slug: "growth", locale: "en", backHref: "/diagnostic" }));
185
- expect(screen.getByTestId("nav-back-link").getAttribute("href")).toBe("/diagnostic");
236
+ expect(screen.queryByTestId("nav-back-link")).toBeNull();
186
237
  expect(screen.getByTestId("stepper").textContent).toContain("Who are you?");
187
238
  const props = mockStepper.mock.calls[0]![0] as Record<string, unknown>;
188
239
  expect(props["slug"]).toBe("growth");
240
+ expect(props["exit"]).toEqual({ href: "/en/diagnostic", label: "exitLabel" });
189
241
  expect(props).not.toHaveProperty("hiddenValues");
190
242
  });
191
243
 
@@ -210,6 +262,159 @@ describe("the walk (#8840 D8, AC-4)", () => {
210
262
  });
211
263
  });
212
264
 
265
+ describe("the walk carries the frame's brand header and Esc, not the back arrow (#11013 AC-1)", () => {
266
+ function stepperProps(): Record<string, unknown> {
267
+ expect(mockStepper).toHaveBeenCalledTimes(1);
268
+ return mockStepper.mock.calls[0]![0] as Record<string, unknown>;
269
+ }
270
+
271
+ it("passes brand (logomark, wordmark, the landing title), exit to the back path and no header", async () => {
272
+ render(await renderMagnetStart({ slug: "growth", locale: "en", backHref: "/flows/x" }));
273
+ const props = stepperProps();
274
+ const brand = props["brand"] as { logomark?: unknown; wordmark?: unknown; title?: string };
275
+ expect(brand.logomark).toBeDefined();
276
+ expect(brand.wordmark).toBeDefined();
277
+ expect(brand.title).toBe("How ready is your team?");
278
+ expect(props["exit"]).toEqual({ href: "/en/flows/x", label: "exitLabel" });
279
+ expect(props).not.toHaveProperty("header");
280
+ expect(props).not.toHaveProperty("presentation");
281
+ expect(screen.queryByTestId("nav-back-link")).toBeNull();
282
+ });
283
+
284
+ it("a careers walk's Esc leaves for its posting, never the landing", async () => {
285
+ mockGet.mockResolvedValue({ ok: true, body: { ...config(), slug: "eng-application" } });
286
+ render(
287
+ await renderMagnetStart({
288
+ slug: "eng-application",
289
+ locale: "en",
290
+ backHref: "/careers/eng/apply",
291
+ hiddenValues: { job: "eng" },
292
+ firstStepTitle: "Engineer",
293
+ }),
294
+ );
295
+ expect(stepperProps()["exit"]).toEqual({ href: "/en/careers/eng/apply", label: "exitLabel" });
296
+ });
297
+
298
+ it("the title falls back to step 1's title with no landing block; a locale that is not enabled exits on the default locale", async () => {
299
+ // The exit is built through the same enabled-locale allowlist every path
300
+ // the walk pushes passes (#4707); the test env enables `en` alone.
301
+ mockGet.mockResolvedValue({ ok: true, body: config(false) });
302
+ render(await renderMagnetStart({ slug: "growth", locale: "fr", backHref: "/flows/x" }));
303
+ const props = stepperProps();
304
+ expect((props["brand"] as { title?: string }).title).toBe("Who are you?");
305
+ expect(props["exit"]).toEqual({ href: "/en/flows/x", label: "exitLabel" });
306
+ });
307
+
308
+ it("forwards presentation when the page passes one", async () => {
309
+ render(await renderMagnetStart({ slug: "growth", locale: "en", backHref: "/flows/x", presentation: "full" }));
310
+ expect(stepperProps()["presentation"]).toBe("full");
311
+ });
312
+
313
+ it("the unavailable path still renders NavBackLink above the contact email", async () => {
314
+ process.env.AILK_API_URL = "https://hub.example";
315
+ try {
316
+ mockGet.mockResolvedValue({ ok: false, status: 503, body: null });
317
+ render(await renderMagnetStart({ slug: "growth", locale: "en", backHref: "/flows/x" }));
318
+ } finally {
319
+ delete process.env.AILK_API_URL;
320
+ }
321
+ const back = screen.getByTestId("nav-back-link");
322
+ const fallback = screen.getByTestId("contact-fallback");
323
+ expect(back.getAttribute("href")).toBe("/flows/x");
324
+ expect(back.compareDocumentPosition(fallback) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
325
+ expect(mockStepper).not.toHaveBeenCalled();
326
+ });
327
+ });
328
+
329
+ describe("a multi-step magnet's title page is the takeover window (#11013 AC-2)", () => {
330
+ function frameProps(): Record<string, unknown> {
331
+ expect(mockFrame).toHaveBeenCalledTimes(1);
332
+ return mockFrame.mock.calls[0]![0] as Record<string, unknown>;
333
+ }
334
+
335
+ it("renders FlowFrame with takeover, no bar, a brand with no title and an exit to the site's home", async () => {
336
+ mockGet.mockResolvedValue({ ok: true, body: multiStep() });
337
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
338
+ const props = frameProps();
339
+ expect(props["takeover"]).toBe(true);
340
+ expect(props["barMode"]).toBe("none");
341
+ const brand = props["brand"] as { logomark?: unknown; wordmark?: unknown; title?: string };
342
+ expect(brand.logomark).toBeDefined();
343
+ expect(brand.wordmark).toBeDefined();
344
+ expect(brand).not.toHaveProperty("title");
345
+ expect(props["exit"]).toEqual({ href: "/en", label: "exitLabel" });
346
+ expect(screen.queryByTestId("hero-cta")).toBeNull();
347
+ });
348
+
349
+ it("inside it: one h1, the description, the button to the start path, then the Time line", async () => {
350
+ mockGet.mockResolvedValue({ ok: true, body: multiStep() });
351
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
352
+ const headings = screen.getAllByRole("heading", { level: 1 });
353
+ expect(headings).toHaveLength(1);
354
+ expect(headings[0]!.textContent).toBe("How ready is your team?");
355
+ expect(screen.getByTestId("flow-title-description").textContent).toBe("Ten questions, one page of results.");
356
+ const cta = screen.getByTestId("flow-title-cta");
357
+ expect(cta.getAttribute("href")).toBe("/diagnostic/start");
358
+ expect(cta.textContent).toBe("Start the diagnostic");
359
+ const time = screen.getByTestId("flow-title-time");
360
+ expect(cta.compareDocumentPosition(time) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
361
+ expect(screen.getByTestId("flow-frame")).toContainElement(time);
362
+ });
363
+
364
+ it("the Time line is landing.meta when set", async () => {
365
+ mockGet.mockResolvedValue({ ok: true, body: multiStep() });
366
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
367
+ expect(screen.getByTestId("flow-title-time").textContent).toBe("About 3 minutes · Your result arrives by email");
368
+ });
369
+
370
+ it("without landing.meta the Time line counts the steps that are not message steps, ÷ 5", async () => {
371
+ const questions = Array.from({ length: 27 }, (_, i) => ({
372
+ key: `q${i + 2}`,
373
+ type: "segmentation",
374
+ copy: { title: en(`Q${i + 2}`) },
375
+ questions: [{ name: `a${i}`, options: [{ value: "x", label: en("X") }] }],
376
+ })) as FlowConfig["steps"];
377
+ // 2 + 27 = 29 counted steps, plus one message step that is not counted.
378
+ mockGet.mockResolvedValue({ ok: true, body: multiStep(false, questions) });
379
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
380
+ expect(screen.getByTestId("flow-title-time").textContent).toBe("landingTime:minutes=6");
381
+ });
382
+
383
+ it("a short flow reads at least one minute", async () => {
384
+ mockGet.mockResolvedValue({ ok: true, body: multiStep(false) });
385
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
386
+ expect(screen.getByTestId("flow-title-time").textContent).toBe("landingTime:minutes=1");
387
+ });
388
+
389
+ it("keeps the WebApplication JSON-LD and the metadata as before, and stays indexable", async () => {
390
+ mockGet.mockResolvedValue({ ok: true, body: multiStep() });
391
+ const { container } = render(
392
+ await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }),
393
+ );
394
+ const script = container.querySelector('script[type="application/ld+json"]');
395
+ const jsonLd = JSON.parse(script!.textContent!) as { "@type": string; name: string; description: string };
396
+ expect(jsonLd["@type"]).toBe("WebApplication");
397
+ expect(jsonLd.name).toBe("How ready is your team?");
398
+ expect(jsonLd.description).toBe("Ten questions, one page of results.");
399
+ const metadata = await renderMagnetLandingMetadata({ slug: "growth", locale: "en" });
400
+ expect(metadata).toEqual({ title: "How ready is your team?", description: "Ten questions, one page of results." });
401
+ });
402
+
403
+ it("localizes the start path as the hero did; a locale that is not enabled exits on the default locale", async () => {
404
+ mockGet.mockResolvedValue({ ok: true, body: multiStep() });
405
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "fr" }));
406
+ expect(screen.getByTestId("flow-title-cta").getAttribute("href")).toBe("/fr/diagnostic/start");
407
+ expect(frameProps()["exit"]).toEqual({ href: "/en", label: "exitLabel" });
408
+ });
409
+
410
+ it("a one-step flow's landing renders today's hero section with no FlowFrame", async () => {
411
+ render(await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }));
412
+ expect(mockFrame).not.toHaveBeenCalled();
413
+ expect(screen.getByTestId("hero-cta").getAttribute("href")).toBe("/diagnostic/start");
414
+ expect(screen.queryByTestId("flow-title-page")).toBeNull();
415
+ });
416
+ });
417
+
213
418
  describe("an unreachable hub shows the contact email (#8840 D8, AC-5)", () => {
214
419
  // #9219 — a configured hub, so a rejected read or a plain 503 is an outage
215
420
  // (`unavailable`), not a site with no hub to ask.
@@ -264,6 +469,53 @@ describe("an unreachable hub shows the contact email (#8840 D8, AC-5)", () => {
264
469
  renderMagnetStart({ slug: "growth", locale: "en", backHref: "/diagnostic" }),
265
470
  ).rejects.toThrow("NEXT_NOT_FOUND");
266
471
  });
472
+
473
+ // #10990 AC-3 — a blocked hub's answers that are not a served flow, and
474
+ // refusals that are not a 404, are an outage: the contact email, never the
475
+ // hero, a throw or notFound().
476
+ it.each([
477
+ ["a 2xx with a null body", { ok: true, body: null }],
478
+ ["a 2xx with no body", { ok: true, body: undefined }],
479
+ ["a 2xx with {}", { ok: true, body: {} }],
480
+ ["a 2xx with no steps", { ok: true, body: { slug: "growth", steps: [] } }],
481
+ ["a 2xx with no slug", { ok: true, body: { steps: config().steps } }],
482
+ ["a 403", { ok: false, status: 403, body: null }],
483
+ ["a 429", { ok: false, status: 429, body: null }],
484
+ ])("%s: both pages render ContactFallback, no notFound(), noindex (#10990)", async (_label, answer) => {
485
+ mockGet.mockResolvedValue(answer);
486
+ const landing = render(
487
+ await renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }),
488
+ );
489
+ expect(screen.getByTestId("contact-fallback").textContent).toContain("hello@example.com");
490
+ landing.unmount();
491
+
492
+ render(await renderMagnetStart({ slug: "growth", locale: "en", backHref: "/diagnostic" }));
493
+ expect(screen.getByTestId("contact-fallback").textContent).toContain("hello@example.com");
494
+ expect(mockStepper).not.toHaveBeenCalled();
495
+
496
+ expect((await magnetLandingMetadata(REF)({ params })).robots).toEqual({ index: false, follow: true });
497
+ });
498
+
499
+ it("a read that never answers gives the contact email after 5 seconds, not before (#10990)", async () => {
500
+ jest.useFakeTimers({ doNotFake: ["Date"] });
501
+ try {
502
+ mockGet.mockReturnValue(new Promise(() => undefined));
503
+ let settled = false;
504
+ const rendering = renderMagnetLanding({ slug: "growth", path: "/diagnostic", locale: "en" }).then(
505
+ (element) => {
506
+ settled = true;
507
+ return element;
508
+ },
509
+ );
510
+ await jest.advanceTimersByTimeAsync(4_999);
511
+ expect(settled).toBe(false);
512
+ await jest.advanceTimersByTimeAsync(1);
513
+ render(await rendering);
514
+ expect(screen.getByTestId("contact-fallback").textContent).toContain("hello@example.com");
515
+ } finally {
516
+ jest.useRealTimers();
517
+ }
518
+ });
267
519
  });
268
520
 
269
521
  describe("a walk that exists apart from its flow passes a title (#9219)", () => {
@@ -439,7 +691,8 @@ describe("a deliverable flow leaves the pair for /reports (#8848 D7, AC-4)", ()
439
691
  it("renderMagnetStart with asDeliverable renders the walk", async () => {
440
692
  render(await renderMagnetStart({ slug: "q3", locale: "en", backHref: "/reports/q3", asDeliverable: true }));
441
693
  expect(mockRedirect).not.toHaveBeenCalled();
442
- expect(screen.getByTestId("nav-back-link").getAttribute("href")).toBe("/reports/q3");
694
+ const props = mockStepper.mock.calls[0]![0] as Record<string, unknown>;
695
+ expect(props["exit"]).toEqual({ href: "/en/reports/q3", label: "exitLabel" });
443
696
  expect(screen.getByTestId("stepper")).toBeTruthy();
444
697
  });
445
698
 
@@ -1,18 +1,21 @@
1
1
  /**
2
- * Tests for "Email me this plan" — `saveRecommendationAction` (#4842 D7),
3
- * split out of `checkout.actions.ts` with its cases by #6786 so the save half
4
- * ships with the results page while checkout stays commerce's.
2
+ * Tests for Get your full report — `sendResultsEmailAction` (#11013 spec E,
3
+ * D-F), the results page's email moment, which replaced "Email me this plan"
4
+ * (`saveRecommendationAction`, #4842 D7 / #6786).
5
5
  *
6
- * AC-4 (the action half) — calls `flows.save` once with
7
- * `{ answers, email, locale }` and returns the lead id.
8
- * D7 — the shared status → kind map (`email-moment.ts`), never a throw;
9
- * an invalid body → `invalid_input` without calling the api-client.
6
+ * AC-4 (the action half) — refuses a bad slug or body as `invalid_input`
7
+ * without a call; `unavailable` on a refused bot check; on success calls
8
+ * `flows.resultsEmail` once with the body and the visitor's IP init and
9
+ * answers `{ ok: true }` — never an id. No `saveRecommendationAction`
10
+ * export remains.
11
+ * D7 — the shared status → kind map (`email-moment.ts`), never a throw.
10
12
  *
11
13
  * Mock shape: `checkout.actions.test.ts`'s (`@working-theory/api-client` +
12
14
  * `next/headers`).
13
15
  */
14
16
 
15
- import { saveRecommendationAction } from "../save.actions.js";
17
+ import * as actions from "../save.actions.js";
18
+ import { sendResultsEmailAction } from "../save.actions.js";
16
19
 
17
20
  // #9255 — the write bot check's verdict. `checkBotId` reads Vercel's
18
21
  // request context, which jest has none of, so every case decides it here.
@@ -23,6 +26,7 @@ jest.mock("botid/server", () => ({
23
26
 
24
27
  jest.mock("@working-theory/api-client", () => ({
25
28
  flows: {
29
+ resultsEmail: jest.fn(),
26
30
  save: jest.fn(),
27
31
  },
28
32
  }));
@@ -35,12 +39,13 @@ jest.mock("next/headers", () => ({
35
39
  import { flows } from "@working-theory/api-client";
36
40
  import { headers } from "next/headers";
37
41
 
42
+ const mockResultsEmail = flows.resultsEmail as jest.Mock;
38
43
  const mockSave = flows.save as jest.Mock;
39
44
  const mockHeaders = headers as jest.Mock;
40
45
 
41
46
  const SLUG = "ailk-recommender";
42
47
  const ANSWERS = { team_size: "agency", wants_seo: "yes" };
43
- const SAVE_BODY = { answers: ANSWERS, email: "jane@example.com", locale: "en" };
48
+ const BODY = { answers: ANSWERS, email: "jane@example.com", locale: "en" };
44
49
 
45
50
  beforeEach(() => {
46
51
  jest.spyOn(console, "error").mockImplementation(() => undefined);
@@ -52,77 +57,71 @@ afterEach(() => {
52
57
  mockHeaders.mockResolvedValue({ get: () => null });
53
58
  });
54
59
 
55
- describe("saveRecommendationAction — AC-4 (the action half)", () => {
56
- it("calls flows.save once with { answers, email, locale } and returns the leadId", async () => {
57
- mockSave.mockResolvedValueOnce({
58
- ok: true,
59
- body: { leadId: "lead_1", sessionId: "fs_1" },
60
- });
61
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
62
- ok: true,
63
- leadId: "lead_1",
64
- });
65
- expect(mockSave).toHaveBeenCalledTimes(1);
66
- expect(mockSave).toHaveBeenCalledWith(SLUG, SAVE_BODY);
60
+ describe("sendResultsEmailAction — AC-4 (the action half)", () => {
61
+ it("calls flows.resultsEmail once with the body and answers { ok: true } with no id", async () => {
62
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
63
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: true });
64
+ expect(mockResultsEmail).toHaveBeenCalledTimes(1);
65
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, BODY);
66
+ expect(mockSave).not.toHaveBeenCalled();
67
67
  });
68
68
 
69
- it("maps failures exactly as checkout does and never throws", async () => {
70
- mockSave.mockResolvedValueOnce({
71
- ok: false,
72
- status: 429,
73
- body: { retryAfterSeconds: 9 },
74
- });
75
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
69
+ it("forwards the stored session id when the body carries one", async () => {
70
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
71
+ await sendResultsEmailAction(SLUG, { ...BODY, sessionId: "fs_1" });
72
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, { ...BODY, sessionId: "fs_1" });
73
+ });
74
+
75
+ it("maps failures through the shared status → kind map and never throws", async () => {
76
+ mockResultsEmail.mockResolvedValueOnce({ ok: false, status: 429, body: { retryAfterSeconds: 9 } });
77
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({
76
78
  ok: false,
77
79
  kind: "rate_limited",
78
80
  retryAfterSeconds: 9,
79
81
  });
80
- mockSave.mockRejectedValueOnce(new Error("boom"));
81
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
82
+ mockResultsEmail.mockResolvedValueOnce({ ok: false, status: 409, body: null });
83
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: false, kind: "not_configured" });
84
+ mockResultsEmail.mockRejectedValueOnce(new Error("boom"));
85
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: false, kind: "network" });
86
+ expect(mockResultsEmail).toHaveBeenCalledTimes(3);
87
+ });
88
+
89
+ it.each([
90
+ ["a bad email", SLUG, { ...BODY, email: "nope" }],
91
+ ["an unknown body key", SLUG, { ...BODY, consents: { marketing: true } }],
92
+ ["a bad slug", "Not A Slug", BODY],
93
+ ])("%s is invalid_input with no call", async (_label, slug, body) => {
94
+ await expect(sendResultsEmailAction(slug, body as typeof BODY)).resolves.toEqual({
82
95
  ok: false,
83
- kind: "network",
96
+ kind: "invalid_input",
84
97
  });
85
- await expect(
86
- saveRecommendationAction(SLUG, { ...SAVE_BODY, email: "nope" }),
87
- ).resolves.toEqual({ ok: false, kind: "invalid_input" });
88
- expect(mockSave).toHaveBeenCalledTimes(2);
98
+ expect(mockResultsEmail).not.toHaveBeenCalled();
99
+ expect(checkBotIdMock).not.toHaveBeenCalled();
89
100
  });
90
101
 
91
102
  it("forwards the visitor's x-forwarded-for on the outbound call (#4730)", async () => {
92
103
  mockHeaders.mockResolvedValueOnce({
93
- get: (name: string) =>
94
- name === "x-forwarded-for" ? "203.0.113.7" : null,
104
+ get: (name: string) => (name === "x-forwarded-for" ? "203.0.113.7" : null),
95
105
  });
96
- mockSave.mockResolvedValueOnce({
97
- ok: true,
98
- body: { leadId: "lead_1", sessionId: "fs_1" },
99
- });
100
- await saveRecommendationAction(SLUG, SAVE_BODY);
101
- expect(mockSave).toHaveBeenCalledWith(SLUG, SAVE_BODY, {
106
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
107
+ await sendResultsEmailAction(SLUG, BODY);
108
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, BODY, {
102
109
  headers: { "x-forwarded-for": "203.0.113.7" },
103
110
  });
104
111
  });
112
+
113
+ it("no saveRecommendationAction export remains", () => {
114
+ expect(Object.keys(actions)).not.toContain("saveRecommendationAction");
115
+ });
105
116
  });
106
117
 
107
118
  // #9255 D4 — the write bot check runs after the slug and body checks,
108
- // immediately before the write (spec
109
- // docs/specs/9255-an-edge-bot-challenge-in-spec.md §5.1 AC-2).
110
- describe("saveRecommendationAction — the write bot check (#9255)", () => {
111
- const BOT = {
112
- isHuman: false,
113
- isBot: true,
114
- isVerifiedBot: false,
115
- bypassed: false,
116
- };
119
+ // immediately before the write.
120
+ describe("sendResultsEmailAction — the write bot check (#9255)", () => {
121
+ const BOT = { isHuman: false, isBot: true, isVerifiedBot: false, bypassed: false };
117
122
  const HUMAN = { ...BOT, isHuman: true, isBot: false };
118
- const BOT_ENV_KEYS = [
119
- "VERCEL",
120
- "AILK_BOT_CHECK",
121
- "AILK_BOOKING_BOT_CHECK",
122
- ] as const;
123
- const priorBotEnv = new Map(
124
- BOT_ENV_KEYS.map((name) => [name, process.env[name]]),
125
- );
123
+ const BOT_ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK", "AILK_BOOKING_BOT_CHECK"] as const;
124
+ const priorBotEnv = new Map(BOT_ENV_KEYS.map((name) => [name, process.env[name]]));
126
125
 
127
126
  let botLogSpies: jest.SpyInstance[] = [];
128
127
 
@@ -146,48 +145,29 @@ describe("saveRecommendationAction — the write bot check (#9255)", () => {
146
145
 
147
146
  it.each([
148
147
  ["a bot", () => checkBotIdMock.mockResolvedValue(BOT)],
149
- [
150
- "a check that fails",
151
- () => checkBotIdMock.mockRejectedValue(new Error("boom")),
152
- ],
153
- ])(
154
- "%s gets kind unavailable, and nothing is sent",
155
- async (_label, decide) => {
156
- decide();
157
- expect(await saveRecommendationAction(SLUG, SAVE_BODY)).toStrictEqual({
158
- ok: false,
159
- kind: "unavailable",
160
- });
161
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
162
- expect(mockSave).not.toHaveBeenCalled();
163
- },
164
- );
148
+ ["a check that fails", () => checkBotIdMock.mockRejectedValue(new Error("boom"))],
149
+ ])("%s gets kind unavailable, and nothing is sent", async (_label, decide) => {
150
+ decide();
151
+ expect(await sendResultsEmailAction(SLUG, BODY)).toStrictEqual({ ok: false, kind: "unavailable" });
152
+ expect(checkBotIdMock).toHaveBeenCalledTimes(1);
153
+ expect(mockResultsEmail).not.toHaveBeenCalled();
154
+ });
165
155
 
166
156
  it("a human sends exactly what the check off sends", async () => {
167
157
  checkBotIdMock.mockResolvedValue(HUMAN);
168
- mockSave.mockResolvedValue({
169
- ok: true,
170
- status: 201,
171
- body: { leadId: "lead_1" },
172
- });
158
+ mockResultsEmail.mockResolvedValue({ ok: true, status: 200, body: { sent: true } });
173
159
  delete process.env.VERCEL;
174
- await saveRecommendationAction(SLUG, SAVE_BODY);
160
+ await sendResultsEmailAction(SLUG, BODY);
175
161
  process.env.VERCEL = "1";
176
- expect(await saveRecommendationAction(SLUG, SAVE_BODY)).toEqual({
177
- ok: true,
178
- leadId: "lead_1",
179
- });
162
+ expect(await sendResultsEmailAction(SLUG, BODY)).toEqual({ ok: true });
180
163
  expect(checkBotIdMock).toHaveBeenCalledTimes(1);
181
- expect(mockSave).toHaveBeenCalledTimes(2);
182
- expect(mockSave.mock.calls[1]).toEqual(mockSave.mock.calls[0]);
164
+ expect(mockResultsEmail).toHaveBeenCalledTimes(2);
165
+ expect(mockResultsEmail.mock.calls[1]).toEqual(mockResultsEmail.mock.calls[0]);
183
166
  });
184
167
 
185
168
  it("an invalid slug answers invalid_input with no check", async () => {
186
169
  checkBotIdMock.mockResolvedValue(BOT);
187
- expect(await saveRecommendationAction("Not A Slug", SAVE_BODY)).toEqual({
188
- ok: false,
189
- kind: "invalid_input",
190
- });
170
+ expect(await sendResultsEmailAction("Not A Slug", BODY)).toEqual({ ok: false, kind: "invalid_input" });
191
171
  expect(checkBotIdMock).not.toHaveBeenCalled();
192
172
  });
193
173
  });
@@ -1,8 +1,8 @@
1
1
  // oss: false
2
2
  /**
3
3
  * email-moment.ts — the helpers the recommender's two email-moment Server
4
- * Actions share (#4842 D7): `saveRecommendationAction` (`save.actions.ts`,
5
- * shipped with the results page) and `startCheckoutAction`
4
+ * Actions share (#4842 D7): `sendResultsEmailAction` (`save.actions.ts`,
5
+ * shipped with the results page; #11013 D-F) and `startCheckoutAction`
6
6
  * (`checkout.actions.ts`, commerce's). Split out of `checkout.actions.ts` by
7
7
  * #6786 so the save half ships without the checkout half; a `"use server"`
8
8
  * file may export only async functions, so the shared sync helpers live here.