@bevel-software/platform-core-frontend 0.15.1 → 0.20.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 (347) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +20 -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__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  33. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  34. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  35. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  36. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  37. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  38. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  39. package/src/modules/admin/components/group-members-path.ts +32 -0
  40. package/src/modules/admin/services/roles.api.ts +12 -1
  41. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  42. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  43. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  44. package/src/modules/audit/components/principal-grouping.ts +49 -0
  45. package/src/modules/audit/services/audit.api.ts +98 -0
  46. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  47. package/src/modules/auth/components/AccountPage.tsx +73 -54
  48. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  49. package/src/modules/auth/services/account.api.ts +78 -4
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  58. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  59. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  60. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  61. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  62. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  63. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  64. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  65. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  66. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  67. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  68. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  69. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  70. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  71. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  72. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  73. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  74. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  75. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  76. package/src/modules/change-requests/services/propose.api.ts +97 -8
  77. package/src/modules/change-requests/utils/approval.ts +15 -0
  78. package/src/modules/change-requests/utils/author.ts +32 -0
  79. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  80. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  81. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  82. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  83. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  84. package/src/modules/git/services/error-messages.ts +12 -0
  85. package/src/modules/git/services/pr-prompts.ts +5 -5
  86. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  87. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  88. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  89. package/src/modules/layout/components/AppLayout.tsx +2 -0
  90. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  91. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  92. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  93. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  94. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  95. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  96. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  97. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  98. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  99. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  100. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  101. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  102. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  103. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  104. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  105. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  106. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  107. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  108. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  109. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  110. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  111. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  112. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  113. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  114. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  115. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  116. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  117. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  118. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  119. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  120. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  121. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  122. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  123. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  124. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  125. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  126. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  127. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  128. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  129. package/src/modules/library/__tests__/status.test.ts +82 -2
  130. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  131. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  132. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  133. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  134. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  135. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  136. package/src/modules/library/components/LibraryCard.tsx +146 -45
  137. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  138. package/src/modules/library/components/LibraryPage.tsx +172 -39
  139. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  140. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  141. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  142. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  143. package/src/modules/library/components/PageActions.tsx +11 -9
  144. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  145. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  146. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  147. package/src/modules/library/components/PluginExtras.tsx +140 -17
  148. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  149. package/src/modules/library/components/PluginPage.tsx +157 -41
  150. package/src/modules/library/components/PluginRows.tsx +286 -0
  151. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  152. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  153. package/src/modules/library/components/ShareButton.tsx +17 -0
  154. package/src/modules/library/components/SkillsTree.tsx +141 -28
  155. package/src/modules/library/components/TeamRoute.tsx +15 -0
  156. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  157. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  158. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  159. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  160. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  161. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  162. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  163. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  164. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  165. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  166. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  167. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  168. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  169. package/src/modules/library/routes/library-paths.ts +26 -28
  170. package/src/modules/library/services/library.api.ts +38 -20
  171. package/src/modules/library/services/plugins.api.ts +69 -8
  172. package/src/modules/library/services/teams.api.ts +15 -0
  173. package/src/modules/library/services/tools.api.ts +78 -0
  174. package/src/modules/library/state/library-data.tsx +170 -32
  175. package/src/modules/library/utils/personal-plugin.ts +13 -15
  176. package/src/modules/library/utils/plugin-entries.ts +134 -0
  177. package/src/modules/library/utils/plugin-summary.ts +75 -9
  178. package/src/modules/library/utils/status.ts +135 -33
  179. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  180. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  181. package/src/modules/onboarding/agent-clients.ts +55 -23
  182. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  183. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  184. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  185. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  186. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  187. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  188. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  189. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  190. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  191. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  192. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  193. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  194. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  195. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  196. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  197. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  198. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  199. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  200. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  201. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  202. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  203. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  204. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  205. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  206. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  207. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  208. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +7 -6
  209. package/src/modules/settings/services/github-facade.api.ts +23 -0
  210. package/src/modules/settings/settings-nav-items.tsx +13 -3
  211. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  212. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  213. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  214. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  215. package/src/modules/setup/components/SetupGate.tsx +16 -16
  216. package/src/modules/setup/components/SetupScreen.tsx +532 -43
  217. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  218. package/src/modules/setup/services/setup.api.ts +141 -4
  219. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  220. package/src/modules/setup/utils/root-folders.ts +46 -0
  221. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  232. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  233. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  234. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  235. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  236. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  237. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  238. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  239. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  240. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  241. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  242. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  243. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  244. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  245. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  246. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  247. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  248. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  249. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  250. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  251. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  252. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  254. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  255. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  256. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  257. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  258. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  259. package/src/modules/workspace/components/FileViewer.tsx +172 -46
  260. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  261. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  262. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  263. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2533 -129
  264. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  265. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +381 -12
  266. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  267. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  268. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  269. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  270. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  271. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  272. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  273. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  274. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  275. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  276. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  277. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  279. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  280. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  281. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  282. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  283. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  284. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  285. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  286. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  287. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  288. package/src/modules/workspace/components/renderers/index.ts +53 -2
  289. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  290. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  291. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  292. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  294. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  295. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  296. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  297. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  298. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  299. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  300. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  301. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +134 -1
  302. package/src/modules/workspace/services/workspace.api.ts +57 -4
  303. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  304. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  305. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  306. package/src/modules/workspace/state/workspace.context.ts +125 -19
  307. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  308. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  309. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  310. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  311. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  312. package/src/modules/workspace/utils/file-trace.ts +50 -0
  313. package/src/modules/workspace/utils/fileTree.ts +112 -36
  314. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  315. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  316. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  317. package/src/modules/workspace/utils/uploadError.ts +29 -0
  318. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  319. package/src/shared/components/Button.tsx +16 -2
  320. package/src/shared/components/Dialog.tsx +27 -11
  321. package/src/shared/components/Menu.tsx +13 -1
  322. package/src/shared/components/PageShell.tsx +13 -8
  323. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  324. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  325. package/src/shared/components/index.ts +2 -0
  326. package/src/shared/components/useDismissableMenu.ts +32 -10
  327. package/src/shared/components/useFocusHandoff.ts +51 -0
  328. package/src/shared/components/useLatestRef.ts +28 -0
  329. package/src/shared/markdown/Markdown.tsx +12 -3
  330. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  331. package/src/shared/markdown/hrefs.ts +50 -0
  332. package/src/shared/marketplace-url.ts +33 -5
  333. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  334. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  335. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  336. package/src/shared/mcp/connect-snippets.ts +14 -9
  337. package/src/shared/mcp/index.ts +1 -1
  338. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  339. package/src/shared/theme/header.ts +75 -0
  340. package/src/shared/theme/measure.ts +7 -4
  341. package/src/shared/theme/tokens.css +25 -0
  342. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  343. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  344. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  345. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  346. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  347. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -0,0 +1,320 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, fireEvent, within, cleanup } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { MemoryRouter } from 'react-router-dom';
5
+
6
+ /**
7
+ * The menu a skill card and a plugin row carry.
8
+ *
9
+ * A business-user tester could see plugins and skills on a group's page and had
10
+ * nowhere to share any of them: Share lived on the item's own page, in the file
11
+ * tree's right-click and on a nav row, never on the thing they were looking at.
12
+ * So every card and row that HAS a second verb now offers one — and what is
13
+ * under test here is which verb each of them gets, because that is the part
14
+ * that differs: a readable skill shares its own folder, a readable plugin
15
+ * shares its primary folder, and a plugin the caller cannot read is offered
16
+ * the locked page's Subscribe instead.
17
+ *
18
+ * Dismissal — outside click, Escape, the focus handback that comes with it —
19
+ * is `useDismissableMenu`'s and is covered where that is
20
+ * (`PluginsSidebarMenu`); what the keyboard cases here prove is the part this
21
+ * menu added, which is the INSIDE of it: opening lands focus on the first
22
+ * verb, the arrows walk the items, and the two other ways out that leave the
23
+ * focused node unmounted hand focus back too — Tab, and picking a verb whose
24
+ * action opens nothing of its own. A verb that DOES open something (Share's
25
+ * dialog) or navigates (Open) hands focus on from there, and that is the
26
+ * destination's to own, not the menu's.
27
+ */
28
+
29
+ const svc = vi.hoisted(() => ({ requestPluginAccess: vi.fn() }));
30
+ const libStub = vi.hoisted(() => ({ current: null as unknown }));
31
+
32
+ vi.mock('../services/plugins.api', async (orig) => ({
33
+ ...(await orig<typeof import('../services/plugins.api')>()),
34
+ requestPluginAccess: svc.requestPluginAccess,
35
+ }));
36
+ vi.mock('../../admin/state/admin.context', async (orig) => ({
37
+ ...(await orig<typeof import('../../admin/state/admin.context')>()),
38
+ useAdmin: () => ({ isAdmin: false }),
39
+ }));
40
+ // The band reads the catalog from its context; what decides a row's verbs is
41
+ // the entries and the summaries, so the context is stubbed rather than driven
42
+ // through the provider and its four endpoints.
43
+ vi.mock('../state/library-data', async (orig) => ({
44
+ ...(await orig<typeof import('../state/library-data')>()),
45
+ useLibrary: () => libStub.current,
46
+ }));
47
+
48
+ import { LibraryCard, type LibraryCardProps } from '../components/LibraryCard';
49
+ import { PluginRows } from '../components/PluginRows';
50
+ import type { LibraryContextValue } from '../state/library-data';
51
+ import type { PluginEntry } from '../utils/plugin-entries';
52
+ import type { PluginSummary } from '../services/plugins.api';
53
+
54
+ /* ---------------------------------------------------------------- helpers */
55
+
56
+ const items = () =>
57
+ within(screen.getByRole('menu'))
58
+ .getAllByRole('menuitem')
59
+ .map((i) => i.textContent);
60
+
61
+ const trigger = (label: string) => screen.getByRole('button', { name: `Actions for ${label}` });
62
+
63
+ function card(over: Partial<LibraryCardProps> = {}) {
64
+ const props = {
65
+ kind: 'skill',
66
+ id: 'rfi',
67
+ name: 'rfi',
68
+ description: 'Answers an RFI.',
69
+ owned: false,
70
+ status: { state: 'ok', text: 'Ready' },
71
+ onOpen: vi.fn(),
72
+ ...over,
73
+ } as LibraryCardProps;
74
+ render(<LibraryCard {...props} />);
75
+ return props;
76
+ }
77
+
78
+ const summary = (over: Partial<PluginSummary>): PluginSummary => ({
79
+ name: 'gtm',
80
+ displayName: 'GTM',
81
+ folders: ['Plugins/GTM'],
82
+ linksAreManaged: true,
83
+ canRead: true,
84
+ canWrite: false,
85
+ isOwner: false,
86
+ skillCount: 2,
87
+ toolCount: 1,
88
+ brokenLinks: 0,
89
+ owners: { roles: [], users: [{ name: 'Olga Ivanova', email: 'olga@example.com' }] },
90
+ writers: { roles: [], users: [] },
91
+ readers: { restricted: true, roles: [], users: [] },
92
+ isPrivate: false,
93
+ hasRequested: false,
94
+ requestNumber: null,
95
+ ...over,
96
+ });
97
+
98
+ const entry = (over: Partial<PluginEntry>): PluginEntry => ({
99
+ name: 'gtm',
100
+ label: 'GTM',
101
+ summary: summary({}),
102
+ skillCount: 2,
103
+ toolCount: 1,
104
+ attention: 0,
105
+ urgent: false,
106
+ member: true,
107
+ ...over,
108
+ });
109
+
110
+ /**
111
+ * The band with the catalog stubbed at the context, not at the network: what
112
+ * is under test is which verbs a row offers, and that is decided from the
113
+ * entries and the summaries alone.
114
+ */
115
+ function rows(entries: PluginEntry[], onShare?: (folder: string) => void) {
116
+ const lib = {
117
+ loading: false,
118
+ error: null,
119
+ items: [],
120
+ pluginSummaries: entries.map((e) => e.summary).filter((s): s is PluginSummary => s !== null),
121
+ pluginsLoading: false,
122
+ pluginsError: null,
123
+ teams: [],
124
+ teamsLoading: false,
125
+ teamsError: null,
126
+ reload: vi.fn(),
127
+ reloadPlugins: vi.fn(),
128
+ } as unknown as LibraryContextValue;
129
+ libStub.current = lib;
130
+ render(
131
+ <MemoryRouter>
132
+ <PluginRows entries={entries} onShare={onShare} />
133
+ </MemoryRouter>,
134
+ );
135
+ return lib;
136
+ }
137
+
138
+ beforeEach(() => {
139
+ vi.clearAllMocks();
140
+ svc.requestPluginAccess.mockResolvedValue(undefined);
141
+ });
142
+
143
+ /* ------------------------------------------------------------------ cards */
144
+
145
+ describe('a skill card', () => {
146
+ it('offers Open and Share, and Share opens the skill’s own access rules', () => {
147
+ const onShare = vi.fn();
148
+ card({ onShare });
149
+
150
+ fireEvent.click(trigger('rfi'));
151
+ expect(items()).toEqual(['Open', 'Share']);
152
+
153
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Share' }));
154
+ expect(onShare).toHaveBeenCalledTimes(1);
155
+ // Picking closes the menu — the dialog it opened is the surface now.
156
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
157
+ });
158
+
159
+ it('opens the same menu on right-click, at the pointer', () => {
160
+ card({ onShare: vi.fn() });
161
+
162
+ fireEvent.contextMenu(screen.getByRole('group', { name: 'rfi' }), { clientX: 120, clientY: 240 });
163
+ expect(items()).toEqual(['Open', 'Share']);
164
+ // AT THE POINTER, which is the half of this that a menu opening at the
165
+ // trigger — or at the origin — would still pass without. The panel is
166
+ // placed by the fixed wrapper around it; nothing is measurable in this
167
+ // DOM, so the pointer is where it stays.
168
+ const panel = screen.getByRole('menu').parentElement as HTMLElement;
169
+ expect(panel.style.left).toBe('120px');
170
+ expect(panel.style.top).toBe('240px');
171
+ });
172
+
173
+ it('still opens the skill when the card body is clicked', () => {
174
+ const props = card({ onShare: vi.fn() });
175
+
176
+ fireEvent.click(screen.getByTestId('library-card-skill-rfi'));
177
+ expect(props.onOpen).toHaveBeenCalledTimes(1);
178
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
179
+ });
180
+
181
+ it('carries no menu without a Share to offer, and none at all on a tool', () => {
182
+ card({});
183
+ expect(screen.queryByRole('button', { name: /^Actions for/ })).not.toBeInTheDocument();
184
+
185
+ cleanup();
186
+ // Access to a tool is decided at its plugin, so a tool card has nothing of
187
+ // its own to share — the props union refuses `onShare` outright.
188
+ card({ kind: 'integration', flavor: 'utcp', id: 'slack', name: 'Slack', status: { state: 'ok', text: 'Connected' } });
189
+ expect(screen.queryByRole('button', { name: /^Actions for/ })).not.toBeInTheDocument();
190
+ });
191
+
192
+ /**
193
+ * The keyboard path the ticket names: the "…" is a tab stop after the card,
194
+ * Enter opens, the arrows move, Escape closes and hands focus back.
195
+ */
196
+ it('is driveable from the keyboard alone', async () => {
197
+ const onShare = vi.fn();
198
+ card({ onShare });
199
+ const dots = trigger('rfi');
200
+
201
+ // A real Enter on a focused button fires its click; the tab order is DOM
202
+ // order, and the button follows the card inside the frame.
203
+ const frame = screen.getByRole('group', { name: 'rfi' });
204
+ expect(frame.firstElementChild).toBe(screen.getByTestId('library-card-skill-rfi'));
205
+ expect(frame.children[1]).toBe(dots);
206
+
207
+ dots.focus();
208
+ // ENTER, not a synthesised click: the tab stop has to be operable by the
209
+ // key the ticket names, and a click would pass even if it were not.
210
+ await userEvent.keyboard('{Enter}');
211
+ // Focus enters the menu with it, on the first verb.
212
+ expect(document.activeElement).toBe(screen.getByRole('menuitem', { name: 'Open' }));
213
+
214
+ fireEvent.keyDown(screen.getByRole('menu'), { key: 'ArrowDown' });
215
+ expect(document.activeElement).toBe(screen.getByRole('menuitem', { name: 'Share' }));
216
+ // The list wraps, so the arrows never strand anybody at an end.
217
+ fireEvent.keyDown(screen.getByRole('menu'), { key: 'ArrowDown' });
218
+ expect(document.activeElement).toBe(screen.getByRole('menuitem', { name: 'Open' }));
219
+
220
+ fireEvent.keyDown(document, { key: 'Escape' });
221
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
222
+ expect(document.activeElement).toBe(dots);
223
+ expect(onShare).not.toHaveBeenCalled();
224
+ });
225
+
226
+ /**
227
+ * Tab is the way out of the menu that Escape's handback does not cover: the
228
+ * menu closes and the focused node goes with it, and focus left on a removed
229
+ * node restarts the next Tab at the top of the document. The OTHER way —
230
+ * picking a verb — is proved on a row, where a verb exists whose real action
231
+ * opens nothing (see `Subscribe`); Share's own action mounts the
232
+ * Manage-access dialog, and THAT is what takes focus after a pick here.
233
+ */
234
+ it('hands focus back to the "…" when the menu is tabbed out of', () => {
235
+ card({ onShare: vi.fn() });
236
+ const dots = trigger('rfi');
237
+
238
+ fireEvent.click(dots);
239
+ fireEvent.keyDown(screen.getByRole('menu'), { key: 'Tab' });
240
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
241
+ expect(document.activeElement).toBe(dots);
242
+ });
243
+ });
244
+
245
+ /* ------------------------------------------------------------------- rows */
246
+
247
+ describe('a plugin row', () => {
248
+ it("offers Open and Share, and Share names the plugin's primary folder", () => {
249
+ const onShare = vi.fn();
250
+ rows([entry({})], onShare);
251
+
252
+ fireEvent.click(trigger('GTM'));
253
+ expect(items()).toEqual(['Open', 'Share']);
254
+
255
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Share' }));
256
+ expect(onShare).toHaveBeenCalledWith('Plugins/GTM');
257
+ });
258
+
259
+ it('offers Subscribe in place of Share on a plugin the caller cannot read, and asks its owners', async () => {
260
+ rows([entry({ member: false, summary: summary({ canRead: false }) })], vi.fn());
261
+
262
+ fireEvent.click(trigger('GTM'));
263
+ expect(items()).toEqual(['Open', 'Subscribe']);
264
+
265
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Subscribe' }));
266
+ expect(svc.requestPluginAccess).toHaveBeenCalledWith('gtm');
267
+ // Having asked, the row says so — chip and menu both — rather than
268
+ // offering the ask again. The same swap the locked page makes.
269
+ await vi.waitFor(() => expect(screen.getByText('Requested')).toBeInTheDocument());
270
+
271
+ fireEvent.click(trigger('GTM'));
272
+ expect(items()).toEqual(['Open', 'Requested']);
273
+ expect(screen.getByRole('menuitem', { name: 'Requested' })).toBeDisabled();
274
+ });
275
+
276
+ /**
277
+ * The pick that opens NOTHING, which is the case the menu has to answer for
278
+ * itself: Subscribe sends a request and leaves the row exactly where it was,
279
+ * so there is no dialog to take focus and no page to navigate to. Only the
280
+ * service is stubbed here — the verb runs its own handler — so focus landing
281
+ * anywhere but the "…" would show up.
282
+ */
283
+ it('hands focus back to the "…" after a verb that opens nothing', async () => {
284
+ rows([entry({ member: false, summary: summary({ canRead: false }) })], vi.fn());
285
+ const dots = trigger('GTM');
286
+
287
+ fireEvent.click(dots);
288
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Subscribe' }));
289
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
290
+ expect(document.activeElement).toBe(dots);
291
+ // And it stays there once the request answers and the row re-renders.
292
+ await vi.waitFor(() => expect(screen.getByText('Requested')).toBeInTheDocument());
293
+ expect(document.activeElement).toBe(trigger('GTM'));
294
+ });
295
+
296
+ it('states Requested from the start for a plugin already asked about', () => {
297
+ rows([entry({ member: false, summary: summary({ canRead: false, hasRequested: true }) })], vi.fn());
298
+
299
+ fireEvent.click(trigger('GTM'));
300
+ expect(items()).toEqual(['Open', 'Requested']);
301
+ });
302
+
303
+ it("gives the caller's own space no menu — it is not a plugin, and has neither verb", () => {
304
+ rows([entry({ name: null, label: 'Yours', summary: null })], vi.fn());
305
+
306
+ expect(screen.queryByRole('button', { name: /^Actions for/ })).not.toBeInTheDocument();
307
+ });
308
+
309
+ it('gives a readable plugin no menu when there is no folder to point Share at', () => {
310
+ // Two ways to have none: the PAGE cannot address folders yet (no `onShare`
311
+ // — its KB directory has not resolved), and the PLUGIN has no folder the
312
+ // index named. Either way Share would open on a path we do not mean.
313
+ rows([entry({})]);
314
+ expect(screen.queryByRole('button', { name: /^Actions for/ })).not.toBeInTheDocument();
315
+
316
+ cleanup();
317
+ rows([entry({ summary: summary({ folders: [] }) })], vi.fn());
318
+ expect(screen.queryByRole('button', { name: /^Actions for/ })).not.toBeInTheDocument();
319
+ });
320
+ });
@@ -0,0 +1,98 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, act } from '@testing-library/react';
3
+ import type { LibraryData } from '../hooks/useLibraryData';
4
+ import type { LibrarySkillSummary } from '../services/library.api';
5
+
6
+ /**
7
+ * What the catalog payload becomes — specifically, what it does NOT become.
8
+ *
9
+ * This is the reachable layer for the lifecycle removal. A `SKILL.md` may
10
+ * still declare `metadata.lifecycle`/`metadata.owner` and an older server may
11
+ * still put them on the wire; the acceptance criterion is that neither key
12
+ * reaches a `LibraryItem`. Pinned HERE rather than on a component, because
13
+ * once the mapper drops the keys no downstream card, picker or panel can
14
+ * badge or filter on them — there is nothing left to read.
15
+ */
16
+ const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
17
+ vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
18
+ vi.mock('../services/plugins.api', () => ({ listPlugins: vi.fn().mockResolvedValue([]) }));
19
+ vi.mock('../services/teams.api', () => ({ listTeams: vi.fn().mockResolvedValue([]) }));
20
+
21
+ import { LibraryProvider, useLibrary, type LibraryItem } from '../state/library-data';
22
+
23
+ function catalog(skills: LibrarySkillSummary[]): LibraryData {
24
+ return {
25
+ loading: false,
26
+ error: null,
27
+ skills,
28
+ pendingSkills: [],
29
+ pendingTools: [],
30
+ tools: [],
31
+ ownedSkills: new Set(),
32
+ writableSkills: new Set(),
33
+ ownedTools: new Set(),
34
+ allowedToolsBySkill: new Map(),
35
+ crs: [],
36
+ myCrNumbers: new Set(),
37
+ reload: vi.fn(),
38
+ };
39
+ }
40
+
41
+ /** Reads the mapped items back out of the provider. */
42
+ function Probe({ seen }: { seen: LibraryItem[][] }) {
43
+ seen.push(useLibrary().items);
44
+ return null;
45
+ }
46
+
47
+ async function itemsFor(skills: LibrarySkillSummary[]): Promise<LibraryItem[]> {
48
+ dataMock.useLibraryData.mockReturnValue(catalog(skills));
49
+ const seen: LibraryItem[][] = [];
50
+ render(
51
+ <LibraryProvider>
52
+ <Probe seen={seen} />
53
+ </LibraryProvider>,
54
+ );
55
+ await act(async () => undefined);
56
+ return seen[seen.length - 1];
57
+ }
58
+
59
+ describe('LibraryProvider item mapping', () => {
60
+ it('drops the governance keys an older server still sends', async () => {
61
+ // The cast is the case under test: `lifecycle`/`owner` are gone from
62
+ // `LibrarySkillSummary`, so the only way they arrive is from a server
63
+ // this frontend no longer agrees with — a deployment mid-upgrade, or a
64
+ // SKILL.md whose frontmatter still declares them.
65
+ const legacy = {
66
+ name: 'legacy-pitch',
67
+ description: 'Old but readable.',
68
+ version: '2.1.0',
69
+ path: 'Skills/Sales/legacy-pitch',
70
+ plugins: [],
71
+ lifecycle: 'retired',
72
+ owner: 'gtm-team',
73
+ } as LibrarySkillSummary;
74
+
75
+ const [item] = await itemsFor([legacy]);
76
+
77
+ // The skill is present and complete — the removal drops the two keys,
78
+ // not the skill and not the metadata that stayed.
79
+ expect(item.name).toBe('legacy-pitch');
80
+ expect(item.version).toBe('2.1.0');
81
+ expect(item.path).toBe('Skills/Sales/legacy-pitch');
82
+
83
+ // `in`, not a truthiness check: the point is the key is absent from the
84
+ // item, not merely that it reads as undefined.
85
+ expect('lifecycle' in item).toBe(false);
86
+ expect('owner' in item).toBe(false);
87
+ });
88
+
89
+ it('keeps a lifecycle-less skill indistinguishable from the legacy one', async () => {
90
+ // Both shapes map to the same item, which is the whole claim: the
91
+ // platform has no opinion left to form about a skill's lifecycle.
92
+ const [legacy] = await itemsFor([
93
+ { name: 'x', description: 'd', path: 'Skills/x', plugins: [], lifecycle: 'retired' } as LibrarySkillSummary,
94
+ ]);
95
+ const [plain] = await itemsFor([{ name: 'x', description: 'd', path: 'Skills/x', plugins: [] }]);
96
+ expect(legacy).toEqual(plain);
97
+ });
98
+ });
@@ -1,6 +1,8 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
+ import { useState } from 'react';
2
3
  import { render, act } from '@testing-library/react';
3
4
  import type { LibraryData } from '../hooks/useLibraryData';
5
+ import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
4
6
 
5
7
  /**
6
8
  * The catalog's own view of change requests refreshes on the same event the
@@ -10,25 +12,37 @@ import type { LibraryData } from '../hooks/useLibraryData';
10
12
  const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
11
13
  vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
12
14
  vi.mock('../services/plugins.api', () => ({ listPlugins: vi.fn().mockResolvedValue([]) }));
15
+ vi.mock('../services/teams.api', () => ({ listTeams: vi.fn().mockResolvedValue([]) }));
13
16
 
14
17
  import { LibraryProvider, useLibrary } from '../state/library-data';
15
- import { PR_STALE_EVENT } from '../../../core/events';
18
+ import { PR_STALE_COALESCE_MS, PR_STALE_EVENT, TOOL_CREDENTIALS_STALE_EVENT } from '../../../core/events';
19
+
20
+ /** Well past the window in which stale events are coalesced into one reload — for asserting that nothing more happens. */
21
+ const settled = () => new Promise<void>((resolve) => setTimeout(resolve, PR_STALE_COALESCE_MS * 3));
22
+
23
+ /** The catalog, empty — each test fills in only the part it is about. */
24
+ function emptyData(reload: () => void): LibraryData {
25
+ return {
26
+ loading: false,
27
+ error: null,
28
+ skills: [],
29
+ pendingSkills: [],
30
+ pendingTools: [],
31
+ tools: [],
32
+ ownedSkills: new Set(),
33
+ writableSkills: new Set(),
34
+ ownedTools: new Set(),
35
+ allowedToolsBySkill: new Map(),
36
+ crs: [],
37
+ myCrNumbers: new Set(),
38
+ reload,
39
+ };
40
+ }
16
41
 
17
42
  describe('LibraryProvider', () => {
18
43
  it('reloads the catalog when change requests go stale', async () => {
19
44
  const reload = vi.fn();
20
- const data: LibraryData = {
21
- loading: false,
22
- error: null,
23
- skills: [],
24
- pendingSkills: [],
25
- tools: [],
26
- ownedSkills: new Set(),
27
- allowedToolsBySkill: new Map(),
28
- crs: [],
29
- myCrNumbers: new Set(),
30
- reload,
31
- };
45
+ const data = emptyData(reload);
32
46
  dataMock.useLibraryData.mockReturnValue(data);
33
47
  const { listPlugins } = await import('../services/plugins.api');
34
48
  vi.mocked(listPlugins).mockClear();
@@ -36,16 +50,20 @@ describe('LibraryProvider', () => {
36
50
  await act(async () => undefined);
37
51
  expect(reload).not.toHaveBeenCalled();
38
52
  expect(listPlugins).toHaveBeenCalledTimes(1);
39
- await act(async () => {
53
+ // Two events in one burst — the local announcement and the bus binder's
54
+ // — are one reload, once the coalescing window has passed.
55
+ act(() => {
56
+ window.dispatchEvent(new Event(PR_STALE_EVENT));
40
57
  window.dispatchEvent(new Event(PR_STALE_EVENT));
41
58
  });
42
- expect(reload).toHaveBeenCalledTimes(1);
59
+ await vi.waitFor(() => expect(reload).toHaveBeenCalledTimes(1));
43
60
  // A merged change can move plugin links and access: the summaries
44
61
  // refresh with the catalog, not only on a page's own reload.
45
- expect(listPlugins).toHaveBeenCalledTimes(2);
62
+ await vi.waitFor(() => expect(listPlugins).toHaveBeenCalledTimes(2));
46
63
  view.unmount();
47
64
  await act(async () => {
48
65
  window.dispatchEvent(new Event(PR_STALE_EVENT));
66
+ await settled();
49
67
  });
50
68
  expect(reload).toHaveBeenCalledTimes(1);
51
69
  });
@@ -54,18 +72,7 @@ describe('LibraryProvider', () => {
54
72
  // A page that reloads after a link, a repair or an access edit must get
55
73
  // fresh plugin counts too — the broken-link number lives in the summary.
56
74
  const reload = vi.fn();
57
- const data: LibraryData = {
58
- loading: false,
59
- error: null,
60
- skills: [],
61
- pendingSkills: [],
62
- tools: [],
63
- ownedSkills: new Set(),
64
- allowedToolsBySkill: new Map(),
65
- crs: [],
66
- myCrNumbers: new Set(),
67
- reload,
68
- };
75
+ const data = emptyData(reload);
69
76
  dataMock.useLibraryData.mockReturnValue(data);
70
77
  const { listPlugins } = await import('../services/plugins.api');
71
78
  vi.mocked(listPlugins).mockClear();
@@ -87,4 +94,90 @@ describe('LibraryProvider', () => {
87
94
  expect(reload).toHaveBeenCalledTimes(1);
88
95
  expect(listPlugins).toHaveBeenCalledTimes(2);
89
96
  });
97
+
98
+ /**
99
+ * A credential landing anywhere in the app.
100
+ *
101
+ * The tool page re-probes itself after a save, which is exactly why the bug
102
+ * this covers was invisible there and obvious one click later: everything
103
+ * that says "needs setup" — the cards, the plugin page's banner, the sidebar
104
+ * count — reads the tool rows in THIS catalog, loaded before the write.
105
+ */
106
+ describe('after a credential lands', () => {
107
+ it('reloads the catalog and the plugin summaries together', async () => {
108
+ // Together, not just the catalog: the plugin summaries carry the counts
109
+ // behind the banner and the sidebar, and a catalog-only reload leaves
110
+ // the number from before the save beside a card that has moved on.
111
+ const reload = vi.fn();
112
+ dataMock.useLibraryData.mockReturnValue(emptyData(reload));
113
+ const { listPlugins } = await import('../services/plugins.api');
114
+ vi.mocked(listPlugins).mockClear();
115
+
116
+ const view = render(<LibraryProvider>x</LibraryProvider>);
117
+ await act(async () => undefined);
118
+ expect(reload).not.toHaveBeenCalled();
119
+ expect(listPlugins).toHaveBeenCalledTimes(1);
120
+
121
+ await act(async () => {
122
+ window.dispatchEvent(new Event(TOOL_CREDENTIALS_STALE_EVENT));
123
+ });
124
+ expect(reload).toHaveBeenCalledTimes(1);
125
+ expect(listPlugins).toHaveBeenCalledTimes(2);
126
+
127
+ // The listener dies with the provider: a save on /secrets, which is a
128
+ // shell route of its own with no Library mounted under it, must not
129
+ // reach for a store that is gone.
130
+ view.unmount();
131
+ await act(async () => {
132
+ window.dispatchEvent(new Event(TOOL_CREDENTIALS_STALE_EVENT));
133
+ });
134
+ expect(reload).toHaveBeenCalledTimes(1);
135
+ });
136
+
137
+ it('leaves the tool reading as configured for the page the reader goes back to', async () => {
138
+ // The whole point, end to end: the catalog refetches, and the item every
139
+ // card and banner is built from carries the NEW state. The mock stands
140
+ // in for the real hook's refetch — one reload, one fresher answer.
141
+ const tool = (userConfigured: boolean): ToolSecrets => ({
142
+ slug: 'heyreach',
143
+ name: 'heyreach',
144
+ path: 'Plugins/GTM/heyreach.tool',
145
+ type: 'inline',
146
+ setup: null,
147
+ canWrite: false,
148
+ variables: [
149
+ {
150
+ name: 'API_KEY',
151
+ scope: 'user',
152
+ label: null,
153
+ key: 'heyreach_API_KEY',
154
+ adminConfigured: true,
155
+ userConfigured,
156
+ },
157
+ ],
158
+ });
159
+ dataMock.useLibraryData.mockImplementation(() => {
160
+ const [saved, setSaved] = useState(false);
161
+ return { ...emptyData(() => setSaved(true)), tools: [tool(saved)] };
162
+ });
163
+
164
+ let status = '';
165
+ function Probe() {
166
+ status = useLibrary().items[0].status.text;
167
+ return null;
168
+ }
169
+ render(
170
+ <LibraryProvider>
171
+ <Probe />
172
+ </LibraryProvider>,
173
+ );
174
+ await act(async () => undefined);
175
+ expect(status).toBe('Needs a key from you');
176
+
177
+ await act(async () => {
178
+ window.dispatchEvent(new Event(TOOL_CREDENTIALS_STALE_EVENT));
179
+ });
180
+ expect(status).toBe('Key saved');
181
+ });
182
+ });
90
183
  });
@@ -19,6 +19,7 @@ function item(plugin: string | null): LibraryItem {
19
19
  name: 'scratch',
20
20
  description: '',
21
21
  owned: false,
22
+ canWrite: false,
22
23
  plugin,
23
24
  path: plugin ? `Plugins/${plugin}/scratch` : 'Skills/scratch',
24
25
  status: { state: 'ok', text: 'Ready' },
@@ -31,8 +32,11 @@ function lib(over: Partial<LibraryContextValue> = {}): LibraryContextValue {
31
32
  error: null,
32
33
  skills: [],
33
34
  pendingSkills: [],
35
+ pendingTools: [],
34
36
  tools: [],
35
37
  ownedSkills: new Set(),
38
+ writableSkills: new Set(),
39
+ ownedTools: new Set(),
36
40
  allowedToolsBySkill: new Map(),
37
41
  crs: [],
38
42
  myCrNumbers: new Set(),
@@ -41,6 +45,9 @@ function lib(over: Partial<LibraryContextValue> = {}): LibraryContextValue {
41
45
  pluginSummaries: [],
42
46
  pluginsLoading: false,
43
47
  pluginsError: null,
48
+ teams: [],
49
+ teamsLoading: false,
50
+ teamsError: null,
44
51
  reloadPlugins: vi.fn(),
45
52
  ...over,
46
53
  };