@bevel-software/platform-core-frontend 0.4.1 → 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 +37 -2
  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 +93 -117
  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 +17 -1
  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 +36 -28
  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 +3 -3
  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 +113 -20
  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 +52 -28
  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 +123 -102
  119. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  120. package/src/modules/library/components/LibraryPage.tsx +111 -227
  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 +33 -245
  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 +108 -25
  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 +147 -110
  185. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  186. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  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 +38 -15
  200. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  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 +413 -189
  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 +700 -294
  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 +7 -4
  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 +8 -5
  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,540 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+
5
+ const api = vi.hoisted(() => ({
6
+ fetchSetupStatus: vi.fn(),
7
+ saveSettings: vi.fn(),
8
+ testConnection: vi.fn(),
9
+ }));
10
+ vi.mock('../services/setup.api', async () => {
11
+ // The error class is real — the screen distinguishes field problems from a
12
+ // general failure by `instanceof`, so a stub would defeat the test.
13
+ const actual = await vi.importActual<typeof import('../services/setup.api')>(
14
+ '../services/setup.api',
15
+ );
16
+ return { ...actual, ...api };
17
+ });
18
+
19
+ import { SetupGate } from '../components/SetupGate';
20
+ import { SetupScreen } from '../components/SetupScreen';
21
+ import { SettingsProblems, type SettingStatus } from '../services/setup.api';
22
+
23
+ const KB = 'knowledge-base' as const;
24
+ const SETTINGS: SettingStatus[] = [
25
+ { key: 'kbRepoUrl', envVar: 'KB_REPO_URL', section: KB, source: 'unset', value: '', configured: false, secret: false, restartToApply: false },
26
+ { key: 'gitToken', envVar: 'GIT_TOKEN', section: KB, source: 'unset', configured: false, secret: true, restartToApply: false },
27
+ { key: 'gitUsername', envVar: 'GIT_USERNAME', section: KB, source: 'unset', value: '', configured: false, secret: false, restartToApply: false },
28
+ { key: 'kbDirName', envVar: 'KB_DIR_NAME', section: KB, source: 'unset', value: '', configured: false, secret: false, restartToApply: true },
29
+ { key: 'defaultBranch', envVar: 'DEFAULT_BRANCH', section: KB, source: 'unset', value: '', configured: false, secret: false, restartToApply: true },
30
+ { key: 'protectedBranches', envVar: 'PROTECTED_BRANCHES', section: KB, source: 'unset', value: '', configured: false, secret: false, restartToApply: true },
31
+ { key: 'oidcClientSecret', envVar: 'OIDC_CLIENT_SECRET', section: 'sign-in', source: 'unset', configured: false, secret: true, restartToApply: true },
32
+ ];
33
+
34
+ /**
35
+ * Completing setup RELOADS rather than re-rendering: the branch model the
36
+ * browser holds was fetched before any of it existed, and every module that
37
+ * reads it took its value then. Stubbed so the assertion is "it reloaded",
38
+ * which is the actual contract.
39
+ */
40
+ let reload: ReturnType<typeof vi.fn>;
41
+
42
+ beforeEach(() => {
43
+ api.fetchSetupStatus.mockReset();
44
+ api.saveSettings.mockReset();
45
+ api.testConnection.mockReset();
46
+ reload = vi.fn();
47
+ Object.defineProperty(window, 'location', {
48
+ configurable: true,
49
+ value: { ...window.location, reload, origin: 'https://example.test' },
50
+ });
51
+ });
52
+
53
+ const APP = <div>The application</div>;
54
+
55
+ describe('SetupGate', () => {
56
+ it('lets a configured deployment straight through', async () => {
57
+ api.fetchSetupStatus.mockResolvedValue({ complete: true, isAdmin: true });
58
+ render(<SetupGate>{APP}</SetupGate>);
59
+ expect(await screen.findByText('The application')).toBeInTheDocument();
60
+ });
61
+
62
+ /**
63
+ * The app behind this gate reads from a workspace that cannot exist yet.
64
+ * Rendering it — even for a moment — shows a broken file tree and a stream of
65
+ * failed requests to the person least able to do anything about it.
66
+ */
67
+ it('shows a non-admin that setup is in progress, not the app', async () => {
68
+ api.fetchSetupStatus.mockResolvedValue({ complete: false, isAdmin: false });
69
+ render(<SetupGate>{APP}</SetupGate>);
70
+ expect(await screen.findByText(/Still being set up/)).toBeInTheDocument();
71
+ expect(screen.queryByText('The application')).toBeNull();
72
+ });
73
+
74
+ it('tells a non-admin nothing about what is missing', async () => {
75
+ api.fetchSetupStatus.mockResolvedValue({ complete: false, isAdmin: false });
76
+ render(<SetupGate>{APP}</SetupGate>);
77
+ await screen.findByText(/Still being set up/);
78
+ expect(document.body.textContent).not.toContain('KB_REPO_URL');
79
+ expect(screen.queryByRole('textbox')).toBeNull();
80
+ });
81
+
82
+ /**
83
+ * The check guards against an unconfigured deployment; it is not an
84
+ * authorisation boundary. Blocking on a transient failure would lock everyone
85
+ * out of a deployment that works.
86
+ */
87
+ it('opens the gate when the status check itself fails', async () => {
88
+ api.fetchSetupStatus.mockRejectedValue(new Error('offline'));
89
+ render(<SetupGate>{APP}</SetupGate>);
90
+ expect(await screen.findByText('The application')).toBeInTheDocument();
91
+ });
92
+
93
+ it('claims nothing until the answer is in', () => {
94
+ api.fetchSetupStatus.mockReturnValue(new Promise(() => {}));
95
+ render(<SetupGate>{APP}</SetupGate>);
96
+ expect(screen.queryByText('The application')).toBeNull();
97
+ expect(screen.getByText('Loading…')).toBeInTheDocument();
98
+ });
99
+ });
100
+
101
+ describe('SetupScreen', () => {
102
+ async function renderScreen(settings: SettingStatus[] = SETTINGS) {
103
+ api.fetchSetupStatus.mockResolvedValue({ complete: false, isAdmin: true, settings });
104
+ render(<SetupGate>{APP}</SetupGate>);
105
+ await screen.findByRole('heading', { name: /Set up this deployment/ });
106
+ }
107
+
108
+ it('saves what was typed and lets the app through once complete', async () => {
109
+ await renderScreen();
110
+ api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: SETTINGS });
111
+ // The second status read is what the gate acts on.
112
+ api.fetchSetupStatus.mockResolvedValue({ complete: true, isAdmin: true });
113
+
114
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://example.com/kb.git');
115
+ await userEvent.type(screen.getByLabelText('Access token'), 'ghp_secret');
116
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
117
+
118
+ await waitFor(() =>
119
+ expect(api.saveSettings).toHaveBeenCalledWith(
120
+ expect.objectContaining({
121
+ kbRepoUrl: 'https://example.com/kb.git',
122
+ gitToken: 'ghp_secret',
123
+ }),
124
+ ),
125
+ );
126
+ await waitFor(() => expect(reload).toHaveBeenCalled());
127
+ });
128
+
129
+ /**
130
+ * The whole reason a form beats an environment variable: it can ask the host
131
+ * whether the answer is right, and say which part was wrong — before anything
132
+ * is saved, rather than in a clone failure minutes later.
133
+ */
134
+ it('reports what the host said about the credentials', async () => {
135
+ await renderScreen();
136
+ api.testConnection.mockResolvedValue({
137
+ ok: false,
138
+ error: 'The host rejected those credentials.',
139
+ });
140
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
141
+ expect(await screen.findByText(/rejected those credentials/)).toBeInTheDocument();
142
+ });
143
+
144
+ /** An empty repository is a supported starting point, not a failure. */
145
+ it('treats an empty repository as a success', async () => {
146
+ await renderScreen();
147
+ api.testConnection.mockResolvedValue({ ok: true, empty: true, branches: [] });
148
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
149
+ expect(await screen.findByText(/repository is empty/)).toBeInTheDocument();
150
+ });
151
+
152
+ it('marks the field the server complained about', async () => {
153
+ await renderScreen();
154
+ api.saveSettings.mockRejectedValue(
155
+ new SettingsProblems({ kbRepoUrl: 'The URL must start with https://' }),
156
+ );
157
+ await userEvent.type(screen.getByLabelText('Repository address'), 'git@example.com:kb.git');
158
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
159
+
160
+ expect(await screen.findByRole('alert')).toHaveTextContent('must start with https://');
161
+ expect(screen.getByLabelText('Repository address')).toHaveAttribute('aria-invalid', 'true');
162
+ });
163
+
164
+ /**
165
+ * A stored secret is never sent back, so there is nothing to prefill. The
166
+ * field says what leaving it blank means instead of looking empty-and-unset.
167
+ */
168
+ it('does not pretend to show a saved token', async () => {
169
+ await renderScreen([
170
+ { ...SETTINGS[1]!, source: 'stored', configured: true },
171
+ ...SETTINGS.filter((s) => s.key !== 'gitToken'),
172
+ ]);
173
+ const token = screen.getByLabelText('Access token');
174
+ expect(token).toHaveValue('');
175
+ expect(token).toHaveAttribute('placeholder', 'Saved. Type to replace');
176
+ });
177
+
178
+ /**
179
+ * A value the environment supplies cannot be overwritten from a browser —
180
+ * the server refuses it, so offering an input would be a lie. The variable is
181
+ * named instead, which is the actionable thing.
182
+ */
183
+ it('does not offer to edit a setting the environment owns', async () => {
184
+ await renderScreen([
185
+ { ...SETTINGS[0]!, source: 'env', value: 'https://env.example/kb.git', configured: true },
186
+ ...SETTINGS.slice(1),
187
+ ]);
188
+ expect(screen.queryByLabelText('Repository address')).toBeNull();
189
+ expect(screen.getByText('KB_REPO_URL')).toBeInTheDocument();
190
+ });
191
+
192
+ /**
193
+ * Branch names must match the repository exactly, and a typo produces a
194
+ * deployment pointing at a branch nobody has. The connection test already
195
+ * knows what is there, so it offers them rather than leaving it to memory.
196
+ */
197
+ it('offers the branches the connection test found', async () => {
198
+ await renderScreen();
199
+ api.testConnection.mockResolvedValue({
200
+ ok: true,
201
+ empty: false,
202
+ branches: ['main', 'release'],
203
+ });
204
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
205
+ await screen.findByText(/Found 2 branches/);
206
+
207
+ const list = screen.getByLabelText('Main branch').getAttribute('list');
208
+ expect(list).toBeTruthy();
209
+ const options = [...document.querySelectorAll(`#${list} option`)].map((o) =>
210
+ o.getAttribute('value'),
211
+ );
212
+ expect(options).toEqual(['main', 'release']);
213
+ });
214
+
215
+ /** Nothing to suggest before a test has run — an empty list is not an answer. */
216
+ it('offers nothing until the remote has been asked', async () => {
217
+ await renderScreen();
218
+ expect(screen.getByLabelText('Main branch')).not.toHaveAttribute('list');
219
+ });
220
+
221
+ /**
222
+ * Neither branch field is valid on its own — the default has to appear in the
223
+ * protected list — so the server checks the pair and the screen marks the
224
+ * field with room to hold the answer.
225
+ */
226
+ it('surfaces the pair problem the server reports', async () => {
227
+ await renderScreen();
228
+ api.saveSettings.mockRejectedValue(
229
+ new SettingsProblems({
230
+ protectedBranches: 'The default branch ("main") must be one of the protected branches (release).',
231
+ }),
232
+ );
233
+ await userEvent.type(screen.getByLabelText('Main branch'), 'main');
234
+ await userEvent.type(screen.getByLabelText('Branches that need approval'), 'release');
235
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
236
+ expect(await screen.findByRole('alert')).toHaveTextContent('must be one of the protected');
237
+ });
238
+
239
+ /** SSO is optional, so the screen shows the one thing the provider needs. */
240
+ it('shows the redirect URI to register with the provider', async () => {
241
+ await renderScreen();
242
+ expect(screen.getByText(`${window.location.origin}/api/auth/oidc/callback`)).toBeInTheDocument();
243
+ });
244
+
245
+ /** A section whose fields all come from the environment is not rendered at all. */
246
+ it('omits a section the environment fully owns', async () => {
247
+ await renderScreen(
248
+ SETTINGS.map((s) =>
249
+ s.section === 'sign-in' ? { ...s, source: 'env' as const, configured: true } : s,
250
+ ),
251
+ );
252
+ expect(screen.queryByRole('heading', { name: 'Single sign-on' })).toBeNull();
253
+ expect(screen.getByRole('heading', { name: 'Knowledge, skills & tools' })).toBeInTheDocument();
254
+ });
255
+
256
+ /**
257
+ * "Token username" is not a username. People read it as their own account,
258
+ * and it is in fact a fixed string each host expects beside a token — so it
259
+ * is answered from the repository address rather than asked for, and lives
260
+ * under Advanced for the self-hosted cases that address cannot settle.
261
+ */
262
+ it('answers the token-username question from the repository address', async () => {
263
+ await renderScreen();
264
+ await userEvent.type(
265
+ screen.getByLabelText('Repository address'),
266
+ 'https://gitlab.com/acme/kb.git',
267
+ );
268
+ expect(screen.getByLabelText('Token username')).toHaveValue('oauth2');
269
+ });
270
+
271
+ it('does not overwrite a token username somebody typed', async () => {
272
+ await renderScreen();
273
+ await userEvent.type(screen.getByLabelText('Token username'), 'custom-user');
274
+ await userEvent.type(
275
+ screen.getByLabelText('Repository address'),
276
+ 'https://github.com/acme/kb.git',
277
+ );
278
+ expect(screen.getByLabelText('Token username')).toHaveValue('custom-user');
279
+ });
280
+
281
+ /** An unrecognised host gets no guess — a wrong credential is worse than none. */
282
+ it('guesses nothing for a self-hosted address', async () => {
283
+ await renderScreen();
284
+ await userEvent.type(
285
+ screen.getByLabelText('Repository address'),
286
+ 'https://git.internal.example/acme/kb.git',
287
+ );
288
+ expect(screen.getByLabelText('Token username')).toHaveValue('');
289
+ });
290
+
291
+ /**
292
+ * The branch names must match the repository exactly. Asking someone to
293
+ * remember them is how a deployment ends up pointing at a branch nobody has,
294
+ * so the repository is asked instead.
295
+ */
296
+ it('fills the version fields from what the repository calls its trunk', async () => {
297
+ await renderScreen();
298
+ api.testConnection.mockResolvedValue({
299
+ ok: true,
300
+ empty: false,
301
+ branches: ['develop', 'trunk'],
302
+ defaultBranch: 'trunk',
303
+ });
304
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
305
+ await waitFor(() => expect(screen.getByLabelText('Main branch')).toHaveValue('trunk'));
306
+ expect(screen.getByLabelText('Branches that need approval')).toHaveValue('trunk');
307
+ });
308
+
309
+ it('leaves version fields somebody already filled in alone', async () => {
310
+ await renderScreen();
311
+ await userEvent.type(screen.getByLabelText('Main branch'), 'release');
312
+ api.testConnection.mockResolvedValue({ ok: true, branches: ['main'], defaultBranch: 'main' });
313
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
314
+ await waitFor(() => expect(api.testConnection).toHaveBeenCalled());
315
+ expect(screen.getByLabelText('Main branch')).toHaveValue('release');
316
+ });
317
+
318
+ /**
319
+ * The branch pair lives under Advanced now, and the server validates it as a
320
+ * pair. A message about it landing inside a closed box is a form that refuses
321
+ * to save and will not say why, so the box opens itself.
322
+ */
323
+ it('opens Advanced when the problem is inside it', async () => {
324
+ await renderScreen();
325
+ const advanced = document.querySelector('details');
326
+ expect(advanced).not.toHaveAttribute('open');
327
+
328
+ api.saveSettings.mockRejectedValue(
329
+ new SettingsProblems({ protectedBranches: 'The default branch must be one of them.' }),
330
+ );
331
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
332
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
333
+
334
+ await waitFor(() => expect(document.querySelector('details')).toHaveAttribute('open'));
335
+ expect(await screen.findByRole('alert')).toHaveTextContent('must be one of them');
336
+ });
337
+
338
+ /**
339
+ * A blank field means "leave it alone", so the server accepts a batch that
340
+ * answers only part of what it needs. The screen then cleared the form and
341
+ * re-rendered — indistinguishable from a save that silently failed, which is
342
+ * exactly what it looked like.
343
+ */
344
+ it('says what is still missing when a save lands but does not finish setup', async () => {
345
+ await renderScreen();
346
+ api.saveSettings.mockResolvedValue({
347
+ restartRequired: false,
348
+ complete: false,
349
+ settings: SETTINGS.map((s) =>
350
+ s.key === 'kbRepoUrl' || s.key === 'gitToken' ? { ...s, configured: true } : s,
351
+ ),
352
+ });
353
+ api.fetchSetupStatus.mockResolvedValue({ complete: false, isAdmin: true, settings: SETTINGS });
354
+
355
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
356
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
357
+
358
+ const notice = await screen.findByRole('status');
359
+ expect(notice).toHaveTextContent(/still needs/);
360
+ expect(notice).toHaveTextContent('Main branch');
361
+ // And the box holding them opens, or the advice points somewhere invisible.
362
+ await waitFor(() => expect(document.querySelector('details')).toHaveAttribute('open'));
363
+ });
364
+
365
+ it('says nothing of the sort when the save does finish setup', async () => {
366
+ await renderScreen();
367
+ api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: SETTINGS });
368
+ api.fetchSetupStatus.mockResolvedValue({ complete: true, isAdmin: true });
369
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
370
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
371
+ await waitFor(() => expect(reload).toHaveBeenCalled());
372
+ });
373
+
374
+ /**
375
+ * Not every host advertises its HEAD, and a blank version field is the one
376
+ * way a save can succeed without finishing setup — so a visible, correctable
377
+ * guess beats leaving it empty.
378
+ */
379
+ it('falls back to a conventional branch when the remote does not name one', async () => {
380
+ await renderScreen();
381
+ api.testConnection.mockResolvedValue({
382
+ ok: true,
383
+ branches: ['develop', 'main', 'release'],
384
+ defaultBranch: null,
385
+ });
386
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
387
+ await waitFor(() => expect(screen.getByLabelText('Main branch')).toHaveValue('main'));
388
+ });
389
+
390
+ it('falls back to the first branch when even that is absent', async () => {
391
+ await renderScreen();
392
+ api.testConnection.mockResolvedValue({
393
+ ok: true,
394
+ branches: ['production', 'staging'],
395
+ defaultBranch: null,
396
+ });
397
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
398
+ await waitFor(() => expect(screen.getByLabelText('Main branch')).toHaveValue('production'));
399
+ });
400
+
401
+ /**
402
+ * The test belongs beside the two fields it proves, not after every section.
403
+ * Pinned by position rather than by eye: it drifted to the end once already,
404
+ * which put "did I type the token right?" below the identity-provider
405
+ * questions and, on a page that now scrolls, below the fold.
406
+ */
407
+ it('keeps the connection test inside the knowledge-base card', async () => {
408
+ await renderScreen();
409
+ const card = screen.getByRole('heading', { name: 'Knowledge, skills & tools' }).closest('section');
410
+ expect(card).not.toBeNull();
411
+ expect(card).toContainElement(screen.getByRole('button', { name: 'Test connection' }));
412
+ // Above Advanced, because testing is what fills Advanced in.
413
+ const details = card!.querySelector('details');
414
+ expect(details).not.toBeNull();
415
+ expect(
416
+ screen
417
+ .getByRole('button', { name: 'Test connection' })
418
+ .compareDocumentPosition(details!) & Node.DOCUMENT_POSITION_FOLLOWING,
419
+ ).toBeTruthy();
420
+ });
421
+
422
+ /**
423
+ * Pressing Save without pressing Test used to be refused over a missing
424
+ * branch name. That is a question with a knowable answer — ask the
425
+ * repository — so it is only worth refusing over when the repository cannot
426
+ * answer either.
427
+ */
428
+ it('works the version out on save rather than refusing over it', async () => {
429
+ await renderScreen();
430
+ api.testConnection.mockResolvedValue({ ok: true, branches: ['main'], defaultBranch: 'main' });
431
+ api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: SETTINGS });
432
+
433
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
434
+ await userEvent.type(screen.getByLabelText('Access token'), 'ghp_x');
435
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
436
+
437
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalled());
438
+ expect(api.saveSettings).toHaveBeenCalledWith(
439
+ expect.objectContaining({ defaultBranch: 'main', protectedBranches: 'main' }),
440
+ );
441
+ });
442
+
443
+ it('settings mode: a COMPLETE save refreshes in place, never reloads the document', async () => {
444
+ // In setup mode a complete save reloads the page (the gate's browser
445
+ // holds no branch model yet). On the Deployment page the app around the
446
+ // form is already running — a save must refetch status, not yank the
447
+ // document out from under the admin. `onSaved` being called at all is
448
+ // the distinguishing observable: the setup path reloads INSTEAD of
449
+ // calling it.
450
+ const onSaved = vi.fn();
451
+ render(<SetupScreen settings={SETTINGS} onSaved={onSaved} variant="settings" />);
452
+ api.saveSettings.mockResolvedValue({
453
+ restartRequired: false,
454
+ complete: true,
455
+ settings: SETTINGS,
456
+ });
457
+
458
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
459
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
460
+
461
+ await waitFor(() => expect(onSaved).toHaveBeenCalled());
462
+ });
463
+
464
+ it('settings mode: an awaiting-restart save refreshes AND keeps the restart notice', async () => {
465
+ const onSaved = vi.fn();
466
+ render(<SetupScreen settings={SETTINGS} onSaved={onSaved} variant="settings" />);
467
+ api.saveSettings.mockResolvedValue({
468
+ restartRequired: true,
469
+ complete: false,
470
+ awaitingRestart: true,
471
+ settings: SETTINGS,
472
+ });
473
+
474
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
475
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
476
+
477
+ await waitFor(() => expect(onSaved).toHaveBeenCalled());
478
+ expect(await screen.findByText(/needs a restart/)).toBeInTheDocument();
479
+ });
480
+
481
+ it('derives the standard branch name on save when the repository is empty', async () => {
482
+ await renderScreen();
483
+ api.testConnection.mockResolvedValue({ ok: true, empty: true, branches: [], defaultBranch: null });
484
+ api.saveSettings.mockResolvedValue({
485
+ restartRequired: false,
486
+ complete: true,
487
+ settings: SETTINGS,
488
+ });
489
+ api.fetchSetupStatus.mockResolvedValue({ complete: true, isAdmin: true, settings: SETTINGS });
490
+
491
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
492
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
493
+
494
+ // An EMPTY repository has no branch to report, but it will be seeded with
495
+ // whatever is configured — so the conventional name is derived and the
496
+ // save FINISHES setup, instead of succeeding into a "still needs Main
497
+ // branch" notice about a value the app could have supplied itself.
498
+ await waitFor(() =>
499
+ expect(api.saveSettings).toHaveBeenCalledWith(
500
+ expect.objectContaining({ defaultBranch: 'main', protectedBranches: 'main' }),
501
+ ),
502
+ );
503
+ });
504
+
505
+ /**
506
+ * The branch model is applied at boot. Saving it now applies it to the
507
+ * running process too, but if that ever fails the gate must stay shut and
508
+ * ask for a restart rather than open onto a server that cannot serve.
509
+ */
510
+ it('asks for a restart instead of claiming a field is missing', async () => {
511
+ await renderScreen();
512
+ api.saveSettings.mockResolvedValue({
513
+ restartRequired: true,
514
+ complete: false,
515
+ awaitingRestart: true,
516
+ settings: SETTINGS,
517
+ });
518
+ await userEvent.type(screen.getByLabelText('Repository address'), 'https://x/y.git');
519
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
520
+
521
+ const notice = await screen.findByRole('status');
522
+ expect(notice).toHaveTextContent(/needs a restart/);
523
+ expect(notice).not.toHaveTextContent(/still needs/);
524
+ });
525
+
526
+ /** Single sign-on is skippable, and the screen has to say so. */
527
+ it('marks the optional section optional', async () => {
528
+ await renderScreen();
529
+ expect(screen.getByText('Optional')).toBeInTheDocument();
530
+ });
531
+
532
+ it('says so when a saved setting needs a restart', async () => {
533
+ await renderScreen();
534
+ api.saveSettings.mockResolvedValue({ restartRequired: true, complete: false, settings: SETTINGS });
535
+ api.fetchSetupStatus.mockResolvedValue({ complete: false, isAdmin: true, settings: SETTINGS });
536
+ await userEvent.type(screen.getByLabelText('Folder name'), 'company-brain');
537
+ await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
538
+ expect(await screen.findByText(/restart it when convenient/)).toBeInTheDocument();
539
+ });
540
+ });
@@ -0,0 +1,67 @@
1
+ import { useCallback, useEffect, useState, type ReactNode } from 'react';
2
+ import { fetchSetupStatus, type SetupStatus } from '../services/setup.api';
3
+ import { SetupScreen } from './SetupScreen';
4
+
5
+ /**
6
+ * Stands between a signed-in session and the application, and only lets it
7
+ * through once the deployment can reach its knowledge base.
8
+ *
9
+ * WHY IT SITS INSIDE THE AUTH GATE. Setup is not public — it is where a
10
+ * repository URL and an access token are entered. It works on an unconfigured
11
+ * deployment because the bootstrap admin (`ADMIN_EMAIL`) is recognised without
12
+ * consulting `roles.yaml`, so the one person who can finish setup can always
13
+ * sign in even though nothing has been cloned yet.
14
+ *
15
+ * WHY NON-ADMINS GET A DIFFERENT SCREEN RATHER THAN THE APP. Every surface
16
+ * behind here reads from a workspace that cannot exist yet; letting someone in
17
+ * would show them a broken file tree and a stream of failed requests. "Still
18
+ * being set up" is both true and useful, and it does not tell them what is
19
+ * missing — that is the admin's business.
20
+ *
21
+ * A FAILED STATUS CHECK OPENS THE GATE. The check is a guard against an
22
+ * unconfigured deployment, not an authorisation boundary: if it cannot be
23
+ * reached, the app behind it is no less usable than it was, and blocking on a
24
+ * transient network failure would lock everyone out of a working deployment.
25
+ */
26
+ export function SetupGate({ children }: { children: ReactNode }) {
27
+ const [status, setStatus] = useState<SetupStatus | null>(null);
28
+ const [checked, setChecked] = useState(false);
29
+
30
+ const refresh = useCallback(() => {
31
+ fetchSetupStatus()
32
+ .then(setStatus)
33
+ .catch(() => setStatus(null))
34
+ .finally(() => setChecked(true));
35
+ }, []);
36
+
37
+ useEffect(refresh, [refresh]);
38
+
39
+ // Nothing is claimed until the answer is in. Rendering the app here and
40
+ // replacing it a moment later would flash a broken workspace at exactly the
41
+ // people this gate exists to protect from one.
42
+ if (!checked) {
43
+ return (
44
+ <div className="flex h-full items-center justify-center bg-surface text-ui text-ink-muted">
45
+ Loading…
46
+ </div>
47
+ );
48
+ }
49
+
50
+ if (!status || status.complete) return <>{children}</>;
51
+
52
+ if (!status.isAdmin || !status.settings) {
53
+ return (
54
+ <div className="flex h-full items-center justify-center bg-sunken px-6">
55
+ <div className="max-w-[46ch] text-center">
56
+ <h1 className="text-title font-semibold text-ink">Still being set up</h1>
57
+ <p className="mt-2 text-body text-ink-muted">
58
+ An admin is connecting this deployment to the place its knowledge, skills and tools
59
+ will live. It will be ready shortly; try again in a few minutes.
60
+ </p>
61
+ </div>
62
+ </div>
63
+ );
64
+ }
65
+
66
+ return <SetupScreen settings={status.settings} onSaved={refresh} />;
67
+ }