create-ailk 0.47.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +180 -43
  2. package/component-catalog.json +223 -285
  3. package/component-catalog.md +1 -1
  4. package/dist/apply-design.d.ts +26 -68
  5. package/dist/apply-design.js +150 -322
  6. package/dist/cli.js +152 -17
  7. package/dist/compare-chrome.d.ts +108 -0
  8. package/dist/compare-chrome.js +481 -0
  9. package/dist/compare-look.d.ts +94 -0
  10. package/dist/compare-look.js +378 -0
  11. package/dist/copy.js +1 -1
  12. package/dist/design-compile.d.ts +17 -21
  13. package/dist/design-compile.js +32 -56
  14. package/dist/design-files.d.ts +93 -0
  15. package/dist/design-files.js +312 -0
  16. package/dist/design-home.d.ts +4 -2
  17. package/dist/design-home.js +88 -6
  18. package/dist/design-names.d.ts +13 -0
  19. package/dist/design-names.js +76 -0
  20. package/dist/design-package.d.ts +46 -56
  21. package/dist/design-package.js +285 -288
  22. package/dist/design-presets.d.ts +41 -0
  23. package/dist/design-presets.js +83 -4
  24. package/dist/design-scaffold.d.ts +12 -2
  25. package/dist/design-scaffold.js +72 -34
  26. package/dist/generated/design-settings.d.ts +56 -0
  27. package/dist/generated/design-settings.js +237 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/inventory.d.ts +3 -2
  31. package/dist/inventory.js +10 -4
  32. package/dist/lib/design-checks.d.ts +46 -0
  33. package/dist/lib/design-checks.js +79 -1
  34. package/dist/lib/env-catalog.js +1 -1
  35. package/dist/lib/module-license-gate.d.ts +1 -1
  36. package/dist/lib/module-license-gate.js +1 -1
  37. package/dist/lib/render-verdict.d.ts +13 -1
  38. package/dist/lib/render-verdict.js +41 -1
  39. package/dist/look-hub.d.ts +44 -0
  40. package/dist/look-hub.js +130 -0
  41. package/dist/look-record.d.ts +35 -0
  42. package/dist/look-record.js +85 -0
  43. package/dist/look-samples.d.ts +66 -0
  44. package/dist/look-samples.js +456 -0
  45. package/dist/look-settings.d.ts +53 -0
  46. package/dist/look-settings.js +363 -0
  47. package/dist/module-architecture.js +12 -0
  48. package/dist/parse-args.d.ts +10 -6
  49. package/dist/parse-args.js +26 -13
  50. package/dist/programmatic.d.ts +1 -19
  51. package/dist/programmatic.js +65 -103
  52. package/dist/retired-design-bodies.d.ts +29 -0
  53. package/dist/retired-design-bodies.js +51 -0
  54. package/dist/seed-flows.d.ts +1 -1
  55. package/dist/seed-flows.js +12 -14
  56. package/dist/seed-workspace.d.ts +4 -1
  57. package/dist/seed-workspace.js +139 -17
  58. package/dist/site-chrome.d.ts +41 -41
  59. package/dist/site-chrome.js +50 -70
  60. package/dist/site-fonts.d.ts +10 -14
  61. package/dist/site-fonts.js +5 -1
  62. package/dist/starter-grid.d.ts +2 -2
  63. package/dist/strip-look-copies.d.ts +67 -0
  64. package/dist/strip-look-copies.js +591 -0
  65. package/dist/template-manifest.d.ts +6 -14
  66. package/dist/template-manifest.js +0 -9
  67. package/dist/template-record.d.ts +3 -1
  68. package/dist/template-record.js +3 -1
  69. package/dist/topology.d.ts +15 -0
  70. package/dist/topology.js +60 -0
  71. package/dist/update.d.ts +57 -1
  72. package/dist/update.js +742 -13
  73. package/package.json +3 -4
  74. package/site-templates/aliases/hub.TEMPLATE-MANIFEST.json +2 -31
  75. package/site-templates/designs/minimalism/DESIGN.md +163 -297
  76. package/site-templates/designs/minimalism/LOOK.md +42 -0
  77. package/site-templates/designs/minimalism/design.yaml +167 -0
  78. package/site-templates/designs/standard/DESIGN.md +145 -149
  79. package/site-templates/designs/standard/LOOK.md +42 -0
  80. package/site-templates/designs/standard/design.yaml +72 -0
  81. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +2 -31
  82. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +1 -25
  83. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +2 -31
  84. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +1 -25
  85. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +2 -31
  86. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +1 -25
  87. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +2 -31
  88. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +1 -25
  89. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +2 -31
  90. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +1 -25
  91. package/site-templates/shapes/person-service/content/_site.mdx +0 -26
  92. package/templates/.claude/rules/extending.md +3 -2
  93. package/templates/.env.example +11 -4
  94. package/templates/CLAUDE.md +1 -1
  95. package/templates/DESIGN.md +145 -149
  96. package/templates/README.md +15 -16
  97. package/templates/apps/api/.env.example +11 -4
  98. package/templates/apps/api/CLAUDE.md +6 -4
  99. package/templates/apps/api/src/lib/__mocks__/prisma.ts +15 -5
  100. package/templates/apps/mcp/CLAUDE.md +4 -2
  101. package/templates/apps/web/.env.example +10 -3
  102. package/templates/apps/web/CLAUDE.md +14 -3
  103. package/templates/apps/web/app/[locale]/layout.tsx +53 -50
  104. package/templates/apps/web/app/not-found.tsx +11 -11
  105. package/templates/apps/web/auth.ts +48 -35
  106. package/templates/apps/web/jest.config.cjs +5 -0
  107. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +179 -31
  108. package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
  109. package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +71 -32
  110. package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
  111. package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
  112. package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
  113. package/templates/apps/web/lib/deck-page.ts +3 -10
  114. package/templates/apps/web/lib/deploy-fonts.ts +12 -0
  115. package/templates/apps/web/lib/hub-site-config.ts +97 -14
  116. package/templates/apps/web/lib/library-fonts.ts +41 -0
  117. package/templates/apps/web/lib/mcp-oauth.ts +11 -4
  118. package/templates/apps/web/lib/page-chrome.ts +52 -34
  119. package/templates/apps/web/lib/section-look.ts +28 -0
  120. package/templates/apps/web/lib/site-design.ts +205 -0
  121. package/templates/apps/web/lib/site-theme-head.ts +98 -13
  122. package/templates/apps/web/lib/site-theme.ts +40 -62
  123. package/templates/apps/web/messages/en.json +0 -6
  124. package/templates/apps/web/next.config.mjs +195 -6
  125. package/templates/apps/web/package.json +2 -0
  126. package/templates/apps/web/site-pages.config.tsx +4 -2
  127. package/templates/content/_site.mdx +0 -26
  128. package/templates/design.yaml +75 -0
  129. package/templates/project.yaml +14 -0
  130. package/versions.json +52 -51
  131. package/site-templates/marketing-site/DESIGN.md +0 -259
  132. package/site-templates/marketing-site-free/DESIGN.md +0 -259
  133. package/site-templates/saas-product/DESIGN.md +0 -259
  134. package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
  135. package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
  136. package/templates/apps/web/lib/site-chrome.ts +0 -46
  137. package/templates/apps/web/lib/site-fonts.ts +0 -15
@@ -5,30 +5,44 @@
5
5
  * (AC-4). The reads run over a scratch content root (`AILK_CONTENT_ROOT`),
6
6
  * so the real readers parse real files.
7
7
  */
8
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
9
9
  import { tmpdir } from "node:os";
10
10
  import { join } from "node:path";
11
11
 
12
12
  import { FrontmatterSchema } from "@working-theory/content-adapters";
13
- import {
14
- FOOTER_STYLES,
15
- HEADER_STYLES,
16
- ROUTE_FAMILY_KEYS,
17
- } from "@working-theory/site-config/schema";
13
+ import { ROUTE_FAMILY_KEYS } from "@working-theory/site-config/schema";
14
+ import { compileDesignLayout } from "@working-theory/theme";
15
+ import { designSettingsSchema, FOOTER_STYLES, HEADER_STYLES } from "@working-theory/validation";
18
16
  import { ROUTES } from "@working-theory/templates/routes";
17
+ import { parse as parseYaml } from "yaml";
18
+
19
+ // #12473 — the hub read behind the design record: `siteConfig.get` is the
20
+ // HTTP call to the hub, and the data cache runs the read uncached.
21
+ const mockSiteConfigGet = jest.fn();
22
+ jest.mock("@working-theory/api-client", () => ({
23
+ ...jest.requireActual("@working-theory/api-client"),
24
+ sendsSpokeKey: () => (process.env.AILK_SPOKE_KEY ?? "") !== "",
25
+ siteConfig: { get: (...args: unknown[]) => mockSiteConfigGet(...args) },
26
+ }));
27
+ jest.mock("next/cache", () => ({
28
+ unstable_cache: (fn: () => Promise<unknown>) => fn,
29
+ }));
30
+
31
+ import { __resetHubSiteForTests } from "../hub-site-config";
19
32
 
20
33
  import {
21
34
  chromePageCandidates,
22
35
  readClosingFooterSettings,
23
36
  readSiteChromeSettings,
24
37
  resolveChromePage,
38
+ resolveHomeChrome,
25
39
  resolveHomeLayout,
26
40
  resolvePageChrome,
27
41
  routeFamilyOf,
28
42
  type PageChromeInput,
29
43
  type SiteChromeSettings,
30
44
  } from "../page-chrome";
31
- import type { SiteChrome } from "../site-chrome";
45
+ import { BASE_SITE_LAYOUT, type SiteChrome } from "../site-design";
32
46
 
33
47
  // #10704 — a fixture suite: its content is shaped for the mdx source, whatever the site serves from.
34
48
  process.env.CONTENT_ADAPTER = "mdx";
@@ -49,7 +63,7 @@ describe("route families (#10049 AC-2)", () => {
49
63
  expect([...ROUTE_FAMILY_KEYS]).toEqual(hubs);
50
64
  });
51
65
 
52
- it("the page frontmatter's header and footer enums equal the site's style lists", () => {
66
+ it("the page frontmatter's header and footer enums equal the one style lists (#12470 AC-14)", () => {
53
67
  const shape = FrontmatterSchema.shape;
54
68
  expect(shape.header.unwrap().options).toEqual([...HEADER_STYLES]);
55
69
  expect(shape.footer.unwrap().options).toEqual([...FOOTER_STYLES]);
@@ -104,7 +118,6 @@ const MINIMALISM: SiteChrome = {
104
118
  home: "deck",
105
119
  deckPresentation: true,
106
120
  innerPages: "bare",
107
- colorMode: "light",
108
121
  chromeStyle: "minimal",
109
122
  };
110
123
  const NOTHING: SiteChromeSettings = { families: {} };
@@ -151,29 +164,21 @@ describe("resolvePageChrome — the template level (#10049 AC-3)", () => {
151
164
  ["inner, bare inner pages", { chrome: MINIMALISM }, "bare", "line"],
152
165
  ["inner, otherwise", {}, "full", "columns"],
153
166
  ])("%s → (%j) %s / %s", (_name, over, header, footer) => {
154
- expect(resolvePageChrome(input(over))).toEqual({
155
- header,
156
- footer,
157
- headerFromTemplate: true,
158
- });
167
+ expect(resolvePageChrome(input(over))).toEqual({ header, footer });
159
168
  });
160
169
 
161
170
  it("a standard design whose home resolves deck keeps the full header and its own footer", () => {
162
171
  expect(
163
172
  resolvePageChrome(input({ isHome: true, homeIsDeck: true })),
164
- ).toEqual({
165
- header: "full",
166
- footer: "columns",
167
- headerFromTemplate: true,
168
- });
173
+ ).toEqual({ header: "full", footer: "columns" });
169
174
  });
170
175
 
171
- it("a minimalism site that turns its deck home off gets the full bar", () => {
176
+ it("a minimalism site that turns its deck home off gets its look's bar, mark-only", () => {
172
177
  expect(
173
178
  resolvePageChrome(
174
179
  input({ isHome: true, homeIsDeck: false, chrome: MINIMALISM }),
175
180
  ),
176
- ).toEqual({ header: "full", footer: "centered", headerFromTemplate: true });
181
+ ).toEqual({ header: "mark-only", footer: "centered" });
177
182
  });
178
183
 
179
184
  it("a closing-listed page whose own footer is columns ends on columns", () => {
@@ -185,6 +190,43 @@ describe("resolvePageChrome — the template level (#10049 AC-3)", () => {
185
190
  });
186
191
  });
187
192
 
193
+ describe("resolvePageChrome — the look's nav and footer (#12470 D7, AC-14)", () => {
194
+ it.each<[string, Partial<PageChromeInput>]>([
195
+ ["a default home", { isHome: true }],
196
+ ["an inner page that is not bare", {}],
197
+ ["a closing-listed page that is not bare", { closingListed: true }],
198
+ ])("%s takes the look's nav, every value of the one list", (_name, over) => {
199
+ for (const nav of HEADER_STYLES) {
200
+ expect(resolvePageChrome(input({ ...over, chrome: { ...STANDARD, nav } })).header).toBe(nav);
201
+ }
202
+ });
203
+
204
+ it("a default home and an inner page take the look's footer, every value of the one list; a closing-listed page keeps closing", () => {
205
+ for (const footer of FOOTER_STYLES) {
206
+ const chrome = { ...STANDARD, footer };
207
+ expect(resolvePageChrome(input({ isHome: true, chrome })).footer).toBe(footer);
208
+ expect(resolvePageChrome(input({ chrome })).footer).toBe(footer);
209
+ expect(resolvePageChrome(input({ closingListed: true, chrome })).footer).toBe("closing");
210
+ }
211
+ });
212
+
213
+ it("a deck home and a bare inner page keep their bare header whatever the look's nav, and line stays a resolved value only", () => {
214
+ const chrome = { ...MINIMALISM, nav: "none" as const };
215
+ expect(resolvePageChrome(input({ isHome: true, homeIsDeck: true, chrome })).header).toBe("bare");
216
+ expect(resolvePageChrome(input({ chrome }))).toEqual({ header: "bare", footer: "line" });
217
+ });
218
+
219
+ it("mark-only set by a site, a family or a page resolves the same mark-only a look's nav does", () => {
220
+ const fromLook = resolvePageChrome(input({ chrome: { ...STANDARD, nav: "mark-only" } })).header;
221
+ expect(fromLook).toBe("mark-only");
222
+ expect(resolvePageChrome(input({ site: { headerStyle: "mark-only", families: {} } })).header).toBe(fromLook);
223
+ expect(
224
+ resolvePageChrome(input({ family: "blog", site: { families: { blog: { header: "mark-only" } } } })).header,
225
+ ).toBe(fromLook);
226
+ expect(resolvePageChrome(input({ page: { header: "mark-only" } })).header).toBe(fromLook);
227
+ });
228
+ });
229
+
188
230
  describe("resolvePageChrome — most specific wins (#10049 AC-3)", () => {
189
231
  const site: SiteChromeSettings = {
190
232
  headerStyle: "none",
@@ -196,7 +238,6 @@ describe("resolvePageChrome — most specific wins (#10049 AC-3)", () => {
196
238
  expect(resolvePageChrome(input({ site }))).toEqual({
197
239
  header: "none",
198
240
  footer: "none",
199
- headerFromTemplate: false,
200
241
  });
201
242
  });
202
243
 
@@ -204,7 +245,6 @@ describe("resolvePageChrome — most specific wins (#10049 AC-3)", () => {
204
245
  expect(resolvePageChrome(input({ site, family: "blog" }))).toEqual({
205
246
  header: "bare",
206
247
  footer: "centered",
207
- headerFromTemplate: false,
208
248
  });
209
249
  });
210
250
 
@@ -217,7 +257,7 @@ describe("resolvePageChrome — most specific wins (#10049 AC-3)", () => {
217
257
  page: { header: "full", footer: "closing" },
218
258
  }),
219
259
  ),
220
- ).toEqual({ header: "full", footer: "closing", headerFromTemplate: false });
260
+ ).toEqual({ header: "full", footer: "closing" });
221
261
  });
222
262
 
223
263
  it("the axes resolve independently", () => {
@@ -232,10 +272,10 @@ describe("resolvePageChrome — most specific wins (#10049 AC-3)", () => {
232
272
  page: { footer: "none" },
233
273
  }),
234
274
  ),
235
- ).toEqual({ header: "none", footer: "none", headerFromTemplate: false });
275
+ ).toEqual({ header: "none", footer: "none" });
236
276
  expect(
237
277
  resolvePageChrome(input({ site: { headerStyle: "bare", families: {} } })),
238
- ).toEqual({ header: "bare", footer: "columns", headerFromTemplate: false });
278
+ ).toEqual({ header: "bare", footer: "columns" });
239
279
  });
240
280
 
241
281
  it("a family key for another family has no effect", () => {
@@ -545,3 +585,60 @@ describe("a renamed route family (#11385 AC-9)", () => {
545
585
  expect(list).not.toContainEqual({ type: "LandingPage", slug: "writing-samples" });
546
586
  });
547
587
  });
588
+
589
+ // ── #12473 AC-3 — the home's chrome from the hub design record's layout ─────
590
+
591
+ // The monorepo's design library; a scaffold ships this file (#10704) but not
592
+ // the library, so the block skips there (#12593).
593
+ const MINIMALISM_SETTINGS = join(__dirname, "../../../../packages/create-ailk/site-templates/designs/minimalism/design.yaml");
594
+
595
+ (existsSync(MINIMALISM_SETTINGS) ? describe : describe.skip)("resolveHomeChrome — the design record's layout knobs (#12473 AC-3)", () => {
596
+ /** Minimalism's settings with `deckAnchors: bare` added, parsed as the hub parses them. */
597
+ const settings = () => {
598
+ const parsed = parseYaml(readFileSync(MINIMALISM_SETTINGS, "utf8")) as { layout: Record<string, unknown> };
599
+ return designSettingsSchema.parse({ ...parsed, layout: { ...parsed.layout, deckAnchors: "bare" } });
600
+ };
601
+ const answer = (design: unknown) =>
602
+ mockSiteConfigGet.mockResolvedValue({ ok: true, body: { identity: null, seo: null, design } });
603
+ const ENV = ["AILK_SPOKE_KEY", "AILK_API_URL", "AILK_CONTENT_ROOT"] as const;
604
+ const saved = new Map(ENV.map((k) => [k, process.env[k]]));
605
+ let root: string;
606
+
607
+ beforeEach(() => {
608
+ __resetHubSiteForTests();
609
+ mockSiteConfigGet.mockReset();
610
+ root = mkdtempSync(join(tmpdir(), "home-knobs-"));
611
+ process.env.AILK_CONTENT_ROOT = root;
612
+ process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
613
+ process.env.AILK_API_URL = "https://hub.example";
614
+ });
615
+
616
+ afterEach(() => {
617
+ rmSync(root, { recursive: true, force: true });
618
+ for (const [k, v] of saved) {
619
+ if (v === undefined) delete process.env[k];
620
+ else process.env[k] = v;
621
+ }
622
+ });
623
+
624
+ it("answers the record's deck home and its compiled knobs", async () => {
625
+ const worked = settings();
626
+ answer({ version: 2, record: { version: "1", from: { look: "minimalism", version: "1" } }, settings: worked, look: null });
627
+ const home = await resolveHomeChrome("en", BASE_SITE_LAYOUT);
628
+ expect(home.layout).toBe("deck");
629
+ expect(home.knobs).toStrictEqual(compileDesignLayout(worked.layout));
630
+ expect(home.chrome).toEqual({ header: "bare", footer: "closing" });
631
+ });
632
+
633
+ it.each<[string, () => void]>([
634
+ ["no record", () => answer(null)],
635
+ ["a record with settings: null and only a brand", () =>
636
+ answer({ version: 2, record: { version: "1", from: null, brand: { colors: { primary: "#1a7f37" } } }, settings: null, look: null })],
637
+ ])("with %s, answers the base look's values and no knobs", async (_label, arrange) => {
638
+ arrange();
639
+ const home = await resolveHomeChrome("en", BASE_SITE_LAYOUT);
640
+ expect(home.layout).toBe("default");
641
+ expect(home).not.toHaveProperty("knobs");
642
+ expect(home.chrome).toEqual({ header: "full", footer: "columns" });
643
+ });
644
+ });
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ /**
6
+ * The site registers its section look over its hub read (#12474 D3; AC-3):
7
+ * the reader answers the worked-out `settings.sections` of the hub read's
8
+ * `design`, never the record's own `settings`; nothing is registered, and no
9
+ * read made, on a site that is not hub-connected.
10
+ *
11
+ * External boundaries doubled: `@working-theory/api-client`'s
12
+ * `siteConfig.get` (the HTTP call to the hub) and `next/cache`'s
13
+ * `unstable_cache` (a pass-through, so each read reaches the double). The env
14
+ * decides `hubConnected()`; `@working-theory/page-renderer`'s registration is
15
+ * recorded.
16
+ */
17
+ import type { SectionLookReader } from "@working-theory/page-renderer";
18
+
19
+ const mockSetSectionLookReader = jest.fn<void, [SectionLookReader | undefined]>();
20
+ jest.mock("@working-theory/page-renderer", () => ({
21
+ ...jest.requireActual("@working-theory/page-renderer"),
22
+ setSectionLookReader: (reader: SectionLookReader | undefined) => mockSetSectionLookReader(reader),
23
+ }));
24
+
25
+ const mockGet = jest.fn();
26
+ jest.mock("@working-theory/api-client", () => ({
27
+ ...jest.requireActual("@working-theory/api-client"),
28
+ siteConfig: { get: (...args: unknown[]) => mockGet(...args) },
29
+ }));
30
+ jest.mock("next/cache", () => ({
31
+ unstable_cache: (fn: () => Promise<unknown>) => fn,
32
+ }));
33
+
34
+ const KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
35
+ const ENV_KEYS = ["AILK_SPOKE_KEY", "AILK_API_URL", "NEXT_PUBLIC_AILK_API_URL", "NEXT_PUBLIC_API_URL"] as const;
36
+ const savedEnv = new Map(ENV_KEYS.map((k) => [k, process.env[k]]));
37
+
38
+ const S = { HomePage: { hero: { variant: "centered", fill: "viewport" }, team: { variant: "with-portraits" } } };
39
+ const R = { HomePage: { hero: { variant: "split" } } };
40
+
41
+ /** A complete design's settings, as the hub works them out. */
42
+ function settings(sections?: unknown): Record<string, unknown> {
43
+ return {
44
+ name: "Minimalism",
45
+ version: 1,
46
+ description: "The minimalism design.",
47
+ colors: {
48
+ bg: "#ffffff",
49
+ fg: "#000000",
50
+ surface: "#ffffff",
51
+ "surface-secondary": "#ffffff",
52
+ border: "#000000",
53
+ "text-muted": "#333333",
54
+ brand: "#000000",
55
+ "fg-on-brand": "#ffffff",
56
+ accent: "#000000",
57
+ "bg-dark": "#000000",
58
+ "fg-dark": "#ffffff",
59
+ "surface-dark": "#000000",
60
+ "surface-secondary-dark": "#000000",
61
+ "border-dark": "#ffffff",
62
+ "text-muted-dark": "#cccccc",
63
+ "brand-dark": "#ffffff",
64
+ "fg-on-brand-dark": "#000000",
65
+ "accent-dark": "#ffffff",
66
+ },
67
+ typography: {
68
+ body: { fontFamily: "system-ui, sans-serif", fontSize: "1.125rem", fontWeight: 400, lineHeight: 1.5 },
69
+ },
70
+ rounded: { button: "0.5rem" },
71
+ spacing: { section: "7rem" },
72
+ layout: { nav: "full", footer: "columns", announcementBanner: false, home: "default" },
73
+ ...(sections === undefined ? {} : { sections }),
74
+ };
75
+ }
76
+
77
+ const LOOK = { name: "minimalism", version: "1", latest: "1", behind: false };
78
+
79
+ /** One site-config answer carrying `design`. */
80
+ function answer(design: unknown) {
81
+ return { ok: true, status: 200, body: { identity: null, seo: null, navigation: null, design } };
82
+ }
83
+
84
+ /** Load the module fresh and answer the reader it registered, if any. */
85
+ function load(): SectionLookReader | undefined {
86
+ mockSetSectionLookReader.mockClear();
87
+ jest.isolateModules(() => {
88
+ require("../section-look");
89
+ });
90
+ return mockSetSectionLookReader.mock.calls[0]?.[0];
91
+ }
92
+
93
+ beforeEach(() => {
94
+ mockGet.mockReset();
95
+ for (const k of ENV_KEYS) delete process.env[k];
96
+ process.env.AILK_SPOKE_KEY = KEY;
97
+ process.env.AILK_API_URL = "https://hub.example";
98
+ jest.spyOn(console, "warn").mockImplementation(() => undefined);
99
+ });
100
+
101
+ afterEach(() => {
102
+ jest.restoreAllMocks();
103
+ for (const [k, v] of savedEnv) {
104
+ if (v === undefined) delete process.env[k];
105
+ else process.env[k] = v;
106
+ }
107
+ });
108
+
109
+ describe("apps/web section look (#12474 AC-3)", () => {
110
+ it("answers the worked-out sections of a library-look record, which holds no settings of its own", async () => {
111
+ mockGet.mockResolvedValue(
112
+ answer({ version: 3, record: { version: "1", from: { look: "minimalism", version: "1" } }, settings: settings(S), look: LOOK }),
113
+ );
114
+ const reader = load();
115
+ expect(reader).toBeDefined();
116
+ expect(await reader!()).toEqual(S);
117
+ });
118
+
119
+ it("answers the worked-out sections, not the record's, for an own look", async () => {
120
+ mockGet.mockResolvedValue(
121
+ answer({ version: 1, record: { version: "1", from: null, settings: settings(R) }, settings: settings(S), look: null }),
122
+ );
123
+ expect(await load()!()).toEqual(S);
124
+ });
125
+
126
+ it.each([
127
+ ["no design", null],
128
+ ["worked-out settings of null", { version: 1, record: { version: "1", from: null }, settings: null, look: null }],
129
+ ["settings with no sections", { version: 1, record: { version: "1", from: null }, settings: settings(), look: null }],
130
+ ])("answers undefined with %s", async (_label, design) => {
131
+ mockGet.mockResolvedValue(answer(design));
132
+ expect(await load()!()).toBeUndefined();
133
+ });
134
+
135
+ it("registers nothing, and reads nothing, on a site that is not hub-connected", () => {
136
+ for (const k of ENV_KEYS) delete process.env[k];
137
+ expect(load()).toBeUndefined();
138
+ expect(mockSetSectionLookReader).not.toHaveBeenCalled();
139
+ expect(mockGet).not.toHaveBeenCalled();
140
+ });
141
+
142
+ it("reads the hub on each call, so a changed look reaches the next render", async () => {
143
+ const reader = load()!;
144
+ expect(mockGet).not.toHaveBeenCalled();
145
+ mockGet.mockResolvedValueOnce(answer({ version: 1, record: { version: "1", from: null }, settings: settings(S), look: null }));
146
+ mockGet.mockResolvedValueOnce(answer({ version: 2, record: { version: "1", from: null }, settings: settings(R), look: null }));
147
+ expect(await reader()).toEqual(S);
148
+ expect(await reader()).toEqual(R);
149
+ });
150
+ });