@astryxdesign/cli 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +76 -67
  3. package/api/build/build.test.mjs +37 -0
  4. package/api/build/build.type.mjs +1 -1
  5. package/api/build/kit/kit.mjs +31 -1
  6. package/api/component/_adapter.mjs +14 -28
  7. package/api/component/integration-import-agreement.test.mjs +318 -0
  8. package/api/doctor/doctor.d.mts +32 -3
  9. package/api/doctor/doctor.doc.mjs +2 -1
  10. package/api/doctor/doctor.mjs +97 -4
  11. package/api/doctor/doctor.test.mjs +90 -1
  12. package/api/gap-report/gap-report-worker.d.mts +4 -0
  13. package/api/gap-report/gap-report-worker.mjs +73 -0
  14. package/api/gap-report/gap-report.d.mts +81 -0
  15. package/api/gap-report/gap-report.doc.d.mts +9 -0
  16. package/api/gap-report/gap-report.doc.mjs +127 -0
  17. package/api/gap-report/gap-report.mjs +707 -0
  18. package/api/gap-report/gap-report.test.mjs +1210 -0
  19. package/api/gap-report/gap-report.type.d.mts +88 -0
  20. package/api/gap-report/gap-report.type.mjs +69 -0
  21. package/api/index.d.mts +8 -1
  22. package/api/index.mjs +24 -1
  23. package/api/integration/add-contribution.d.mts +44 -0
  24. package/api/integration/add-contribution.mjs +1160 -0
  25. package/api/integration/add-contribution.test.mjs +733 -0
  26. package/api/integration/add-helpers.d.mts +80 -0
  27. package/api/integration/add-helpers.mjs +333 -0
  28. package/api/integration/add-helpers.test.mjs +161 -0
  29. package/api/integration/add-theme.d.mts +10 -0
  30. package/api/integration/add-theme.mjs +332 -0
  31. package/api/integration/add-theme.test.mjs +194 -0
  32. package/api/integration/integration-authoring.type.d.mts +55 -0
  33. package/api/integration/integration-authoring.type.mjs +76 -0
  34. package/api/integration/integration-block-exports.test.mjs +4 -0
  35. package/api/integration/integrationAdd.doc.d.mts +5 -0
  36. package/api/integration/integrationAdd.doc.mjs +100 -0
  37. package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
  38. package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
  39. package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
  40. package/api/integration/integrationAddCodemod.doc.mjs +55 -0
  41. package/api/integration/integrationAddComponent.doc.d.mts +5 -0
  42. package/api/integration/integrationAddComponent.doc.mjs +49 -0
  43. package/api/integration/integrationAddDoc.doc.d.mts +5 -0
  44. package/api/integration/integrationAddDoc.doc.mjs +59 -0
  45. package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
  46. package/api/integration/integrationAddTemplate.doc.mjs +55 -0
  47. package/api/integration/integrationAddTheme.doc.d.mts +5 -0
  48. package/api/integration/integrationAddTheme.doc.mjs +85 -0
  49. package/api/integration/integrationPackCheck.doc.d.mts +5 -0
  50. package/api/integration/integrationPackCheck.doc.mjs +35 -0
  51. package/api/integration/pack-check.d.mts +27 -0
  52. package/api/integration/pack-check.mjs +795 -0
  53. package/api/integration/pack-check.test.mjs +569 -0
  54. package/api/integration/pack-check.type.d.mts +45 -0
  55. package/api/integration/pack-check.type.mjs +56 -0
  56. package/api/integration/public-api.test.mjs +21 -0
  57. package/api/integration/validate-integration.mjs +221 -11
  58. package/api/integration/validate-integration.test.mjs +189 -5
  59. package/api/integration/validateIntegration.doc.mjs +2 -2
  60. package/api/json/index.ts +1 -0
  61. package/api/search/search.mjs +19 -1
  62. package/api/theme/_adapter.d.mts +26 -28
  63. package/api/theme/_adapter.mjs +101 -38
  64. package/api/theme/add/add.d.mts +2 -1
  65. package/api/theme/add/add.mjs +56 -20
  66. package/api/theme/add/add.test.mjs +1 -0
  67. package/api/theme/build/build.d.mts +25 -0
  68. package/api/theme/build/build.mjs +101 -70
  69. package/api/theme/build/build.test.mjs +77 -44
  70. package/api/theme/integration-themes.test.mjs +183 -0
  71. package/api/theme/list/list.d.mts +10 -2
  72. package/api/theme/list/list.mjs +31 -10
  73. package/api/theme/list/list.test.mjs +102 -23
  74. package/api/theme/listThemes.doc.d.mts +1 -5
  75. package/api/theme/listThemes.doc.mjs +6 -13
  76. package/api/theme/targets/targets.test.mjs +22 -8
  77. package/api/theme/theme.d.mts +1 -1
  78. package/api/theme/theme.mjs +1 -1
  79. package/api/theme/theme.type.d.mts +9 -0
  80. package/api/theme/theme.type.mjs +3 -1
  81. package/api/theme/themeAdd.doc.d.mts +1 -4
  82. package/api/theme/themeAdd.doc.mjs +31 -31
  83. package/api/theme/themeBuild.doc.mjs +1 -1
  84. package/api/theme/themeList.doc.d.mts +1 -4
  85. package/api/theme/themeList.doc.mjs +7 -15
  86. package/api/theme/themeListAvailable.doc.d.mts +8 -0
  87. package/api/theme/themeListAvailable.doc.mjs +57 -0
  88. package/api/theme/themeTargets.doc.mjs +21 -7
  89. package/api/upgrade/_adapter.d.mts +2 -0
  90. package/api/upgrade/_adapter.mjs +1 -0
  91. package/api/upgrade/registry/registry.d.mts +40 -0
  92. package/api/upgrade/registry/registry.mjs +1154 -0
  93. package/api/upgrade/registry/registry.test.mjs +826 -0
  94. package/api/upgrade/run/run.mjs +49 -8
  95. package/api/upgrade/status/status.d.mts +6 -4
  96. package/api/upgrade/status/status.mjs +26 -8
  97. package/api/upgrade/upgrade.d.mts +2 -2
  98. package/api/upgrade/upgrade.doc.mjs +33 -9
  99. package/api/upgrade/upgrade.mjs +34 -7
  100. package/api/upgrade/upgrade.test.mjs +198 -8
  101. package/api/upgrade/upgrade.type.d.mts +90 -1
  102. package/api/upgrade/upgrade.type.mjs +51 -2
  103. package/assets/docs/cli-integrations.doc.mjs +152 -28
  104. package/assets/docs/getting-started.doc.mjs +1 -1
  105. package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
  106. package/assets/docs/styling.doc.mjs +3 -3
  107. package/assets/docs/theme.doc.dense.mjs +2 -2
  108. package/assets/docs/theme.doc.mjs +23 -13
  109. package/assets/docs/theme.doc.zh.mjs +1 -1
  110. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
  111. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
  112. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
  114. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
  115. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
  116. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
  117. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
  118. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
  119. package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
  120. package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
  121. package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
  122. package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
  123. package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
  124. package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
  125. package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
  126. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
  127. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
  128. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
  129. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
  130. package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
  131. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
  132. package/assets/templates/themes/butter/butterTheme.ts +3 -3
  133. package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
  134. package/assets/templates/themes/stone/stoneTheme.ts +3 -3
  135. package/assets/theme.template.ts +4 -7
  136. package/authoring/config/config.doc.mjs +9 -1
  137. package/authoring/config/parse.d.mts +2 -0
  138. package/authoring/config/parse.mjs +28 -3
  139. package/authoring/config/parse.test.mjs +25 -3
  140. package/authoring/config/type.ts +3 -0
  141. package/authoring/doctypes/_schema.d.mts +3 -0
  142. package/authoring/doctypes/_schema.mjs +6 -1
  143. package/authoring/doctypes/base/type.ts +6 -6
  144. package/authoring/doctypes/component/component.doc.mjs +6 -0
  145. package/authoring/doctypes/component/type.ts +2 -0
  146. package/authoring/gap-report/parse.d.mts +63 -0
  147. package/authoring/gap-report/parse.mjs +121 -0
  148. package/authoring/gap-report/parse.test.mjs +172 -0
  149. package/authoring/gap-report/type.ts +107 -0
  150. package/authoring/index.d.mts +1 -0
  151. package/authoring/index.d.ts +12 -0
  152. package/authoring/index.mjs +4 -0
  153. package/authoring/integration/integration.doc.mjs +14 -2
  154. package/authoring/integration/parse.test.mjs +9 -4
  155. package/authoring/integration/schema.d.mts +2 -0
  156. package/authoring/integration/schema.mjs +1 -0
  157. package/authoring/integration/type.ts +23 -6
  158. package/authoring/shadcn/receipt.d.mts +219 -0
  159. package/authoring/shadcn/receipt.mjs +248 -0
  160. package/authoring/shadcn/receipt.test.mjs +187 -0
  161. package/authoring/shadcn/source-variants.d.mts +28 -0
  162. package/authoring/shadcn/source-variants.mjs +176 -0
  163. package/authoring/shadcn/source-variants.test.mjs +120 -0
  164. package/clients/cli/commands/build-theme.mjs +54 -19
  165. package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
  166. package/clients/cli/commands/component/index.mjs +1 -1
  167. package/clients/cli/commands/docs.test.mjs +1 -0
  168. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  169. package/clients/cli/commands/gap-report.doc.mjs +73 -0
  170. package/clients/cli/commands/gap-report.mjs +114 -0
  171. package/clients/cli/commands/gap-report.test.mjs +198 -0
  172. package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
  173. package/clients/cli/commands/integration-add.doc.mjs +88 -0
  174. package/clients/cli/commands/integration-authoring.test.mjs +177 -0
  175. package/clients/cli/commands/integration-pack.doc.mjs +34 -0
  176. package/clients/cli/commands/integration-real-world.test.mjs +618 -0
  177. package/clients/cli/commands/integration.doc.mjs +28 -0
  178. package/clients/cli/commands/integration.mjs +153 -0
  179. package/clients/cli/commands/theme-add.doc.mjs +11 -6
  180. package/clients/cli/commands/theme-list.doc.mjs +21 -5
  181. package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
  182. package/clients/cli/commands/theme.doc.mjs +2 -2
  183. package/clients/cli/commands/upgrade.doc.mjs +17 -4
  184. package/clients/cli/commands/upgrade.mjs +12 -1
  185. package/clients/cli/commands/upgrade.test.mjs +41 -0
  186. package/clients/cli/index.mjs +5 -0
  187. package/clients/cli/lib/component-format.mjs +42 -26
  188. package/clients/cli/lib/component-format.test.mjs +34 -3
  189. package/clients/cli/lib/manifest.mjs +12 -0
  190. package/foundation/config/project-themes.test.mjs +127 -0
  191. package/foundation/config/project.d.mts +23 -4
  192. package/foundation/config/project.mjs +96 -9
  193. package/foundation/config/project.test.mjs +132 -6
  194. package/foundation/discovery/component-discovery.d.mts +36 -0
  195. package/foundation/discovery/component-discovery.mjs +96 -0
  196. package/foundation/discovery/theme-discovery.d.mts +39 -0
  197. package/foundation/discovery/theme-discovery.mjs +650 -0
  198. package/foundation/discovery/theme-discovery.test.mjs +375 -0
  199. package/foundation/discovery/theming-targets.d.mts +16 -0
  200. package/foundation/discovery/theming-targets.mjs +39 -3
  201. package/foundation/discovery/theming-targets.test.mjs +139 -0
  202. package/foundation/integrations/autolink.d.mts +96 -0
  203. package/foundation/integrations/autolink.mjs +265 -0
  204. package/foundation/integrations/autolink.test.mjs +430 -0
  205. package/foundation/integrations/contribution-inventory.d.mts +152 -0
  206. package/foundation/integrations/contribution-inventory.mjs +497 -0
  207. package/foundation/integrations/contribution-inventory.test.mjs +361 -0
  208. package/foundation/integrations/integrations.d.mts +73 -9
  209. package/foundation/integrations/integrations.mjs +158 -8
  210. package/foundation/integrations/integrations.test.mjs +152 -29
  211. package/foundation/integrations/manifest-writer.d.mts +56 -0
  212. package/foundation/integrations/manifest-writer.mjs +328 -0
  213. package/foundation/integrations/manifest-writer.test.mjs +229 -0
  214. package/foundation/integrations/validate-contributions.mjs +81 -6
  215. package/foundation/response/error-codes.d.mts +4 -1
  216. package/foundation/response/error-codes.doc.mjs +16 -1
  217. package/foundation/response/error-codes.mjs +10 -1
  218. package/foundation/response/response-types.doc.mjs +23 -2
  219. package/package.json +8 -1
@@ -0,0 +1,733 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import {
7
+ integrationAdd,
8
+ integrationAddAgentDoc,
9
+ integrationAddCodemod,
10
+ integrationAddComponent,
11
+ integrationAddDoc,
12
+ integrationAddTemplate,
13
+ } from './add-contribution.mjs';
14
+ import {validateLocalIntegration} from './validate-integration.mjs';
15
+
16
+ let tmpDir;
17
+
18
+ /**
19
+ * @param {{manifest?: string, files?: string[], includeFiles?: boolean, name?: string, exports?: unknown}} [opts]
20
+ */
21
+ function setup({
22
+ manifest = 'export default {};\n',
23
+ files = ['dist'],
24
+ includeFiles = true,
25
+ name = '@acme/integration',
26
+ exports,
27
+ } = {}) {
28
+ /** @type {{name: string, version: string, files?: string[], exports?: unknown}} */
29
+ const pkg = {name, version: '1.0.0'};
30
+ if (includeFiles) pkg.files = files;
31
+ if (exports !== undefined) pkg.exports = exports;
32
+ fs.writeFileSync(
33
+ path.join(tmpDir, 'package.json'),
34
+ `${JSON.stringify(pkg, null, 2)}\n`,
35
+ );
36
+ fs.writeFileSync(path.join(tmpDir, 'astryx.integration.mjs'), manifest);
37
+ }
38
+
39
+ /** Create a bare package dir with no manifest (first-add scenario). */
40
+ function setupBare({files, includeFiles = true} = {}) {
41
+ /** @type {{name: string, version: string, files?: string[]}} */
42
+ const pkg = {name: '@acme/integration', version: '1.0.0'};
43
+ if (includeFiles) pkg.files = files ?? ['dist'];
44
+ fs.writeFileSync(
45
+ path.join(tmpDir, 'package.json'),
46
+ `${JSON.stringify(pkg, null, 2)}\n`,
47
+ );
48
+ }
49
+
50
+ beforeEach(() => {
51
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-contrib-'));
52
+ });
53
+
54
+ afterEach(() => {
55
+ fs.rmSync(tmpDir, {recursive: true, force: true});
56
+ });
57
+
58
+ // ── COMPONENT ───────────────────────────────────────────────────────
59
+
60
+ describe('integrationAdd component', () => {
61
+ it('writes doc + source, patches root, and appends to files array', async () => {
62
+ setup();
63
+ const result = await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
64
+
65
+ expect(result.type).toBe('integration.add');
66
+ expect(result.data.kind).toBe('component');
67
+ expect(result.data.name).toBe('MyWidget');
68
+ expect(result.data.root).toEqual({path: './components', created: true});
69
+ expect(result.data.written).toBe(true);
70
+ expect(result.data.dryRun).toBe(false);
71
+ expect(result.data.files).toContain('components/MyWidget.doc.mjs');
72
+ expect(result.data.files).toContain('components/MyWidget.tsx');
73
+ expect(result.data.files).toContain('astryx.integration.mjs');
74
+
75
+ // Doc file is valid
76
+ const doc = fs.readFileSync(
77
+ path.join(tmpDir, 'components/MyWidget.doc.mjs'),
78
+ 'utf-8',
79
+ );
80
+ expect(doc).toContain("type: 'component'");
81
+ expect(doc).toContain("name: 'MyWidget'");
82
+ expect(doc).toContain('props: []');
83
+
84
+ // Source file exists
85
+ expect(fs.existsSync(path.join(tmpDir, 'components/MyWidget.tsx'))).toBe(
86
+ true,
87
+ );
88
+
89
+ // Manifest updated
90
+ const manifestContent = fs.readFileSync(
91
+ path.join(tmpDir, 'astryx.integration.mjs'),
92
+ 'utf-8',
93
+ );
94
+ expect(manifestContent).toContain("components: './components'");
95
+
96
+ // package.json files updated
97
+ const pkg = JSON.parse(
98
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
99
+ );
100
+ expect(pkg.files).toContain('components');
101
+ expect(pkg.files).toContain('astryx.integration.mjs');
102
+
103
+ // Doctor validates cleanly
104
+ const validation = await validateLocalIntegration(tmpDir);
105
+ const componentErrors = validation.issues.filter(
106
+ i => i.code === 'invalid_component',
107
+ );
108
+ expect(componentErrors).toEqual([]);
109
+ });
110
+
111
+ it('publishes and documents the generated component in an existing exports map', async () => {
112
+ setup({exports: {'.': './index.mjs'}});
113
+
114
+ await integrationAddComponent('MyWidget', {cwd: tmpDir});
115
+
116
+ const pkg = JSON.parse(
117
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
118
+ );
119
+ expect(pkg.exports).toEqual({
120
+ '.': './index.mjs',
121
+ './components/MyWidget.tsx': './components/MyWidget.tsx',
122
+ });
123
+ expect(
124
+ fs.readFileSync(
125
+ path.join(tmpDir, 'components/MyWidget.doc.mjs'),
126
+ 'utf-8',
127
+ ),
128
+ ).toContain('import: "@acme/integration/components/MyWidget.tsx"');
129
+ });
130
+
131
+ it('does not create exports when the package has no exports map', async () => {
132
+ setup();
133
+
134
+ await integrationAddComponent('MyWidget', {cwd: tmpDir});
135
+
136
+ const pkg = JSON.parse(
137
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
138
+ );
139
+ expect(pkg.exports).toBeUndefined();
140
+ });
141
+
142
+ it('refuses an existing conflicting component export before writing files', async () => {
143
+ setup({
144
+ exports: {
145
+ '.': './index.mjs',
146
+ './components/MyWidget.tsx': './different.tsx',
147
+ },
148
+ });
149
+
150
+ await expect(
151
+ integrationAddComponent('MyWidget', {cwd: tmpDir}),
152
+ ).rejects.toMatchObject({code: 'ERR_INTEGRATION_EXPORT_CONFLICT'});
153
+ expect(fs.existsSync(path.join(tmpDir, 'components'))).toBe(false);
154
+ });
155
+
156
+ it('dry-runs without writing', async () => {
157
+ setup();
158
+ const result = await integrationAdd('component', 'MyWidget', {
159
+ cwd: tmpDir,
160
+ dryRun: true,
161
+ });
162
+ expect(result.data.written).toBe(false);
163
+ expect(result.data.dryRun).toBe(true);
164
+ expect(result.data.root).toEqual({path: './components', created: true});
165
+ expect(fs.existsSync(path.join(tmpDir, 'components'))).toBe(false);
166
+ });
167
+
168
+ it('creates the manifest on first add', async () => {
169
+ setupBare();
170
+ const result = await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
171
+ expect(result.data.root.created).toBe(true);
172
+ expect(fs.existsSync(path.join(tmpDir, 'astryx.integration.mjs'))).toBe(
173
+ true,
174
+ );
175
+ });
176
+
177
+ it('refuses to overwrite an existing doc file', async () => {
178
+ setup();
179
+ fs.mkdirSync(path.join(tmpDir, 'components'), {recursive: true});
180
+ fs.writeFileSync(
181
+ path.join(tmpDir, 'components/MyWidget.doc.mjs'),
182
+ 'existing',
183
+ );
184
+ await expect(
185
+ integrationAdd('component', 'MyWidget', {cwd: tmpDir}),
186
+ ).rejects.toThrow(/Refusing to overwrite/);
187
+ });
188
+
189
+ it('refuses to overwrite an existing source file', async () => {
190
+ setup();
191
+ fs.mkdirSync(path.join(tmpDir, 'components'), {recursive: true});
192
+ fs.writeFileSync(path.join(tmpDir, 'components/MyWidget.tsx'), 'existing');
193
+ await expect(
194
+ integrationAdd('component', 'MyWidget', {cwd: tmpDir}),
195
+ ).rejects.toThrow(/Refusing to overwrite/);
196
+ });
197
+
198
+ it('rejects a lowercase name', async () => {
199
+ setup();
200
+ await expect(
201
+ integrationAdd('component', 'myWidget', {cwd: tmpDir}),
202
+ ).rejects.toThrow(/PascalCase/);
203
+ });
204
+
205
+ // ── MUTATION TESTS: same-stem pair ──────────────────────────────
206
+
207
+ it('mutation: doc alone (no .tsx) causes a validate-contributions error', async () => {
208
+ setup();
209
+ await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
210
+ // Remove the .tsx — keep the doc
211
+ fs.rmSync(path.join(tmpDir, 'components/MyWidget.tsx'));
212
+ const validation = await validateLocalIntegration(tmpDir);
213
+ const componentErrors = validation.issues.filter(
214
+ i => i.code === 'invalid_component',
215
+ );
216
+ expect(componentErrors.length).toBeGreaterThan(0);
217
+ });
218
+
219
+ it('mutation: source alone (no .doc) is invisible to discovery', async () => {
220
+ setup();
221
+ await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
222
+ // Remove the doc — keep the tsx
223
+ fs.rmSync(path.join(tmpDir, 'components/MyWidget.doc.mjs'));
224
+ const validation = await validateLocalIntegration(tmpDir);
225
+ // No error because the component is simply invisible — it was never discovered
226
+ const componentErrors = validation.issues.filter(
227
+ i => i.code === 'invalid_component',
228
+ );
229
+ expect(componentErrors).toEqual([]);
230
+ expect(
231
+ validation.issues.some(
232
+ issue => issue.code === 'source_without_component_doc',
233
+ ),
234
+ ).toBe(true);
235
+ // The component is not discoverable without metadata.
236
+ const {discoverIntegrationComponents} =
237
+ await import('../../foundation/discovery/component-discovery.mjs');
238
+ const {loadManifestObject} =
239
+ await import('../../foundation/integrations/integrations.mjs');
240
+ const {assertWithin} = await import('../../foundation/fs/path-safety.mjs');
241
+ const manifest = await loadManifestObject(
242
+ path.join(tmpDir, 'astryx.integration.mjs'),
243
+ 'test',
244
+ {fresh: true},
245
+ );
246
+ const compsRoot = assertWithin(manifest.components, tmpDir, {
247
+ label: 'test',
248
+ });
249
+ const records = discoverIntegrationComponents({
250
+ name: '@acme/integration',
251
+ components: compsRoot,
252
+ __spec: '@acme/integration',
253
+ __packageDir: tmpDir,
254
+ __manifestFile: path.join(tmpDir, 'astryx.integration.mjs'),
255
+ });
256
+ expect(records.some(r => r.name === 'MyWidget')).toBe(false);
257
+ });
258
+ });
259
+
260
+ // ── FILES ALLOWLIST MUTATION ────────────────────────────────────────
261
+
262
+ describe('package.json files allowlist', () => {
263
+ it('never creates a files field when absent', async () => {
264
+ setup({includeFiles: false});
265
+ await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
266
+ const pkg = JSON.parse(
267
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
268
+ );
269
+ expect(pkg.files).toBeUndefined();
270
+ });
271
+
272
+ it('appends root and manifest to existing files array', async () => {
273
+ setup({files: ['dist']});
274
+ await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
275
+ const pkg = JSON.parse(
276
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
277
+ );
278
+ expect(pkg.files).toEqual(['dist', 'components', 'astryx.integration.mjs']);
279
+ });
280
+
281
+ it('does not duplicate entries already in files', async () => {
282
+ setup({files: ['dist', 'components', 'astryx.integration.mjs']});
283
+ await integrationAdd('component', 'MyWidget', {cwd: tmpDir});
284
+ const pkg = JSON.parse(
285
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
286
+ );
287
+ expect(pkg.files).toEqual(['dist', 'components', 'astryx.integration.mjs']);
288
+ });
289
+ });
290
+
291
+ // ── DOC TOPIC ───────────────────────────────────────────────────────
292
+
293
+ describe('integrationAdd doc', () => {
294
+ it('writes a valid generic topic with receipt', async () => {
295
+ setup();
296
+ const result = await integrationAdd('doc', 'my-guide', {cwd: tmpDir});
297
+
298
+ expect(result.data.kind).toBe('doc');
299
+ expect(result.data.name).toBe('my-guide');
300
+ expect(result.data.root).toEqual({path: './docs', created: true});
301
+ expect(result.data.files).toContain('docs/my-guide.doc.mjs');
302
+
303
+ const doc = fs.readFileSync(
304
+ path.join(tmpDir, 'docs/my-guide.doc.mjs'),
305
+ 'utf-8',
306
+ );
307
+ expect(doc).toContain("type: 'generic'");
308
+ expect(doc).toContain("name: 'my-guide'");
309
+
310
+ const validation = await validateLocalIntegration(tmpDir);
311
+ const docErrors = validation.issues.filter(i => i.code === 'invalid_doc');
312
+ expect(docErrors).toEqual([]);
313
+ });
314
+
315
+ it('includes replaces in the generated doc', async () => {
316
+ setup();
317
+ const result = await integrationAdd('doc', 'my-tokens', {
318
+ cwd: tmpDir,
319
+ replaces: 'tokens',
320
+ });
321
+ const doc = fs.readFileSync(
322
+ path.join(tmpDir, 'docs/my-tokens.doc.mjs'),
323
+ 'utf-8',
324
+ );
325
+ expect(doc).toContain("replaces: 'tokens'");
326
+ expect(doc).not.toContain('extends:');
327
+ });
328
+
329
+ it('includes extends in the generated doc', async () => {
330
+ setup();
331
+ const result = await integrationAdd('doc', 'extra-tokens', {
332
+ cwd: tmpDir,
333
+ extends: 'tokens',
334
+ });
335
+ const doc = fs.readFileSync(
336
+ path.join(tmpDir, 'docs/extra-tokens.doc.mjs'),
337
+ 'utf-8',
338
+ );
339
+ expect(doc).toContain("extends: 'tokens'");
340
+ expect(doc).not.toContain('replaces:');
341
+ });
342
+
343
+ it('rejects replaces + extends together', async () => {
344
+ setup();
345
+ await expect(
346
+ integrationAdd('doc', 'my-tokens', {
347
+ cwd: tmpDir,
348
+ replaces: 'tokens',
349
+ extends: 'tokens',
350
+ }),
351
+ ).rejects.toThrow(/not both/);
352
+ });
353
+
354
+ it.each([
355
+ ['my--guide', 'My Guide'],
356
+ ['a-_-b', 'A B'],
357
+ ['___', '___'],
358
+ ])(
359
+ 'accepts topic name %s without crashing title generation',
360
+ async (name, title) => {
361
+ setup();
362
+ await integrationAdd('doc', name, {cwd: tmpDir});
363
+ expect(
364
+ fs.readFileSync(path.join(tmpDir, 'docs', `${name}.doc.mjs`), 'utf-8'),
365
+ ).toContain(`title: '${title}'`);
366
+ },
367
+ );
368
+
369
+ it('rejects an unsafe replacement topic before writing source', async () => {
370
+ setup();
371
+ await expect(
372
+ integrationAdd('doc', 'my-guide', {
373
+ cwd: tmpDir,
374
+ replaces: "topic'; process.exit(1); //",
375
+ }),
376
+ ).rejects.toThrow(/--replaces/);
377
+ expect(fs.existsSync(path.join(tmpDir, 'docs'))).toBe(false);
378
+ });
379
+ });
380
+
381
+ // ── TEMPLATE ────────────────────────────────────────────────────────
382
+
383
+ describe('integrationAdd template', () => {
384
+ it('writes a valid page template with receipt', async () => {
385
+ setup();
386
+ const result = await integrationAdd('template', 'my-widget', {
387
+ cwd: tmpDir,
388
+ });
389
+
390
+ expect(result.data.kind).toBe('template');
391
+ expect(result.data.name).toBe('my-widget');
392
+ expect(result.data.root).toEqual({path: './templates', created: true});
393
+ expect(result.data.files).toContain('templates/my-widget.template.mjs');
394
+ expect(result.data.files).toContain('templates/my-widget.tsx');
395
+
396
+ const spec = fs.readFileSync(
397
+ path.join(tmpDir, 'templates/my-widget.template.mjs'),
398
+ 'utf-8',
399
+ );
400
+ expect(spec).toContain("type: 'page'");
401
+ expect(spec).toContain("name: 'my-widget'");
402
+
403
+ expect(fs.existsSync(path.join(tmpDir, 'templates/my-widget.tsx'))).toBe(
404
+ true,
405
+ );
406
+
407
+ const manifest = fs.readFileSync(
408
+ path.join(tmpDir, 'astryx.integration.mjs'),
409
+ 'utf-8',
410
+ );
411
+ expect(manifest).toContain("templates: './templates'");
412
+ });
413
+
414
+ it('publishes generated template source in an existing exports map', async () => {
415
+ setup({exports: './index.mjs'});
416
+
417
+ await integrationAddTemplate('my-widget', {cwd: tmpDir, type: 'page'});
418
+
419
+ const pkg = JSON.parse(
420
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
421
+ );
422
+ expect(pkg.exports).toEqual({
423
+ '.': './index.mjs',
424
+ './templates/my-widget.tsx': './templates/my-widget.tsx',
425
+ });
426
+ });
427
+
428
+ it('supports block type', async () => {
429
+ setup();
430
+ const result = await integrationAdd('template', 'my-card', {
431
+ cwd: tmpDir,
432
+ templateType: 'block',
433
+ });
434
+ const spec = fs.readFileSync(
435
+ path.join(tmpDir, 'templates/my-card.template.mjs'),
436
+ 'utf-8',
437
+ );
438
+ expect(spec).toContain("type: 'block'");
439
+ });
440
+
441
+ it('rejects an invalid template type', async () => {
442
+ setup();
443
+ await expect(
444
+ integrationAdd('template', 'my-widget', {
445
+ cwd: tmpDir,
446
+ templateType: /** @type {any} */ ('invalid'),
447
+ }),
448
+ ).rejects.toThrow(/must be "page" or "block"/);
449
+ });
450
+ });
451
+
452
+ // ── CODEMOD ─────────────────────────────────────────────────────────
453
+
454
+ describe('integrationAdd codemod', () => {
455
+ it('writes a valid identity codemod under the version folder', async () => {
456
+ setup();
457
+ const result = await integrationAdd('codemod', 'rename-widget', {
458
+ cwd: tmpDir,
459
+ to: '1.0.0',
460
+ });
461
+
462
+ expect(result.data.kind).toBe('codemod');
463
+ expect(result.data.name).toBe('rename-widget');
464
+ expect(result.data.root).toEqual({path: './codemods', created: true});
465
+ expect(result.data.files).toContain('codemods/1.0.0/rename-widget.mjs');
466
+
467
+ const codemod = fs.readFileSync(
468
+ path.join(tmpDir, 'codemods/1.0.0/rename-widget.mjs'),
469
+ 'utf-8',
470
+ );
471
+ expect(codemod).toContain("type: 'code'");
472
+ expect(codemod).toContain('transform(file, api)');
473
+ expect(codemod).toContain('return file.source');
474
+
475
+ const manifest = fs.readFileSync(
476
+ path.join(tmpDir, 'astryx.integration.mjs'),
477
+ 'utf-8',
478
+ );
479
+ expect(manifest).toContain("codemods: './codemods'");
480
+ });
481
+
482
+ it('requires --to as valid semver', async () => {
483
+ setup();
484
+ await expect(
485
+ integrationAdd('codemod', 'rename-widget', {cwd: tmpDir}),
486
+ ).rejects.toThrow(/--to is required/);
487
+ await expect(
488
+ integrationAdd('codemod', 'rename-widget', {
489
+ cwd: tmpDir,
490
+ to: 'v1',
491
+ }),
492
+ ).rejects.toThrow(/exact semver/);
493
+ });
494
+
495
+ it('accepts an exact semver prerelease target', async () => {
496
+ setup();
497
+ const result = await integrationAdd('codemod', 'rename-widget', {
498
+ cwd: tmpDir,
499
+ to: '1.0.0-beta.1',
500
+ });
501
+ expect(result.data.files).toContain(
502
+ 'codemods/1.0.0-beta.1/rename-widget.mjs',
503
+ );
504
+ });
505
+ });
506
+
507
+ // ── AGENT-DOC ───────────────────────────────────────────────────────
508
+
509
+ describe('integrationAdd agent-doc', () => {
510
+ it('adds a line to agentDocs.append and verifies', async () => {
511
+ setup();
512
+ const result = await integrationAdd(
513
+ 'agent-doc',
514
+ 'This integration provides MyWidget.',
515
+ {cwd: tmpDir},
516
+ );
517
+
518
+ expect(result.data.kind).toBe('agent-doc');
519
+ expect(result.data.name).toBe('This integration provides MyWidget.');
520
+ expect(result.data.root).toBeNull();
521
+ expect(result.data.files).toContain('astryx.integration.mjs');
522
+
523
+ const manifest = fs.readFileSync(
524
+ path.join(tmpDir, 'astryx.integration.mjs'),
525
+ 'utf-8',
526
+ );
527
+ expect(manifest).toContain('This integration provides MyWidget.');
528
+ expect(manifest).toContain('agentDocs');
529
+ expect(manifest).toContain('append');
530
+ });
531
+
532
+ it('converges: adding the same line twice is idempotent', async () => {
533
+ setup();
534
+ await integrationAdd('agent-doc', 'A line.', {cwd: tmpDir});
535
+ const result = await integrationAdd('agent-doc', 'A line.', {
536
+ cwd: tmpDir,
537
+ });
538
+ expect(result.data.written).toBe(false);
539
+ expect(result.data.files).toEqual([]);
540
+ });
541
+
542
+ it('appends to existing lines', async () => {
543
+ setup({
544
+ manifest:
545
+ "export default {\n agentDocs: {\n append: ['Line one.'],\n },\n};\n",
546
+ });
547
+ await integrationAdd('agent-doc', 'Line two.', {cwd: tmpDir});
548
+ const manifest = fs.readFileSync(
549
+ path.join(tmpDir, 'astryx.integration.mjs'),
550
+ 'utf-8',
551
+ );
552
+ expect(manifest).toContain('Line one.');
553
+ expect(manifest).toContain('Line two.');
554
+ });
555
+
556
+ it('creates the manifest when none exists', async () => {
557
+ setupBare();
558
+ await integrationAdd('agent-doc', 'A line.', {cwd: tmpDir});
559
+ expect(fs.existsSync(path.join(tmpDir, 'astryx.integration.mjs'))).toBe(
560
+ true,
561
+ );
562
+ const manifest = fs.readFileSync(
563
+ path.join(tmpDir, 'astryx.integration.mjs'),
564
+ 'utf-8',
565
+ );
566
+ expect(manifest).toContain('A line.');
567
+ });
568
+
569
+ it('rejects a blank line', async () => {
570
+ setup();
571
+ await expect(
572
+ integrationAdd('agent-doc', ' ', {cwd: tmpDir}),
573
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
574
+ });
575
+
576
+ it('adds the manifest to an existing package files allowlist', async () => {
577
+ setup({files: ['dist']});
578
+ await integrationAdd('agent-doc', 'A line.', {cwd: tmpDir});
579
+ const pkg = JSON.parse(
580
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
581
+ );
582
+ expect(pkg.files).toEqual(['dist', 'astryx.integration.mjs']);
583
+ });
584
+
585
+ it('refuses invalid existing agent-doc state instead of deleting it', async () => {
586
+ const manifest =
587
+ "export default {agentDocs: {append: [' line with spaces ']}};\n";
588
+ setup({manifest});
589
+ await expect(
590
+ integrationAdd('agent-doc', 'A new line.', {cwd: tmpDir}),
591
+ ).rejects.toThrow(/Cannot update agentDocs/);
592
+ expect(
593
+ fs.readFileSync(path.join(tmpDir, 'astryx.integration.mjs'), 'utf-8'),
594
+ ).toBe(manifest);
595
+ });
596
+
597
+ it('preserves comments attached to existing agent-doc state', async () => {
598
+ setup({
599
+ manifest:
600
+ "export default {\n // Keep this owner note.\n agentDocs: {append: ['Line one.']},\n};\n",
601
+ });
602
+ await integrationAdd('agent-doc', 'Line two.', {cwd: tmpDir});
603
+ const manifest = fs.readFileSync(
604
+ path.join(tmpDir, 'astryx.integration.mjs'),
605
+ 'utf-8',
606
+ );
607
+ expect(manifest).toContain('// Keep this owner note.');
608
+ expect(manifest).toContain('Line one.');
609
+ expect(manifest).toContain('Line two.');
610
+ });
611
+
612
+ it('refuses non-static agent-doc state without changing it', async () => {
613
+ const manifest =
614
+ "const docs = {append: ['Line one.']};\nexport default {agentDocs: docs};\n";
615
+ setup({manifest});
616
+ await expect(
617
+ integrationAdd('agent-doc', 'Line two.', {cwd: tmpDir}),
618
+ ).rejects.toThrow(/not a static object literal/);
619
+ expect(
620
+ fs.readFileSync(path.join(tmpDir, 'astryx.integration.mjs'), 'utf-8'),
621
+ ).toBe(manifest);
622
+ });
623
+
624
+ it('refuses a runtime-computed manifest without changing it', async () => {
625
+ const manifest =
626
+ "function makeManifest() { return {agentDocs: {append: ['Line one.']}}; }\nexport default makeManifest();\n";
627
+ setup({manifest});
628
+ await expect(
629
+ integrationAdd('agent-doc', 'Line two.', {cwd: tmpDir}),
630
+ ).rejects.toThrow(/default export is not a static object literal/);
631
+ expect(
632
+ fs.readFileSync(path.join(tmpDir, 'astryx.integration.mjs'), 'utf-8'),
633
+ ).toBe(manifest);
634
+ });
635
+
636
+ it('dry-run predicts the same files as the real write', async () => {
637
+ setup({files: ['dist']});
638
+ const plan = await integrationAdd('agent-doc', 'A line.', {
639
+ cwd: tmpDir,
640
+ dryRun: true,
641
+ });
642
+ const written = await integrationAdd('agent-doc', 'A line.', {cwd: tmpDir});
643
+ expect(written.data.files).toEqual(plan.data.files);
644
+ });
645
+
646
+ it('dry-run predicts without writing', async () => {
647
+ setup();
648
+ const before = fs.readFileSync(
649
+ path.join(tmpDir, 'astryx.integration.mjs'),
650
+ 'utf-8',
651
+ );
652
+ const result = await integrationAdd('agent-doc', 'A line.', {
653
+ cwd: tmpDir,
654
+ dryRun: true,
655
+ });
656
+ expect(result.data.written).toBe(false);
657
+ expect(result.data.dryRun).toBe(true);
658
+ expect(
659
+ fs.readFileSync(path.join(tmpDir, 'astryx.integration.mjs'), 'utf-8'),
660
+ ).toBe(before);
661
+ });
662
+ });
663
+
664
+ // ── CROSS-KIND: custom root preservation ────────────────────────────
665
+
666
+ describe('custom root preservation', () => {
667
+ it('uses an existing custom root from the manifest', async () => {
668
+ setup({manifest: "export default {\n components: './src/ui',\n};\n"});
669
+ const result = await integrationAdd('component', 'MyWidget', {
670
+ cwd: tmpDir,
671
+ });
672
+ expect(result.data.root.path).toBe('./src/ui');
673
+ expect(fs.existsSync(path.join(tmpDir, 'src/ui/MyWidget.doc.mjs'))).toBe(
674
+ true,
675
+ );
676
+ });
677
+ });
678
+
679
+ describe('public per-kind APIs', () => {
680
+ it('exposes narrow functions for every non-theme contribution kind', async () => {
681
+ setup();
682
+ const results = await Promise.all([
683
+ integrationAddComponent('MyWidget', {cwd: tmpDir, dryRun: true}),
684
+ integrationAddDoc('my-guide', {cwd: tmpDir, dryRun: true}),
685
+ integrationAddTemplate('my-page', {
686
+ cwd: tmpDir,
687
+ dryRun: true,
688
+ type: 'page',
689
+ }),
690
+ integrationAddCodemod('rename-widget', {
691
+ cwd: tmpDir,
692
+ dryRun: true,
693
+ to: '1.0.0',
694
+ }),
695
+ integrationAddAgentDoc('Use MyWidget.', {cwd: tmpDir, dryRun: true}),
696
+ ]);
697
+
698
+ expect(results.map(result => result.data.kind)).toEqual([
699
+ 'component',
700
+ 'doc',
701
+ 'template',
702
+ 'codemod',
703
+ 'agent-doc',
704
+ ]);
705
+ });
706
+ });
707
+
708
+ describe('public dispatcher', () => {
709
+ it('delegates theme authoring to the theme-specific implementation', async () => {
710
+ setup();
711
+ const result = await integrationAdd('theme', 'ocean', {cwd: tmpDir});
712
+ expect(result.data).toMatchObject({kind: 'theme', name: 'ocean'});
713
+ expect(result.data.files).toContain('themes/ocean/oceanTheme.ts');
714
+ });
715
+
716
+ it('refuses a kind-specific option on the wrong kind', async () => {
717
+ setup();
718
+ await expect(
719
+ integrationAdd('component', 'MyWidget', {
720
+ cwd: tmpDir,
721
+ to: '1.0.0',
722
+ }),
723
+ ).rejects.toThrow(/does not apply/);
724
+ expect(fs.existsSync(path.join(tmpDir, 'components'))).toBe(false);
725
+ });
726
+
727
+ it('names every supported kind when the kind is unknown', async () => {
728
+ setup();
729
+ await expect(
730
+ integrationAdd(/** @type {any} */ ('plugin'), 'thing', {cwd: tmpDir}),
731
+ ).rejects.toThrow(/component, doc, template, codemod, agent-doc, or theme/);
732
+ });
733
+ });