create-ailk 0.46.2 → 0.46.3
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/component-catalog.json +104 -6
- package/component-catalog.md +7 -6
- package/dist/surfaces.js +1 -1
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +134 -2
- package/templates/apps/web/app/globals.css +12 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/llms.txt/route.ts +22 -0
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/sitemap.xml/route.ts +43 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +170 -1
- package/templates/apps/web/lib/__tests__/magnet-addresses.test.ts +406 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +704 -4
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +276 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +44 -0
- package/templates/apps/web/lib/in-page-magnet.ts +86 -9
- package/templates/apps/web/lib/magnet-addresses.ts +317 -0
- package/templates/apps/web/lib/offerings-pricing.ts +406 -45
- package/templates/apps/web/lib/paid-section-contracts.ts +41 -1
- package/templates/apps/web/lib/pricing-page.ts +163 -6
- package/templates/apps/web/lib/served-pages.ts +38 -1
- package/templates/apps/web/messages/en.json +2 -1
- package/templates/apps/web/site-pages.config.tsx +9 -0
- package/versions.json +50 -50
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
* `DocsDetail` rows, so those rows are listed at the docs path; otherwise
|
|
36
36
|
* those rows are skipped (the MDX docs route never serves them) and the docs
|
|
37
37
|
* directory is listed instead (`getDocsPages`, default `listDocsPages`).
|
|
38
|
+
*
|
|
39
|
+
* Magnet addresses (#12204 D8): after the content pages, one entry per
|
|
40
|
+
* (enabled locale, address the site serves in that locale) — only addresses
|
|
41
|
+
* the hub lists (`listed`), never `/flows/<slug>` — with alternates over the
|
|
42
|
+
* locales it is served in and `lastmod` the magnet's last change
|
|
43
|
+
* (`getMagnetAddresses`, default `servedAddresses`).
|
|
38
44
|
*/
|
|
39
45
|
|
|
40
46
|
import {
|
|
@@ -47,6 +53,7 @@ import {
|
|
|
47
53
|
listedPath,
|
|
48
54
|
type SiteListing,
|
|
49
55
|
} from "@working-theory/page-renderer";
|
|
56
|
+
import type { FlowAddressItem } from "@working-theory/validation";
|
|
50
57
|
|
|
51
58
|
import {
|
|
52
59
|
adapterDocsUrl,
|
|
@@ -54,6 +61,7 @@ import {
|
|
|
54
61
|
listDocsPages,
|
|
55
62
|
type DocsIndexPage,
|
|
56
63
|
} from "../../lib/docs-index";
|
|
64
|
+
import { servedAddresses } from "../../lib/magnet-addresses";
|
|
57
65
|
import { PUBLIC_PAGES } from "../../lib/modules.generated";
|
|
58
66
|
import { SITE_LISTING } from "../../lib/site-listing";
|
|
59
67
|
import { siteLive } from "../../lib/site-visibility";
|
|
@@ -75,6 +83,8 @@ export interface SitemapHandlerDeps {
|
|
|
75
83
|
discoverable?: () => Promise<boolean>;
|
|
76
84
|
/** The site's own listing (#10940 D3). Defaults to `SITE_LISTING`. */
|
|
77
85
|
getSiteListing?: () => SiteListing;
|
|
86
|
+
/** The magnet addresses served in a locale (#12204 D8). Defaults to `servedAddresses`. */
|
|
87
|
+
getMagnetAddresses?: (locale: string) => Promise<readonly FlowAddressItem[]>;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
function escapeXml(value: string): string {
|
|
@@ -112,6 +122,7 @@ export function createSitemapHandler(deps: SitemapHandlerDeps = {}) {
|
|
|
112
122
|
const resolveDocsPages = deps.getDocsPages ?? listDocsPages;
|
|
113
123
|
const isDiscoverable = deps.discoverable ?? siteLive;
|
|
114
124
|
const resolveSiteListing = deps.getSiteListing ?? (() => SITE_LISTING);
|
|
125
|
+
const resolveMagnetAddresses = deps.getMagnetAddresses ?? servedAddresses;
|
|
115
126
|
return async function sitemapGET(): Promise<Response> {
|
|
116
127
|
// #10040 decision 7 — no public page, no sitemap: 404 before the adapter.
|
|
117
128
|
if (!PUBLIC_PAGES) return new Response(null, { status: 404 });
|
|
@@ -188,6 +199,38 @@ export function createSitemapHandler(deps: SitemapHandlerDeps = {}) {
|
|
|
188
199
|
}
|
|
189
200
|
}
|
|
190
201
|
|
|
202
|
+
// #12204 D8 — the magnet addresses: listed ones only, each at the one URL
|
|
203
|
+
// per locale it is served at.
|
|
204
|
+
const addressLists = await Promise.all(
|
|
205
|
+
locales.map((locale) => resolveMagnetAddresses(locale).catch(() => [])),
|
|
206
|
+
);
|
|
207
|
+
const servedIn = new Map<string, string[]>();
|
|
208
|
+
for (let i = 0; i < locales.length; i++) {
|
|
209
|
+
for (const item of addressLists[i]!) {
|
|
210
|
+
if (item.listed) servedIn.set(item.path, [...(servedIn.get(item.path) ?? []), locales[i]!]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (let i = 0; i < locales.length; i++) {
|
|
214
|
+
const locale = locales[i]!;
|
|
215
|
+
for (const item of addressLists[i]!) {
|
|
216
|
+
if (!item.listed) continue;
|
|
217
|
+
const path = item.path;
|
|
218
|
+
const alternates = (servedIn.get(path) ?? [])
|
|
219
|
+
.map(
|
|
220
|
+
(alt) =>
|
|
221
|
+
` <xhtml:link rel="alternate" hreflang="${escapeXml(alt)}" href="${escapeXml(buildLocaleUrl(baseUrl, alt, defaultLocale, path))}"/>`,
|
|
222
|
+
)
|
|
223
|
+
.join("\n");
|
|
224
|
+
// x-default names the default-locale URL, so only where it is served.
|
|
225
|
+
const xDefault = (servedIn.get(path) ?? []).includes(defaultLocale)
|
|
226
|
+
? `\n <xhtml:link rel="alternate" hreflang="x-default" href="${escapeXml(buildLocaleUrl(baseUrl, defaultLocale, defaultLocale, path))}"/>`
|
|
227
|
+
: "";
|
|
228
|
+
urlEntries.push(
|
|
229
|
+
` <url>\n <loc>${escapeXml(buildLocaleUrl(baseUrl, locale, defaultLocale, path))}</loc>\n <lastmod>${item.updatedAt.slice(0, 10)}</lastmod>\n${alternates}${xDefault}\n </url>`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
191
234
|
if (!databaseDocs) {
|
|
192
235
|
for (const doc of resolveDocsPages()) pushDocsEntry(doc.url, today);
|
|
193
236
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { LeadCaptureForm } from "@working-theory/ui";
|
|
9
9
|
import {
|
|
10
10
|
contactFormFlowConfig,
|
|
11
|
+
flowConfigSchema,
|
|
11
12
|
newsletterFlowConfig,
|
|
12
13
|
type FlowConfig,
|
|
13
14
|
} from "@working-theory/validation";
|
|
@@ -17,7 +18,6 @@ jest.mock("@working-theory/api-client", () => ({
|
|
|
17
18
|
leads: { captureStatus: jest.fn() },
|
|
18
19
|
}));
|
|
19
20
|
|
|
20
|
-
// eslint-disable-next-line no-restricted-syntax -- test-seam mock: a "use server" boundary the module only binds
|
|
21
21
|
jest.mock("@working-theory/site-pages/pages/contact/contact.actions", () => ({
|
|
22
22
|
captureLeadAction: jest.fn(),
|
|
23
23
|
}));
|
|
@@ -263,3 +263,172 @@ describe("readServedMagnet", () => {
|
|
|
263
263
|
expect(await readServedMagnet("down")).toBeNull();
|
|
264
264
|
});
|
|
265
265
|
});
|
|
266
|
+
|
|
267
|
+
// ─── The magnet section's renderer (#12205 D4; AC-4, AC-5) ────────────────────
|
|
268
|
+
|
|
269
|
+
describe("renderMagnetSection", () => {
|
|
270
|
+
type Module = typeof import("../in-page-magnet");
|
|
271
|
+
|
|
272
|
+
const FIVE_TYPES: FlowConfig = flowConfigSchema.parse({
|
|
273
|
+
slug: "five-types",
|
|
274
|
+
defaultLocale: "en",
|
|
275
|
+
steps: [
|
|
276
|
+
{
|
|
277
|
+
key: "about",
|
|
278
|
+
type: "field",
|
|
279
|
+
copy: { title: { en: "About you" } },
|
|
280
|
+
fields: [
|
|
281
|
+
{ name: "email", inputType: "email", required: true, mapsTo: "email", copy: { label: { en: "Email" } } },
|
|
282
|
+
{ name: "site", inputType: "url", copy: { label: { en: "Site" } } },
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
key: "pace",
|
|
287
|
+
type: "segmentation",
|
|
288
|
+
copy: { title: { en: "Pace?" } },
|
|
289
|
+
questions: [{ name: "pace", options: [{ value: "fast", label: { en: "Fast" } }, { value: "slow", label: { en: "Slow" } }] }],
|
|
290
|
+
},
|
|
291
|
+
{ key: "note", type: "message", copy: { title: { en: "A note" } } },
|
|
292
|
+
{ key: "score", type: "aeo_score", copy: { title: { en: "Your score" } }, urlField: "site" },
|
|
293
|
+
{ key: "extra", type: "custom", copy: { title: { en: "Extra" } }, renderer: "extra" },
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
function StubLauncher(): null {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A fresh copy of the module (its package load is memoized per process),
|
|
303
|
+
* with the site's package answering `ui`, and the registration spied.
|
|
304
|
+
*/
|
|
305
|
+
function load(ui: unknown): {
|
|
306
|
+
mod: Module;
|
|
307
|
+
get: jest.Mock;
|
|
308
|
+
loadUi: jest.Mock;
|
|
309
|
+
register: jest.Mock;
|
|
310
|
+
} {
|
|
311
|
+
jest.resetModules();
|
|
312
|
+
const loadUi = jest.fn(async () => ui);
|
|
313
|
+
const register = jest.fn();
|
|
314
|
+
jest.doMock("../paid-sections.generated", () => ({
|
|
315
|
+
...jest.requireActual("../paid-sections.generated"),
|
|
316
|
+
loadUiSignalCollectors: loadUi,
|
|
317
|
+
}));
|
|
318
|
+
jest.doMock("@working-theory/page-renderer", () => ({
|
|
319
|
+
...jest.requireActual("@working-theory/page-renderer"),
|
|
320
|
+
setMagnetSectionRenderer: register,
|
|
321
|
+
}));
|
|
322
|
+
const mod = require("../in-page-magnet") as Module;
|
|
323
|
+
const get = (require("@working-theory/api-client") as { flows: { get: jest.Mock } }).flows.get;
|
|
324
|
+
return { mod, get, loadUi, register };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
let warn: jest.SpyInstance;
|
|
328
|
+
beforeEach(() => {
|
|
329
|
+
warn = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
330
|
+
});
|
|
331
|
+
afterEach(() => {
|
|
332
|
+
warn.mockRestore();
|
|
333
|
+
jest.useRealTimers();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("registers itself with page-renderer at module load", () => {
|
|
337
|
+
const { mod, register } = load(null);
|
|
338
|
+
expect(register).toHaveBeenCalledWith(mod.renderMagnetSection);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it.each([
|
|
342
|
+
["absent or a draft (404)", (get: jest.Mock) => get.mockResolvedValueOnce({ ok: false, status: 404, body: {} })],
|
|
343
|
+
["a rejected read", (get: jest.Mock) => get.mockRejectedValueOnce(new Error("hub down"))],
|
|
344
|
+
["a 2xx that is not a served flow", (get: jest.Mock) => get.mockResolvedValueOnce({ ok: true, status: 200, body: { slug: "x" } })],
|
|
345
|
+
])("answers null for %s, and never loads the package", async (_name, arrange) => {
|
|
346
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
347
|
+
arrange(get);
|
|
348
|
+
expect(await mod.renderMagnetSection({ slug: "x", locale: "en" })).toBeNull();
|
|
349
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("answers null for a read that never settles, after 2,000 ms", async () => {
|
|
353
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
354
|
+
jest.useFakeTimers();
|
|
355
|
+
get.mockReturnValueOnce(new Promise(() => undefined));
|
|
356
|
+
const pending = mod.renderMagnetSection({ slug: "stalled", locale: "en" });
|
|
357
|
+
await jest.advanceTimersByTimeAsync(2_000);
|
|
358
|
+
expect(await pending).toBeNull();
|
|
359
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("answers null for a deliverable magnet (its one route is /reports/<slug>)", async () => {
|
|
363
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
364
|
+
get.mockResolvedValueOnce({
|
|
365
|
+
ok: true,
|
|
366
|
+
status: 200,
|
|
367
|
+
body: { ...FIVE_TYPES, deliverable: { kind: "file", gated: true, copy: { title: { en: "Report" } } } },
|
|
368
|
+
});
|
|
369
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
370
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it.each([
|
|
374
|
+
["no package", null],
|
|
375
|
+
["a package without MagnetSectionClient", { flowsMessages: () => ({}) }],
|
|
376
|
+
])("answers null with %s", async (_name, ui) => {
|
|
377
|
+
const { mod, get } = load(ui);
|
|
378
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
379
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("answers the package's launcher over the whole served config", async () => {
|
|
383
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher });
|
|
384
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
385
|
+
const element = (await mod.renderMagnetSection({ slug: "five-types", locale: "fr" }))!;
|
|
386
|
+
expect(element.type).toBe(StubLauncher);
|
|
387
|
+
const props = element.props as Record<string, unknown>;
|
|
388
|
+
expect(props["config"]).toBe(FIVE_TYPES);
|
|
389
|
+
expect(props["slug"]).toBe("five-types");
|
|
390
|
+
expect(props["locale"]).toBe("fr");
|
|
391
|
+
expect(props["consentPolicies"]).toEqual(expect.any(Object));
|
|
392
|
+
expect(props["brand"]).toEqual({ logomark: expect.anything(), wordmark: expect.anything() });
|
|
393
|
+
expect(props).not.toHaveProperty("bookingStep");
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("passes the booking step's calendar the package builds, when there is one", async () => {
|
|
397
|
+
const calendar = { type: "div", props: {} };
|
|
398
|
+
const bookingStepElement = jest.fn(async () => calendar);
|
|
399
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher, bookingStepElement });
|
|
400
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
401
|
+
const element = (await mod.renderMagnetSection({ slug: "five-types", locale: "en" }))!;
|
|
402
|
+
expect(bookingStepElement).toHaveBeenCalledWith(FIVE_TYPES);
|
|
403
|
+
expect((element.props as Record<string, unknown>)["bookingStep"]).toBe(calendar);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("a throw past the read answers null with one warning that names nothing read", async () => {
|
|
407
|
+
const bookingStepElement = jest.fn(async () => {
|
|
408
|
+
throw new Error("five-types exploded");
|
|
409
|
+
});
|
|
410
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher, bookingStepElement });
|
|
411
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
412
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
413
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
414
|
+
expect(warn).toHaveBeenCalledWith("[magnet-section] render failed; the section is removed");
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("rethrows Next's control flow", async () => {
|
|
418
|
+
const { redirect } = jest.requireActual("next/navigation") as typeof import("next/navigation");
|
|
419
|
+
let signal: unknown;
|
|
420
|
+
try {
|
|
421
|
+
redirect("/elsewhere");
|
|
422
|
+
} catch (err) {
|
|
423
|
+
signal = err;
|
|
424
|
+
}
|
|
425
|
+
const { mod, get } = load({
|
|
426
|
+
MagnetSectionClient: StubLauncher,
|
|
427
|
+
bookingStepElement: jest.fn(async () => {
|
|
428
|
+
throw signal;
|
|
429
|
+
}),
|
|
430
|
+
});
|
|
431
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
432
|
+
await expect(mod.renderMagnetSection({ slug: "five-types", locale: "en" })).rejects.toBe(signal);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the site's magnet-address resolver (#12204, spec
|
|
7
|
+
* docs/specs/12204-an-owner-chosen-address-a-spec.md D2, D5, D6, D9):
|
|
8
|
+
*
|
|
9
|
+
* - AC-1 — an address the hub lists and nothing on the site claims serves its
|
|
10
|
+
* cover, walk, verify and results through the package's dispatcher, and the
|
|
11
|
+
* walk at an address is chrome-free while its cover is not;
|
|
12
|
+
* - AC-2 — a shadowed address is not served (so the forward, the sitemap and
|
|
13
|
+
* llms.txt never name it);
|
|
14
|
+
* - AC-4 — a keyless site reads nothing, an older hub's 404 is no address;
|
|
15
|
+
* - AC-5 — the table is the hub's, read again after 15 seconds with no
|
|
16
|
+
* rebuild, shared by concurrent reads, held on a failed read;
|
|
17
|
+
* - D2's drift test — every built-in route's first segment is reserved.
|
|
18
|
+
*
|
|
19
|
+
* Each case loads the module fresh (`jest.isolateModules`), so its 15-second
|
|
20
|
+
* table starts empty.
|
|
21
|
+
*/
|
|
22
|
+
import { readdirSync } from "node:fs";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
|
|
25
|
+
import { ROUTES } from "@working-theory/templates/routes";
|
|
26
|
+
import { MAGNET_ADDRESS_RESERVED_SEGMENTS } from "@working-theory/validation";
|
|
27
|
+
|
|
28
|
+
import { isMagnetWalkPath } from "../magnet-routes";
|
|
29
|
+
|
|
30
|
+
const mockAddresses = jest.fn();
|
|
31
|
+
const mockRedirect = jest.fn();
|
|
32
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
33
|
+
flows: { addresses: (...args: unknown[]) => mockAddresses(...args) },
|
|
34
|
+
pages: { redirect: (...args: unknown[]) => mockRedirect(...args) },
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const mockGetMdxSource = jest.fn();
|
|
38
|
+
jest.mock("@working-theory/page-renderer", () => ({
|
|
39
|
+
getMdxSource: (...args: unknown[]) => mockGetMdxSource(...args),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
let mockAdapterKind = "mdx";
|
|
43
|
+
jest.mock("@working-theory/content-adapters", () => ({
|
|
44
|
+
resolvedAdapterKind: () => mockAdapterKind,
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
jest.mock("@working-theory/web-i18n", () => ({
|
|
48
|
+
readLocales: () => ["en", "es"],
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
let mockStatics: string[] = [];
|
|
52
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: the route tree's reader, tested over real trees in served-pages.test.ts; pinned here so each case names its static segments
|
|
53
|
+
jest.mock("../served-pages", () => ({
|
|
54
|
+
staticFirstSegments: () => mockStatics,
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const mockRenderMagnetAt = jest.fn(async (input: unknown) => ({
|
|
58
|
+
rendered: input,
|
|
59
|
+
}));
|
|
60
|
+
const mockMagnetMetadataAt = jest.fn(async (input: unknown) => ({
|
|
61
|
+
metadata: input,
|
|
62
|
+
}));
|
|
63
|
+
let mockPackage: object | null = {};
|
|
64
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: a per-site generated file (create-ailk writes it); this suite pins whether the package is carried
|
|
65
|
+
jest.mock("../paid-sections.generated", () => ({
|
|
66
|
+
loadUiSignalCollectors: async () => mockPackage,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
type Mod = typeof import("../magnet-addresses");
|
|
70
|
+
|
|
71
|
+
function load(): Mod {
|
|
72
|
+
let mod!: Mod;
|
|
73
|
+
jest.isolateModules(() => {
|
|
74
|
+
mod = jest.requireActual<Mod>("../magnet-addresses");
|
|
75
|
+
});
|
|
76
|
+
return mod;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const AG = {
|
|
80
|
+
slug: "agency-application",
|
|
81
|
+
path: "/agencies/apply",
|
|
82
|
+
listed: true,
|
|
83
|
+
title: "Agency application",
|
|
84
|
+
purpose: "Answer a few questions to get a scored assessment.",
|
|
85
|
+
updatedAt: "2026-11-20T10:00:00.000Z",
|
|
86
|
+
};
|
|
87
|
+
const ONE = { ...AG, slug: "apply-now", path: "/apply", title: "Apply now" };
|
|
88
|
+
|
|
89
|
+
function table(...items: unknown[]) {
|
|
90
|
+
return { ok: true, body: { addresses: items } };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
mockAddresses.mockReset();
|
|
95
|
+
mockAddresses.mockResolvedValue(table(AG, ONE));
|
|
96
|
+
mockRedirect.mockReset();
|
|
97
|
+
mockRedirect.mockResolvedValue({ ok: false, status: 404, body: null });
|
|
98
|
+
mockGetMdxSource.mockReset();
|
|
99
|
+
mockGetMdxSource.mockResolvedValue(null);
|
|
100
|
+
mockRenderMagnetAt.mockClear();
|
|
101
|
+
mockMagnetMetadataAt.mockClear();
|
|
102
|
+
mockAdapterKind = "mdx";
|
|
103
|
+
mockStatics = ["about", "flows", "pricing"];
|
|
104
|
+
mockPackage = {
|
|
105
|
+
renderMagnetAt: mockRenderMagnetAt,
|
|
106
|
+
magnetMetadataAt: mockMagnetMetadataAt,
|
|
107
|
+
};
|
|
108
|
+
delete process.env.NEXT_PUBLIC_AILK_DOCS_PATH;
|
|
109
|
+
delete process.env.NEXT_PUBLIC_AILK_ROUTE_PATHS;
|
|
110
|
+
process.env.NEXT_PUBLIC_DEFAULT_LOCALE = "en";
|
|
111
|
+
process.env.NEXT_PUBLIC_BASE_URL = "https://site.example";
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
afterEach(() => {
|
|
115
|
+
jest.useRealTimers();
|
|
116
|
+
delete process.env.NEXT_PUBLIC_DEFAULT_LOCALE;
|
|
117
|
+
delete process.env.NEXT_PUBLIC_BASE_URL;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("magnetPageAt — AC-1 (D5, D6)", () => {
|
|
121
|
+
it.each([
|
|
122
|
+
[
|
|
123
|
+
["agencies", "apply"],
|
|
124
|
+
{},
|
|
125
|
+
{ slug: "agency-application", base: "/agencies/apply", rest: [] },
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
["agencies", "apply", "start"],
|
|
129
|
+
{},
|
|
130
|
+
{ slug: "agency-application", base: "/agencies/apply", rest: ["start"] },
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
["agencies", "apply", "verify"],
|
|
134
|
+
{ lead: "x", verify: "y" },
|
|
135
|
+
{ slug: "agency-application", base: "/agencies/apply", rest: ["verify"] },
|
|
136
|
+
],
|
|
137
|
+
[
|
|
138
|
+
["agencies", "apply", "results", "p1"],
|
|
139
|
+
{},
|
|
140
|
+
{
|
|
141
|
+
slug: "agency-application",
|
|
142
|
+
base: "/agencies/apply",
|
|
143
|
+
rest: ["results", "p1"],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
[["apply"], {}, { slug: "apply-now", base: "/apply", rest: [] }],
|
|
147
|
+
[
|
|
148
|
+
["apply", "start"],
|
|
149
|
+
{},
|
|
150
|
+
{ slug: "apply-now", base: "/apply", rest: ["start"] },
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
["apply", "results", "p1"],
|
|
154
|
+
{},
|
|
155
|
+
{ slug: "apply-now", base: "/apply", rest: ["results", "p1"] },
|
|
156
|
+
],
|
|
157
|
+
])(
|
|
158
|
+
"%j dispatches to the package",
|
|
159
|
+
async (segments, searchParams, expected) => {
|
|
160
|
+
const element = await load().magnetPageAt(segments, "en", searchParams);
|
|
161
|
+
expect(mockRenderMagnetAt).toHaveBeenCalledWith({
|
|
162
|
+
...expected,
|
|
163
|
+
locale: "en",
|
|
164
|
+
searchParams,
|
|
165
|
+
});
|
|
166
|
+
expect(element).toEqual({
|
|
167
|
+
rendered: { ...expected, locale: "en", searchParams },
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
it.each([
|
|
173
|
+
[["agencies", "apply", "other"]],
|
|
174
|
+
[["agencies"]],
|
|
175
|
+
[["agencies", "apply", "results"]],
|
|
176
|
+
[["agencies", "apply", "start", "x"]],
|
|
177
|
+
[["apply", "results", "p1", "x"]],
|
|
178
|
+
[["unknown"]],
|
|
179
|
+
])("%j is no magnet page", async (segments) => {
|
|
180
|
+
await expect(load().magnetPageAt(segments, "en", {})).resolves.toBeNull();
|
|
181
|
+
expect(mockRenderMagnetAt).not.toHaveBeenCalled();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("names the address as the cover's canonical, with the sitemap's locale prefix (D8, D9)", async () => {
|
|
185
|
+
const mod = load();
|
|
186
|
+
await mod.magnetMetadataAt(["agencies", "apply"], "en");
|
|
187
|
+
expect(mockMagnetMetadataAt).toHaveBeenLastCalledWith({
|
|
188
|
+
slug: "agency-application",
|
|
189
|
+
base: "/agencies/apply",
|
|
190
|
+
rest: [],
|
|
191
|
+
locale: "en",
|
|
192
|
+
canonical: "https://site.example/agencies/apply",
|
|
193
|
+
});
|
|
194
|
+
await mod.magnetMetadataAt(["agencies", "apply"], "es");
|
|
195
|
+
expect(mockMagnetMetadataAt).toHaveBeenLastCalledWith(
|
|
196
|
+
expect.objectContaining({
|
|
197
|
+
locale: "es",
|
|
198
|
+
canonical: "https://site.example/es/agencies/apply",
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
await expect(mod.magnetMetadataAt(["agencies"], "en")).resolves.toBeNull();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("serves no item the hub's contract refuses (NFR-4)", async () => {
|
|
205
|
+
mockAddresses.mockResolvedValue(
|
|
206
|
+
table(
|
|
207
|
+
{ ...AG, path: "//evil.example" },
|
|
208
|
+
{ ...ONE, path: "/Apply" },
|
|
209
|
+
{ ...ONE, slug: "x", extra: 1 },
|
|
210
|
+
),
|
|
211
|
+
);
|
|
212
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("keeps the walk at an address chrome-free and its cover in the chrome", () => {
|
|
216
|
+
expect(isMagnetWalkPath("/agencies/apply/start", ["en"])).toBe(true);
|
|
217
|
+
expect(isMagnetWalkPath("/apply/start", ["en"])).toBe(true);
|
|
218
|
+
expect(isMagnetWalkPath("/agencies/apply", ["en"])).toBe(false);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("answers the forward's address for a served magnet, null for any other (D7)", async () => {
|
|
222
|
+
const mod = load();
|
|
223
|
+
await expect(mod.servedAddressOf("agency-application", "en")).resolves.toBe(
|
|
224
|
+
"/agencies/apply",
|
|
225
|
+
);
|
|
226
|
+
await expect(mod.servedAddressOf("contact", "en")).resolves.toBeNull();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("servedAddresses — the shadow rule (D5 a–d, AC-2)", () => {
|
|
231
|
+
it("leaves out an address under a static route", async () => {
|
|
232
|
+
mockStatics = ["agencies"];
|
|
233
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([ONE]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("leaves out an address under the docs base", async () => {
|
|
237
|
+
process.env.NEXT_PUBLIC_AILK_DOCS_PATH = "/agencies/docs";
|
|
238
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([ONE]);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("leaves out an address on a renamed family's segment", async () => {
|
|
242
|
+
process.env.NEXT_PUBLIC_AILK_ROUTE_PATHS = JSON.stringify({
|
|
243
|
+
portfolio: "apply",
|
|
244
|
+
});
|
|
245
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([AG]);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("leaves out an address whose first segment is a content page in that locale", async () => {
|
|
249
|
+
mockGetMdxSource.mockImplementation(
|
|
250
|
+
async (type: string, slug: string, locale: string) =>
|
|
251
|
+
type === "BlogList" && slug === "apply" && locale === "es"
|
|
252
|
+
? { frontmatter: {} }
|
|
253
|
+
: null,
|
|
254
|
+
);
|
|
255
|
+
const mod = load();
|
|
256
|
+
await expect(mod.servedAddresses("es")).resolves.toEqual([AG]);
|
|
257
|
+
await expect(mod.servedAddresses("en")).resolves.toEqual([AG, ONE]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("leaves out a moved page's old address under the database adapter only", async () => {
|
|
261
|
+
mockRedirect.mockImplementation(async (path: string) =>
|
|
262
|
+
path === "/apply"
|
|
263
|
+
? { ok: true, body: { to: "/new" } }
|
|
264
|
+
: { ok: false, status: 404, body: null },
|
|
265
|
+
);
|
|
266
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([AG, ONE]);
|
|
267
|
+
expect(mockRedirect).not.toHaveBeenCalled();
|
|
268
|
+
mockAdapterKind = "database";
|
|
269
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([AG]);
|
|
270
|
+
expect(mockRedirect).toHaveBeenCalledWith("/apply", { locale: "en" });
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("probes only the table's first segments, once per window, never the requested path (SEC-12204-6)", async () => {
|
|
274
|
+
const mod = load();
|
|
275
|
+
await mod.magnetPageAt(["random", "path"], "en", {});
|
|
276
|
+
await mod.magnetPageAt(["agencies", "apply"], "en", {});
|
|
277
|
+
await mod.servedAddresses("en");
|
|
278
|
+
const probed = mockGetMdxSource.mock.calls.map(([, slug]) => slug);
|
|
279
|
+
expect(new Set(probed)).toEqual(new Set(["agencies", "apply"]));
|
|
280
|
+
expect(mockGetMdxSource).toHaveBeenCalledTimes(4);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("readAddressTable — AC-4 (D14)", () => {
|
|
285
|
+
it("makes no read on a site without the signal-collectors package", async () => {
|
|
286
|
+
mockPackage = null;
|
|
287
|
+
const mod = load();
|
|
288
|
+
await expect(mod.servedAddresses("en")).resolves.toEqual([]);
|
|
289
|
+
await expect(
|
|
290
|
+
mod.magnetPageAt(["agencies", "apply"], "en", {}),
|
|
291
|
+
).resolves.toBeNull();
|
|
292
|
+
expect(mockAddresses).not.toHaveBeenCalled();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("reads an older hub's 404 as no address", async () => {
|
|
296
|
+
mockAddresses.mockResolvedValue({ ok: false, status: 404, body: null });
|
|
297
|
+
const mod = load();
|
|
298
|
+
await expect(mod.servedAddresses("en")).resolves.toEqual([]);
|
|
299
|
+
await expect(
|
|
300
|
+
mod.servedAddressOf("agency-application", "en"),
|
|
301
|
+
).resolves.toBeNull();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("never rejects when the client throws", async () => {
|
|
305
|
+
mockAddresses.mockRejectedValue(new Error("refused"));
|
|
306
|
+
await expect(load().servedAddresses("en")).resolves.toEqual([]);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("a locale the site does not enable keys no computation and costs no hub read", async () => {
|
|
310
|
+
mockAddresses.mockResolvedValue(table(AG));
|
|
311
|
+
const mod = load();
|
|
312
|
+
await expect(mod.servedAddresses("x.1")).resolves.toEqual([]);
|
|
313
|
+
await expect(mod.servedAddressOf("agency-application", "x.2")).resolves.toBeNull();
|
|
314
|
+
await expect(mod.magnetPageAt(["agencies", "apply"], "x.3", {})).resolves.toBeNull();
|
|
315
|
+
expect(mockAddresses).not.toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("readAddressTable — AC-5 (shared, refreshed, held)", () => {
|
|
320
|
+
it("reads the hub again after the window with no rebuild, and keeps the last good table on a failure", async () => {
|
|
321
|
+
jest.useFakeTimers();
|
|
322
|
+
const mod = load();
|
|
323
|
+
mockAddresses.mockResolvedValueOnce(table(AG));
|
|
324
|
+
await expect(mod.readAddressTable()).resolves.toEqual([AG]);
|
|
325
|
+
|
|
326
|
+
jest.advanceTimersByTime(16_000);
|
|
327
|
+
mockAddresses.mockResolvedValueOnce(table(ONE));
|
|
328
|
+
await expect(mod.readAddressTable()).resolves.toEqual([ONE]);
|
|
329
|
+
await expect(mod.servedAddresses("en")).resolves.toEqual([ONE]);
|
|
330
|
+
|
|
331
|
+
jest.advanceTimersByTime(16_000);
|
|
332
|
+
mockAddresses.mockResolvedValueOnce({ ok: false, status: 500, body: null });
|
|
333
|
+
await expect(mod.readAddressTable()).resolves.toEqual([ONE]);
|
|
334
|
+
|
|
335
|
+
jest.advanceTimersByTime(16_000);
|
|
336
|
+
mockAddresses.mockRejectedValueOnce(new Error("refused"));
|
|
337
|
+
await expect(mod.readAddressTable()).resolves.toEqual([ONE]);
|
|
338
|
+
expect(mockAddresses).toHaveBeenCalledTimes(4);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("shares one read across concurrent callers", async () => {
|
|
342
|
+
const mod = load();
|
|
343
|
+
await Promise.all([
|
|
344
|
+
mod.readAddressTable(),
|
|
345
|
+
mod.servedAddresses("en"),
|
|
346
|
+
mod.servedAddressOf("apply-now", "en"),
|
|
347
|
+
]);
|
|
348
|
+
expect(mockAddresses).toHaveBeenCalledTimes(1);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("holds a failed read for its window rather than retrying", async () => {
|
|
352
|
+
jest.useFakeTimers();
|
|
353
|
+
mockAddresses.mockResolvedValue({ ok: false, status: 503, body: null });
|
|
354
|
+
const mod = load();
|
|
355
|
+
await mod.readAddressTable();
|
|
356
|
+
jest.advanceTimersByTime(10_000);
|
|
357
|
+
await mod.readAddressTable();
|
|
358
|
+
expect(mockAddresses).toHaveBeenCalledTimes(1);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("counts a read with no answer within 5 seconds as failed", async () => {
|
|
362
|
+
jest.useFakeTimers();
|
|
363
|
+
mockAddresses.mockReturnValue(new Promise(() => {}));
|
|
364
|
+
const mod = load();
|
|
365
|
+
const read = mod.readAddressTable();
|
|
366
|
+
await jest.advanceTimersByTimeAsync(2_000);
|
|
367
|
+
await expect(read).resolves.toEqual([]);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
describe("MAGNET_ADDRESS_RESERVED_SEGMENTS — the D2 drift test", () => {
|
|
372
|
+
const reserved = new Set(MAGNET_ADDRESS_RESERVED_SEGMENTS);
|
|
373
|
+
|
|
374
|
+
it("reserves every ROUTES first segment", () => {
|
|
375
|
+
const firsts = new Set(
|
|
376
|
+
ROUTES.map((row) => row.route.split("/")[1] ?? "").filter(
|
|
377
|
+
(segment) => segment !== "" && !segment.startsWith(":"),
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
expect([...firsts].filter((segment) => !reserved.has(segment))).toEqual([]);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("reserves every legacyRoutes source's first segment, which the site redirects", () => {
|
|
384
|
+
const firsts = new Set(
|
|
385
|
+
ROUTES.flatMap((row) => row.legacyRoutes ?? []).map((route) => route.split("/")[1] ?? ""),
|
|
386
|
+
);
|
|
387
|
+
expect(firsts.size).toBeGreaterThan(0);
|
|
388
|
+
expect([...firsts].filter((segment) => !reserved.has(segment))).toEqual([]);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("reserves every static top-level route directory of the site, route groups opened", () => {
|
|
392
|
+
const localeDir = join(__dirname, "..", "..", "app", "[locale]");
|
|
393
|
+
const dirs = (dir: string): string[] =>
|
|
394
|
+
readdirSync(dir, { withFileTypes: true })
|
|
395
|
+
.filter((entry) => entry.isDirectory())
|
|
396
|
+
.flatMap((entry) =>
|
|
397
|
+
/^\(.*\)$/.test(entry.name)
|
|
398
|
+
? dirs(join(dir, entry.name))
|
|
399
|
+
: [entry.name],
|
|
400
|
+
)
|
|
401
|
+
.filter((name) => !/^[[_@]/.test(name));
|
|
402
|
+
const segments = dirs(localeDir);
|
|
403
|
+
expect(segments.length).toBeGreaterThan(10);
|
|
404
|
+
expect(segments.filter((segment) => !reserved.has(segment))).toEqual([]);
|
|
405
|
+
});
|
|
406
|
+
});
|