@bevel-software/platform-core-frontend 0.4.1 → 0.5.1

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 (327) hide show
  1. package/THIRD-PARTY-NOTICES.md +5366 -0
  2. package/package.json +7 -4
  3. package/src/core/CoreAppShell.tsx +195 -56
  4. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  6. package/src/core/__tests__/bootstrap.test.ts +63 -0
  7. package/src/core/bootstrap.ts +73 -0
  8. package/src/core/events.ts +12 -0
  9. package/src/core/registry.ts +58 -9
  10. package/src/index.css +100 -11
  11. package/src/index.ts +24 -23
  12. package/src/lib/utils.ts +93 -117
  13. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  15. package/src/modules/access/api.ts +49 -0
  16. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  17. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  18. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  19. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  20. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  21. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  23. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  24. package/src/modules/admin/state/admin.context.tsx +15 -6
  25. package/src/modules/auth/components/AccountPage.tsx +11 -11
  26. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  27. package/src/modules/auth/services/sso.ts +47 -1
  28. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  29. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  30. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  31. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  32. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  33. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  34. package/src/modules/change-requests/change-requests.css +22 -0
  35. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  36. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  37. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  38. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  39. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  40. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  41. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  42. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  43. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  44. package/src/modules/change-requests/services/propose.api.ts +162 -0
  45. package/src/modules/change-requests/utils/author.ts +47 -0
  46. package/src/modules/change-requests/utils/conflict.ts +38 -0
  47. package/src/modules/change-requests/utils/diff.ts +80 -0
  48. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  49. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  50. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  51. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  52. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  53. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  54. package/src/modules/git/components/DiffView.tsx +4 -4
  55. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  56. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  57. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  58. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  59. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  60. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  61. package/src/modules/git/hooks/useGitState.ts +15 -14
  62. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  63. package/src/modules/git/services/error-messages.ts +7 -7
  64. package/src/modules/git/services/git.api.ts +17 -11
  65. package/src/modules/git/services/pr-prompts.ts +2 -2
  66. package/src/modules/git/state/git.context.ts +10 -1
  67. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  68. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  69. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  70. package/src/modules/layout/breakpoints.ts +6 -0
  71. package/src/modules/layout/components/AppLayout.tsx +17 -5
  72. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  73. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  74. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  75. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  76. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  77. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  78. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  79. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  80. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  81. package/src/modules/layout/state/sidebar.ts +200 -0
  82. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  83. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  84. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  85. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  86. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  89. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  90. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  91. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  92. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  93. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  94. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  95. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  96. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  97. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  98. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  99. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  100. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  101. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  102. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  103. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  104. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  105. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  106. package/src/modules/library/__tests__/status.test.ts +113 -20
  107. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  108. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  109. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  110. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  111. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  112. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  113. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  114. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  115. package/src/modules/library/components/GroupPage.tsx +373 -0
  116. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  117. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  118. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  119. package/src/modules/library/components/LibraryCard.tsx +123 -102
  120. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  121. package/src/modules/library/components/LibraryPage.tsx +111 -227
  122. package/src/modules/library/components/LockGlyph.tsx +31 -0
  123. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  124. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  125. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  126. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  127. package/src/modules/library/components/PageActions.tsx +156 -0
  128. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  129. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  130. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  131. package/src/modules/library/components/StatusDot.tsx +25 -0
  132. package/src/modules/library/components/ToolLogo.tsx +171 -0
  133. package/src/modules/library/components/group-page-parts.tsx +419 -0
  134. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  135. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  136. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  137. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  138. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  139. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  140. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  141. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  142. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  143. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  144. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  145. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  146. package/src/modules/library/hooks/useToolPage.ts +145 -0
  147. package/src/modules/library/library.css +33 -245
  148. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  149. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  150. package/src/modules/library/routes/library-paths.ts +191 -0
  151. package/src/modules/library/services/groups.api.ts +189 -0
  152. package/src/modules/library/services/library.api.ts +291 -164
  153. package/src/modules/library/services/tools.api.ts +60 -0
  154. package/src/modules/library/state/library-context.ts +22 -0
  155. package/src/modules/library/state/library-data.tsx +223 -0
  156. package/src/modules/library/state/toast.context.ts +32 -0
  157. package/src/modules/library/state/toast.tsx +84 -42
  158. package/src/modules/library/utils/clipboard.ts +33 -0
  159. package/src/modules/library/utils/group-summary.ts +68 -0
  160. package/src/modules/library/utils/names.ts +30 -0
  161. package/src/modules/library/utils/navigate-external.ts +15 -0
  162. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  163. package/src/modules/library/utils/personal-group.ts +36 -0
  164. package/src/modules/library/utils/status.ts +108 -25
  165. package/src/modules/library/utils/toast-duration.ts +16 -0
  166. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  167. package/src/modules/onboarding/agent-clients.ts +48 -0
  168. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  169. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  170. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  171. package/src/modules/onboarding/paths.ts +9 -0
  172. package/src/modules/onboarding/state/onboarding.ts +191 -0
  173. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  174. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  175. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  176. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  177. package/src/modules/review/components/DiffViewer.tsx +4 -4
  178. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  179. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  180. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  181. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  182. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  183. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  184. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  185. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  186. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  187. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  188. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  189. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  190. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  191. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  192. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  193. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  194. package/src/modules/settings/settings-nav-items.tsx +166 -0
  195. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  196. package/src/modules/setup/components/SetupGate.tsx +67 -0
  197. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  198. package/src/modules/setup/services/setup.api.ts +106 -0
  199. package/src/modules/setup/utils/git-host.ts +34 -0
  200. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  201. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  202. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  203. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  204. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  205. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  206. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  207. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  208. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  209. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  210. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  211. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  212. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  213. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  214. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  215. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  216. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  217. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  218. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  219. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  220. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  221. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  222. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  223. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  224. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  225. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  226. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  227. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  228. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  229. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  230. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  231. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  232. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  233. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  234. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  235. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  236. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  237. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  238. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  240. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  241. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  242. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  243. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  244. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  245. package/src/modules/workspace/components/renderers/index.ts +78 -2
  246. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  247. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  248. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  249. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  250. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  251. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  252. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  253. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  254. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  255. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  256. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  257. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  258. package/src/modules/workspace/services/workspace.api.ts +9 -2
  259. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  260. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  261. package/src/modules/workspace/state/workspace.context.ts +9 -0
  262. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  263. package/src/modules/workspace/utils/diff.ts +130 -53
  264. package/src/modules/workspace/utils/fileTree.ts +7 -4
  265. package/src/modules/workspace/workspace.css +28 -0
  266. package/src/shared/components/Badge.tsx +62 -0
  267. package/src/shared/components/Banner.tsx +58 -0
  268. package/src/shared/components/Button.tsx +90 -0
  269. package/src/shared/components/Dialog.tsx +6 -6
  270. package/src/shared/components/Field.tsx +45 -0
  271. package/src/shared/components/IconButton.tsx +74 -0
  272. package/src/shared/components/ListRow.tsx +96 -0
  273. package/src/shared/components/Menu.tsx +88 -0
  274. package/src/shared/components/PageShell.tsx +8 -5
  275. package/src/shared/components/Surface.tsx +86 -0
  276. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  277. package/src/shared/components/index.ts +48 -0
  278. package/src/shared/components/useDismissableMenu.ts +71 -0
  279. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  280. package/src/shared/theme/index.css +12 -0
  281. package/src/shared/theme/measure.ts +64 -0
  282. package/src/shared/theme/shadows.css +34 -0
  283. package/src/shared/theme/tokens.css +193 -0
  284. package/src/test-setup.ts +9 -0
  285. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  286. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  287. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  288. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  289. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  290. package/src/modules/library/__tests__/diff.test.ts +0 -62
  291. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  292. package/src/modules/library/components/CompareView.tsx +0 -357
  293. package/src/modules/library/components/DetailDialog.tsx +0 -566
  294. package/src/modules/library/components/GearIcon.tsx +0 -12
  295. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  296. package/src/modules/library/components/StatusGem.tsx +0 -21
  297. package/src/modules/library/components/SuggestChange.tsx +0 -171
  298. package/src/modules/library/components/particles.ts +0 -50
  299. package/src/modules/library/state/loadout.tsx +0 -129
  300. package/src/modules/library/utils/diff.ts +0 -102
  301. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  302. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  303. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  304. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  305. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  306. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  307. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  308. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  309. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  310. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  311. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  312. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  313. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  314. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  315. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  316. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  317. package/src/modules/pr/components/PrHeader.tsx +0 -45
  318. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  319. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  320. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  321. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  322. package/src/modules/pr/components/PrViewer.tsx +0 -364
  323. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  324. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  325. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  326. package/src/modules/pr/utils/parsePatch.ts +0 -57
  327. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vi, afterEach } from 'vitest';
2
- import { render, screen, waitFor, act } from '@testing-library/react';
2
+ import { render, screen, waitFor, act, within } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { MemoryRouter } from 'react-router-dom';
5
5
  import { useEffect, useState } from 'react';
@@ -61,6 +61,63 @@ vi.mock('../../../workflow/services/lock.api', () => ({
61
61
  },
62
62
  }));
63
63
 
64
+ // The propose flow's one side effect that leaves the page: the network call
65
+ // that commits to the suggestions branch and opens the change request. The
66
+ // spy is the assertion surface; the branch-name helper stays real.
67
+ const proposeMock = vi.hoisted(() =>
68
+ vi.fn(async () => ({ branch: 'suggestions/reader-u9/knowledge' })),
69
+ );
70
+ vi.mock('../../../change-requests/services/propose.api', async (importOriginal) => {
71
+ const actual =
72
+ await importOriginal<typeof import('../../../change-requests/services/propose.api')>();
73
+ return { ...actual, proposeKnowledgeChange: proposeMock };
74
+ });
75
+ // Entering propose mode checks for the caller's open proposal and reads the
76
+ // file's proposed version; the change boxes read the default-branch raw for
77
+ // their diffs — all stubbed so tests decide what is in flight.
78
+ const myCrsMock = vi.hoisted(() => vi.fn(async (): Promise<unknown[]> => []));
79
+ const readBranchMock = vi.hoisted(() => vi.fn(async () => ''));
80
+ vi.mock('../../../change-requests/services/change-requests.api', () => ({
81
+ listOpenChangeRequests: vi.fn(async () => []),
82
+ listMyChangeRequests: myCrsMock,
83
+ readFileOnBranch: readBranchMock,
84
+ }));
85
+
86
+ // The access sheet is a 1200-line dialog with its own suite and its own
87
+ // endpoints. Here it only has to prove WHICH entry the page handed it — a file
88
+ // and its parent folder are the two share scopes, and picking the wrong one is
89
+ // the only mistake this wiring can make.
90
+ vi.mock('../../../access/components/ManageAccessDialog', () => ({
91
+ ManageAccessDialog: ({ entry }: { entry: { relativePath: string; type: string } }) => (
92
+ <div role="dialog" aria-label={`Manage access: ${entry.type} ${entry.relativePath}`} />
93
+ ),
94
+ }));
95
+
96
+ // Wrap `useFileLock` rather than replacing it: every other case in this file
97
+ // depends on the real acquire/release lifecycle. The wrapper only observes
98
+ // `recordActivity`, which has no other visible effect (it resets a timer), so
99
+ // there is no way to assert the scroll→lock wiring without a spy on it.
100
+ const lockActivity = vi.hoisted(() => ({ recordActivity: vi.fn() }));
101
+ vi.mock('../../../workflow/hooks/useFileLock', async (importOriginal) => {
102
+ const actual = await importOriginal<typeof import('../../../workflow/hooks/useFileLock')>();
103
+ const { useCallback } = await import('react');
104
+ return {
105
+ ...actual,
106
+ useFileLock: (args: Parameters<typeof actual.useFileLock>[0]) => {
107
+ const real = actual.useFileLock(args);
108
+ const realRecord = real.recordActivity;
109
+ // Stable identity: FileViewer's scroll effect lists `recordActivity` in
110
+ // its deps, and a fresh function each render would re-bind the listener
111
+ // on every render — changing exactly the behaviour under test.
112
+ const recordActivity = useCallback(() => {
113
+ lockActivity.recordActivity();
114
+ realRecord();
115
+ }, [realRecord]);
116
+ return { ...real, recordActivity };
117
+ },
118
+ };
119
+ });
120
+
64
121
  import { FileViewer } from '../FileViewer';
65
122
  // The lock API is mocked above; import the mocked fns so individual tests can
66
123
  // override the acquire outcome (e.g. a 403 on enter-edit).
@@ -69,7 +126,7 @@ import { WorkspaceContext, type WorkspaceContextValue } from '../../state/worksp
69
126
  import { GitContext, type GitContextValue } from '../../../git/state/git.context';
70
127
  import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
71
128
  import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
72
- import { PrViewerContext, type PrViewerContextValue } from '../../../pr/state/pr-viewer.context';
129
+ import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
73
130
 
74
131
  let injectPendingFromTest: ((value?: string) => void) | null = null;
75
132
 
@@ -81,6 +138,16 @@ function makeStatus(branch = 'alice/draft'): WorkingTreeStatus {
81
138
  };
82
139
  }
83
140
 
141
+ const fetchFileHistoryMock = vi.fn(async () => [
142
+ {
143
+ sha: 'abc1234',
144
+ authorName: 'Ali Raza',
145
+ authorEmail: 'ali@example.com',
146
+ subject: 'Tighten the wording',
147
+ committedAt: new Date(Date.now() - 3 * 24 * 3600 * 1000).toISOString(),
148
+ },
149
+ ]);
150
+
84
151
  function makeGit(status: WorkingTreeStatus): GitContextValue {
85
152
  const branches: BranchInfo[] = [];
86
153
  return {
@@ -94,15 +161,9 @@ function makeGit(status: WorkingTreeStatus): GitContextValue {
94
161
  deleteBranch: async () => {},
95
162
  pull: async () => {},
96
163
  fetchForkBase: async () => null,
97
- revert: async () => ({
98
- sha: 'abc',
99
- authorName: 'n',
100
- authorEmail: 'e',
101
- subject: 's',
102
- committedAt: '2026-04-20T00:00:00.000Z',
103
- }),
104
- fetchFileHistory: async () => [],
164
+ fetchFileHistory: fetchFileHistoryMock,
105
165
  fetchFileDiff: async () => '',
166
+ fetchFileAtChange: async () => ({ baseline: null, current: null }),
106
167
  fetchFileComparison: async () => '',
107
168
  };
108
169
  }
@@ -114,6 +175,9 @@ function ViewerHarness({
114
175
  filePath = 'knowledge-base/Knowledge/Foo.md',
115
176
  kbDirName = 'knowledge-base',
116
177
  addTab,
178
+ changeRequests = [],
179
+ authUser = null,
180
+ captureTyped = false,
117
181
  }: {
118
182
  initialContent?: string;
119
183
  pendingValue?: string;
@@ -121,8 +185,19 @@ function ViewerHarness({
121
185
  filePath?: string;
122
186
  kbDirName?: string | null;
123
187
  addTab?: WorkspaceContextValue['addTab'];
188
+ /** Open change requests touching `filePath`. */
189
+ changeRequests?: { number: number; title: string; who: string }[];
190
+ /** The signed-in user — the propose flow needs one to author the request. */
191
+ authUser?: AuthContextValue['user'];
192
+ /**
193
+ * Route `setActiveTabContent` into `openFileContent` (savedContent stays
194
+ * put), the way the real workspace state does. Opt-in so the many existing
195
+ * tests keep the historical no-op.
196
+ */
197
+ captureTyped?: boolean;
124
198
  }) {
125
199
  const [openFileContent, setOpenFileContent] = useState(initialContent);
200
+ const [savedContent, setSavedContent] = useState(initialContent);
126
201
  const [pendingFileContent, setPendingFileContent] = useState<string | null>(null);
127
202
 
128
203
  useEffect(() => {
@@ -134,10 +209,11 @@ function ViewerHarness({
134
209
  };
135
210
  }, [pendingValue]);
136
211
 
212
+ const effectiveSaved = captureTyped ? savedContent : openFileContent;
137
213
  const tab = {
138
214
  path: filePath,
139
215
  content: openFileContent,
140
- savedContent: openFileContent,
216
+ savedContent: effectiveSaved,
141
217
  isDirty: false,
142
218
  pendingFileContent,
143
219
  };
@@ -150,11 +226,13 @@ function ViewerHarness({
150
226
  dirtyTabFilenames: [],
151
227
  openFilePath: filePath,
152
228
  openFileContent,
153
- openFileSavedContent: openFileContent,
229
+ openFileSavedContent: effectiveSaved,
154
230
  hasUnsavedFileChanges: false,
155
231
  pendingFileContent,
156
- setActiveTabContent: () => {},
232
+ setActiveTabContent: captureTyped ? (v: string) => setOpenFileContent(v) : () => {},
157
233
  uploadError: null,
234
+ uploadNotice: null,
235
+ clearUploadNotice: () => {},
158
236
  isUploading: false,
159
237
  uploadProgress: null,
160
238
  pendingUploads: new Map(),
@@ -178,6 +256,7 @@ function ViewerHarness({
178
256
  moveEntry: async () => {},
179
257
  saveFile: async (_relativePath: string, content: string) => {
180
258
  setOpenFileContent(content);
259
+ setSavedContent(content);
181
260
  },
182
261
  reloadTabFromDisk: async () => {},
183
262
  setPendingContent: (content: string) => {
@@ -207,37 +286,42 @@ function ViewerHarness({
207
286
  clearError: () => {},
208
287
  };
209
288
  const auth: AuthContextValue = {
210
- user: null,
211
- token: null,
289
+ user: authUser,
290
+ token: authUser ? 't' : null,
212
291
  isLoading: false,
213
292
  login: async () => {},
214
293
  logout: () => {},
215
294
  };
216
- const prViewer: PrViewerContextValue = {
217
- openPrNumber: null,
218
- detail: null,
219
- notFound: false,
220
- selectedPath: null,
221
- isLoading: false,
222
- lastError: null,
223
- openPr: () => {},
224
- closeViewer: () => {},
225
- selectPath: () => {},
226
- refresh: async () => {},
227
- };
228
-
229
295
  return (
230
296
  <MemoryRouter>
231
297
  <AuthContext.Provider value={auth}>
232
298
  <WorkspaceContext.Provider value={workspace}>
233
299
  <GitContext.Provider value={makeGit(makeStatus(branch))}>
234
300
  <ReviewContext.Provider value={review}>
235
- <PrViewerContext.Provider value={prViewer}>
236
- <button type="button" onClick={() => setPendingFileContent(pendingValue)}>
237
- Inject pending
238
- </button>
239
- <FileViewer />
240
- </PrViewerContext.Provider>
301
+ <OpenChangeRequestsContext.Provider
302
+ value={{
303
+ paths: new Set(changeRequests.length ? [filePath] : []),
304
+ minePaths: new Map(),
305
+ mineNumbers: new Set<number>(),
306
+ forPath: (p) =>
307
+ p === filePath
308
+ ? (changeRequests.map((c) => ({
309
+ number: c.number,
310
+ title: c.title,
311
+ appAuthor: { name: c.who },
312
+ author: { login: 'bevel-bot' },
313
+ branch: `suggestions/${c.who.toLowerCase().replace(/\s+/g, '-')}/knowledge`,
314
+ createdAt: new Date().toISOString(),
315
+ touchedNodePaths: ['Knowledge/Foo.md'],
316
+ })) as never)
317
+ : [],
318
+ }}
319
+ >
320
+ <button type="button" onClick={() => setPendingFileContent(pendingValue)}>
321
+ Inject pending
322
+ </button>
323
+ <FileViewer />
324
+ </OpenChangeRequestsContext.Provider>
241
325
  </ReviewContext.Provider>
242
326
  </GitContext.Provider>
243
327
  </WorkspaceContext.Provider>
@@ -354,16 +438,20 @@ describe('FileViewer', () => {
354
438
  // never exist, and the access-denied view lives at the route level. See
355
439
  // FileRoute.test.tsx's file-denied cases.)
356
440
 
357
- it('shows the canonical-state banner on a protected branch but keeps editing enabled', () => {
358
- // Write access is now governed by roles.yaml + access.md and enforced by
359
- // the backend at commit time — the editor itself is no longer disabled
360
- // based on branch name. The banner stays as informational copy.
441
+ it('keeps editing enabled on a protected branch and shows no canonical-state banner', () => {
442
+ // Write access is governed by roles.yaml + access.md and enforced by the
443
+ // backend at commit time — the editor is not disabled based on branch
444
+ // name. The informational strip that used to explain the protected branch
445
+ // is gone; nothing narrates the branch to the reader here anymore.
361
446
  render(<ViewerHarness initialContent="official" branch="current-company-state" />);
362
- expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
363
- expect(screen.getByText(/current company state/i)).toBeInTheDocument();
447
+ // `toBeEnabled`, not `toBeInTheDocument`: the header disables Edit when
448
+ // someone else holds the lock, so presence alone would pass on a branch
449
+ // that had gone read-only — the opposite of what this test claims.
450
+ expect(screen.getByRole('button', { name: 'Edit' })).toBeEnabled();
451
+ expect(screen.queryByText(/current company state/i)).not.toBeInTheDocument();
364
452
  });
365
453
 
366
- it('goes read-only and shows AccessRestrictedBanner when canWrite is false on a protected branch', async () => {
454
+ it('goes read-only, WITHOUT a permission banner, when canWrite is false on a protected branch', async () => {
367
455
  // The access gate only fires on protected branches — drafts are
368
456
  // free-for-all and never reach the API, so reproducing the read-only
369
457
  // state requires a protected branch.
@@ -374,11 +462,14 @@ describe('FileViewer', () => {
374
462
  owners: EMPTY_ELIGIBLE,
375
463
  };
376
464
  render(<ViewerHarness initialContent="official" branch="target-company-state" />);
465
+ // Read-only means the Edit affordance withdraws…
377
466
  await waitFor(() => {
378
- expect(screen.getByText(/You don't have permission to edit/i)).toBeInTheDocument();
467
+ expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
379
468
  });
380
- expect(screen.getByText(/Admin, Product Manager/)).toBeInTheDocument();
381
- expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
469
+ // …and that is ALL it means on screen: no "you don't have permission"
470
+ // stripe — for a reader the restriction is not news, and the propose
471
+ // affordance says what they CAN do instead.
472
+ expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
382
473
  });
383
474
 
384
475
  // Drafts are free-for-all: even if the backend would deny at PR-merge
@@ -489,4 +580,331 @@ describe('FileViewer', () => {
489
580
  // And we did NOT flip into edit mode — no editable textbox appeared.
490
581
  expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
491
582
  });
583
+
584
+ // WP1 regression. The document column moved: the viewer pane used to be
585
+ // `overflow-hidden` with a per-renderer scroller, and `editorContainerRef`
586
+ // sat on that pane. It now sits on `KbDocumentShell`, which is what actually
587
+ // scrolls. Scroll events do NOT bubble, so if the ref ever lands on a
588
+ // wrapper nested inside the scroller the capture listener stops firing,
589
+ // nothing type-errors, and a reader's lock silently auto-releases after two
590
+ // minutes. This suite had zero scroll / recordActivity coverage before.
591
+ it('resets the lock idle timer when the document is scrolled in edit mode', async () => {
592
+ const user = userEvent.setup();
593
+ lockActivity.recordActivity.mockClear();
594
+ render(<ViewerHarness initialContent="a long document" />);
595
+
596
+ await user.click(screen.getByRole('button', { name: 'Edit' }));
597
+ // Edit mode is what arms the scroll listener.
598
+ await screen.findByRole('textbox');
599
+ lockActivity.recordActivity.mockClear();
600
+
601
+ const shell = screen.getByTestId('kb-document-shell');
602
+ await act(async () => {
603
+ shell.dispatchEvent(new Event('scroll'));
604
+ });
605
+
606
+ expect(lockActivity.recordActivity).toHaveBeenCalled();
607
+ });
608
+
609
+ it('leads the page with the document column, not a full-bleed pane', () => {
610
+ render(<ViewerHarness initialContent="measured" />);
611
+ const shell = screen.getByTestId('kb-document-shell');
612
+ // A markdown file is a document, so it gets the prose measure.
613
+ expect(shell.getAttribute('data-variant')).toBe('prose');
614
+ // …and the tab strip lives inside it, so tabs and text share one edge.
615
+ expect(shell.querySelector('[role="tablist"]')).not.toBeNull();
616
+ });
617
+
618
+ // ── WP4: the document names itself ──
619
+
620
+ it('names the file in an h1 and keeps no 40px chrome strip', () => {
621
+ render(<ViewerHarness initialContent="titled" />);
622
+ expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Foo');
623
+ // The trio of sub-tabs went behind ⋯; Content is the page now.
624
+ expect(screen.queryByRole('button', { name: 'Content' })).not.toBeInTheDocument();
625
+ expect(screen.queryByRole('button', { name: 'History' })).not.toBeInTheDocument();
626
+ expect(screen.queryByRole('button', { name: 'Compare' })).not.toBeInTheDocument();
627
+ });
628
+
629
+ it('opens Version history from ⋯ and offers a way back to the document', async () => {
630
+ const user = userEvent.setup();
631
+ render(<ViewerHarness initialContent="historic" />);
632
+
633
+ await user.click(screen.getByRole('button', { name: 'More actions' }));
634
+ await user.click(screen.getByRole('menuitem', { name: /Version history/ }));
635
+
636
+ const back = await screen.findByRole('button', { name: /Back to the document/ });
637
+ await user.click(back);
638
+ // The document is back, and so is its Edit affordance.
639
+ expect(await screen.findByRole('button', { name: 'Edit' })).toBeInTheDocument();
640
+ });
641
+
642
+ it('shares the file itself from Share, and the parent folder from the chevron', async () => {
643
+ const user = userEvent.setup();
644
+ render(<ViewerHarness initialContent="shared" />);
645
+
646
+ await user.click(screen.getByRole('button', { name: 'Share' }));
647
+ expect(
648
+ await screen.findByRole('dialog', {
649
+ name: 'Manage access: file knowledge-base/Knowledge/Foo.md',
650
+ }),
651
+ ).toBeInTheDocument();
652
+ // And there is no second scope: sharing the whole folder starts at the
653
+ // folder's own row in the tree, beside the children it governs.
654
+ await user.click(screen.getByRole('button', { name: 'More sharing options' }));
655
+ expect(screen.queryByRole('menuitem', { name: /whole folder/i })).not.toBeInTheDocument();
656
+ });
657
+
658
+ // ── WP5: the rail ──
659
+
660
+ // The rail lost its only trigger with the ⋯ menu's File details entry, so
661
+ // the page never mounts it — and never pays for the history request that
662
+ // used to sit behind its "Edited" row.
663
+ it('mounts no rail, and issues no history request for one', () => {
664
+ fetchFileHistoryMock.mockClear();
665
+ render(<ViewerHarness initialContent="railed" />);
666
+
667
+ expect(screen.queryByText('About this file')).not.toBeInTheDocument();
668
+ expect(fetchFileHistoryMock).not.toHaveBeenCalled();
669
+ });
670
+
671
+ // ── WP6: the third place ──
672
+
673
+ // The D3 asymmetry, made visible: this signal comes from the BROAD endpoint,
674
+ // so a request opened by somebody else on a file you can read but not write
675
+ // still says so here — while the dock, which is scoped to you, stays empty.
676
+ // A DOCUMENT shows it as the skill page does: a change box UNDER the file,
677
+ // whose "Read the whole change" opens the shared change-request dialog.
678
+ it('shows an open change request as a box under the document', async () => {
679
+ const user = userEvent.setup();
680
+ render(
681
+ <ViewerHarness
682
+ initialContent="contested"
683
+ changeRequests={[{ number: 32, title: 'Tighten the wording', who: 'Ali Raza' }]}
684
+ />,
685
+ );
686
+
687
+ expect(await screen.findByText(/proposed a change/)).toBeInTheDocument();
688
+ expect(screen.getByText('Ali Raza')).toBeInTheDocument();
689
+ await user.click(screen.getByRole('button', { name: 'Read the whole change' }));
690
+ // The shared dialog.
691
+ expect(
692
+ await screen.findByRole('dialog', { name: /Change request: Tighten the wording/ }),
693
+ ).toBeInTheDocument();
694
+ });
695
+
696
+ it('says nothing on a file nobody has proposed a change to', () => {
697
+ render(<ViewerHarness initialContent="quiet" />);
698
+ expect(screen.queryByText(/proposed a change/)).not.toBeInTheDocument();
699
+ });
700
+
701
+ /**
702
+ * The unification the skill page and this viewer share: a document renders
703
+ * inside the SAME edged pane card, named by the same mono filename bar. The
704
+ * frame is one declaration (`FilePaneCard`); this pins that this surface
705
+ * actually mounts it.
706
+ */
707
+ it('frames a prose document in the shared file pane card', () => {
708
+ render(<ViewerHarness initialContent="boxed" />);
709
+ const card = screen.getByTestId('file-pane-card');
710
+ // The bar names the file, extension and all — same as the skill page.
711
+ expect(within(card).getByText('Foo.md')).toBeInTheDocument();
712
+ expect(within(card).getByText('boxed')).toBeInTheDocument();
713
+ });
714
+
715
+ // With no rail to make room for, the column stays on the base measure.
716
+ it('keeps the base measure', () => {
717
+ render(<ViewerHarness initialContent="railed" />);
718
+ const wrap = screen.getByTestId('kb-document-shell').firstElementChild as HTMLElement;
719
+ expect(wrap.className).toContain('max-w-[880px]');
720
+ });
721
+ });
722
+
723
+ /**
724
+ * The reader's write path. Where a write grant opens the editor, its absence
725
+ * now opens the SAME editor pointed somewhere else: the text goes to the
726
+ * caller's personal suggestions branch as a change request, and the file on
727
+ * this branch is untouched until an owner approves.
728
+ */
729
+ describe('FileViewer: proposing a change without write access', () => {
730
+ const reader = { id: 'u9', email: 'reader@example.com', name: 'Rae Reader' };
731
+
732
+ function denyWrite() {
733
+ accessMock.result = {
734
+ canWrite: false,
735
+ canOwner: false,
736
+ eligible: { roles: ['Admin'], users: [] },
737
+ owners: EMPTY_ELIGIBLE,
738
+ };
739
+ }
740
+
741
+ afterEach(() => {
742
+ accessMock.result = {
743
+ canWrite: true,
744
+ canOwner: false,
745
+ eligible: { roles: ['Admin'], users: [] },
746
+ owners: EMPTY_ELIGIBLE,
747
+ };
748
+ proposeMock.mockClear();
749
+ proposeMock.mockResolvedValue({ branch: 'suggestions/reader-u9/knowledge' });
750
+ myCrsMock.mockClear();
751
+ myCrsMock.mockResolvedValue([]);
752
+ readBranchMock.mockClear();
753
+ readBranchMock.mockResolvedValue('');
754
+ });
755
+
756
+ it('offers Propose changes exactly where Edit is refused', async () => {
757
+ denyWrite();
758
+ render(
759
+ <ViewerHarness initialContent="official" branch="target-company-state" authUser={reader} />,
760
+ );
761
+ expect(
762
+ await screen.findByRole('button', { name: 'Propose changes' }),
763
+ ).toBeInTheDocument();
764
+ expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
765
+ });
766
+
767
+ it('does not offer Propose changes to someone who can simply edit', async () => {
768
+ render(
769
+ <ViewerHarness initialContent="official" branch="target-company-state" authUser={reader} />,
770
+ );
771
+ expect(await screen.findByRole('button', { name: 'Edit' })).toBeInTheDocument();
772
+ expect(screen.queryByRole('button', { name: 'Propose changes' })).not.toBeInTheDocument();
773
+ });
774
+
775
+ it('sends the typed text as a knowledge proposal and reports it', async () => {
776
+ denyWrite();
777
+ const user = userEvent.setup();
778
+ render(
779
+ <ViewerHarness
780
+ initialContent="official"
781
+ branch="target-company-state"
782
+ authUser={reader}
783
+ captureTyped
784
+ />,
785
+ );
786
+
787
+ await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
788
+ // The read-only "you can't edit" strip yields to the propose surface —
789
+ // showing both would contradict the open editor.
790
+ expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
791
+ expect(screen.getByText(/You're proposing a change/)).toBeInTheDocument();
792
+
793
+ const textarea = await screen.findByRole('textbox');
794
+ await user.clear(textarea);
795
+ await user.type(textarea, 'the corrected paragraph');
796
+ await user.click(screen.getByRole('button', { name: 'Send proposal' }));
797
+
798
+ await waitFor(() =>
799
+ expect(proposeMock).toHaveBeenCalledWith({
800
+ // kbDirName stripped: the propose service takes repo-relative paths.
801
+ repoRelativePath: 'Knowledge/Foo.md',
802
+ content: 'the corrected paragraph',
803
+ userEmail: 'reader@example.com',
804
+ userId: 'u9',
805
+ userName: 'Rae Reader',
806
+ }),
807
+ );
808
+ // Back in read mode, with the one confirmation that the change is now
809
+ // someone else's to act on.
810
+ expect(
811
+ await screen.findByText(/sent as a change request/i),
812
+ ).toBeInTheDocument();
813
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
814
+ });
815
+
816
+ /**
817
+ * Proposing AGAIN is a continuation, not a restart. With an open proposal
818
+ * on the caller's suggestions branch, the editor seeds from the file AS
819
+ * PROPOSED — and sending stacks the new edits into the same change
820
+ * request, never silently reverting the pending one to this branch's text.
821
+ */
822
+ it('seeds a second proposal from the proposed version, and edits stack', async () => {
823
+ denyWrite();
824
+ myCrsMock.mockResolvedValue([
825
+ { number: 12, state: 'open', branch: 'suggestions/reader-u9/knowledge' },
826
+ ]);
827
+ readBranchMock.mockResolvedValue('first proposed paragraph');
828
+ const user = userEvent.setup();
829
+ render(
830
+ <ViewerHarness
831
+ initialContent="official"
832
+ branch="target-company-state"
833
+ authUser={reader}
834
+ captureTyped
835
+ />,
836
+ );
837
+
838
+ await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
839
+
840
+ // The editor shows the PROPOSED text, read from the suggestions branch —
841
+ // not this branch's "official".
842
+ const textarea = await screen.findByRole('textbox');
843
+ expect(textarea).toHaveValue('first proposed paragraph');
844
+ expect(readBranchMock).toHaveBeenCalledWith(
845
+ 'suggestions/reader-u9/knowledge',
846
+ 'Knowledge/Foo.md',
847
+ );
848
+
849
+ await user.type(textarea, ' plus a second thought');
850
+ await user.click(screen.getByRole('button', { name: 'Send proposal' }));
851
+
852
+ await waitFor(() =>
853
+ expect(proposeMock).toHaveBeenCalledWith(
854
+ expect.objectContaining({
855
+ content: 'first proposed paragraph plus a second thought',
856
+ }),
857
+ ),
858
+ );
859
+ });
860
+
861
+ it('closes without sending when nothing was typed over the open proposal', async () => {
862
+ denyWrite();
863
+ myCrsMock.mockResolvedValue([
864
+ { number: 12, state: 'open', branch: 'suggestions/reader-u9/knowledge' },
865
+ ]);
866
+ readBranchMock.mockResolvedValue('first proposed paragraph');
867
+ const user = userEvent.setup();
868
+ render(
869
+ <ViewerHarness
870
+ initialContent="official"
871
+ branch="target-company-state"
872
+ authUser={reader}
873
+ captureTyped
874
+ />,
875
+ );
876
+
877
+ await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
878
+ await screen.findByRole('textbox');
879
+ await user.click(screen.getByRole('button', { name: 'Send proposal' }));
880
+
881
+ // The branch already says exactly this — no write, no empty commit.
882
+ await waitFor(() => expect(screen.queryByRole('textbox')).not.toBeInTheDocument());
883
+ expect(proposeMock).not.toHaveBeenCalled();
884
+ });
885
+
886
+ it('discard walks away without sending anything', async () => {
887
+ denyWrite();
888
+ const user = userEvent.setup();
889
+ render(
890
+ <ViewerHarness
891
+ initialContent="official"
892
+ branch="target-company-state"
893
+ authUser={reader}
894
+ captureTyped
895
+ />,
896
+ );
897
+
898
+ await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
899
+ const textarea = await screen.findByRole('textbox');
900
+ await user.type(textarea, ': never mind');
901
+ await user.click(screen.getByRole('button', { name: 'Discard' }));
902
+
903
+ expect(proposeMock).not.toHaveBeenCalled();
904
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
905
+ // Back to the read-only view: the propose affordance returns, and no
906
+ // permission stripe with it (removed for readers everywhere).
907
+ expect(await screen.findByRole('button', { name: 'Propose changes' })).toBeInTheDocument();
908
+ expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
909
+ });
492
910
  });