@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
@@ -0,0 +1,336 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file End-to-end tests for integration-contributed doc topics: a scaffolded
5
+ * consumer project whose configured integration ships a `docs` root, read back
6
+ * through the public surfaces — `docs()`, `search()`, and the agent-docs block.
7
+ *
8
+ * The unit-level rules (what a docs root contributes, what the catalog does
9
+ * with `replaces`/`extends`) are covered in
10
+ * foundation/discovery/docs-discovery.test.mjs. What is pinned here is that a
11
+ * contributed topic is indistinguishable from a built-in one at the surfaces
12
+ * an agent actually reads.
13
+ *
14
+ * Fixtures live under a repo-local temp dir, not /tmp, because Vite refuses to
15
+ * dynamically import a module from outside the project root.
16
+ */
17
+
18
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
19
+ import * as fs from 'node:fs';
20
+ import * as path from 'node:path';
21
+ import {docs} from './docs.mjs';
22
+ import {search} from '../search/search.mjs';
23
+ import {loadDocsCatalog} from './_adapter.mjs';
24
+ import {AstryxError} from '../error.mjs';
25
+
26
+ const SLOW = 30_000;
27
+
28
+ let tmpDir;
29
+
30
+ /** A minimal, valid topic. */
31
+ function topic(fields) {
32
+ return {
33
+ type: 'generic',
34
+ name: 'deploying',
35
+ title: 'Deploying',
36
+ description: 'How to ship an app built with Acme widgets.',
37
+ category: 'guide',
38
+ sections: [
39
+ {title: 'Overview', content: [{type: 'prose', text: 'Push the button.'}]},
40
+ ],
41
+ ...fields,
42
+ };
43
+ }
44
+
45
+ /**
46
+ * A consumer project that configures one integration, optionally with a docs
47
+ * root holding the given topics.
48
+ * @param {Record<string, object|string>} [topics] file name → doc
49
+ * @param {{config?: string}} [options]
50
+ */
51
+ function scaffold(topics, {config} = {}) {
52
+ fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({name: 'consumer'}));
53
+ fs.writeFileSync(
54
+ path.join(tmpDir, 'astryx.config.mjs'),
55
+ config ?? "export default {integrations: ['@acme/widgets']};\n",
56
+ );
57
+
58
+ const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
59
+ fs.mkdirSync(pkgDir, {recursive: true});
60
+ fs.writeFileSync(
61
+ path.join(pkgDir, 'package.json'),
62
+ JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
63
+ );
64
+ fs.writeFileSync(
65
+ path.join(pkgDir, 'astryx.integration.mjs'),
66
+ `export default ${JSON.stringify(topics ? {docs: './docs'} : {})};\n`,
67
+ );
68
+
69
+ if (topics) {
70
+ const docsDir = path.join(pkgDir, 'docs');
71
+ fs.mkdirSync(docsDir, {recursive: true});
72
+ for (const [file, doc] of Object.entries(topics)) {
73
+ fs.writeFileSync(
74
+ path.join(docsDir, file),
75
+ typeof doc === 'string'
76
+ ? doc
77
+ : `export const docs = ${JSON.stringify(doc, null, 2)};\n`,
78
+ );
79
+ }
80
+ }
81
+ }
82
+
83
+ beforeEach(() => {
84
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-integration-docs-test-'));
85
+ });
86
+
87
+ afterEach(() => {
88
+ fs.rmSync(tmpDir, {recursive: true, force: true});
89
+ });
90
+
91
+ describe('integration-contributed topics', () => {
92
+ it('lists and reads like a built-in topic, naming its owner', async () => {
93
+ scaffold({'deploying.doc.mjs': topic()});
94
+
95
+ const listed = await docs(undefined, undefined, {cwd: tmpDir});
96
+ const entry = listed.data.find(t => t.topic === 'deploying');
97
+ expect(entry).toMatchObject({
98
+ topic: 'deploying',
99
+ description: 'How to ship an app built with Acme widgets.',
100
+ package: '@acme/widgets',
101
+ });
102
+ // The built-in topics keep their own owner.
103
+ expect(listed.data.find(t => t.topic === 'tokens').package).toBe('@astryxdesign/cli');
104
+
105
+ const detail = await docs('deploying', undefined, {cwd: tmpDir, full: true});
106
+ expect(detail.type).toBe('docs.detail');
107
+ expect(detail.data.sections[0].content[0].text).toBe('Push the button.');
108
+
109
+ const section = await docs('deploying', 'overview', {cwd: tmpDir});
110
+ expect(section.data.title).toBe('Overview');
111
+ }, SLOW);
112
+
113
+ it('is invisible to a project that does not configure the integration', async () => {
114
+ scaffold({'deploying.doc.mjs': topic()}, {config: 'export default {};\n'});
115
+ const listed = await docs(undefined, undefined, {cwd: tmpDir});
116
+ expect(listed.data.some(t => t.topic === 'deploying')).toBe(false);
117
+ }, SLOW);
118
+
119
+ it('serves the replacement of a built-in topic, and says what it replaced', async () => {
120
+ scaffold({
121
+ 'getting-started.doc.mjs': topic({
122
+ name: 'getting-started',
123
+ replaces: 'getting-started',
124
+ title: 'Getting started',
125
+ description: 'Install Acme widgets.',
126
+ sections: [
127
+ {title: 'Install', content: [{type: 'prose', text: 'yarn add @acme/widgets'}]},
128
+ ],
129
+ }),
130
+ });
131
+
132
+ const detail = await docs('getting-started', undefined, {cwd: tmpDir, full: true});
133
+ expect(detail.data.sections.map(s => s.title)).toEqual(['Install']);
134
+ expect(detail.data.sections[0].content[0].text).toBe('yarn add @acme/widgets');
135
+
136
+ const listed = await docs(undefined, undefined, {cwd: tmpDir});
137
+ const entries = listed.data.filter(t => t.topic === 'getting-started');
138
+ expect(entries).toHaveLength(1);
139
+ expect(entries[0]).toMatchObject({
140
+ package: '@acme/widgets',
141
+ replaces: 'getting-started',
142
+ });
143
+ }, SLOW);
144
+
145
+ it('keeps the replaced name resolving when the replacement renames it', async () => {
146
+ scaffold({
147
+ 'setup.doc.mjs': topic({name: 'setup', replaces: 'getting-started'}),
148
+ });
149
+ const byOldName = await docs('getting-started', undefined, {cwd: tmpDir, full: true});
150
+ const byNewName = await docs('setup', undefined, {cwd: tmpDir, full: true});
151
+ expect(byOldName.data.name).toBe('setup');
152
+ expect(byNewName.data.name).toBe('setup');
153
+ }, SLOW);
154
+
155
+ it('merges an extension into the topic it extends', async () => {
156
+ const builtin = await docs('theme', undefined, {full: true});
157
+ const baseSectionTitle = builtin.data.sections[0].title;
158
+ scaffold({
159
+ 'theme-internal.doc.mjs': topic({
160
+ name: 'theme-internal',
161
+ extends: 'theme',
162
+ sections: [
163
+ {title: baseSectionTitle, content: [{type: 'prose', text: 'Use the Acme theme.'}]},
164
+ {title: 'Acme themes', content: [{type: 'prose', text: 'Three of them.'}]},
165
+ ],
166
+ }),
167
+ });
168
+
169
+ const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
170
+ // The extension is not a topic of its own.
171
+ expect((await docs(undefined, undefined, {cwd: tmpDir})).data.some(
172
+ t => t.topic === 'theme-internal',
173
+ )).toBe(false);
174
+ expect(extended.data.sections[0].content[0].text).toBe('Use the Acme theme.');
175
+ expect(extended.data.sections.at(-1).title).toBe('Acme themes');
176
+ // Everything the extension did not name is still the base doc's.
177
+ expect(extended.data.sections.length).toBe(builtin.data.sections.length + 1);
178
+ }, SLOW);
179
+
180
+ it('migrates a real built-in section to a stable ID without duplicating it', async () => {
181
+ const builtin = await docs('theme', undefined, {full: true});
182
+ // Readers see a key on every section; the migration case is one whose
183
+ // source authors no id.
184
+ const {docs: authored} = await import('../../assets/docs/theme.doc.mjs');
185
+ const target = authored.sections.find(section => section.id == null);
186
+ expect(target).toBeDefined();
187
+ scaffold({
188
+ 'theme-internal.doc.mjs': topic({
189
+ name: 'theme-internal',
190
+ extends: 'theme',
191
+ sections: [
192
+ {
193
+ id: 'acme-theme-setup',
194
+ title: target.title,
195
+ content: [{type: 'prose', text: 'Use the Acme theme.'}],
196
+ },
197
+ ],
198
+ }),
199
+ });
200
+
201
+ const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
202
+ expect(extended.data.sections).toHaveLength(builtin.data.sections.length);
203
+ const matches = extended.data.sections.filter(
204
+ section => section.title === target.title,
205
+ );
206
+ expect(matches).toEqual([
207
+ expect.objectContaining({
208
+ id: 'acme-theme-setup',
209
+ content: [{type: 'prose', text: 'Use the Acme theme.'}],
210
+ }),
211
+ ]);
212
+ }, SLOW);
213
+
214
+ it('replaces a real built-in section by the key its index shows', async () => {
215
+ const index = await docs('theme', undefined, {index: true});
216
+ const target = index.data.sections[0];
217
+ scaffold({
218
+ 'theme-internal.doc.mjs': topic({
219
+ name: 'theme-internal',
220
+ extends: 'theme',
221
+ sections: [
222
+ {
223
+ id: target.id,
224
+ title: `${target.title} with Acme`,
225
+ content: [{type: 'prose', text: 'Acme first.'}],
226
+ },
227
+ ],
228
+ }),
229
+ });
230
+
231
+ const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
232
+ expect(extended.data.sections).toHaveLength(index.data.sections.length);
233
+ expect(extended.data.sections.filter(s => s.id === target.id)).toEqual([
234
+ expect.objectContaining({content: [{type: 'prose', text: 'Acme first.'}]}),
235
+ ]);
236
+ const read = await docs('theme', target.id, {cwd: tmpDir});
237
+ expect(read.data.title).toBe(`${target.title} with Acme`);
238
+ }, SLOW);
239
+
240
+ it.each(['zh', 'dense'])(
241
+ 'replaces translated real sections by their authored titles under --%s',
242
+ async lang => {
243
+ const english = await docs('theme', undefined, {full: true});
244
+ const englishTitles = english.data.sections.map(section => section.title);
245
+ expect(englishTitles).toEqual(
246
+ expect.arrayContaining(['Available Themes', 'Theme Props']),
247
+ );
248
+ scaffold({
249
+ 'theme-internal.doc.mjs': topic({
250
+ name: 'theme-internal',
251
+ extends: 'theme',
252
+ sections: [
253
+ {
254
+ id: 'acme-available-themes',
255
+ title: 'Available Themes',
256
+ content: [{type: 'prose', text: 'Acme themes.'}],
257
+ },
258
+ {
259
+ title: 'Theme Props',
260
+ content: [{type: 'prose', text: 'Acme props.'}],
261
+ },
262
+ ],
263
+ }),
264
+ });
265
+
266
+ const base = await docs('theme', undefined, {lang, full: true});
267
+ expect(base.data.sections.map(section => section.title)).not.toEqual(
268
+ englishTitles,
269
+ );
270
+ const extended = await docs('theme', undefined, {cwd: tmpDir, lang, full: true});
271
+ expect(extended.data.sections).toHaveLength(base.data.sections.length);
272
+ expect(
273
+ extended.data.sections.filter(
274
+ section => section.id === 'acme-available-themes',
275
+ ),
276
+ ).toHaveLength(1);
277
+ expect(
278
+ extended.data.sections.filter(
279
+ section => section.content[0]?.text === 'Acme props.',
280
+ ),
281
+ ).toHaveLength(1);
282
+ },
283
+ SLOW,
284
+ );
285
+
286
+ it('offers the contributed topics as suggestions on an unknown one', async () => {
287
+ scaffold({'deploying.doc.mjs': topic()});
288
+ await expect(docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true})).rejects.toBeInstanceOf(
289
+ AstryxError,
290
+ );
291
+ try {
292
+ await docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true});
293
+ } catch (err) {
294
+ expect(err.suggestions.map(s => s.name)).toContain('deploying');
295
+ }
296
+ }, SLOW);
297
+
298
+ it('indexes a contributed topic in search', async () => {
299
+ scaffold({'deploying.doc.mjs': topic()});
300
+ const {data} = await search('deploying', {cwd: tmpDir, type: 'doc'});
301
+ expect(data.results[0]).toMatchObject({
302
+ domain: 'doc',
303
+ name: 'deploying',
304
+ command: 'astryx docs deploying',
305
+ });
306
+ }, SLOW);
307
+
308
+ it('ranks the topics that match every word of the query first', async () => {
309
+ // Dozens of CLI docs match `integration` alone, by name or in a code
310
+ // tick; the topics that hold both words, this one and the CLI's own
311
+ // troubleshooting guide, must still come first.
312
+ scaffold({
313
+ 'troubleshooting.doc.mjs': topic({
314
+ name: 'troubleshooting',
315
+ title: 'Troubleshooting',
316
+ description: 'What to check when an integration does not load.',
317
+ }),
318
+ });
319
+ const {data} = await search('troubleshoot integration', {cwd: tmpDir, type: 'doc'});
320
+ const top = data.results.slice(0, 2).map(result => result.name);
321
+ // This topic, and the CLI's own troubleshooting guide wherever the tree
322
+ // places it.
323
+ expect(top).toContain('troubleshooting');
324
+ expect(
325
+ top.some(name => /^cli\/integrations\/(?:.+\/)?troubleshooting$/.test(name)),
326
+ top.join(', '),
327
+ ).toBe(true);
328
+ }, SLOW);
329
+
330
+ it("falls back to the CLI's own topics when the project config is unreadable", async () => {
331
+ scaffold({'deploying.doc.mjs': topic()}, {config: 'export default {integrations: 42};\n'});
332
+ const catalog = await loadDocsCatalog(tmpDir);
333
+ expect(catalog.resolve('tokens')).toBeTruthy();
334
+ expect(catalog.resolve('deploying')).toBeUndefined();
335
+ }, SLOW);
336
+ });
package/api/error.d.mts CHANGED
@@ -1,6 +1,28 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The error for a write that failed on the filesystem: no permission, a
6
+ * read-only mount, a full disk, a path component that is not a directory.
7
+ *
8
+ * A raw Node errno error reached the envelope as
9
+ * `{"error": "EACCES: permission denied, open '/home/you/p/readonly/x.tsx'",
10
+ * "code": "ERR_UNKNOWN"}` — the wrong code (ERR_WRITE_FAILED is in the frozen
11
+ * registry for exactly this) and an absolute host path in the message. This
12
+ * keeps the errno, which is the part that tells you what to fix, and reports
13
+ * the target the way every other Astryx message does: relative to the project.
14
+ *
15
+ * A caller that wrote files before the failure must undo them first and pass
16
+ * the ones it could not restore as `unrestored`, so the message never says
17
+ * nothing was written when something was.
18
+ *
19
+ * @param {string} target absolute path the write was aimed at
20
+ * @param {string} cwd project root, for the relative form
21
+ * @param {unknown} cause the error the filesystem call threw
22
+ * @param {string[]} [unrestored] absolute paths an undo could not put back
23
+ * @returns {AstryxError}
24
+ */
25
+ export function writeFailed(target: string, cwd: string, cause: unknown, unrestored?: string[]): AstryxError;
4
26
  export class AstryxError extends Error {
5
27
  /**
6
28
  * @param {string} message
package/api/error.mjs CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import {ERROR_CODES} from '../foundation/response/error-codes.mjs';
15
+ import * as path from 'node:path';
15
16
 
16
17
  export class AstryxError extends Error {
17
18
  /** @type {import('../foundation/response/base').Suggestion[] | undefined} */
@@ -36,3 +37,44 @@ export class AstryxError extends Error {
36
37
  if (Array.isArray(suggestions) && suggestions.length) this.suggestions = suggestions;
37
38
  }
38
39
  }
40
+
41
+ /**
42
+ * The error for a write that failed on the filesystem: no permission, a
43
+ * read-only mount, a full disk, a path component that is not a directory.
44
+ *
45
+ * A raw Node errno error reached the envelope as
46
+ * `{"error": "EACCES: permission denied, open '/home/you/p/readonly/x.tsx'",
47
+ * "code": "ERR_UNKNOWN"}` — the wrong code (ERR_WRITE_FAILED is in the frozen
48
+ * registry for exactly this) and an absolute host path in the message. This
49
+ * keeps the errno, which is the part that tells you what to fix, and reports
50
+ * the target the way every other Astryx message does: relative to the project.
51
+ *
52
+ * A caller that wrote files before the failure must undo them first and pass
53
+ * the ones it could not restore as `unrestored`, so the message never says
54
+ * nothing was written when something was.
55
+ *
56
+ * @param {string} target absolute path the write was aimed at
57
+ * @param {string} cwd project root, for the relative form
58
+ * @param {unknown} cause the error the filesystem call threw
59
+ * @param {string[]} [unrestored] absolute paths an undo could not put back
60
+ * @returns {AstryxError}
61
+ */
62
+ export function writeFailed(target, cwd, cause, unrestored = []) {
63
+ const rel = path.relative(cwd, target) || target;
64
+ const errno =
65
+ typeof (/** @type {any} */ (cause)?.code) === 'string'
66
+ ? /** @type {any} */ (cause).code
67
+ : null;
68
+ const why = errno === 'EACCES' || errno === 'EPERM' ? ' (no permission)' : '';
69
+ const outcome =
70
+ unrestored.length === 0
71
+ ? 'Nothing was written.'
72
+ : `Earlier writes could not all be undone: ${unrestored
73
+ .map(file => path.relative(cwd, file) || file)
74
+ .join(', ')}.`;
75
+ return new AstryxError(
76
+ `Could not write ${rel}${errno ? `: ${errno}` : ''}${why}. ${outcome}`,
77
+ undefined,
78
+ ERROR_CODES.ERR_WRITE_FAILED,
79
+ );
80
+ }
@@ -31,7 +31,7 @@ export function integrationAddAgentDoc(line: string, options?: import("./integra
31
31
  *
32
32
  * @param {'component'|'doc'|'template'|'codemod'|'agent-doc'|'theme'} kind
33
33
  * @param {string} name
34
- * @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string}} [options]
34
+ * @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string, from?: string}} [options]
35
35
  * @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
36
36
  */
37
37
  export function integrationAdd(kind: "component" | "doc" | "template" | "codemod" | "agent-doc" | "theme", name: string, options?: {
@@ -42,4 +42,5 @@ export function integrationAdd(kind: "component" | "doc" | "template" | "codemod
42
42
  replaces?: string;
43
43
  extends?: string;
44
44
  parent?: string;
45
+ from?: string;
45
46
  }): Promise<import("./integration-authoring.type.mjs").IntegrationAddResponse>;
@@ -1211,7 +1211,7 @@ const KIND_OPTIONS = {
1211
1211
  template: new Set(['cwd', 'dryRun', 'templateType']),
1212
1212
  codemod: new Set(['cwd', 'dryRun', 'to']),
1213
1213
  'agent-doc': new Set(['cwd', 'dryRun']),
1214
- theme: new Set(['cwd', 'dryRun']),
1214
+ theme: new Set(['cwd', 'dryRun', 'from']),
1215
1215
  };
1216
1216
 
1217
1217
  /**
@@ -1238,7 +1238,7 @@ function validateKindOptions(kind, options) {
1238
1238
  *
1239
1239
  * @param {'component'|'doc'|'template'|'codemod'|'agent-doc'|'theme'} kind
1240
1240
  * @param {string} name
1241
- * @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string}} [options]
1241
+ * @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string, from?: string}} [options]
1242
1242
  * @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
1243
1243
  */
1244
1244
  export async function integrationAdd(kind, name, options = {}) {
@@ -1270,6 +1270,10 @@ export async function integrationAdd(kind, name, options = {}) {
1270
1270
  case 'agent-doc':
1271
1271
  return integrationAddAgentDoc(name, options);
1272
1272
  case 'theme':
1273
- return integrationAddTheme(name, options);
1273
+ return integrationAddTheme(name, {
1274
+ cwd: options.cwd,
1275
+ dryRun: options.dryRun,
1276
+ from: options.from,
1277
+ });
1274
1278
  }
1275
1279
  }
@@ -12,7 +12,7 @@ import {
12
12
  integrationAddTemplate,
13
13
  } from './add-contribution.mjs';
14
14
  import {validateLocalIntegration} from './validate-integration.mjs';
15
- import {DOCS_TREE_CLI} from '../../foundation/integrations/cli-requirement.mjs';
15
+ import {NAMESPACE_DOCS_CLI} from '../../foundation/integrations/cli-requirement.mjs';
16
16
 
17
17
  let tmpDir;
18
18
 
@@ -355,7 +355,7 @@ describe('integrationAdd doc', () => {
355
355
 
356
356
  // The namespace doc needs a CLI that reads it, declared as an optional peer.
357
357
  const pkg = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'));
358
- expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': `>=${DOCS_TREE_CLI}`});
358
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
359
359
  expect(pkg.peerDependenciesMeta).toEqual({'@astryxdesign/cli': {optional: true}});
360
360
 
361
361
  const second = await integrationAdd('doc', 'upgrading', {
@@ -429,7 +429,7 @@ describe('integrationAdd doc', () => {
429
429
  write('^0.6.0');
430
430
  await integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'acme'});
431
431
  expect(JSON.parse(fs.readFileSync(file, 'utf-8')).peerDependencies).toEqual({
432
- '@astryxdesign/cli': `>=${DOCS_TREE_CLI}`,
432
+ '@astryxdesign/cli': `>=${NAMESPACE_DOCS_CLI}`,
433
433
  });
434
434
  write('^9.1.0');
435
435
  await integrationAdd('doc', 'upgrading', {cwd: tmpDir, parent: 'acme'});