@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
@@ -269,21 +269,21 @@ export function ToolRenderer({
269
269
 
270
270
  return (
271
271
  <div className="flex h-full min-h-0">
272
- <div className="flex min-h-0 flex-1 flex-col border-r border-slate-200">
273
- <div className="flex shrink-0 items-center gap-2 border-b border-slate-100 px-3 py-1.5">
274
- <span className="text-xs font-medium text-slate-600">{filePath.split('/').pop()}</span>
275
- {dirty && <span className="text-[10px] text-amber-600">● unsaved</span>}
276
- {saveState === 'error' && <span className="text-[10px] text-red-600">{saveError}</span>}
272
+ <div className="flex min-h-0 flex-1 flex-col border-r border-line">
273
+ <div className="flex shrink-0 items-center gap-2 border-b border-line px-3 py-1.5">
274
+ <span className="text-xs font-medium text-ink-muted">{filePath.split('/').pop()}</span>
275
+ {dirty && <span className="text-micro text-wait">● unsaved</span>}
276
+ {saveState === 'error' && <span className="text-micro text-danger">{saveError}</span>}
277
277
  {/* No Save button here — like the other renderers, the FileViewer's Save
278
278
  persists edits (tracked via onValueChange). We only own the view toggle. */}
279
- <div className="ml-auto flex overflow-hidden rounded border border-slate-200">
279
+ <div className="ml-auto flex overflow-hidden rounded-xs border border-line">
280
280
  {(['form', 'code'] as const).map((m) => (
281
281
  <button
282
282
  key={m}
283
283
  type="button"
284
284
  onClick={() => setMode(m)}
285
- className={`px-2 py-0.5 text-[11px] capitalize ${
286
- mode === m ? 'bg-slate-800 text-white' : 'bg-white text-slate-600 hover:bg-slate-100'
285
+ className={`px-2 py-0.5 text-meta capitalize ${
286
+ mode === m ? 'bg-ink text-white' : 'bg-white text-ink-muted hover:bg-hover'
287
287
  }`}
288
288
  >
289
289
  {m}
@@ -295,8 +295,8 @@ export function ToolRenderer({
295
295
  <div className="min-h-0 flex-1 overflow-y-auto p-3">
296
296
  <ToolForm value={value} onChange={updateValue} readOnly={readOnly} />
297
297
  {notesOf(value) && (
298
- <section className="mt-4 border-t border-slate-200 pt-3">
299
- <h3 className="mb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">Notes</h3>
298
+ <section className="mt-4 border-t border-line pt-3">
299
+ <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Notes</h3>
300
300
  {/* The free-form markdown after the frontmatter fence — where a
301
301
  tool's setup instructions live. Edited in the Code view. */}
302
302
  <Markdown className="text-xs">{notesOf(value)}</Markdown>
@@ -311,7 +311,7 @@ export function ToolRenderer({
311
311
  onChange={(e) => updateValue(e.target.value)}
312
312
  onKeyDown={handleKeyDown}
313
313
  spellCheck={false}
314
- className="min-h-0 flex-1 resize-none bg-slate-50 p-3 font-mono text-xs text-slate-800 focus:outline-none"
314
+ className="min-h-0 flex-1 resize-none bg-sunken p-3 font-mono text-xs text-ink focus:outline-none"
315
315
  placeholder="A .tool file is a UTCP manual. Use a scaffold →"
316
316
  />
317
317
  )}
@@ -320,7 +320,7 @@ export function ToolRenderer({
320
320
  <aside className="flex w-72 shrink-0 flex-col gap-4 overflow-y-auto p-3">
321
321
  {!readOnly && (
322
322
  <section>
323
- <h3 className="mb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">Scaffold</h3>
323
+ <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Scaffold</h3>
324
324
  <div className="flex gap-1">
325
325
  {(['inline', 'http', 'mcp'] as const).map((t) => (
326
326
  <button
@@ -330,7 +330,7 @@ export function ToolRenderer({
330
330
  updateValue(SCAFFOLDS[t]);
331
331
  }
332
332
  }}
333
- className="rounded bg-slate-100 px-2 py-1 text-[11px] text-slate-600 hover:bg-slate-200"
333
+ className="rounded-xs bg-sunken px-2 py-1 text-meta text-ink-muted hover:bg-hover"
334
334
  >
335
335
  {t}
336
336
  </button>
@@ -341,9 +341,9 @@ export function ToolRenderer({
341
341
 
342
342
  {!readOnly && (
343
343
  <section>
344
- <h3 className="mb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">Secret variables</h3>
344
+ <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secret variables</h3>
345
345
  {secretKeys.length === 0 ? (
346
- <p className="text-[11px] text-slate-400">
346
+ <p className="text-meta text-ink-faint">
347
347
  No secrets yet. Add them on the Secrets page, then reference them here.
348
348
  </p>
349
349
  ) : (
@@ -352,7 +352,7 @@ export function ToolRenderer({
352
352
  <button
353
353
  key={k}
354
354
  onClick={() => insertAtCursor(`\${${k}}`)}
355
- className="rounded bg-blue-50 px-1.5 py-0.5 font-mono text-[10px] text-blue-700 hover:bg-blue-100"
355
+ className="rounded-xs bg-accent/10 px-1.5 py-0.5 font-mono text-micro text-accent hover:bg-accent/15"
356
356
  title={`Insert \${${k}}`}
357
357
  >
358
358
  {`\${${k}}`}
@@ -364,12 +364,12 @@ export function ToolRenderer({
364
364
  )}
365
365
 
366
366
  <section>
367
- <h3 className="mb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">Secrets for this tool</h3>
367
+ <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secrets for this tool</h3>
368
368
  {toolSecrets ? (
369
369
  <ToolSecretsPanel tool={toolSecrets} onChanged={() => void loadToolSecrets()} />
370
370
  ) : (
371
- <p className="text-[11px] text-slate-400">
372
- Declare a <code className="rounded bg-slate-100 px-1">variables</code> block and save this tool to the
371
+ <p className="text-meta text-ink-faint">
372
+ Declare a <code className="rounded-xs bg-sunken px-1">variables</code> block and save this tool to the
373
373
  default branch to configure its secrets here.
374
374
  </p>
375
375
  )}
@@ -377,19 +377,19 @@ export function ToolRenderer({
377
377
 
378
378
  <section>
379
379
  <div className="mb-1 flex items-center gap-2">
380
- <h3 className="text-[11px] font-semibold uppercase tracking-wide text-slate-400">Preview</h3>
380
+ <h3 className="text-meta font-semibold uppercase tracking-wide text-ink-faint">Preview</h3>
381
381
  <button
382
382
  onClick={() => void runPreview()}
383
383
  disabled={previewing}
384
- className="ml-auto rounded bg-slate-100 px-2 py-0.5 text-[11px] text-slate-600 hover:bg-slate-200 disabled:opacity-40"
384
+ className="ml-auto rounded-xs bg-sunken px-2 py-0.5 text-meta text-ink-muted hover:bg-hover disabled:opacity-40"
385
385
  >
386
386
  {previewing ? '…' : 'Run'}
387
387
  </button>
388
388
  </div>
389
389
  {preview && (
390
- <div className="text-[11px]">
390
+ <div className="text-meta">
391
391
  {preview.errors?.length ? (
392
- <ul className="space-y-1 text-red-600">
392
+ <ul className="space-y-1 text-danger">
393
393
  {preview.errors.map((e, i) => (
394
394
  <li key={i}>{e}</li>
395
395
  ))}
@@ -397,14 +397,14 @@ export function ToolRenderer({
397
397
  ) : preview.tools && preview.tools.length > 0 ? (
398
398
  <ul className="space-y-1">
399
399
  {preview.tools.map((t) => (
400
- <li key={t.name} className="rounded bg-slate-50 px-1.5 py-1">
401
- <code className="text-slate-700">{t.name}</code>
402
- {t.description && <div className="text-slate-400">{t.description}</div>}
400
+ <li key={t.name} className="rounded-xs bg-sunken px-1.5 py-1">
401
+ <code className="text-ink">{t.name}</code>
402
+ {t.description && <div className="text-ink-faint">{t.description}</div>}
403
403
  </li>
404
404
  ))}
405
405
  </ul>
406
406
  ) : (
407
- <p className="text-slate-400">
407
+ <p className="text-ink-faint">
408
408
  {preview.ok ? 'Valid. Tools resolve at runtime (http/mcp).' : 'No tools.'}
409
409
  </p>
410
410
  )}
@@ -77,7 +77,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
77
77
 
78
78
  if (error) {
79
79
  return (
80
- <div className="flex items-center justify-center h-full text-red-600 text-sm">
80
+ <div className="flex items-center justify-center h-full text-danger text-sm">
81
81
  {error}
82
82
  </div>
83
83
  );
@@ -85,7 +85,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
85
85
 
86
86
  if (sheets === null) {
87
87
  return (
88
- <div className="flex items-center justify-center h-full text-slate-600 text-sm">
88
+ <div className="flex items-center justify-center h-full text-ink-muted text-sm">
89
89
  Loading spreadsheet...
90
90
  </div>
91
91
  );
@@ -93,7 +93,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
93
93
 
94
94
  if (sheets.length === 0) {
95
95
  return (
96
- <div className="flex items-center justify-center h-full text-slate-600 text-sm">
96
+ <div className="flex items-center justify-center h-full text-ink-muted text-sm">
97
97
  The workbook has no sheets.
98
98
  </div>
99
99
  );
@@ -104,16 +104,16 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
104
104
  return (
105
105
  <div className="flex flex-col h-full">
106
106
  {sheets.length > 1 && (
107
- <div className="flex items-center gap-1 border-b border-slate-200 px-1 pb-1 overflow-x-auto shrink-0">
107
+ <div className="flex items-center gap-1 border-b border-line px-1 pb-1 overflow-x-auto shrink-0">
108
108
  {sheets.map((s, i) => (
109
109
  <button
110
110
  key={s.name}
111
111
  type="button"
112
112
  onClick={() => setActiveSheet(i)}
113
- className={`px-2 py-1 rounded text-xs font-medium whitespace-nowrap transition-colors ${
113
+ className={`px-2 py-1 rounded-xs text-xs font-medium whitespace-nowrap transition-colors ${
114
114
  i === activeSheet
115
- ? 'bg-slate-100 text-slate-900'
116
- : 'text-slate-600 hover:text-slate-900 hover:bg-slate-100/80'
115
+ ? 'bg-sunken text-ink'
116
+ : 'text-ink-muted hover:text-ink hover:bg-hover'
117
117
  }`}
118
118
  >
119
119
  {s.name}
@@ -123,7 +123,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
123
123
  )}
124
124
  <div className="flex-1 overflow-auto">
125
125
  {sheet.rows.length === 0 ? (
126
- <div className="flex items-center justify-center h-full text-slate-600 text-sm">
126
+ <div className="flex items-center justify-center h-full text-ink-muted text-sm">
127
127
  This sheet is empty.
128
128
  </div>
129
129
  ) : (
@@ -136,10 +136,10 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
136
136
  return (
137
137
  <Tag
138
138
  key={cIdx}
139
- className={`border border-slate-200 px-2 py-1 align-top whitespace-pre-wrap ${
139
+ className={`border border-line px-2 py-1 align-top whitespace-pre-wrap ${
140
140
  rIdx === 0
141
- ? 'bg-slate-50 text-slate-900 font-medium text-left'
142
- : 'text-slate-700'
141
+ ? 'bg-sunken text-ink font-medium text-left'
142
+ : 'text-ink'
143
143
  }`}
144
144
  >
145
145
  {cell}
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import {
4
+ WorkspaceContext,
5
+ type WorkspaceContextValue,
6
+ } from '../../../state/workspace.context';
7
+
8
+ // mammoth is the untrusted-content boundary under test: it faithfully copies
9
+ // a hyperlink's target out of the `.docx`, so we make it return exactly what
10
+ // it would emit for a document crafted with a `javascript:` hyperlink.
11
+ const mammothMock = vi.hoisted(() => ({ convertToHtml: vi.fn() }));
12
+ vi.mock('mammoth/mammoth.browser.js', () => ({ default: mammothMock }));
13
+
14
+ const apiMock = vi.hoisted(() => ({ authFetch: vi.fn() }));
15
+ vi.mock('../../../../../lib/api', () => ({ authFetch: apiMock.authFetch }));
16
+
17
+ import { DocxRenderer } from '../DocxRenderer';
18
+
19
+ function renderDocx() {
20
+ return render(
21
+ <WorkspaceContext.Provider
22
+ value={{ workspaceId: 'ws-1' } as unknown as WorkspaceContextValue}
23
+ >
24
+ <DocxRenderer filePath="Inbox/report.docx" content="" onSave={async () => {}} />
25
+ </WorkspaceContext.Provider>,
26
+ );
27
+ }
28
+
29
+ beforeEach(() => {
30
+ apiMock.authFetch.mockReset().mockResolvedValue({
31
+ ok: true,
32
+ arrayBuffer: async () => new ArrayBuffer(8),
33
+ });
34
+ mammothMock.convertToHtml.mockReset();
35
+ });
36
+
37
+ /**
38
+ * The sanitizer has its own unit tests; this one proves it is actually WIRED
39
+ * into the sink. `DocxRenderer` injects with `dangerouslySetInnerHTML` into
40
+ * the app origin, so a regression that drops the sanitize call would be
41
+ * invisible to the sanitizer's own tests — and would hand every reader of an
42
+ * uploaded document a one-click XSS.
43
+ */
44
+ describe('DocxRenderer', () => {
45
+ it('renders no script-capable link from a malicious document', async () => {
46
+ mammothMock.convertToHtml.mockResolvedValue({
47
+ value: '<p><a href="javascript:fetch(\'/api/steal\')">Download the Q3 figures</a></p>',
48
+ });
49
+ const { container } = renderDocx();
50
+
51
+ await waitFor(() => expect(screen.getByText('Download the Q3 figures')).toBeInTheDocument());
52
+ const anchor = container.querySelector('a')!;
53
+ expect(anchor.getAttribute('href')).toBeNull();
54
+ expect(container.innerHTML).not.toContain('javascript:');
55
+ });
56
+
57
+ it('leaves an ordinary document intact', async () => {
58
+ mammothMock.convertToHtml.mockResolvedValue({
59
+ value: '<h1>Quarterly report</h1><p><a href="https://example.com">source</a></p>',
60
+ });
61
+ const { container } = renderDocx();
62
+
63
+ await waitFor(() => expect(screen.getByText('Quarterly report')).toBeInTheDocument());
64
+ expect(container.querySelector('a')!.getAttribute('href')).toBe('https://example.com');
65
+ });
66
+ });
@@ -87,9 +87,25 @@ describe('KbMarkdownView', () => {
87
87
 
88
88
  it('renders inline HTML details blocks (Source of Information)', () => {
89
89
  const onOpenFile = vi.fn();
90
- const src = `# Goal\nThe goal.\n\n<details><summary>Source of Information</summary>\n\n1. PROD-1 — goal (2026-06-09)\n\n</details>\n`;
90
+ const src = `# Goal\nThe goal.\n\n<details><summary>Source of Information</summary>\n\n1. PROD-1. Goal (2026-06-09)\n\n</details>\n`;
91
91
  render(<KbMarkdownView source={src} onOpenFile={onOpenFile} />);
92
92
  // rehype-raw turns the <details> into a real element rather than literal text.
93
93
  expect(screen.getByText('Source of Information').tagName.toLowerCase()).toBe('summary');
94
94
  });
95
+
96
+ // WP1: the file viewer's document column is the scroller, so the view must be
97
+ // able to surrender its own. The DEFAULT keeps it — the Atlassian embed and
98
+ // the library's detail dialog both mount this view outside a document column
99
+ // and would lose their scrollbar if the default flipped.
100
+ it('owns a scroller by default', () => {
101
+ const { container } = render(<KbMarkdownView source={'Body.\n'} onOpenFile={vi.fn()} />);
102
+ expect((container.firstElementChild as HTMLElement).className).toContain('overflow-auto');
103
+ });
104
+
105
+ it('surrenders its scroller when scroll={false}', () => {
106
+ const { container } = render(
107
+ <KbMarkdownView source={'Body.\n'} onOpenFile={vi.fn()} scroll={false} />,
108
+ );
109
+ expect((container.firstElementChild as HTMLElement).className).not.toContain('overflow-auto');
110
+ });
95
111
  });
@@ -29,9 +29,9 @@ function makeGit(): GitContextValue {
29
29
  deleteBranch: async () => {},
30
30
  pull: async () => {},
31
31
  fetchForkBase: async () => null,
32
- revert: async () => ({ sha: 'a', authorName: 'n', authorEmail: 'e', subject: 's', committedAt: '2026-04-20T00:00:00.000Z' }),
33
32
  fetchFileHistory: async () => [],
34
33
  fetchFileDiff: async () => '',
34
+ fetchFileAtChange: async () => ({ baseline: null, current: null }),
35
35
  fetchFileComparison: async () => '',
36
36
  };
37
37
  }
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+
4
+ // mermaid is the boundary under test: what matters is what this component does
5
+ // when `render` REJECTS, which is the normal case for a diagram whose fence was
6
+ // split across a diff's change boundary.
7
+ const mermaidMock = vi.hoisted(() => ({
8
+ initialize: vi.fn(),
9
+ render: vi.fn(),
10
+ }));
11
+ vi.mock('mermaid', () => ({ default: mermaidMock }));
12
+
13
+ import { MermaidDiagram } from '../MermaidDiagram';
14
+
15
+ beforeEach(() => {
16
+ mermaidMock.render.mockReset();
17
+ });
18
+
19
+ describe('MermaidDiagram', () => {
20
+ it('shows the error box when a diagram fails to parse and no fallback is given', async () => {
21
+ mermaidMock.render.mockRejectedValue(new Error('Parse error on line 2'));
22
+ render(<MermaidDiagram code="graph TD; A-->" />);
23
+ // A document view WANTS this: a broken diagram there is a real defect the
24
+ // author should see.
25
+ expect(await screen.findByText('Mermaid diagram error')).toBeInTheDocument();
26
+ expect(screen.getByText(/Parse error on line 2/)).toBeInTheDocument();
27
+ });
28
+
29
+ /**
30
+ * The diff case. A diagram edited inside a change request reaches the
31
+ * renderer with its ```mermaid fence truncated — it CANNOT parse, by
32
+ * construction, every time. Without this the error box would replace the
33
+ * red/green source lines, which are the only useful content in that block.
34
+ */
35
+ it('renders the fallback instead of the error box when one is given', async () => {
36
+ mermaidMock.render.mockRejectedValue(new Error('Parse error on line 2'));
37
+ render(
38
+ <MermaidDiagram
39
+ code="graph TD; A-->"
40
+ errorFallback={<pre>graph TD; A--&gt;</pre>}
41
+ />,
42
+ );
43
+ await waitFor(() => expect(screen.getByText(/graph TD/)).toBeInTheDocument());
44
+ expect(screen.queryByText('Mermaid diagram error')).not.toBeInTheDocument();
45
+ expect(screen.queryByText(/Parse error/)).not.toBeInTheDocument();
46
+ });
47
+
48
+ it('renders the diagram when it parses, fallback or not', async () => {
49
+ mermaidMock.render.mockResolvedValue({ svg: '<svg data-testid="diagram"></svg>' });
50
+ const { container } = render(
51
+ <MermaidDiagram code="graph TD; A-->B" errorFallback={<pre>source</pre>} />,
52
+ );
53
+ // An UNTOUCHED diagram sits whole inside a single unchanged fragment, so it
54
+ // parses and must still render as a diagram even in a diff.
55
+ await waitFor(() => expect(container.querySelector('svg')).toBeTruthy());
56
+ expect(screen.queryByText('source')).not.toBeInTheDocument();
57
+ });
58
+ });
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import type { ComponentType } from 'react';
5
+ import { lazyRenderer } from '../lazyRenderer';
6
+ import type { FileRendererProps } from '../types';
7
+
8
+ /**
9
+ * The retry path, which is the only reason this factory is more than three
10
+ * lines. `React.lazy` memoises the loader's REJECTION as well as its success:
11
+ * the obvious implementation — one `lazy()` per renderer, an error boundary
12
+ * that clears its own flag — renders a "Try again" button that can never
13
+ * succeed, because it re-renders the same poisoned lazy component.
14
+ */
15
+
16
+ function Loaded({ content }: FileRendererProps) {
17
+ return <div>loaded: {content}</div>;
18
+ }
19
+
20
+ const props: FileRendererProps = {
21
+ content: 'hello',
22
+ filePath: 'book.xlsx',
23
+ onSave: async () => {},
24
+ };
25
+
26
+ beforeEach(() => {
27
+ // The boundary logs the caught chunk error; keep the run's output readable.
28
+ vi.spyOn(console, 'error').mockImplementation(() => {});
29
+ });
30
+
31
+ afterEach(() => {
32
+ vi.restoreAllMocks();
33
+ });
34
+
35
+ describe('lazyRenderer', () => {
36
+ it('recovers when the first import fails and the retry succeeds', async () => {
37
+ const loader = vi
38
+ .fn<() => Promise<{ default: ComponentType<FileRendererProps> }>>()
39
+ .mockRejectedValueOnce(new Error('chunk 404'))
40
+ .mockResolvedValue({ default: Loaded });
41
+
42
+ const Renderer = lazyRenderer('spreadsheet', loader);
43
+ render(<Renderer {...props} />);
44
+
45
+ // First attempt fails: the boundary catches and offers a way back.
46
+ expect(await screen.findByText(/could not load the spreadsheet viewer/i)).toBeTruthy();
47
+
48
+ await userEvent.click(screen.getByRole('button', { name: /try again/i }));
49
+
50
+ // The retry has to actually re-run the import — this is the assertion that
51
+ // fails if `Try again` merely re-renders the cached rejection.
52
+ await waitFor(() => {
53
+ expect(screen.getByText(/loaded: hello/)).toBeTruthy();
54
+ });
55
+ expect(loader).toHaveBeenCalledTimes(2);
56
+ expect(screen.queryByText(/could not load/i)).toBeNull();
57
+ });
58
+
59
+ it('renders the chunk without a retry when the first import succeeds', async () => {
60
+ const loader = vi.fn().mockResolvedValue({ default: Loaded });
61
+
62
+ const Renderer = lazyRenderer('document', loader);
63
+ render(<Renderer {...props} />);
64
+
65
+ expect(await screen.findByText(/loaded: hello/)).toBeTruthy();
66
+ expect(loader).toHaveBeenCalledTimes(1);
67
+ });
68
+ });
@@ -0,0 +1,64 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { getRendererLayout, isBinaryFile } from '../index';
3
+
4
+ /**
5
+ * The layout choice is the one thing in WP1 that cannot fail loudly: pick
6
+ * `prose` for a PDF and the `h-full` iframe collapses to zero height in an
7
+ * auto-height column, with no type error and no console warning. So the map is
8
+ * pinned here, extension by extension.
9
+ */
10
+ describe('getRendererLayout', () => {
11
+ it.each([
12
+ 'Knowledge/Foo.md',
13
+ 'Knowledge/notes.txt',
14
+ 'Knowledge/report.docx',
15
+ 'Knowledge/no-extension-file',
16
+ ])('lays out %s as a document', (path) => {
17
+ expect(getRendererLayout(path)).toBe('prose');
18
+ });
19
+
20
+ it.each([
21
+ 'Inbox/brief.pdf',
22
+ 'Inbox/diagram.png',
23
+ 'Inbox/photo.JPG',
24
+ 'Data/velocity.csv',
25
+ 'Data/book.xlsx',
26
+ 'Knowledge/page.html',
27
+ 'Tools/search.tool',
28
+ ])('lays out %s as a viewport of its own', (path) => {
29
+ expect(getRendererLayout(path)).toBe('full-bleed');
30
+ });
31
+ });
32
+
33
+ /**
34
+ * Deliberately NOT the same set as the layout map — a CSV is laid out
35
+ * full-bleed and is still text you can count. Conflating the two would make
36
+ * the rail print a character count for a PDF, which is a number nobody can
37
+ * interpret.
38
+ */
39
+ describe('isBinaryFile', () => {
40
+ it.each(['Inbox/brief.pdf', 'Inbox/diagram.png', 'Inbox/report.docx', 'Data/book.xlsx'])(
41
+ 'knows %s holds no countable text',
42
+ (path) => {
43
+ expect(isBinaryFile(path)).toBe(true);
44
+ },
45
+ );
46
+
47
+ // The one file whose bytes ARE text and still must not be counted: it goes
48
+ // to `ImageRenderer` as a picture, so the character count would describe a
49
+ // buffer nobody was shown.
50
+ it.each(['Diagrams/flow.svg', 'Diagrams/LOGO.SVG'])(
51
+ 'treats %s as an image payload, not countable text',
52
+ (path) => {
53
+ expect(isBinaryFile(path)).toBe(true);
54
+ expect(getRendererLayout(path)).toBe('full-bleed');
55
+ },
56
+ );
57
+
58
+ it.each(['Knowledge/Foo.md', 'Data/velocity.csv', 'Knowledge/page.html', 'Knowledge/notes.txt'])(
59
+ 'knows %s is text',
60
+ (path) => {
61
+ expect(isBinaryFile(path)).toBe(false);
62
+ },
63
+ );
64
+ });
@@ -0,0 +1,71 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from 'react';
2
+
3
+ /**
4
+ * The two components a lazily-loaded renderer wraps itself in.
5
+ *
6
+ * They live here rather than beside `lazyRenderer` because that module's
7
+ * export is a FACTORY, not a component. A file that mixes the two cannot be
8
+ * hot-reloaded — React Fast Refresh can only swap a module whose exports are
9
+ * all components — so `react-refresh/only-export-components` fails the lint.
10
+ * Splitting on that seam gives Fast Refresh a component-only module to swap
11
+ * and leaves the factory in a component-free one.
12
+ */
13
+
14
+ interface BoundaryProps {
15
+ children: ReactNode;
16
+ /** Shown when the chunk fails to load. */
17
+ label: string;
18
+ /**
19
+ * Ask the parent for a FRESH attempt. The boundary deliberately does not
20
+ * clear its own `failed` flag: `React.lazy` memoises a rejected loader, so
21
+ * re-rendering the same lazy component just re-throws the cached failure.
22
+ * Recovery has to come from above, by building a new lazy component and
23
+ * remounting this boundary with it.
24
+ */
25
+ onRetry(): void;
26
+ }
27
+
28
+ interface BoundaryState {
29
+ failed: boolean;
30
+ }
31
+
32
+ /**
33
+ * Not optional politeness. A dynamic import fails on a flaky network or after
34
+ * a deploy invalidates the old chunk hash; without a boundary React unmounts
35
+ * the whole tree and the user gets a blank pane with no way back.
36
+ */
37
+ export class ChunkErrorBoundary extends Component<BoundaryProps, BoundaryState> {
38
+ state: BoundaryState = { failed: false };
39
+
40
+ static getDerivedStateFromError(): BoundaryState {
41
+ return { failed: true };
42
+ }
43
+
44
+ componentDidCatch(error: Error, info: ErrorInfo) {
45
+ console.error('[renderer] failed to load viewer chunk', error, info.componentStack);
46
+ }
47
+
48
+ render() {
49
+ if (!this.state.failed) return this.props.children;
50
+ return (
51
+ <div className="flex h-full flex-col items-center justify-center gap-3 p-6 text-center">
52
+ <p className="text-ui text-ink-muted">Could not load the {this.props.label} viewer.</p>
53
+ <button
54
+ type="button"
55
+ className="rounded-full border border-line-strong px-[15px] py-[7px] text-ui font-medium text-ink transition-colors hover:bg-hover"
56
+ onClick={this.props.onRetry}
57
+ >
58
+ Try again
59
+ </button>
60
+ </div>
61
+ );
62
+ }
63
+ }
64
+
65
+ export function RendererFallback() {
66
+ return (
67
+ <div className="flex h-full items-center justify-center p-6">
68
+ <span className="text-ui text-ink-faint">Loading viewer…</span>
69
+ </div>
70
+ );
71
+ }