@bevel-software/platform-core-frontend 0.15.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +16 -9
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/events.test.ts +43 -0
  6. package/src/core/bootstrap.ts +11 -3
  7. package/src/core/events.ts +85 -3
  8. package/src/core/registry.ts +1 -1
  9. package/src/lib/__tests__/email.test.ts +44 -0
  10. package/src/lib/email.ts +37 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  12. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  16. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  20. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
  21. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  22. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  23. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  24. package/src/modules/access/api.ts +140 -6
  25. package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
  26. package/src/modules/access/manage-access-affordance.ts +17 -0
  27. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  28. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  29. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  30. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  31. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  33. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  34. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  35. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  36. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  37. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  38. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  39. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  40. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  41. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  42. package/src/modules/admin/components/group-members-path.ts +32 -0
  43. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  44. package/src/modules/admin/services/roles.api.ts +12 -1
  45. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  46. package/src/modules/auth/components/AccountPage.tsx +73 -54
  47. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  48. package/src/modules/auth/services/account.api.ts +78 -4
  49. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  57. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  58. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  59. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  60. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  61. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  62. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  63. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  64. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  65. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  66. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  67. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  68. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  69. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  70. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  71. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  72. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  73. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  74. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  75. package/src/modules/change-requests/services/propose.api.ts +97 -8
  76. package/src/modules/change-requests/utils/approval.ts +15 -0
  77. package/src/modules/change-requests/utils/author.ts +32 -0
  78. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  79. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  80. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  81. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  82. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  83. package/src/modules/git/services/error-messages.ts +12 -0
  84. package/src/modules/git/services/pr-prompts.ts +5 -5
  85. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  86. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  87. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  88. package/src/modules/layout/components/AppLayout.tsx +2 -0
  89. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  90. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  91. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  92. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  93. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  94. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  95. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  96. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  97. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  98. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  99. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  100. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  101. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  102. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  103. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  104. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  105. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  106. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  107. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  108. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  109. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  110. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  111. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  112. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  113. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  114. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  115. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  116. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  117. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  118. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  119. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  120. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  121. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  122. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  123. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  124. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  125. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  126. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  127. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  128. package/src/modules/library/__tests__/status.test.ts +82 -2
  129. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  130. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  131. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  132. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  133. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  134. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  135. package/src/modules/library/components/LibraryCard.tsx +146 -45
  136. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  137. package/src/modules/library/components/LibraryPage.tsx +172 -39
  138. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  139. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  140. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  141. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  142. package/src/modules/library/components/PageActions.tsx +11 -9
  143. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  144. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  145. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  146. package/src/modules/library/components/PluginExtras.tsx +140 -17
  147. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  148. package/src/modules/library/components/PluginPage.tsx +157 -41
  149. package/src/modules/library/components/PluginRows.tsx +286 -0
  150. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  151. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  152. package/src/modules/library/components/ShareButton.tsx +17 -0
  153. package/src/modules/library/components/SkillsTree.tsx +141 -28
  154. package/src/modules/library/components/TeamRoute.tsx +15 -0
  155. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  156. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  157. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  158. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  159. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  160. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  161. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  162. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  163. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  164. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  165. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  166. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  167. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  168. package/src/modules/library/routes/library-paths.ts +26 -28
  169. package/src/modules/library/services/library.api.ts +38 -20
  170. package/src/modules/library/services/plugins.api.ts +69 -8
  171. package/src/modules/library/services/teams.api.ts +15 -0
  172. package/src/modules/library/services/tools.api.ts +78 -0
  173. package/src/modules/library/state/library-data.tsx +170 -32
  174. package/src/modules/library/utils/personal-plugin.ts +13 -15
  175. package/src/modules/library/utils/plugin-entries.ts +134 -0
  176. package/src/modules/library/utils/plugin-summary.ts +75 -9
  177. package/src/modules/library/utils/status.ts +135 -33
  178. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  179. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  180. package/src/modules/onboarding/agent-clients.ts +55 -23
  181. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  182. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  183. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  184. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  185. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  186. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  187. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  188. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  189. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  190. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  191. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  192. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  193. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  194. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  195. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  196. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  197. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  198. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  199. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  200. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  201. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  202. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  203. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  204. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  205. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  206. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  207. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  208. package/src/modules/settings/services/github-facade.api.ts +23 -0
  209. package/src/modules/settings/settings-nav-items.tsx +10 -2
  210. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  211. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  212. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  213. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  214. package/src/modules/setup/components/SetupGate.tsx +16 -16
  215. package/src/modules/setup/components/SetupScreen.tsx +521 -43
  216. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  217. package/src/modules/setup/services/setup.api.ts +140 -3
  218. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  219. package/src/modules/setup/utils/root-folders.ts +46 -0
  220. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  221. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  232. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  233. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  234. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  235. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  236. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  237. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  238. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  239. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  240. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  241. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  242. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  243. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  244. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  245. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  246. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  247. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  248. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  249. package/src/modules/toolbar/services/external-api-keys.api.ts +6 -0
  250. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  251. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  252. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  254. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  255. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  256. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  257. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  258. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  259. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  260. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  261. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  262. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  263. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  264. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +331 -12
  265. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  266. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  267. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  268. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  269. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  270. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  271. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  272. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  273. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  274. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  275. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  276. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  277. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  279. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  280. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  281. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  282. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  283. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  284. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  285. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  286. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  287. package/src/modules/workspace/components/renderers/index.ts +53 -2
  288. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  289. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  290. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  291. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  292. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  294. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  295. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  296. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  297. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  298. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  299. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  300. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  301. package/src/modules/workspace/services/workspace.api.ts +57 -4
  302. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  303. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  304. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  305. package/src/modules/workspace/state/workspace.context.ts +125 -19
  306. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  307. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  308. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  309. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  310. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  311. package/src/modules/workspace/utils/file-trace.ts +50 -0
  312. package/src/modules/workspace/utils/fileTree.ts +112 -36
  313. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  314. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  315. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  316. package/src/modules/workspace/utils/uploadError.ts +29 -0
  317. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  318. package/src/shared/components/Button.tsx +16 -2
  319. package/src/shared/components/Dialog.tsx +27 -11
  320. package/src/shared/components/Menu.tsx +13 -1
  321. package/src/shared/components/PageShell.tsx +13 -8
  322. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  323. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  324. package/src/shared/components/index.ts +2 -0
  325. package/src/shared/components/useDismissableMenu.ts +32 -10
  326. package/src/shared/components/useFocusHandoff.ts +51 -0
  327. package/src/shared/components/useLatestRef.ts +28 -0
  328. package/src/shared/markdown/Markdown.tsx +12 -3
  329. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  330. package/src/shared/markdown/hrefs.ts +50 -0
  331. package/src/shared/marketplace-url.ts +33 -5
  332. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  333. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  334. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  335. package/src/shared/mcp/connect-snippets.ts +14 -9
  336. package/src/shared/mcp/index.ts +1 -1
  337. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  338. package/src/shared/theme/header.ts +75 -0
  339. package/src/shared/theme/measure.ts +7 -4
  340. package/src/shared/theme/tokens.css +25 -0
  341. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  342. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  343. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  344. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  345. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  346. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -1,760 +1,853 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { render, renderHook, screen, cleanup, waitFor } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
5
- import { AuthContext } from '../../auth/state/auth.context';
6
- import { authValue } from '../../library/__tests__/auth-harness';
7
- import { LibraryToastProvider } from '../../library/state/toast';
8
- import { WelcomePage } from '../components/WelcomePage';
9
- import { AppRegistryContext, EMPTY_REGISTRY } from '../../../core/registry';
10
- import { ConnectAgentPill } from '../components/ConnectAgentPill';
11
- import { RootLanding } from '../components/RootLanding';
12
- import { POST_LOGIN_REDIRECT_KEY } from '../../auth/services/sso';
13
- import { WELCOME_PATH } from '../paths';
14
- import { resetOnboardingForTests } from '../state/onboarding';
15
- import { configureMcpUrl } from '../../../shared/mcp';
16
- import { setSidebarCollapsed, useSidebar } from '../../layout/state/sidebar';
17
-
18
- /**
19
- * The onboarding contract, end to end on the client:
20
- *
21
- * - `/` redirects to the welcome page ONCE, on an account the server says is
22
- * not onboarded — and never hijacks anything after that first greeting.
23
- * - the pill outlives the redirect: it stays until × or Done, exactly two.
24
- * - Done concludes (server write + navigation); the skip link and the copy
25
- * button conclude NOTHING — leaving and copying are not promises.
26
- */
27
-
28
- // No parameters: the mock never reads its arguments, and `vi.fn` records every
29
- // call regardless of the implementation's signature — so the call assertions
30
- // below keep working while lint stays clean.
31
- const { authFetchMock } = vi.hoisted(() => ({
32
- authFetchMock: vi.fn(async () => ({ ok: true, status: 200 }) as Response),
33
- }));
34
- vi.mock('../../../lib/api', () => ({ authFetch: authFetchMock }));
35
-
36
- /**
37
- * The `RequestInit` of a recorded `authFetch` call.
38
- *
39
- * The mock declares no parameters — deliberately, so lint stays clean — which
40
- * leaves `mock.calls` typed as an empty tuple even though the calls really do
41
- * carry two arguments. Naming that gap ONCE, here, is better than a cast at
42
- * every assertion that wants to read a request body.
43
- */
44
- function fetchInit(call = 0): RequestInit | undefined {
45
- return (authFetchMock.mock.calls[call] as unknown as [string, RequestInit] | undefined)?.[1];
46
- }
47
-
48
- /** A user the server considers NOT onboarded (the explicit false matters). */
49
- const newUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: false } });
50
- /** The same account after the server has recorded the onboarding as done. */
51
- const doneUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: true } });
52
-
53
- /** Reads the sidebar store the way a component would. */
54
- function sidebarState() {
55
- return renderHook(() => useSidebar()).result.current;
56
- }
57
-
58
- /** Where we are, whether we got here by being greeted, and any carried link. */
59
- function LocationProbe() {
60
- const { pathname, state } = useLocation();
61
- const s = state as { greeting?: boolean; returnTo?: string | null } | null;
62
- return (
63
- <>
64
- <div data-testid="pathname">{pathname}</div>
65
- <div data-testid="greeting">{String(s?.greeting === true)}</div>
66
- <div data-testid="returnTo">{s?.returnTo ?? ''}</div>
67
- </>
68
- );
69
- }
70
-
71
- /** The welcome page as the first-sign-in redirect leaves it: greeted. */
72
- const greeted = { pathname: WELCOME_PATH, state: { greeting: true } };
73
-
74
- /**
75
- * Render `ui` inside the three contexts the onboarding actually reads — a
76
- * router at `route`, an auth context holding `auth`, and the toast provider —
77
- * plus the location probe every redirect assertion below looks at. `route`
78
- * takes a location object when a test needs to arrive as the greeting does.
79
- */
80
- function mount(
81
- ui: React.ReactNode,
82
- auth = newUser(),
83
- route: string | { pathname: string; state?: unknown } = '/',
84
- ) {
85
- return render(
86
- <MemoryRouter initialEntries={[route]}>
87
- <AuthContext.Provider value={auth}>
88
- <LibraryToastProvider>
89
- {ui}
90
- <LocationProbe />
91
- </LibraryToastProvider>
92
- </AuthContext.Provider>
93
- </MemoryRouter>,
94
- );
95
- }
96
-
97
- const landingRoutes = (
98
- <Routes>
99
- <Route path="/" element={<RootLanding />} />
100
- <Route path={WELCOME_PATH} element={<div>welcome page</div>} />
101
- <Route path="/workspace" element={<div>knowledge</div>} />
102
- </Routes>
103
- );
104
-
105
- beforeEach(() => {
106
- resetOnboardingForTests();
107
- authFetchMock.mockClear();
108
- sessionStorage.clear();
109
- });
110
-
111
- /**
112
- * jsdom ships no `navigator.clipboard`, so a copy test has to install one —
113
- * but only THAT property, never a replacement `navigator`: the rest of the
114
- * object (`userAgent`, `language`, whatever a library reaches for next) has no
115
- * business changing because one test wanted a spy.
116
- */
117
- let restoreClipboard: (() => void) | null = null;
118
-
119
- function stubClipboard() {
120
- const writeText = vi.fn().mockResolvedValue(undefined);
121
- const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
122
- Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
123
- restoreClipboard = () => {
124
- if (original) Object.defineProperty(navigator, 'clipboard', original);
125
- else Reflect.deleteProperty(navigator, 'clipboard');
126
- };
127
- return writeText;
128
- }
129
-
130
- // In a hook, not at the end of a test body: a failing assertion would otherwise
131
- // leave the stub installed for every test after it.
132
- afterEach(() => {
133
- restoreClipboard?.();
134
- restoreClipboard = null;
135
- vi.unstubAllGlobals();
136
- });
137
-
138
- describe('RootLanding: the one-time greeting', () => {
139
- it('sends a brand-new account to the welcome page', () => {
140
- mount(landingRoutes);
141
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
142
- });
143
-
144
- // The flag the page reads to know this arrival is a ceremony rather than a
145
- // visit — the sidebar collapse hangs off it, and only this navigation sets it.
146
- it('marks the automatic redirect as a greeting', () => {
147
- mount(landingRoutes);
148
- expect(screen.getByTestId('greeting')).toHaveTextContent('true');
149
- });
150
-
151
- it('sends everyone the server marked done straight to Knowledge', () => {
152
- mount(landingRoutes, doneUser());
153
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
154
- });
155
-
156
- // Optional-field semantics: an ABSENT flag (old fixture, cached session)
157
- // must never resurrect the welcome flow. Only an explicit false onboards.
158
- it('treats a missing flag as done, not as new', () => {
159
- mount(landingRoutes, authValue());
160
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
161
- });
162
-
163
- /**
164
- * The SSO round-trip returns to a fixed callback URL, so a deep link
165
- * someone clicked dies in transit unless `startSsoLogin` stashed it. These
166
- * prove the far side: the stash is honoured, exactly once, and can never
167
- * point off-site.
168
- */
169
- it('sends an existing account straight to the stashed deep link, once', () => {
170
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
171
- sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
172
- mount(landingRoutes, doneUser());
173
- expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
174
- // Taken, not peeked: the next front-door visit is an ordinary one.
175
- expect(sessionStorage.getItem(POST_LOGIN_REDIRECT_KEY)).toBeNull();
176
- });
177
-
178
- it('greets a brand-new account first, handing the link to the welcome page', () => {
179
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
180
- sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
181
- mount(landingRoutes);
182
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
183
- expect(screen.getByTestId('greeting')).toHaveTextContent('true');
184
- expect(screen.getByTestId('returnTo')).toHaveTextContent(DEEP);
185
- });
186
-
187
- it('discards a stash that is not an in-app path — never an off-site redirect', () => {
188
- sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, '//evil.example/phish');
189
- mount(landingRoutes, doneUser());
190
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
191
- });
192
-
193
- it('greets ONCE: after the welcome page has been seen, / goes to Knowledge', async () => {
194
- mount(
195
- <Routes>
196
- <Route path="/" element={<RootLanding />} />
197
- <Route path={WELCOME_PATH} element={<WelcomePage />} />
198
- <Route path="/workspace" element={<div>knowledge</div>} />
199
- </Routes>,
200
- );
201
- // Landed on the real page, which marks `welcomed` on mount.
202
- await screen.findByRole('heading', { name: /Welcome, Juan/ });
203
- cleanup();
204
- // A fresh visit to `/` — same account, same browser.
205
- mount(landingRoutes);
206
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
207
- });
208
- });
209
-
210
- describe('WelcomePage', () => {
211
- // Default: the ordinary visit, from the sidebar pill. The greeting — the
212
- // one-time redirect — is the special case, and says so at each call site.
213
- const mountPage = (auth = newUser(), route: string | typeof greeted = WELCOME_PATH) =>
214
- mount(
215
- <Routes>
216
- <Route path={WELCOME_PATH} element={<WelcomePage />} />
217
- <Route path="/skills-and-tools" element={<div>library</div>} />
218
- <Route path="/skills-and-tools/yours" element={<div>your plugin</div>} />
219
- </Routes>,
220
- auth,
221
- route,
222
- );
223
-
224
- it('addresses the person by first name', () => {
225
- mountPage();
226
- expect(screen.getByRole('heading', { name: 'Welcome, Juan' })).toBeInTheDocument();
227
- });
228
-
229
- /**
230
- * The entrance must BEGIN on a painted frame. A CSS animation runs on the
231
- * document timeline whether or not the browser is producing frames, so an
232
- * animation attached at mount can elapse entirely during a cold boot and
233
- * never be seen — the bug that made this page "just appear" at every
234
- * duration we tried. Held invisible first, animating second.
235
- */
236
- it('starts its entrance on a painted frame, not at mount', async () => {
237
- mountPage(newUser(), greeted);
238
- const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
239
- const body = screen.getByText(/company’s shared library/).parentElement!;
240
- // An inline style, deliberately — a utility class would depend on Tailwind
241
- // having compiled it, and that is exactly what failed silently before.
242
- expect(title.style.opacity).toBe('0');
243
- expect(body.style.opacity).toBe('0');
244
- await waitFor(() => {
245
- expect(title.className).toContain('animate-onboarding-greeting');
246
- expect(body.className).toContain('animate-onboarding-body');
247
- });
248
- // …and never both at once: held invisible and animating would fight.
249
- expect(title.style.opacity).toBe('');
250
- expect(body.style.opacity).toBe('');
251
- });
252
-
253
- /**
254
- * Being welcomed happens once. Opening the same page from the pill later is
255
- * a visit, and a 2.6s arrival every time you come back to copy your MCP
256
- * snippet is a page you learn to dread — so there is no hold and no fade,
257
- * only the page.
258
- */
259
- it('does not replay the entrance when you open it from the pill', () => {
260
- mountPage();
261
- const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
262
- expect(title.style.opacity).toBe('');
263
- expect(title.className).not.toContain('animate-onboarding-greeting');
264
- });
265
-
266
- // However the sign-in record spells it. The page addressed to one person is
267
- // the last place that should get their name wrong.
268
- it('capitalizes the name whatever the account holds', () => {
269
- mountPage(authValue({ user: { id: 'u1', email: 'j@bevel.software', name: 'juan viera', onboardingDone: false } }));
270
- expect(screen.getByRole('heading', { name: 'Welcome, Juan' })).toBeInTheDocument();
271
- });
272
-
273
- it('greets someone with no name at all', () => {
274
- mountPage(authValue({ user: { id: 'u1', email: 'j@bevel.software', name: '', onboardingDone: false } }));
275
- expect(screen.getByRole('heading', { name: 'Welcome, there' })).toBeInTheDocument();
276
- });
277
-
278
- /**
279
- * The nav gets out of the way for the greeting and STAYS out — there is no
280
- * restore. Putting it back meant leaving a screen with no nav and arriving
281
- * at one where the nav had opened itself, which is the app rearranging a
282
- * page you asked for. Whether the sidebar shows is the toolbar toggle's to
283
- * say, and after the greeting it says whatever it said last.
284
- */
285
- it('collapses the sidebar for the greeting, without animating it', () => {
286
- setSidebarCollapsed(false);
287
- mountPage(newUser(), greeted);
288
- expect(sidebarState()).toMatchObject({ collapsed: true, instant: true });
289
- });
290
-
291
- it('leaves it collapsed when you go to your own plugin', async () => {
292
- setSidebarCollapsed(false);
293
- mountPage(newUser(), greeted);
294
- await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
295
- expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
296
- expect(sidebarState().collapsed).toBe(true);
297
- });
298
-
299
- it('leaves it collapsed after Done too', async () => {
300
- setSidebarCollapsed(false);
301
- mountPage(newUser(), greeted);
302
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
303
- expect(sidebarState().collapsed).toBe(true);
304
- });
305
-
306
- /**
307
- * The one case where the nav is showing on the way out: you opened it
308
- * yourself while you were here. The page collapses once, on arrival, and
309
- * never touches the store again — so your gesture is the last word.
310
- */
311
- it('respects a sidebar you opened yourself while reading the page', async () => {
312
- setSidebarCollapsed(false);
313
- mountPage(newUser(), greeted);
314
- expect(sidebarState().collapsed).toBe(true);
315
- setSidebarCollapsed(false); // …the toolbar toggle, from the user's hand
316
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
317
- expect(sidebarState().collapsed).toBe(false);
318
- });
319
-
320
- it('leaves it collapsed for someone who arrived that way', () => {
321
- setSidebarCollapsed(true);
322
- const { unmount } = mountPage(newUser(), greeted);
323
- expect(sidebarState().collapsed).toBe(true);
324
- unmount();
325
- expect(sidebarState().collapsed).toBe(true);
326
- });
327
-
328
- // Reached from the pill it is a page, not a ceremony: the nav it was just
329
- // clicked in stays exactly where it is.
330
- it('leaves the sidebar alone when you open it from the pill', () => {
331
- setSidebarCollapsed(false);
332
- const { unmount } = mountPage();
333
- expect(sidebarState().collapsed).toBe(false);
334
- unmount();
335
- expect(sidebarState().collapsed).toBe(false);
336
- });
337
-
338
- it('shows one snippet at a time, following the picker', async () => {
339
- mountPage();
340
- // Desktop agents default: the local hexis-mcp config, not the bare URL.
341
- expect(screen.getByText(/@bevel-software\/hexis-mcp/)).toBeInTheDocument();
342
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
343
- expect(screen.getByText(/\/api\/mcp$/)).toBeInTheDocument();
344
- expect(screen.queryByText(/mcpServers/)).toBeNull();
345
- await userEvent.click(screen.getByRole('radio', { name: 'Other' }));
346
- expect(screen.getByText(/skills-tools-knowledge/)).toBeInTheDocument();
347
- });
348
-
349
- /**
350
- * The RECOMMENDED default: the local server serves everything the hosted
351
- * endpoint does plus the plugins' local-only tools, so the picker leads
352
- * with it and the page opens on it. No key exists at onboarding time, so
353
- * the snippet must carry the placeholder that tells someone what to paste
354
- * — keyless is the interactive mode: the local server opens the browser
355
- * to sign in on first run, so the config carries no key at all.
356
- */
357
- it('defaults to Desktop agents: the keyless hexis-mcp config', () => {
358
- mountPage();
359
- expect(screen.getByRole('radio', { name: 'Desktop agents' })).toHaveAttribute(
360
- 'aria-checked',
361
- 'true',
362
- );
363
- const snippet = screen.getByText(/mcpServers/).textContent!;
364
- expect(snippet).toContain('@bevel-software/hexis-mcp');
365
- // Keyless = interactive sign-in: no key env at all, not a placeholder —
366
- // the server opens the browser on first run.
367
- expect(snippet).not.toContain('HEXIS_CONNECTION_KEY');
368
- // The hint says how identity arrives instead: browser sign-in on first run.
369
- expect(screen.getByText(/your browser opens so you can sign in/)).toBeInTheDocument();
370
- });
371
-
372
- /**
373
- * One click instead of a menu path. It is Claude-only because Claude is the
374
- * only client with a documented install link, and it appears only when
375
- * Anthropic could actually reach this deployment — see `canDeepLink`. The
376
- * copy block stays either way; it is the route that always works.
377
- *
378
- * Every case selects the Claude option first: the picker now defaults to
379
- * Desktop agents (the local server), and the install link belongs to the
380
- * hosted claude.ai path alone.
381
- */
382
- describe('the Add to Claude link', () => {
383
- it('offers one-click connect on a reachable deployment', async () => {
384
- configureMcpUrl('https://kb.acme.com/api/mcp');
385
- mountPage();
386
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
387
- const link = screen.getByRole('link', { name: 'Add to Claude' });
388
- const href = new URL(link.getAttribute('href')!);
389
- expect(href.origin + href.pathname).toBe('https://claude.ai/customize/connectors');
390
- expect(href.searchParams.get('connectorUrl')).toBe('https://kb.acme.com/api/mcp');
391
- expect(href.searchParams.get('connectorName')).toBe('Skills, Tools and Knowledge — kb.acme.com');
392
- });
393
-
394
- /**
395
- * The default install: `PUBLIC_BACKEND_URL` unset means localhost, which
396
- * claude.ai cannot reach. A dead button on the first screen a self-hoster
397
- * sees reads as a broken product.
398
- */
399
- it('offers nothing to click on a localhost deployment', async () => {
400
- configureMcpUrl('http://localhost:3001/api/mcp');
401
- mountPage();
402
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
403
- expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
404
- // …and the route that always works is still there.
405
- expect(screen.getByText('http://localhost:3001/api/mcp')).toBeInTheDocument();
406
- });
407
-
408
- /**
409
- * No `PUBLIC_BACKEND_URL` hint on THIS surface. The reader is a new
410
- * employee who cannot change deployment config; naming an env var at them
411
- * is noise. The settings page, whose reader plausibly can, says it there.
412
- */
413
- it('does not lecture a new employee about deployment config', async () => {
414
- configureMcpUrl('http://localhost:3001/api/mcp');
415
- mountPage();
416
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
417
- expect(screen.queryByText(/PUBLIC_BACKEND_URL/)).toBeNull();
418
- });
419
-
420
- it('belongs to Claude alone', async () => {
421
- configureMcpUrl('https://kb.acme.com/api/mcp');
422
- mountPage();
423
- // The default — Desktop agents — earns no install link either.
424
- expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
425
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
426
- expect(screen.getByRole('link', { name: 'Add to Claude' })).toBeInTheDocument();
427
- await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
428
- expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
429
- await userEvent.click(screen.getByRole('radio', { name: 'Other' }));
430
- expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
431
- });
432
-
433
- /**
434
- * ChatGPT gets its own button, on its own option only. It cannot prefill
435
- * anything — ChatGPT has no such link — so it opens the settings pane and
436
- * the hint beside it spells out the name to type, which is what stops a
437
- * dozen employees each inventing their own.
438
- */
439
- it('offers Add to ChatGPT on the ChatGPT option alone, with the name to type', async () => {
440
- configureMcpUrl('https://kb.acme.com/api/mcp');
441
- mountPage();
442
- expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
443
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
444
- expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
445
- await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
446
- const link = screen.getByRole('link', { name: 'Add to ChatGPT' });
447
- expect(link).toHaveAttribute('href', 'https://chatgpt.com/#settings/Connectors');
448
- expect(link).toHaveAttribute('target', '_blank');
449
- expect(link).toHaveAttribute('rel', 'noopener noreferrer');
450
- expect(screen.getByText(/Skills, Tools and Knowledge/)).toBeInTheDocument();
451
- // …and the URL to paste is still the copy block.
452
- expect(screen.getByText('https://kb.acme.com/api/mcp')).toBeInTheDocument();
453
- });
454
-
455
- it('offers no ChatGPT button on a localhost deployment either', async () => {
456
- configureMcpUrl('http://localhost:3001/api/mcp');
457
- mountPage();
458
- await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
459
- expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
460
- expect(screen.getByText('http://localhost:3001/api/mcp')).toBeInTheDocument();
461
- });
462
-
463
- // Opening claude.ai must not hand it a handle on this window.
464
- it('opens in a new tab safely', async () => {
465
- configureMcpUrl('https://kb.acme.com/api/mcp');
466
- mountPage();
467
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
468
- const link = screen.getByRole('link', { name: 'Add to Claude' });
469
- expect(link).toHaveAttribute('target', '_blank');
470
- expect(link).toHaveAttribute('rel', 'noopener noreferrer');
471
- });
472
-
473
- /**
474
- * The whole point of the canonical URL: what the button hands Claude and
475
- * what the copy block shows a human must be the same string, or one of
476
- * them is lying.
477
- */
478
- it('hands Claude exactly the URL the copy block shows', async () => {
479
- configureMcpUrl('https://kb.acme.com/api/mcp');
480
- mountPage();
481
- await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
482
- const href = new URL(
483
- screen.getByRole('link', { name: 'Add to Claude' }).getAttribute('href')!,
484
- );
485
- expect(href.searchParams.get('connectorUrl')).toBe(
486
- screen.getByText(/\/api\/mcp$/).textContent,
487
- );
488
- });
489
- });
490
-
491
- it('copies the visible snippet without concluding anything', async () => {
492
- const writeText = stubClipboard();
493
- mountPage();
494
- await userEvent.click(screen.getByRole('button', { name: 'Copy' }));
495
- // The default snippet is the local server's config, not the hosted URL.
496
- expect(writeText).toHaveBeenCalledWith(expect.stringContaining('@bevel-software/hexis-mcp'));
497
- // Copying is not Done: no server write, no navigation.
498
- expect(authFetchMock).not.toHaveBeenCalled();
499
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
500
- });
501
-
502
- // Exact, not a substring: `/skills-and-tools` is a PREFIX of the personal
503
- // plugin's path, so a loose match would pass even if Done dropped someone in
504
- // the whole company's catalog instead of their own shelf.
505
- it('Done concludes: server write + landing in your own plugin', async () => {
506
- mountPage();
507
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
508
- expect(authFetchMock).toHaveBeenCalledWith(
509
- '/api/auth/onboarding-done',
510
- expect.objectContaining({ method: 'POST' }),
511
- );
512
- expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/skills-and-tools\/yours$/);
513
- });
514
-
515
- // Both exits, one destination — stated as its own fact so a future change to
516
- // either button has to face the question deliberately.
517
- it('sends you to the same place whether you finish or skip', async () => {
518
- mountPage();
519
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
520
- const afterDone = screen.getByTestId('pathname').textContent;
521
- cleanup();
522
- mountPage();
523
- await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
524
- expect(screen.getByTestId('pathname')).toHaveTextContent(afterDone!);
525
- });
526
-
527
- // Exclusive-choice semantics: `radio` says one of these is always chosen
528
- // and the others are not. Three `aria-pressed` toggles said any combination,
529
- // including none, was possible.
530
- it('presents the client picker as an exclusive choice', async () => {
531
- mountPage();
532
- const group = screen.getByRole('radiogroup', { name: 'Your agent' });
533
- const options = screen.getAllByRole('radio');
534
- expect(group).toContainElement(options[0]!);
535
- // Desktop agents — the local server — leads, and is the default.
536
- expect(options.map((o) => o.getAttribute('aria-checked'))).toEqual([
537
- 'true',
538
- 'false',
539
- 'false',
540
- 'false',
541
- ]);
542
- await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
543
- expect(screen.getAllByRole('radio').map((o) => o.getAttribute('aria-checked'))).toEqual([
544
- 'false',
545
- 'false',
546
- 'true',
547
- 'false',
548
- ]);
549
- });
550
-
551
- /**
552
- * `role="radiogroup"` is a promise about the keyboard, not just a label for
553
- * a screen reader: arrows select, and selection follows focus. The plugin
554
- * wraps, because four options in a row have no edge worth stopping at.
555
- */
556
- it('drives the picker with the arrow keys, wrapping at both ends', async () => {
557
- mountPage();
558
- const checked = () =>
559
- screen.getAllByRole('radio').find((o) => o.getAttribute('aria-checked') === 'true');
560
-
561
- screen.getByRole('radio', { name: 'Desktop agents' }).focus();
562
- await userEvent.keyboard('{ArrowRight}');
563
- expect(checked()).toHaveAccessibleName('Claude');
564
- expect(checked()).toHaveFocus();
565
-
566
- // Off the end and round to the first.
567
- await userEvent.keyboard('{ArrowRight}{ArrowRight}{ArrowRight}');
568
- expect(checked()).toHaveAccessibleName('Desktop agents');
569
-
570
- // And backwards past the start, to the last.
571
- await userEvent.keyboard('{ArrowLeft}');
572
- expect(checked()).toHaveAccessibleName('Other');
573
- });
574
-
575
- // Roving tabindex: the picker is ONE tab stop, not one per client.
576
- it('offers a single tab stop for the whole picker', () => {
577
- mountPage();
578
- expect(screen.getAllByRole('radio').map((o) => o.getAttribute('tabindex'))).toEqual([
579
- '0',
580
- '-1',
581
- '-1',
582
- '-1',
583
- ]);
584
- });
585
-
586
- // Into the person's OWN plugin, not the whole catalog — the same place the
587
- // sidebar's personal row goes.
588
- it('the skip link leaves for your own plugin, without concluding', async () => {
589
- mountPage();
590
- await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
591
- expect(authFetchMock).not.toHaveBeenCalled();
592
- expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
593
- });
594
-
595
- /**
596
- * A deep link that survived the SSO round-trip retargets BOTH exits: the
597
- * greeting concluded by discarding the page someone was sent would cost
598
- * them the reason they came. The skip label says where it now goes.
599
- */
600
- it('keeps a carried deep link: Done lands on it, and the skip link says so', async () => {
601
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
602
- const arrivedWithLink = { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } };
603
- mountPage(newUser(), arrivedWithLink);
604
- expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
605
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
606
- expect(authFetchMock).toHaveBeenCalledWith(
607
- '/api/auth/onboarding-done',
608
- expect.objectContaining({ method: 'POST' }),
609
- );
610
- expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
611
- });
612
-
613
- /**
614
- * `AppRegistry.welcomeExit` moves where a new person starts. WHERE that is,
615
- * is a property of the product: core sends them to their own skills shelf,
616
- * because on a core deployment that is the product and a fresh knowledge
617
- * base is empty. A distribution built around the knowledge graph wants the
618
- * opposite and would otherwise greet someone and then leave them in a
619
- * surface they did not come for.
620
- *
621
- * The tests above deliberately mount WITHOUT a registry, so they pin the
622
- * default: the seam must be invisible to a deployment that does not use it.
623
- */
624
- describe('welcomeExit', () => {
625
- const mountWithExit = (
626
- welcomeExit: { path: string; label: string } | undefined,
627
- // Same shape `mount` accepts — `typeof greeted` would pin `state` to
628
- // `{ greeting: boolean }` and reject the deep-link case below.
629
- route: string | { pathname: string; state?: unknown } = greeted,
630
- ) =>
631
- mount(
632
- <AppRegistryContext.Provider value={{ ...EMPTY_REGISTRY, welcomeExit }}>
633
- <Routes>
634
- <Route path={WELCOME_PATH} element={<WelcomePage />} />
635
- <Route path="/skills-and-tools/yours" element={<div>your plugin</div>} />
636
- <Route path="/workspace" element={<div>knowledge</div>} />
637
- </Routes>
638
- </AppRegistryContext.Provider>,
639
- newUser(),
640
- route,
641
- );
642
-
643
- it('sends both exits to the configured destination', async () => {
644
- mountWithExit({ path: '/workspace', label: 'Go to your knowledge base' });
645
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
646
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
647
- });
648
-
649
- /**
650
- * The label travels WITH the path. "Go to your skills →" pointing at a
651
- * knowledge base is a lie, and letting a caller set one without the other
652
- * is the likeliest way to produce it.
653
- */
654
- it('labels the skip link with the configured destination', () => {
655
- mountWithExit({ path: '/workspace', label: 'Go to your knowledge base' });
656
- expect(
657
- screen.getByRole('button', { name: /Go to your knowledge base/ }),
658
- ).toBeInTheDocument();
659
- expect(screen.queryByRole('button', { name: /Go to your skills/ })).not.toBeInTheDocument();
660
- });
661
-
662
- it('falls back to the skills shelf when a registry sets nothing', async () => {
663
- mountWithExit(undefined);
664
- expect(screen.getByRole('button', { name: /Go to your skills/ })).toBeInTheDocument();
665
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
666
- expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
667
- });
668
-
669
- /**
670
- * A deep link still outranks it. Someone who followed a link is owed that
671
- * link, and no amount of deployment configuration may eat an intention.
672
- */
673
- it('does not override a carried deep link', async () => {
674
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
675
- mountWithExit(
676
- { path: '/skills-and-tools/yours', label: 'Go to your skills' },
677
- { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } },
678
- );
679
- expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
680
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
681
- expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
682
- });
683
- });
684
- });
685
-
686
- describe('ConnectAgentPill', () => {
687
- const mountPill = (auth = newUser(), route = '/skills-and-tools') =>
688
- mount(
689
- <Routes>
690
- <Route path="*" element={<ConnectAgentPill />} />
691
- </Routes>,
692
- auth,
693
- route,
694
- );
695
-
696
- it('shows for a not-onboarded account and leads to the welcome page', async () => {
697
- mountPill();
698
- await userEvent.click(screen.getByRole('button', { name: 'Connect your agent' }));
699
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
700
- // …as a plain visit. The pill opens the page; it does not re-run the
701
- // first-sign-in ceremony that folds the nav it lives in away.
702
- expect(screen.getByTestId('greeting')).toHaveTextContent('false');
703
- });
704
-
705
- it('renders nothing once the server says done', () => {
706
- mountPill(doneUser());
707
- expect(screen.queryByRole('button', { name: 'Connect your agent' })).toBeNull();
708
- });
709
-
710
- // `page`, not `true` — the pill navigates, so the value that means "this is
711
- // the page you are on" is the one a screen reader announces as such.
712
- it('wears the selected state on the welcome page itself', () => {
713
- mountPill(newUser(), WELCOME_PATH);
714
- expect(screen.getByRole('button', { name: 'Connect your agent' })).toHaveAttribute(
715
- 'aria-current',
716
- 'page',
717
- );
718
- });
719
-
720
- it('claims no current page anywhere else', () => {
721
- mountPill();
722
- expect(screen.getByRole('button', { name: 'Connect your agent' })).not.toHaveAttribute(
723
- 'aria-current',
724
- );
725
- });
726
-
727
- it('the × concludes: same field as Done. And the pill goes', async () => {
728
- mountPill();
729
- await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
730
- expect(authFetchMock).toHaveBeenCalledWith(
731
- '/api/auth/onboarding-done',
732
- expect.objectContaining({ method: 'POST' }),
733
- );
734
- expect(screen.queryByRole('button', { name: 'Connect your agent' })).toBeNull();
735
- });
736
-
737
- // The stale-tab guard's client half: the request states which account it
738
- // means, so the server can refuse to conclude somebody else's onboarding.
739
- it('states which account it is concluding', async () => {
740
- mountPill();
741
- await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
742
- expect(JSON.parse(String(fetchInit()?.body))).toEqual({ userId: 'u1' });
743
- });
744
-
745
- /**
746
- * A write that never landed must not leave the UI claiming it did. The pill
747
- * comes back immediately, rather than mysteriously reappearing at the next
748
- * sign-in with no account of why it left.
749
- */
750
- it('brings the pill back when the server refuses the write', async () => {
751
- authFetchMock.mockResolvedValueOnce({ ok: false, status: 409 } as Response);
752
- const errors = vi.spyOn(console, 'error').mockImplementation(() => {});
753
- mountPill();
754
- await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
755
- expect(
756
- await screen.findByRole('button', { name: 'Connect your agent' }),
757
- ).toBeInTheDocument();
758
- errors.mockRestore();
759
- });
760
- });
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { render, renderHook, screen, cleanup, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
5
+ import { AuthContext } from '../../auth/state/auth.context';
6
+ import { authValue } from '../../library/__tests__/auth-harness';
7
+ import { LibraryToastProvider } from '../../library/state/toast';
8
+ import { WelcomePage } from '../components/WelcomePage';
9
+ import { AppRegistryContext, EMPTY_REGISTRY } from '../../../core/registry';
10
+ import { ConnectAgentPill } from '../components/ConnectAgentPill';
11
+ import { RootLanding } from '../components/RootLanding';
12
+ import { POST_LOGIN_REDIRECT_KEY } from '../../auth/services/sso';
13
+ import { WELCOME_PATH } from '../paths';
14
+ import { resetOnboardingForTests } from '../state/onboarding';
15
+ import { configureMcpUrl } from '../../../shared/mcp';
16
+ import { setSidebarCollapsed, useSidebar } from '../../layout/state/sidebar';
17
+
18
+ /**
19
+ * The onboarding contract, end to end on the client:
20
+ *
21
+ * - `/` redirects to the welcome page ONCE, on an account the server says is
22
+ * not onboarded — and never hijacks anything after that first greeting.
23
+ * - the pill outlives the redirect: it stays until × or Done, exactly two.
24
+ * - Done concludes (server write + navigation); the skip link and the copy
25
+ * button conclude NOTHING — leaving and copying are not promises.
26
+ */
27
+
28
+ // No parameters: the mock never reads its arguments, and `vi.fn` records every
29
+ // call regardless of the implementation's signature — so the call assertions
30
+ // below keep working while lint stays clean.
31
+ const { authFetchMock } = vi.hoisted(() => ({
32
+ authFetchMock: vi.fn(async () => ({ ok: true, status: 200 }) as Response),
33
+ }));
34
+ vi.mock('../../../lib/api', () => ({ authFetch: authFetchMock }));
35
+
36
+ /**
37
+ * The `RequestInit` of a recorded `authFetch` call.
38
+ *
39
+ * The mock declares no parameters — deliberately, so lint stays clean — which
40
+ * leaves `mock.calls` typed as an empty tuple even though the calls really do
41
+ * carry two arguments. Naming that gap ONCE, here, is better than a cast at
42
+ * every assertion that wants to read a request body.
43
+ */
44
+ function fetchInit(call = 0): RequestInit | undefined {
45
+ return (authFetchMock.mock.calls[call] as unknown as [string, RequestInit] | undefined)?.[1];
46
+ }
47
+
48
+ /** A user the server considers NOT onboarded (the explicit false matters). */
49
+ const newUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: false } });
50
+ /** The same account after the server has recorded the onboarding as done. */
51
+ const doneUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: true } });
52
+
53
+ /** Reads the sidebar store the way a component would. */
54
+ function sidebarState() {
55
+ return renderHook(() => useSidebar()).result.current;
56
+ }
57
+
58
+ /** Where we are, whether we got here by being greeted, and any carried link. */
59
+ function LocationProbe() {
60
+ const { pathname, state } = useLocation();
61
+ const s = state as { greeting?: boolean; returnTo?: string | null } | null;
62
+ return (
63
+ <>
64
+ <div data-testid="pathname">{pathname}</div>
65
+ <div data-testid="greeting">{String(s?.greeting === true)}</div>
66
+ <div data-testid="returnTo">{s?.returnTo ?? ''}</div>
67
+ </>
68
+ );
69
+ }
70
+
71
+ /** The welcome page as the first-sign-in redirect leaves it: greeted. */
72
+ const greeted = { pathname: WELCOME_PATH, state: { greeting: true } };
73
+
74
+ /**
75
+ * Render `ui` inside the three contexts the onboarding actually reads — a
76
+ * router at `route`, an auth context holding `auth`, and the toast provider —
77
+ * plus the location probe every redirect assertion below looks at. `route`
78
+ * takes a location object when a test needs to arrive as the greeting does.
79
+ */
80
+ function mount(
81
+ ui: React.ReactNode,
82
+ auth = newUser(),
83
+ route: string | { pathname: string; state?: unknown } = '/',
84
+ ) {
85
+ return render(
86
+ <MemoryRouter initialEntries={[route]}>
87
+ <AuthContext.Provider value={auth}>
88
+ <LibraryToastProvider>
89
+ {ui}
90
+ <LocationProbe />
91
+ </LibraryToastProvider>
92
+ </AuthContext.Provider>
93
+ </MemoryRouter>,
94
+ );
95
+ }
96
+
97
+ const landingRoutes = (
98
+ <Routes>
99
+ <Route path="/" element={<RootLanding />} />
100
+ <Route path={WELCOME_PATH} element={<div>welcome page</div>} />
101
+ <Route path="/workspace" element={<div>knowledge</div>} />
102
+ </Routes>
103
+ );
104
+
105
+ beforeEach(() => {
106
+ resetOnboardingForTests();
107
+ authFetchMock.mockClear();
108
+ sessionStorage.clear();
109
+ });
110
+
111
+ /**
112
+ * jsdom ships no `navigator.clipboard`, so a copy test has to install one —
113
+ * but only THAT property, never a replacement `navigator`: the rest of the
114
+ * object (`userAgent`, `language`, whatever a library reaches for next) has no
115
+ * business changing because one test wanted a spy.
116
+ */
117
+ let restoreClipboard: (() => void) | null = null;
118
+
119
+ function stubClipboard() {
120
+ const writeText = vi.fn().mockResolvedValue(undefined);
121
+ const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
122
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
123
+ restoreClipboard = () => {
124
+ if (original) Object.defineProperty(navigator, 'clipboard', original);
125
+ else Reflect.deleteProperty(navigator, 'clipboard');
126
+ };
127
+ return writeText;
128
+ }
129
+
130
+ // In a hook, not at the end of a test body: a failing assertion would otherwise
131
+ // leave the stub installed for every test after it.
132
+ afterEach(() => {
133
+ restoreClipboard?.();
134
+ restoreClipboard = null;
135
+ vi.unstubAllGlobals();
136
+ });
137
+
138
+ describe('RootLanding: the one-time greeting', () => {
139
+ it('sends a brand-new account to the welcome page', () => {
140
+ mount(landingRoutes);
141
+ expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
142
+ });
143
+
144
+ // The flag the page reads to know this arrival is a ceremony rather than a
145
+ // visit — the sidebar collapse hangs off it, and only this navigation sets it.
146
+ it('marks the automatic redirect as a greeting', () => {
147
+ mount(landingRoutes);
148
+ expect(screen.getByTestId('greeting')).toHaveTextContent('true');
149
+ });
150
+
151
+ it('sends everyone the server marked done straight to Knowledge', () => {
152
+ mount(landingRoutes, doneUser());
153
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
154
+ });
155
+
156
+ // Optional-field semantics: an ABSENT flag (old fixture, cached session)
157
+ // must never resurrect the welcome flow. Only an explicit false onboards.
158
+ it('treats a missing flag as done, not as new', () => {
159
+ mount(landingRoutes, authValue());
160
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
161
+ });
162
+
163
+ /**
164
+ * The SSO round-trip returns to a fixed callback URL, so a deep link
165
+ * someone clicked dies in transit unless `startSsoLogin` stashed it. These
166
+ * prove the far side: the stash is honoured, exactly once, and can never
167
+ * point off-site.
168
+ */
169
+ it('sends an existing account straight to the stashed deep link, once', () => {
170
+ const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
171
+ sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
172
+ mount(landingRoutes, doneUser());
173
+ expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
174
+ // Taken, not peeked: the next front-door visit is an ordinary one.
175
+ expect(sessionStorage.getItem(POST_LOGIN_REDIRECT_KEY)).toBeNull();
176
+ });
177
+
178
+ it('greets a brand-new account first, handing the link to the welcome page', () => {
179
+ const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
180
+ sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
181
+ mount(landingRoutes);
182
+ expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
183
+ expect(screen.getByTestId('greeting')).toHaveTextContent('true');
184
+ expect(screen.getByTestId('returnTo')).toHaveTextContent(DEEP);
185
+ });
186
+
187
+ it('discards a stash that is not an in-app path — never an off-site redirect', () => {
188
+ sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, '//evil.example/phish');
189
+ mount(landingRoutes, doneUser());
190
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
191
+ });
192
+
193
+ it('greets ONCE: after the welcome page has been seen, / goes to Knowledge', async () => {
194
+ mount(
195
+ <Routes>
196
+ <Route path="/" element={<RootLanding />} />
197
+ <Route path={WELCOME_PATH} element={<WelcomePage />} />
198
+ <Route path="/workspace" element={<div>knowledge</div>} />
199
+ </Routes>,
200
+ );
201
+ // Landed on the real page, which marks `welcomed` on mount.
202
+ await screen.findByRole('heading', { name: /Welcome, Juan/ });
203
+ cleanup();
204
+ // A fresh visit to `/` — same account, same browser.
205
+ mount(landingRoutes);
206
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
207
+ });
208
+ });
209
+
210
+ describe('WelcomePage', () => {
211
+ // Default: the ordinary visit, from the sidebar pill. The greeting — the
212
+ // one-time redirect — is the special case, and says so at each call site.
213
+ const mountPage = (auth = newUser(), route: string | typeof greeted = WELCOME_PATH) =>
214
+ mount(
215
+ <Routes>
216
+ <Route path={WELCOME_PATH} element={<WelcomePage />} />
217
+ <Route path="/skills-and-tools" element={<div>library</div>} />
218
+ <Route path="/skills-and-tools/yours" element={<div>your plugin</div>} />
219
+ </Routes>,
220
+ auth,
221
+ route,
222
+ );
223
+
224
+ it('addresses the person by first name', () => {
225
+ mountPage();
226
+ expect(screen.getByRole('heading', { name: 'Welcome, Juan' })).toBeInTheDocument();
227
+ });
228
+
229
+ /**
230
+ * The entrance must BEGIN on a painted frame. A CSS animation runs on the
231
+ * document timeline whether or not the browser is producing frames, so an
232
+ * animation attached at mount can elapse entirely during a cold boot and
233
+ * never be seen — the bug that made this page "just appear" at every
234
+ * duration we tried. Held invisible first, animating second.
235
+ */
236
+ it('starts its entrance on a painted frame, not at mount', async () => {
237
+ mountPage(newUser(), greeted);
238
+ const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
239
+ const body = screen.getByText(/company’s shared library/).parentElement!;
240
+ // An inline style, deliberately — a utility class would depend on Tailwind
241
+ // having compiled it, and that is exactly what failed silently before.
242
+ expect(title.style.opacity).toBe('0');
243
+ expect(body.style.opacity).toBe('0');
244
+ await waitFor(() => {
245
+ expect(title.className).toContain('animate-onboarding-greeting');
246
+ expect(body.className).toContain('animate-onboarding-body');
247
+ });
248
+ // …and never both at once: held invisible and animating would fight.
249
+ expect(title.style.opacity).toBe('');
250
+ expect(body.style.opacity).toBe('');
251
+ });
252
+
253
+ /**
254
+ * Being welcomed happens once. Opening the same page from the pill later is
255
+ * a visit, and a 2.6s arrival every time you come back to copy your MCP
256
+ * snippet is a page you learn to dread — so there is no hold and no fade,
257
+ * only the page.
258
+ */
259
+ it('does not replay the entrance when you open it from the pill', () => {
260
+ mountPage();
261
+ const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
262
+ expect(title.style.opacity).toBe('');
263
+ expect(title.className).not.toContain('animate-onboarding-greeting');
264
+ });
265
+
266
+ // However the sign-in record spells it. The page addressed to one person is
267
+ // the last place that should get their name wrong.
268
+ it('capitalizes the name whatever the account holds', () => {
269
+ mountPage(authValue({ user: { id: 'u1', email: 'j@bevel.software', name: 'juan viera', onboardingDone: false } }));
270
+ expect(screen.getByRole('heading', { name: 'Welcome, Juan' })).toBeInTheDocument();
271
+ });
272
+
273
+ it('greets someone with no name at all', () => {
274
+ mountPage(authValue({ user: { id: 'u1', email: 'j@bevel.software', name: '', onboardingDone: false } }));
275
+ expect(screen.getByRole('heading', { name: 'Welcome, there' })).toBeInTheDocument();
276
+ });
277
+
278
+ /**
279
+ * The nav gets out of the way for the greeting and STAYS out — there is no
280
+ * restore. Putting it back meant leaving a screen with no nav and arriving
281
+ * at one where the nav had opened itself, which is the app rearranging a
282
+ * page you asked for. Whether the sidebar shows is the toolbar toggle's to
283
+ * say, and after the greeting it says whatever it said last.
284
+ */
285
+ it('collapses the sidebar for the greeting, without animating it', () => {
286
+ setSidebarCollapsed(false);
287
+ mountPage(newUser(), greeted);
288
+ expect(sidebarState()).toMatchObject({ collapsed: true, instant: true });
289
+ });
290
+
291
+ it('leaves it collapsed when you go to your own plugin', async () => {
292
+ setSidebarCollapsed(false);
293
+ mountPage(newUser(), greeted);
294
+ await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
295
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
296
+ expect(sidebarState().collapsed).toBe(true);
297
+ });
298
+
299
+ it('leaves it collapsed after Done too', async () => {
300
+ setSidebarCollapsed(false);
301
+ mountPage(newUser(), greeted);
302
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
303
+ expect(sidebarState().collapsed).toBe(true);
304
+ });
305
+
306
+ /**
307
+ * The one case where the nav is showing on the way out: you opened it
308
+ * yourself while you were here. The page collapses once, on arrival, and
309
+ * never touches the store again — so your gesture is the last word.
310
+ */
311
+ it('respects a sidebar you opened yourself while reading the page', async () => {
312
+ setSidebarCollapsed(false);
313
+ mountPage(newUser(), greeted);
314
+ expect(sidebarState().collapsed).toBe(true);
315
+ setSidebarCollapsed(false); // …the toolbar toggle, from the user's hand
316
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
317
+ expect(sidebarState().collapsed).toBe(false);
318
+ });
319
+
320
+ it('leaves it collapsed for someone who arrived that way', () => {
321
+ setSidebarCollapsed(true);
322
+ const { unmount } = mountPage(newUser(), greeted);
323
+ expect(sidebarState().collapsed).toBe(true);
324
+ unmount();
325
+ expect(sidebarState().collapsed).toBe(true);
326
+ });
327
+
328
+ // Reached from the pill it is a page, not a ceremony: the nav it was just
329
+ // clicked in stays exactly where it is.
330
+ it('leaves the sidebar alone when you open it from the pill', () => {
331
+ setSidebarCollapsed(false);
332
+ const { unmount } = mountPage();
333
+ expect(sidebarState().collapsed).toBe(false);
334
+ unmount();
335
+ expect(sidebarState().collapsed).toBe(false);
336
+ });
337
+
338
+ it('shows one snippet at a time, following the picker', async () => {
339
+ mountPage();
340
+ // Claude default: the bare hosted URL, not a config.
341
+ expect(screen.getByText(/\/api\/mcp$/)).toBeInTheDocument();
342
+ expect(screen.queryByText(/mcpServers/)).toBeNull();
343
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
344
+ expect(screen.getByText(/@bevel-software\/hexis-mcp/)).toBeInTheDocument();
345
+ await userEvent.click(screen.getByRole('radio', { name: 'Other tools' }));
346
+ expect(screen.getByText(/skills-tools-knowledge/)).toBeInTheDocument();
347
+ });
348
+
349
+ /**
350
+ * ChatGPT renamed Apps & Connectors to Plugins, and a one-line path with the
351
+ * old names stranded people. The steps are numbered, in the order the
352
+ * settings are actually walked, and each renamed thing is named both ways
353
+ * so either build of ChatGPT reads right.
354
+ */
355
+ it('walks ChatGPT as numbered steps naming both the current and the previous page', async () => {
356
+ mountPage();
357
+ await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
358
+ const steps = screen.getAllByRole('listitem').map((li) => li.textContent);
359
+ expect(steps).toEqual([
360
+ 'Open Settings in ChatGPT.',
361
+ 'Open Plugins (called Apps & Connectors in older versions).',
362
+ 'Turn on Developer Mode (under Advanced in older versions).',
363
+ 'Go back and choose Create (or Add).',
364
+ 'Name it “Skills, Tools and Knowledge”.',
365
+ 'Paste the address below, then save.',
366
+ ]);
367
+ // An ordered list, so the numbers are real rather than typed into the text.
368
+ expect(screen.getByRole('list').tagName).toBe('OL');
369
+ // The other options keep their one-paragraph hint.
370
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
371
+ expect(screen.queryByRole('list')).toBeNull();
372
+ });
373
+
374
+ /**
375
+ * "A JSON config" told a business user nothing. The Other tools option
376
+ * says where it goes, and gives the bare address too — many tools take a
377
+ * URL and nothing else — each with its own copy button.
378
+ */
379
+ it('tells Other tools where the configuration goes, and offers the bare address too', async () => {
380
+ configureMcpUrl('https://kb.acme.com/api/mcp');
381
+ const writeText = stubClipboard();
382
+ mountPage();
383
+ await userEvent.click(screen.getByRole('radio', { name: 'Other tools' }));
384
+ expect(
385
+ screen.getByText(
386
+ 'For any other AI tool that supports MCP servers. Open the tool’s settings, find MCP servers (also called connectors or integrations), choose add, and paste this configuration. If the tool asks for an address only, paste this instead:',
387
+ ),
388
+ ).toBeInTheDocument();
389
+
390
+ const address = screen.getByText('https://kb.acme.com/api/mcp');
391
+ const config = screen.getByText(/mcpServers/);
392
+ // The address first — the hint ends on "paste this instead:" — then the JSON.
393
+ expect(address.compareDocumentPosition(config) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
394
+ expect(config.textContent).toContain('https://kb.acme.com/api/mcp');
395
+
396
+ await userEvent.click(screen.getByRole('button', { name: 'Copy address' }));
397
+ expect(writeText).toHaveBeenLastCalledWith('https://kb.acme.com/api/mcp');
398
+ await userEvent.click(screen.getByRole('button', { name: 'Copy' }));
399
+ expect(writeText).toHaveBeenLastCalledWith(config.textContent);
400
+ });
401
+
402
+ it('shows the separate address block on Other tools alone', async () => {
403
+ mountPage();
404
+ expect(screen.queryByRole('button', { name: 'Copy address' })).toBeNull();
405
+ await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
406
+ expect(screen.queryByRole('button', { name: 'Copy address' })).toBeNull();
407
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
408
+ expect(screen.queryByRole('button', { name: 'Copy address' })).toBeNull();
409
+ });
410
+
411
+ /**
412
+ * The default: Claude, which is what most people arriving here already use
413
+ * and the one connection that is a single click. The button and the hosted
414
+ * address are both on screen before anything is clicked.
415
+ */
416
+ it('defaults to Claude: its install button and the hosted address, without a click', () => {
417
+ configureMcpUrl('https://kb.acme.com/api/mcp');
418
+ mountPage();
419
+ expect(screen.getByRole('radio', { name: 'Claude' })).toHaveAttribute('aria-checked', 'true');
420
+ expect(screen.getByRole('link', { name: 'Add to Claude' })).toBeInTheDocument();
421
+ expect(screen.getByText('https://kb.acme.com/api/mcp')).toBeInTheDocument();
422
+ });
423
+
424
+ /**
425
+ * Desktop agents is no longer the default, but its snippet is still the
426
+ * keyless local-server config: the local server opens the browser to sign
427
+ * in on first run, so the config carries no key at all.
428
+ */
429
+ it('offers Desktop agents the keyless hexis-mcp config', async () => {
430
+ mountPage();
431
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
432
+ const snippet = screen.getByText(/mcpServers/).textContent!;
433
+ expect(snippet).toContain('@bevel-software/hexis-mcp');
434
+ // Keyless = interactive sign-in: no key env at all, not a placeholder —
435
+ // the server opens the browser on first run.
436
+ expect(snippet).not.toContain('HEXIS_CONNECTION_KEY');
437
+ // The hint says how identity arrives instead: browser sign-in on first run.
438
+ expect(screen.getByText(/your browser opens so you can sign in/)).toBeInTheDocument();
439
+ });
440
+
441
+ /**
442
+ * The two ways this snippet fails on a machine where it is otherwise
443
+ * right: the wrong Node major, and a client launched from the Dock, which
444
+ * was started by the window server and so never read the shell profile
445
+ * that put `npx` on PATH (Cursor and Claude Desktop on macOS). The fix for
446
+ * the second is an absolute path, which is specific to one machine — so it
447
+ * belongs in the hint and NOT in the snippet, which has to stay right for
448
+ * every reader whose PATH was fine all along.
449
+ */
450
+ it('warns Desktop agents about Node and PATH, leaving the snippet on bare npx', async () => {
451
+ mountPage();
452
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
453
+ expect(screen.getByText(/Needs Node 22\.13\+ or 24/)).toBeInTheDocument();
454
+ expect(screen.getByText(/cannot see your shell’s PATH/)).toBeInTheDocument();
455
+ expect(screen.getByText(/run `which npx` in a terminal/)).toBeInTheDocument();
456
+ const snippet = screen.getByText(/mcpServers/).textContent!;
457
+ expect(JSON.parse(snippet).mcpServers['skills-tools-knowledge'].command).toBe('npx');
458
+ });
459
+
460
+ /**
461
+ * One click instead of a menu path. It is Claude-only because Claude is the
462
+ * only client with a documented install link, and it appears only when
463
+ * Anthropic could actually reach this deployment — see `canDeepLink`. The
464
+ * copy block stays either way; it is the route that always works.
465
+ *
466
+ * Every case still selects the Claude option explicitly, although it is
467
+ * the default: the link belongs to that option, and the cases say so.
468
+ */
469
+ describe('the Add to Claude link', () => {
470
+ it('offers one-click connect on a reachable deployment', async () => {
471
+ configureMcpUrl('https://kb.acme.com/api/mcp');
472
+ mountPage();
473
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
474
+ const link = screen.getByRole('link', { name: 'Add to Claude' });
475
+ const href = new URL(link.getAttribute('href')!);
476
+ expect(href.origin + href.pathname).toBe('https://claude.ai/customize/connectors');
477
+ expect(href.searchParams.get('connectorUrl')).toBe('https://kb.acme.com/api/mcp');
478
+ expect(href.searchParams.get('connectorName')).toBe('Skills, Tools and Knowledge — kb.acme.com');
479
+ });
480
+
481
+ /**
482
+ * The default install: `PUBLIC_BACKEND_URL` unset means localhost, which
483
+ * claude.ai cannot reach. A dead button on the first screen a self-hoster
484
+ * sees reads as a broken product.
485
+ */
486
+ it('offers nothing to click on a localhost deployment', async () => {
487
+ configureMcpUrl('http://localhost:3001/api/mcp');
488
+ mountPage();
489
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
490
+ expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
491
+ // …and the route that always works is still there.
492
+ expect(screen.getByText('http://localhost:3001/api/mcp')).toBeInTheDocument();
493
+ });
494
+
495
+ /**
496
+ * No `PUBLIC_BACKEND_URL` hint on THIS surface. The reader is a new
497
+ * employee who cannot change deployment config; naming an env var at them
498
+ * is noise. The settings page, whose reader plausibly can, says it there.
499
+ */
500
+ it('does not lecture a new employee about deployment config', async () => {
501
+ configureMcpUrl('http://localhost:3001/api/mcp');
502
+ mountPage();
503
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
504
+ expect(screen.queryByText(/PUBLIC_BACKEND_URL/)).toBeNull();
505
+ });
506
+
507
+ it('belongs to Claude alone', async () => {
508
+ configureMcpUrl('https://kb.acme.com/api/mcp');
509
+ mountPage();
510
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
511
+ expect(screen.getByRole('link', { name: 'Add to Claude' })).toBeInTheDocument();
512
+ await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
513
+ expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
514
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
515
+ expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
516
+ await userEvent.click(screen.getByRole('radio', { name: 'Other tools' }));
517
+ expect(screen.queryByRole('link', { name: 'Add to Claude' })).toBeNull();
518
+ });
519
+
520
+ /**
521
+ * ChatGPT gets its own button, on its own option only. It cannot prefill
522
+ * anything — ChatGPT has no such link — so it opens the settings pane and
523
+ * the hint beside it spells out the name to type, which is what stops a
524
+ * dozen employees each inventing their own.
525
+ */
526
+ it('offers Add to ChatGPT on the ChatGPT option alone, with the name to type', async () => {
527
+ configureMcpUrl('https://kb.acme.com/api/mcp');
528
+ mountPage();
529
+ // The default — Claude — carries no ChatGPT button.
530
+ expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
531
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
532
+ expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
533
+ await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
534
+ const link = screen.getByRole('link', { name: 'Add to ChatGPT' });
535
+ expect(link).toHaveAttribute('href', 'https://chatgpt.com/#settings');
536
+ expect(link).toHaveAttribute('target', '_blank');
537
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
538
+ expect(screen.getByText(/Skills, Tools and Knowledge/)).toBeInTheDocument();
539
+ // …and the URL to paste is still the copy block.
540
+ expect(screen.getByText('https://kb.acme.com/api/mcp')).toBeInTheDocument();
541
+ });
542
+
543
+ it('offers no ChatGPT button on a localhost deployment either', async () => {
544
+ configureMcpUrl('http://localhost:3001/api/mcp');
545
+ mountPage();
546
+ await userEvent.click(screen.getByRole('radio', { name: 'ChatGPT' }));
547
+ expect(screen.queryByRole('link', { name: 'Add to ChatGPT' })).toBeNull();
548
+ expect(screen.getByText('http://localhost:3001/api/mcp')).toBeInTheDocument();
549
+ });
550
+
551
+ // Opening claude.ai must not hand it a handle on this window.
552
+ it('opens in a new tab safely', async () => {
553
+ configureMcpUrl('https://kb.acme.com/api/mcp');
554
+ mountPage();
555
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
556
+ const link = screen.getByRole('link', { name: 'Add to Claude' });
557
+ expect(link).toHaveAttribute('target', '_blank');
558
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
559
+ });
560
+
561
+ /**
562
+ * The whole point of the canonical URL: what the button hands Claude and
563
+ * what the copy block shows a human must be the same string, or one of
564
+ * them is lying.
565
+ */
566
+ it('hands Claude exactly the URL the copy block shows', async () => {
567
+ configureMcpUrl('https://kb.acme.com/api/mcp');
568
+ mountPage();
569
+ await userEvent.click(screen.getByRole('radio', { name: 'Claude' }));
570
+ const href = new URL(
571
+ screen.getByRole('link', { name: 'Add to Claude' }).getAttribute('href')!,
572
+ );
573
+ expect(href.searchParams.get('connectorUrl')).toBe(
574
+ screen.getByText(/\/api\/mcp$/).textContent,
575
+ );
576
+ });
577
+ });
578
+
579
+ it('copies the visible snippet without concluding anything', async () => {
580
+ const writeText = stubClipboard();
581
+ mountPage();
582
+ await userEvent.click(screen.getByRole('button', { name: 'Copy' }));
583
+ // The default snippet is Claude's: the hosted URL itself.
584
+ expect(writeText).toHaveBeenCalledWith(expect.stringMatching(/\/api\/mcp$/));
585
+ // Copying is not Done: no server write, no navigation.
586
+ expect(authFetchMock).not.toHaveBeenCalled();
587
+ expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
588
+ });
589
+
590
+ // Exact, not a substring: `/skills-and-tools` is a PREFIX of the personal
591
+ // plugin's path, so a loose match would pass even if Done dropped someone in
592
+ // the whole company's catalog instead of their own shelf.
593
+ it('Done concludes: server write + landing in your own plugin', async () => {
594
+ mountPage();
595
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
596
+ expect(authFetchMock).toHaveBeenCalledWith(
597
+ '/api/auth/onboarding-done',
598
+ expect.objectContaining({ method: 'POST' }),
599
+ );
600
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/skills-and-tools\/yours$/);
601
+ });
602
+
603
+ // Both exits, one destination — stated as its own fact so a future change to
604
+ // either button has to face the question deliberately.
605
+ it('sends you to the same place whether you finish or skip', async () => {
606
+ mountPage();
607
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
608
+ const afterDone = screen.getByTestId('pathname').textContent;
609
+ cleanup();
610
+ mountPage();
611
+ await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
612
+ expect(screen.getByTestId('pathname')).toHaveTextContent(afterDone!);
613
+ });
614
+
615
+ // Exclusive-choice semantics: `radio` says one of these is always chosen
616
+ // and the others are not. Three `aria-pressed` toggles said any combination,
617
+ // including none, was possible.
618
+ it('presents the client picker as an exclusive choice', async () => {
619
+ mountPage();
620
+ const group = screen.getByRole('radiogroup', { name: 'Your agent' });
621
+ const options = screen.getAllByRole('radio');
622
+ expect(group).toContainElement(options[0]!);
623
+ // Claude and ChatGPT lead; Claude is the default.
624
+ expect(options.map((o) => o.textContent)).toEqual(['Claude', 'ChatGPT', 'Desktop agents', 'Other tools']);
625
+ expect(options.map((o) => o.getAttribute('aria-checked'))).toEqual([
626
+ 'true',
627
+ 'false',
628
+ 'false',
629
+ 'false',
630
+ ]);
631
+ await userEvent.click(screen.getByRole('radio', { name: 'Desktop agents' }));
632
+ expect(screen.getAllByRole('radio').map((o) => o.getAttribute('aria-checked'))).toEqual([
633
+ 'false',
634
+ 'false',
635
+ 'true',
636
+ 'false',
637
+ ]);
638
+ });
639
+
640
+ /**
641
+ * `role="radiogroup"` is a promise about the keyboard, not just a label for
642
+ * a screen reader: arrows select, and selection follows focus. The plugin
643
+ * wraps, because four options in a row have no edge worth stopping at.
644
+ */
645
+ it('drives the picker with the arrow keys, wrapping at both ends', async () => {
646
+ mountPage();
647
+ const checked = () =>
648
+ screen.getAllByRole('radio').find((o) => o.getAttribute('aria-checked') === 'true');
649
+
650
+ screen.getByRole('radio', { name: 'Claude' }).focus();
651
+ await userEvent.keyboard('{ArrowRight}');
652
+ expect(checked()).toHaveAccessibleName('ChatGPT');
653
+ expect(checked()).toHaveFocus();
654
+ await userEvent.keyboard('{ArrowDown}');
655
+ expect(checked()).toHaveAccessibleName('Desktop agents');
656
+ await userEvent.keyboard('{ArrowRight}');
657
+ expect(checked()).toHaveAccessibleName('Other tools');
658
+
659
+ // Off the end and round to the first.
660
+ await userEvent.keyboard('{ArrowRight}');
661
+ expect(checked()).toHaveAccessibleName('Claude');
662
+
663
+ // And backwards past the start, to the last.
664
+ await userEvent.keyboard('{ArrowLeft}');
665
+ expect(checked()).toHaveAccessibleName('Other tools');
666
+ });
667
+
668
+ // Roving tabindex: the picker is ONE tab stop, not one per client.
669
+ it('offers a single tab stop for the whole picker', () => {
670
+ mountPage();
671
+ expect(screen.getAllByRole('radio').map((o) => o.getAttribute('tabindex'))).toEqual([
672
+ '0',
673
+ '-1',
674
+ '-1',
675
+ '-1',
676
+ ]);
677
+ });
678
+
679
+ // Into the person's OWN plugin, not the whole catalog — the same place the
680
+ // sidebar's personal row goes.
681
+ it('the skip link leaves for your own plugin, without concluding', async () => {
682
+ mountPage();
683
+ await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
684
+ expect(authFetchMock).not.toHaveBeenCalled();
685
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
686
+ });
687
+
688
+ /**
689
+ * A deep link that survived the SSO round-trip retargets BOTH exits: the
690
+ * greeting concluded by discarding the page someone was sent would cost
691
+ * them the reason they came. The skip label says where it now goes.
692
+ */
693
+ it('keeps a carried deep link: Done lands on it, and the skip link says so', async () => {
694
+ const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
695
+ const arrivedWithLink = { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } };
696
+ mountPage(newUser(), arrivedWithLink);
697
+ expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
698
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
699
+ expect(authFetchMock).toHaveBeenCalledWith(
700
+ '/api/auth/onboarding-done',
701
+ expect.objectContaining({ method: 'POST' }),
702
+ );
703
+ expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
704
+ });
705
+
706
+ /**
707
+ * `AppRegistry.welcomeExit` moves where a new person starts. WHERE that is,
708
+ * is a property of the product: core sends them to their own skills shelf,
709
+ * because on a core deployment that is the product and a fresh knowledge
710
+ * base is empty. A distribution built around the knowledge graph wants the
711
+ * opposite and would otherwise greet someone and then leave them in a
712
+ * surface they did not come for.
713
+ *
714
+ * The tests above deliberately mount WITHOUT a registry, so they pin the
715
+ * default: the seam must be invisible to a deployment that does not use it.
716
+ */
717
+ describe('welcomeExit', () => {
718
+ const mountWithExit = (
719
+ welcomeExit: { path: string; label: string } | undefined,
720
+ // Same shape `mount` accepts — `typeof greeted` would pin `state` to
721
+ // `{ greeting: boolean }` and reject the deep-link case below.
722
+ route: string | { pathname: string; state?: unknown } = greeted,
723
+ ) =>
724
+ mount(
725
+ <AppRegistryContext.Provider value={{ ...EMPTY_REGISTRY, welcomeExit }}>
726
+ <Routes>
727
+ <Route path={WELCOME_PATH} element={<WelcomePage />} />
728
+ <Route path="/skills-and-tools/yours" element={<div>your plugin</div>} />
729
+ <Route path="/workspace" element={<div>knowledge</div>} />
730
+ </Routes>
731
+ </AppRegistryContext.Provider>,
732
+ newUser(),
733
+ route,
734
+ );
735
+
736
+ it('sends both exits to the configured destination', async () => {
737
+ mountWithExit({ path: '/workspace', label: 'Go to your knowledge base' });
738
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
739
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
740
+ });
741
+
742
+ /**
743
+ * The label travels WITH the path. "Go to your skills →" pointing at a
744
+ * knowledge base is a lie, and letting a caller set one without the other
745
+ * is the likeliest way to produce it.
746
+ */
747
+ it('labels the skip link with the configured destination', () => {
748
+ mountWithExit({ path: '/workspace', label: 'Go to your knowledge base' });
749
+ expect(
750
+ screen.getByRole('button', { name: /Go to your knowledge base/ }),
751
+ ).toBeInTheDocument();
752
+ expect(screen.queryByRole('button', { name: /Go to your skills/ })).not.toBeInTheDocument();
753
+ });
754
+
755
+ it('falls back to the skills shelf when a registry sets nothing', async () => {
756
+ mountWithExit(undefined);
757
+ expect(screen.getByRole('button', { name: /Go to your skills/ })).toBeInTheDocument();
758
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
759
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
760
+ });
761
+
762
+ /**
763
+ * A deep link still outranks it. Someone who followed a link is owed that
764
+ * link, and no amount of deployment configuration may eat an intention.
765
+ */
766
+ it('does not override a carried deep link', async () => {
767
+ const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
768
+ mountWithExit(
769
+ { path: '/skills-and-tools/yours', label: 'Go to your skills' },
770
+ { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } },
771
+ );
772
+ expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
773
+ await userEvent.click(screen.getByRole('button', { name: 'Done' }));
774
+ expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
775
+ });
776
+ });
777
+ });
778
+
779
+ describe('ConnectAgentPill', () => {
780
+ const mountPill = (auth = newUser(), route = '/skills-and-tools') =>
781
+ mount(
782
+ <Routes>
783
+ <Route path="*" element={<ConnectAgentPill />} />
784
+ </Routes>,
785
+ auth,
786
+ route,
787
+ );
788
+
789
+ it('shows for a not-onboarded account and leads to the welcome page', async () => {
790
+ mountPill();
791
+ await userEvent.click(screen.getByRole('button', { name: 'Connect your agent' }));
792
+ expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
793
+ // …as a plain visit. The pill opens the page; it does not re-run the
794
+ // first-sign-in ceremony that folds the nav it lives in away.
795
+ expect(screen.getByTestId('greeting')).toHaveTextContent('false');
796
+ });
797
+
798
+ it('renders nothing once the server says done', () => {
799
+ mountPill(doneUser());
800
+ expect(screen.queryByRole('button', { name: 'Connect your agent' })).toBeNull();
801
+ });
802
+
803
+ // `page`, not `true` — the pill navigates, so the value that means "this is
804
+ // the page you are on" is the one a screen reader announces as such.
805
+ it('wears the selected state on the welcome page itself', () => {
806
+ mountPill(newUser(), WELCOME_PATH);
807
+ expect(screen.getByRole('button', { name: 'Connect your agent' })).toHaveAttribute(
808
+ 'aria-current',
809
+ 'page',
810
+ );
811
+ });
812
+
813
+ it('claims no current page anywhere else', () => {
814
+ mountPill();
815
+ expect(screen.getByRole('button', { name: 'Connect your agent' })).not.toHaveAttribute(
816
+ 'aria-current',
817
+ );
818
+ });
819
+
820
+ it('the × concludes: same field as Done. And the pill goes', async () => {
821
+ mountPill();
822
+ await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
823
+ expect(authFetchMock).toHaveBeenCalledWith(
824
+ '/api/auth/onboarding-done',
825
+ expect.objectContaining({ method: 'POST' }),
826
+ );
827
+ expect(screen.queryByRole('button', { name: 'Connect your agent' })).toBeNull();
828
+ });
829
+
830
+ // The stale-tab guard's client half: the request states which account it
831
+ // means, so the server can refuse to conclude somebody else's onboarding.
832
+ it('states which account it is concluding', async () => {
833
+ mountPill();
834
+ await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
835
+ expect(JSON.parse(String(fetchInit()?.body))).toEqual({ userId: 'u1' });
836
+ });
837
+
838
+ /**
839
+ * A write that never landed must not leave the UI claiming it did. The pill
840
+ * comes back immediately, rather than mysteriously reappearing at the next
841
+ * sign-in with no account of why it left.
842
+ */
843
+ it('brings the pill back when the server refuses the write', async () => {
844
+ authFetchMock.mockResolvedValueOnce({ ok: false, status: 409 } as Response);
845
+ const errors = vi.spyOn(console, 'error').mockImplementation(() => {});
846
+ mountPill();
847
+ await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
848
+ expect(
849
+ await screen.findByRole('button', { name: 'Connect your agent' }),
850
+ ).toBeInTheDocument();
851
+ errors.mockRestore();
852
+ });
853
+ });