create-ailk 0.34.1 → 0.35.1

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 (54) hide show
  1. package/component-catalog.json +25 -3
  2. package/component-catalog.md +9 -8
  3. package/dist/add-module.js +7 -2
  4. package/dist/derive-architecture.js +2 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/module-architecture.js +9 -0
  8. package/dist/programmatic.js +5 -2
  9. package/dist/site-listing-path.d.ts +8 -0
  10. package/dist/site-listing-path.js +8 -0
  11. package/dist/surfaces.d.ts +20 -0
  12. package/dist/surfaces.js +26 -0
  13. package/dist/template-record.js +2 -0
  14. package/dist/update.js +11 -0
  15. package/package.json +3 -3
  16. package/templates/apps/api/CLAUDE.md +6 -6
  17. package/templates/apps/mcp/CLAUDE.md +16 -7
  18. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
  19. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
  20. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
  21. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +43 -4
  22. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +23 -9
  23. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +15 -0
  24. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +74 -0
  25. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +34 -1
  26. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +257 -4
  27. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +72 -92
  28. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +2 -2
  29. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +164 -65
  30. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +100 -0
  31. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +99 -0
  32. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +415 -253
  33. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +113 -32
  34. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +16 -17
  35. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +284 -0
  36. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +52 -19
  37. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +402 -0
  38. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +100 -12
  39. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +153 -101
  40. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +36 -0
  41. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +121 -33
  42. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +27 -17
  43. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +91 -0
  44. package/templates/apps/web/app/[locale]/layout.tsx +18 -1
  45. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +24 -0
  46. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +5 -1
  47. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +122 -0
  48. package/templates/apps/web/app/llms.txt/route.ts +14 -2
  49. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +98 -0
  50. package/templates/apps/web/app/sitemap.xml/route.ts +13 -2
  51. package/templates/apps/web/lib/account-config.ts +24 -9
  52. package/templates/apps/web/lib/site-listing.ts +7 -0
  53. package/templates/apps/web/messages/en.json +13 -1
  54. package/versions.json +47 -47
@@ -57,7 +57,20 @@
57
57
  * platform default with the locale's `/terms` and `/privacy` links
58
58
  * (`consentPoliciesFor`, the map every agreement surface uses); a `message`
59
59
  * step is shown but not counted in "Step N of M"; `hiddenValues` and `header`
60
- * pass through from the page. When the config carries an `ending`, it is the
60
+ * pass through from the page, as do the frame's `brand`, `exit` and
61
+ * `presentation` (#11013 D-A — the page builds the brand on the server and
62
+ * hands it down; the walk's Esc leaves for where it was entered from).
63
+ *
64
+ * The results page's reach (#11013 D-J): a recommending flow with no
65
+ * `ending` has a results page (`hasResultsPage`, spec C), whether or not it
66
+ * carries `offers`. `isRecommending` keeps its `offers` condition — its three
67
+ * readers are kept as they were, so a recommending `user` magnet still lands
68
+ * on sign-up at once (`goToSignUp`) — and a separate predicate,
69
+ * `showsResultsPage`, drives only the results push: a walk changes landing
70
+ * only when it is recommending with no ending, no `offers`, no sign-up
71
+ * hand-off and no deliverable (`deliveredRef`), and then pushes the results
72
+ * permalink instead of ending in the stepper's completed state. Every other
73
+ * walk lands where it landed before. When the config carries an `ending`, it is the
61
74
  * one ending: `onCompleted` is not passed (so neither `thankYou` nor a
62
75
  * recommending flow's permalink runs), and on the completing response the
63
76
  * client picks the outcome from the answers it accumulated
@@ -87,6 +100,7 @@
87
100
  * bundle, the same reasoning `middleware.ts` already documents for the
88
101
  * Edge runtime) before it ever reaches the template literal.
89
102
  */
103
+ import type { FlowFrameBrand, FlowFrameExit, FlowFramePresentation } from "@working-theory/ui";
90
104
  import { Button, Heading, Link, localeHref, Text } from "@working-theory/ui";
91
105
  import { VideoEmbed } from "@working-theory/ui/blocks";
92
106
  import {
@@ -112,6 +126,7 @@ import {
112
126
  flowSitePathSchema,
113
127
  flowStepDeliverableSchema,
114
128
  flowStepNextSchema,
129
+ hasResultsPage,
115
130
  hiddenAnswers,
116
131
  PERMALINK_VERSION,
117
132
  pruneHiddenState,
@@ -139,8 +154,14 @@ interface Props {
139
154
  slug: string;
140
155
  /** #8840 D9 — page-supplied `hidden` field values (a posting's slug). */
141
156
  hiddenValues?: Readonly<Record<string, string>>;
142
- /** #8840 D9 — the walk's back arrow, above the step. */
157
+ /** #8840 D9 — the walk's back arrow, above the step. Not rendered beside `brand` / `exit`. */
143
158
  header?: ReactNode;
159
+ /** #11013 D-A — the frame's brand header (logomark, wordmark, the landing title). */
160
+ brand?: FlowFrameBrand;
161
+ /** #11013 D-A — the one `Esc ×` exit, to where the walk was entered from. */
162
+ exit?: FlowFrameExit;
163
+ /** #11013 decision 2 — a bounded window at `md:`+ (the default) or edge to edge. */
164
+ presentation?: FlowFramePresentation;
144
165
  }
145
166
 
146
167
  const DEFAULT_LOCALE = "en";
@@ -216,6 +237,9 @@ export function FlowStepperClient({
216
237
  slug,
217
238
  hiddenValues,
218
239
  header,
240
+ brand,
241
+ exit,
242
+ presentation,
219
243
  }: Props): ReactElement {
220
244
  const t = useTranslations("flow");
221
245
  const router = useRouter();
@@ -225,6 +249,10 @@ export function FlowStepperClient({
225
249
  // client never routes to.
226
250
  const isRecommending =
227
251
  config.mode === "recommending" && config.offers !== undefined;
252
+ // #11013 D-J — spec C's predicate: the flow has a results page (recommending,
253
+ // no ending), offers or not. It drives only the results push below;
254
+ // `isRecommending`'s own readers are unchanged.
255
+ const showsResultsPage = hasResultsPage(config);
228
256
  // #10616 D4 — a flow whose scoring maps at least one tier to a thank-you
229
257
  // page: completion may redirect there, so `onCompleted` is passed.
230
258
  const hasTierThankYou =
@@ -244,6 +272,9 @@ export function FlowStepperClient({
244
272
  // has left for the sign-up landing, so no other ending races it.
245
273
  const emailRef = useRef<string | undefined>(undefined);
246
274
  const signingUpRef = useRef(false);
275
+ // #11013 D-J — set when the completing response (or the config) carried a
276
+ // deliverable: the walk keeps it and never leaves for the results page.
277
+ const deliveredRef = useRef(false);
247
278
  // #8840 D9 — a config with an `ending` ends on it, never on `thankYou` or
248
279
  // the permalink; the chosen screen is drawn in the finished card.
249
280
  const endingWins = config.ending !== undefined;
@@ -268,6 +299,7 @@ export function FlowStepperClient({
268
299
  // #8848 D8 — a deliverable (or a gated file's by-email line) is never
269
300
  // lost to a navigation.
270
301
  const hasDeliverable = raw !== undefined || config.deliverable !== undefined;
302
+ deliveredRef.current = hasDeliverable;
271
303
  if (!hasDeliverable && (await goToSignUp(result.response))) return result;
272
304
  const delivered = showDeliverable(raw);
273
305
  if (endingWins) showEnding(delivered);
@@ -440,7 +472,9 @@ export function FlowStepperClient({
440
472
  }
441
473
  }
442
474
 
443
- if (isRecommending) {
475
+ // #11013 D-J — the results push: a flow with `offers`, as before, or one
476
+ // whose results page is reached with no deliverable in hand.
477
+ if (isRecommending || (showsResultsPage && !deliveredRef.current)) {
444
478
  // D1 (hidden-step pruning) — apply the shipped visibility resolver to
445
479
  // the accumulated state before encoding, so an abandoned branch's
446
480
  // answers never reach the URL.
@@ -560,7 +594,8 @@ export function FlowStepperClient({
560
594
  locale={locale}
561
595
  messages={messages}
562
596
  onSubmitStep={handleSubmitStep}
563
- {...(!endingWins && (thankYou !== undefined || isRecommending || hasTierThankYou)
597
+ {...(!endingWins &&
598
+ (thankYou !== undefined || isRecommending || showsResultsPage || hasTierThankYou)
564
599
  ? { onCompleted: handleCompleted }
565
600
  : {})}
566
601
  // #8840 D9 — the locale's policy links, the input-step count, and the
@@ -569,6 +604,10 @@ export function FlowStepperClient({
569
604
  uncountedStepKeys={config.steps.filter((step) => step.type === "message").map((step) => step.key)}
570
605
  {...(hiddenValues !== undefined ? { hiddenValues } : {})}
571
606
  {...(header !== undefined ? { header } : {})}
607
+ // #11013 D-A — the frame's brand header, exit and presentation, unchanged.
608
+ {...(brand !== undefined ? { brand } : {})}
609
+ {...(exit !== undefined ? { exit } : {})}
610
+ {...(presentation !== undefined ? { presentation } : {})}
572
611
  {...(completedContent !== undefined ? { completedContent } : {})}
573
612
  />
574
613
  );
@@ -25,24 +25,26 @@ jest.mock("../flow.actions", () => ({ submitFlowStepAction: jest.fn() }));
25
25
  jest.mock("../account-invite.actions", () => ({ accountInviteLinkAction: jest.fn() }));
26
26
 
27
27
  interface StubProps {
28
- onSubmitStep: (payload: { stepKey: string; values: Record<string, unknown> }) => Promise<unknown>;
28
+ onSubmitStep: (payload: { stepKey: string; values: Record<string, unknown> }) => Promise<{
29
+ ok: boolean;
30
+ response?: { completed: boolean };
31
+ }>;
32
+ onCompleted?: (result: Record<string, never>) => void;
29
33
  completedContent?: ReactNode;
30
34
  }
31
35
 
32
36
  jest.mock("@working-theory/ui-signal-collectors", () => ({
33
37
  FlowStepper: (props: StubProps) => {
34
38
  const react = require("react");
39
+ // The real FlowStepper fires `onCompleted` after a completing submit.
40
+ async function handleSubmit(): Promise<void> {
41
+ const result = await props.onSubmitStep({ stepKey: "contact", values: { email: "ana@example.com" } });
42
+ if (result.ok && result.response?.completed) props.onCompleted?.({});
43
+ }
35
44
  return react.createElement(
36
45
  "div",
37
46
  { "data-testid": "mock-card" },
38
- react.createElement(
39
- "button",
40
- {
41
- "data-testid": "mock-submit",
42
- onClick: () => props.onSubmitStep({ stepKey: "contact", values: { email: "ana@example.com" } }),
43
- },
44
- "Submit",
45
- ),
47
+ react.createElement("button", { "data-testid": "mock-submit", onClick: handleSubmit }, "Submit"),
46
48
  props.completedContent,
47
49
  ) as ReactElement;
48
50
  },
@@ -189,6 +191,18 @@ describe("the ending delivers the deliverable (#8848 D8, AC-5)", () => {
189
191
  expect(document.querySelector("video")).toBeNull();
190
192
  });
191
193
 
194
+ // #11013 D-J (AC-3) — a recommending walk with no offers that shows a
195
+ // deliverable keeps it: the deliverable's action renders and no results
196
+ // permalink is pushed.
197
+ it("a recommending walk with no offers keeps its deliverable and pushes no permalink", async () => {
198
+ respondWith({ kind: "file", grantId: "dgrant_x" });
199
+ await walk(config({ mode: "recommending" }));
200
+
201
+ const action = await screen.findByTestId("flow-deliverable-action");
202
+ expect(action.getAttribute("href")).toBe("/reports/q3?g=dgrant_x");
203
+ expect(mockPush).not.toHaveBeenCalled();
204
+ });
205
+
192
206
  it("a config with no deliverable and no response key renders today's card", async () => {
193
207
  respondWith();
194
208
  await walk(config({ deliverable: undefined, deliverables: undefined }));
@@ -258,6 +258,21 @@ describe("a user magnet lands on sign-up (#10826 D6)", () => {
258
258
  expect(navigated()).toBe("");
259
259
  });
260
260
 
261
+ // #11013 D-J (AC-3) — the results page's reach never pre-empts the sign-up
262
+ // hand-off: a recommending `user` magnet with no offers and no ending still
263
+ // lands on sign-up at once, and no results permalink is pushed.
264
+ it("a recommending user magnet with no offers and no ending still lands on sign-up, with no permalink push", async () => {
265
+ mockSubmit.mockResolvedValue(ok({ next: { completion: "invite" } }));
266
+
267
+ await walk({ ...config({ tagged: true, thankYou: false }), mode: "recommending" } as FlowConfig);
268
+
269
+ await waitFor(() => expect(navigated()).toBe(HREF));
270
+ expect(mockLink).toHaveBeenCalledTimes(1);
271
+ expect(mockLink).toHaveBeenCalledWith(EMAIL);
272
+ expect(mockPush).not.toHaveBeenCalled();
273
+ expect(window.sessionStorage.getItem("ailk:flow-session:get-a-quote")).toBeNull();
274
+ });
275
+
261
276
  it("a completion with no next pushes /thanks with no email in the URL", async () => {
262
277
  mockSubmit.mockResolvedValue(ok({}));
263
278
 
@@ -444,3 +444,77 @@ describe("FlowStepperClient — session hand-off on completion (#4842 AC-6, writ
444
444
  expect(window.sessionStorage.getItem(STORAGE_KEY)).toBeNull();
445
445
  });
446
446
  });
447
+
448
+ // ─── #11013 spec E, D-J (AC-3) — a recommending flow with no offers now reaches
449
+ // the results page; a flow with offers pushes exactly as before ─────────────
450
+
451
+ describe("FlowStepperClient — the results push on a recommending flow with no offers (#11013 D-J, AC-3)", () => {
452
+ function noOffersConfig(extra: Record<string, unknown> = {}): FlowConfig {
453
+ const { offers: _offers, ...rest } = recommendingFlowConfig();
454
+ return { ...rest, ...extra } as FlowConfig;
455
+ }
456
+
457
+ it("no offers, no by-result rows, no ending: the completed walk pushes the results permalink", async () => {
458
+ mockSubmitFlowStepAction.mockResolvedValueOnce({
459
+ ok: true,
460
+ response: { sessionId: "sess-r", landed: "team", nextStepKey: null, completed: true },
461
+ });
462
+
463
+ render(<FlowStepperClient config={noOffersConfig()} locale="en" slug={SLUG} />);
464
+ expect(captured?.onCompleted).toBeDefined();
465
+
466
+ await captured!.onSubmitStep({
467
+ stepKey: "team",
468
+ values: { team_size: "solo", wants_seo: "yes" },
469
+ locale: "en",
470
+ });
471
+ captured!.onCompleted?.({});
472
+
473
+ const decoded = decodePermalink(pushedPayload());
474
+ expect(decoded.ok).toBe(true);
475
+ if (!decoded.ok) return;
476
+ expect(decoded.value.answers).toEqual({ team_size: "solo", wants_seo: "yes" });
477
+ expect(window.sessionStorage.getItem(`ailk:flow-session:${SLUG}`)).toBe("sess-r");
478
+ });
479
+
480
+ it("a flow that is not recommending is passed no onCompleted and pushes nothing", async () => {
481
+ mockSubmitFlowStepAction.mockResolvedValueOnce({
482
+ ok: true,
483
+ response: { sessionId: "sess-q", landed: "team", nextStepKey: null, completed: true },
484
+ });
485
+ const { mode: _mode, ...qualifying } = noOffersConfig();
486
+
487
+ render(<FlowStepperClient config={qualifying as FlowConfig} locale="en" slug={SLUG} />);
488
+ expect(captured?.onCompleted).toBeUndefined();
489
+ await captured!.onSubmitStep({ stepKey: "team", values: { team_size: "solo" }, locale: "en" });
490
+ expect(mockPush).not.toHaveBeenCalled();
491
+ });
492
+
493
+ it("a recommending flow with an ending and offers is passed no onCompleted (the ending wins, D-I)", () => {
494
+ render(
495
+ <FlowStepperClient
496
+ config={{
497
+ ...recommendingFlowConfig(),
498
+ ending: { default: { kind: "screen", headline: { en: "Done" } } },
499
+ } as FlowConfig}
500
+ locale="en"
501
+ slug={SLUG}
502
+ />,
503
+ );
504
+ expect(captured?.onCompleted).toBeUndefined();
505
+ });
506
+
507
+ it("a recommending flow with offers and no ending pushes the permalink as at the pin", async () => {
508
+ mockSubmitFlowStepAction.mockResolvedValueOnce({
509
+ ok: true,
510
+ response: { sessionId: "sess-o", landed: "team", nextStepKey: null, completed: true },
511
+ });
512
+
513
+ render(<FlowStepperClient config={recommendingFlowConfig()} locale="en" slug={SLUG} />);
514
+ await captured!.onSubmitStep({ stepKey: "team", values: { team_size: "agency", wants_seo: "no" }, locale: "en" });
515
+ captured!.onCompleted?.({});
516
+
517
+ const decoded = decodePermalink(pushedPayload());
518
+ expect(decoded.ok && decoded.value.answers).toEqual({ team_size: "agency", wants_seo: "no" });
519
+ });
520
+ });
@@ -69,10 +69,13 @@ const PII_PAYLOAD = {
69
69
  };
70
70
 
71
71
  let capturedOnCompleted: MockFlowStepperProps["onCompleted"];
72
+ // #11013 AC-1 — every prop the client hands the stepper, for the forwarding cases.
73
+ let capturedProps: Record<string, unknown> | undefined;
72
74
 
73
75
  jest.mock("@working-theory/ui-signal-collectors", () => ({
74
- FlowStepper: (props: MockFlowStepperProps) => {
76
+ FlowStepper: (props: MockFlowStepperProps & Record<string, unknown>) => {
75
77
  capturedOnCompleted = props.onCompleted;
78
+ capturedProps = props;
76
79
  async function handleSubmit(): Promise<void> {
77
80
  const result = await props.onSubmitStep({
78
81
  stepKey: "contact",
@@ -140,6 +143,36 @@ beforeEach(() => {
140
143
  mockPush.mockClear();
141
144
  mockSubmitFlowStepAction.mockClear();
142
145
  capturedOnCompleted = undefined;
146
+ capturedProps = undefined;
147
+ });
148
+
149
+ describe("FlowStepperClient — forwards brand, exit and presentation to FlowStepper (#11013 AC-1)", () => {
150
+ const brand = { logomark: <span data-testid="mark" />, wordmark: <span data-testid="word" />, title: "Quote" };
151
+ const exit = { href: "/en/flows/x", label: "Exit" };
152
+
153
+ it("forwards each unchanged", () => {
154
+ render(
155
+ <FlowStepperClient
156
+ config={noThankYouFlowConfig()}
157
+ locale="en"
158
+ slug="get-a-quote"
159
+ brand={brand}
160
+ exit={exit}
161
+ presentation="full"
162
+ />,
163
+ );
164
+ expect(capturedProps?.["brand"]).toBe(brand);
165
+ expect(capturedProps?.["exit"]).toBe(exit);
166
+ expect(capturedProps?.["presentation"]).toBe("full");
167
+ expect(capturedProps).not.toHaveProperty("header");
168
+ });
169
+
170
+ it("omits each when absent, so the stepper's own defaults apply", () => {
171
+ render(<FlowStepperClient config={noThankYouFlowConfig()} locale="en" slug="get-a-quote" />);
172
+ expect(capturedProps).not.toHaveProperty("brand");
173
+ expect(capturedProps).not.toHaveProperty("exit");
174
+ expect(capturedProps).not.toHaveProperty("presentation");
175
+ });
143
176
  });
144
177
 
145
178
  describe("FlowStepperClient — segment-keyed completion redirect (AC1)", () => {
@@ -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