@astryxdesign/cli 0.6.5-canary.c3016f8 → 0.6.5-canary.c8d8a1d

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 (167) hide show
  1. package/README.md +14 -13
  2. package/api/build/_adapter.d.mts +36 -2
  3. package/api/build/_adapter.mjs +41 -10
  4. package/api/build/build.doc.mjs +2 -2
  5. package/api/build/build.test.mjs +38 -2
  6. package/api/build/kit/kit.mjs +65 -21
  7. package/api/build/kit/rank.d.mts +24 -8
  8. package/api/build/kit/rank.mjs +277 -97
  9. package/api/build/kit/rank.test.mjs +231 -48
  10. package/api/docs/docs.test.mjs +279 -0
  11. package/api/docs/integration-tree.test.mjs +572 -0
  12. package/api/docs/integrationDocs.test.mjs +336 -0
  13. package/api/error.d.mts +22 -0
  14. package/api/error.mjs +42 -0
  15. package/api/integration/add-contribution.d.mts +2 -1
  16. package/api/integration/add-contribution.mjs +7 -3
  17. package/api/integration/add-contribution.test.mjs +3 -3
  18. package/api/integration/add-theme.mjs +246 -24
  19. package/api/integration/add-theme.test.mjs +214 -1
  20. package/api/integration/authoring-checks.mjs +10 -7
  21. package/api/integration/authoring-checks.type.d.mts +8 -0
  22. package/api/integration/authoring-checks.type.mjs +7 -3
  23. package/api/integration/integration-authoring.type.d.mts +4 -1
  24. package/api/integration/integration-authoring.type.mjs +6 -1
  25. package/api/integration/integrationAdd.doc.mjs +6 -0
  26. package/api/integration/integrationAddTheme.doc.mjs +10 -0
  27. package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
  28. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  29. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
  30. package/api/integration/pack-check.mjs +12 -3
  31. package/api/integration/pack-check.test.mjs +52 -3
  32. package/api/integration/validate-integration.d.mts +4 -2
  33. package/api/integration/validate-integration.mjs +7 -2
  34. package/api/integration/validate-integration.test.mjs +55 -0
  35. package/api/integration/validate-integration.type.d.mts +5 -0
  36. package/api/integration/validate-integration.type.mjs +5 -1
  37. package/api/integration/validateIntegration.doc.mjs +1 -1
  38. package/api/layout/expand/expand.mjs +12 -7
  39. package/api/layout/expand/expand.receipt.test.mjs +74 -0
  40. package/api/layout/layout.type.d.mts +1 -0
  41. package/api/layout/layout.type.mjs +1 -0
  42. package/api/layout/layoutExpand.doc.mjs +1 -1
  43. package/api/search/search.d.mts +24 -0
  44. package/api/search/search.mjs +71 -1
  45. package/api/search/search.test.mjs +710 -0
  46. package/api/swizzle/copy/copy.mjs +66 -3
  47. package/api/swizzle/swizzle.doc.mjs +4 -0
  48. package/api/template/copy/copy.mjs +14 -8
  49. package/api/template/copy/copy.receipt.test.mjs +77 -0
  50. package/api/template/show/show.mjs +15 -4
  51. package/api/template/show/show.test.mjs +76 -0
  52. package/api/template/template-integration.test.mjs +14 -0
  53. package/api/template/template.d.mts +1 -1
  54. package/api/template/template.doc.mjs +6 -2
  55. package/api/template/template.mjs +1 -0
  56. package/api/template/template.type.d.mts +2 -0
  57. package/api/template/template.type.mjs +2 -0
  58. package/api/theme/build/build.d.mts +24 -0
  59. package/api/theme/build/build.mjs +235 -8
  60. package/api/theme/build/build.project-core.test.mjs +165 -0
  61. package/api/upgrade/run/run.mjs +20 -3
  62. package/api/upgrade/run/run.test.mjs +45 -1
  63. package/api/upgrade/upgrade.doc.mjs +1 -1
  64. package/api/upgrade/upgrade.type.d.mts +1 -0
  65. package/api/upgrade/upgrade.type.mjs +1 -0
  66. package/assets/docs/icons.doc.mjs +1 -0
  67. package/assets/docs/theme.doc.mjs +1 -1
  68. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  69. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  70. package/assets/docs/tree/checks.doc.mjs +1 -1
  71. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  72. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  73. package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
  74. package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
  75. package/assets/docs/tree/versioning.doc.mjs +7 -6
  76. package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
  77. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
  78. package/assets/templates/pages/blank/template.doc.mjs +3 -1
  79. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
  80. package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
  81. package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
  82. package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
  83. package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
  84. package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
  85. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
  86. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
  87. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
  88. package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
  89. package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
  90. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
  91. package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
  92. package/assets/templates/pages/documentation/template.doc.mjs +10 -1
  93. package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
  94. package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
  95. package/assets/templates/pages/editor/template.doc.mjs +9 -1
  96. package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
  97. package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
  98. package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
  99. package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
  100. package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
  101. package/assets/templates/pages/ide/template.doc.mjs +9 -1
  102. package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
  103. package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
  104. package/assets/templates/pages/library/template.doc.mjs +15 -1
  105. package/assets/templates/pages/login/template.doc.mjs +10 -1
  106. package/assets/templates/pages/login-card/template.doc.mjs +11 -1
  107. package/assets/templates/pages/login-split/template.doc.mjs +10 -1
  108. package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
  109. package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
  110. package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
  111. package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
  112. package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
  113. package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
  114. package/assets/templates/pages/settings/template.doc.mjs +3 -1
  115. package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
  116. package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
  117. package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
  118. package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
  119. package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
  120. package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
  121. package/assets/templates/pages/table/template.doc.mjs +11 -1
  122. package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
  123. package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
  124. package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
  125. package/assets/templates/pages/table-page/template.doc.mjs +20 -1
  126. package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
  127. package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
  128. package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
  129. package/assets/templates/themes/butter/icons.tsx +2 -0
  130. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  131. package/assets/templates/themes/gothic/icons.tsx +2 -0
  132. package/assets/templates/themes/matcha/icons.tsx +2 -0
  133. package/assets/templates/themes/neutral/icons.tsx +2 -0
  134. package/assets/templates/themes/stone/icons.tsx +2 -0
  135. package/assets/templates/themes/y2k/icons.tsx +2 -0
  136. package/authoring/doctypes/template/parse.d.mts +2 -0
  137. package/authoring/doctypes/template/parse.mjs +1 -0
  138. package/authoring/doctypes/template/parse.test.mjs +21 -0
  139. package/authoring/doctypes/template/template.doc.mjs +6 -0
  140. package/authoring/doctypes/template/type.ts +10 -0
  141. package/clients/cli/commands/docs.test.mjs +383 -0
  142. package/clients/cli/commands/doctor.mjs +4 -4
  143. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  144. package/clients/cli/commands/integration-authoring.test.mjs +12 -2
  145. package/clients/cli/commands/integration.mjs +3 -1
  146. package/clients/cli/commands/layout-expand.doc.mjs +3 -1
  147. package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
  148. package/clients/cli/commands/layout.mjs +16 -0
  149. package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
  150. package/clients/cli/commands/template.mjs +19 -5
  151. package/clients/cli/commands/template.show-media.test.mjs +62 -0
  152. package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
  153. package/clients/cli/commands/write-failure.test.mjs +175 -0
  154. package/clients/cli/lib/manifest.mjs +44 -165
  155. package/clients/cli/lib/manifest.test.mjs +98 -7
  156. package/foundation/agent-docs/agent-docs.test.mjs +1160 -0
  157. package/foundation/discovery/template-adapter.d.mts +14 -0
  158. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
  159. package/foundation/discovery/template-adapter.mjs +21 -1
  160. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  161. package/foundation/doc-compiler/tree.test.mjs +649 -0
  162. package/foundation/integrations/cli-requirement.d.mts +57 -13
  163. package/foundation/integrations/cli-requirement.mjs +84 -22
  164. package/foundation/integrations/cli-requirement.test.mjs +135 -8
  165. package/foundation/response/response-types.doc.d.mts +5 -5
  166. package/foundation/response/response-types.doc.mjs +13 -13
  167. package/package.json +9 -9
@@ -2,14 +2,15 @@
2
2
 
3
3
  /**
4
4
  * @file Tests for build's page ranker: long ideas, head nouns, family bases,
5
- * rare-word weighting, and family words taken from the templates themselves.
5
+ * rare-word weighting, keywords, family words taken from the templates
6
+ * themselves, and parts told from pages by the system's own components.
6
7
  */
7
8
 
8
9
  import {describe, it, expect} from 'vitest';
9
10
  import * as path from 'node:path';
10
11
  import {fileURLToPath} from 'node:url';
11
- import {pickStart, rankPages} from './rank.mjs';
12
- import {loadPageTemplates} from '../_adapter.mjs';
12
+ import {ideaKind, pickStart, rankPages} from './rank.mjs';
13
+ import {loadComponents, loadPageTemplates} from '../_adapter.mjs';
13
14
 
14
15
  // api/build/kit/ -> up 5 = repo root (has packages/core and the templates).
15
16
  const REPO = path.resolve(
@@ -17,14 +18,24 @@ const REPO = path.resolve(
17
18
  '../../../../..',
18
19
  );
19
20
 
20
- /** @param {string} name @param {string} category @param {string} description */
21
- const page = (name, category, description) => ({
21
+ /**
22
+ * @param {string} name
23
+ * @param {string} category
24
+ * @param {string} description
25
+ * @param {string[]} [keywords]
26
+ */
27
+ const page = (name, category, description, keywords = []) => ({
22
28
  name,
23
29
  displayName: name,
24
30
  category,
25
31
  description,
32
+ keywords,
33
+ command: `astryx template ${name} --type page`,
26
34
  });
27
35
 
36
+ /** @param {string} name @param {string[]} [keywords] */
37
+ const component = (name, keywords = []) => ({name, keywords});
38
+
28
39
  describe('rankPages on the shipped page templates', () => {
29
40
  /** @param {string} query */
30
41
  const start = async query =>
@@ -49,6 +60,19 @@ describe('rankPages on the shipped page templates', () => {
49
60
  );
50
61
  });
51
62
 
63
+ it('keeps the family base when a variant shares one incidental word', async () => {
64
+ // "comparison" and "cohort" name dashboard variants, but here each is one
65
+ // small part of a general dashboard.
66
+ expect(
67
+ await start(
68
+ 'support dashboard with ticket volume charts and a small comparison note',
69
+ ),
70
+ ).toBe('dashboard');
71
+ expect(
72
+ await start('sales dashboard with a cohort filter and weekly charts'),
73
+ ).toBe('dashboard');
74
+ });
75
+
52
76
  it('lets the head noun decide between families', async () => {
53
77
  // Both ideas mention a table and summary numbers; the head says which
54
78
  // page it is.
@@ -64,6 +88,14 @@ describe('rankPages on the shipped page templates', () => {
64
88
  ).toMatch(/^table-/);
65
89
  });
66
90
 
91
+ it('keeps a variant that leads when its family base cannot start alone', async () => {
92
+ // The dashboard base matches only the family word here; the funnel
93
+ // dashboard matches the idea.
94
+ expect(await start('a funnel for a dashboard')).toBe(
95
+ 'dashboard-cohort-funnel',
96
+ );
97
+ });
98
+
67
99
  it('does not start from one rare word', async () => {
68
100
  // "board" is the kanban board's own word; a game board is not a kanban.
69
101
  expect(
@@ -75,11 +107,10 @@ describe('rankPages on the shipped page templates', () => {
75
107
  describe('rankPages on any catalog', () => {
76
108
  it('ranks only the templates it is given', () => {
77
109
  const ranked = rankPages('dashboard', [
78
- page(
110
+ page('dashboard', 'Dashboard - Analytics', 'Tiles, charts, tables.', [
79
111
  'dashboard',
80
- 'Dashboard - Analytics',
81
- 'Tiles, charts, tables. Dashboard, metrics.',
82
- ),
112
+ 'metrics',
113
+ ]),
83
114
  ]);
84
115
  expect(ranked.map(r => r.name)).toEqual(['dashboard']);
85
116
  });
@@ -88,17 +119,14 @@ describe('rankPages on any catalog', () => {
88
119
  // An integration's family: its word is in two of its ids, so an idea
89
120
  // naming it picks the family, and its base template leads it.
90
121
  const catalog = [
91
- page(
122
+ page('dashboard', 'Dashboard - Analytics', 'Tiles, charts, tables.', [
92
123
  'dashboard',
93
- 'Dashboard - Analytics',
94
- 'Tiles, charts, tables. Dashboard, metrics.',
95
- ),
96
- page('widget', 'Widget - Basic', 'One compact card. Widget, tile.'),
97
- page(
98
- 'widget-grid',
99
- 'Widget - Grid',
100
- 'Many compact cards in a grid. Widget wall.',
101
- ),
124
+ 'metrics',
125
+ ]),
126
+ page('widget', 'Widget - Basic', 'One compact card.', ['widget', 'tile']),
127
+ page('widget-grid', 'Widget - Grid', 'Many compact cards in a grid.', [
128
+ 'widget wall',
129
+ ]),
102
130
  ];
103
131
  const ranked = rankPages('weather widget with charts', catalog);
104
132
  expect(ranked[0].name).toBe('widget');
@@ -106,15 +134,41 @@ describe('rankPages on any catalog', () => {
106
134
  expect(pickStart(ranked)?.name).toBe('widget');
107
135
  });
108
136
 
137
+ it("counts a template's keywords above words in its description", () => {
138
+ // Both mention uptime; only one names it as an idea it serves.
139
+ const catalog = [
140
+ page('ops', 'Dashboard - Ops', 'Uptime strips beside alert rows.'),
141
+ page('health', 'Dashboard - Health', 'Status tiles over time charts.', [
142
+ 'uptime',
143
+ ]),
144
+ ];
145
+ expect(rankPages('uptime overview', catalog)[0].name).toBe('health');
146
+ });
147
+
148
+ it("lets a variant displace its family's base only with two words of its own", () => {
149
+ const catalog = [
150
+ page('widget', 'Widget - Basic', 'One compact card.', ['widget']),
151
+ page('widget-weather', 'Widget - Weather', 'A forecast card.', [
152
+ 'weather',
153
+ 'forecast',
154
+ 'radar',
155
+ ]),
156
+ ];
157
+ // One word of the variant's own: still the family's base.
158
+ expect(rankPages('weather widget', catalog)[0].name).toBe('widget');
159
+ // Two: the variant.
160
+ expect(rankPages('weather widget with radar', catalog)[0].name).toBe(
161
+ 'widget-weather',
162
+ );
163
+ });
164
+
109
165
  it('weighs a word by how rare it is among page templates', () => {
110
166
  const catalog = [
111
- page('alpha', 'Dashboard - Alpha', 'Status tiles. Status overview.'),
112
- page('beta', 'Dashboard - Beta', 'Status rows. Status list.'),
113
- page(
114
- 'gamma',
115
- 'Dashboard - Gamma',
116
- 'Funnel of stages. Funnel conversion.',
117
- ),
167
+ page('alpha', 'Dashboard - Alpha', 'Status tiles.', ['status overview']),
168
+ page('beta', 'Dashboard - Beta', 'Status rows.', ['status list']),
169
+ page('gamma', 'Dashboard - Gamma', 'Funnel of stages.', [
170
+ 'funnel conversion',
171
+ ]),
118
172
  ];
119
173
  // "status" is on two templates, "funnel" on one: the rare word wins.
120
174
  const ranked = rankPages('status funnel', catalog);
@@ -127,22 +181,24 @@ describe('rankPages structure signals', () => {
127
181
  page(
128
182
  'dialog-panel',
129
183
  'Settings - Dialog',
130
- 'Preferences inside a modal container. Settings, or modal dialog.',
131
- ),
132
- page(
133
- 'tree-table',
134
- 'Table - Tree',
135
- 'Nested rows under parents. Tree, nested rows, file browser.',
136
- ),
137
- page(
138
- 'item-detail',
139
- 'Content - Item Detail',
140
- 'One item with its media. Product, listing, or item detail.',
184
+ 'Preferences inside a modal container.',
185
+ ['settings', 'modal dialog'],
141
186
  ),
187
+ page('tree-table', 'Table - Tree', 'Nested rows under parents.', [
188
+ 'tree',
189
+ 'nested rows',
190
+ 'file browser',
191
+ ]),
192
+ page('item-detail', 'Content - Item Detail', 'One item with its media.', [
193
+ 'product',
194
+ 'listing',
195
+ 'item detail',
196
+ ]),
142
197
  page(
143
198
  'docs-catalog',
144
199
  'Content - Documentation Catalog',
145
- 'A grid of category cards. Documentation, docs, or API index.',
200
+ 'A grid of category cards.',
201
+ ['documentation', 'docs', 'api index'],
146
202
  ),
147
203
  ];
148
204
 
@@ -179,18 +235,145 @@ describe('rankPages structure signals', () => {
179
235
  it('does not treat a synonym as a family name', () => {
180
236
  // "landing" is a synonym of "hero" in search, not a family word here.
181
237
  const heroes = [
182
- page(
183
- 'hero-centered',
184
- 'Gallery - Hero',
185
- 'A centered hero. Hero, banner, or landing.',
186
- ),
187
- page(
188
- 'hero-split',
189
- 'Gallery - Hero Split',
190
- 'A split hero. Hero or splash.',
191
- ),
238
+ page('hero-centered', 'Gallery - Hero', 'A centered hero.', [
239
+ 'hero',
240
+ 'banner',
241
+ 'landing',
242
+ ]),
243
+ page('hero-split', 'Gallery - Hero Split', 'A split hero.', [
244
+ 'hero',
245
+ 'splash',
246
+ ]),
192
247
  ];
193
248
  const ranked = rankPages('internal landing page', heroes);
194
249
  expect(ranked.every(r => !r.familyNamed)).toBe(true);
195
250
  });
196
251
  });
252
+
253
+ describe('ideaKind: a part of a page, told by the components the system ships', () => {
254
+ const pages = [
255
+ page('table', 'Table - Basic', 'Rows of records.'),
256
+ page('table-filter', 'Table - Filtering', 'Rows narrowed by filters.'),
257
+ page('settings', 'Settings', 'Grouped preferences.'),
258
+ ];
259
+ const components = [
260
+ component('DateRangeInput', ['date picker']),
261
+ component('Tooltip'),
262
+ component('Calendar'),
263
+ component('Table'),
264
+ component('Dialog', ['modal']),
265
+ ];
266
+ /** @param {string} idea @param {object[]} [using] */
267
+ const kind = (idea, using = components) => ideaKind(idea, pages, using);
268
+
269
+ it('takes a part from a component name or keyword at the head', () => {
270
+ expect(kind('a date range input')).toBe('part');
271
+ expect(kind('a date picker with presets')).toBe('part');
272
+ expect(kind('a tooltip')).toBe('part');
273
+ });
274
+
275
+ it('takes a page word or a family word at the head as a page', () => {
276
+ expect(kind('a calendar')).toBe('part');
277
+ expect(kind('a team calendar page')).toBe('page');
278
+ // Table is a component, but table is also a family of page templates.
279
+ expect(kind('a data table with filters')).toBe('page');
280
+ });
281
+
282
+ it("reads parts from the project's own components", () => {
283
+ // An integration's component joins the vocabulary by existing.
284
+ expect(kind('a revenue gauge')).toBe('page');
285
+ expect(
286
+ kind('a revenue gauge', [...components, component('AcmeGauge')]),
287
+ ).toBe('part');
288
+ });
289
+
290
+ it("takes an idea that lists a page's worth of pieces as a page", () => {
291
+ expect(kind('a calendar with a tooltip')).toBe('part');
292
+ expect(kind('a calendar, a tooltip, and a date range input')).toBe('page');
293
+ });
294
+
295
+ it('takes the frame of a container phrase as the frame, not the head', () => {
296
+ expect(kind('a dialog')).toBe('part');
297
+ expect(kind('saved drafts in a modal')).toBe('page');
298
+ });
299
+
300
+ it('takes a change to an existing page or part as an edit', () => {
301
+ expect(kind('add a sort toggle to the existing reports table')).toBe(
302
+ 'edit',
303
+ );
304
+ expect(kind('reuse the existing tooltip on the chart')).toBe('edit');
305
+ });
306
+
307
+ it('does not take "existing" that names no page or part as an edit', () => {
308
+ expect(kind('a new settings page inspired by the existing one')).toBe(
309
+ 'page',
310
+ );
311
+ expect(kind('show existing users in a settings page')).toBe('page');
312
+ });
313
+
314
+ it('does not take a request for a new page as an edit', () => {
315
+ expect(
316
+ kind('a new settings page based on the existing settings page'),
317
+ ).toBe('page');
318
+ expect(kind('clone the existing table as a new page')).toBe('page');
319
+ // "A new column" asks for a part, so the change stays a change.
320
+ expect(kind('add a new column to the existing reports table')).toBe('edit');
321
+ });
322
+ });
323
+
324
+ describe('pickStart on parts and edits (spec:AST-048/FR3)', () => {
325
+ const shipped = Promise.all([loadPageTemplates(REPO), loadComponents(REPO)]);
326
+ /** @param {string} query */
327
+ const start = async query => {
328
+ const [catalog, components] = await shipped;
329
+ const kind = ideaKind(query, catalog, components);
330
+ return pickStart(rankPages(query, catalog), kind)?.name ?? null;
331
+ };
332
+
333
+ it('starts a part from the page it names, else from the app shell', async () => {
334
+ expect(await start('an empty state for a settings page')).toBe('settings');
335
+ expect(await start('a date range picker')).toBeNull();
336
+ expect(await start('compact status pill with a tooltip')).toBeNull();
337
+ });
338
+
339
+ it('starts an edit of an existing page or part from the app shell', async () => {
340
+ for (const idea of [
341
+ 'add a sparkline column to the existing incidents table',
342
+ 'add a sort toggle to the existing reports dashboard',
343
+ 'swap the existing banner for a toast',
344
+ ]) {
345
+ expect(await start(idea)).toBeNull();
346
+ }
347
+ });
348
+
349
+ it('starts a new page that mentions something existing from its template', async () => {
350
+ expect(await start('a new dashboard inspired by the existing one')).toBe(
351
+ 'dashboard',
352
+ );
353
+ expect(await start('show existing users in a table page')).toMatch(
354
+ /^table/,
355
+ );
356
+ });
357
+
358
+ it('starts a new page that names an existing one from its template', async () => {
359
+ for (const idea of [
360
+ 'a new dashboard based on the existing dashboard',
361
+ 'a new dashboard like the existing dashboard',
362
+ 'clone the existing dashboard as a new page',
363
+ ]) {
364
+ expect(await start(idea)).toBe('dashboard');
365
+ }
366
+ });
367
+
368
+ it('reads a bare "existing" phrase that names a page as the builder\'s page', async () => {
369
+ expect(
370
+ await start('existing reports dashboard with a date filter'),
371
+ ).toBeNull();
372
+ });
373
+
374
+ it('still starts a whole page from its template', async () => {
375
+ expect(
376
+ await start('saved drafts in a modal with resume and delete row actions'),
377
+ ).toBe('settings-dialog');
378
+ });
379
+ });
@@ -0,0 +1,279 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Dispatcher-level tests for docs() — the argument-shape routing that
5
+ * sits above the list/detail/section leaves. The leaves have their own tests;
6
+ * this pins the router: docs() -> list, docs(topic) -> detail,
7
+ * docs(topic, section) -> section, plus the unknown-topic/section error codes.
8
+ * Runs against the real CLI-bundled docs (no cwd/project needed).
9
+ */
10
+
11
+ import {describe, it, expect} from 'vitest';
12
+ import {docs} from './docs.mjs';
13
+ import {AstryxError} from '../error.mjs';
14
+
15
+ const SLOW = 30_000;
16
+
17
+ /**
18
+ * The first guide a namespace places, read from the tree rather than named,
19
+ * so a restructure of the guides does not break the reads under test.
20
+ * @param {any} node the data of a docs.node read
21
+ * @returns {string}
22
+ */
23
+ function placedGuide(node) {
24
+ const guide = node.slots
25
+ .flatMap((/** @type {any} */ slot) => slot.children)
26
+ .find((/** @type {any} */ child) => child.kind === 'generic');
27
+ if (guide == null) throw new Error(`${node.route} places no guide`);
28
+ return guide.route;
29
+ }
30
+
31
+ describe('docs() dispatcher routing', () => {
32
+ it('no topic -> docs.list', async () => {
33
+ const r = await docs();
34
+ expect(r.type).toBe('docs.list');
35
+ expect(Array.isArray(r.data)).toBe(true);
36
+ expect(r.data.length).toBeGreaterThan(0);
37
+ }, SLOW);
38
+
39
+ it('empty topic -> docs.list (falsy topic routes to list)', async () => {
40
+ expect((await docs('')).type).toBe('docs.list');
41
+ }, SLOW);
42
+
43
+ it('topic only -> docs.detail, the whole doc', async () => {
44
+ const {data} = await docs();
45
+ expect((await docs(data[0].topic)).type).toBe('docs.detail');
46
+ }, SLOW);
47
+
48
+ it('topic + index -> docs.index', async () => {
49
+ const {data} = await docs();
50
+ const r = await docs(data[0].topic, undefined, {index: true});
51
+ expect(r.type).toBe('docs.index');
52
+ }, SLOW);
53
+
54
+ it('reads a shortened section by its old key, which its title still derives', async () => {
55
+ const r = await docs(
56
+ 'styling',
57
+ 'stylex-build-setup-required-for-swizzled-components',
58
+ );
59
+ expect(r.type).toBe('docs.detail.section');
60
+ expect(r.data).toMatchObject({id: 'stylex-setup'});
61
+ }, SLOW);
62
+
63
+ it('topic + section -> docs.detail.section', async () => {
64
+ const {data} = await docs();
65
+ let routed = null;
66
+ for (const {topic} of data) {
67
+ const detail = await docs(topic);
68
+ const sections = detail.data.sections;
69
+ if (Array.isArray(sections) && sections.length > 0) {
70
+ routed = await docs(topic, sections[0].title);
71
+ break;
72
+ }
73
+ }
74
+ expect(routed).not.toBeNull();
75
+ expect(routed.type).toBe('docs.detail.section');
76
+ }, SLOW);
77
+
78
+ it('unknown topic -> ERR_UNKNOWN_TOPIC', async () => {
79
+ await expect(docs('zzz-not-a-real-topic')).rejects.toBeInstanceOf(AstryxError);
80
+ await expect(docs('zzz-not-a-real-topic')).rejects.toMatchObject({
81
+ code: 'ERR_UNKNOWN_TOPIC',
82
+ });
83
+ }, SLOW);
84
+
85
+ it('known topic + unknown section -> ERR_UNKNOWN_SECTION', async () => {
86
+ const {data} = await docs();
87
+ const topic = data[0].topic;
88
+ await expect(docs(topic, 'zzz-not-a-real-section')).rejects.toMatchObject({
89
+ code: 'ERR_UNKNOWN_SECTION',
90
+ });
91
+ }, SLOW);
92
+
93
+ it("lists the docs tree's namespaces in meta, so every data entry reads as a topic", async () => {
94
+ const res = await docs();
95
+ expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'unorganized']);
96
+ for (const entry of res.data) {
97
+ expect((await docs(entry.topic)).type).toBe('docs.detail');
98
+ }
99
+ }, SLOW);
100
+
101
+ it('opens a route typed in another case', async () => {
102
+ const r = await docs('CLI/API');
103
+ expect(r.type).toBe('docs.node');
104
+ expect(r.data).toMatchObject({route: 'cli/api', links: {up: 'astryx docs cli'}});
105
+ }, SLOW);
106
+
107
+ it('a section of a typed doc -> ERR_UNKNOWN_SECTION, suggesting the doc itself', async () => {
108
+ const err = await docs('cli/api/functions/search', 'x').catch(e => e);
109
+ expect(err.code).toBe('ERR_UNKNOWN_SECTION');
110
+ expect(err.message).toContain('astryx docs cli/api/functions/search');
111
+ expect(err.suggestions.map(s => s.name)).toEqual(['cli/api/functions/search']);
112
+ }, SLOW);
113
+
114
+ it('a namespace route -> docs.node, one level of children', async () => {
115
+ const r = await docs('cli/api');
116
+ expect(r.type).toBe('docs.node');
117
+ expect(r.data).toMatchObject({
118
+ id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/namespace/api',
119
+ route: 'cli/api',
120
+ kind: 'namespace',
121
+ package: '@astryxdesign/cli',
122
+ breadcrumb: [{route: 'cli', title: 'Astryx CLI'}],
123
+ content: [],
124
+ });
125
+ expect(r.data.slots.flatMap(slot => slot.children.map(c => c.route))).toEqual([
126
+ 'cli/api/functions',
127
+ 'cli/api/schemas',
128
+ 'cli/api/enums',
129
+ ]);
130
+ }, SLOW);
131
+
132
+ it('a typed doc route -> docs.node with its content', async () => {
133
+ const r = await docs('cli/api/functions/search');
134
+ expect(r.type).toBe('docs.node');
135
+ expect(r.data).toMatchObject({
136
+ id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/function/search',
137
+ kind: 'function',
138
+ title: 'search()',
139
+ slots: [],
140
+ });
141
+ expect(r.data.breadcrumb.map(link => link.route)).toEqual([
142
+ 'cli',
143
+ 'cli/api',
144
+ 'cli/api/functions',
145
+ ]);
146
+ expect(JSON.stringify(r.data.content)).toContain(
147
+ '`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
148
+ );
149
+ }, SLOW);
150
+
151
+ it('a guide the tree places reads like a topic: the whole doc, its index, a section', async () => {
152
+ // cli/integrations is a namespace of short guides; each guide reads like a topic.
153
+ const integrations = await docs('cli/integrations');
154
+ expect(integrations.type).toBe('docs.node');
155
+ const guide = placedGuide(integrations.data);
156
+ expect((await docs(guide)).type).toBe('docs.detail');
157
+ const index = await docs(guide, undefined, {index: true});
158
+ expect(index).toMatchObject({type: 'docs.index', data: {name: guide}});
159
+ expect(index.data.sections.length).toBeGreaterThan(1);
160
+ expect((await docs(guide, index.data.sections[0].id)).type).toBe(
161
+ 'docs.detail.section',
162
+ );
163
+ }, SLOW);
164
+
165
+ it('every read carries its moves (spec:AST-047)', async () => {
166
+ const root = (await docs('cli')).data;
167
+ expect(root.links).toEqual({up: 'astryx docs'});
168
+ const leaf = (await docs('cli/api/functions/search')).data;
169
+ expect(leaf.links.up).toBe('astryx docs cli/api/functions');
170
+ expect(leaf.links.previous).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
171
+ expect(leaf.links.next).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
172
+ const integrations = (await docs('cli/integrations')).data;
173
+ const guide = placedGuide(integrations);
174
+ const siblings = integrations.slots
175
+ .find(slot => slot.children.some(child => child.route === guide))
176
+ .children.map(child => child.route);
177
+ const at = siblings.indexOf(guide);
178
+ const index = await docs(guide, undefined, {index: true});
179
+ // A guide moves across its namespace's slot, as any tree node does.
180
+ expect(index.data.links).toEqual({
181
+ up: 'astryx docs cli/integrations',
182
+ ...(at > 0 ? {previous: `astryx docs ${siblings[at - 1]}`} : {}),
183
+ ...(at < siblings.length - 1
184
+ ? {next: `astryx docs ${siblings[at + 1]}`}
185
+ : {}),
186
+ });
187
+ const first = (await docs(guide, index.data.sections[0].id)).data;
188
+ expect(first.links).toEqual({
189
+ up: `astryx docs ${guide} --index`,
190
+ next: `astryx docs ${guide} ${index.data.sections[1].id}`,
191
+ });
192
+ const last = index.data.sections.at(-1).id;
193
+ const end = (await docs(guide, last)).data;
194
+ expect(end.links.next).toBeUndefined();
195
+ expect(end.links.previous).toBe(
196
+ `astryx docs ${guide} ${index.data.sections.at(-2).id}`,
197
+ );
198
+ // A flat topic's home is the Unorganized level, and it moves across it.
199
+ const flat = (await docs('principles')).data.links;
200
+ expect(flat.up).toBe('astryx docs unorganized');
201
+ expect(flat.previous).toMatch(/^astryx docs [a-z-]+$/);
202
+ expect(flat.next).toMatch(/^astryx docs [a-z-]+$/);
203
+ const home = (await docs('unorganized')).data;
204
+ expect(home).toMatchObject({id: null, kind: 'namespace', links: {up: 'astryx docs'}});
205
+ expect(home.slots[0].children.map(child => child.route)).toEqual(
206
+ (await docs()).data.map(entry => entry.topic),
207
+ );
208
+ }, SLOW);
209
+
210
+ it('names a node by its doc identity; a generated level has id null', async () => {
211
+ const level = (await docs('cli/api/functions')).data;
212
+ expect(level).toHaveProperty('id', null);
213
+ expect(level.route).toBe('cli/api/functions');
214
+ }, SLOW);
215
+
216
+ it("offers a typed doc's related docs as moves", async () => {
217
+ const fn = (await docs('cli/api/functions/search')).data;
218
+ expect(fn.links.related).toContain('astryx docs cli/commands/search');
219
+ const cmd = (await docs('cli/commands/search')).data;
220
+ expect(cmd.links.related).toContain('astryx docs cli/api/functions/search');
221
+ }, SLOW);
222
+
223
+ it('a topic read returns the whole doc; index returns its sections', async () => {
224
+ expect((await docs('principles')).type).toBe('docs.detail');
225
+ const index = await docs('principles', undefined, {index: true});
226
+ expect(index.type).toBe('docs.index');
227
+ expect(index.data.sections.length).toBeGreaterThan(1);
228
+ expect((await docs('principles', undefined, {dense: true})).type).toBe(
229
+ 'docs.detail',
230
+ );
231
+ }, SLOW);
232
+
233
+ it("the guide's old flat name is gone, and its error names the new route", async () => {
234
+ await expect(docs('cli-integrations')).rejects.toMatchObject({
235
+ code: 'ERR_UNKNOWN_TOPIC',
236
+ suggestions: [expect.objectContaining({name: 'cli/integrations'})],
237
+ });
238
+ expect((await docs()).data.map(entry => entry.topic)).not.toContain(
239
+ 'cli-integrations',
240
+ );
241
+ }, SLOW);
242
+
243
+ it('a section of a namespace -> ERR_UNKNOWN_SECTION, naming its children', async () => {
244
+ const err = await docs('cli', 'commands').catch(e => e);
245
+ expect(err).toBeInstanceOf(AstryxError);
246
+ expect(err.code).toBe('ERR_UNKNOWN_SECTION');
247
+ // It names the namespace's children, in the order its slots list them.
248
+ const cli = (await docs('cli')).data;
249
+ expect(err.suggestions.map(s => s.name)).toEqual(
250
+ cli.slots.flatMap(slot => slot.children.map(child => child.route)),
251
+ );
252
+ expect(err.suggestions.map(s => s.name)).toContain('cli/commands');
253
+ }, SLOW);
254
+
255
+ it('an unknown route suggests the children of the deepest namespace it reaches', async () => {
256
+ const err = await docs('cli/api/functions/serch').catch(e => e);
257
+ expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
258
+ expect(err.suggestions.map(s => s.name)).toContain('cli/api/functions/search');
259
+ expect(err.suggestions.every(s => s.name.startsWith('cli/api/functions/'))).toBe(true);
260
+ }, SLOW);
261
+
262
+ it('non-string topic -> ERR_UNKNOWN_TOPIC (not a raw TypeError)', async () => {
263
+ for (const bad of [123, {}, ['tokens'], true]) {
264
+ const err = await docs(/** @type {any} */ (bad)).catch(e => e);
265
+ expect(err).toBeInstanceOf(AstryxError);
266
+ expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
267
+ }
268
+ }, SLOW);
269
+
270
+ it('non-string section -> ERR_UNKNOWN_SECTION (not a raw TypeError)', async () => {
271
+ const {data} = await docs();
272
+ const topic = data[0].topic;
273
+ for (const bad of [456, {}, ['x']]) {
274
+ const err = await docs(topic, /** @type {any} */ (bad)).catch(e => e);
275
+ expect(err).toBeInstanceOf(AstryxError);
276
+ expect(err.code).toBe('ERR_UNKNOWN_SECTION');
277
+ }
278
+ }, SLOW);
279
+ });