@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,135 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { Outlet, useLocation } from 'react-router-dom';
3
+ import { AdminContext } from '../../admin/state/admin.context';
4
+ import type { AdminMenuItem } from '../../../core/registry';
5
+ import { SidebarFrame } from '../../layout/components/SidebarFrame';
6
+ import { useMediaQuery } from '../../layout/hooks/useMediaQuery';
7
+ import {
8
+ isSettingsNavPath,
9
+ normalizeSettingsPath,
10
+ useMenuSections,
11
+ } from '../settings-nav-items';
12
+ import { SettingsNav, type LinkableItem } from './SettingsNav';
13
+
14
+ /**
15
+ * The settings surfaces, wrapped in the nav that reaches them.
16
+ *
17
+ * The settings pages used to be reachable ONLY from the profile dropdown,
18
+ * which closes on the way out — so getting from Secrets to Account meant
19
+ * finding a 22px avatar in the far corner and re-summoning a list. The list
20
+ * looked like a nav and behaved like a menu. This makes it a nav: mounted by
21
+ * the route table, so it is a property of being a settings page rather than
22
+ * something each page has to remember to render.
23
+ *
24
+ * It fills the app's ONE `SidebarFrame` — the third renderer of it, after
25
+ * Knowledge's file tree and Skills & Tools' group list. `sidebar.ts` already
26
+ * states the claim this relies on: there is one nav, in one place, holding a
27
+ * different list depending on where you are.
28
+ *
29
+ * Three things here are load-bearing and easy to undo by accident:
30
+ *
31
+ * 1. NO `key={pathname}` anywhere. React Router keeps a layout element
32
+ * mounted across sibling child-route changes, and that is exactly what
33
+ * makes the nav persistent — the collapse state survives `/secrets` →
34
+ * `/account`, focus survives the click, and the child page mounts fresh
35
+ * without the layout blinking. A key here would remount all of it and
36
+ * reintroduce the bug in a subtler form.
37
+ *
38
+ * 2. `useContext(AdminContext)` directly, never `useAdmin()`. That hook
39
+ * throws outside `AdminProvider`, and the shell's route tests render
40
+ * `ShellRoutes` with no providers at all. Reading the context is honest
41
+ * rather than a dodge: this nav is WAYFINDING, not the security boundary
42
+ * — the backend gates every roles/accounts endpoint and each admin page
43
+ * renders its own "Admins only" notice — and no-context reading as "not
44
+ * an admin" is precisely `AdminProvider`'s own starting state.
45
+ *
46
+ * 3. `<main>` is NOT the scroller, which is the one deliberate departure
47
+ * from `LibraryLayout`. All six pages below already own a full-height
48
+ * scrolling container (`PageShell` is `h-full overflow-y-auto`), so
49
+ * scrolling here too would nest two scrollers and float the scrollbar
50
+ * off the page's own edge.
51
+ */
52
+ /**
53
+ * A row can be shown only if it declares where it goes AND that destination is
54
+ * one of the routes this layout wraps.
55
+ *
56
+ * The first half excludes dialog rows — a dialog has no URL, so it can be
57
+ * neither linked to nor marked current. The second excludes a registry row
58
+ * pointing somewhere else in the app: a settings nav that could navigate you
59
+ * into Knowledge would be a nav that replaces itself mid-click. Neither kind
60
+ * is lost; both keep working in the dropdown, which is the surface that can
61
+ * run arbitrary actions.
62
+ *
63
+ * Module scope, not a closure inside the component: it captures nothing, and
64
+ * as a closure it was a dependency the memos below had to either list (and
65
+ * rebuild on every render) or lie about.
66
+ *
67
+ * The surviving rows come out NORMALIZED, so both halves of the current-row
68
+ * comparison are spelled the same way — the pathname is normalized on its way
69
+ * in, and a registry row that happened to declare `/secrets/` would otherwise
70
+ * render a link that never matches the page it is on.
71
+ */
72
+ function linkable(items: AdminMenuItem[]): LinkableItem[] {
73
+ return items
74
+ .filter((item): item is LinkableItem => !!item.path && isSettingsNavPath(item.path))
75
+ .map((item) => ({ ...item, path: normalizeSettingsPath(item.path) }));
76
+ }
77
+
78
+ export function SettingsLayout() {
79
+ // Normalized, because the row paths are — see `normalizeSettingsPath`. The
80
+ // page renders at `/secrets/` either way; without this its row is the only
81
+ // one in the nav that is never marked current.
82
+ const currentPath = normalizeSettingsPath(useLocation().pathname);
83
+ // Not `useAdmin()` — see (2) above.
84
+ const isAdmin = useContext(AdminContext)?.isAdmin ?? false;
85
+ const { defaultItems, adminItems } = useMenuSections();
86
+ /* Below `md` the sidebar frame is not mounted AT ALL and the rows become a
87
+ horizontal strip. A 212px rail on a 375px screen is most of the screen. */
88
+ const isCompact = useMediaQuery('(max-width: 767px)');
89
+
90
+ const navDefault = useMemo(() => linkable(defaultItems), [defaultItems]);
91
+ const navAdmin = useMemo(
92
+ () => (isAdmin ? linkable(adminItems) : []),
93
+ [adminItems, isAdmin],
94
+ );
95
+
96
+ if (isCompact) {
97
+ return (
98
+ <div className="flex h-full min-h-0 flex-col bg-canvas text-ink">
99
+ {/* Horizontal-only scroll, the same idiom (and the same reasons) as
100
+ the toolbar's compact item cluster: `overflow-y-hidden` stops a
101
+ tall row growing a vertical scrollbar, and `pan-x` stops touch
102
+ browsers claiming a downward swipe that started on the strip. */}
103
+ <div
104
+ className="shrink-0 border-b border-line bg-sidebar px-3 py-2 overflow-x-auto overflow-y-hidden"
105
+ style={{ touchAction: 'pan-x' }}
106
+ >
107
+ <SettingsNav
108
+ defaultItems={navDefault}
109
+ adminItems={navAdmin}
110
+ currentPath={currentPath}
111
+ orientation="strip"
112
+ />
113
+ </div>
114
+ <main className="min-h-0 flex-1">
115
+ <Outlet />
116
+ </main>
117
+ </div>
118
+ );
119
+ }
120
+
121
+ return (
122
+ <div className="flex h-full min-h-0 bg-canvas text-ink">
123
+ <SidebarFrame label="Settings">
124
+ <SettingsNav
125
+ defaultItems={navDefault}
126
+ adminItems={navAdmin}
127
+ currentPath={currentPath}
128
+ />
129
+ </SidebarFrame>
130
+ <main className="min-w-0 flex-1">
131
+ <Outlet />
132
+ </main>
133
+ </div>
134
+ );
135
+ }
@@ -0,0 +1,114 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import type { AdminMenuItem } from '../../../core/registry';
4
+ import { cn } from '../../../lib/utils';
5
+
6
+ /** A row the nav can render: one that declares where it goes. */
7
+ export type LinkableItem = AdminMenuItem & { path: string };
8
+
9
+ /**
10
+ * `rail` is the sidebar column; `strip` is the horizontal row it becomes below
11
+ * the `md` breakpoint. The rows are identical in both — only the axis and the
12
+ * section label change, because a label that introduces a group beneath it is
13
+ * a vertical-list device and reads as noise inline.
14
+ */
15
+ export type SettingsNavOrientation = 'rail' | 'strip';
16
+
17
+ /**
18
+ * The settings nav's CONTENTS — a pure view of the URL, in the same sense
19
+ * `GroupsSidebar` is. It holds no state, decides no membership and fetches
20
+ * nothing; the layout works out which rows exist and which one is current,
21
+ * and this renders them.
22
+ *
23
+ * Row styling is `GroupsSidebar`'s declaration token for token, minus the
24
+ * count slot it has no use for, plus `FileExplorer`'s inset focus ring — the
25
+ * more complete of the two treatments. The two sidebars must not read as two
26
+ * products, and the class string is what that rule actually protects.
27
+ *
28
+ * Two things here differ from both existing sidebars, deliberately, and
29
+ * neither is a style choice:
30
+ *
31
+ * - `<Link>`, not `<button onClick>`. Every row here HAS a URL (that is the
32
+ * membership rule), so cmd-click, middle-click and copy-link-address all
33
+ * work — which matters more for settings than for anything else in the app.
34
+ * The existing sidebars use buttons because their destinations are filter
35
+ * states and tree nodes reached by callback, not because buttons are the
36
+ * house style for navigation.
37
+ * - `aria-current="page"`, not `aria-current={boolean}` (which serialises to
38
+ * `"true"`). These rows go to pages, and `"page"` is the token for that.
39
+ *
40
+ * No icons, also deliberately: neither existing sidebar shows any, and
41
+ * `AdminMenuItem.icon` is optional — so an icon column would be ragged the
42
+ * moment the enterprise shell contributes a row without one. The icons stay in
43
+ * the dropdown, where a short vertical scan benefits from them.
44
+ */
45
+ export function SettingsNav({
46
+ defaultItems,
47
+ adminItems,
48
+ currentPath,
49
+ orientation = 'rail',
50
+ }: {
51
+ defaultItems: LinkableItem[];
52
+ adminItems: LinkableItem[];
53
+ currentPath: string;
54
+ orientation?: SettingsNavOrientation;
55
+ }) {
56
+ const strip = orientation === 'strip';
57
+
58
+ const row = (item: LinkableItem) => {
59
+ const current = item.path === currentPath;
60
+ return (
61
+ <Link
62
+ key={item.id}
63
+ to={item.path}
64
+ aria-current={current ? 'page' : undefined}
65
+ className={cn(
66
+ 'flex items-center gap-2 rounded-sm px-2.5 py-1.5 text-ui transition-colors',
67
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent',
68
+ // Inline, a row must not shrink to an ellipsis just because the next
69
+ // one wants room — the strip scrolls instead.
70
+ strip && 'shrink-0',
71
+ current
72
+ ? 'bg-hover font-semibold text-ink'
73
+ : 'text-ink-muted hover:bg-hover hover:text-ink',
74
+ )}
75
+ >
76
+ <span className="truncate">{item.label}</span>
77
+ </Link>
78
+ );
79
+ };
80
+
81
+ return (
82
+ <nav
83
+ aria-label="Settings"
84
+ className={cn(
85
+ 'flex min-h-0',
86
+ strip ? 'flex-row items-center gap-1' : 'flex-col overflow-y-auto',
87
+ )}
88
+ >
89
+ {defaultItems.map(row)}
90
+ {adminItems.length > 0 && (
91
+ <>
92
+ {/* Inline, the rows simply continue — see the orientation docblock. */}
93
+ {!strip && <SectionLabel spaced>Admin only</SectionLabel>}
94
+ {adminItems.map(row)}
95
+ </>
96
+ )}
97
+ </nav>
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Copied from `GroupsSidebar`'s `SectionLabel` rather than extracted into a
103
+ * shared component — the same call `FileExplorer` made about its own row
104
+ * class. Three sidebars agreeing on a label's padding is not yet an
105
+ * abstraction, and hoisting it would put a shared dependency between two
106
+ * modules that otherwise know nothing about each other.
107
+ */
108
+ function SectionLabel({ children, spaced = false }: { children: ReactNode; spaced?: boolean }) {
109
+ return (
110
+ <div className={cn('px-2.5 pb-1.5 text-label uppercase text-ink-faint', spaced && 'pt-5')}>
111
+ {children}
112
+ </div>
113
+ );
114
+ }
@@ -0,0 +1,110 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
4
+
5
+ /**
6
+ * The deployment settings page — first-run setup with a permanent address.
7
+ * What is worth testing is the door itself: an admin gets the real form (with
8
+ * the same fields the setup gate shows), a non-admin gets told this is not
9
+ * theirs, and a failed status load offers a retry instead of a blank page.
10
+ * The form's own behaviour is covered by the setup suite — same component.
11
+ */
12
+
13
+ const apiMock = vi.hoisted(() => ({ fetchSetupStatus: vi.fn(), saveSettings: vi.fn() }));
14
+ vi.mock('../../../setup/services/setup.api', async (importOriginal) => ({
15
+ ...(await importOriginal<object>()),
16
+ fetchSetupStatus: apiMock.fetchSetupStatus,
17
+ saveSettings: apiMock.saveSettings,
18
+ }));
19
+
20
+ import { DeploymentPage } from '../DeploymentPage';
21
+
22
+ function admin(isAdmin: boolean): AdminContextValue {
23
+ return { isAdmin } as AdminContextValue;
24
+ }
25
+
26
+ /** A settled status: setup is COMPLETE — this page exists for exactly then. */
27
+ const COMPLETE_STATUS = {
28
+ complete: true,
29
+ awaitingRestart: false,
30
+ isAdmin: true,
31
+ settings: [
32
+ { key: 'kbRepoUrl', section: 'knowledge-base', source: 'saved', value: 'https://git.example.com/kb.git' },
33
+ { key: 'oidcIssuerUrl', section: 'sign-in', source: 'saved', value: '' },
34
+ { key: 'oidcClientId', section: 'sign-in', source: 'saved', value: '' },
35
+ { key: 'oidcClientSecret', section: 'sign-in', source: 'saved', value: '' },
36
+ ],
37
+ };
38
+
39
+ function renderPage(value: AdminContextValue) {
40
+ return render(
41
+ <AdminContext.Provider value={value}>
42
+ <DeploymentPage />
43
+ </AdminContext.Provider>,
44
+ );
45
+ }
46
+
47
+ describe('DeploymentPage', () => {
48
+ beforeEach(() => {
49
+ apiMock.fetchSetupStatus.mockReset();
50
+ apiMock.fetchSetupStatus.mockResolvedValue(COMPLETE_STATUS);
51
+ });
52
+
53
+ it('shows the setup form to an admin — AFTER setup is complete', async () => {
54
+ renderPage(admin(true));
55
+ // The single-sign-on fields are reachable again: the whole point of the page.
56
+ expect(await screen.findByText('Provider address')).toBeInTheDocument();
57
+ // And the same redirect-URI helper the setup screen shows.
58
+ expect(screen.getByText(/api\/auth\/oidc\/callback/)).toBeInTheDocument();
59
+ // Post-setup only: the caution against repointing a LIVE deployment at a
60
+ // different repository (first-run has nothing to lose yet).
61
+ expect(
62
+ screen.getByText(/Only change this if the same repository was moved or renamed/),
63
+ ).toBeInTheDocument();
64
+ });
65
+
66
+ it('tells a non-admin this is not theirs, and never fetches the settings', () => {
67
+ renderPage(admin(false));
68
+ expect(screen.getByText(/Admins only/)).toBeInTheDocument();
69
+ expect(screen.queryByText('Provider address')).toBeNull();
70
+ // Never fetched, not merely never rendered: the page already told them
71
+ // this is not theirs, so a request nothing renders is pure noise.
72
+ expect(apiMock.fetchSetupStatus).not.toHaveBeenCalled();
73
+ });
74
+
75
+ it('a failed refresh after an awaiting-restart save keeps the form AND the notice', async () => {
76
+ // The save landed; only the follow-up status fetch died. The page must
77
+ // not trade the confirmation of what was saved for a load error — the
78
+ // form stays mounted with its restart notice, and the banner above it
79
+ // says "refresh", not "load", with a retry.
80
+ apiMock.saveSettings.mockResolvedValue({
81
+ restartRequired: true,
82
+ complete: false,
83
+ awaitingRestart: true,
84
+ settings: COMPLETE_STATUS.settings,
85
+ });
86
+ renderPage(admin(true));
87
+ await screen.findByText('Provider address');
88
+ apiMock.fetchSetupStatus.mockRejectedValueOnce(new Error('down'));
89
+
90
+ fireEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
91
+
92
+ expect(await screen.findByText(/needs a restart/)).toBeInTheDocument();
93
+ expect(await screen.findByText(/Couldn't refresh the deployment settings/)).toBeInTheDocument();
94
+ // Still the form, not a blank page: the last good settings render on.
95
+ expect(screen.getByText('Provider address')).toBeInTheDocument();
96
+ expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument();
97
+ });
98
+
99
+ it('offers a retry when the status cannot be loaded, and the retry fetches again', async () => {
100
+ apiMock.fetchSetupStatus.mockRejectedValueOnce(new Error('down'));
101
+ renderPage(admin(true));
102
+ expect(await screen.findByText(/Couldn't load the deployment settings/)).toBeInTheDocument();
103
+ expect(apiMock.fetchSetupStatus).toHaveBeenCalledTimes(1);
104
+
105
+ fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
106
+ await waitFor(() => expect(apiMock.fetchSetupStatus).toHaveBeenCalledTimes(2));
107
+ // The second answer (the beforeEach default) is the real settings.
108
+ expect(await screen.findByText('Provider address')).toBeInTheDocument();
109
+ });
110
+ });
@@ -0,0 +1,249 @@
1
+ import type { ReactNode } from 'react';
2
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
3
+ import { render, screen, within } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
6
+ import { SettingsLayout } from '../SettingsLayout';
7
+ import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
8
+ import { SIDEBAR_DOM_ID } from '../../../layout/components/SidebarFrame';
9
+ import { setSidebarCollapsed } from '../../../layout/state/sidebar';
10
+ import { AppRegistryContext, makeRegistry, type AdminMenuItem } from '../../../../core/registry';
11
+
12
+ /**
13
+ * The settings nav's contract.
14
+ *
15
+ * The load-bearing case is "the nav survives the click" — the exact inverse of
16
+ * the profile menu's `panelGone()`, and the regression test for the bug this
17
+ * layout exists to fix.
18
+ *
19
+ * Renders `SettingsLayout` as a real layout route over STUB children, so no
20
+ * real settings page mounts and the suite needs no API mocks and no provider
21
+ * stack beyond the two contexts under test.
22
+ */
23
+
24
+ /**
25
+ * Two shapes the membership rule must REJECT, alongside a normal row: a
26
+ * dialog-only row (no URL, so it can be neither linked nor marked current),
27
+ * and an `onSelect` + off-surface `path` row — the enterprise shape that
28
+ * navigates somewhere else in the app.
29
+ */
30
+ const stubRows: AdminMenuItem[] = [
31
+ {
32
+ id: 'stub-dialog',
33
+ order: 10,
34
+ label: 'Stub dialog row',
35
+ dialog: ({ open }) => (open ? <div role="dialog" aria-label="Stub" /> : <></>),
36
+ },
37
+ {
38
+ id: 'stub-elsewhere',
39
+ order: 20,
40
+ label: 'Stub elsewhere row',
41
+ path: '/workspace/connectors',
42
+ onSelect: () => {},
43
+ },
44
+ ];
45
+
46
+ function LocationProbe() {
47
+ return <div data-testid="pathname">{useLocation().pathname}</div>;
48
+ }
49
+
50
+ /**
51
+ * The router subtree, built ONCE and shared by `renderAt` and the rerender
52
+ * below.
53
+ *
54
+ * React reconciles children by position and type, so a rerender that omits any
55
+ * of this — `LocationProbe`, a sibling route — replaces the subtree instead of
56
+ * updating it, and `SettingsLayout` remounts with the new props already baked
57
+ * in. A remounted component cannot be caught holding stale memoized state,
58
+ * which is the one thing the update test exists to catch. Sharing the builder
59
+ * is what makes "identical except for the AdminContext value" true by
60
+ * construction rather than by everyone remembering.
61
+ */
62
+ function routerTree(route: string) {
63
+ return (
64
+ <AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: stubRows })}>
65
+ <MemoryRouter initialEntries={[route]}>
66
+ <LocationProbe />
67
+ <Routes>
68
+ <Route element={<SettingsLayout />}>
69
+ <Route path="/secrets" element={<div>Secrets stub</div>} />
70
+ <Route path="/account" element={<div>Account stub</div>} />
71
+ <Route path="/tools" element={<div>Tools stub</div>} />
72
+ <Route path="/external-agent-access" element={<div>Agent access stub</div>} />
73
+ <Route path="/roles-and-members" element={<div>Roles stub</div>} />
74
+ <Route path="/user-accounts" element={<div>User accounts stub</div>} />
75
+ </Route>
76
+ </Routes>
77
+ </MemoryRouter>
78
+ </AppRegistryContext.Provider>
79
+ );
80
+ }
81
+
82
+ function withAdmin(isAdmin: boolean, tree: ReactNode) {
83
+ return (
84
+ <AdminContext.Provider value={{ isAdmin } as AdminContextValue}>{tree}</AdminContext.Provider>
85
+ );
86
+ }
87
+
88
+ function renderAt(
89
+ route: string,
90
+ { isAdmin, withAdminContext = true }: { isAdmin?: boolean; withAdminContext?: boolean } = {},
91
+ ) {
92
+ const tree = routerTree(route);
93
+ if (!withAdminContext) return render(tree);
94
+ return render(withAdmin(!!isAdmin, tree));
95
+ }
96
+
97
+ const nav = () => screen.getByRole('navigation', { name: 'Settings' });
98
+ const noNav = () => screen.queryByRole('navigation', { name: 'Settings' });
99
+
100
+ /**
101
+ * `collapsed` is module state that `test-setup.ts` does not reset, and
102
+ * Toolbar.test.tsx mutates it — so it leaks across files in a run. A collapsed
103
+ * sidebar is `inert`, which would make every query here fail for a reason that
104
+ * has nothing to do with this suite.
105
+ */
106
+ beforeEach(() => setSidebarCollapsed(false));
107
+
108
+ describe('SettingsLayout', () => {
109
+ it('lists every settings destination', () => {
110
+ renderAt('/secrets');
111
+ const links = within(nav()).getAllByRole('link');
112
+ expect(links.map((l) => l.textContent)).toEqual([
113
+ 'External agent access',
114
+ 'Secrets',
115
+ 'Browse available tools',
116
+ 'Account',
117
+ ]);
118
+ });
119
+
120
+ it('marks the current destination, and only it', () => {
121
+ renderAt('/secrets');
122
+ expect(within(nav()).getByRole('link', { name: 'Secrets' })).toHaveAttribute(
123
+ 'aria-current',
124
+ 'page',
125
+ );
126
+ expect(within(nav()).getByRole('link', { name: 'Account' })).not.toHaveAttribute(
127
+ 'aria-current',
128
+ );
129
+ expect(
130
+ within(nav())
131
+ .getAllByRole('link')
132
+ .filter((l) => l.getAttribute('aria-current') === 'page'),
133
+ ).toHaveLength(1);
134
+ });
135
+
136
+ // THE REGRESSION TEST. The reported bug was that picking a destination made
137
+ // the list of destinations disappear.
138
+ it('keeps the nav on screen after navigating, and moves the current marker', async () => {
139
+ renderAt('/secrets');
140
+ await userEvent.click(within(nav()).getByRole('link', { name: 'Account' }));
141
+
142
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/account');
143
+ expect(nav()).toBeInTheDocument();
144
+ expect(within(nav()).getByRole('link', { name: 'Account' })).toHaveAttribute(
145
+ 'aria-current',
146
+ 'page',
147
+ );
148
+ });
149
+
150
+ // React Router matches `/secrets/` to the route declared `/secrets`, so the
151
+ // page renders — but `useLocation().pathname` keeps the slash. Comparing it
152
+ // raw against the row paths marked NOTHING as current, on a page that is
153
+ // plainly one of the six.
154
+ it('marks the current destination when the URL carries a trailing slash', () => {
155
+ renderAt('/secrets/');
156
+ expect(within(nav()).getByRole('link', { name: 'Secrets' })).toHaveAttribute(
157
+ 'aria-current',
158
+ 'page',
159
+ );
160
+ });
161
+
162
+ it('excludes a registry row that only opens a dialog', () => {
163
+ renderAt('/secrets');
164
+ expect(within(nav()).queryByRole('link', { name: 'Stub dialog row' })).toBeNull();
165
+ });
166
+
167
+ // A settings nav that could navigate you into Knowledge would be a nav that
168
+ // replaces itself mid-click.
169
+ it('excludes a registry row pointing outside the settings surface', () => {
170
+ renderAt('/secrets');
171
+ expect(within(nav()).queryByRole('link', { name: 'Stub elsewhere row' })).toBeNull();
172
+ });
173
+
174
+ // This is what keeps ShellRoutes.test.tsx free of providers: the layout
175
+ // reads AdminContext directly rather than through useAdmin(), which throws.
176
+ it('renders with no AdminContext at all, as a non-admin', () => {
177
+ expect(() => renderAt('/secrets', { withAdminContext: false })).not.toThrow();
178
+ expect(within(nav()).queryByText('Admin only')).toBeNull();
179
+ expect(within(nav()).queryByRole('link', { name: 'Roles & Members' })).toBeNull();
180
+ });
181
+
182
+ it('hides the admin section from a non-admin', () => {
183
+ renderAt('/secrets', { isAdmin: false });
184
+ expect(within(nav()).queryByText('Admin only')).toBeNull();
185
+ expect(within(nav()).queryByRole('link', { name: 'Roles & Members' })).toBeNull();
186
+ expect(within(nav()).queryByRole('link', { name: 'User accounts' })).toBeNull();
187
+ });
188
+
189
+ it('shows the admin section to an admin', () => {
190
+ renderAt('/secrets', { isAdmin: true });
191
+ expect(within(nav()).getByText('Admin only')).toBeInTheDocument();
192
+ expect(within(nav()).getByRole('link', { name: 'Roles & Members' })).toBeInTheDocument();
193
+ expect(within(nav()).getByRole('link', { name: 'User accounts' })).toBeInTheDocument();
194
+ });
195
+
196
+ // isAdmin resolves asynchronously — the nav must not have baked in the
197
+ // starting `false`.
198
+ //
199
+ // Rerendered through the SAME `routerTree`, with only the AdminContext value
200
+ // changed, so the layout is UPDATED rather than replaced. The identity check
201
+ // below is what enforces that: a remount would build a new <nav> node, and
202
+ // the assertion after it would then be passing for the wrong reason — a
203
+ // fresh component reading `isAdmin: true` on its first render proves nothing
204
+ // about a memo going stale.
205
+ it('grows the admin section when isAdmin flips true after mount', () => {
206
+ const { rerender } = renderAt('/secrets', { isAdmin: false });
207
+ const navBefore = nav();
208
+ expect(within(navBefore).queryByRole('link', { name: 'Roles & Members' })).toBeNull();
209
+
210
+ rerender(withAdmin(true, routerTree('/secrets')));
211
+
212
+ expect(nav()).toBe(navBefore);
213
+ expect(within(nav()).getByRole('link', { name: 'Roles & Members' })).toBeInTheDocument();
214
+ });
215
+
216
+ describe('narrow windows', () => {
217
+ const stubMatchMedia = (matches: boolean) => {
218
+ vi.stubGlobal(
219
+ 'matchMedia',
220
+ vi.fn().mockImplementation((query: string) => ({
221
+ matches,
222
+ media: query,
223
+ addEventListener: vi.fn(),
224
+ removeEventListener: vi.fn(),
225
+ })),
226
+ );
227
+ };
228
+
229
+ it('fills the app sidebar frame on a wide window', () => {
230
+ stubMatchMedia(false);
231
+ renderAt('/secrets');
232
+ const frame = document.getElementById(SIDEBAR_DOM_ID);
233
+ expect(frame).not.toBeNull();
234
+ expect(frame).toContainElement(nav());
235
+ vi.unstubAllGlobals();
236
+ });
237
+
238
+ // The one-sidebar invariant on phones: a 212px rail on a 375px screen is
239
+ // most of the screen, so the rows become a strip and no frame is mounted.
240
+ it('becomes a strip with no sidebar frame on a narrow window', () => {
241
+ stubMatchMedia(true);
242
+ renderAt('/secrets');
243
+ expect(document.getElementById(SIDEBAR_DOM_ID)).toBeNull();
244
+ expect(noNav()).not.toBeNull();
245
+ expect(within(nav()).getAllByRole('link')).toHaveLength(4);
246
+ vi.unstubAllGlobals();
247
+ });
248
+ });
249
+ });