@bevel-software/platform-core-frontend 0.15.1 → 0.19.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 (346) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +16 -9
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/events.test.ts +43 -0
  6. package/src/core/bootstrap.ts +11 -3
  7. package/src/core/events.ts +85 -3
  8. package/src/core/registry.ts +1 -1
  9. package/src/lib/__tests__/email.test.ts +44 -0
  10. package/src/lib/email.ts +37 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  12. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  16. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  20. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
  21. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  22. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  23. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  24. package/src/modules/access/api.ts +140 -6
  25. package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
  26. package/src/modules/access/manage-access-affordance.ts +17 -0
  27. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  28. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  29. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  30. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  31. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  33. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  34. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  35. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  36. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  37. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  38. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  39. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  40. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  41. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  42. package/src/modules/admin/components/group-members-path.ts +32 -0
  43. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  44. package/src/modules/admin/services/roles.api.ts +12 -1
  45. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  46. package/src/modules/auth/components/AccountPage.tsx +73 -54
  47. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  48. package/src/modules/auth/services/account.api.ts +78 -4
  49. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  57. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  58. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  59. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  60. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  61. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  62. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  63. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  64. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  65. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  66. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  67. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  68. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  69. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  70. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  71. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  72. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  73. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  74. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  75. package/src/modules/change-requests/services/propose.api.ts +97 -8
  76. package/src/modules/change-requests/utils/approval.ts +15 -0
  77. package/src/modules/change-requests/utils/author.ts +32 -0
  78. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  79. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  80. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  81. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  82. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  83. package/src/modules/git/services/error-messages.ts +12 -0
  84. package/src/modules/git/services/pr-prompts.ts +5 -5
  85. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  86. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  87. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  88. package/src/modules/layout/components/AppLayout.tsx +2 -0
  89. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  90. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  91. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  92. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  93. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  94. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  95. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  96. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  97. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  98. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  99. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  100. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  101. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  102. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  103. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  104. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  105. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  106. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  107. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  108. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  109. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  110. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  111. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  112. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  113. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  114. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  115. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  116. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  117. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  118. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  119. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  120. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  121. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  122. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  123. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  124. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  125. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  126. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  127. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  128. package/src/modules/library/__tests__/status.test.ts +82 -2
  129. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  130. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  131. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  132. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  133. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  134. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  135. package/src/modules/library/components/LibraryCard.tsx +146 -45
  136. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  137. package/src/modules/library/components/LibraryPage.tsx +172 -39
  138. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  139. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  140. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  141. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  142. package/src/modules/library/components/PageActions.tsx +11 -9
  143. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  144. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  145. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  146. package/src/modules/library/components/PluginExtras.tsx +140 -17
  147. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  148. package/src/modules/library/components/PluginPage.tsx +157 -41
  149. package/src/modules/library/components/PluginRows.tsx +286 -0
  150. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  151. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  152. package/src/modules/library/components/ShareButton.tsx +17 -0
  153. package/src/modules/library/components/SkillsTree.tsx +141 -28
  154. package/src/modules/library/components/TeamRoute.tsx +15 -0
  155. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  156. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  157. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  158. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  159. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  160. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  161. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  162. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  163. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  164. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  165. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  166. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  167. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  168. package/src/modules/library/routes/library-paths.ts +26 -28
  169. package/src/modules/library/services/library.api.ts +38 -20
  170. package/src/modules/library/services/plugins.api.ts +69 -8
  171. package/src/modules/library/services/teams.api.ts +15 -0
  172. package/src/modules/library/services/tools.api.ts +78 -0
  173. package/src/modules/library/state/library-data.tsx +170 -32
  174. package/src/modules/library/utils/personal-plugin.ts +13 -15
  175. package/src/modules/library/utils/plugin-entries.ts +134 -0
  176. package/src/modules/library/utils/plugin-summary.ts +75 -9
  177. package/src/modules/library/utils/status.ts +135 -33
  178. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  179. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  180. package/src/modules/onboarding/agent-clients.ts +55 -23
  181. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  182. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  183. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  184. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  185. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  186. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  187. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  188. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  189. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  190. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  191. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  192. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  193. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  194. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  195. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  196. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  197. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  198. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  199. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  200. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  201. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  202. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  203. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  204. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  205. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  206. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  207. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  208. package/src/modules/settings/services/github-facade.api.ts +23 -0
  209. package/src/modules/settings/settings-nav-items.tsx +10 -2
  210. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  211. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  212. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  213. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  214. package/src/modules/setup/components/SetupGate.tsx +16 -16
  215. package/src/modules/setup/components/SetupScreen.tsx +521 -43
  216. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  217. package/src/modules/setup/services/setup.api.ts +140 -3
  218. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  219. package/src/modules/setup/utils/root-folders.ts +46 -0
  220. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  221. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  232. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  233. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  234. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  235. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  236. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  237. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  238. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  239. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  240. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  241. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  242. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  243. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  244. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  245. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  246. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  247. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  248. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  249. package/src/modules/toolbar/services/external-api-keys.api.ts +6 -0
  250. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  251. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  252. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  254. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  255. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  256. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  257. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  258. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  259. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  260. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  261. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  262. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  263. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  264. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +331 -12
  265. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  266. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  267. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  268. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  269. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  270. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  271. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  272. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  273. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  274. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  275. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  276. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  277. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  279. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  280. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  281. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  282. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  283. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  284. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  285. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  286. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  287. package/src/modules/workspace/components/renderers/index.ts +53 -2
  288. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  289. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  290. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  291. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  292. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  294. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  295. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  296. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  297. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  298. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  299. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  300. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  301. package/src/modules/workspace/services/workspace.api.ts +57 -4
  302. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  303. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  304. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  305. package/src/modules/workspace/state/workspace.context.ts +125 -19
  306. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  307. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  308. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  309. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  310. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  311. package/src/modules/workspace/utils/file-trace.ts +50 -0
  312. package/src/modules/workspace/utils/fileTree.ts +112 -36
  313. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  314. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  315. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  316. package/src/modules/workspace/utils/uploadError.ts +29 -0
  317. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  318. package/src/shared/components/Button.tsx +16 -2
  319. package/src/shared/components/Dialog.tsx +27 -11
  320. package/src/shared/components/Menu.tsx +13 -1
  321. package/src/shared/components/PageShell.tsx +13 -8
  322. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  323. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  324. package/src/shared/components/index.ts +2 -0
  325. package/src/shared/components/useDismissableMenu.ts +32 -10
  326. package/src/shared/components/useFocusHandoff.ts +51 -0
  327. package/src/shared/components/useLatestRef.ts +28 -0
  328. package/src/shared/markdown/Markdown.tsx +12 -3
  329. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  330. package/src/shared/markdown/hrefs.ts +50 -0
  331. package/src/shared/marketplace-url.ts +33 -5
  332. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  333. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  334. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  335. package/src/shared/mcp/connect-snippets.ts +14 -9
  336. package/src/shared/mcp/index.ts +1 -1
  337. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  338. package/src/shared/theme/header.ts +75 -0
  339. package/src/shared/theme/measure.ts +7 -4
  340. package/src/shared/theme/tokens.css +25 -0
  341. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  342. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  343. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  344. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  345. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  346. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -47,6 +47,33 @@ export async function listFiles(workspaceId: string): Promise<FileTreeEntry> {
47
47
  return res.json();
48
48
  }
49
49
 
50
+ /**
51
+ * The URL that serves a workspace file's bytes, `GET /api/workspace/:id/file/raw`.
52
+ *
53
+ * One builder for every consumer (the document renderers' fetches, the file
54
+ * tree's Download, and the `<img>` tags the markdown pipeline emits), so the
55
+ * route's shape lives in one place. `workspaceId` is already the URL-encoded
56
+ * branch (see `getOrCreateWorkspace`) and is used verbatim; the path is
57
+ * encoded as one query value, so `#`, `?`, `%` and spaces in a file name
58
+ * round-trip.
59
+ *
60
+ * - `download` asks for `Content-Disposition: attachment`, which the backend
61
+ * gates on the per-path `download:` verb.
62
+ * - `version` is a cache key appended as `&v=`; `0` or undefined adds nothing,
63
+ * so the URL stays stable (and browser-cacheable) until the file is known to
64
+ * have changed. See `useImageRevision`.
65
+ */
66
+ export function rawFileUrl(
67
+ workspaceId: string,
68
+ relativePath: string,
69
+ options: { download?: boolean; version?: number } = {},
70
+ ): string {
71
+ let url = `/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(relativePath)}`;
72
+ if (options.download) url += '&download=1';
73
+ if (options.version) url += `&v=${options.version}`;
74
+ return url;
75
+ }
76
+
50
77
  export async function readFile(workspaceId: string, relativePath: string): Promise<string> {
51
78
  // `_` cache-bust query parameter. The backend already sends
52
79
  // `Cache-Control: no-store` on this route, but intermediate CDNs /
@@ -62,20 +89,46 @@ export async function readFile(workspaceId: string, relativePath: string): Promi
62
89
  return data.content;
63
90
  }
64
91
 
92
+ /**
93
+ * An `allowed-tools` entry in a saved SKILL.md that looks like a platform tool
94
+ * but names none the saver can see. Advisory: the save already happened.
95
+ */
96
+ export interface SkillToolWarning {
97
+ entry: string;
98
+ message: string;
99
+ /** The closest tool name, in the entry's own spelling, when one is near. */
100
+ suggestion?: string;
101
+ }
102
+
103
+ export interface WriteFileResult {
104
+ /** Present only for a skill file whose `allowed-tools` names unknown platform tools. */
105
+ warnings?: SkillToolWarning[];
106
+ }
107
+
65
108
  export async function writeFile(
66
109
  workspaceId: string,
67
110
  relativePath: string,
68
111
  content: string,
69
- options?: { ifAbsent?: boolean },
70
- ): Promise<void> {
112
+ options?: { ifAbsent?: boolean; ifMatch?: string },
113
+ ): Promise<WriteFileResult> {
71
114
  const res = await authFetch(`/api/workspace/${workspaceId}/file?path=${encodeURIComponent(relativePath)}`, {
72
115
  method: 'PUT',
73
116
  headers: { 'Content-Type': 'application/json' },
74
117
  // `ifAbsent` asks the backend for an exclusive create — a 409 instead of
75
- // a silent replace when the target already exists.
76
- body: JSON.stringify(options?.ifAbsent ? { content, ifAbsent: true } : { content }),
118
+ // a silent replace when the target already exists. `ifMatch` is the same
119
+ // 409 for an UPDATE: the bytes the caller last read, so a save composed
120
+ // from a stale snapshot is refused instead of erasing someone else's.
121
+ body: JSON.stringify({
122
+ content,
123
+ ...(options?.ifAbsent ? { ifAbsent: true } : {}),
124
+ ...(options?.ifMatch !== undefined ? { ifMatch: options.ifMatch } : {}),
125
+ }),
77
126
  });
78
127
  if (!res.ok) throw await toApiError(res);
128
+ // The write succeeded whatever the body says; an unreadable body only
129
+ // means there is nothing to add to it.
130
+ const body = (await res.json().catch(() => null)) as { warnings?: unknown } | null;
131
+ return Array.isArray(body?.warnings) ? { warnings: body.warnings as SkillToolWarning[] } : {};
79
132
  }
80
133
 
81
134
  /**
@@ -0,0 +1,343 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { renderHook, waitFor, act } from '@testing-library/react';
3
+ import type { ReactNode } from 'react';
4
+ import type {
5
+ PullRequestSummary,
6
+ WorkflowEvent,
7
+ WorkflowEventPayload,
8
+ } from '@bevel-software/platform-shared';
9
+
10
+ const api = vi.hoisted(() => ({
11
+ listOpenChangeRequests: vi.fn(),
12
+ listMyChangeRequests: vi.fn(),
13
+ }));
14
+ vi.mock('../../../change-requests/services/change-requests.api', () => ({
15
+ listOpenChangeRequests: api.listOpenChangeRequests,
16
+ listMyChangeRequests: api.listMyChangeRequests,
17
+ readFileOnBranch: vi.fn(),
18
+ }));
19
+
20
+ import { OpenChangeRequestsProvider } from '../open-change-requests';
21
+ import { useOpenChangeRequests } from '../../hooks/useOpenChangeRequests';
22
+ import { WorkspaceContext, type WorkspaceContextValue } from '../workspace.context';
23
+ import { ChangeRequestStaleBinder } from '../../../workflow/state/ChangeRequestStaleBinder';
24
+ import {
25
+ EventBusContext,
26
+ type EventBusContextValue,
27
+ } from '../../../workflow/state/event-bus.context';
28
+ import { PR_STALE_COALESCE_MS, PR_STALE_FALLBACK_MS } from '../../../../core/events';
29
+
30
+ /**
31
+ * The reported bug: a business user uploads into a folder they cannot write
32
+ * (a suggestion-routed change request), an admin applies it, and the request
33
+ * keeps showing as pending.
34
+ *
35
+ * Reproduced cause: the merge WAS broadcast to every session
36
+ * (`change-request-merged` is a global event), but nothing on the page
37
+ * listened for it except the clicking tab's own apply hook, which ignores
38
+ * requests it did not start. The tree's open-request provider refreshes only
39
+ * on the in-page stale event, and only the clicker's tab ever dispatched that.
40
+ * So the submitter's suggestion rows and every other viewer's markers stayed
41
+ * until a manual reload, and a lost event stranded even the clicker's
42
+ * sibling tabs, because the provider had no fallback read at all.
43
+ *
44
+ * Each test renders ONE viewer's tab: the bus binder mounted by the app shell,
45
+ * the provider, and a fake bus the test drives as the server would.
46
+ */
47
+
48
+ const KB = 'knowledge-base';
49
+ const SKILL = 'Plugins/x/SKILL.md';
50
+ const ACCESS = 'Plugins/x/access.md';
51
+
52
+ function pr(over: Partial<PullRequestSummary> = {}): PullRequestSummary {
53
+ return {
54
+ number: 7,
55
+ title: 'Upload into Plugins/x',
56
+ author: { login: 'user-bo' },
57
+ appAuthor: { name: 'Bo Business' },
58
+ branch: 'suggestions/bo/knowledge',
59
+ base: 'main',
60
+ state: 'open',
61
+ createdAt: '2026-09-16T09:00:00.000Z',
62
+ touchedNodePaths: [SKILL],
63
+ review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
64
+ url: '/change-requests/7',
65
+ ...over,
66
+ };
67
+ }
68
+
69
+ function fakeBus() {
70
+ const handlers = new Map<string, Set<(e: WorkflowEvent) => void>>();
71
+ const value: EventBusContextValue = {
72
+ subscribe: (kind, handler) => {
73
+ const set = handlers.get(kind) ?? new Set();
74
+ set.add(handler as (e: WorkflowEvent) => void);
75
+ handlers.set(kind, set);
76
+ return () => set.delete(handler as (e: WorkflowEvent) => void);
77
+ },
78
+ setFocus: () => {},
79
+ watchWorkspace: () => () => {},
80
+ };
81
+ const emit = (event: WorkflowEventPayload) => {
82
+ for (const h of handlers.get(event.kind) ?? []) {
83
+ h({ id: 1, ts: new Date().toISOString(), ...event } as WorkflowEvent);
84
+ }
85
+ };
86
+ return { value, emit };
87
+ }
88
+
89
+ /** The server's answer before the apply (request open) and after (merged). */
90
+ function serverHasOpenRequest(open: boolean, opts: { submitter?: boolean } = {}) {
91
+ api.listOpenChangeRequests.mockResolvedValue(open ? [pr()] : []);
92
+ api.listMyChangeRequests.mockResolvedValue(
93
+ opts.submitter ? [pr({ state: open ? 'open' : 'merged' })] : [],
94
+ );
95
+ }
96
+
97
+ function renderTab(bus: EventBusContextValue | null) {
98
+ const wrapper = ({ children }: { children: ReactNode }) => (
99
+ <EventBusContext.Provider value={bus}>
100
+ <WorkspaceContext.Provider value={{ kbDirName: KB } as unknown as WorkspaceContextValue}>
101
+ <ChangeRequestStaleBinder />
102
+ <OpenChangeRequestsProvider>{children}</OpenChangeRequestsProvider>
103
+ </WorkspaceContext.Provider>
104
+ </EventBusContext.Provider>
105
+ );
106
+ return renderHook(() => useOpenChangeRequests(), { wrapper });
107
+ }
108
+
109
+ const pending = (r: { current: ReturnType<typeof useOpenChangeRequests> }) =>
110
+ r.current.paths.has(`${KB}/${SKILL}`);
111
+
112
+ beforeEach(() => {
113
+ api.listOpenChangeRequests.mockReset();
114
+ api.listMyChangeRequests.mockReset();
115
+ });
116
+
117
+ describe('an applied change request stops showing as pending — for every viewer', () => {
118
+ it('the admin who applied: the marker clears on the merged event', async () => {
119
+ serverHasOpenRequest(true);
120
+ const bus = fakeBus();
121
+ const { result } = renderTab(bus.value);
122
+ await waitFor(() => expect(pending(result)).toBe(true));
123
+
124
+ serverHasOpenRequest(false);
125
+ act(() => bus.emit({ kind: 'change-request-merged', number: 7 }));
126
+ await waitFor(() => expect(pending(result)).toBe(false));
127
+ // The refetch bypasses the server's list cache.
128
+ expect(api.listOpenChangeRequests).toHaveBeenLastCalledWith({ fresh: true });
129
+ });
130
+
131
+ it('the submitter (upload into a folder they cannot write): the suggestion rows clear too', async () => {
132
+ serverHasOpenRequest(true, { submitter: true });
133
+ const bus = fakeBus();
134
+ const { result } = renderTab(bus.value);
135
+ await waitFor(() => expect(result.current.minePaths.get(`${KB}/${SKILL}`)).toBe(7));
136
+
137
+ // The upload also announced the request optimistically in this tab.
138
+ act(() => {
139
+ window.dispatchEvent(
140
+ new CustomEvent('bevel:suggestions-optimistic', {
141
+ detail: pr({ touchedNodePaths: [SKILL, 'Plugins/x/extra.md'] }),
142
+ }),
143
+ );
144
+ });
145
+ expect(result.current.mineNumbers.has(7)).toBe(true);
146
+ // The merge happens later than the announcement, never in the same instant.
147
+ await new Promise((r) => setTimeout(r, 5));
148
+
149
+ serverHasOpenRequest(false, { submitter: true });
150
+ act(() => bus.emit({ kind: 'change-request-merged', number: 7 }));
151
+ await waitFor(() => expect(result.current.mineNumbers.has(7)).toBe(false));
152
+ expect(result.current.minePaths.size).toBe(0);
153
+ expect(pending(result)).toBe(false);
154
+ });
155
+
156
+ it('a viewer who can read the folder’s access.md but not its content: same basis before and after', async () => {
157
+ serverHasOpenRequest(true);
158
+ const bus = fakeBus();
159
+ const { result } = renderTab(bus.value);
160
+ await waitFor(() => expect(pending(result)).toBe(true));
161
+ // The request never touched the one file this viewer can open, so no box
162
+ // or tab marker is offered there before the apply…
163
+ expect(result.current.forPath(`${KB}/${ACCESS}`)).toEqual([]);
164
+
165
+ serverHasOpenRequest(false);
166
+ act(() => bus.emit({ kind: 'change-request-merged', number: 7 }));
167
+ await waitFor(() => expect(pending(result)).toBe(false));
168
+ // …nor after it, and nothing is left behind for the hidden content.
169
+ expect(result.current.forPath(`${KB}/${ACCESS}`)).toEqual([]);
170
+ expect(result.current.forPath(`${KB}/${SKILL}`)).toEqual([]);
171
+ });
172
+
173
+ it('a reload shows the same', async () => {
174
+ serverHasOpenRequest(false, { submitter: true });
175
+ const { result } = renderTab(fakeBus().value);
176
+ await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalled());
177
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalled());
178
+ expect(pending(result)).toBe(false);
179
+ expect(result.current.minePaths.size).toBe(0);
180
+ });
181
+
182
+ it('a declined request and a failed apply refresh every viewer too, and so does a resync', async () => {
183
+ serverHasOpenRequest(true);
184
+ const bus = fakeBus();
185
+ renderTab(bus.value);
186
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(1));
187
+
188
+ act(() => bus.emit({ kind: 'change-request-rejected', number: 7 }));
189
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(2));
190
+ act(() => bus.emit({ kind: 'change-request-apply-failed', number: 7 }));
191
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(3));
192
+ act(() => bus.emit({ kind: 'resync', reason: 'buffer overflow' }));
193
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(4));
194
+ });
195
+
196
+ it('a request opened in another session shows up without waiting for the fallback', async () => {
197
+ serverHasOpenRequest(false);
198
+ const bus = fakeBus();
199
+ const { result } = renderTab(bus.value);
200
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(1));
201
+ expect(pending(result)).toBe(false);
202
+
203
+ serverHasOpenRequest(true);
204
+ act(() =>
205
+ bus.emit({
206
+ kind: 'change-request-opened',
207
+ number: 7,
208
+ source: 'suggestions/bo/knowledge',
209
+ target: 'main',
210
+ authorIdHash: null,
211
+ title: 'Upload into Plugins/x',
212
+ }),
213
+ );
214
+ await waitFor(() => expect(pending(result)).toBe(true));
215
+ });
216
+
217
+ it('older reads of either list resolving after the merge refresh do not restore the marker', async () => {
218
+ // The submitter's tab: the request is in the broad list AND in /mine, and
219
+ // both feed the tree's markers and suggestion rows.
220
+ serverHasOpenRequest(true, { submitter: true });
221
+ const bus = fakeBus();
222
+ const { result } = renderTab(bus.value);
223
+ await waitFor(() => expect(result.current.mineNumbers.has(7)).toBe(true));
224
+
225
+ // Reads that left before the merge (a fallback poll) are still in flight…
226
+ let releaseOldOpen!: (v: PullRequestSummary[]) => void;
227
+ let releaseOldMine!: (v: PullRequestSummary[]) => void;
228
+ api.listOpenChangeRequests.mockReturnValueOnce(
229
+ new Promise((r) => {
230
+ releaseOldOpen = r;
231
+ }),
232
+ );
233
+ api.listMyChangeRequests.mockReturnValueOnce(
234
+ new Promise((r) => {
235
+ releaseOldMine = r;
236
+ }),
237
+ );
238
+ act(() => bus.emit({ kind: 'change-request-rejected', number: 99 }));
239
+ // Past the coalescing window, so that read has actually left before…
240
+ await act(() => new Promise<void>((resolve) => setTimeout(resolve, PR_STALE_COALESCE_MS * 3)));
241
+ // …the merge lands and the refresh reads the truth.
242
+ serverHasOpenRequest(false, { submitter: true });
243
+ act(() => bus.emit({ kind: 'change-request-merged', number: 7 }));
244
+ await waitFor(() => expect(pending(result)).toBe(false));
245
+ expect(result.current.mineNumbers.has(7)).toBe(false);
246
+
247
+ // Both stale answers still say "open".
248
+ await act(async () => {
249
+ releaseOldOpen([pr()]);
250
+ releaseOldMine([pr()]);
251
+ });
252
+ expect(pending(result)).toBe(false);
253
+ expect(result.current.mineNumbers.has(7)).toBe(false);
254
+ expect(result.current.minePaths.size).toBe(0);
255
+ });
256
+ });
257
+
258
+ /**
259
+ * Arms a stand-in for the provider's fallback interval: the test fires it by
260
+ * hand instead of faking the clock, because faked intervals would also stall
261
+ * `waitFor`'s own polling. Every other interval runs for real.
262
+ */
263
+ function captureFallback() {
264
+ const realSet = globalThis.setInterval;
265
+ const realClear = globalThis.clearInterval;
266
+ const armed = new Map<number, { fn: () => void; ms: number }>();
267
+ let next = 1_000_000;
268
+ const set = vi.spyOn(globalThis, 'setInterval').mockImplementation(((
269
+ fn: () => void,
270
+ ms?: number,
271
+ ...rest: unknown[]
272
+ ) => {
273
+ if (ms !== PR_STALE_FALLBACK_MS) return realSet(fn, ms, ...rest);
274
+ const id = next++;
275
+ armed.set(id, { fn, ms });
276
+ return id;
277
+ }) as unknown as typeof setInterval);
278
+ const clear = vi.spyOn(globalThis, 'clearInterval').mockImplementation(((id: number) => {
279
+ if (armed.delete(id)) return;
280
+ realClear(id);
281
+ }) as unknown as typeof clearInterval);
282
+ return {
283
+ armedCount: () => armed.size,
284
+ fire: () => act(() => armed.forEach((a) => a.fn())),
285
+ restore: () => {
286
+ set.mockRestore();
287
+ clear.mockRestore();
288
+ },
289
+ };
290
+ }
291
+
292
+ describe('a lost event: the page reconciles from the server within the fallback window', () => {
293
+ let fallback: ReturnType<typeof captureFallback>;
294
+ let hidden: ReturnType<typeof vi.spyOn> | null = null;
295
+ beforeEach(() => {
296
+ fallback = captureFallback();
297
+ });
298
+ afterEach(() => {
299
+ fallback.restore();
300
+ // Released whatever the test's outcome: a `document.hidden` spy left behind
301
+ // would silence every visibility-gated read in the tests after it.
302
+ hidden?.mockRestore();
303
+ hidden = null;
304
+ });
305
+
306
+ it('clears the marker on the next fallback read, with no event and no reload', async () => {
307
+ serverHasOpenRequest(true);
308
+ // A bus that never delivers the merge.
309
+ const { result } = renderTab(fakeBus().value);
310
+ await waitFor(() => expect(pending(result)).toBe(true));
311
+ // Armed on the shared window, the same one the review dock polls on.
312
+ expect(fallback.armedCount()).toBe(1);
313
+
314
+ serverHasOpenRequest(false);
315
+ fallback.fire();
316
+ await waitFor(() => expect(pending(result)).toBe(false));
317
+ });
318
+
319
+ it('a hidden tab skips the fallback read and catches up the moment it is shown', async () => {
320
+ serverHasOpenRequest(true);
321
+ const { result } = renderTab(fakeBus().value);
322
+ await waitFor(() => expect(pending(result)).toBe(true));
323
+ hidden = vi.spyOn(document, 'hidden', 'get').mockReturnValue(true);
324
+
325
+ serverHasOpenRequest(false);
326
+ fallback.fire();
327
+ expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(1);
328
+
329
+ hidden.mockReturnValue(false);
330
+ act(() => {
331
+ document.dispatchEvent(new Event('visibilitychange'));
332
+ });
333
+ await waitFor(() => expect(pending(result)).toBe(false));
334
+ });
335
+
336
+ it('stops reading once the page is gone', async () => {
337
+ serverHasOpenRequest(true);
338
+ const { unmount } = renderTab(fakeBus().value);
339
+ await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(1));
340
+ unmount();
341
+ expect(fallback.armedCount()).toBe(0);
342
+ });
343
+ });
@@ -0,0 +1,158 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { renderHook, waitFor, act } from '@testing-library/react';
3
+ import type { ReactNode } from 'react';
4
+ import type { FileTreeEntry, PullRequestSummary } from '@bevel-software/platform-shared';
5
+
6
+ const api = vi.hoisted(() => ({
7
+ listOpenChangeRequests: vi.fn(),
8
+ listMyChangeRequests: vi.fn(),
9
+ }));
10
+ vi.mock('../../../change-requests/services/change-requests.api', () => ({
11
+ listOpenChangeRequests: api.listOpenChangeRequests,
12
+ listMyChangeRequests: api.listMyChangeRequests,
13
+ readFileOnBranch: vi.fn(),
14
+ }));
15
+
16
+ import { OpenChangeRequestsProvider } from '../open-change-requests';
17
+ import { useMergedWorkspaceTree } from '../../hooks/useMergedWorkspaceTree';
18
+ import { WorkspaceContext } from '../workspace.context';
19
+ import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
20
+ import { SUGGESTIONS_OPTIMISTIC_EVENT, PR_STALE_EVENT } from '../../../../core/events';
21
+
22
+ /**
23
+ * The third of the three reports: "the file did not appear until I reloaded".
24
+ *
25
+ * A suggestion-routed upload puts nothing on the branch being viewed — the
26
+ * bytes are on the caller's personal suggestions branch — so the row the user
27
+ * gets back is synthesized from their own open change requests. The server's
28
+ * `touchedNodePaths` are produced by a `git diff` the background commit worker
29
+ * can trail by many seconds, which is why the upload ANNOUNCES the paths the
30
+ * moment they land and the provider merges the announcement until a real fetch
31
+ * covers them.
32
+ *
33
+ * Both halves matter and both are pinned here: the row is there immediately
34
+ * after the drop, and it is still there after the refetch that follows it.
35
+ * Written against `Skills/`, the folder the report came from — the tree's
36
+ * hidden-root rule drops a synthesized row whose top-level folder is missing
37
+ * from the branch, and `Skills/` is exactly the kind of reserved root that
38
+ * rule was written about.
39
+ */
40
+
41
+ const KB = 'knowledge-base';
42
+ const DROPPED = 'Skills/house-writing-standards/report.pdf';
43
+ const ROW = `${KB}/${DROPPED}`;
44
+
45
+ /** The branch as the viewer sees it: `Skills/` exists, the dropped file does not. */
46
+ const BRANCH_TREE: FileTreeEntry = {
47
+ name: '.',
48
+ relativePath: '.',
49
+ type: 'directory',
50
+ children: [{
51
+ name: KB,
52
+ relativePath: KB,
53
+ type: 'directory',
54
+ children: [{
55
+ name: 'Skills',
56
+ relativePath: `${KB}/Skills`,
57
+ type: 'directory',
58
+ children: [{
59
+ name: 'house-writing-standards',
60
+ relativePath: `${KB}/Skills/house-writing-standards`,
61
+ type: 'directory',
62
+ children: [],
63
+ }],
64
+ }],
65
+ }],
66
+ };
67
+
68
+ function cr(over: Partial<PullRequestSummary> = {}): PullRequestSummary {
69
+ return {
70
+ number: 12,
71
+ title: 'Changes from Bo Business. Knowledge',
72
+ author: { login: 'user-bo' },
73
+ branch: 'suggestions/bo/knowledge',
74
+ base: 'main',
75
+ state: 'open',
76
+ createdAt: '2026-09-17T09:00:00.000Z',
77
+ // What the server says BEFORE its diff has caught up with the commit.
78
+ touchedNodePaths: [],
79
+ review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
80
+ url: '/change-requests/12',
81
+ ...over,
82
+ } as PullRequestSummary;
83
+ }
84
+
85
+ function wrapper({ children }: { children: ReactNode }) {
86
+ return (
87
+ <WorkspaceContext.Provider
88
+ value={makeWorkspaceFixture({ kbDirName: KB, fileTree: BRANCH_TREE })}
89
+ >
90
+ <OpenChangeRequestsProvider>{children}</OpenChangeRequestsProvider>
91
+ </WorkspaceContext.Provider>
92
+ );
93
+ }
94
+
95
+ /** Every path the merged tree draws a row for. */
96
+ function pathsIn(node: FileTreeEntry | null): string[] {
97
+ if (!node) return [];
98
+ return [node.relativePath, ...(node.children ?? []).flatMap(pathsIn)];
99
+ }
100
+
101
+ describe('a suggestion-routed upload shows up where it was dropped', () => {
102
+ beforeEach(() => {
103
+ api.listOpenChangeRequests.mockReset().mockResolvedValue([]);
104
+ api.listMyChangeRequests.mockReset().mockResolvedValue([]);
105
+ });
106
+
107
+ afterEach(() => {
108
+ vi.restoreAllMocks();
109
+ });
110
+
111
+ it("draws the proposed row from the upload's own announcement, before any refetch", async () => {
112
+ const { result } = renderHook(() => useMergedWorkspaceTree(), { wrapper });
113
+ await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalled());
114
+ expect(pathsIn(result.current.tree)).not.toContain(ROW);
115
+
116
+ // What `dispatchUpload` fires the moment the bytes are committed.
117
+ await act(async () => {
118
+ window.dispatchEvent(
119
+ new CustomEvent(SUGGESTIONS_OPTIMISTIC_EVENT, {
120
+ detail: cr({ touchedNodePaths: [DROPPED] }),
121
+ }),
122
+ );
123
+ });
124
+
125
+ expect(result.current.suggestionOnlyPaths.get(ROW)).toBe(12);
126
+ expect(pathsIn(result.current.tree)).toContain(ROW);
127
+ });
128
+
129
+ it('keeps the row when the refetch that follows the upload answers', async () => {
130
+ const { result } = renderHook(() => useMergedWorkspaceTree(), { wrapper });
131
+ await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalled());
132
+
133
+ // The announcement and the stale event go out together, as the upload
134
+ // sends them — the refetch starts before the server's diff has the path.
135
+ await act(async () => {
136
+ window.dispatchEvent(
137
+ new CustomEvent(SUGGESTIONS_OPTIMISTIC_EVENT, {
138
+ detail: cr({ touchedNodePaths: [DROPPED] }),
139
+ }),
140
+ );
141
+ api.listMyChangeRequests.mockResolvedValue([cr()]);
142
+ window.dispatchEvent(new Event(PR_STALE_EVENT));
143
+ });
144
+ await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalledTimes(2));
145
+ // The lagging answer does not take the row away again.
146
+ expect(pathsIn(result.current.tree)).toContain(ROW);
147
+
148
+ // And once the server's own diff carries the path, the row is the
149
+ // server's — same row, no flicker in between.
150
+ await act(async () => {
151
+ api.listMyChangeRequests.mockResolvedValue([cr({ touchedNodePaths: [DROPPED] })]);
152
+ window.dispatchEvent(new Event(PR_STALE_EVENT));
153
+ });
154
+ await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalledTimes(3));
155
+ expect(result.current.suggestionOnlyPaths.get(ROW)).toBe(12);
156
+ expect(pathsIn(result.current.tree)).toContain(ROW);
157
+ });
158
+ });