@bevel-software/platform-core-frontend 0.4.0 → 0.5.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 (326) hide show
  1. package/package.json +5 -3
  2. package/src/core/CoreAppShell.tsx +195 -56
  3. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +130 -95
  5. package/src/core/__tests__/bootstrap.test.ts +63 -0
  6. package/src/core/bootstrap.ts +73 -0
  7. package/src/core/events.ts +12 -0
  8. package/src/core/registry.ts +58 -9
  9. package/src/index.css +100 -11
  10. package/src/index.ts +24 -23
  11. package/src/lib/utils.ts +114 -138
  12. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  14. package/src/modules/access/api.ts +49 -0
  15. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  16. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  17. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  18. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +172 -156
  19. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  22. package/src/modules/admin/components/UserAccountsPage.tsx +361 -353
  23. package/src/modules/admin/state/admin.context.tsx +15 -6
  24. package/src/modules/auth/components/AccountPage.tsx +11 -11
  25. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  26. package/src/modules/auth/services/sso.ts +47 -1
  27. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  28. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  29. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  30. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  31. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  32. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  33. package/src/modules/change-requests/change-requests.css +22 -0
  34. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  35. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  36. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  37. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  38. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  39. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  40. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  41. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  42. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  43. package/src/modules/change-requests/services/propose.api.ts +162 -0
  44. package/src/modules/change-requests/utils/author.ts +47 -0
  45. package/src/modules/change-requests/utils/conflict.ts +38 -0
  46. package/src/modules/change-requests/utils/diff.ts +80 -0
  47. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  48. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  49. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  50. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  51. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  52. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  53. package/src/modules/git/components/DiffView.tsx +4 -4
  54. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  55. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  56. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  57. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  58. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  59. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  60. package/src/modules/git/hooks/useGitState.ts +15 -14
  61. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  62. package/src/modules/git/services/error-messages.ts +7 -7
  63. package/src/modules/git/services/git.api.ts +17 -11
  64. package/src/modules/git/services/pr-prompts.ts +2 -2
  65. package/src/modules/git/state/git.context.ts +10 -1
  66. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  67. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  68. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  69. package/src/modules/layout/breakpoints.ts +6 -0
  70. package/src/modules/layout/components/AppLayout.tsx +17 -5
  71. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  72. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
  73. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  74. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  75. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  76. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  77. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  78. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  79. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  80. package/src/modules/layout/state/sidebar.ts +200 -0
  81. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  82. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  83. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  84. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  85. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  86. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  89. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  90. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  91. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  92. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  93. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  94. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  95. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  96. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  97. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  98. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  99. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  100. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  101. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  102. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  103. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  104. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  105. package/src/modules/library/__tests__/status.test.ts +210 -117
  106. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  107. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  108. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  109. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  110. package/src/modules/library/components/ChangeRequestDock.tsx +71 -47
  111. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  112. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  113. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  114. package/src/modules/library/components/GroupPage.tsx +373 -0
  115. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  116. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  117. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  118. package/src/modules/library/components/LibraryCard.tsx +153 -132
  119. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  120. package/src/modules/library/components/LibraryPage.tsx +138 -254
  121. package/src/modules/library/components/LockGlyph.tsx +31 -0
  122. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  123. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  124. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  125. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  126. package/src/modules/library/components/PageActions.tsx +156 -0
  127. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  128. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  129. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  130. package/src/modules/library/components/StatusDot.tsx +25 -0
  131. package/src/modules/library/components/ToolLogo.tsx +171 -0
  132. package/src/modules/library/components/group-page-parts.tsx +419 -0
  133. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  134. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  135. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  136. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  137. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  138. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  139. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  140. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  141. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  142. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  143. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  144. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  145. package/src/modules/library/hooks/useToolPage.ts +145 -0
  146. package/src/modules/library/library.css +108 -320
  147. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  148. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  149. package/src/modules/library/routes/library-paths.ts +191 -0
  150. package/src/modules/library/services/groups.api.ts +189 -0
  151. package/src/modules/library/services/library.api.ts +291 -164
  152. package/src/modules/library/services/tools.api.ts +60 -0
  153. package/src/modules/library/state/library-context.ts +22 -0
  154. package/src/modules/library/state/library-data.tsx +223 -0
  155. package/src/modules/library/state/toast.context.ts +32 -0
  156. package/src/modules/library/state/toast.tsx +84 -42
  157. package/src/modules/library/utils/clipboard.ts +33 -0
  158. package/src/modules/library/utils/group-summary.ts +68 -0
  159. package/src/modules/library/utils/names.ts +30 -0
  160. package/src/modules/library/utils/navigate-external.ts +15 -0
  161. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  162. package/src/modules/library/utils/personal-group.ts +36 -0
  163. package/src/modules/library/utils/status.ts +199 -116
  164. package/src/modules/library/utils/toast-duration.ts +16 -0
  165. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  166. package/src/modules/onboarding/agent-clients.ts +48 -0
  167. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  168. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  169. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  170. package/src/modules/onboarding/paths.ts +9 -0
  171. package/src/modules/onboarding/state/onboarding.ts +191 -0
  172. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  173. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  174. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  175. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  176. package/src/modules/review/components/DiffViewer.tsx +4 -4
  177. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  178. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  179. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  180. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  181. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  182. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  183. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  184. package/src/modules/secrets-vault/components/SecretsPage.tsx +313 -276
  185. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  186. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +82 -51
  187. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  188. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  189. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  190. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  191. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  192. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  193. package/src/modules/settings/settings-nav-items.tsx +166 -0
  194. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  195. package/src/modules/setup/components/SetupGate.tsx +67 -0
  196. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  197. package/src/modules/setup/services/setup.api.ts +106 -0
  198. package/src/modules/setup/utils/git-host.ts +34 -0
  199. package/src/modules/toolbar/components/AppSwitcher.tsx +131 -108
  200. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
  201. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  202. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  203. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  204. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  205. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  206. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  207. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  208. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  209. package/src/modules/workspace/components/FileExplorer.tsx +1292 -1068
  210. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  211. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  212. package/src/modules/workspace/components/FileViewer.tsx +1312 -906
  213. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  214. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  215. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  216. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  217. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  218. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  219. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  220. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  221. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  222. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  223. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  224. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  225. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  226. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  227. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  228. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  229. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  230. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  231. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  232. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  233. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  234. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  235. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  236. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  237. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  238. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  240. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  241. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  242. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  243. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  244. package/src/modules/workspace/components/renderers/index.ts +78 -2
  245. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  246. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  247. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  248. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  249. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  250. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  251. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  252. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  253. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  254. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  255. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  256. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  257. package/src/modules/workspace/services/workspace.api.ts +9 -2
  258. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  259. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  260. package/src/modules/workspace/state/workspace.context.ts +9 -0
  261. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  262. package/src/modules/workspace/utils/diff.ts +130 -53
  263. package/src/modules/workspace/utils/fileTree.ts +182 -179
  264. package/src/modules/workspace/workspace.css +28 -0
  265. package/src/shared/components/Badge.tsx +62 -0
  266. package/src/shared/components/Banner.tsx +58 -0
  267. package/src/shared/components/Button.tsx +90 -0
  268. package/src/shared/components/Dialog.tsx +6 -6
  269. package/src/shared/components/Field.tsx +45 -0
  270. package/src/shared/components/IconButton.tsx +74 -0
  271. package/src/shared/components/ListRow.tsx +96 -0
  272. package/src/shared/components/Menu.tsx +88 -0
  273. package/src/shared/components/PageShell.tsx +54 -51
  274. package/src/shared/components/Surface.tsx +86 -0
  275. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  276. package/src/shared/components/index.ts +48 -0
  277. package/src/shared/components/useDismissableMenu.ts +71 -0
  278. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  279. package/src/shared/theme/index.css +12 -0
  280. package/src/shared/theme/measure.ts +64 -0
  281. package/src/shared/theme/shadows.css +34 -0
  282. package/src/shared/theme/tokens.css +193 -0
  283. package/src/test-setup.ts +9 -0
  284. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  285. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  286. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  287. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  288. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  289. package/src/modules/library/__tests__/diff.test.ts +0 -62
  290. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  291. package/src/modules/library/components/CompareView.tsx +0 -357
  292. package/src/modules/library/components/DetailDialog.tsx +0 -566
  293. package/src/modules/library/components/GearIcon.tsx +0 -12
  294. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  295. package/src/modules/library/components/StatusGem.tsx +0 -21
  296. package/src/modules/library/components/SuggestChange.tsx +0 -171
  297. package/src/modules/library/components/particles.ts +0 -50
  298. package/src/modules/library/state/loadout.tsx +0 -129
  299. package/src/modules/library/utils/diff.ts +0 -102
  300. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  301. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  302. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  303. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  304. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  305. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  306. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  307. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  308. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  309. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  310. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  311. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  312. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  313. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  314. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  315. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  316. package/src/modules/pr/components/PrHeader.tsx +0 -45
  317. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  318. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  319. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  320. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  321. package/src/modules/pr/components/PrViewer.tsx +0 -364
  322. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  323. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  324. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  325. package/src/modules/pr/utils/parsePatch.ts +0 -57
  326. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -0,0 +1,178 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
+ import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
4
+ import type { JoinRequest } from '../services/groups.api';
5
+
6
+ /**
7
+ * The manager-side join-request surface.
8
+ *
9
+ * The behaviour that matters is that accepting is a GRANT, not a merge: one
10
+ * proposal at a time, through the ordinary access API, leaving the request's
11
+ * branch untouched. The request then settles itself server-side, which this
12
+ * surface only has to ask about.
13
+ */
14
+ const groupsMock = vi.hoisted(() => ({
15
+ listJoinRequests: vi.fn(),
16
+ reconcileJoinRequest: vi.fn(),
17
+ }));
18
+ vi.mock('../services/groups.api', () => ({
19
+ listJoinRequests: groupsMock.listJoinRequests,
20
+ reconcileJoinRequest: groupsMock.reconcileJoinRequest,
21
+ }));
22
+
23
+ const accessMock = vi.hoisted(() => ({ grantAccess: vi.fn() }));
24
+ vi.mock('../../access/api', () => ({ grantAccess: accessMock.grantAccess }));
25
+
26
+ const prMock = vi.hoisted(() => ({ cancelPullRequest: vi.fn() }));
27
+ vi.mock('../../pr/services/pr-cancel.api', () => ({
28
+ cancelPullRequest: prMock.cancelPullRequest,
29
+ }));
30
+
31
+ import { LibraryToastProvider } from '../state/toast';
32
+ import { GroupJoinRequests } from '../components/GroupJoinRequests';
33
+
34
+ const request = (over: Partial<JoinRequest> = {}): JoinRequest => ({
35
+ number: 7,
36
+ branch: 'ali/join-gtm-abc1234',
37
+ requesterName: 'Ali Baba',
38
+ createdAt: '2026-01-01T00:00:00.000Z',
39
+ proposals: [
40
+ {
41
+ verb: 'read',
42
+ id: 'user:ali@bevel.software',
43
+ principal: { kind: 'user', email: 'ali@bevel.software', displayName: 'Ali Baba' },
44
+ label: 'Ali Baba',
45
+ },
46
+ ],
47
+ ...over,
48
+ });
49
+
50
+ function renderBanner(onManage = vi.fn()) {
51
+ render(
52
+ <LibraryToastProvider>
53
+ <GroupJoinRequests group="GTM" folders={['Groups/GTM']} onManage={onManage} />
54
+ </LibraryToastProvider>,
55
+ );
56
+ return { onManage };
57
+ }
58
+
59
+ describe('GroupJoinRequests', () => {
60
+ beforeEach(() => {
61
+ vi.clearAllMocks();
62
+ groupsMock.listJoinRequests.mockResolvedValue([request()]);
63
+ groupsMock.reconcileJoinRequest.mockResolvedValue(true);
64
+ accessMock.grantAccess.mockResolvedValue({});
65
+ prMock.cancelPullRequest.mockResolvedValue({});
66
+ });
67
+
68
+ it('names the requester and the exact grant being proposed', async () => {
69
+ renderBanner();
70
+ expect(await screen.findByText(/Ali Baba asked to join GTM/)).toBeInTheDocument();
71
+ expect(
72
+ screen.getByRole('button', { name: 'Grant read to Ali Baba' }),
73
+ ).toBeInTheDocument();
74
+ });
75
+
76
+ it('states the VERB when a request asks for more than read', async () => {
77
+ // "asked to join" must never hide a write/owner request.
78
+ groupsMock.listJoinRequests.mockResolvedValue([
79
+ request({
80
+ proposals: [
81
+ {
82
+ verb: 'write',
83
+ id: 'role:finance team',
84
+ principal: { kind: 'role', role: 'Finance Team' },
85
+ label: 'Finance Team',
86
+ },
87
+ ],
88
+ }),
89
+ ]);
90
+ renderBanner();
91
+ expect(
92
+ await screen.findByRole('button', { name: 'Grant write to Finance Team' }),
93
+ ).toBeInTheDocument();
94
+ });
95
+
96
+ it('accepting GRANTS the one proposal on the default branch. It never merges', async () => {
97
+ renderBanner();
98
+ fireEvent.click(await screen.findByRole('button', { name: 'Grant read to Ali Baba' }));
99
+ await waitFor(() => expect(accessMock.grantAccess).toHaveBeenCalledTimes(1));
100
+ // The grant lands on the DEFAULT branch — that is where "the list" lives.
101
+ expect(accessMock.grantAccess).toHaveBeenCalledWith(encodeURIComponent(DEFAULT_BRANCH), {
102
+ path: 'Groups/GTM',
103
+ kind: 'folder',
104
+ verb: 'read',
105
+ principal: { kind: 'user', email: 'ali@bevel.software', displayName: 'Ali Baba' },
106
+ });
107
+ // Then it asks the server to settle the request now rather than waiting
108
+ // for the next listing.
109
+ await waitFor(() => expect(groupsMock.reconcileJoinRequest).toHaveBeenCalledWith('GTM', 7));
110
+ });
111
+
112
+ it('offers each proposal separately, so one request can be answered in parts', async () => {
113
+ groupsMock.listJoinRequests.mockResolvedValue([
114
+ request({
115
+ proposals: [
116
+ ...request().proposals,
117
+ {
118
+ verb: 'read',
119
+ id: 'user:juan@bevel.software',
120
+ principal: { kind: 'user', email: 'juan@bevel.software', displayName: 'Juan Viera' },
121
+ label: 'Juan Viera',
122
+ },
123
+ ],
124
+ }),
125
+ ]);
126
+ renderBanner();
127
+ fireEvent.click(await screen.findByRole('button', { name: 'Grant read to Juan Viera' }));
128
+ await waitFor(() => expect(accessMock.grantAccess).toHaveBeenCalledTimes(1));
129
+ expect(accessMock.grantAccess.mock.calls[0][1]).toMatchObject({
130
+ principal: { email: 'juan@bevel.software' },
131
+ });
132
+ });
133
+
134
+ it('a failed grant keeps the proposal on offer and never asks to reconcile', async () => {
135
+ // The optimistic removal must not survive a grant that didn't land — the
136
+ // refetch restores the row, and reconciling would be asking the server to
137
+ // settle a request whose proposal is still pending.
138
+ accessMock.grantAccess.mockRejectedValue(new Error('Not allowed'));
139
+ renderBanner();
140
+ fireEvent.click(await screen.findByRole('button', { name: 'Grant read to Ali Baba' }));
141
+ await waitFor(() => expect(accessMock.grantAccess).toHaveBeenCalledTimes(1));
142
+ expect(
143
+ await screen.findByRole('button', { name: 'Grant read to Ali Baba' }),
144
+ ).toBeInTheDocument();
145
+ expect(groupsMock.reconcileJoinRequest).not.toHaveBeenCalled();
146
+ });
147
+
148
+ it('declining rejects the change request', async () => {
149
+ renderBanner();
150
+ fireEvent.click(
151
+ await screen.findByRole('button', { name: 'Decline the request from Ali Baba' }),
152
+ );
153
+ await waitFor(() => expect(prMock.cancelPullRequest).toHaveBeenCalledWith(7));
154
+ expect(accessMock.grantAccess).not.toHaveBeenCalled();
155
+ });
156
+
157
+ it('renders nothing when there is nothing pending', async () => {
158
+ groupsMock.listJoinRequests.mockResolvedValue([]);
159
+ const { container } = render(
160
+ <LibraryToastProvider>
161
+ <GroupJoinRequests group="GTM" folders={['Groups/GTM']} onManage={vi.fn()} />
162
+ </LibraryToastProvider>,
163
+ );
164
+ await waitFor(() => expect(groupsMock.listJoinRequests).toHaveBeenCalled());
165
+ expect(container.textContent).not.toContain('asked to join');
166
+ });
167
+
168
+ it('stays silent when the listing fails. A manager surface must not break the page', async () => {
169
+ groupsMock.listJoinRequests.mockRejectedValue(new Error('boom'));
170
+ const { container } = render(
171
+ <LibraryToastProvider>
172
+ <GroupJoinRequests group="GTM" folders={['Groups/GTM']} onManage={vi.fn()} />
173
+ </LibraryToastProvider>,
174
+ );
175
+ await waitFor(() => expect(groupsMock.listJoinRequests).toHaveBeenCalled());
176
+ expect(container.querySelector('[role="alert"]')).toBeNull();
177
+ });
178
+ });
@@ -0,0 +1,479 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, act, fireEvent, waitFor } from '@testing-library/react';
3
+ import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
4
+ import type { ReactNode } from 'react';
5
+ import {
6
+ WorkspaceContext,
7
+ type WorkspaceContextValue,
8
+ } from '../../workspace/state/workspace.context';
9
+ import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
10
+ import type { LibraryData } from '../hooks/useLibraryData';
11
+ import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
12
+ import type { GroupSummary } from '../services/groups.api';
13
+ import { withAuth } from './auth-harness';
14
+
15
+ /**
16
+ * The group page: which view a caller gets, what the page says about who runs
17
+ * the group, and where its one action goes. The catalog and the group index are
18
+ * mocked at their two seams — what is under test is the page's judgement, not
19
+ * the fetching underneath it.
20
+ */
21
+
22
+ const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
23
+ vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
24
+
25
+ const groupsMock = vi.hoisted(() => ({
26
+ listGroups: vi.fn(),
27
+ listJoinRequests: vi.fn(),
28
+ reconcileJoinRequest: vi.fn(),
29
+ requestGroupAccess: vi.fn(),
30
+ }));
31
+ const libApiMock = vi.hoisted(() => ({ removeLibraryItem: vi.fn() }));
32
+ vi.mock('../services/library.api', async (importOriginal) => ({
33
+ ...(await importOriginal<object>()),
34
+ removeLibraryItem: libApiMock.removeLibraryItem,
35
+ }));
36
+
37
+ vi.mock('../services/groups.api', () => ({
38
+ listGroups: groupsMock.listGroups,
39
+ listJoinRequests: groupsMock.listJoinRequests,
40
+ reconcileJoinRequest: groupsMock.reconcileJoinRequest,
41
+ requestGroupAccess: groupsMock.requestGroupAccess,
42
+ AlreadyReadableError: class AlreadyReadableError extends Error {},
43
+ }));
44
+
45
+ // The ONE access surface — the separate summary section this page was designed
46
+ // with never shipped, so there is no `GroupAccessSection.test.tsx` to defer to.
47
+ // Mocked at the component: the dialog fetches on mount, and stubbing that seam
48
+ // keeps these tests on the page's judgement rather than the network. Its own
49
+ // behaviour lives in the access module's tests; what this file owes is that the
50
+ // page opens it on the right DIRECTORY.
51
+ vi.mock('../../access/components/ManageAccessDialog', () => ({
52
+ ManageAccessDialog: ({
53
+ entry,
54
+ onClose,
55
+ }: {
56
+ entry: { relativePath: string; type: string };
57
+ onClose(): void;
58
+ }) => (
59
+ <div role="dialog" aria-label={`Manage access ${entry.type} ${entry.relativePath}`}>
60
+ <button type="button" onClick={onClose}>
61
+ Close access
62
+ </button>
63
+ </div>
64
+ ),
65
+ }));
66
+
67
+ import { LibraryProvider } from '../state/library-data';
68
+ import { LibraryToastProvider } from '../state/toast';
69
+ import { GroupPage } from '../components/GroupPage';
70
+
71
+ const workspace = {
72
+ workspaceId: 'target-company-state',
73
+ kbDirName: 'knowledge-base',
74
+ } as unknown as WorkspaceContextValue;
75
+
76
+ const nonAdmin: AdminContextValue = {
77
+ isAdmin: false,
78
+ unreadCount: 0,
79
+ lastSeen: null,
80
+ markSeen: vi.fn(),
81
+ refresh: vi.fn(),
82
+ rolesConfigCorrupted: false,
83
+ rolesConfigErrors: [],
84
+ runRolesRecovery: vi.fn(),
85
+ };
86
+
87
+ const connectedTool = (over: Partial<ToolSecrets> = {}): ToolSecrets => ({
88
+ slug: 'heyreach',
89
+ name: 'heyreach',
90
+ path: 'Groups/GTM/heyreach.tool',
91
+ type: 'inline',
92
+ setup: null,
93
+ canWrite: false,
94
+ variables: [],
95
+ ...over,
96
+ });
97
+
98
+ /** A tool whose user key is missing — one unit of amber. */
99
+ const unsetTool = (over: Partial<ToolSecrets> = {}): ToolSecrets =>
100
+ connectedTool({
101
+ slug: 'apollo',
102
+ name: 'apollo',
103
+ path: 'Groups/GTM/apollo.tool',
104
+ variables: [
105
+ {
106
+ name: 'API_KEY',
107
+ scope: 'user',
108
+ label: null,
109
+ key: 'apollo_API_KEY',
110
+ adminConfigured: false,
111
+ userConfigured: false,
112
+ },
113
+ ],
114
+ ...over,
115
+ });
116
+
117
+ const CATALOG: LibraryData = {
118
+ loading: false,
119
+ error: null,
120
+ skills: [
121
+ { name: 'outreach', description: 'Runs the GTM outreach.', path: 'Groups/GTM/outreach' },
122
+ { name: 'roadmap', description: 'Keeps the roadmap.', path: 'Groups/Product/roadmap' },
123
+ ],
124
+ pendingSkills: [],
125
+ tools: [connectedTool()],
126
+ ownedSkills: new Set(['outreach']),
127
+ allowedToolsBySkill: new Map(),
128
+ crs: [],
129
+ myCrNumbers: new Set<number>(),
130
+ reload: vi.fn(),
131
+ };
132
+
133
+ const gtm = (over: Partial<GroupSummary> = {}): GroupSummary => ({
134
+ name: 'GTM',
135
+ folders: ['Groups/GTM'],
136
+ canRead: true,
137
+ canWrite: false,
138
+ isOwner: false,
139
+ skillCount: 1,
140
+ toolCount: 1,
141
+ owners: { roles: [], users: [{ name: 'Olga Ivanova', email: 'olga@bevel.software' }] },
142
+ writers: { roles: ['Admin'], users: [] },
143
+ readers: {
144
+ restricted: true,
145
+ roles: ['GTM Team'],
146
+ users: [{ name: 'Ali Baba', email: 'ali@bevel.software' }],
147
+ },
148
+ hasRequested: false,
149
+ requestNumber: null,
150
+ ...over,
151
+ });
152
+
153
+ function LocationProbe() {
154
+ const location = useLocation();
155
+ return <div aria-label="href">{location.pathname + location.search}</div>;
156
+ }
157
+
158
+ function renderGroup(name: string, children?: ReactNode) {
159
+ return render(
160
+ <MemoryRouter initialEntries={[`/skills-and-tools/groups/${encodeURIComponent(name)}`]}>
161
+ <AdminContext.Provider value={nonAdmin}>
162
+ <WorkspaceContext.Provider value={workspace}>
163
+ <LibraryToastProvider>
164
+ <LibraryProvider>
165
+ {withAuth(
166
+ <>
167
+ <Routes>
168
+ <Route path="/skills-and-tools/groups/:group" element={<GroupPage />} />
169
+ <Route path="*" element={<div />} />
170
+ </Routes>
171
+ <LocationProbe />
172
+ {children}
173
+ </>,
174
+ )}
175
+ </LibraryProvider>
176
+ </LibraryToastProvider>
177
+ </WorkspaceContext.Provider>
178
+ </AdminContext.Provider>
179
+ </MemoryRouter>,
180
+ );
181
+ }
182
+
183
+ const href = () => screen.getByLabelText('href').textContent;
184
+
185
+ describe('GroupPage', () => {
186
+ beforeEach(() => {
187
+ dataMock.useLibraryData.mockReturnValue(CATALOG);
188
+ groupsMock.listGroups.mockResolvedValue([gtm()]);
189
+ groupsMock.listJoinRequests.mockResolvedValue([]);
190
+ groupsMock.reconcileJoinRequest.mockResolvedValue(false);
191
+ groupsMock.requestGroupAccess.mockResolvedValue(undefined);
192
+ });
193
+
194
+ it('lets a group MANAGER remove a skill, behind a confirm that says who loses it', async () => {
195
+ groupsMock.listGroups.mockResolvedValue([gtm({ canWrite: true })]);
196
+ libApiMock.removeLibraryItem.mockResolvedValue(undefined);
197
+ renderGroup('GTM');
198
+
199
+ fireEvent.click(await screen.findByRole('button', { name: 'Remove outreach' }));
200
+ expect(await screen.findByText(/Everyone here loses it/)).toBeInTheDocument();
201
+ fireEvent.click(screen.getByRole('button', { name: 'Remove' }));
202
+
203
+ // The skill FOLDER, repo-relative — the recursive delete under it runs
204
+ // per-file through the same ACL gate that governs editing the group.
205
+ await waitFor(() =>
206
+ expect(libApiMock.removeLibraryItem).toHaveBeenCalledWith('Groups/GTM/outreach'),
207
+ );
208
+ expect(await screen.findByText(/Removed outreach from GTM/)).toBeInTheDocument();
209
+ });
210
+
211
+ it('offers no remove affordance to a non-manager', async () => {
212
+ renderGroup('GTM'); // gtm() defaults to canWrite: false
213
+ await screen.findByText('outreach');
214
+ expect(screen.queryByRole('button', { name: 'Remove outreach' })).toBeNull();
215
+ });
216
+
217
+ it("shows only the group's own skills and tools", async () => {
218
+ renderGroup('GTM');
219
+ expect(await screen.findByRole('heading', { name: 'GTM', level: 1 })).toBeInTheDocument();
220
+ expect(screen.getByTestId('library-card-skill-outreach')).toBeInTheDocument();
221
+ expect(screen.getByTestId('library-card-integration-heyreach')).toBeInTheDocument();
222
+ // Product's skill belongs to another group and never appears here.
223
+ expect(screen.queryByTestId('library-card-skill-roadmap')).not.toBeInTheDocument();
224
+ expect(screen.getByRole('heading', { name: 'Skills' })).toBeInTheDocument();
225
+ expect(screen.getByRole('heading', { name: 'Tools' })).toBeInTheDocument();
226
+ });
227
+
228
+ it('leads with the group, not with who runs it', async () => {
229
+ renderGroup('GTM');
230
+ expect(await screen.findByRole('heading', { name: 'GTM', level: 1 })).toBeInTheDocument();
231
+ // The run-by/shared-with lede is gone: it restated, above every group, what
232
+ // the Share panel says once and on demand.
233
+ expect(screen.queryByText(/^Run by /)).not.toBeInTheDocument();
234
+ expect(screen.queryByText(/shared with/)).not.toBeInTheDocument();
235
+ });
236
+
237
+ // ONE door, for every role. The page used to fork on `canWrite` into "Add
238
+ // skills or tools" (a dialog) and "Propose a skill or tool" (a whole other
239
+ // page) — the same button, in the same spot, opening a different flow with
240
+ // different words depending on who pressed it. Who reviews what is a property
241
+ // of the group, not of the door.
242
+ it('opens the same add dialog for a writer', async () => {
243
+ groupsMock.listGroups.mockResolvedValue([gtm({ canWrite: true })]);
244
+ renderGroup('GTM');
245
+ fireEvent.click(await screen.findByRole('button', { name: 'Add a skill or tool to GTM' }));
246
+ expect(
247
+ await screen.findByRole('heading', { name: 'Add a skill or tool to GTM' }),
248
+ ).toBeInTheDocument();
249
+ expect(screen.getByText(/No review step/)).toBeInTheDocument();
250
+ expect(screen.queryByText('Start an empty SKILL.md')).not.toBeInTheDocument();
251
+ });
252
+
253
+ it('opens the same add dialog for everyone else, and says review is coming', async () => {
254
+ renderGroup('GTM');
255
+ fireEvent.click(await screen.findByRole('button', { name: 'Add a skill or tool to GTM' }));
256
+ expect(
257
+ await screen.findByRole('heading', { name: 'Add a skill or tool to GTM' }),
258
+ ).toBeInTheDocument();
259
+ expect(screen.getByText(/change request for an owner to review/)).toBeInTheDocument();
260
+ expect(screen.queryByText('Start an empty SKILL.md')).not.toBeInTheDocument();
261
+ });
262
+
263
+ it('offers no separate propose door to anybody', async () => {
264
+ renderGroup('GTM');
265
+ await screen.findByRole('button', { name: 'Add a skill or tool to GTM' });
266
+ expect(screen.queryByRole('button', { name: /Propose/i })).not.toBeInTheDocument();
267
+ });
268
+
269
+ it('warns about integrations that need setup and sends them to Connect', async () => {
270
+ dataMock.useLibraryData.mockReturnValue({
271
+ ...CATALOG,
272
+ tools: [connectedTool(), unsetTool()],
273
+ });
274
+ renderGroup('GTM');
275
+ expect(
276
+ await screen.findByText(
277
+ "1 integration needs setup: connect it to unblock this group's skills.",
278
+ ),
279
+ ).toBeInTheDocument();
280
+ fireEvent.click(screen.getByRole('button', { name: 'Finish setup' }));
281
+ await waitFor(() => expect(href()).toBe('/connect'));
282
+ });
283
+
284
+ it('pluralises the attention banner', async () => {
285
+ dataMock.useLibraryData.mockReturnValue({
286
+ ...CATALOG,
287
+ tools: [unsetTool(), unsetTool({ slug: 'clay', name: 'clay', path: 'Groups/GTM/clay.tool' })],
288
+ });
289
+ renderGroup('GTM');
290
+ expect(
291
+ await screen.findByText(
292
+ "2 integrations need setup: connect them to unblock this group's skills.",
293
+ ),
294
+ ).toBeInTheDocument();
295
+ });
296
+
297
+ it('renders both empty states for a group with nothing in it', async () => {
298
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
299
+ groupsMock.listGroups.mockResolvedValue([gtm({ skillCount: 0, toolCount: 0 })]);
300
+ renderGroup('GTM');
301
+ expect(
302
+ await screen.findByText('No skills yet. Add one, or ask your agent to write one for GTM.'),
303
+ ).toBeInTheDocument();
304
+ expect(screen.getByText('No tools yet.')).toBeInTheDocument();
305
+ });
306
+
307
+ it('keeps Share on an EMPTY group. The folder is what carries access, not the items', async () => {
308
+ // Groups used to be derived from their items, which meant a group with
309
+ // nothing in it had no folder to manage and silently lost its access
310
+ // surface. `folders` now comes from the backend's readdir, so an empty
311
+ // group is still a place whose sharing can be changed.
312
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
313
+ groupsMock.listGroups.mockResolvedValue([gtm({ skillCount: 0, toolCount: 0 })]);
314
+ renderGroup('GTM');
315
+
316
+ fireEvent.click(await screen.findByRole('button', { name: 'Share' }));
317
+ expect(
318
+ await screen.findByRole('dialog', {
319
+ name: 'Manage access directory knowledge-base/Groups/GTM',
320
+ }),
321
+ ).toBeInTheDocument();
322
+ });
323
+
324
+ it('Share IS the manage-access dialog, opened on this group\'s directory', async () => {
325
+ renderGroup('GTM');
326
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
327
+
328
+ fireEvent.click(await screen.findByRole('button', { name: 'Share' }));
329
+ // One dialog for every access path — no intermediate read-only panel.
330
+ // The entry is the group DIRECTORY under the KB dir, so the rules land on
331
+ // the folder, never on one file inside it.
332
+ expect(
333
+ await screen.findByRole('dialog', {
334
+ name: 'Manage access directory knowledge-base/Groups/GTM',
335
+ }),
336
+ ).toBeInTheDocument();
337
+ });
338
+
339
+ it('an UNDISCOVERABLE group renders exactly like one that does not exist', async () => {
340
+ // Fail-closed: the endpoint omits groups with no verdict at all, so the
341
+ // page cannot tell "hidden from you" apart from "absent" — the point.
342
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
343
+ groupsMock.listGroups.mockResolvedValue([]);
344
+ renderGroup('Finance');
345
+ expect(await screen.findByText("This group doesn't exist yet.")).toBeInTheDocument();
346
+ });
347
+
348
+ it('a DISCOVERABLE group the caller cannot read shows the locked view', async () => {
349
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
350
+ groupsMock.listGroups.mockResolvedValue([
351
+ gtm({ name: 'Finance', folders: ['Groups/Finance'], canRead: false }),
352
+ ]);
353
+ renderGroup('Finance');
354
+ expect(
355
+ await screen.findByRole('button', { name: 'Subscribe to its skills and tools' }),
356
+ ).toBeInTheDocument();
357
+ expect(screen.queryByRole('heading', { name: 'Skills' })).not.toBeInTheDocument();
358
+ // A locked group offers no way in at all — not an add door, not a propose one.
359
+ expect(screen.queryByRole('button', { name: /Add a skill or tool/ })).not.toBeInTheDocument();
360
+ });
361
+
362
+ it('a locked-out admin (canWrite via admin-rescue) gets the locked view with Manage access', async () => {
363
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
364
+ groupsMock.listGroups.mockResolvedValue([
365
+ gtm({ name: 'Finance', folders: ['Groups/Finance'], canRead: false, canWrite: true }),
366
+ ]);
367
+ renderGroup('Finance');
368
+ expect(await screen.findByRole('button', { name: 'Manage access' })).toBeInTheDocument();
369
+ });
370
+
371
+ it('keeps the member view when an item-level grant beats the folder verdict', async () => {
372
+ // Closeness-first resolution hands this caller one skill inside a folder
373
+ // they cannot read; the group itself is absent from the (fail-closed)
374
+ // summaries. The platform already returned the item; the page shows it.
375
+ dataMock.useLibraryData.mockReturnValue({
376
+ ...CATALOG,
377
+ skills: [{ name: 'budget', description: '', path: 'Groups/Finance/budget' }],
378
+ tools: [],
379
+ });
380
+ groupsMock.listGroups.mockResolvedValue([]);
381
+ renderGroup('Finance');
382
+ expect(await screen.findByTestId('library-card-skill-budget')).toBeInTheDocument();
383
+ });
384
+
385
+ it('says so when the group does not exist', async () => {
386
+ renderGroup('Nope');
387
+ expect(await screen.findByText("This group doesn't exist yet.")).toBeInTheDocument();
388
+ expect(screen.getByRole('link', { name: 'All groups' })).toHaveAttribute(
389
+ 'href',
390
+ '/skills-and-tools',
391
+ );
392
+ });
393
+
394
+ it('degrades to the catalog when the groups endpoint fails', async () => {
395
+ groupsMock.listGroups.mockRejectedValue(new Error("Couldn't load groups."));
396
+ renderGroup('GTM');
397
+ expect(await screen.findByTestId('library-card-skill-outreach')).toBeInTheDocument();
398
+ // No verified principals, so no claim about them. The add door still opens
399
+ // — it writes nothing, so there is no permission to be wrong about.
400
+ expect(screen.queryByText(/^Run by/)).not.toBeInTheDocument();
401
+ expect(screen.getByRole('button', { name: 'Add a skill or tool to GTM' })).toBeInTheDocument();
402
+ });
403
+
404
+ it('does not claim a missing group is gone while the endpoint is still failing', async () => {
405
+ groupsMock.listGroups.mockRejectedValue(new Error("Couldn't load groups."));
406
+ renderGroup('Finance');
407
+ await waitFor(() =>
408
+ expect(screen.queryByText('Loading the library…')).not.toBeInTheDocument(),
409
+ );
410
+ expect(screen.queryByText("This group doesn't exist yet.")).not.toBeInTheDocument();
411
+ expect(screen.getByRole('heading', { name: 'Finance', level: 1 })).toBeInTheDocument();
412
+ });
413
+
414
+ it('decodes a URL-hostile group name', async () => {
415
+ dataMock.useLibraryData.mockReturnValue({
416
+ ...CATALOG,
417
+ skills: [{ name: 'pricing', description: '', path: 'Groups/Sales & Ops/pricing' }],
418
+ tools: [],
419
+ });
420
+ renderGroup('Sales & Ops');
421
+ expect(
422
+ await screen.findByRole('heading', { name: 'Sales & Ops', level: 1 }),
423
+ ).toBeInTheDocument();
424
+ expect(screen.getByTestId('library-card-skill-pricing')).toBeInTheDocument();
425
+ });
426
+
427
+ it('waits rather than guessing while the catalog is still loading', () => {
428
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
429
+ renderGroup('GTM');
430
+ expect(screen.getByText('Loading the library…')).toBeInTheDocument();
431
+ expect(screen.queryByText("This group doesn't exist yet.")).not.toBeInTheDocument();
432
+ });
433
+
434
+ /**
435
+ * "Last updated just now" is a CLAIM, and the page has to be able to back it.
436
+ * Both refetches behind the button return `void`, so the only honest end of
437
+ * the spin is the loads settling — which is what these two pin. The spinner
438
+ * is read off `animate-spin` because that class is the only thing in the DOM
439
+ * that distinguishes "checking" from "idle": both states render the same
440
+ * button with the same name.
441
+ */
442
+ describe('checking for updates', () => {
443
+ const refreshButton = () => screen.getByRole('button', { name: 'Check for updates' });
444
+ const spinning = () => refreshButton().querySelector('.animate-spin') !== null;
445
+
446
+ it('claims freshness only once the refetch has actually landed', async () => {
447
+ renderGroup('GTM');
448
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
449
+
450
+ let land!: (groups: GroupSummary[]) => void;
451
+ groupsMock.listGroups.mockReturnValueOnce(
452
+ new Promise<GroupSummary[]>((resolve) => {
453
+ land = resolve;
454
+ }),
455
+ );
456
+
457
+ fireEvent.click(refreshButton());
458
+ await waitFor(() => expect(spinning()).toBe(true));
459
+ // Still in flight — the page says nothing about being up to date.
460
+ expect(screen.queryByText('Last updated just now')).not.toBeInTheDocument();
461
+
462
+ await act(async () => {
463
+ land([gtm()]);
464
+ });
465
+ expect(await screen.findByText('Last updated just now')).toBeInTheDocument();
466
+ });
467
+
468
+ it('does not report success when the refetch fails', async () => {
469
+ renderGroup('GTM');
470
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
471
+
472
+ groupsMock.listGroups.mockRejectedValueOnce(new Error("Couldn't load groups."));
473
+ fireEvent.click(refreshButton());
474
+
475
+ await waitFor(() => expect(spinning()).toBe(false));
476
+ expect(screen.queryByText('Last updated just now')).not.toBeInTheDocument();
477
+ });
478
+ });
479
+ });