@astryxdesign/cli 0.7.6-canary.0d71e8d → 0.7.6-canary.0dbd1bd

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 (500) hide show
  1. package/assets/docs/motion.doc.mjs +1 -1
  2. package/foundation/discovery/package-tsconfig.mjs +34 -0
  3. package/package.json +24 -10
  4. package/api/api-docs-parse.test.mjs +0 -47
  5. package/api/blog/_adapter.test.mjs +0 -183
  6. package/api/blog/blog.test.mjs +0 -144
  7. package/api/blog/detail/detail.test.mjs +0 -118
  8. package/api/blog/list/list.test.mjs +0 -81
  9. package/api/build/blocks/blocks.test.mjs +0 -238
  10. package/api/build/build.test.mjs +0 -569
  11. package/api/build/kit/answer.test.mjs +0 -108
  12. package/api/build/kit/rank.test.mjs +0 -380
  13. package/api/build/kit/weights.test.mjs +0 -286
  14. package/api/build/tree.test.mjs +0 -185
  15. package/api/component/component-replacement.test.mjs +0 -616
  16. package/api/component/component.test.mjs +0 -532
  17. package/api/component/doc-links.test.mjs +0 -419
  18. package/api/component/integration-export-name.test.mjs +0 -644
  19. package/api/component/integration-import-agreement.test.mjs +0 -474
  20. package/api/discover/_adapter.test.mjs +0 -839
  21. package/api/discover/_catalog-view.test.mjs +0 -129
  22. package/api/discover/_package-scanner.test.mjs +0 -117
  23. package/api/discover/detail/detail.test.mjs +0 -145
  24. package/api/discover/detail/doc/doc.test.mjs +0 -93
  25. package/api/discover/detail/item/item.test.mjs +0 -75
  26. package/api/discover/discover.test.mjs +0 -100
  27. package/api/discover/list/list.test.mjs +0 -107
  28. package/api/discover/search/search.test.mjs +0 -319
  29. package/api/docs/compiled-topics.test.mjs +0 -94
  30. package/api/docs/detail/section/section.test.mjs +0 -92
  31. package/api/docs/docOverlays.test.mjs +0 -189
  32. package/api/docs/docs-homes.test.mjs +0 -127
  33. package/api/docs/docs.depth.test.mjs +0 -134
  34. package/api/docs/docs.test.mjs +0 -315
  35. package/api/docs/guide-route-targets.test.mjs +0 -1002
  36. package/api/docs/index/index.test.mjs +0 -67
  37. package/api/docs/integration-tree.test.mjs +0 -616
  38. package/api/docs/integrationDocs.test.mjs +0 -546
  39. package/api/docs/namespace-section.test.mjs +0 -260
  40. package/api/docs/react-version-sync.test.mjs +0 -79
  41. package/api/docs/reference-blocks.test.mjs +0 -404
  42. package/api/docs/token-tables.test.mjs +0 -93
  43. package/api/doctor/built-checks.test.mjs +0 -537
  44. package/api/doctor/doctor.test.mjs +0 -1651
  45. package/api/doctor/icon-sets.test.mjs +0 -111
  46. package/api/doctor/release-checks.test.mjs +0 -156
  47. package/api/doctor/theme-checks.test.mjs +0 -884
  48. package/api/gap-report/gap-report.test.mjs +0 -1549
  49. package/api/hook/detail/detail.test.mjs +0 -53
  50. package/api/hook/detail/params/params.test.mjs +0 -39
  51. package/api/hook/hook.test.mjs +0 -75
  52. package/api/icon/all-or-nothing.test.mjs +0 -283
  53. package/api/icon/error-codes.test.mjs +0 -341
  54. package/api/icon/experimental-markers.test.mjs +0 -93
  55. package/api/icon/icon.test.mjs +0 -506
  56. package/api/icon/new-definition/new-definition.undo.test.mjs +0 -97
  57. package/api/icon/new-set/new-set.test.mjs +0 -398
  58. package/api/icon/option-pairs.test.mjs +0 -368
  59. package/api/init/init.test.mjs +0 -319
  60. package/api/init/remove/remove.test.mjs +0 -124
  61. package/api/init/user/user.test.mjs +0 -232
  62. package/api/integration/add-contribution.component-names.test.mjs +0 -186
  63. package/api/integration/add-contribution.test.mjs +0 -990
  64. package/api/integration/add-helpers.test.mjs +0 -161
  65. package/api/integration/add-theme.test.mjs +0 -676
  66. package/api/integration/authoring-checks.test.mjs +0 -1691
  67. package/api/integration/check/check.test.mjs +0 -538
  68. package/api/integration/doc-stability.test.mjs +0 -216
  69. package/api/integration/example-checks.no-npm.test.mjs +0 -140
  70. package/api/integration/example-checks.test.mjs +0 -776
  71. package/api/integration/integration-block-exports.test.mjs +0 -248
  72. package/api/integration/pack-check.component-replaces.test.mjs +0 -126
  73. package/api/integration/pack-check.lifecycle-output.test.mjs +0 -149
  74. package/api/integration/pack-check.test.mjs +0 -2512
  75. package/api/integration/public-api.test.mjs +0 -21
  76. package/api/integration/template-conflict-compatibility.test.mjs +0 -73
  77. package/api/integration/validate-installed-icon-sets.test.mjs +0 -67
  78. package/api/integration/validate-integration-case-disk.test.mjs +0 -123
  79. package/api/integration/validate-integration-fixes.test.mjs +0 -1457
  80. package/api/integration/validate-integration-gaps.test.mjs +0 -2007
  81. package/api/integration/validate-integration.test.mjs +0 -835
  82. package/api/integration/validate-unread-theme-folders.test.mjs +0 -111
  83. package/api/json/envelope-types.test.mjs +0 -76
  84. package/api/json/parse.test.mjs +0 -76
  85. package/api/render/render.test.mjs +0 -1155
  86. package/api/search/_adapter.test.mjs +0 -192
  87. package/api/search/_doc-searcher.test.mjs +0 -36
  88. package/api/search/_entries.test.mjs +0 -48
  89. package/api/search/_main-searcher.test.mjs +0 -106
  90. package/api/search/_order.test.mjs +0 -72
  91. package/api/search/_template-searcher.test.mjs +0 -40
  92. package/api/search/search-return-type.test.mjs +0 -54
  93. package/api/search/search.domain-priority.test.mjs +0 -351
  94. package/api/search/search.family-members.test.mjs +0 -124
  95. package/api/search/search.family-word.test.mjs +0 -146
  96. package/api/search/search.integration-block.test.mjs +0 -100
  97. package/api/search/search.integration-check.test.mjs +0 -24
  98. package/api/search/search.test.mjs +0 -1007
  99. package/api/search/search.tie-order.test.mjs +0 -39
  100. package/api/search/tree.test.mjs +0 -66
  101. package/api/swizzle/_github.test.mjs +0 -53
  102. package/api/swizzle/copy/copy.test.mjs +0 -60
  103. package/api/swizzle/swizzle.test.mjs +0 -157
  104. package/api/template/cdn/cdn.test.mjs +0 -108
  105. package/api/template/checkout-wizard.test.mjs +0 -87
  106. package/api/template/copy/copy.receipt.test.mjs +0 -77
  107. package/api/template/copy/copy.test.mjs +0 -77
  108. package/api/template/data-token-fallbacks.test.mjs +0 -85
  109. package/api/template/discover-integration-templates.test.mjs +0 -56
  110. package/api/template/form-wizard-dialog.test.mjs +0 -47
  111. package/api/template/inline-wizard-template.test.mjs +0 -24
  112. package/api/template/list/list.test.mjs +0 -52
  113. package/api/template/show/show.test.mjs +0 -76
  114. package/api/template/table-filter-view-tabs.test.mjs +0 -45
  115. package/api/template/table-floating-bulk-actions.test.mjs +0 -66
  116. package/api/template/template-integration.test.mjs +0 -1274
  117. package/api/template/template-suffix.test.mjs +0 -286
  118. package/api/template/template.test.mjs +0 -222
  119. package/api/template/tokenizer-showcase.test.mjs +0 -47
  120. package/api/template/unknown-name.test.mjs +0 -63
  121. package/api/theme/add/add.test.mjs +0 -363
  122. package/api/theme/add/add.types.test.mjs +0 -150
  123. package/api/theme/build/build.adaptation-core-compat.test.mjs +0 -394
  124. package/api/theme/build/build.adaptation-enrollment.test.mjs +0 -219
  125. package/api/theme/build/build.core-on-demand.test.mjs +0 -113
  126. package/api/theme/build/build.family.test.mjs +0 -503
  127. package/api/theme/build/build.font-warning.test.mjs +0 -170
  128. package/api/theme/build/build.heading-core-compat.test.mjs +0 -68
  129. package/api/theme/build/build.icon-entry-variants.test.mjs +0 -134
  130. package/api/theme/build/build.icon-function-entries.test.mjs +0 -499
  131. package/api/theme/build/build.icon-lineage.test.mjs +0 -117
  132. package/api/theme/build/build.icon-preservation.test.mjs +0 -639
  133. package/api/theme/build/build.icon-variants.test.mjs +0 -105
  134. package/api/theme/build/build.icons-specifier.test.mjs +0 -149
  135. package/api/theme/build/build.packed-old-core.test.mjs +0 -1512
  136. package/api/theme/build/build.project-core.test.mjs +0 -220
  137. package/api/theme/build/build.public-component-vars.test.mjs +0 -151
  138. package/api/theme/build/build.receipt-doc.test.mjs +0 -111
  139. package/api/theme/build/build.rollback.test.mjs +0 -148
  140. package/api/theme/build/build.test.mjs +0 -1258
  141. package/api/theme/build/font-warning.test.mjs +0 -268
  142. package/api/theme/eject/eject.binary.test.mjs +0 -90
  143. package/api/theme/eject/eject.copy-compat.test.mjs +0 -168
  144. package/api/theme/eject/eject.rollback.test.mjs +0 -158
  145. package/api/theme/eject/eject.staging.test.mjs +0 -83
  146. package/api/theme/eject/eject.test.mjs +0 -160
  147. package/api/theme/integration-themes.test.mjs +0 -218
  148. package/api/theme/list/list.test.mjs +0 -271
  149. package/api/theme/palette/generate/generate.test.mjs +0 -445
  150. package/api/theme/palette/generate/generator.test.mjs +0 -385
  151. package/api/theme/palette/generate/preview.test.mjs +0 -55
  152. package/api/theme/remove/remove.test.mjs +0 -94
  153. package/api/theme/targets/targets.test.mjs +0 -91
  154. package/api/theme/template/template.test.mjs +0 -102
  155. package/api/theme/use/use.test.mjs +0 -98
  156. package/api/upgrade/list/list.test.mjs +0 -73
  157. package/api/upgrade/project-context.test.mjs +0 -272
  158. package/api/upgrade/provider-agreement.test.mjs +0 -152
  159. package/api/upgrade/registry/registry.test.mjs +0 -911
  160. package/api/upgrade/run/authoring-codemod-reachable.test.mjs +0 -99
  161. package/api/upgrade/run/cli-behind-core.test.mjs +0 -438
  162. package/api/upgrade/run/failure-receipt.test.mjs +0 -212
  163. package/api/upgrade/run/files-changed.test.mjs +0 -111
  164. package/api/upgrade/run/outcomes.test.mjs +0 -646
  165. package/api/upgrade/run/run.test.mjs +0 -511
  166. package/api/upgrade/upgrade.test.mjs +0 -594
  167. package/assets/codemods/__tests__/registry.test.mjs +0 -77
  168. package/assets/codemods/__tests__/rename-imperative-ref-to-handleRef.test.mjs +0 -65
  169. package/assets/codemods/__tests__/rename-isStreaming-to-isStopShown.test.mjs +0 -58
  170. package/assets/codemods/__tests__/rename-section-wash-to-muted.test.mjs +0 -103
  171. package/assets/codemods/__tests__/runner.symlinks.test.mjs +0 -205
  172. package/assets/codemods/__tests__/runner.test.mjs +0 -559
  173. package/assets/codemods/__tests__/runner.unparseable.test.mjs +0 -457
  174. package/assets/codemods/__tests__/toolbar-density-to-size.test.mjs +0 -69
  175. package/assets/codemods/__tests__/validation.test.mjs +0 -108
  176. package/assets/codemods/file-count.test.mjs +0 -163
  177. package/assets/codemods/integration-discovery.test.mjs +0 -360
  178. package/assets/codemods/integration-runner.protection.test.mjs +0 -206
  179. package/assets/codemods/outcome.test.mjs +0 -40
  180. package/assets/codemods/term-log.test.mjs +0 -80
  181. package/assets/codemods/transform-prop.test.mjs +0 -130
  182. package/assets/codemods/transforms/v0.0.10/__tests__/remove-size-props.test.mjs +0 -144
  183. package/assets/codemods/transforms/v0.0.12/__tests__/add-is-icon-only.test.mjs +0 -193
  184. package/assets/codemods/transforms/v0.0.13/__tests__/icon-name-deprecations.test.mjs +0 -81
  185. package/assets/codemods/transforms/v0.0.13/__tests__/rename-attachments-to-drawer.test.mjs +0 -126
  186. package/assets/codemods/transforms/v0.0.14/__tests__/rename-action-props.test.mjs +0 -129
  187. package/assets/codemods/transforms/v0.0.14/__tests__/rename-status-variants.test.mjs +0 -126
  188. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-item-children-to-endcontent.test.mjs +0 -95
  189. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-selector-children-to-render-option.test.mjs +0 -109
  190. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-theme-selectors-to-data-attrs.test.mjs +0 -44
  191. package/assets/codemods/transforms/v0.0.15/__tests__/rename-date-picker-to-input.test.mjs +0 -110
  192. package/assets/codemods/transforms/v0.0.15/__tests__/rename-stack-element-to-as.test.mjs +0 -71
  193. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-badge-dot-to-statusdot.test.mjs +0 -137
  194. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-gap-to-numeric.test.mjs +0 -161
  195. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-isFullBleed-to-padding.test.mjs +0 -137
  196. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-useXDSIcon-to-getIcon.test.mjs +0 -110
  197. package/assets/codemods/transforms/v0.0.2/__tests__/rename-banner-endButton-to-endContent.test.mjs +0 -61
  198. package/assets/codemods/transforms/v0.0.2/__tests__/rename-form-tooltip-startIcon.test.mjs +0 -130
  199. package/assets/codemods/transforms/v0.0.2/__tests__/rename-isShown-to-isOpen.test.mjs +0 -89
  200. package/assets/codemods/transforms/v0.0.2/__tests__/rename-selector-items-to-options.test.mjs +0 -74
  201. package/assets/codemods/transforms/v0.0.2/__tests__/rename-sidenav-header-to-heading.test.mjs +0 -140
  202. package/assets/codemods/transforms/v0.0.2/__tests__/rename-topnav-title-to-heading.test.mjs +0 -116
  203. package/assets/codemods/transforms/v0.0.2/__tests__/unify-uncontrolled-to-defaultX.test.mjs +0 -79
  204. package/assets/codemods/transforms/v0.0.2/__tests__/unify-visibility-to-onOpenChange.test.mjs +0 -130
  205. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-badge-children-to-label.test.mjs +0 -46
  206. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-collapse-to-collapsible.test.mjs +0 -72
  207. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-radius-tokens.test.mjs +0 -98
  208. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-shadow-tokens.test.mjs +0 -117
  209. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-skeleton-radius.test.mjs +0 -75
  210. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-token-names.test.mjs +0 -275
  211. package/assets/codemods/transforms/v0.0.7/__tests__/rename-banner-variant-to-container.test.mjs +0 -85
  212. package/assets/codemods/transforms/v0.0.8/__tests__/migrate-token-renames.test.mjs +0 -327
  213. package/assets/codemods/transforms/v0.0.8/__tests__/rename-endslot-to-endcontent.test.mjs +0 -98
  214. package/assets/codemods/transforms/v0.1.0/__tests__/drop-xds-prefix-imports.test.mjs +0 -460
  215. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-css-surfaces.test.mjs +0 -103
  216. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-declare-module.test.mjs +0 -61
  217. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-module-specifiers.test.mjs +0 -123
  218. package/assets/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjs +0 -104
  219. package/assets/codemods/transforms/v0.1.2/__tests__/rename-text-color-active-to-accent.test.mjs +0 -120
  220. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +0 -574
  221. package/assets/codemods/transforms/v0.1.5/__tests__/rename-switch-label-spacing-default-to-hug.test.mjs +0 -93
  222. package/assets/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +0 -120
  223. package/assets/codemods/transforms/v0.1.7/__tests__/rename-table-renderprops-styles-to-xstyle.test.mjs +0 -112
  224. package/assets/codemods/transforms/v0.1.8/__tests__/rename-avatar-size-scale.test.mjs +0 -129
  225. package/assets/codemods/transforms/v0.2.0/__tests__/remove-tablist-orientation.test.mjs +0 -81
  226. package/assets/codemods/transforms/v0.2.1/__tests__/migrate-dialog-position-to-logical.test.mjs +0 -119
  227. package/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjs +0 -296
  228. package/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.tsc.test.mjs +0 -139
  229. package/assets/codemods/transforms/v0.3.0/__tests__/migrate-authoring-imports.test.mjs +0 -80
  230. package/assets/codemods/transforms/v0.3.0/__tests__/migrate-grid-minchildwidth-to-columns.test.mjs +0 -82
  231. package/assets/codemods/transforms/v0.3.0/__tests__/next-codemods.test.mjs +0 -64
  232. package/assets/codemods/transforms/v0.3.0/__tests__/rename-authoring-doctypes.test.mjs +0 -94
  233. package/assets/codemods/transforms/v0.3.0/__tests__/rename-radiogroup-arialabel-to-label.test.mjs +0 -86
  234. package/assets/codemods/transforms/v0.3.0/__tests__/unwrap-authoring-factories.test.mjs +0 -170
  235. package/assets/codemods/transforms/v0.4.0/__tests__/migrate-table-rowexpansion-to-tree.test.mjs +0 -201
  236. package/assets/codemods/transforms/v0.4.0/__tests__/next-codemods.test.mjs +0 -154
  237. package/assets/codemods/transforms/v0.5.0/__tests__/next-codemods.test.mjs +0 -127
  238. package/assets/codemods/transforms/v0.6.0/__tests__/migrate-astryx-theme-selectors-to-data-attrs.test.mjs +0 -398
  239. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +0 -270
  240. package/assets/codemods/transforms/v0.6.4/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -63
  241. package/assets/codemods/transforms/v0.6.4/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -220
  242. package/assets/codemods/transforms/v0.6.7/__tests__/migrate-copied-themes-to-descriptors.test.mjs +0 -129
  243. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +0 -523
  244. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-field-input-styling.test.mjs +0 -108
  245. package/assets/codemods/transforms/v0.7.0/__tests__/preserve-bottom-sheet-content-padding.test.mjs +0 -178
  246. package/assets/codemods/transforms/v0.7.0/__tests__/rename-empty-search-results-text.test.mjs +0 -202
  247. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +0 -168
  248. package/assets/codemods/transforms/v0.7.2/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +0 -120
  249. package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +0 -130
  250. package/authoring/_shared/errors.test.mjs +0 -49
  251. package/authoring/codemod/parse.test.mjs +0 -99
  252. package/authoring/config/debug-composition.test.mjs +0 -92
  253. package/authoring/config/parse.test.mjs +0 -121
  254. package/authoring/debug/parse.test.mjs +0 -187
  255. package/authoring/discover/parse.test.mjs +0 -158
  256. package/authoring/doctypes/doc-stability-types.test.mjs +0 -91
  257. package/authoring/doctypes/doctypes-new.test.mjs +0 -162
  258. package/authoring/doctypes/icon-definition/parse.test.mjs +0 -78
  259. package/authoring/doctypes/icon-set/icon-names.test.mjs +0 -26
  260. package/authoring/doctypes/icon-set/parse.test.mjs +0 -179
  261. package/authoring/doctypes/load-contract.test.mjs +0 -246
  262. package/authoring/doctypes/namespace/parse.test.mjs +0 -163
  263. package/authoring/doctypes/parse.test.mjs +0 -422
  264. package/authoring/doctypes/template/parse.test.mjs +0 -198
  265. package/authoring/gap-report/parse.test.mjs +0 -172
  266. package/authoring/integration/parse.test.mjs +0 -184
  267. package/authoring/shadcn/receipt.test.mjs +0 -187
  268. package/authoring/shadcn/source-variants.test.mjs +0 -120
  269. package/clients/cli/__tests__/cliManifest.test.ts +0 -37
  270. package/clients/cli/cli-command.test.mjs +0 -166
  271. package/clients/cli/cli-exit-codes.test.mjs +0 -163
  272. package/clients/cli/command-load-failure.test.mjs +0 -83
  273. package/clients/cli/command-result-coverage.test.mjs +0 -136
  274. package/clients/cli/commands/blog.test.mjs +0 -138
  275. package/clients/cli/commands/build-theme.adaptations.test.mjs +0 -773
  276. package/clients/cli/commands/build-theme.ascii-output.test.mjs +0 -198
  277. package/clients/cli/commands/build-theme.batch-report.test.mjs +0 -349
  278. package/clients/cli/commands/build-theme.color-scheme.test.mjs +0 -136
  279. package/clients/cli/commands/build-theme.data-tokens.test.mjs +0 -92
  280. package/clients/cli/commands/build-theme.flag-docs.test.mjs +0 -110
  281. package/clients/cli/commands/build-theme.font-warning.test.mjs +0 -170
  282. package/clients/cli/commands/build-theme.icons-specifier.test.mjs +0 -350
  283. package/clients/cli/commands/build-theme.import-path.test.mjs +0 -103
  284. package/clients/cli/commands/build-theme.multi.test.mjs +0 -148
  285. package/clients/cli/commands/build-theme.outside-project.test.mjs +0 -140
  286. package/clients/cli/commands/build-theme.path-safety.test.mjs +0 -398
  287. package/clients/cli/commands/build-theme.prose.test.mjs +0 -103
  288. package/clients/cli/commands/build-theme.registry.test.mjs +0 -160
  289. package/clients/cli/commands/build-theme.variants.test.mjs +0 -560
  290. package/clients/cli/commands/build-theme.watch.test.mjs +0 -320
  291. package/clients/cli/commands/build.error-codes.test.mjs +0 -50
  292. package/clients/cli/commands/build.exit-codes-doc.test.mjs +0 -54
  293. package/clients/cli/commands/build.playbook.test.mjs +0 -75
  294. package/clients/cli/commands/build.text-fields.test.mjs +0 -81
  295. package/clients/cli/commands/cli-postinstall.test.mjs +0 -90
  296. package/clients/cli/commands/component-batch.test.mjs +0 -341
  297. package/clients/cli/commands/component-ownership.test.mjs +0 -384
  298. package/clients/cli/commands/component-package.test.mjs +0 -169
  299. package/clients/cli/commands/component-replacement.text.test.mjs +0 -316
  300. package/clients/cli/commands/component-resolution.test.mjs +0 -204
  301. package/clients/cli/commands/component.test.mjs +0 -612
  302. package/clients/cli/commands/debug-result-summary.test.mjs +0 -214
  303. package/clients/cli/commands/detail-levels.test.mjs +0 -145
  304. package/clients/cli/commands/dialog-adaptive-template.test.mjs +0 -24
  305. package/clients/cli/commands/discover.broken-integration.test.mjs +0 -163
  306. package/clients/cli/commands/discover.components-flag.test.mjs +0 -97
  307. package/clients/cli/commands/discover.icon-sets.test.mjs +0 -133
  308. package/clients/cli/commands/discover.no-source.test.mjs +0 -490
  309. package/clients/cli/commands/discover.sources.test.mjs +0 -292
  310. package/clients/cli/commands/discover.text-projection.test.mjs +0 -103
  311. package/clients/cli/commands/docs.depth.test.mjs +0 -219
  312. package/clients/cli/commands/docs.test.mjs +0 -385
  313. package/clients/cli/commands/doctor-integration.package-json.test.mjs +0 -53
  314. package/clients/cli/commands/doctor-integration.test.mjs +0 -1483
  315. package/clients/cli/commands/doctor.test.mjs +0 -509
  316. package/clients/cli/commands/empty-argument.test.mjs +0 -16
  317. package/clients/cli/commands/external-showcase.test.mjs +0 -121
  318. package/clients/cli/commands/gap-report.test.mjs +0 -412
  319. package/clients/cli/commands/hook.text-projection.test.mjs +0 -45
  320. package/clients/cli/commands/icon-authoring.test.mjs +0 -2845
  321. package/clients/cli/commands/icon-options-wiring.test.mjs +0 -158
  322. package/clients/cli/commands/icon-sets-guide.test.mjs +0 -186
  323. package/clients/cli/commands/icon.test.mjs +0 -96
  324. package/clients/cli/commands/import-hint-correctness.test.mjs +0 -293
  325. package/clients/cli/commands/init.behavior.test.mjs +0 -434
  326. package/clients/cli/commands/init.flag-help.test.mjs +0 -151
  327. package/clients/cli/commands/init.next-steps.test.mjs +0 -41
  328. package/clients/cli/commands/integration-add.controls.test.mjs +0 -132
  329. package/clients/cli/commands/integration-authoring.test.mjs +0 -288
  330. package/clients/cli/commands/integration-check.test.mjs +0 -522
  331. package/clients/cli/commands/integration-real-world.test.mjs +0 -661
  332. package/clients/cli/commands/interactive-guard.test.mjs +0 -143
  333. package/clients/cli/commands/json-contract.test.mjs +0 -216
  334. package/clients/cli/commands/no-prompt-wording.test.mjs +0 -94
  335. package/clients/cli/commands/option-pair-refusals.test.mjs +0 -37
  336. package/clients/cli/commands/outside-project.test.mjs +0 -874
  337. package/clients/cli/commands/search.test.mjs +0 -514
  338. package/clients/cli/commands/setup-nudge.test.mjs +0 -280
  339. package/clients/cli/commands/silent-success-refusals.test.mjs +0 -15
  340. package/clients/cli/commands/swizzle.path-safety.test.mjs +0 -137
  341. package/clients/cli/commands/swizzle.routing.test.mjs +0 -342
  342. package/clients/cli/commands/template-cdn.behavior.test.mjs +0 -113
  343. package/clients/cli/commands/template.copy-receipt.test.mjs +0 -60
  344. package/clients/cli/commands/template.flag-help.test.mjs +0 -124
  345. package/clients/cli/commands/template.icons.test.mjs +0 -132
  346. package/clients/cli/commands/template.path-help.test.mjs +0 -40
  347. package/clients/cli/commands/template.path-safety.test.mjs +0 -82
  348. package/clients/cli/commands/template.show-media.test.mjs +0 -62
  349. package/clients/cli/commands/template.test.mjs +0 -62
  350. package/clients/cli/commands/text-json-parity.test.mjs +0 -850
  351. package/clients/cli/commands/theme-add-lifecycle.test.mjs +0 -228
  352. package/clients/cli/commands/theme-list.behavior.test.mjs +0 -51
  353. package/clients/cli/commands/theme-palette-generate.test.mjs +0 -154
  354. package/clients/cli/commands/theme-targets.behavior.test.mjs +0 -84
  355. package/clients/cli/commands/theme-template.behavior.test.mjs +0 -97
  356. package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -101
  357. package/clients/cli/commands/upgrade.config-ordering.test.mjs +0 -342
  358. package/clients/cli/commands/upgrade.file-protection.test.mjs +0 -404
  359. package/clients/cli/commands/upgrade.flag-help.test.mjs +0 -221
  360. package/clients/cli/commands/upgrade.hook-output.test.mjs +0 -89
  361. package/clients/cli/commands/upgrade.integration-policy.test.mjs +0 -581
  362. package/clients/cli/commands/upgrade.older-cli.test.mjs +0 -160
  363. package/clients/cli/commands/upgrade.outcomes.test.mjs +0 -350
  364. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +0 -97
  365. package/clients/cli/commands/upgrade.test.mjs +0 -361
  366. package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +0 -67
  367. package/clients/cli/commands/write-failure.test.mjs +0 -175
  368. package/clients/cli/e2e-smoke.test.mjs +0 -162
  369. package/clients/cli/error-envelope-code.test.mjs +0 -38
  370. package/clients/cli/formatters/index.test.mjs +0 -262
  371. package/clients/cli/latest-version-env.test.mjs +0 -50
  372. package/clients/cli/lib/cli-error.test.mjs +0 -206
  373. package/clients/cli/lib/component-format.test.mjs +0 -246
  374. package/clients/cli/lib/define-command.test.mjs +0 -103
  375. package/clients/cli/lib/doc-text-ascii.test.mjs +0 -85
  376. package/clients/cli/lib/exit-codes.test.mjs +0 -111
  377. package/clients/cli/lib/hook-format.test.mjs +0 -35
  378. package/clients/cli/lib/json-shim.test.mjs +0 -268
  379. package/clients/cli/lib/manifest.test.mjs +0 -346
  380. package/clients/cli/lib/parse-error-format.test.mjs +0 -81
  381. package/clients/cli/lib/resolve-theme.test.mjs +0 -543
  382. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +0 -1550
  383. package/foundation/agent-docs/agent-docs.test.mjs +0 -1937
  384. package/foundation/agent-docs/app-theme-workflow.test.mjs +0 -16
  385. package/foundation/agent-docs/computer-agent-text.test.mjs +0 -699
  386. package/foundation/config/config-cache.test.mjs +0 -83
  387. package/foundation/config/config-writer.test.mjs +0 -84
  388. package/foundation/config/integration-debug.test.mjs +0 -218
  389. package/foundation/config/project-themes.test.mjs +0 -119
  390. package/foundation/config/project.test.mjs +0 -931
  391. package/foundation/config/theme-private-vars.test.mjs +0 -76
  392. package/foundation/config/theme-state.test.mjs +0 -182
  393. package/foundation/debug/debug-fields.test.mjs +0 -327
  394. package/foundation/debug/integration-handlers.test.mjs +0 -267
  395. package/foundation/debug/on-event.test.mjs +0 -643
  396. package/foundation/debug/privacy-contract.test.mjs +0 -195
  397. package/foundation/debug/redact.test.mjs +0 -534
  398. package/foundation/discovery/authoring-self-docs.test.mjs +0 -202
  399. package/foundation/discovery/authoring-surface.test.mjs +0 -392
  400. package/foundation/discovery/cli-self-docs.test.mjs +0 -396
  401. package/foundation/discovery/component-discovery.export-names.test.mjs +0 -832
  402. package/foundation/discovery/component-discovery.importpath.test.mjs +0 -59
  403. package/foundation/discovery/component-discovery.test.mjs +0 -336
  404. package/foundation/discovery/component-loader.test.mjs +0 -190
  405. package/foundation/discovery/component-replacement.test.mjs +0 -520
  406. package/foundation/discovery/componentDocOverlay.test.mjs +0 -159
  407. package/foundation/discovery/copied-passages.test.mjs +0 -124
  408. package/foundation/discovery/doc-consistency.test.mjs +0 -347
  409. package/foundation/discovery/doc-fluff.test.mjs +0 -142
  410. package/foundation/discovery/doc-types.test.mjs +0 -774
  411. package/foundation/discovery/docs-discovery.test.mjs +0 -707
  412. package/foundation/discovery/docs-section-key.test.mjs +0 -246
  413. package/foundation/discovery/hook-discovery.test.mjs +0 -216
  414. package/foundation/discovery/icon-set-checks.test.mjs +0 -1018
  415. package/foundation/discovery/icon-set-discovery.test.mjs +0 -320
  416. package/foundation/discovery/icon-set-writer.test.mjs +0 -26
  417. package/foundation/discovery/integration-doc-files.test.mjs +0 -275
  418. package/foundation/discovery/module-exports.test.mjs +0 -209
  419. package/foundation/discovery/package-tsconfig.test.mjs +0 -210
  420. package/foundation/discovery/prop-drift.test.mjs +0 -2337
  421. package/foundation/discovery/runner-commands.test.mjs +0 -131
  422. package/foundation/discovery/stray-pointers.test.mjs +0 -92
  423. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +0 -284
  424. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +0 -94
  425. package/foundation/discovery/template-adapter.test.mjs +0 -223
  426. package/foundation/discovery/template-conflict-release.test.mjs +0 -40
  427. package/foundation/discovery/template-icons.test.mjs +0 -560
  428. package/foundation/discovery/template-needs.test.mjs +0 -306
  429. package/foundation/discovery/theme-discovery.test.mjs +0 -775
  430. package/foundation/discovery/theme-imports.test.mjs +0 -173
  431. package/foundation/discovery/theming-targets.test.mjs +0 -328
  432. package/foundation/discovery/type-match.test.mjs +0 -169
  433. package/foundation/discovery/type-text.test.mjs +0 -196
  434. package/foundation/discovery/unresolved-references.test.mjs +0 -567
  435. package/foundation/doc-compiler/bundle.test.mjs +0 -266
  436. package/foundation/doc-compiler/doc-compiler.test.mjs +0 -714
  437. package/foundation/doc-compiler/doc-loads.test.mjs +0 -1762
  438. package/foundation/doc-compiler/doc-syntax.test.mjs +0 -383
  439. package/foundation/doc-compiler/inputs.test.mjs +0 -298
  440. package/foundation/doc-compiler/links.test.mjs +0 -285
  441. package/foundation/doc-compiler/lower-doc.test.mjs +0 -495
  442. package/foundation/doc-compiler/read.test.mjs +0 -380
  443. package/foundation/doc-compiler/split-topic-keywords.test.mjs +0 -74
  444. package/foundation/doc-compiler/tree.test.mjs +0 -691
  445. package/foundation/env/cli-command.test.mjs +0 -129
  446. package/foundation/env/node-version.test.mjs +0 -103
  447. package/foundation/env/package-manager.global.test.mjs +0 -66
  448. package/foundation/env/package-manager.test.mjs +0 -910
  449. package/foundation/env/search-path.test.mjs +0 -122
  450. package/foundation/env/semver.test.mjs +0 -111
  451. package/foundation/env/user-dirs.test.mjs +0 -72
  452. package/foundation/env/user-settings.test.mjs +0 -64
  453. package/foundation/fs/file-protection.test.mjs +0 -250
  454. package/foundation/fs/listing-cache.test.mjs +0 -88
  455. package/foundation/fs/module-loader.stdout.test.mjs +0 -333
  456. package/foundation/fs/module-loader.test.mjs +0 -410
  457. package/foundation/fs/path-safety.test.mjs +0 -222
  458. package/foundation/fs/paths.test.mjs +0 -725
  459. package/foundation/fs/publish-file-eperm-mutation.test.mjs +0 -64
  460. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +0 -142
  461. package/foundation/fs/publish-file.test.mjs +0 -136
  462. package/foundation/fs/read-record.test.mjs +0 -164
  463. package/foundation/identity/provider-identity.test.mjs +0 -254
  464. package/foundation/integrations/autolink.test.mjs +0 -430
  465. package/foundation/integrations/cli-peer-version.test.mjs +0 -354
  466. package/foundation/integrations/cli-requirement.test.mjs +0 -383
  467. package/foundation/integrations/computer-integrations.test.mjs +0 -292
  468. package/foundation/integrations/contribution-inventory.test.mjs +0 -420
  469. package/foundation/integrations/integration-warnings.test.mjs +0 -191
  470. package/foundation/integrations/integrations.test.mjs +0 -818
  471. package/foundation/integrations/manifest-writer.test.mjs +0 -271
  472. package/foundation/integrations/provider-conflicts.test.mjs +0 -125
  473. package/foundation/integrations/provider-ledger.test.mjs +0 -275
  474. package/foundation/integrations/provider-resolution.test.mjs +0 -369
  475. package/foundation/integrations/public-imports.test.mjs +0 -1818
  476. package/foundation/release/cache.test.mjs +0 -923
  477. package/foundation/release/choose.test.mjs +0 -427
  478. package/foundation/release/global-state.test.mjs +0 -381
  479. package/foundation/release/handoff.e2e.test.mjs +0 -278
  480. package/foundation/release/notices.test.mjs +0 -586
  481. package/foundation/release/project.test.mjs +0 -288
  482. package/foundation/render/render.test.mjs +0 -117
  483. package/foundation/response/error-codes.test.mjs +0 -297
  484. package/foundation/response/json-contract.test.mjs +0 -235
  485. package/foundation/response/json-serialize.test.mjs +0 -66
  486. package/foundation/response/response-types.doc.test.mjs +0 -278
  487. package/foundation/route/route.test.mjs +0 -153
  488. package/foundation/runtime/hosted-runtime.test.mjs +0 -403
  489. package/foundation/runtime/package-set.test.mjs +0 -432
  490. package/foundation/text/copyright-header.test.mjs +0 -58
  491. package/foundation/text/levenshtein.test.mjs +0 -53
  492. package/foundation/text/string-utils.test.mjs +0 -175
  493. package/foundation/text/suggest-order.test.mjs +0 -312
  494. package/foundation/xle/browser-imports.test.mjs +0 -74
  495. package/foundation/xle/expand.test.mjs +0 -54
  496. package/foundation/xle/print.test.mjs +0 -50
  497. package/foundation/xle/registry.test.mjs +0 -28
  498. package/foundation/xle/xle.test.mjs +0 -382
  499. package/host/door-conformance.test.mjs +0 -274
  500. package/host/index.test.mjs +0 -302
@@ -1,1937 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- import * as os from 'node:os';
7
- import {renderComputerAgentText} from './computer-agent-text.mjs';
8
- import {
9
- generateCompressedIndex,
10
- projectHasBuiltCheck,
11
- detectStylingSystem,
12
- getXdsVersion,
13
- installAgentDocs,
14
- injectAgentsMd,
15
- injectClaudeMd,
16
- injectXdsBlock,
17
- removeAgentDocs,
18
- removeXdsBlock,
19
- discoverAgentDocs,
20
- resolveAgentPaths,
21
- parseBlockVersion,
22
- renderAgentDocsBlock,
23
- inspectAgentDocs,
24
- isAstryxInitialized,
25
- AgentDocsHomeError,
26
- resolveAgentDocsRoot,
27
- } from './agent-docs.mjs';
28
-
29
- let tmpDir;
30
-
31
- /** The managed import of AGENTS.md the default writes to GEMINI.md. */
32
- const GEMINI_IMPORT = '<!-- ASTRYX:START -->\n@./AGENTS.md\n<!-- ASTRYX:END -->\n';
33
- /** The heading of a .claude/CLAUDE.md the default creates. */
34
- const CLAUDE_HEADING = '# CLAUDE\n\nProject-specific guidance for AI coding agents.\n\n';
35
-
36
- /** Every file the default layout can write. */
37
- const LAYOUT_FILES = ['AGENTS.md', 'CLAUDE.md', '.claude/CLAUDE.md', 'GEMINI.md'];
38
-
39
- /**
40
- * How many full managed blocks the files hold, by the header every block
41
- * starts with. An import of AGENTS.md carries no header.
42
- * @param {string} dir
43
- * @param {string[]} files
44
- */
45
- function countBlocks(dir, files) {
46
- return files
47
- .filter(f => fs.existsSync(path.join(dir, f)))
48
- .map(f => fs.readFileSync(path.join(dir, f), 'utf-8').split(/Astryx v\d/).length - 1)
49
- .reduce((a, b) => a + b, 0);
50
- }
51
-
52
- /**
53
- * Full blocks in the files each agent reads at the project root, as measured:
54
- * Codex reads AGENTS.md; Copilot CLI reads AGENTS.md, CLAUDE.md and GEMINI.md
55
- * and does not expand an import in GEMINI.md; Claude Code reads CLAUDE.md and
56
- * .claude/CLAUDE.md, or AGENTS.md when neither exists; Gemini CLI reads
57
- * GEMINI.md and expands its import of AGENTS.md.
58
- * @param {string} dir
59
- */
60
- function blocksSeen(dir) {
61
- const claudeFiles = ['CLAUDE.md', '.claude/CLAUDE.md'].filter(f =>
62
- fs.existsSync(path.join(dir, f)),
63
- );
64
- const gemini = fs.existsSync(path.join(dir, 'GEMINI.md'))
65
- ? fs.readFileSync(path.join(dir, 'GEMINI.md'), 'utf-8')
66
- : null;
67
- return {
68
- claude: countBlocks(dir, claudeFiles.length > 0 ? claudeFiles : ['AGENTS.md']),
69
- codex: countBlocks(dir, ['AGENTS.md']),
70
- gemini:
71
- gemini == null
72
- ? 0
73
- : countBlocks(dir, ['GEMINI.md']) +
74
- (/(^|\s)@(\.\/)?AGENTS\.md(\s|$)/.test(gemini) ? countBlocks(dir, ['AGENTS.md']) : 0),
75
- copilot: countBlocks(dir, ['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']),
76
- };
77
- }
78
- /** Every agent reads one copy. */
79
- const ONCE_EACH = {claude: 1, codex: 1, gemini: 1, copilot: 1};
80
- /** Copilot CLI reads AGENTS.md and a root CLAUDE.md together: the accepted duplicate. */
81
- const COPILOT_TWICE = {claude: 1, codex: 1, gemini: 1, copilot: 2};
82
-
83
- beforeEach(() => {
84
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-agent-docs-test-'));
85
- });
86
-
87
- afterEach(() => {
88
- fs.rmSync(tmpDir, {recursive: true, force: true});
89
- vi.restoreAllMocks();
90
- });
91
-
92
- describe('generateCompressedIndex', () => {
93
- it('includes the version number', () => {
94
- const result = generateCompressedIndex('1.2.3');
95
- expect(result).toContain('Astryx v1.2.3');
96
- expect(result).toContain('<!-- ASTRYX:START -->');
97
- expect(result).toContain('<!-- ASTRYX:END -->');
98
- });
99
-
100
- it('tells agents to check a build with doctor --built; the computer-level skill does not', () => {
101
- const line =
102
- "Before you deliver a build, run `astryx doctor --built <dir>`; don't deliver it if it fails.";
103
- expect(generateCompressedIndex('0.7.4', {builtCheck: true})).toContain(line);
104
- expect(generateCompressedIndex('0.7.4')).not.toContain('doctor --built');
105
- expect(renderComputerAgentText({command: 'astryx'})).not.toContain(
106
- 'doctor --built',
107
- );
108
- });
109
-
110
- describe('projectHasBuiltCheck reads the CLI the project installs', () => {
111
- /**
112
- * @param {string | null} cliVersion the installed CLI, or none
113
- * @param {{workspace?: boolean}} [options] install it at a workspace root
114
- */
115
- const project = (cliVersion, {workspace = false} = {}) => {
116
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-built-check-'));
117
- const app = workspace ? path.join(root, 'apps', 'web') : root;
118
- fs.mkdirSync(app, {recursive: true});
119
- if (workspace) {
120
- fs.writeFileSync(
121
- path.join(root, 'package.json'),
122
- JSON.stringify({name: 'repo', private: true, workspaces: ['apps/*'], devDependencies: {'@astryxdesign/cli': cliVersion ?? '0.7.3'}}),
123
- );
124
- }
125
- fs.writeFileSync(
126
- path.join(app, 'package.json'),
127
- JSON.stringify({name: 'web', dependencies: {'@astryxdesign/core': '0.7.4'}}),
128
- );
129
- if (cliVersion) {
130
- const cliDir = path.join(root, 'node_modules', '@astryxdesign', 'cli');
131
- fs.mkdirSync(cliDir, {recursive: true});
132
- fs.writeFileSync(
133
- path.join(cliDir, 'package.json'),
134
- JSON.stringify({name: '@astryxdesign/cli', version: cliVersion}),
135
- );
136
- }
137
- return {root, app};
138
- };
139
- it.each([
140
- ['an installed CLI 0.7.4', '0.7.4', {}, true],
141
- ['an installed CLI 0.8.0', '0.8.0', {}, true],
142
- ['an installed CLI 0.7.3', '0.7.3', {}, false],
143
- ['an installed 0.7.4 canary', '0.7.4-canary.b25f95e', {}, false],
144
- ['no installed CLI (before install, or Core only)', null, {}, false],
145
- ['a workspace root that installs CLI 0.7.3', '0.7.3', {workspace: true}, false],
146
- ['a workspace root that installs CLI 0.7.4', '0.7.4', {workspace: true}, true],
147
- ])('%s', (_label, cliVersion, options, expected) => {
148
- const {root, app} = project(cliVersion, options);
149
- try {
150
- expect(projectHasBuiltCheck(app)).toBe(expected);
151
- } finally {
152
- fs.rmSync(root, {recursive: true, force: true});
153
- }
154
- });
155
- });
156
-
157
-
158
-
159
- it('includes theme nudge rule', () => {
160
- const result = generateCompressedIndex('1.0.0');
161
- expect(result).toMatch(/astryx docs theme/);
162
- expect(result).toMatch(/never :root/);
163
- });
164
-
165
- it('sends frame choice to the layout doc rather than naming a shell', () => {
166
- const result = generateCompressedIndex('1.0.0');
167
- const frameRule = result.split('\n').find(l => l.includes('astryx docs layout'));
168
- expect(frameRule).toBeDefined();
169
- expect(result).not.toMatch(/AppShell/);
170
- expect(frameRule).not.toMatch(/https?:/);
171
- });
172
-
173
- it('starts every page from a template before any component', () => {
174
- const lines = generateCompressedIndex('1.0.0').split('\n');
175
- const workflow = lines.findIndex(l => l.startsWith('WORKFLOW'));
176
- expect(lines[workflow]).toMatch(/start every page from a template/);
177
- expect(lines[workflow + 1]).toMatch(/^1\. `astryx build /);
178
- expect(lines[workflow + 2]).toMatch(/^2\. .*keep its frame, gap and padding/);
179
- expect(lines.join('\n')).not.toMatch(/reference code/);
180
- });
181
-
182
- it('includes the post-generation self-check rule', () => {
183
- const result = generateCompressedIndex('1.0.0');
184
- expect(result).toContain('SELF-CHECK');
185
- expect(result).toMatch(/re-read the file/);
186
- expect(result).toMatch(/component or a token/);
187
- });
188
-
189
- it('tailors the self-check to the styling system (xstyle for StyleX, not className for Tailwind)', () => {
190
- const stylex = generateCompressedIndex('1.0.0', {stylingSystem: 'stylex'});
191
- const stylexSelfCheck = stylex.split('\n').find(l => l.includes('SELF-CHECK'));
192
- expect(stylexSelfCheck).toMatch(/xstyle/);
193
- expect(stylexSelfCheck).toMatch(/className=/);
194
- const tailwind = generateCompressedIndex('1.0.0', {stylingSystem: 'tailwind'});
195
- const tailwindSelfCheck = tailwind.split('\n').find(l => l.includes('SELF-CHECK'));
196
- expect(tailwindSelfCheck).toBeDefined();
197
- expect(tailwindSelfCheck).not.toMatch(/className=/);
198
- });
199
-
200
- it('defaults to the CSS-variable styling path (no compiler)', () => {
201
- const result = generateCompressedIndex('1.0.0');
202
- expect(result).toMatch(/tokens.*var\(--color-/);
203
- // Must NOT push xstyle when no StyleX compiler is present.
204
- expect(result).not.toMatch(/xstyle prop/);
205
- // Must warn that no compiler is present.
206
- expect(result).toMatch(/No StyleX\/Tailwind compiler/);
207
- // Must acknowledge that some templates use StyleX and point at the doc.
208
- expect(result).toMatch(/templates.*StyleX/i);
209
- expect(result).toMatch(/styling-overview/);
210
- });
211
-
212
- it('recommends xstyle when StyleX is configured', () => {
213
- const result = generateCompressedIndex('1.0.0', {stylingSystem: 'stylex'});
214
- expect(result).toMatch(/xstyle prop \/ StyleX tokens/);
215
- });
216
-
217
- it('recommends Tailwind utilities when Tailwind is configured', () => {
218
- const result = generateCompressedIndex('1.0.0', {stylingSystem: 'tailwind'});
219
- expect(result).toMatch(/Tailwind utilities/);
220
- });
221
-
222
- it('includes upgrade command and migration rule', () => {
223
- const result = generateCompressedIndex('1.0.0');
224
- // `upgrade --apply` alone stops with "Missing required --from".
225
- expect(result).toContain('upgrade --from <old version> --apply');
226
- expect(result).toMatch(/after a dependency bump/);
227
- });
228
-
229
- it('points agents at discover for integrations they could add', () => {
230
- const result = generateCompressedIndex('1.0.0');
231
- // Without this line no surface an agent reads names `discover`, and agents
232
- // look for a theme in the package registry instead.
233
- expect(result).toMatch(/^ {2}discover <words> {3}integrations you could add$/m);
234
- expect(result).toMatch(/^ {2}search "<query>"/m);
235
- });
236
-
237
- it('states the invocation once in the CLI header (yarn)', () => {
238
- const result = generateCompressedIndex('1.0.0', {invocation: 'yarn astryx'});
239
- expect(result).toContain('yarn astryx <cmd>');
240
- expect(result).not.toContain('npx astryx');
241
- });
242
-
243
- it('uses the pnpm exec invocation', () => {
244
- const result = generateCompressedIndex('1.0.0', {invocation: 'pnpm exec astryx'});
245
- expect(result).toContain('pnpm exec astryx <cmd>');
246
- expect(result).not.toContain('npx astryx');
247
- });
248
-
249
- it('uses the scoped package for one-off (uninstalled) runs so agents never hit the bare name', () => {
250
- const result = generateCompressedIndex('1.0.0', {invocation: 'npx @astryxdesign/cli'});
251
- expect(result).toContain('npx @astryxdesign/cli <cmd>');
252
- // The header defines the mapping; the bare "run every command as `npx astryx`" footgun must be absent.
253
- expect(result).not.toContain('npx astryx <cmd>');
254
- });
255
-
256
- /** The `docs <topic> a, b, c` line of the block. */
257
- function topicLine(block) {
258
- return (
259
- block.split('\n').find(line => line.trimStart().startsWith('docs <topic>')) ?? ''
260
- );
261
- }
262
-
263
- it('keeps hyphenated key topics visible and points at astryx docs for the rest', () => {
264
- // The compact block shows key topics inline; the full list is via
265
- // `astryx docs`. `getting-started` is a hyphenated key topic that the old
266
- // \w+ scan used to drop — it must stay visible.
267
- const line = topicLine(generateCompressedIndex('1.0.0'));
268
- expect(line).toContain('getting-started');
269
- expect(line).toContain('principles');
270
- expect(line).toContain('astryx docs');
271
- });
272
-
273
- it('points to the CLI docs and the authoring docs on lines of their own', () => {
274
- // The integration guides live under `authoring` in the docs tree, so the
275
- // topic line does not name them; the tree's entry points do.
276
- const block = generateCompressedIndex('1.0.0');
277
- expect(block).toContain(' docs cli commands and API reference');
278
- expect(block).toContain(
279
- ' docs authoring build an integration package, and every field it holds',
280
- );
281
- expect(topicLine(block)).not.toContain('cli-integrations');
282
- });
283
-
284
- it('shows key topics from the given list and points at astryx docs for the rest', () => {
285
- const line = topicLine(
286
- generateCompressedIndex('1.0.0', {topics: ['tokens', 'deploying']}),
287
- );
288
- // 'tokens' is a key topic present in the given list, so it appears inline.
289
- expect(line).toContain('tokens');
290
- // The project's catalog replaces the built-in scan: a built-in topic not
291
- // in the given list must not appear.
292
- expect(line).not.toContain('typography');
293
- // Agents reach the full list via 'astryx docs'.
294
- expect(line).toContain('astryx docs');
295
- });
296
-
297
- it('omits the line entirely when the project has no topics', () => {
298
- expect(topicLine(generateCompressedIndex('1.0.0', {topics: []}))).toBe('');
299
- });
300
-
301
- it('is byte-identical when integrations contribute no lines', () => {
302
- const options = {
303
- invocation: 'npx @astryxdesign/cli',
304
- stylingSystem: 'css',
305
- topics: ['tokens', 'working-with-ai'],
306
- };
307
- expect(generateCompressedIndex('1.0.0', {...options, agentDocs: []})).toBe(
308
- generateCompressedIndex('1.0.0', options),
309
- );
310
- });
311
-
312
- it('appends package-labeled lines after core guidance in config order', () => {
313
- const result = generateCompressedIndex('1.0.0', {
314
- topics: [],
315
- agentDocs: [
316
- {
317
- package: '@acme/second',
318
- append: ['second one', 'second two'],
319
- },
320
- {
321
- package: '@acme/first',
322
- append: ['first one'],
323
- },
324
- ],
325
- });
326
-
327
- expect(result.indexOf('upgrade --from <old version> --apply')).toBeLessThan(
328
- result.indexOf('INTEGRATIONS:'),
329
- );
330
- expect(result.indexOf('INTEGRATIONS:')).toBeLessThan(
331
- result.indexOf('<!-- ASTRYX:END -->'),
332
- );
333
- expect(result).toContain(
334
- 'INTEGRATIONS:\n' +
335
- '- `@acme/second`: second one\n' +
336
- '- `@acme/second`: second two\n' +
337
- '- `@acme/first`: first one',
338
- );
339
- });
340
-
341
- it('caps the configured project at 32 integration lines', () => {
342
- const agentDocs = Array.from({length: 5}, (_, packageIndex) => ({
343
- package: `@acme/package-${packageIndex}`,
344
- append: Array.from(
345
- {length: packageIndex === 4 ? 1 : 8},
346
- (_, lineIndex) => `line ${lineIndex}`,
347
- ),
348
- }));
349
- expect(() => generateCompressedIndex('1.0.0', {agentDocs})).toThrow(
350
- /32-line project limit/,
351
- );
352
- });
353
- });
354
-
355
- describe('renderAgentDocsBlock', () => {
356
- it('produces repeatable target bytes from configured manifests', async () => {
357
- const projectDir = fs.mkdtempSync(
358
- path.join(process.cwd(), '.astryx-agent-doc-render-'),
359
- );
360
- try {
361
- fs.writeFileSync(
362
- path.join(projectDir, 'package.json'),
363
- JSON.stringify({name: 'consumer'}),
364
- );
365
- fs.writeFileSync(
366
- path.join(projectDir, 'astryx.config.mjs'),
367
- `export default {integrations: ['@acme/second', '@acme/first']};\n`,
368
- );
369
- const coreDir = path.join(
370
- projectDir,
371
- 'node_modules',
372
- '@astryxdesign',
373
- 'core',
374
- );
375
- fs.mkdirSync(coreDir, {recursive: true});
376
- fs.writeFileSync(
377
- path.join(coreDir, 'package.json'),
378
- JSON.stringify({name: '@astryxdesign/core', version: '1.0.0'}),
379
- );
380
- for (const [name, agentDocs] of [
381
- ['@acme/second', {append: ['second one', 'second two']}],
382
- ['@acme/first', {append: ['first one']}],
383
- ]) {
384
- const packageDir = path.join(
385
- projectDir,
386
- 'node_modules',
387
- ...name.split('/'),
388
- );
389
- fs.mkdirSync(packageDir, {recursive: true});
390
- fs.writeFileSync(
391
- path.join(packageDir, 'package.json'),
392
- JSON.stringify({name}),
393
- );
394
- fs.writeFileSync(
395
- path.join(packageDir, 'astryx.integration.mjs'),
396
- `export default {agentDocs: ${JSON.stringify(agentDocs)}};\n`,
397
- );
398
- }
399
- fs.writeFileSync(path.join(projectDir, 'AGENTS.md'), '# Agents\n');
400
- fs.writeFileSync(path.join(projectDir, 'CLAUDE.md'), '# Claude\n');
401
-
402
- const renderedBlock = await renderAgentDocsBlock(projectDir);
403
- expect(renderedBlock.indexOf('second one')).toBeLessThan(
404
- renderedBlock.indexOf('second two'),
405
- );
406
- expect(renderedBlock.indexOf('second two')).toBeLessThan(
407
- renderedBlock.indexOf('first one'),
408
- );
409
-
410
- installAgentDocs(projectDir, {renderedBlock});
411
- const firstAgents = fs.readFileSync(
412
- path.join(projectDir, 'AGENTS.md'),
413
- 'utf-8',
414
- );
415
- const firstClaude = fs.readFileSync(
416
- path.join(projectDir, 'CLAUDE.md'),
417
- 'utf-8',
418
- );
419
- expect(firstAgents).toContain(renderedBlock);
420
- expect(firstClaude).toBe(`# Claude\n\n${renderedBlock}\n`);
421
- expect(fs.existsSync(path.join(projectDir, '.claude'))).toBe(false);
422
-
423
- installAgentDocs(projectDir, {renderedBlock});
424
- expect(fs.readFileSync(path.join(projectDir, 'AGENTS.md'), 'utf-8')).toBe(
425
- firstAgents,
426
- );
427
- expect(fs.readFileSync(path.join(projectDir, 'CLAUDE.md'), 'utf-8')).toBe(
428
- firstClaude,
429
- );
430
- } finally {
431
- fs.rmSync(projectDir, {recursive: true, force: true});
432
- }
433
- });
434
- it('renders doc tokens in an integration line for the project', async () => {
435
- const projectDir = fs.mkdtempSync(
436
- path.join(process.cwd(), '.astryx-agent-doc-tokens-'),
437
- );
438
- try {
439
- fs.writeFileSync(
440
- path.join(projectDir, 'package.json'),
441
- JSON.stringify({name: 'consumer'}),
442
- );
443
- fs.writeFileSync(path.join(projectDir, 'bun.lock'), '{}\n');
444
- fs.writeFileSync(
445
- path.join(projectDir, 'astryx.config.mjs'),
446
- `export default {integrations: ['@acme/kit']};\n`,
447
- );
448
- const coreDir = path.join(
449
- projectDir,
450
- 'node_modules',
451
- '@astryxdesign',
452
- 'core',
453
- );
454
- fs.mkdirSync(coreDir, {recursive: true});
455
- fs.writeFileSync(
456
- path.join(coreDir, 'package.json'),
457
- JSON.stringify({name: '@astryxdesign/core', version: '1.0.0'}),
458
- );
459
- const packageDir = path.join(projectDir, 'node_modules', '@acme', 'kit');
460
- fs.mkdirSync(packageDir, {recursive: true});
461
- fs.writeFileSync(
462
- path.join(packageDir, 'package.json'),
463
- JSON.stringify({name: '@acme/kit'}),
464
- );
465
- fs.writeFileSync(
466
- path.join(packageDir, 'astryx.integration.mjs'),
467
- `export default {agentDocs: {append: ['Add it with {@pm install @acme/kit}, then run {@command doctor}.']}};\n`,
468
- );
469
-
470
- const block = await renderAgentDocsBlock(projectDir);
471
- expect(block).toContain(
472
- '- `@acme/kit`: Add it with `bun add @acme/kit`, then run `astryx doctor`.',
473
- );
474
- expect(block).not.toContain('{@');
475
- } finally {
476
- fs.rmSync(projectDir, {recursive: true, force: true});
477
- }
478
- });
479
-
480
- it('rejects a package label that could alter managed block structure', async () => {
481
- const projectDir = fs.mkdtempSync(
482
- path.join(process.cwd(), '.astryx-agent-doc-label-'),
483
- );
484
- try {
485
- fs.writeFileSync(
486
- path.join(projectDir, 'package.json'),
487
- JSON.stringify({name: 'consumer'}),
488
- );
489
- fs.writeFileSync(
490
- path.join(projectDir, 'astryx.config.mjs'),
491
- `export default {integrations: ['@acme/widgets']};\n`,
492
- );
493
- const packageDir = path.join(
494
- projectDir,
495
- 'node_modules',
496
- '@acme',
497
- 'widgets',
498
- );
499
- fs.mkdirSync(packageDir, {recursive: true});
500
- fs.writeFileSync(
501
- path.join(packageDir, 'package.json'),
502
- JSON.stringify({name: '@acme/widgets\nASTRYX:END'}),
503
- );
504
- fs.writeFileSync(
505
- path.join(packageDir, 'astryx.integration.mjs'),
506
- `export default {agentDocs: {append: ['safe line']}};\n`,
507
- );
508
-
509
- await expect(renderAgentDocsBlock(projectDir)).rejects.toThrow(
510
- /not safe to render/,
511
- );
512
- } finally {
513
- fs.rmSync(projectDir, {recursive: true, force: true});
514
- }
515
- });
516
- });
517
-
518
- describe('detectStylingSystem', () => {
519
- function writePkg(deps) {
520
- fs.writeFileSync(
521
- path.join(tmpDir, 'package.json'),
522
- JSON.stringify({name: 'x', devDependencies: deps}),
523
- );
524
- }
525
-
526
- it('defaults to css when no package.json', () => {
527
- expect(detectStylingSystem(tmpDir)).toBe('css');
528
- });
529
-
530
- it('returns css for a plain project', () => {
531
- writePkg({react: '19.0.0', vite: '6.0.0'});
532
- expect(detectStylingSystem(tmpDir)).toBe('css');
533
- });
534
-
535
- it('detects stylex when the compiler plugin is present', () => {
536
- writePkg({'@stylexjs/babel-plugin': '0.0.1'});
537
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
538
- });
539
-
540
- it('detects the official Rollup/Vite plugin', () => {
541
- writePkg({'@stylexjs/rollup-plugin': '0.10.0'});
542
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
543
- });
544
-
545
- it('detects the official Webpack plugin', () => {
546
- writePkg({'@stylexjs/webpack-plugin': '0.10.0'});
547
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
548
- });
549
-
550
- it('detects the official Next.js plugin', () => {
551
- writePkg({'@stylexjs/nextjs-plugin': '0.10.0'});
552
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
553
- });
554
-
555
- it('detects the official unplugin (the standard Vite path)', () => {
556
- writePkg({'@stylexjs/unplugin': '0.10.0'});
557
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
558
- });
559
-
560
- it('detects tailwind when tailwindcss is present', () => {
561
- writePkg({tailwindcss: '4.0.0'});
562
- expect(detectStylingSystem(tmpDir)).toBe('tailwind');
563
- });
564
-
565
- it('does NOT treat the StyleX runtime alone as a compiler', () => {
566
- // Only the runtime, no compiler plugin → must stay on the safe css path.
567
- writePkg({'@stylexjs/stylex': '0.0.1'});
568
- expect(detectStylingSystem(tmpDir)).toBe('css');
569
- });
570
-
571
- it('prefers stylex over tailwind when both are configured', () => {
572
- writePkg({'@stylexjs/babel-plugin': '0.0.1', tailwindcss: '4.0.0'});
573
- expect(detectStylingSystem(tmpDir)).toBe('stylex');
574
- });
575
- });
576
-
577
- describe('getXdsVersion', () => {
578
- it('reads version from core package.json', () => {
579
- const coreDir = path.join(tmpDir, 'core');
580
- fs.mkdirSync(coreDir, {recursive: true});
581
- fs.writeFileSync(
582
- path.join(coreDir, 'package.json'),
583
- JSON.stringify({version: '3.4.5'}),
584
- );
585
-
586
- expect(getXdsVersion(coreDir)).toBe('3.4.5');
587
- });
588
- });
589
-
590
- describe('injectXdsBlock', () => {
591
- it('injects into an existing file without markers', () => {
592
- const filePath = path.join(tmpDir, 'test.md');
593
- fs.writeFileSync(filePath, '# Existing content\n');
594
-
595
- const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->');
596
-
597
- expect(result).toBe(true);
598
- const content = fs.readFileSync(filePath, 'utf-8');
599
- expect(content).toContain('# Existing content');
600
- expect(content).toContain('<!-- ASTRYX:START -->');
601
- });
602
-
603
- it('replaces existing markers', () => {
604
- const filePath = path.join(tmpDir, 'test.md');
605
- fs.writeFileSync(filePath, 'before\n<!-- XDS:START -->\nold\n<!-- XDS:END -->\nafter\n');
606
-
607
- injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->');
608
-
609
- const content = fs.readFileSync(filePath, 'utf-8');
610
- expect(content).toContain('new');
611
- expect(content).not.toContain('old');
612
- expect(content).toContain('before');
613
- expect(content).toContain('after');
614
- });
615
-
616
- it('returns false and does not create file when createIfMissing is false', () => {
617
- const filePath = path.join(tmpDir, 'nonexistent.md');
618
-
619
- const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\ncontent\n<!-- ASTRYX:END -->');
620
-
621
- expect(result).toBe(false);
622
- expect(fs.existsSync(filePath)).toBe(false);
623
- });
624
-
625
- it('skips files without markers when onlyReplace is true', () => {
626
- const filePath = path.join(tmpDir, 'test.md');
627
- fs.writeFileSync(filePath, '# Existing content\n\nNo XDS markers here.\n');
628
-
629
- const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->', {onlyReplace: true});
630
-
631
- expect(result).toBe(false);
632
- const content = fs.readFileSync(filePath, 'utf-8');
633
- expect(content).not.toContain('<!-- ASTRYX:START -->');
634
- expect(content).toBe('# Existing content\n\nNo XDS markers here.\n');
635
- });
636
-
637
- it('replaces existing markers even when onlyReplace is true', () => {
638
- const filePath = path.join(tmpDir, 'test.md');
639
- fs.writeFileSync(filePath, 'before\n<!-- XDS:START -->\nold\n<!-- XDS:END -->\nafter\n');
640
-
641
- const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->', {onlyReplace: true});
642
-
643
- expect(result).toBe(true);
644
- const content = fs.readFileSync(filePath, 'utf-8');
645
- expect(content).toContain('new');
646
- expect(content).not.toContain('old');
647
- });
648
-
649
- it('creates file when createIfMissing is true', () => {
650
- const filePath = path.join(tmpDir, 'new.md');
651
-
652
- const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\ncontent\n<!-- ASTRYX:END -->', {
653
- createIfMissing: true,
654
- header: '# Header',
655
- });
656
-
657
- expect(result).toBe(true);
658
- const content = fs.readFileSync(filePath, 'utf-8');
659
- expect(content).toContain('# Header');
660
- expect(content).toContain('<!-- ASTRYX:START -->');
661
- });
662
- });
663
-
664
- describe('injectAgentsMd', () => {
665
- it('creates new AGENTS.md when none exists', () => {
666
- injectAgentsMd(tmpDir, '1.0.0');
667
-
668
- const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
669
- expect(content).toContain('# AGENTS.md');
670
- expect(content).toContain('<!-- ASTRYX:START -->');
671
- expect(content).toContain('Astryx v1.0.0');
672
- expect(content).toContain('<!-- ASTRYX:END -->');
673
- });
674
-
675
- it('updates existing AGENTS.md by replacing XDS markers', () => {
676
- const existing = `# My Project
677
-
678
- Some content.
679
-
680
- <!-- XDS:START -->
681
- old content
682
- <!-- XDS:END -->
683
-
684
- More stuff.
685
- `;
686
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), existing);
687
-
688
- injectAgentsMd(tmpDir, '2.0.0');
689
-
690
- const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
691
- expect(content).toContain('Astryx v2.0.0');
692
- expect(content).not.toContain('old content');
693
- expect(content).toContain('Some content.');
694
- expect(content).toContain('More stuff.');
695
- });
696
-
697
- it('appends to existing AGENTS.md without markers', () => {
698
- const existing = `# My Project
699
-
700
- Existing agent docs.
701
- `;
702
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), existing);
703
-
704
- injectAgentsMd(tmpDir, '1.0.0');
705
-
706
- const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
707
- expect(content).toContain('Existing agent docs.');
708
- expect(content).toContain('<!-- ASTRYX:START -->');
709
- expect(content).toContain('Astryx v1.0.0');
710
- });
711
- });
712
-
713
- describe('injectClaudeMd', () => {
714
- it('injects into existing CLAUDE.md', () => {
715
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude Config\n\nExisting rules.\n');
716
-
717
- const result = injectClaudeMd(tmpDir, '1.0.0');
718
-
719
- expect(result).toBe(true);
720
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
721
- expect(content).toContain('# Claude Config');
722
- expect(content).toContain('Existing rules.');
723
- expect(content).toContain('<!-- ASTRYX:START -->');
724
- expect(content).toContain('Astryx v1.0.0');
725
- });
726
-
727
- it('does not create CLAUDE.md when it does not exist', () => {
728
- const result = injectClaudeMd(tmpDir, '1.0.0');
729
-
730
- expect(result).toBe(false);
731
- expect(fs.existsSync(path.join(tmpDir, 'CLAUDE.md'))).toBe(false);
732
- });
733
-
734
- it('updates existing markers in CLAUDE.md', () => {
735
- const existing = `# Claude Config
736
-
737
- <!-- XDS:START -->
738
- old content
739
- <!-- XDS:END -->
740
-
741
- Other rules.
742
- `;
743
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), existing);
744
-
745
- injectClaudeMd(tmpDir, '2.0.0');
746
-
747
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
748
- expect(content).toContain('Astryx v2.0.0');
749
- expect(content).not.toContain('old content');
750
- expect(content).toContain('Other rules.');
751
- });
752
- });
753
-
754
- describe('removeAgentDocs', () => {
755
- it('removes XDS section from AGENTS.md', () => {
756
- const content = `# My Project
757
-
758
- Custom content here.
759
-
760
- <!-- XDS:START -->
761
- XDS index stuff
762
- <!-- XDS:END -->
763
-
764
- More custom content.
765
- `;
766
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), content);
767
- vi.spyOn(console, 'log').mockImplementation(() => {});
768
-
769
- removeAgentDocs(tmpDir);
770
-
771
- const result = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
772
- expect(result).toContain('Custom content here.');
773
- expect(result).toContain('More custom content.');
774
- expect(result).not.toContain('<!-- XDS:START -->');
775
- expect(result).not.toContain('XDS index stuff');
776
- });
777
-
778
- it('removes the file entirely when only XDS content remains', () => {
779
- const content = `# AGENTS.md
780
-
781
- Project-specific guidance for AI coding agents.
782
-
783
- <!-- XDS:START -->
784
- XDS index stuff
785
- <!-- XDS:END -->
786
- `;
787
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), content);
788
- vi.spyOn(console, 'log').mockImplementation(() => {});
789
-
790
- removeAgentDocs(tmpDir);
791
-
792
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
793
- });
794
-
795
- it('removes XDS section from CLAUDE.md when present', () => {
796
- fs.writeFileSync(
797
- path.join(tmpDir, 'AGENTS.md'),
798
- '# AGENTS.md\n\n<!-- XDS:START -->\nstuff\n<!-- XDS:END -->\n',
799
- );
800
- fs.writeFileSync(
801
- path.join(tmpDir, 'CLAUDE.md'),
802
- '# Claude\n\nRules.\n\n<!-- XDS:START -->\nstuff\n<!-- XDS:END -->\n\nMore rules.\n',
803
- );
804
- vi.spyOn(console, 'log').mockImplementation(() => {});
805
-
806
- removeAgentDocs(tmpDir);
807
-
808
- const claudeContent = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
809
- expect(claudeContent).toContain('Rules.');
810
- expect(claudeContent).toContain('More rules.');
811
- expect(claudeContent).not.toContain('<!-- XDS:START -->');
812
- });
813
- });
814
-
815
- describe('installAgentDocs', () => {
816
- function setupCorePackage(dir, version = '1.0.0') {
817
- // Create a minimal @astryxdesign/core so getXdsVersion works
818
- const coreDir = path.join(dir, 'node_modules', '@astryxdesign', 'core');
819
- fs.mkdirSync(coreDir, {recursive: true});
820
- fs.writeFileSync(
821
- path.join(coreDir, 'package.json'),
822
- JSON.stringify({version}),
823
- );
824
- }
825
-
826
- it('creates AGENTS.md, plus the GEMINI.md import, when no agent docs exist', () => {
827
- setupCorePackage(tmpDir);
828
-
829
- const written = installAgentDocs(tmpDir);
830
-
831
- expect(written).toEqual(['AGENTS.md', 'GEMINI.md']);
832
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(true);
833
- // Claude Code reads AGENTS.md when the project has no CLAUDE.md, so no
834
- // Claude file is created.
835
- expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(false);
836
- expect(fs.existsSync(path.join(tmpDir, 'CLAUDE.md'))).toBe(false);
837
- const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
838
- expect(content).toContain('# AGENTS.md');
839
- expect(content).toContain('<!-- ASTRYX:START -->');
840
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(GEMINI_IMPORT);
841
- });
842
-
843
- it('defaults to AGENTS.md but writes .claude/CLAUDE.md only when --agent claude is explicit', () => {
844
- // Default (no agent): tool-agnostic AGENTS.md, never the Claude file.
845
- setupCorePackage(tmpDir);
846
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
847
- expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(false);
848
-
849
- // Explicit Claude: the Claude-specific file, in a fresh project.
850
- const claudeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-agent-docs-claude-'));
851
- setupCorePackage(claudeDir);
852
- try {
853
- expect(installAgentDocs(claudeDir, {agent: 'claude'})).toEqual(['.claude/CLAUDE.md']);
854
- expect(fs.existsSync(path.join(claudeDir, 'AGENTS.md'))).toBe(false);
855
- } finally {
856
- fs.rmSync(claudeDir, {recursive: true, force: true});
857
- }
858
- });
859
-
860
- it('writes the block to AGENTS.md and to root CLAUDE.md when the project has only CLAUDE.md', () => {
861
- // Codex reads only AGENTS.md, and Claude Code skips AGENTS.md beside a
862
- // CLAUDE.md. The copy goes in the committed root CLAUDE.md; init creates
863
- // no .claude/ folder.
864
- setupCorePackage(tmpDir);
865
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\nProject rules.\n');
866
-
867
- const written = installAgentDocs(tmpDir);
868
-
869
- expect(written).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
870
- expect(
871
- fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8').startsWith(
872
- '# Claude\n\nProject rules.\n\n<!-- ASTRYX:START -->',
873
- ),
874
- ).toBe(true);
875
- expect(fs.existsSync(path.join(tmpDir, '.claude'))).toBe(false);
876
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(GEMINI_IMPORT);
877
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
878
- });
879
-
880
- it('keeps the block in root CLAUDE.md when AGENTS.md and CLAUDE.md both exist', () => {
881
- setupCorePackage(tmpDir);
882
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n\nAgent rules.\n');
883
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\nClaude rules.\n');
884
-
885
- const written = installAgentDocs(tmpDir);
886
-
887
- expect(written).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
888
- const agentsContent = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
889
- expect(agentsContent).toContain('Agent rules.');
890
- expect(agentsContent).toContain('<!-- ASTRYX:START -->');
891
- expect(fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8')).toContain(
892
- 'Claude rules.',
893
- );
894
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
895
- });
896
-
897
- it('refreshes a block an older run wrote into CLAUDE.md and adds one to AGENTS.md', () => {
898
- setupCorePackage(tmpDir, '2.0.0');
899
- fs.writeFileSync(
900
- path.join(tmpDir, 'CLAUDE.md'),
901
- '# Claude\n\nRules.\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0 · old\n<!-- ASTRYX:END -->\n\nMore rules.\n',
902
- );
903
-
904
- const written = installAgentDocs(tmpDir);
905
-
906
- expect(written).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
907
- const claude = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
908
- expect(claude).toContain('Astryx v2.0.0');
909
- expect(claude).not.toContain('Astryx v1.0.0');
910
- expect(claude).toContain('More rules.');
911
- expect(fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8')).toContain(
912
- 'Astryx v2.0.0',
913
- );
914
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
915
- });
916
-
917
- it('gives Claude Code one copy when CLAUDE.md and .claude/CLAUDE.md both exist', () => {
918
- // The copy goes in root CLAUDE.md, which projects commit even when they
919
- // ignore .claude/; a block an older run left in .claude/CLAUDE.md goes.
920
- setupCorePackage(tmpDir, '2.0.0');
921
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
922
- fs.mkdirSync(path.join(tmpDir, '.claude'));
923
- fs.writeFileSync(
924
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
925
- '# Local\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0 · old\n<!-- ASTRYX:END -->\n',
926
- );
927
-
928
- const written = installAgentDocs(tmpDir);
929
-
930
- expect(written).toEqual(['AGENTS.md', 'CLAUDE.md', '.claude/CLAUDE.md', 'GEMINI.md']);
931
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
932
- '# Local\n',
933
- );
934
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
935
- });
936
-
937
- it('writes the same bytes when run again', () => {
938
- setupCorePackage(tmpDir);
939
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
940
- installAgentDocs(tmpDir);
941
- const files = ['AGENTS.md', 'CLAUDE.md', 'GEMINI.md'];
942
- const first = files.map(f => fs.readFileSync(path.join(tmpDir, f), 'utf-8'));
943
-
944
- expect(installAgentDocs(tmpDir)).toEqual(files);
945
- expect(files.map(f => fs.readFileSync(path.join(tmpDir, f), 'utf-8'))).toEqual(first);
946
- });
947
-
948
- it('adds no import when GEMINI.md already imports AGENTS.md inline', () => {
949
- setupCorePackage(tmpDir);
950
- const gemini = '# Gemini\n\nFollow @./AGENTS.md always.\n';
951
- fs.writeFileSync(path.join(tmpDir, 'GEMINI.md'), gemini);
952
-
953
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md']);
954
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(gemini);
955
- expect(blocksSeen(tmpDir)).toEqual(ONCE_EACH);
956
- });
957
-
958
- it('removes its own import when GEMINI.md also imports AGENTS.md', () => {
959
- setupCorePackage(tmpDir);
960
- fs.writeFileSync(
961
- path.join(tmpDir, 'GEMINI.md'),
962
- `# Gemini\n\nSee @AGENTS.md first.\n\n${GEMINI_IMPORT}`,
963
- );
964
-
965
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
966
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(
967
- '# Gemini\n\nSee @AGENTS.md first.\n',
968
- );
969
- });
970
-
971
- it('adds the import when GEMINI.md mentions AGENTS.md only in code or not as an import', () => {
972
- setupCorePackage(tmpDir);
973
- // Gemini CLI follows no `@` inside backticks, none glued to a word, and
974
- // none whose path does not name AGENTS.md exactly.
975
- const gemini = 'Write `@./AGENTS.md` to import.\nmail@AGENTS.md\nRead @./AGENTS.md.\n';
976
- fs.writeFileSync(path.join(tmpDir, 'GEMINI.md'), gemini);
977
-
978
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
979
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(
980
- `${gemini}\n${GEMINI_IMPORT}`,
981
- );
982
- });
983
-
984
- it.each([
985
- ['a list', '{"context": {"fileName": ["AGENTS.md", "GEMINI.md"]}}'],
986
- ['a name', '{"context": {"fileName": "AGENTS.md"}}'],
987
- ['comments', '{\n // Gemini reads AGENTS.md\n "context": {/* both */ "fileName": ["AGENTS.md", "GEMINI.md"]}\n}\n'],
988
- ['another file', '{"context": {"fileName": "GEMINI.md"}}'],
989
- ])('writes the GEMINI.md import whatever the project Gemini settings read (%s)', (_label, settings) => {
990
- // Gemini loads project settings only when it starts at the project root;
991
- // started in a subfolder, the import is its only copy.
992
- setupCorePackage(tmpDir);
993
- fs.mkdirSync(path.join(tmpDir, '.gemini'));
994
- fs.writeFileSync(path.join(tmpDir, '.gemini', 'settings.json'), settings);
995
-
996
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
997
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(GEMINI_IMPORT);
998
- });
999
-
1000
- it('keeps its GEMINI.md import when the project Gemini settings read AGENTS.md', () => {
1001
- setupCorePackage(tmpDir);
1002
- fs.writeFileSync(path.join(tmpDir, 'GEMINI.md'), `# Gemini\n\n${GEMINI_IMPORT}`);
1003
- fs.mkdirSync(path.join(tmpDir, '.gemini'));
1004
- fs.writeFileSync(
1005
- path.join(tmpDir, '.gemini', 'settings.json'),
1006
- '{"context": {"fileName": ["AGENTS.md", "GEMINI.md"]}}',
1007
- );
1008
-
1009
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
1010
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(
1011
- `# Gemini\n\n${GEMINI_IMPORT}`,
1012
- );
1013
- });
1014
-
1015
- it('leaves a file that is AGENTS.md under another name alone', () => {
1016
- setupCorePackage(tmpDir);
1017
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n');
1018
- fs.symlinkSync('AGENTS.md', path.join(tmpDir, 'CLAUDE.md'));
1019
-
1020
- // Claude Code reads the block through CLAUDE.md, so no copy is added.
1021
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
1022
- expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(false);
1023
- expect(countBlocks(tmpDir, ['AGENTS.md'])).toBe(1);
1024
- });
1025
-
1026
- it('keeps an existing GEMINI.md and adds the import to it', () => {
1027
- setupCorePackage(tmpDir);
1028
- fs.writeFileSync(path.join(tmpDir, 'GEMINI.md'), '# Gemini\n\nUse tabs.\n');
1029
-
1030
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'GEMINI.md']);
1031
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(
1032
- `# Gemini\n\nUse tabs.\n\n${GEMINI_IMPORT}`,
1033
- );
1034
- });
1035
-
1036
- it('preserves import wrappers while initializing standalone files', () => {
1037
- setupCorePackage(tmpDir);
1038
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n');
1039
- const wrapperPath = path.join(tmpDir, '.hermes.md');
1040
- const wrapper = '@AGENTS.md\n';
1041
- fs.writeFileSync(wrapperPath, wrapper);
1042
- fs.writeFileSync(path.join(tmpDir, '.cursorrules'), 'Cursor rules.\n');
1043
-
1044
- const written = installAgentDocs(tmpDir);
1045
-
1046
- expect(written).toEqual(['AGENTS.md', 'GEMINI.md', '.cursorrules']);
1047
- expect(fs.readFileSync(wrapperPath, 'utf-8')).toBe(wrapper);
1048
- expect(fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8')).toContain(
1049
- '<!-- ASTRYX:START -->',
1050
- );
1051
- expect(fs.readFileSync(path.join(tmpDir, '.cursorrules'), 'utf-8')).toContain(
1052
- '<!-- ASTRYX:START -->',
1053
- );
1054
- });
1055
-
1056
- it('treats cyclic imports as standalone files', () => {
1057
- setupCorePackage(tmpDir);
1058
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '@CLAUDE.md\n');
1059
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '@AGENTS.md\n');
1060
- fs.writeFileSync(path.join(tmpDir, '.cursorrules'), 'Cursor rules.\n');
1061
-
1062
- const written = installAgentDocs(tmpDir);
1063
-
1064
- expect(written).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md', '.cursorrules']);
1065
- for (const rel of ['AGENTS.md', 'CLAUDE.md', '.cursorrules']) {
1066
- expect(countBlocks(tmpDir, [rel])).toBe(1);
1067
- }
1068
- });
1069
-
1070
- it('keeps the per-file layout when a wrapper imports a file other than AGENTS.md', () => {
1071
- setupCorePackage(tmpDir);
1072
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1073
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '@CLAUDE.md\n');
1074
-
1075
- expect(installAgentDocs(tmpDir)).toEqual(['CLAUDE.md']);
1076
- expect(fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8')).toBe('@CLAUDE.md\n');
1077
- expect(countBlocks(tmpDir, ['CLAUDE.md'])).toBe(1);
1078
- expect(fs.existsSync(path.join(tmpDir, 'GEMINI.md'))).toBe(false);
1079
- });
1080
-
1081
- it('removes a managed block previously expanded into an import wrapper', () => {
1082
- setupCorePackage(tmpDir);
1083
- installAgentDocs(tmpDir, {agent: 'codex'});
1084
- const wrapperPath = path.join(tmpDir, '.hermes.md');
1085
- const wrapper = '@AGENTS.md\n';
1086
- fs.writeFileSync(wrapperPath, wrapper);
1087
- installAgentDocs(tmpDir, {agent: 'hermes'});
1088
- expect(fs.readFileSync(wrapperPath, 'utf-8')).toContain(
1089
- '<!-- ASTRYX:START -->',
1090
- );
1091
-
1092
- const written = installAgentDocs(tmpDir, {onlyReplace: true});
1093
-
1094
- expect(written).toContain('AGENTS.md');
1095
- expect(written).toContain('.hermes.md');
1096
- expect(fs.readFileSync(wrapperPath, 'utf-8')).toBe(wrapper);
1097
- });
1098
-
1099
- it('refuses a malformed managed block inside an import wrapper', () => {
1100
- setupCorePackage(tmpDir);
1101
- installAgentDocs(tmpDir, {agent: 'codex'});
1102
- fs.mkdirSync(path.join(tmpDir, '.claude'), {recursive: true});
1103
- fs.writeFileSync(
1104
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
1105
- '@../AGENTS.md\n<!-- ASTRYX:START -->\nincomplete\n',
1106
- );
1107
-
1108
- expect(() => installAgentDocs(tmpDir)).toThrow(/malformed|no matching/i);
1109
- });
1110
-
1111
- it('adds the block to an existing .claude/CLAUDE.md and to AGENTS.md', () => {
1112
- setupCorePackage(tmpDir);
1113
- fs.mkdirSync(path.join(tmpDir, '.claude'), {recursive: true});
1114
- fs.writeFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), '# Project\n\nExisting content.\n');
1115
-
1116
- const written = installAgentDocs(tmpDir);
1117
-
1118
- expect(written).toEqual(['AGENTS.md', '.claude/CLAUDE.md', 'GEMINI.md']);
1119
- const content = fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8');
1120
- expect(content.startsWith('# Project\n\nExisting content.\n\n<!-- ASTRYX:START -->')).toBe(
1121
- true,
1122
- );
1123
- expect(blocksSeen(tmpDir)).toEqual(ONCE_EACH);
1124
- });
1125
-
1126
- it('gives a root CLAUDE.md that imports AGENTS.md a copy too', () => {
1127
- // Claude Code does not follow an import of a file above the folder it
1128
- // starts in, so a session in a subfolder reads only the copy.
1129
- setupCorePackage(tmpDir);
1130
- const claude = '# Claude\n\n@AGENTS.md\n';
1131
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), claude);
1132
-
1133
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
1134
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
1135
- expect(content.startsWith(`${claude}\n<!-- ASTRYX:START -->`)).toBe(true);
1136
- expect(countBlocks(tmpDir, ['AGENTS.md', 'CLAUDE.md'])).toBe(2);
1137
- expect(fs.existsSync(path.join(tmpDir, '.claude'))).toBe(false);
1138
-
1139
- // Running again keeps the copy where it is.
1140
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
1141
- expect(fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8')).toBe(content);
1142
- });
1143
-
1144
- it('keeps the copy in root CLAUDE.md, not .claude/CLAUDE.md, when root CLAUDE.md imports AGENTS.md', () => {
1145
- // Root CLAUDE.md is committed even where .claude/ is ignored, so a fresh
1146
- // clone still gives a session in a subfolder its copy.
1147
- setupCorePackage(tmpDir, '2.0.0');
1148
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\n@AGENTS.md\n');
1149
- fs.mkdirSync(path.join(tmpDir, '.claude'));
1150
- fs.writeFileSync(
1151
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
1152
- '# Local\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0 · old\n<!-- ASTRYX:END -->\n',
1153
- );
1154
-
1155
- expect(installAgentDocs(tmpDir)).toEqual([
1156
- 'AGENTS.md',
1157
- 'CLAUDE.md',
1158
- '.claude/CLAUDE.md',
1159
- 'GEMINI.md',
1160
- ]);
1161
- expect(countBlocks(tmpDir, ['CLAUDE.md'])).toBe(1);
1162
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1163
- '# Local\n',
1164
- );
1165
- });
1166
-
1167
- it('gives a .claude/CLAUDE.md that imports AGENTS.md a copy when there is no root CLAUDE.md', () => {
1168
- setupCorePackage(tmpDir);
1169
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n');
1170
- fs.mkdirSync(path.join(tmpDir, '.claude'));
1171
- fs.writeFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), '@../AGENTS.md\n');
1172
-
1173
- expect(installAgentDocs(tmpDir)).toEqual(['AGENTS.md', '.claude/CLAUDE.md', 'GEMINI.md']);
1174
- const content = fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8');
1175
- expect(content.startsWith('@../AGENTS.md\n\n<!-- ASTRYX:START -->')).toBe(true);
1176
- });
1177
-
1178
- it('onlyReplace: refreshes the copy in a Claude file that imports AGENTS.md instead of removing it', () => {
1179
- setupCorePackage(tmpDir, '1.0.0');
1180
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\n@AGENTS.md\n');
1181
- installAgentDocs(tmpDir);
1182
- setupCorePackage(tmpDir, '2.0.0');
1183
-
1184
- expect(installAgentDocs(tmpDir, {onlyReplace: true})).toEqual(['AGENTS.md', 'CLAUDE.md']);
1185
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
1186
- expect(content).toContain('@AGENTS.md');
1187
- expect(content).toContain('Astryx v2.0.0');
1188
- expect(content).not.toContain('Astryx v1.0.0');
1189
- });
1190
-
1191
- it('--agent all after the default keeps the GEMINI.md import and one Claude copy', () => {
1192
- setupCorePackage(tmpDir);
1193
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n');
1194
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1195
- fs.mkdirSync(path.join(tmpDir, '.claude'));
1196
- fs.writeFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), '# Local\n');
1197
- installAgentDocs(tmpDir);
1198
-
1199
- expect(installAgentDocs(tmpDir, {agent: 'all'})).toEqual(['AGENTS.md', 'CLAUDE.md']);
1200
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(GEMINI_IMPORT);
1201
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1202
- '# Local\n',
1203
- );
1204
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
1205
- });
1206
-
1207
- it('--agent claude writes CLAUDE.md and removes a block from .claude/CLAUDE.md', () => {
1208
- setupCorePackage(tmpDir);
1209
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1210
- fs.mkdirSync(path.join(tmpDir, '.claude'));
1211
- fs.writeFileSync(
1212
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
1213
- '# Local\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0 · old\n<!-- ASTRYX:END -->\n',
1214
- );
1215
- installAgentDocs(tmpDir);
1216
-
1217
- expect(installAgentDocs(tmpDir, {agent: 'claude'})).toEqual(['CLAUDE.md']);
1218
- expect(installAgentDocs(tmpDir, {agent: 'all'})).toEqual(['AGENTS.md', 'CLAUDE.md']);
1219
- fs.writeFileSync(
1220
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
1221
- '# Local\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0 · old\n<!-- ASTRYX:END -->\n',
1222
- );
1223
- expect(installAgentDocs(tmpDir, {agent: 'claude'})).toEqual(['CLAUDE.md', '.claude/CLAUDE.md']);
1224
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1225
- '# Local\n',
1226
- );
1227
- expect(blocksSeen(tmpDir).claude).toBe(1);
1228
- });
1229
-
1230
- it('respects --agent claude preset: finds existing CLAUDE.md', () => {
1231
- setupCorePackage(tmpDir);
1232
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\nRules.\n');
1233
-
1234
- const written = installAgentDocs(tmpDir, {agent: 'claude'});
1235
-
1236
- expect(written).toEqual(['CLAUDE.md']);
1237
- });
1238
-
1239
- it('respects --agent claude preset: creates .claude/CLAUDE.md when nothing exists', () => {
1240
- setupCorePackage(tmpDir);
1241
-
1242
- const written = installAgentDocs(tmpDir, {agent: 'claude'});
1243
-
1244
- expect(written).toEqual(['.claude/CLAUDE.md']);
1245
- expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(true);
1246
- });
1247
-
1248
- it('respects --agent codex preset: creates AGENTS.md', () => {
1249
- setupCorePackage(tmpDir);
1250
-
1251
- const written = installAgentDocs(tmpDir, {agent: 'codex'});
1252
-
1253
- expect(written).toEqual(['AGENTS.md']);
1254
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(true);
1255
- });
1256
-
1257
- it('respects --agent hermes preset: creates AGENTS.md', () => {
1258
- setupCorePackage(tmpDir);
1259
-
1260
- const written = installAgentDocs(tmpDir, {agent: 'hermes'});
1261
-
1262
- expect(written).toEqual(['AGENTS.md']);
1263
- const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
1264
- expect(content).toContain('<!-- ASTRYX:START -->');
1265
- expect(fs.existsSync(path.join(tmpDir, '.claude'))).toBe(false);
1266
- });
1267
-
1268
- it('respects --agent muse preset: creates AGENTS.md', () => {
1269
- setupCorePackage(tmpDir);
1270
-
1271
- const written = installAgentDocs(tmpDir, {agent: 'muse'});
1272
-
1273
- expect(written).toEqual(['AGENTS.md']);
1274
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(true);
1275
- });
1276
-
1277
- it('respects explicit --paths', () => {
1278
- setupCorePackage(tmpDir);
1279
-
1280
- const written = installAgentDocs(tmpDir, {paths: ['custom/AGENT.md']});
1281
-
1282
- expect(written).toEqual(['custom/AGENT.md']);
1283
- expect(fs.existsSync(path.join(tmpDir, 'custom', 'AGENT.md'))).toBe(true);
1284
- });
1285
-
1286
- it('onlyReplace: skips files without XDS markers', () => {
1287
- setupCorePackage(tmpDir);
1288
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n\nProject rules only.\n');
1289
-
1290
- const written = installAgentDocs(tmpDir, {onlyReplace: true});
1291
-
1292
- expect(written).toEqual([]);
1293
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
1294
- expect(content).not.toContain('<!-- ASTRYX:START -->');
1295
- expect(content).toBe('# Claude\n\nProject rules only.\n');
1296
- });
1297
-
1298
- it('onlyReplace: updates files that have XDS markers', () => {
1299
- setupCorePackage(tmpDir, '2.0.0');
1300
- fs.writeFileSync(
1301
- path.join(tmpDir, 'CLAUDE.md'),
1302
- '# Claude\n\n<!-- XDS:START -->\nPLACEHOLDER_STALE_CONTENT\n<!-- XDS:END -->\n\nOther rules.\n',
1303
- );
1304
-
1305
- const written = installAgentDocs(tmpDir, {onlyReplace: true});
1306
-
1307
- expect(written).toEqual(['CLAUDE.md']);
1308
- const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
1309
- expect(content).toContain('Astryx v2.0.0');
1310
- expect(content).not.toContain('PLACEHOLDER_STALE_CONTENT');
1311
- expect(content).toContain('Other rules.');
1312
- });
1313
-
1314
- it('onlyReplace: refreshes both copies of the block and leaves the GEMINI.md import alone', () => {
1315
- setupCorePackage(tmpDir, '1.0.0');
1316
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1317
- installAgentDocs(tmpDir);
1318
- setupCorePackage(tmpDir, '2.0.0');
1319
-
1320
- expect(installAgentDocs(tmpDir, {onlyReplace: true})).toEqual([
1321
- 'AGENTS.md',
1322
- 'CLAUDE.md',
1323
- ]);
1324
- for (const rel of ['AGENTS.md', 'CLAUDE.md']) {
1325
- const content = fs.readFileSync(path.join(tmpDir, rel), 'utf-8');
1326
- expect(content).toContain('Astryx v2.0.0');
1327
- expect(content).not.toContain('Astryx v1.0.0');
1328
- }
1329
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(GEMINI_IMPORT);
1330
- expect(blocksSeen(tmpDir)).toEqual(COPILOT_TWICE);
1331
- });
1332
-
1333
- it('onlyReplace: refreshes a block beside an import of a missing AGENTS.md', () => {
1334
- setupCorePackage(tmpDir, '2.0.0');
1335
- fs.writeFileSync(
1336
- path.join(tmpDir, 'CLAUDE.md'),
1337
- '@AGENTS.md\n\n<!-- ASTRYX:START -->\nAstryx v1.0.0\n<!-- ASTRYX:END -->\n',
1338
- );
1339
-
1340
- expect(installAgentDocs(tmpDir, {onlyReplace: true})).toEqual(['CLAUDE.md']);
1341
- expect(fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8')).toContain(
1342
- 'Astryx v2.0.0',
1343
- );
1344
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
1345
- });
1346
-
1347
- it('onlyReplace: does not create the default AGENTS.md when nothing exists', () => {
1348
- setupCorePackage(tmpDir);
1349
-
1350
- const written = installAgentDocs(tmpDir, {onlyReplace: true});
1351
-
1352
- expect(written).toEqual([]);
1353
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
1354
- expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(false);
1355
- });
1356
- });
1357
-
1358
- describe('discoverAgentDocs', () => {
1359
- it('finds AGENTS.md and CLAUDE.md at root', () => {
1360
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '');
1361
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '');
1362
-
1363
- const found = discoverAgentDocs(tmpDir);
1364
-
1365
- expect(found).toContain('AGENTS.md');
1366
- expect(found).toContain('CLAUDE.md');
1367
- });
1368
-
1369
- it('finds .claude/CLAUDE.md', () => {
1370
- fs.mkdirSync(path.join(tmpDir, '.claude'), {recursive: true});
1371
- fs.writeFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), '');
1372
-
1373
- const found = discoverAgentDocs(tmpDir);
1374
-
1375
- expect(found).toContain('.claude/CLAUDE.md');
1376
- });
1377
-
1378
- it('returns empty when nothing exists', () => {
1379
- expect(discoverAgentDocs(tmpDir)).toEqual([]);
1380
- });
1381
- });
1382
-
1383
- describe('resolveAgentPaths', () => {
1384
- it('claude preset finds existing CLAUDE.md at root', () => {
1385
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '');
1386
- const result = resolveAgentPaths(tmpDir, 'claude');
1387
- expect(result).toEqual({inject: ['CLAUDE.md'], create: []});
1388
- });
1389
-
1390
- it('claude preset falls back to .claude/CLAUDE.md', () => {
1391
- const result = resolveAgentPaths(tmpDir, 'claude');
1392
- expect(result).toEqual({inject: [], create: ['.claude/CLAUDE.md']});
1393
- });
1394
-
1395
- it('all preset discovers existing files', () => {
1396
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '');
1397
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '');
1398
- const result = resolveAgentPaths(tmpDir, 'all');
1399
- expect(result.inject).toContain('AGENTS.md');
1400
- expect(result.inject).toContain('CLAUDE.md');
1401
- expect(result.create).toEqual([]);
1402
- });
1403
-
1404
- it('all preset creates defaults when nothing exists', () => {
1405
- const result = resolveAgentPaths(tmpDir, 'all');
1406
- expect(result.inject).toEqual([]);
1407
- expect(result.create).toContain('AGENTS.md');
1408
- expect(result.create).toContain('.claude/CLAUDE.md');
1409
- });
1410
-
1411
- it('hermes preset creates AGENTS.md when nothing exists', () => {
1412
- const result = resolveAgentPaths(tmpDir, 'hermes');
1413
- expect(result).toEqual({inject: [], create: ['AGENTS.md']});
1414
- });
1415
-
1416
- it('hermes preset finds existing .hermes.md', () => {
1417
- fs.writeFileSync(path.join(tmpDir, '.hermes.md'), '');
1418
- const result = resolveAgentPaths(tmpDir, 'hermes');
1419
- expect(result).toEqual({inject: ['.hermes.md'], create: []});
1420
- });
1421
-
1422
- it('hermes preset finds existing HERMES.md when no .hermes.md', () => {
1423
- fs.writeFileSync(path.join(tmpDir, 'HERMES.md'), '');
1424
- const result = resolveAgentPaths(tmpDir, 'hermes');
1425
- expect(result).toEqual({inject: ['HERMES.md'], create: []});
1426
- });
1427
-
1428
- it('muse preset creates AGENTS.md when nothing exists', () => {
1429
- const result = resolveAgentPaths(tmpDir, 'muse');
1430
- expect(result).toEqual({inject: [], create: ['AGENTS.md']});
1431
- });
1432
-
1433
- it('claude preset still creates .claude/CLAUDE.md when nothing exists (hermes is additive)', () => {
1434
- const result = resolveAgentPaths(tmpDir, 'claude');
1435
- expect(result).toEqual({inject: [], create: ['.claude/CLAUDE.md']});
1436
- });
1437
- });
1438
-
1439
- describe('parseBlockVersion', () => {
1440
- it('reads the version from the header of a generated block', () => {
1441
- expect(parseBlockVersion(generateCompressedIndex('1.2.3'))).toBe('1.2.3');
1442
- });
1443
-
1444
- it('reads prerelease versions', () => {
1445
- expect(parseBlockVersion('Astryx v1.2.3-beta.4 · 10 components')).toBe(
1446
- '1.2.3-beta.4',
1447
- );
1448
- });
1449
-
1450
- it('returns null when no versioned header is present', () => {
1451
- expect(parseBlockVersion('<!-- XDS:START -->\nold\n<!-- XDS:END -->')).toBeNull();
1452
- expect(parseBlockVersion('')).toBeNull();
1453
- expect(parseBlockVersion(undefined)).toBeNull();
1454
- });
1455
- });
1456
-
1457
- describe('inspectAgentDocs', () => {
1458
- function writeBlock(rel, version) {
1459
- const filePath = path.join(tmpDir, rel);
1460
- fs.mkdirSync(path.dirname(filePath), {recursive: true});
1461
- fs.writeFileSync(filePath, `# Doc\n\n${generateCompressedIndex(version)}\n`);
1462
- }
1463
-
1464
- it('reports missing when no agent docs exist at all', () => {
1465
- const res = inspectAgentDocs(tmpDir, '1.0.0');
1466
- expect(res.status).toBe('missing');
1467
- expect(res.files).toEqual([]);
1468
- expect(res.staleFiles).toEqual([]);
1469
- });
1470
-
1471
- it('reports missing when agent files exist but carry no Astryx marker', () => {
1472
- fs.writeFileSync(path.join(tmpDir, 'AGENTS.md'), '# Agents\n\nHand-written notes.\n');
1473
- expect(inspectAgentDocs(tmpDir, '1.0.0').status).toBe('missing');
1474
- });
1475
-
1476
- it('reports current when the only block matches the installed version', () => {
1477
- writeBlock('AGENTS.md', '1.0.0');
1478
- const res = inspectAgentDocs(tmpDir, '1.0.0');
1479
- expect(res.status).toBe('current');
1480
- expect(res.staleFiles).toEqual([]);
1481
- expect(res.blockVersions).toEqual([]);
1482
- });
1483
-
1484
- it.each([
1485
- ['append addition', [], [{package: '@acme/a', append: ['added']}]],
1486
- ['append removal', [{package: '@acme/a', append: ['removed']}], []],
1487
- [
1488
- 'integration reorder',
1489
- [
1490
- {package: '@acme/a', append: ['a']},
1491
- {package: '@acme/b', append: ['b']},
1492
- ],
1493
- [
1494
- {package: '@acme/b', append: ['b']},
1495
- {package: '@acme/a', append: ['a']},
1496
- ],
1497
- ],
1498
- [
1499
- 'line content change',
1500
- [{package: '@acme/a', append: ['old']}],
1501
- [{package: '@acme/a', append: ['new']}],
1502
- ],
1503
- ])(
1504
- 'reports stale at the same Core version after %s',
1505
- (_label, current, expected) => {
1506
- const actualBlock = generateCompressedIndex('1.0.0', {
1507
- agentDocs: current,
1508
- });
1509
- fs.writeFileSync(
1510
- path.join(tmpDir, 'AGENTS.md'),
1511
- `# Doc\n\n${actualBlock}\n`,
1512
- );
1513
- const expectedBlock = generateCompressedIndex('1.0.0', {
1514
- agentDocs: expected,
1515
- });
1516
-
1517
- expect(inspectAgentDocs(tmpDir, '1.0.0', expectedBlock)).toMatchObject({
1518
- status: 'stale',
1519
- staleFiles: ['AGENTS.md'],
1520
- });
1521
- },
1522
- );
1523
-
1524
- it('reports stale (with the old version) when the block is behind', () => {
1525
- writeBlock('AGENTS.md', '1.0.0');
1526
- const res = inspectAgentDocs(tmpDir, '2.0.0');
1527
- expect(res.status).toBe('stale');
1528
- expect(res.staleFiles).toEqual(['AGENTS.md']);
1529
- expect(res.blockVersions).toEqual(['1.0.0']);
1530
- expect(res.installedVersion).toBe('2.0.0');
1531
- });
1532
-
1533
- it('treats a legacy XDS block as stale even with no parseable version', () => {
1534
- fs.writeFileSync(
1535
- path.join(tmpDir, 'CLAUDE.md'),
1536
- '# Claude\n\n<!-- XDS:START -->\nlegacy index\n<!-- XDS:END -->\n',
1537
- );
1538
- const res = inspectAgentDocs(tmpDir, '1.0.0');
1539
- expect(res.status).toBe('stale');
1540
- expect(res.files[0].legacy).toBe(true);
1541
- expect(res.blockVersions).toEqual([]);
1542
- });
1543
-
1544
- it('is stale if ANY marked file is behind (mixed current + stale)', () => {
1545
- writeBlock('AGENTS.md', '2.0.0');
1546
- writeBlock('CLAUDE.md', '1.0.0');
1547
- const res = inspectAgentDocs(tmpDir, '2.0.0');
1548
- expect(res.status).toBe('stale');
1549
- expect(res.staleFiles).toEqual(['CLAUDE.md']);
1550
- });
1551
-
1552
- it('checks both copies of the block and does not count the GEMINI.md import', () => {
1553
- const core = path.join(tmpDir, 'node_modules', '@astryxdesign', 'core');
1554
- fs.mkdirSync(core, {recursive: true});
1555
- fs.writeFileSync(path.join(core, 'package.json'), JSON.stringify({version: '3.0.0'}));
1556
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1557
- installAgentDocs(tmpDir);
1558
-
1559
- const current = inspectAgentDocs(tmpDir, '3.0.0');
1560
- expect(current.status).toBe('current');
1561
- expect(current.files.map(f => f.path)).toEqual(['AGENTS.md', 'CLAUDE.md']);
1562
- expect(inspectAgentDocs(tmpDir, '4.0.0').staleFiles).toEqual(['AGENTS.md', 'CLAUDE.md']);
1563
-
1564
- // Without the blocks, the import alone reads as not set up.
1565
- fs.rmSync(path.join(tmpDir, 'AGENTS.md'));
1566
- fs.rmSync(path.join(tmpDir, 'CLAUDE.md'));
1567
- expect(inspectAgentDocs(tmpDir, '3.0.0').status).toBe('missing');
1568
- expect(isAstryxInitialized(tmpDir)).toBe(false);
1569
- });
1570
-
1571
- it('defaults the installed version to the core package when omitted', () => {
1572
- const coreDir = path.join(tmpDir, 'node_modules', '@astryxdesign', 'core');
1573
- fs.mkdirSync(coreDir, {recursive: true});
1574
- fs.writeFileSync(path.join(coreDir, 'package.json'), JSON.stringify({version: '3.0.0'}));
1575
- writeBlock('AGENTS.md', '3.0.0');
1576
- const res = inspectAgentDocs(tmpDir);
1577
- expect(res.installedVersion).toBe('3.0.0');
1578
- expect(res.status).toBe('current');
1579
- });
1580
- });
1581
-
1582
- describe('injectXdsBlock / removeXdsBlock — malformed managed blocks (no user-content loss)', () => {
1583
- const S = '<!-- ASTRYX:START -->';
1584
- const E = '<!-- ASTRYX:END -->';
1585
- const BLOCK = `${S}\nNEW\n${E}`;
1586
-
1587
- it('does not duplicate user content when END precedes START', () => {
1588
- const f = path.join(tmpDir, 'a.md');
1589
- fs.writeFileSync(f, `# Doc\nUSER-A\n${E}\nUSER-B\n${S}\nUSER-C\n`);
1590
- removeXdsBlock(f);
1591
- const c = fs.readFileSync(f, 'utf-8');
1592
- expect((c.match(/USER-B/g) || []).length).toBeLessThanOrEqual(1);
1593
- });
1594
-
1595
- it('refuses (throws) instead of orphaning a second block when duplicates exist', () => {
1596
- const f = path.join(tmpDir, 'b.md');
1597
- fs.writeFileSync(f, `# Doc\n${S}\nB1\n${E}\nMID\n${S}\nB2\n${E}\nTAIL\n`);
1598
- expect(() => injectXdsBlock(f, BLOCK)).toThrow(/multiple|malformed/i);
1599
- // file left untouched for the user to fix
1600
- expect(fs.readFileSync(f, 'utf-8')).toContain('MID');
1601
- expect(fs.readFileSync(f, 'utf-8')).toContain('TAIL');
1602
- });
1603
-
1604
- it('refuses to append a second block when a START has no matching END', () => {
1605
- const f = path.join(tmpDir, 'c.md');
1606
- fs.writeFileSync(f, `# Doc\nUSER1\n${S}\nOLD (no end)\nUSER2\n`);
1607
- expect(() => injectXdsBlock(f, BLOCK)).toThrow(/end marker|malformed|no matching/i);
1608
- expect((fs.readFileSync(f, 'utf-8').match(/ASTRYX:START/g) || []).length).toBe(1);
1609
- });
1610
-
1611
- it('replaces a single well-formed block idempotently, preserving surrounding content', () => {
1612
- const f = path.join(tmpDir, 'ok.md');
1613
- fs.writeFileSync(f, `# Doc\nUSER\n${S}\nOLD\n${E}\nTAIL\n`);
1614
- injectXdsBlock(f, BLOCK);
1615
- const c = fs.readFileSync(f, 'utf-8');
1616
- expect((c.match(/ASTRYX:START/g) || []).length).toBe(1);
1617
- expect(c).toContain('NEW');
1618
- expect(c).toContain('USER');
1619
- expect(c).toContain('TAIL');
1620
- expect(c).not.toContain('OLD');
1621
- });
1622
- });
1623
-
1624
- describe('isAstryxInitialized — resilient to malformed markers (postinstall hot path)', () => {
1625
- // isAstryxInitialized runs on every consumer `npm install` (via postinstall).
1626
- // It must never throw — even on a half-written or garbage-marker file — so it
1627
- // uses a plain `.includes(MARKER_START)`, never the strict findManagedBlock.
1628
- const START = '<!-- ASTRYX:START -->';
1629
- const END = '<!-- ASTRYX:END -->';
1630
-
1631
- it('returns true (never throws) on duplicate START markers', () => {
1632
- fs.writeFileSync(
1633
- path.join(tmpDir, 'AGENTS.md'),
1634
- `${START}\na\n${START}\nb\n${END}\n`,
1635
- );
1636
- expect(() => isAstryxInitialized(tmpDir)).not.toThrow();
1637
- expect(isAstryxInitialized(tmpDir)).toBe(true);
1638
- });
1639
-
1640
- it('returns true on an END-before-START file without throwing', () => {
1641
- fs.writeFileSync(
1642
- path.join(tmpDir, 'AGENTS.md'),
1643
- `${END}\nuser\n${START}\nblock\n`,
1644
- );
1645
- expect(() => isAstryxInitialized(tmpDir)).not.toThrow();
1646
- expect(isAstryxInitialized(tmpDir)).toBe(true);
1647
- });
1648
-
1649
- it('returns true on a START with no END (half-written block)', () => {
1650
- fs.writeFileSync(
1651
- path.join(tmpDir, 'AGENTS.md'),
1652
- `# Doc\nuser\n${START}\ntruncated block, no end\n`,
1653
- );
1654
- expect(() => isAstryxInitialized(tmpDir)).not.toThrow();
1655
- expect(isAstryxInitialized(tmpDir)).toBe(true);
1656
- });
1657
-
1658
- it('returns false for a directory with no agent docs', () => {
1659
- expect(isAstryxInitialized(tmpDir)).toBe(false);
1660
- });
1661
-
1662
- it('returns false for a nonexistent directory', () => {
1663
- expect(isAstryxInitialized(path.join(tmpDir, 'does-not-exist'))).toBe(false);
1664
- });
1665
- });
1666
-
1667
- describe('removeAgentDocs after the default layout', () => {
1668
- beforeEach(() => {
1669
- vi.spyOn(console, 'log').mockImplementation(() => {});
1670
- });
1671
-
1672
- it('deletes the files the default created and keeps the project files', () => {
1673
- const core = path.join(tmpDir, 'node_modules', '@astryxdesign', 'core');
1674
- fs.mkdirSync(core, {recursive: true});
1675
- fs.writeFileSync(path.join(core, 'package.json'), JSON.stringify({version: '1.0.0'}));
1676
- fs.writeFileSync(path.join(tmpDir, 'CLAUDE.md'), '# Claude\n');
1677
- installAgentDocs(tmpDir);
1678
-
1679
- expect(removeAgentDocs(tmpDir)).toEqual(['AGENTS.md', 'CLAUDE.md', 'GEMINI.md']);
1680
- expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
1681
- expect(fs.existsSync(path.join(tmpDir, 'GEMINI.md'))).toBe(false);
1682
- expect(fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8')).toBe('# Claude\n');
1683
- });
1684
-
1685
- it('keeps a GEMINI.md that has the project\'s own content', () => {
1686
- fs.writeFileSync(
1687
- path.join(tmpDir, 'GEMINI.md'),
1688
- `# Gemini\n\nUse tabs.\n\n${GEMINI_IMPORT}`,
1689
- );
1690
-
1691
- expect(removeAgentDocs(tmpDir)).toEqual(['GEMINI.md']);
1692
- expect(fs.readFileSync(path.join(tmpDir, 'GEMINI.md'), 'utf-8')).toBe(
1693
- '# Gemini\n\nUse tabs.\n',
1694
- );
1695
- });
1696
- });
1697
-
1698
- describe('agent docs never go into the home folder', () => {
1699
- const saved = {HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE};
1700
- const personal = '# My notes\n\nAlways use tabs.\n';
1701
-
1702
- beforeEach(() => {
1703
- process.env.HOME = tmpDir;
1704
- process.env.USERPROFILE = tmpDir;
1705
- fs.mkdirSync(path.join(tmpDir, '.claude'), {recursive: true});
1706
- fs.writeFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), personal);
1707
- });
1708
- afterEach(() => {
1709
- for (const [key, value] of Object.entries(saved)) {
1710
- if (value === undefined) delete process.env[key];
1711
- else process.env[key] = value;
1712
- }
1713
- });
1714
-
1715
- it.each([
1716
- ['the default', {}],
1717
- ['a preset', {agent: 'claude'}],
1718
- ['an explicit path', {paths: ['AGENTS.md']}],
1719
- ['a refresh', {onlyReplace: true}],
1720
- ])('refuses %s and writes nothing', (_label, options) => {
1721
- expect(() => installAgentDocs(tmpDir, options)).toThrow(AgentDocsHomeError);
1722
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1723
- personal,
1724
- );
1725
- expect(fs.readdirSync(tmpDir).sort()).toEqual(['.claude']);
1726
- });
1727
-
1728
- it('writes an explicit path into a plain folder of the home folder, as 0.7.x did', () => {
1729
- expect(installAgentDocs(tmpDir, {paths: ['notes/AI.md']})).toEqual(['notes/AI.md']);
1730
- expect(fs.readFileSync(path.join(tmpDir, 'notes', 'AI.md'), 'utf-8')).toContain(
1731
- '<!-- ASTRYX:START -->',
1732
- );
1733
- });
1734
-
1735
- it.each([
1736
- ['a file in the home folder', ['AI.md']],
1737
- ['a file at the top of a settings folder', ['.claude/CLAUDE.md']],
1738
- ['one of several paths', ['notes/AI.md', 'AI.md']],
1739
- ])('refuses an explicit path to %s, and writes nothing', (_label, paths) => {
1740
- expect(() => installAgentDocs(tmpDir, {paths})).toThrow(AgentDocsHomeError);
1741
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1742
- personal,
1743
- );
1744
- expect(fs.readdirSync(tmpDir).sort()).toEqual(['.claude']);
1745
- });
1746
-
1747
- it('init with an explicit path from the home folder writes it, and refuses one in the home folder', async () => {
1748
- const {init} = await import('../../api/init/init.mjs');
1749
- const written = await init(
1750
- {features: ['agents'], agentDocsPath: 'notes/AI.md'},
1751
- {cwd: tmpDir},
1752
- );
1753
- expect(written.data.docsWritten).toEqual(['notes/AI.md']);
1754
- expect(written.data.docsError ?? null).toBeNull();
1755
- const refused = await init(
1756
- {features: ['agents'], agentDocsPath: 'AI.md'},
1757
- {cwd: tmpDir},
1758
- );
1759
- expect(refused.data.docsError).toMatchObject({kind: 'install-failed'});
1760
- expect(fs.existsSync(path.join(tmpDir, 'AI.md'))).toBe(false);
1761
- });
1762
-
1763
- it('refuses through a symlink to the home folder', () => {
1764
- const link = `${tmpDir}-link`;
1765
- fs.symlinkSync(tmpDir, link);
1766
- try {
1767
- expect(() => installAgentDocs(link)).toThrow(AgentDocsHomeError);
1768
- } finally {
1769
- fs.rmSync(link);
1770
- }
1771
- });
1772
-
1773
- it('still removes a block an older run wrote there', () => {
1774
- vi.spyOn(console, 'log').mockImplementation(() => {});
1775
- fs.writeFileSync(
1776
- path.join(tmpDir, '.claude', 'CLAUDE.md'),
1777
- `${personal}\n<!-- ASTRYX:START -->\nAstryx v1.0.0\n<!-- ASTRYX:END -->\n`,
1778
- );
1779
-
1780
- expect(removeAgentDocs(tmpDir)).toEqual(['.claude/CLAUDE.md']);
1781
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1782
- personal,
1783
- );
1784
- });
1785
-
1786
- it.each(['.gemini', '.claude', '.codex', path.join('.gemini', 'extensions', 'x')])(
1787
- 'refuses the settings folder ~/%s',
1788
- folder => {
1789
- const dir = path.join(tmpDir, folder);
1790
- fs.mkdirSync(dir, {recursive: true});
1791
- const before = fs.readdirSync(dir);
1792
- expect(() => installAgentDocs(dir)).toThrow(AgentDocsHomeError);
1793
- expect(fs.readdirSync(dir)).toEqual(before);
1794
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1795
- personal,
1796
- );
1797
- },
1798
- );
1799
-
1800
- it('writes in a project folder inside the home folder', () => {
1801
- const project = path.join(tmpDir, 'app');
1802
- fs.mkdirSync(project);
1803
- expect(installAgentDocs(project)).toEqual(['AGENTS.md', 'GEMINI.md']);
1804
- });
1805
-
1806
- /**
1807
- * A git project that declares Astryx, at `rel` under the home folder, with
1808
- * Core installed at `version`.
1809
- * @param {string} rel
1810
- * @param {string} version
1811
- */
1812
- function writeProject(rel, version) {
1813
- const project = path.join(tmpDir, rel);
1814
- fs.mkdirSync(path.join(project, 'src'), {recursive: true});
1815
- fs.writeFileSync(path.join(project, '.git'), 'gitdir: /elsewhere/.git/worktrees/web\n');
1816
- fs.writeFileSync(
1817
- path.join(project, 'package.json'),
1818
- JSON.stringify({name: 'web', dependencies: {'@astryxdesign/core': version}}),
1819
- );
1820
- const core = path.join(project, 'node_modules', '@astryxdesign', 'core');
1821
- fs.mkdirSync(core, {recursive: true});
1822
- fs.writeFileSync(path.join(core, 'package.json'), JSON.stringify({version}));
1823
- return project;
1824
- }
1825
-
1826
- it.each([
1827
- ['a Codex worktree', path.join('.codex', 'worktrees', 'a1b2c3', 'web')],
1828
- ['a Cursor worktree', path.join('.cursor', 'worktrees', 'web', 'x9y8')],
1829
- ['a project with its package.json one level in', path.join('.config', 'web')],
1830
- ])('writes and refreshes the docs of a project inside a settings folder (%s)', (_label, rel) => {
1831
- const project = writeProject(rel, '1.0.0');
1832
-
1833
- expect(resolveAgentDocsRoot(path.join(project, 'src'))).toBe(project);
1834
- expect(installAgentDocs(project)).toEqual(['AGENTS.md', 'GEMINI.md']);
1835
-
1836
- // upgrade refreshes the block in place.
1837
- writeProject(rel, '2.0.0');
1838
- expect(installAgentDocs(project, {onlyReplace: true})).toEqual(['AGENTS.md']);
1839
- expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf-8')).toContain(
1840
- 'Astryx v2.0.0',
1841
- );
1842
-
1843
- // Nothing reaches the settings folder or the home folder.
1844
- const settings = path.join(tmpDir, rel.split(path.sep)[0]);
1845
- expect(fs.readdirSync(settings)).toEqual([rel.split(path.sep)[1]]);
1846
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1847
- personal,
1848
- );
1849
- });
1850
-
1851
- it('refuses the top of a settings folder even with a package.json, and the folders in it outside a project', () => {
1852
- // A package.json in ~/.claude (for hook scripts, say) would otherwise put the
1853
- // block in ~/.claude/CLAUDE.md, which Claude Code reads in every project.
1854
- fs.writeFileSync(path.join(tmpDir, '.claude', 'package.json'), '{"name":"hooks"}\n');
1855
- fs.mkdirSync(path.join(tmpDir, '.claude', 'hooks'));
1856
-
1857
- expect(() => installAgentDocs(path.join(tmpDir, '.claude'))).toThrow(AgentDocsHomeError);
1858
- expect(() => installAgentDocs(path.join(tmpDir, '.claude', 'hooks'))).toThrow(
1859
- AgentDocsHomeError,
1860
- );
1861
- expect(resolveAgentDocsRoot(path.join(tmpDir, '.claude', 'hooks'))).toBe(
1862
- path.join(tmpDir, '.claude'),
1863
- );
1864
- expect(fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8')).toBe(
1865
- personal,
1866
- );
1867
-
1868
- // A worktree folder whose project has no package.json is not a project.
1869
- const bare = path.join(tmpDir, '.codex', 'worktrees', 'a1b2c3', 'notes');
1870
- fs.mkdirSync(bare, {recursive: true});
1871
- expect(() => installAgentDocs(bare)).toThrow(AgentDocsHomeError);
1872
- expect(fs.readdirSync(bare)).toEqual([]);
1873
- });
1874
- });
1875
-
1876
- describe('resolveAgentDocsRoot', () => {
1877
- /** @param {string} dir @param {object} pkg */
1878
- const writePkg = (dir, pkg) => {
1879
- fs.mkdirSync(dir, {recursive: true});
1880
- fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkg));
1881
- };
1882
- const astryx = {devDependencies: {'@astryxdesign/cli': '0.7.0'}};
1883
-
1884
- it('finds the nearest folder whose package.json declares Astryx', () => {
1885
- writePkg(tmpDir, astryx);
1886
- const sub = path.join(tmpDir, 'src', 'app');
1887
- fs.mkdirSync(sub, {recursive: true});
1888
- expect(resolveAgentDocsRoot(sub)).toBe(tmpDir);
1889
- expect(resolveAgentDocsRoot(tmpDir)).toBe(tmpDir);
1890
-
1891
- // A nested package that does not declare Astryx is passed over.
1892
- const functions = path.join(tmpDir, 'functions');
1893
- writePkg(functions, {name: 'functions'});
1894
- fs.mkdirSync(path.join(functions, 'src'));
1895
- expect(resolveAgentDocsRoot(path.join(functions, 'src'))).toBe(tmpDir);
1896
-
1897
- // A nested package that declares Astryx is its own project.
1898
- const web = path.join(tmpDir, 'apps', 'web');
1899
- writePkg(web, {dependencies: {'@astryxdesign/core': '0.7.0'}});
1900
- expect(resolveAgentDocsRoot(web)).toBe(web);
1901
- });
1902
-
1903
- it('falls back to the nearest package.json when none declares Astryx', () => {
1904
- writePkg(tmpDir, {name: 'app'});
1905
- const pkg = path.join(tmpDir, 'packages', 'web');
1906
- writePkg(pkg, {name: 'web'});
1907
- fs.mkdirSync(path.join(pkg, 'src'));
1908
- expect(resolveAgentDocsRoot(path.join(pkg, 'src'))).toBe(pkg);
1909
- });
1910
-
1911
- it('stops at a repository root, and finds no project without a package.json', () => {
1912
- writePkg(tmpDir, astryx);
1913
- const repo = path.join(tmpDir, 'repo');
1914
- fs.mkdirSync(path.join(repo, '.git'), {recursive: true});
1915
- const sub = path.join(repo, 'docs');
1916
- fs.mkdirSync(sub);
1917
- expect(resolveAgentDocsRoot(sub)).toBeNull();
1918
- });
1919
-
1920
- it('never returns the home folder', () => {
1921
- const saved = {HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE};
1922
- process.env.HOME = tmpDir;
1923
- process.env.USERPROFILE = tmpDir;
1924
- try {
1925
- writePkg(tmpDir, astryx);
1926
- const scratch = path.join(tmpDir, 'scratch');
1927
- fs.mkdirSync(scratch);
1928
- expect(resolveAgentDocsRoot(scratch)).toBeNull();
1929
- expect(resolveAgentDocsRoot(tmpDir)).toBeNull();
1930
- } finally {
1931
- for (const [key, value] of Object.entries(saved)) {
1932
- if (value === undefined) delete process.env[key];
1933
- else process.env[key] = value;
1934
- }
1935
- }
1936
- });
1937
- });