create-ailk 0.40.0 → 0.40.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.
- package/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +13 -2
- package/templates/apps/web/app/[locale]/layout.tsx +41 -24
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
- package/templates/apps/web/app/llms.txt/route.ts +5 -2
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
- package/templates/apps/web/lib/hub-site-config.ts +151 -0
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/lib/site-contact-email.ts +24 -4
- package/templates/apps/web/lib/site-contact-lines.ts +20 -4
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +3 -0
- package/versions.json +50 -50
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The hub read of the site's identity and seo (#11456, spec
|
|
7
|
+
* docs/specs/11456-a-hub-connected-site-reads-spec.md D3; AC-2, AC-3).
|
|
8
|
+
*
|
|
9
|
+
* External boundaries doubled:
|
|
10
|
+
* - `@working-theory/api-client`'s `siteConfig.get` — the HTTP call to the
|
|
11
|
+
* hub (`sendsSpokeKey` stays real, so the switch is the env's);
|
|
12
|
+
* - `next/cache`'s `unstable_cache` — a fake with Next's write rule: a
|
|
13
|
+
* RESOLVED callback is written, a THROWING one writes nothing and the
|
|
14
|
+
* last entry is served (`unstable-cache.js` `cacheNewResult`).
|
|
15
|
+
*/
|
|
16
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
|
|
20
|
+
const mockGet = jest.fn();
|
|
21
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
22
|
+
...jest.requireActual("@working-theory/api-client"),
|
|
23
|
+
siteConfig: { get: (...args: unknown[]) => mockGet(...args) },
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
/** The fake data cache: one entry per joined key parts. */
|
|
27
|
+
const mockCacheStore = new Map<string, unknown>();
|
|
28
|
+
const mockUnstableCache = jest.fn(
|
|
29
|
+
(
|
|
30
|
+
fn: () => Promise<unknown>,
|
|
31
|
+
keyParts: string[],
|
|
32
|
+
_options: { tags: string[]; revalidate: number },
|
|
33
|
+
) =>
|
|
34
|
+
async () => {
|
|
35
|
+
const key = keyParts.join("|");
|
|
36
|
+
try {
|
|
37
|
+
const value = await fn();
|
|
38
|
+
mockCacheStore.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (mockCacheStore.has(key)) return mockCacheStore.get(key);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
jest.mock("next/cache", () => ({
|
|
47
|
+
unstable_cache: (...args: Parameters<typeof mockUnstableCache>) =>
|
|
48
|
+
mockUnstableCache(...args),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
import { siteConfigTag } from "@working-theory/page-renderer/edge";
|
|
52
|
+
|
|
53
|
+
import {
|
|
54
|
+
__resetHubSiteForTests,
|
|
55
|
+
HUB_SITE_REVALIDATE_SECONDS,
|
|
56
|
+
HUB_SITE_TIMEOUT_MS,
|
|
57
|
+
heldHubSite,
|
|
58
|
+
hubConnected,
|
|
59
|
+
readHubSite,
|
|
60
|
+
} from "../hub-site-config";
|
|
61
|
+
import { readSiteContactEmail } from "../site-contact-email";
|
|
62
|
+
|
|
63
|
+
const KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
64
|
+
const HUB_IDENTITY = {
|
|
65
|
+
kind: "Person",
|
|
66
|
+
name: "Hub Person",
|
|
67
|
+
url: "https://hub.example",
|
|
68
|
+
email: "hub@hub.example",
|
|
69
|
+
};
|
|
70
|
+
const HUB_SEO = { version: "1", robots: { index: false } };
|
|
71
|
+
const ok = (data: unknown) => ({ ok: true, body: data });
|
|
72
|
+
|
|
73
|
+
const ENV_KEYS = ["CONTENT_ADAPTER", "AILK_SPOKE_KEY", "AILK_API_URL", "AILK_CONTENT_ROOT"] as const;
|
|
74
|
+
const savedEnv = new Map(ENV_KEYS.map((k) => [k, process.env[k]]));
|
|
75
|
+
let root: string;
|
|
76
|
+
|
|
77
|
+
function hubConnect(): void {
|
|
78
|
+
process.env.CONTENT_ADAPTER = "database";
|
|
79
|
+
process.env.AILK_SPOKE_KEY = KEY;
|
|
80
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
mockGet.mockReset();
|
|
85
|
+
mockUnstableCache.mockClear();
|
|
86
|
+
mockCacheStore.clear();
|
|
87
|
+
__resetHubSiteForTests();
|
|
88
|
+
for (const k of ENV_KEYS) delete process.env[k];
|
|
89
|
+
root = mkdtempSync(join(tmpdir(), "hub-site-config-"));
|
|
90
|
+
process.env.AILK_CONTENT_ROOT = root;
|
|
91
|
+
writeFileSync(
|
|
92
|
+
join(root, "_site.mdx"),
|
|
93
|
+
"---\nsiteName: File Site\ncontactEmail: file@file.example\n---\n",
|
|
94
|
+
);
|
|
95
|
+
jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
jest.restoreAllMocks();
|
|
100
|
+
jest.useRealTimers();
|
|
101
|
+
rmSync(root, { recursive: true, force: true });
|
|
102
|
+
for (const [k, v] of savedEnv) {
|
|
103
|
+
if (v === undefined) delete process.env[k];
|
|
104
|
+
else process.env[k] = v;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("hubConnected (#11456 D3)", () => {
|
|
109
|
+
it("is true only with CONTENT_ADAPTER=database and a spoke key on the wire", () => {
|
|
110
|
+
expect(hubConnected()).toBe(false);
|
|
111
|
+
hubConnect();
|
|
112
|
+
expect(hubConnected()).toBe(true);
|
|
113
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
114
|
+
expect(hubConnected()).toBe(false);
|
|
115
|
+
hubConnect();
|
|
116
|
+
delete process.env.CONTENT_ADAPTER;
|
|
117
|
+
expect(hubConnected()).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
122
|
+
it.each([
|
|
123
|
+
["no AILK_SPOKE_KEY", () => delete process.env.AILK_SPOKE_KEY],
|
|
124
|
+
["CONTENT_ADAPTER unset", () => delete process.env.CONTENT_ADAPTER],
|
|
125
|
+
])("with %s answers undefined and never calls the hub", async (_label, unset) => {
|
|
126
|
+
hubConnect();
|
|
127
|
+
unset();
|
|
128
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
129
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
130
|
+
expect(mockUnstableCache).not.toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("wraps the read with tags [siteConfigTag()] and revalidate 300, keyed by a digest of the key, never the key", async () => {
|
|
134
|
+
hubConnect();
|
|
135
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
136
|
+
|
|
137
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO });
|
|
138
|
+
|
|
139
|
+
expect(mockUnstableCache).toHaveBeenCalledTimes(1);
|
|
140
|
+
const [, keyParts, options] = mockUnstableCache.mock.calls[0]!;
|
|
141
|
+
expect(options).toEqual({ tags: [siteConfigTag()], revalidate: 300 });
|
|
142
|
+
expect(HUB_SITE_REVALIDATE_SECONDS).toBe(300);
|
|
143
|
+
expect(keyParts[0]).toBe("ailk-hub-site-config");
|
|
144
|
+
expect(keyParts[1]).toBe("default");
|
|
145
|
+
expect(keyParts[2]).toMatch(/^[0-9a-f]{16}$/);
|
|
146
|
+
expect(keyParts.join("|")).not.toContain(KEY);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("two different keys never share an entry", async () => {
|
|
150
|
+
hubConnect();
|
|
151
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
152
|
+
await readHubSite();
|
|
153
|
+
process.env.AILK_SPOKE_KEY = `${KEY.slice(0, -1)}y`;
|
|
154
|
+
await readHubSite();
|
|
155
|
+
const [a, b] = mockUnstableCache.mock.calls.map((call) => call[1].join("|"));
|
|
156
|
+
expect(a).not.toBe(b);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("re-parses each row; a row its schema refuses is null", async () => {
|
|
160
|
+
hubConnect();
|
|
161
|
+
mockGet.mockResolvedValue(
|
|
162
|
+
ok({ identity: { kind: "Organization", name: "" }, seo: { version: "1", robots: { index: "no" } } }),
|
|
163
|
+
);
|
|
164
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it.each([
|
|
168
|
+
["a non-2xx", () => mockGet.mockResolvedValue({ ok: false, status: 401, body: {} })],
|
|
169
|
+
["a throw", () => mockGet.mockRejectedValue(new TypeError("fetch failed"))],
|
|
170
|
+
["a body without the two keys", () => mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY }))],
|
|
171
|
+
])("%s writes nothing, serves the last good value and never rejects", async (_label, fail) => {
|
|
172
|
+
hubConnect();
|
|
173
|
+
// Cold instance, nothing cached: a failure answers undefined.
|
|
174
|
+
fail();
|
|
175
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
176
|
+
expect(mockCacheStore.size).toBe(0);
|
|
177
|
+
|
|
178
|
+
// One good read, then the failure again: the entry and the held value stand.
|
|
179
|
+
mockGet.mockReset().mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
180
|
+
await readHubSite();
|
|
181
|
+
const [entry] = [...mockCacheStore.values()];
|
|
182
|
+
mockGet.mockReset();
|
|
183
|
+
fail();
|
|
184
|
+
mockCacheStore.clear(); // a purged tag: the next read misses
|
|
185
|
+
await expect(readHubSite()).resolves.toEqual(entry);
|
|
186
|
+
expect(mockCacheStore.size).toBe(0);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("a read slower than 3 s is a failed read", async () => {
|
|
190
|
+
jest.useFakeTimers();
|
|
191
|
+
hubConnect();
|
|
192
|
+
mockGet.mockReturnValue(new Promise(() => undefined));
|
|
193
|
+
const read = readHubSite();
|
|
194
|
+
await jest.advanceTimersByTimeAsync(HUB_SITE_TIMEOUT_MS);
|
|
195
|
+
await expect(read).resolves.toBeUndefined();
|
|
196
|
+
expect(mockCacheStore.size).toBe(0);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("the contact email from the held hub value (#11456 D4, AC-2)", () => {
|
|
201
|
+
it("answers the file value on a cold instance, then the hub email after one resolved read", async () => {
|
|
202
|
+
hubConnect();
|
|
203
|
+
expect(heldHubSite()).toBeUndefined();
|
|
204
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
205
|
+
|
|
206
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
207
|
+
await readHubSite();
|
|
208
|
+
|
|
209
|
+
expect(readSiteContactEmail()).toBe("hub@hub.example");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("a hub identity with no email falls back to the file's top-level contactEmail", async () => {
|
|
213
|
+
hubConnect();
|
|
214
|
+
const { email: _email, ...noEmail } = HUB_IDENTITY;
|
|
215
|
+
mockGet.mockResolvedValue(ok({ identity: noEmail, seo: null }));
|
|
216
|
+
await readHubSite();
|
|
217
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it.each([
|
|
221
|
+
["has no frontmatter", "No frontmatter here.\n"],
|
|
222
|
+
["has empty frontmatter", "---\n---\n"],
|
|
223
|
+
])("answers the hub email when _site.mdx %s", async (_label, body) => {
|
|
224
|
+
hubConnect();
|
|
225
|
+
writeFileSync(join(root, "_site.mdx"), body);
|
|
226
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
227
|
+
await readHubSite();
|
|
228
|
+
expect(readSiteContactEmail()).toBe("hub@hub.example");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("a site that is not hub-connected never reads a held value", async () => {
|
|
232
|
+
hubConnect();
|
|
233
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
234
|
+
await readHubSite();
|
|
235
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
236
|
+
expect(heldHubSite()).toBeUndefined();
|
|
237
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { deckReturnHref } from "@working-theory/ui/chrome";
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
ancestorPaths,
|
|
16
17
|
backLinkHref,
|
|
17
18
|
backLinkName,
|
|
18
19
|
navLabelsByPath,
|
|
@@ -87,6 +88,17 @@ describe("backLinkHref — the served parent", () => {
|
|
|
87
88
|
});
|
|
88
89
|
});
|
|
89
90
|
|
|
91
|
+
describe("ancestorPaths — the parents the walk asks about (#11438)", () => {
|
|
92
|
+
it("lists the bare ancestors below the home, nearest first, locale prefix dropped", () => {
|
|
93
|
+
expect(ancestorPaths("/es/flows/audit/start?x=1", LOCALES)).toEqual(["/flows/audit", "/flows"]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("has none for a top-level page or an absent pathname", () => {
|
|
97
|
+
expect(ancestorPaths("/about", LOCALES)).toEqual([]);
|
|
98
|
+
expect(ancestorPaths(null, LOCALES)).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
90
102
|
describe("backLinkName — the destination named in the label", () => {
|
|
91
103
|
const titles = new Map([
|
|
92
104
|
["/meet", "Book a meeting with Sam"],
|
|
@@ -109,6 +121,52 @@ describe("backLinkName — the destination named in the label", () => {
|
|
|
109
121
|
"Case studies",
|
|
110
122
|
);
|
|
111
123
|
});
|
|
124
|
+
|
|
125
|
+
describe("a title carrying the site name as a suffix", () => {
|
|
126
|
+
const siteName = "Sam Henry";
|
|
127
|
+
const suffixed = new Map([
|
|
128
|
+
["/about", "About — Sam Henry"],
|
|
129
|
+
["/faq", "Questions about hiring Sam | Sam Henry"],
|
|
130
|
+
["/work", "Work - Sam Henry"],
|
|
131
|
+
["/blog/ai-builder-principles", "The AI Builder Principles"],
|
|
132
|
+
["/notes", "Sam Henry — Notes from the field"],
|
|
133
|
+
["/press", "Working with Sam Henry and the team"],
|
|
134
|
+
["/only", " — Sam Henry"],
|
|
135
|
+
]);
|
|
136
|
+
const name = (parent: string, navLabels = new Map<string, string>()): string =>
|
|
137
|
+
backLinkName(parent, { navLabels, titles: suffixed, siteName });
|
|
138
|
+
|
|
139
|
+
it.each([
|
|
140
|
+
["/about", "About"],
|
|
141
|
+
["/faq", "Questions about hiring Sam"],
|
|
142
|
+
["/work", "Work"],
|
|
143
|
+
])("strips the trailing suffix: %s → %s", (parent, expected) => {
|
|
144
|
+
expect(name(parent)).toBe(expected);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("leaves a title without the suffix unchanged", () => {
|
|
148
|
+
expect(name("/blog/ai-builder-principles")).toBe("The AI Builder Principles");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("leaves the site name anywhere but the trailing suffix alone", () => {
|
|
152
|
+
expect(name("/notes")).toBe("Sam Henry — Notes from the field");
|
|
153
|
+
expect(name("/press")).toBe("Working with Sam Henry and the team");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("prefers the nav label when the nav has one for the parent", () => {
|
|
157
|
+
expect(name("/about", new Map([["/about", "About me"]]))).toBe("About me");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("keeps the title when stripping would leave nothing", () => {
|
|
161
|
+
expect(name("/only")).toBe(" — Sam Henry");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("leaves the title whole when no site name is known", () => {
|
|
165
|
+
expect(backLinkName("/about", { navLabels: new Map(), titles: suffixed })).toBe(
|
|
166
|
+
"About — Sam Henry",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
112
170
|
});
|
|
113
171
|
|
|
114
172
|
describe("navLabelsByPath", () => {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for the served-pages source the bare back arrow walks up through
|
|
3
3
|
* (operator handoff 2026-11-09): listed content pages with their titles,
|
|
4
|
-
*
|
|
5
|
-
* fail-safe when
|
|
4
|
+
* the page routes the app builds (#11438) — its page files and Next's
|
|
5
|
+
* app-path routes manifest, dynamic segments included — and a fail-safe when
|
|
6
|
+
* a source cannot be read.
|
|
7
|
+
*
|
|
8
|
+
* Every case builds its own app tree in a temporary directory and points
|
|
9
|
+
* `process.cwd()` at it, so the suite asserts the same thing in this
|
|
10
|
+
* monorepo and in any scaffold, whatever pages either carries.
|
|
6
11
|
*/
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { SCHEDULING_PAGES } from "../modules.generated";
|
|
13
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
|
|
17
|
+
import { ancestorPaths, servedParent } from "../profile-back-link";
|
|
14
18
|
|
|
15
19
|
const mockListPages = jest.fn();
|
|
16
20
|
let mockAdapterThrows = false;
|
|
@@ -27,15 +31,44 @@ function page(type: string, slug: string, title: string) {
|
|
|
27
31
|
return { type, slug, title };
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
let root: string;
|
|
35
|
+
|
|
36
|
+
/** Writes empty files under the temporary site root, at their relative paths. */
|
|
37
|
+
function site(files: Record<string, string>): void {
|
|
38
|
+
for (const [path, body] of Object.entries(files)) {
|
|
39
|
+
const file = join(root, path);
|
|
40
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
41
|
+
writeFileSync(file, body);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** An app tree of empty page files, each given relative to `app/[locale]/`. */
|
|
46
|
+
function appPages(...routes: string[]): void {
|
|
47
|
+
site(Object.fromEntries(routes.map((route) => [join("app/[locale]", route, "page.tsx"), ""])));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function loadModule(): typeof import("../served-pages") {
|
|
51
|
+
let mod!: typeof import("../served-pages");
|
|
32
52
|
jest.isolateModules(() => {
|
|
33
|
-
|
|
53
|
+
mod = jest.requireActual("../served-pages");
|
|
34
54
|
});
|
|
35
|
-
return
|
|
55
|
+
return mod;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function loadServed(locale: string, candidates?: readonly string[]) {
|
|
59
|
+
return loadModule().servedPages(locale, candidates);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The arrow's parent for `pathname`, as the locale layout asks it. */
|
|
63
|
+
async function arrowParent(pathname: string): Promise<string | null> {
|
|
64
|
+
const locales = ["en"];
|
|
65
|
+
const pages = await loadServed("en", ancestorPaths(pathname, locales));
|
|
66
|
+
return servedParent({ pathname, locales, served: (path) => pages.has(path) });
|
|
36
67
|
}
|
|
37
68
|
|
|
38
69
|
beforeEach(() => {
|
|
70
|
+
root = mkdtempSync(join(tmpdir(), "served-pages-"));
|
|
71
|
+
jest.spyOn(process, "cwd").mockReturnValue(root);
|
|
39
72
|
mockAdapterThrows = false;
|
|
40
73
|
mockListPages.mockReset();
|
|
41
74
|
mockListPages.mockImplementation((type: string) => {
|
|
@@ -47,7 +80,12 @@ beforeEach(() => {
|
|
|
47
80
|
});
|
|
48
81
|
});
|
|
49
82
|
|
|
50
|
-
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
jest.restoreAllMocks();
|
|
85
|
+
rmSync(root, { recursive: true, force: true });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("servedPages — content pages", () => {
|
|
51
89
|
it("lists a content page at its served path with its title", async () => {
|
|
52
90
|
const pages = await loadServed("en");
|
|
53
91
|
expect(pages.get("/about")).toBe("About us");
|
|
@@ -58,20 +96,125 @@ describe("servedPages", () => {
|
|
|
58
96
|
expect([...pages.values()]).not.toContain("Thanks");
|
|
59
97
|
});
|
|
60
98
|
|
|
61
|
-
it("includes /meet, the scheduling module's code-rendered index, with no title", async () => {
|
|
62
|
-
const pages = await loadServed("en");
|
|
63
|
-
expect(pages.get("/meet")).toBe(SCHEDULING_PAGES ? "" : undefined);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
99
|
it("reads the locale it is asked for", async () => {
|
|
67
100
|
await loadServed("es");
|
|
68
101
|
expect(mockListPages).toHaveBeenCalledWith("AboutPage", "es");
|
|
69
102
|
});
|
|
70
103
|
|
|
71
|
-
it("keeps
|
|
104
|
+
it("keeps a content page's title where the app also builds its route", async () => {
|
|
105
|
+
appPages("about");
|
|
106
|
+
const pages = await loadServed("en");
|
|
107
|
+
expect(pages.get("/about")).toBe("About us");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("servedPages — the page routes the app builds (#11438)", () => {
|
|
112
|
+
// The fixture site has no package.json and no generated module flag, so
|
|
113
|
+
// /meet is served by its page file alone (samhenry.org's own /meet pages).
|
|
114
|
+
it("serves /meet from the app's own page file, with no scheduling package and no title", async () => {
|
|
115
|
+
appPages("meet", "meet/[slug]");
|
|
116
|
+
const pages = await loadServed("en");
|
|
117
|
+
expect(pages.get("/meet")).toBe("");
|
|
118
|
+
await expect(arrowParent("/meet/intro")).resolves.toBe("/meet");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it.each([
|
|
122
|
+
["/private/meet-up", "/private", ["private"]],
|
|
123
|
+
["/diagnostic/start", "/diagnostic", ["diagnostic", "diagnostic/start"]],
|
|
124
|
+
["/flows/audit/start", "/flows/audit", ["flows/[slug]", "flows/[slug]/start"]],
|
|
125
|
+
["/es/flows/audit/start", "/flows/audit", ["flows/[slug]", "flows/[slug]/start"]],
|
|
126
|
+
])("%s → %s, a page route the app builds", async (pathname, parent, routes) => {
|
|
127
|
+
appPages(...routes);
|
|
128
|
+
const locales = ["en", "es"];
|
|
129
|
+
const pages = await loadServed("en", ancestorPaths(pathname, locales));
|
|
130
|
+
expect(servedParent({ pathname, locales, served: (path) => pages.has(path) })).toBe(parent);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("reads Next's app-path routes manifest where the page files are not deployed", async () => {
|
|
134
|
+
site({
|
|
135
|
+
".next/app-path-routes-manifest.json": JSON.stringify({
|
|
136
|
+
"/[locale]/diagnostic/page": "/[locale]/diagnostic",
|
|
137
|
+
"/[locale]/flows/[slug]/page": "/[locale]/flows/[slug]",
|
|
138
|
+
"/[locale]/feed.xml/route": "/[locale]/feed.xml",
|
|
139
|
+
"/_not-found/page": "/_not-found",
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
await expect(arrowParent("/diagnostic/start")).resolves.toBe("/diagnostic");
|
|
143
|
+
await expect(arrowParent("/flows/audit/start")).resolves.toBe("/flows/audit");
|
|
144
|
+
const pages = await loadServed("en");
|
|
145
|
+
expect(pages.has("/feed.xml")).toBe(false);
|
|
146
|
+
expect(pages.has("/_not-found")).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("drops route groups and skips private folders", async () => {
|
|
150
|
+
appPages("(authed)/account", "_parts/hidden");
|
|
151
|
+
const pages = await loadServed("en");
|
|
152
|
+
expect(pages.get("/account")).toBe("");
|
|
153
|
+
expect(pages.has("/_parts/hidden")).toBe(false);
|
|
154
|
+
expect(pages.has("/hidden")).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("serves an optional catch-all's own index, never a path under it", async () => {
|
|
158
|
+
appPages("blog/[[...slug]]");
|
|
159
|
+
const pages = await loadServed("en", ["/blog/series"]);
|
|
160
|
+
expect(pages.get("/blog")).toBe("");
|
|
161
|
+
expect(pages.has("/blog/series")).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("adds a dynamic route's match only for the candidates asked about, never to the shared set", async () => {
|
|
165
|
+
appPages("flows/[slug]");
|
|
166
|
+
const mod = loadModule();
|
|
167
|
+
expect((await mod.servedPages("en", ["/flows/audit"])).has("/flows/audit")).toBe(true);
|
|
168
|
+
expect((await mod.servedPages("en")).has("/flows/audit")).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("names no route in its own source", () => {
|
|
172
|
+
// The code alone: its doc comments name routes as examples.
|
|
173
|
+
const source = readFileSync(join(__dirname, "..", "served-pages.ts"), "utf8")
|
|
174
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
175
|
+
.replace(/^\s*\/\/.*$/gm, "");
|
|
176
|
+
for (const route of ["meet", "private", "diagnostic", "flows"]) {
|
|
177
|
+
expect(source).not.toMatch(new RegExp(`["'\`]/${route}\\b`));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("servedPages — what still falls through", () => {
|
|
183
|
+
it("walks past a parent with no built page route and no content page, then home", async () => {
|
|
184
|
+
appPages("meet");
|
|
185
|
+
await expect(arrowParent("/meet/nothing/deeper")).resolves.toBe("/meet");
|
|
186
|
+
await expect(arrowParent("/nowhere/at-all")).resolves.toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("never counts the site's all-dynamic content catch-all as a parent", async () => {
|
|
190
|
+
appPages("[slug]", "[slug]/[detail]");
|
|
191
|
+
await expect(arrowParent("/widgets/one/two")).resolves.toBeNull();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("never counts a required catch-all as a parent", async () => {
|
|
195
|
+
appPages("files/[...path]");
|
|
196
|
+
await expect(arrowParent("/files/a/b")).resolves.toBeNull();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("counts a built route with seed content only through its content page", async () => {
|
|
200
|
+
appPages("faq");
|
|
201
|
+
const pages = await loadServed("en");
|
|
202
|
+
expect(pages.has("/faq")).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("keeps the built routes when the adapter throws", async () => {
|
|
206
|
+
appPages("meet");
|
|
72
207
|
mockAdapterThrows = true;
|
|
73
208
|
const pages = await loadServed("en");
|
|
74
|
-
expect(pages.has("/meet")).toBe(
|
|
209
|
+
expect(pages.has("/meet")).toBe(true);
|
|
75
210
|
expect(pages.has("/about")).toBe(false);
|
|
76
211
|
});
|
|
212
|
+
|
|
213
|
+
it("serves only content pages, and warns, when neither the page files nor the manifest can be read", async () => {
|
|
214
|
+
site({ ".next/app-path-routes-manifest.json": "not json" });
|
|
215
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
216
|
+
const pages = await loadServed("en", ["/flows/audit"]);
|
|
217
|
+
expect([...pages.keys()]).toEqual(["/about"]);
|
|
218
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("[served-pages]"));
|
|
219
|
+
});
|
|
77
220
|
});
|
|
@@ -290,3 +290,80 @@ describe("siteLogo() — brand.logomark (#6820)", () => {
|
|
|
290
290
|
expect(() => siteLogo()).toThrow(/alt/);
|
|
291
291
|
});
|
|
292
292
|
});
|
|
293
|
+
|
|
294
|
+
// #11456 D4 — the async brand. The hub read is doubled at its own module
|
|
295
|
+
// (`readHubSite`, whose HTTP and cache edges `hub-site-config.test.ts` pins).
|
|
296
|
+
describe("resolveSiteBrand() (#11456 D4)", () => {
|
|
297
|
+
const mockReadHubSite = jest.fn();
|
|
298
|
+
beforeEach(() => {
|
|
299
|
+
process.env.AILK_CONTENT_ROOT = tmpRoot;
|
|
300
|
+
delete process.env.NEXT_PUBLIC_SITE_NAME;
|
|
301
|
+
writeSiteMdx(tmpRoot, { siteName: "File Site", baseUrl: "https://file.example" });
|
|
302
|
+
mockReadHubSite.mockReset();
|
|
303
|
+
// The hub read is the HTTP boundary; its own suite pins it.
|
|
304
|
+
jest.doMock("../hub-site-config", () => ({ readHubSite: () => mockReadHubSite() }));
|
|
305
|
+
});
|
|
306
|
+
afterEach(() => {
|
|
307
|
+
jest.dontMock("../hub-site-config");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const hub = (identity: unknown, seo: unknown = null) =>
|
|
311
|
+
mockReadHubSite.mockResolvedValue({ identity, seo });
|
|
312
|
+
|
|
313
|
+
it("with no hub site, answers the module's constants and indexable", async () => {
|
|
314
|
+
mockReadHubSite.mockResolvedValue(undefined);
|
|
315
|
+
const brand = await loadSiteBrand();
|
|
316
|
+
await expect(brand.resolveSiteBrand()).resolves.toEqual({
|
|
317
|
+
siteName: brand.SITE_NAME,
|
|
318
|
+
description: brand.SITE_DESCRIPTION,
|
|
319
|
+
copyrightHolder: brand.COPYRIGHT_HOLDER,
|
|
320
|
+
indexable: true,
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("a hub identity with no description takes the seo row's, never the file's", async () => {
|
|
325
|
+
hub(
|
|
326
|
+
{ kind: "Organization", name: "Hub Co", url: "https://hub.example" },
|
|
327
|
+
{ version: "1", description: "Seo description." },
|
|
328
|
+
);
|
|
329
|
+
const { resolveSiteBrand } = await loadSiteBrand();
|
|
330
|
+
await expect(resolveSiteBrand()).resolves.toEqual({
|
|
331
|
+
siteName: "Hub Co",
|
|
332
|
+
description: "Seo description.",
|
|
333
|
+
copyrightHolder: "Hub Co",
|
|
334
|
+
indexable: true,
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("collapses control and line-separator runs in hub values to one space", async () => {
|
|
339
|
+
hub({
|
|
340
|
+
kind: "Organization",
|
|
341
|
+
name: "A\n\u2028\u202eB\u200b",
|
|
342
|
+
legalName: "Legal\r\nCo",
|
|
343
|
+
description: "Line\tone\u2029two",
|
|
344
|
+
url: "https://hub.example",
|
|
345
|
+
});
|
|
346
|
+
const { resolveSiteBrand } = await loadSiteBrand();
|
|
347
|
+
await expect(resolveSiteBrand()).resolves.toMatchObject({
|
|
348
|
+
siteName: "A B",
|
|
349
|
+
copyrightHolder: "Legal Co",
|
|
350
|
+
description: "Line one two",
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("NEXT_PUBLIC_SITE_NAME still wins the hub name", async () => {
|
|
355
|
+
process.env.NEXT_PUBLIC_SITE_NAME = "Env Name";
|
|
356
|
+
hub({ kind: "Organization", name: "Hub Co", url: "https://hub.example" });
|
|
357
|
+
const { resolveSiteBrand } = await loadSiteBrand();
|
|
358
|
+
await expect(resolveSiteBrand()).resolves.toMatchObject({ siteName: "Env Name" });
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("indexable reads the seo row even with no identity row", async () => {
|
|
362
|
+
hub(null, { version: "1", robots: { index: false } });
|
|
363
|
+
const brand = await loadSiteBrand();
|
|
364
|
+
await expect(brand.resolveSiteBrand()).resolves.toMatchObject({
|
|
365
|
+
siteName: brand.SITE_NAME,
|
|
366
|
+
indexable: false,
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|