@bevel-software/platform-core-frontend 0.14.0 → 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 (360) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +34 -26
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/bootstrap.test.ts +33 -1
  6. package/src/core/__tests__/events.test.ts +43 -0
  7. package/src/core/bootstrap.ts +38 -1
  8. package/src/core/events.ts +85 -3
  9. package/src/core/registry.ts +1 -1
  10. package/src/lib/__tests__/api.test.ts +38 -0
  11. package/src/lib/__tests__/email.test.ts +44 -0
  12. package/src/lib/api.ts +19 -2
  13. package/src/lib/email.ts +37 -1
  14. package/src/lib/utils.ts +2 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  16. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  20. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  21. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  22. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  23. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  24. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +781 -76
  25. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  26. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  27. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  28. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  29. package/src/modules/access/api.ts +192 -10
  30. package/src/modules/access/components/ManageAccessDialog.tsx +1337 -570
  31. package/src/modules/access/manage-access-affordance.ts +17 -0
  32. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  33. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  34. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  35. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  36. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  37. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  38. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  39. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  40. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  41. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  42. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  43. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  44. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  45. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  46. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  47. package/src/modules/admin/components/group-members-path.ts +32 -0
  48. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  49. package/src/modules/admin/services/roles.api.ts +12 -1
  50. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  51. package/src/modules/auth/components/AccountPage.tsx +73 -54
  52. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  53. package/src/modules/auth/services/account.api.ts +78 -4
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  58. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  59. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  60. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  61. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  62. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  63. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  64. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  65. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  66. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  67. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  68. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  69. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  70. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  71. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  72. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  73. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  74. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  75. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  76. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  77. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  78. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  79. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  80. package/src/modules/change-requests/services/propose.api.ts +97 -8
  81. package/src/modules/change-requests/utils/approval.ts +15 -0
  82. package/src/modules/change-requests/utils/author.ts +32 -0
  83. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  84. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  85. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  86. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  87. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  88. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  89. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  90. package/src/modules/git/services/error-messages.ts +12 -0
  91. package/src/modules/git/services/pr-prompts.ts +5 -5
  92. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  93. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  94. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  95. package/src/modules/layout/components/AppLayout.tsx +2 -0
  96. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  97. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  98. package/src/modules/layout/components/SidebarFrame.tsx +109 -4
  99. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  100. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  101. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  102. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  103. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  104. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +104 -99
  105. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +136 -0
  106. package/src/modules/library/__tests__/LockedPluginView.test.tsx +103 -7
  107. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +18 -8
  108. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  109. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  110. package/src/modules/library/__tests__/PluginExtras.test.tsx +115 -9
  111. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  112. package/src/modules/library/__tests__/PluginPage.test.tsx +453 -7
  113. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +17 -57
  114. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +161 -97
  115. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  116. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  117. package/src/modules/library/__tests__/SkillPage.test.tsx +391 -78
  118. package/src/modules/library/__tests__/SkillsTree.test.tsx +461 -0
  119. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  120. package/src/modules/library/__tests__/ToolPage.test.tsx +94 -4
  121. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +279 -21
  122. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  123. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  124. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  125. package/src/modules/library/__tests__/library-data.stale.test.tsx +183 -0
  126. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  127. package/src/modules/library/__tests__/library-paths.test.ts +75 -0
  128. package/src/modules/library/__tests__/link-membership.test.ts +129 -0
  129. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  130. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  131. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  132. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  133. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  134. package/src/modules/library/__tests__/plugin-summary.test.ts +67 -0
  135. package/src/modules/library/__tests__/status.test.ts +82 -2
  136. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  137. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  138. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  139. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  140. package/src/modules/library/components/AddToPluginDialog.tsx +107 -18
  141. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  142. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  143. package/src/modules/library/components/LibraryCard.tsx +149 -34
  144. package/src/modules/library/components/LibraryLayout.tsx +120 -247
  145. package/src/modules/library/components/LibraryPage.tsx +172 -39
  146. package/src/modules/library/components/LinkSkillPanel.tsx +169 -0
  147. package/src/modules/library/components/LockedPluginView.tsx +63 -35
  148. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  149. package/src/modules/library/components/NewPluginDialog.tsx +19 -5
  150. package/src/modules/library/components/PageActions.tsx +31 -9
  151. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  152. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  153. package/src/modules/library/components/PersonalPluginPage.tsx +123 -23
  154. package/src/modules/library/components/PluginExtras.tsx +143 -18
  155. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  156. package/src/modules/library/components/PluginPage.tsx +234 -38
  157. package/src/modules/library/components/PluginRows.tsx +286 -0
  158. package/src/modules/library/components/PluginsSidebar.tsx +271 -238
  159. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  160. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  161. package/src/modules/library/components/ShareButton.tsx +17 -0
  162. package/src/modules/library/components/SkillsTree.tsx +204 -0
  163. package/src/modules/library/components/StatusDot.tsx +1 -0
  164. package/src/modules/library/components/TeamRoute.tsx +15 -0
  165. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  166. package/src/modules/library/components/plugin-page-parts.tsx +132 -23
  167. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +212 -0
  168. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  169. package/src/modules/library/components/skill-page/SkillPage.tsx +337 -121
  170. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  171. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  172. package/src/modules/library/components/tool-page/ToolPage.tsx +116 -17
  173. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  174. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  175. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  176. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  177. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  178. package/src/modules/library/routes/WorkspaceItemRoute.tsx +229 -82
  179. package/src/modules/library/routes/library-paths.ts +46 -35
  180. package/src/modules/library/services/library.api.ts +89 -17
  181. package/src/modules/library/services/plugins.api.ts +161 -9
  182. package/src/modules/library/services/teams.api.ts +15 -0
  183. package/src/modules/library/services/tools.api.ts +78 -0
  184. package/src/modules/library/state/library-data.tsx +268 -37
  185. package/src/modules/library/utils/personal-plugin.ts +13 -15
  186. package/src/modules/library/utils/plugin-entries.ts +134 -0
  187. package/src/modules/library/utils/plugin-summary.ts +102 -0
  188. package/src/modules/library/utils/status.ts +204 -35
  189. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +11 -3
  190. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  191. package/src/modules/onboarding/agent-clients.ts +55 -23
  192. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  193. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  194. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  195. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  196. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  197. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  198. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  199. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  200. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  201. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  202. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  203. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  204. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  205. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  206. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  207. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  208. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  209. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  210. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  211. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  212. package/src/modules/settings/components/ClaudeConnectionCard.tsx +154 -0
  213. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  214. package/src/modules/settings/components/DeploymentPage.tsx +16 -22
  215. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  216. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  217. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +74 -1
  218. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  219. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  220. package/src/modules/settings/services/github-facade.api.ts +66 -0
  221. package/src/modules/settings/settings-nav-items.tsx +10 -2
  222. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  223. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  224. package/src/modules/setup/__tests__/setup.test.tsx +615 -4
  225. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  226. package/src/modules/setup/components/SetupGate.tsx +16 -16
  227. package/src/modules/setup/components/SetupScreen.tsx +711 -40
  228. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  229. package/src/modules/setup/services/setup.api.ts +218 -3
  230. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  231. package/src/modules/setup/utils/root-folders.ts +46 -0
  232. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  233. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  234. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  235. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  236. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  237. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  238. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  239. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  240. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  241. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  242. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  243. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  244. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  245. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  246. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  247. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  248. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +395 -124
  249. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  250. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  251. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  252. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +659 -36
  253. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  254. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  255. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  256. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  257. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  258. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  259. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  260. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  261. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  262. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  263. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  264. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  265. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  266. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  267. package/src/modules/workspace/__tests__/testFixtures.ts +6 -3
  268. package/src/modules/workspace/components/FileExplorer.tsx +1527 -367
  269. package/src/modules/workspace/components/FileRoute.tsx +376 -22
  270. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  271. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  272. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  273. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  274. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  275. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +768 -16
  276. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +332 -12
  277. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  278. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  279. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  280. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  281. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  282. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  283. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  284. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  285. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  286. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  287. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  288. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  289. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  290. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  291. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  292. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  293. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  294. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  295. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  296. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  297. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  298. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  299. package/src/modules/workspace/components/renderers/index.ts +53 -2
  300. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  301. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  302. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  303. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  304. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  305. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  306. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  307. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +89 -0
  308. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  309. package/src/modules/workspace/hooks/useWorkspaceState.ts +438 -66
  310. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  311. package/src/modules/workspace/routing/kb-routes.ts +207 -30
  312. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  313. package/src/modules/workspace/services/workspace.api.ts +57 -4
  314. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  315. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  316. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  317. package/src/modules/workspace/state/workspace.context.ts +130 -16
  318. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  319. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +234 -5
  320. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  321. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  322. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  323. package/src/modules/workspace/utils/file-trace.ts +50 -0
  324. package/src/modules/workspace/utils/fileTree.ts +126 -52
  325. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  326. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  327. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  328. package/src/modules/workspace/utils/uploadError.ts +29 -0
  329. package/src/shared/__tests__/marketplace-url.test.ts +59 -0
  330. package/src/shared/components/Badge.tsx +3 -1
  331. package/src/shared/components/Banner.tsx +5 -1
  332. package/src/shared/components/Button.tsx +16 -2
  333. package/src/shared/components/Dialog.tsx +27 -11
  334. package/src/shared/components/Menu.tsx +13 -1
  335. package/src/shared/components/PageShell.tsx +13 -8
  336. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  337. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  338. package/src/shared/components/index.ts +2 -0
  339. package/src/shared/components/useDismissableMenu.ts +32 -10
  340. package/src/shared/components/useFocusHandoff.ts +51 -0
  341. package/src/shared/components/useLatestRef.ts +28 -0
  342. package/src/shared/markdown/Markdown.tsx +12 -3
  343. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  344. package/src/shared/markdown/hrefs.ts +50 -0
  345. package/src/shared/marketplace-url.ts +118 -0
  346. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  347. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  348. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  349. package/src/shared/mcp/connect-snippets.ts +14 -9
  350. package/src/shared/mcp/index.ts +1 -1
  351. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  352. package/src/shared/theme/header.ts +75 -0
  353. package/src/shared/theme/measure.ts +7 -4
  354. package/src/shared/theme/tokens.css +34 -0
  355. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  356. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  357. package/src/modules/library/components/PluginsIndexPage.tsx +0 -265
  358. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  359. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  360. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -7,8 +7,8 @@ import { renderHook, act, waitFor } from '@testing-library/react';
7
7
  const apiMocks = vi.hoisted(() => {
8
8
  class FakeWorkspaceApiError extends Error {
9
9
  status: number;
10
- constructor(status: number) {
11
- super(`HTTP ${status}`);
10
+ constructor(status: number, message?: string) {
11
+ super(message ?? `HTTP ${status}`);
12
12
  this.status = status;
13
13
  this.name = 'WorkspaceApiError';
14
14
  }
@@ -46,8 +46,28 @@ import type { ReactNode } from 'react';
46
46
  import { AuthContext } from '../../../auth/state/auth.context';
47
47
  import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../../core/events';
48
48
  import { useWorkspaceState } from '../useWorkspaceState';
49
+ import {
50
+ KNOWLEDGE_UPLOAD_TARGET,
51
+ libraryUploadTarget,
52
+ type UploadError,
53
+ type UploadNotice,
54
+ } from '../../state/workspace.context';
55
+ import { FILE_TRACE_STORAGE_KEY } from '../../utils/file-trace';
49
56
  const WorkspaceApiError = apiMocks.WorkspaceApiError;
50
57
 
58
+ /**
59
+ * The upload banners are keyed by the tree that took the drop, so every
60
+ * assertion about one names its tree. `KNOWLEDGE_UPLOAD_TARGET` is what a
61
+ * `dispatchUpload` with no target of its own lands under.
62
+ */
63
+ interface UploadBanners {
64
+ uploadNotices: ReadonlyMap<string, UploadNotice>;
65
+ uploadErrors: ReadonlyMap<string, UploadError>;
66
+ }
67
+ const noticeIn = (s: UploadBanners, target = KNOWLEDGE_UPLOAD_TARGET) => s.uploadNotices.get(target) ?? null;
68
+ const errorIn = (s: UploadBanners, target = KNOWLEDGE_UPLOAD_TARGET) => s.uploadErrors.get(target) ?? null;
69
+
70
+
51
71
  const WORKSPACE_FIXTURE = {
52
72
  workspace: {
53
73
  id: 'ws-1',
@@ -296,21 +316,293 @@ describe('useWorkspaceState multi-tab', () => {
296
316
  expect(result.current.openFileSavedContent).toBe('content:a.md');
297
317
  });
298
318
 
299
- it('persists tabs to localStorage after hydrate, debounced', async () => {
319
+ /**
320
+ * The reproduction's "URL and open file disagree after fast clicks": click
321
+ * several unopened files, then one that is already open. Reopening an open
322
+ * tab took a shortcut that skipped the "latest open" token, so the last
323
+ * still-in-flight read counted as the newest intent and activated ITS file
324
+ * when it landed — the URL naming one file and the screen showing another,
325
+ * indefinitely.
326
+ */
327
+ it('reopening an already-open tab outranks an older read still in flight', async () => {
300
328
  const result = await mountReady();
329
+ await act(async () => { await result.current.addTab('b.md'); });
330
+ expect(result.current.activeTab?.path).toBe('b.md');
331
+
332
+ // A click on an unopened file: its read hangs.
333
+ let releaseRead: ((content: string) => void) | undefined;
334
+ apiMocks.readFile.mockImplementation(
335
+ () => new Promise<string>((resolve) => { releaseRead = resolve; }),
336
+ );
337
+ let slowOpen: Promise<boolean> | undefined;
338
+ act(() => { slowOpen = result.current.addTab('a.md'); });
339
+
340
+ // A click on `b.md`, which is already open — the last thing the user asked for.
341
+ await act(async () => { await result.current.addTab('b.md'); });
342
+ expect(result.current.activeTab?.path).toBe('b.md');
343
+
344
+ // Now `a.md` arrives. It opens its tab, but it does NOT steal the focus.
345
+ await act(async () => {
346
+ releaseRead?.('content:a.md');
347
+ await slowOpen;
348
+ });
349
+ expect(result.current.openTabs.map((t) => t.path)).toEqual(['b.md', 'a.md']);
350
+ expect(result.current.activeTab?.path).toBe('b.md');
351
+ });
352
+
353
+ it('persists tabs to localStorage after hydrate, debounced', async () => {
354
+ // A real workspace id IS the encoded branch, and the persistence key is
355
+ // built from the branch the workspace turned out to be — so the fixture
356
+ // has to be a branch-shaped id, not an opaque one.
357
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
358
+ ...WORKSPACE_FIXTURE,
359
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
360
+ });
361
+ const { result } = renderHook(() => useWorkspaceState());
362
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
301
363
  act(() => { result.current.setPersistenceBranch('alice/draft'); });
302
364
  await act(async () => { await result.current.hydrateTabs(['a.md', 'b.md'], 'b.md'); });
303
365
  await act(async () => { await result.current.addTab('c.md'); });
304
366
 
305
367
  // Wait for the 200ms debounce to flush.
306
368
  await waitFor(() => {
307
- const raw = localStorage.getItem('bevel.tabs.ws-1.alice/draft');
369
+ const raw = localStorage.getItem('bevel.tabs.alice%2Fdraft.alice/draft');
308
370
  expect(raw).not.toBeNull();
309
371
  const parsed = JSON.parse(raw!);
310
372
  expect(parsed.paths).toEqual(['a.md', 'b.md', 'c.md']);
311
373
  expect(parsed.activePath).toBe('c.md');
312
374
  });
313
375
  });
376
+
377
+ /**
378
+ * A restore and an open are different claims. The open says "this file is
379
+ * what I want ACTIVE"; the restore says "these tabs are this branch's".
380
+ * Sharing one token made an ordinary click mid-restore look like it had
381
+ * retired the restore: the branch's whole tab list was dropped on the floor,
382
+ * and — the marker for "this key has been hydrated" never being set —
383
+ * persistence for that branch stayed off, so the list was never written
384
+ * again either. The click wins the focus; it does not empty the strip.
385
+ */
386
+ it('an open during a hydration keeps the focus without discarding the restored tabs', async () => {
387
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
388
+ ...WORKSPACE_FIXTURE,
389
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
390
+ });
391
+ const { result } = renderHook(() => useWorkspaceState());
392
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
393
+ act(() => { result.current.setPersistenceBranch('alice/draft'); });
394
+
395
+ // The restore's reads hang; the click's read answers at once.
396
+ const pendingReads: ((content: string) => void)[] = [];
397
+ apiMocks.readFile.mockImplementation(async (_wsId: string, path: string) => {
398
+ if (path === 'c.md') return 'content:c.md';
399
+ return new Promise<string>((resolve) => { pendingReads.push(resolve); });
400
+ });
401
+
402
+ let hydration: Promise<unknown> | undefined;
403
+ act(() => { hydration = result.current.hydrateTabs(['a.md', 'b.md'], 'b.md'); });
404
+ await act(async () => { await result.current.addTab('c.md'); });
405
+ expect(result.current.activeTab?.path).toBe('c.md');
406
+
407
+ await act(async () => {
408
+ for (const resolve of pendingReads) resolve('content:restored');
409
+ await hydration;
410
+ });
411
+
412
+ // Every restored tab is there, alongside the one the user clicked, and the
413
+ // click keeps the focus it claimed.
414
+ expect(result.current.openTabs.map((t) => t.path)).toEqual(['a.md', 'b.md', 'c.md']);
415
+ expect(result.current.activeTab?.path).toBe('c.md');
416
+
417
+ // And persistence is live for this branch: the restore counted.
418
+ await waitFor(() => {
419
+ const raw = localStorage.getItem('bevel.tabs.alice%2Fdraft.alice/draft');
420
+ expect(raw).not.toBeNull();
421
+ expect(JSON.parse(raw!).paths).toEqual(['a.md', 'b.md', 'c.md']);
422
+ });
423
+ });
424
+
425
+ /**
426
+ * The other half of the same split: a NEWER RESTORE does retire an older
427
+ * one, and the older one has to say so. A caller that recorded it as done
428
+ * would mark the branch hydrated on the strength of a result that never
429
+ * reached the screen.
430
+ */
431
+ it('reports a hydration overtaken by a newer hydration as superseded', async () => {
432
+ const { result } = await (async () => {
433
+ const r = renderHook(() => useWorkspaceState());
434
+ await waitFor(() => expect(r.result.current.workspaceId).toBe('ws-1'));
435
+ return r;
436
+ })();
437
+
438
+ const pendingReads: ((content: string) => void)[] = [];
439
+ apiMocks.readFile.mockImplementation(
440
+ () => new Promise<string>((resolve) => { pendingReads.push(resolve); }),
441
+ );
442
+ let first: Promise<{ superseded: boolean }> | undefined;
443
+ act(() => { first = result.current.hydrateTabs(['a.md'], 'a.md'); });
444
+
445
+ apiMocks.readFile.mockImplementation(async (_wsId: string, path: string) => `content:${path}`);
446
+ await act(async () => { await result.current.hydrateTabs(['b.md'], 'b.md'); });
447
+
448
+ let firstResult: { superseded: boolean } | undefined;
449
+ await act(async () => {
450
+ for (const resolve of pendingReads) resolve('content:a.md');
451
+ firstResult = await first;
452
+ });
453
+ expect(firstResult?.superseded).toBe(true);
454
+ // The newer restore's strip stands, untouched by the older one.
455
+ expect(result.current.openTabs.map((t) => t.path)).toEqual(['b.md']);
456
+ });
457
+
458
+ /**
459
+ * The crossed key from the reproduction: `bevel.tabs.main.someone/draft` —
460
+ * one branch's workspace under another branch's name. It was written
461
+ * mid-switch, because the persistence key took its branch from
462
+ * `persistenceBranch`, which points at the branch being switched TO from the
463
+ * instant the switch starts, while `workspaceId` still serves the branch
464
+ * being left. Tabs are persisted under the key of the branch they were READ
465
+ * from, or not at all.
466
+ */
467
+ it('never persists one branch\'s tabs under another branch\'s key during a switch', async () => {
468
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
469
+ ...WORKSPACE_FIXTURE,
470
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'main' },
471
+ });
472
+ const { result } = renderHook(() => useWorkspaceState());
473
+ await waitFor(() => expect(result.current.workspaceId).toBe('main'));
474
+
475
+ act(() => { result.current.setPersistenceBranch('main'); });
476
+ await act(async () => { await result.current.hydrateTabs(['a.md'], 'a.md'); });
477
+ await waitFor(() => {
478
+ expect(localStorage.getItem('bevel.tabs.main.main')).not.toBeNull();
479
+ });
480
+
481
+ // A second hydration against `main` goes in flight…
482
+ const pendingReads: ((content: string) => void)[] = [];
483
+ apiMocks.readFile.mockImplementation(
484
+ () => new Promise<string>((resolve) => { pendingReads.push(resolve); }),
485
+ );
486
+ let hydration: Promise<unknown> | undefined;
487
+ act(() => { hydration = result.current.hydrateTabs(['a.md', 'b.md'], 'b.md'); });
488
+
489
+ // …and mid-flight the user switches away. `persistenceBranch` moves to the
490
+ // destination immediately; the destination's workspace never arrives.
491
+ apiMocks.getOrCreateWorkspace.mockImplementation(() => new Promise(() => {}));
492
+ act(() => { result.current.setPersistenceBranch('someone/draft'); });
493
+
494
+ // Now `main`'s reads land. These bytes belong to `main` and to no other key.
495
+ await act(async () => {
496
+ for (const resolve of pendingReads) resolve('content:from-main');
497
+ await hydration;
498
+ });
499
+ await new Promise((r) => setTimeout(r, 300));
500
+
501
+ expect(localStorage.getItem('bevel.tabs.main.someone/draft')).toBeNull();
502
+ expect(localStorage.getItem('bevel.tabs.someone%2Fdraft.someone/draft')).toBeNull();
503
+ expect(JSON.parse(localStorage.getItem('bevel.tabs.main.main')!).paths)
504
+ .toEqual(['a.md', 'b.md']);
505
+ });
506
+
507
+ /**
508
+ * A restore overtaken by a click MERGES into the strip rather than replacing
509
+ * it. If the strip still held the branch being left, the merge carried those
510
+ * tabs over: shown on the new branch with the old branch's text, and
511
+ * persisted under the new branch's key. The strip belongs to the workspace
512
+ * it was read from, so a new workspace starts it empty.
513
+ */
514
+ it('a click during a switch never carries the previous branch\'s tabs into the new one', async () => {
515
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
516
+ ...WORKSPACE_FIXTURE,
517
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'main' },
518
+ });
519
+ const { result } = renderHook(() => useWorkspaceState());
520
+ await waitFor(() => expect(result.current.workspaceId).toBe('main'));
521
+ act(() => { result.current.setPersistenceBranch('main'); });
522
+ await act(async () => { await result.current.hydrateTabs(['only-on-main.md'], 'only-on-main.md'); });
523
+ expect(result.current.openTabs.map((t) => t.path)).toEqual(['only-on-main.md']);
524
+
525
+ // Switch to the draft; its workspace arrives.
526
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
527
+ ...WORKSPACE_FIXTURE,
528
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
529
+ });
530
+ act(() => { result.current.setPersistenceBranch('alice/draft'); });
531
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
532
+
533
+ // The draft's restore hangs; the user clicks a file meanwhile.
534
+ const pendingReads: ((content: string) => void)[] = [];
535
+ apiMocks.readFile.mockImplementation(async (_wsId: string, path: string) => {
536
+ if (path === 'clicked.md') return 'content:clicked.md';
537
+ return new Promise<string>((resolve) => { pendingReads.push(resolve); });
538
+ });
539
+ let hydration: Promise<unknown> | undefined;
540
+ act(() => { hydration = result.current.hydrateTabs(['restored.md'], 'restored.md'); });
541
+ await act(async () => { await result.current.addTab('clicked.md'); });
542
+ await act(async () => {
543
+ for (const resolve of pendingReads) resolve('content:restored.md');
544
+ await hydration;
545
+ });
546
+
547
+ // Only the draft's tabs: the restored one and the clicked one.
548
+ expect(result.current.openTabs.map((t) => t.path)).toEqual(['restored.md', 'clicked.md']);
549
+ await waitFor(() => {
550
+ const raw = localStorage.getItem('bevel.tabs.alice%2Fdraft.alice/draft');
551
+ expect(raw).not.toBeNull();
552
+ expect(JSON.parse(raw!).paths).toEqual(['restored.md', 'clicked.md']);
553
+ });
554
+ });
555
+
556
+ /**
557
+ * The last read without a workspace guard: activating a tab whose bytes an
558
+ * fs bump invalidated re-reads it in the background. If the branch switches
559
+ * while that read is in flight, the tab of the same path on the new branch
560
+ * is not the one it was for — its answer, bytes or a 404, is about the
561
+ * branch that was left.
562
+ */
563
+ it.each([
564
+ ['bytes', (resolve: (c: string) => void) => resolve('content:from-main')],
565
+ ['a 404', (_resolve: (c: string) => void, reject: (e: unknown) => void) => reject(new WorkspaceApiError(404))],
566
+ ])('an activate re-read from the branch left behind lands nowhere (%s)', async (_label, settle) => {
567
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
568
+ ...WORKSPACE_FIXTURE,
569
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'main' },
570
+ });
571
+ const { result } = renderHook(() => useWorkspaceState());
572
+ await waitFor(() => expect(result.current.workspaceId).toBe('main'));
573
+ await act(async () => { await result.current.addTab('shared.md'); });
574
+ await act(async () => { await result.current.addTab('other.md'); });
575
+ // An fs bump invalidates the inactive tab; re-activating it re-reads.
576
+ act(() => { result.current.bumpFsRevision(); });
577
+ await waitFor(() => {
578
+ expect(result.current.openTabs.find((t) => t.path === 'shared.md')?.content).toBeNull();
579
+ });
580
+ let resolveOld: (c: string) => void = () => {};
581
+ let rejectOld: (e: unknown) => void = () => {};
582
+ apiMocks.readFile.mockImplementation((wsId: string, path: string) => {
583
+ if (wsId === 'main') {
584
+ return new Promise<string>((resolve, reject) => { resolveOld = resolve; rejectOld = reject; });
585
+ }
586
+ return Promise.resolve(`content:draft:${path}`);
587
+ });
588
+ const invalidated = result.current.openTabs.find((t) => t.path === 'shared.md')!;
589
+ act(() => { result.current.activateTab(invalidated); });
590
+
591
+ // Switch to the draft and open the same path there.
592
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
593
+ ...WORKSPACE_FIXTURE,
594
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
595
+ });
596
+ act(() => { result.current.setPersistenceBranch('alice/draft'); });
597
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
598
+ await act(async () => { await result.current.addTab('shared.md'); });
599
+
600
+ // main's answer arrives late.
601
+ await act(async () => { settle(resolveOld, rejectOld); await Promise.resolve(); });
602
+
603
+ const draftTab = result.current.openTabs.find((t) => t.path === 'shared.md');
604
+ expect(draftTab?.content).toBe('content:draft:shared.md');
605
+ });
314
606
  });
315
607
 
316
608
 
@@ -424,14 +716,68 @@ describe('dispatchUpload: suggestion routing', () => {
424
716
  const detail = (onAnnounce.mock.calls[0][0] as CustomEvent).detail;
425
717
  expect(detail.number).toBe(12);
426
718
  expect(detail.touchedNodePaths).toContain('KnowledgeBase/Ops/note.md');
427
- expect(result.current.uploadNotice).toMatch(/became a suggestion/);
428
- expect(result.current.uploadError).toBeNull();
719
+ expect(noticeIn(result.current)?.message).toMatch(/became a suggestion/);
720
+ expect(noticeIn(result.current)?.kind).toBe('suggestion');
721
+ // …and where to undo it. The notice used to say a thing happened and
722
+ // nothing about reversing it, and the accent-coloured row it produces
723
+ // said nothing either — which is how an accidental upload into a folder
724
+ // you cannot write came to read as permanent.
725
+ expect(noticeIn(result.current)?.message).toMatch(
726
+ /To take it back, right-click the file and choose Withdraw suggestion\.$/,
727
+ );
728
+ expect(errorIn(result.current)).toBeNull();
429
729
  } finally {
430
730
  window.removeEventListener(PR_STALE_EVENT, onStale);
431
731
  window.removeEventListener(SUGGESTIONS_OPTIMISTIC_EVENT, onAnnounce);
432
732
  }
433
733
  });
434
734
 
735
+ it('refuses an upload into a folder the caller cannot READ — no suggestion, no bytes, a banner', async () => {
736
+ accessApiMock.fetchFileAccess.mockResolvedValue({
737
+ canRead: false,
738
+ canWrite: false,
739
+ eligible: { roles: [], users: [] },
740
+ owners: { roles: [], users: [] },
741
+ });
742
+ const result = await mountProtected();
743
+ const file = new File(['hello'], 'brief.pdf', { type: 'application/pdf' });
744
+ await act(async () => {
745
+ await result.current.dispatchUpload(
746
+ { kind: 'files', files: [file] },
747
+ 'knowledge-base/KnowledgeBase/Sealed',
748
+ );
749
+ });
750
+ // Nothing was provisioned and nothing moved: the same gate would have
751
+ // refused every file on the suggestions branch, one by one.
752
+ expect(proposeMocks.ensureKnowledgeSuggestionWorkspace).not.toHaveBeenCalled();
753
+ expect(apiMocks.uploadFile).not.toHaveBeenCalled();
754
+ // The refusal is in this tree's banner, with the server's sentence and
755
+ // the status its gate would have answered.
756
+ expect(errorIn(result.current)).toMatchObject({
757
+ filename: 'brief.pdf',
758
+ status: 403,
759
+ reason: 'You don\'t have read access to "KnowledgeBase/Sealed"; only what you can read can be created, changed or removed.',
760
+ });
761
+ expect(result.current.isUploading).toBe(false);
762
+ });
763
+
764
+ it('leaves a folder directly under a root to the server: a drop there may start a new folder', async () => {
765
+ accessApiMock.fetchFileAccess.mockResolvedValue({
766
+ canRead: false,
767
+ canWrite: false,
768
+ eligible: { roles: [], users: [] },
769
+ owners: { roles: [], users: [] },
770
+ });
771
+ const result = await mountProtected();
772
+ const file = new File(['hello'], 'note.md', { type: 'text/markdown' });
773
+ await act(async () => {
774
+ await result.current.dispatchUpload({ kind: 'files', files: [file] }, 'knowledge-base/KnowledgeBase');
775
+ });
776
+ // Routed as any no-write folder is; the server decides per file.
777
+ expect(proposeMocks.ensureKnowledgeSuggestionWorkspace).toHaveBeenCalled();
778
+ expect(errorIn(result.current)).toBeNull();
779
+ });
780
+
435
781
  it('uploads normally when the caller may write the folder', async () => {
436
782
  accessApiMock.fetchFileAccess.mockResolvedValue({
437
783
  canWrite: true,
@@ -454,7 +800,7 @@ describe('dispatchUpload: suggestion routing', () => {
454
800
  { defer: false },
455
801
  );
456
802
  expect(proposeMocks.ensureKnowledgeSuggestionWorkspace).not.toHaveBeenCalled();
457
- expect(result.current.uploadNotice).toBeNull();
803
+ expect(noticeIn(result.current)).toBeNull();
458
804
  });
459
805
 
460
806
  it('never routes on a draft branch, even without write access', async () => {
@@ -481,3 +827,542 @@ describe('dispatchUpload: suggestion routing', () => {
481
827
  );
482
828
  });
483
829
  });
830
+
831
+ /**
832
+ * The reported silence: "first upload to Skills, nothing happened; second one
833
+ * showed the message". Reproduced from the code path, because the difference
834
+ * between the two uploads is entirely in how long the FIRST one takes to
835
+ * learn where the bytes go.
836
+ *
837
+ * Every scrap of feedback used to wait on `resolveSuggestionRouting`, and the
838
+ * first suggestion of a session is the one time that answer is slow: the
839
+ * server creates the caller's personal branch and clones a workspace for it
840
+ * before `ensureKnowledgeSuggestionWorkspace` resolves, and only then is the
841
+ * change request opened. A suggestion-routed upload also draws no optimistic
842
+ * rows, deliberately — the files never land on the branch being viewed — so
843
+ * for the whole of that wait the tree showed nothing whatsoever: no spinner,
844
+ * no row, no banner. The SECOND upload finds the branch, the workspace and
845
+ * the open request all there and answers at once, which is the whole of the
846
+ * difference the user saw.
847
+ *
848
+ * The fix is to say something on the first tick, in the tree that took the
849
+ * drop. These tests pin that, and pin that the result still replaces it.
850
+ */
851
+ describe('dispatchUpload: the drop is never silent', () => {
852
+ const PROTECTED_FIXTURE = {
853
+ workspace: {
854
+ id: 'target-company-state',
855
+ name: 'Workspace',
856
+ absolutePath: '/tmp/ws',
857
+ createdAt: '2026-04-20T00:00:00.000Z',
858
+ kbDirName: 'knowledge-base',
859
+ },
860
+ fileTree: { name: '.', relativePath: '.', type: 'directory' as const, children: [] },
861
+ };
862
+
863
+ /** The Library's Skills tree — the surface the report came from. */
864
+ const SKILLS_TREE = libraryUploadTarget('Skills');
865
+ const SKILLS_FOLDER = 'knowledge-base/Skills/house-writing-standards';
866
+
867
+ const SUGGESTION_TARGET = {
868
+ branch: 'suggestions/reader/knowledge',
869
+ workspaceId: 'suggestions%2Freader%2Fknowledge',
870
+ kbDirName: 'knowledge-base',
871
+ existingCr: null,
872
+ };
873
+
874
+ const CHANGE_REQUEST = {
875
+ number: 12,
876
+ title: 'Changes from Rae Reader. Knowledge',
877
+ branch: 'suggestions/reader/knowledge',
878
+ base: 'target-company-state',
879
+ state: 'open',
880
+ createdAt: '2026-09-17T00:00:00.000Z',
881
+ touchedNodePaths: [],
882
+ author: { login: 'user-x' },
883
+ review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
884
+ url: '',
885
+ };
886
+
887
+ function wrapper({ children }: { children: ReactNode }) {
888
+ return (
889
+ <AuthContext.Provider
890
+ value={{
891
+ user: { id: 'u1', email: 'bo@example.com', name: 'Bo Business' },
892
+ token: 't',
893
+ isLoading: false,
894
+ login: async () => {},
895
+ logout: () => {},
896
+ }}
897
+ >
898
+ {children}
899
+ </AuthContext.Provider>
900
+ );
901
+ }
902
+
903
+ /** Every relativePath in a server tree, for "did the row arrive?". */
904
+ function pathsIn(node: { relativePath: string; children?: unknown[] } | null): string[] {
905
+ if (!node) return [];
906
+ const out = [node.relativePath];
907
+ for (const child of (node.children ?? []) as { relativePath: string; children?: unknown[] }[]) {
908
+ out.push(...pathsIn(child));
909
+ }
910
+ return out;
911
+ }
912
+
913
+ beforeEach(() => {
914
+ apiMocks.getOrCreateWorkspace.mockReset().mockResolvedValue(PROTECTED_FIXTURE);
915
+ apiMocks.listFiles.mockReset().mockResolvedValue(PROTECTED_FIXTURE.fileTree);
916
+ apiMocks.uploadFile.mockReset().mockResolvedValue(undefined);
917
+ accessApiMock.fetchFileAccess.mockReset();
918
+ proposeMocks.ensureKnowledgeSuggestionWorkspace.mockReset().mockResolvedValue(SUGGESTION_TARGET);
919
+ proposeMocks.ensureKnowledgeChangeRequest.mockReset().mockResolvedValue(CHANGE_REQUEST);
920
+ });
921
+
922
+ afterEach(() => {
923
+ vi.restoreAllMocks();
924
+ localStorage.clear();
925
+ });
926
+
927
+ async function mountProtected() {
928
+ const { result } = renderHook(() => useWorkspaceState(), { wrapper });
929
+ await waitFor(() => expect(result.current.workspaceId).toBe('target-company-state'));
930
+ return result;
931
+ }
932
+
933
+ it('reports the drop before the suggestion routing has answered', async () => {
934
+ accessApiMock.fetchFileAccess.mockResolvedValue({
935
+ canWrite: false,
936
+ eligible: { roles: [], users: [] },
937
+ owners: { roles: [], users: [] },
938
+ });
939
+ // The FIRST suggestion of a session: the branch and its workspace clone do
940
+ // not exist yet, so this is the call that takes seconds. Held open here so
941
+ // the assertions land inside the window the user was staring at.
942
+ let releaseRouting: (target: typeof SUGGESTION_TARGET) => void = () => {};
943
+ proposeMocks.ensureKnowledgeSuggestionWorkspace.mockReturnValue(
944
+ new Promise((resolve) => { releaseRouting = resolve; }),
945
+ );
946
+ const result = await mountProtected();
947
+
948
+ const file = new File(['hello'], 'report.pdf', { type: 'application/pdf' });
949
+ let dispatched: Promise<void> | undefined;
950
+ await act(async () => {
951
+ dispatched = result.current.dispatchUpload(
952
+ { kind: 'files', files: [file] },
953
+ SKILLS_FOLDER,
954
+ SKILLS_TREE,
955
+ );
956
+ await Promise.resolve();
957
+ });
958
+
959
+ // Nothing has been uploaded yet, and nothing is going to appear in this
960
+ // branch's tree when it is — so the notice is the only thing there is.
961
+ expect(apiMocks.uploadFile).not.toHaveBeenCalled();
962
+ expect(result.current.isUploading).toBe(true);
963
+ expect(noticeIn(result.current, SKILLS_TREE)).toEqual({
964
+ kind: 'progress',
965
+ message: 'Adding report.pdf to house-writing-standards…',
966
+ });
967
+
968
+ await act(async () => {
969
+ releaseRouting(SUGGESTION_TARGET);
970
+ await dispatched;
971
+ });
972
+
973
+ // The result replaces it — in the same tree, once.
974
+ expect(result.current.uploadNotices.size).toBe(1);
975
+ expect(noticeIn(result.current, SKILLS_TREE)).toEqual({
976
+ kind: 'suggestion',
977
+ message: expect.stringContaining('became a suggestion'),
978
+ });
979
+ expect(errorIn(result.current, SKILLS_TREE)).toBeNull();
980
+ expect(result.current.isUploading).toBe(false);
981
+ });
982
+
983
+ it('says so on the FIRST suggestion as reliably as on a repeat', async () => {
984
+ accessApiMock.fetchFileAccess.mockResolvedValue({
985
+ canWrite: false,
986
+ eligible: { roles: [], users: [] },
987
+ owners: { roles: [], users: [] },
988
+ });
989
+ const result = await mountProtected();
990
+ const upload = (name: string) =>
991
+ act(async () => {
992
+ await result.current.dispatchUpload(
993
+ { kind: 'files', files: [new File(['x'], name)] },
994
+ SKILLS_FOLDER,
995
+ SKILLS_TREE,
996
+ );
997
+ });
998
+
999
+ // First: the branch has to be made and the request opened.
1000
+ await upload('first.pdf');
1001
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('suggestion');
1002
+ expect(result.current.uploadNotices.size).toBe(1);
1003
+
1004
+ // Second: the request is already there, so nothing is created.
1005
+ proposeMocks.ensureKnowledgeSuggestionWorkspace.mockResolvedValue({
1006
+ ...SUGGESTION_TARGET,
1007
+ existingCr: CHANGE_REQUEST,
1008
+ });
1009
+ await upload('second.pdf');
1010
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('suggestion');
1011
+ expect(result.current.uploadNotices.size).toBe(1);
1012
+ });
1013
+
1014
+ // Two drops in flight at once. The notices are per-TREE and the progress
1015
+ // one is retired per-tree too, because over a single shared slot the drop
1016
+ // that settled first pulled the other's notice off the screen — and a
1017
+ // suggestion-routed upload has nothing else to show, so that drop went
1018
+ // silent, which is the whole failure this feature exists to prevent.
1019
+ it('keeps a second drop\u2019s notice when the first settles', async () => {
1020
+ accessApiMock.fetchFileAccess.mockImplementation(async (_ws: string, path: string) => ({
1021
+ // The Knowledge drop may write (ordinary upload, settles at once); the
1022
+ // Skills drop may not, so it goes off to the routing round-trip.
1023
+ canWrite: !path.startsWith('Skills/'),
1024
+ eligible: { roles: [], users: [] },
1025
+ owners: { roles: [], users: [] },
1026
+ }));
1027
+ let releaseRouting: (target: typeof SUGGESTION_TARGET) => void = () => {};
1028
+ proposeMocks.ensureKnowledgeSuggestionWorkspace.mockReturnValue(
1029
+ new Promise((resolve) => { releaseRouting = resolve; }),
1030
+ );
1031
+ const result = await mountProtected();
1032
+
1033
+ // The slow one first: dropped into Skills, still waiting on its branch.
1034
+ let skillsDrop: Promise<void> | undefined;
1035
+ await act(async () => {
1036
+ skillsDrop = result.current.dispatchUpload(
1037
+ { kind: 'files', files: [new File(['x'], 'report.pdf')] },
1038
+ SKILLS_FOLDER,
1039
+ SKILLS_TREE,
1040
+ );
1041
+ await Promise.resolve();
1042
+ });
1043
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('progress');
1044
+
1045
+ // And an ordinary drop into Knowledge, which runs to completion.
1046
+ await act(async () => {
1047
+ await result.current.dispatchUpload(
1048
+ { kind: 'files', files: [new File(['y'], 'note.md')] },
1049
+ 'knowledge-base/KnowledgeBase/Ops',
1050
+ );
1051
+ });
1052
+
1053
+ // Knowledge has its rows and no notice; Skills is still waiting, and is
1054
+ // still saying so.
1055
+ expect(noticeIn(result.current)).toBeNull();
1056
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('progress');
1057
+
1058
+ await act(async () => {
1059
+ releaseRouting(SUGGESTION_TARGET);
1060
+ await skillsDrop;
1061
+ });
1062
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('suggestion');
1063
+ });
1064
+
1065
+ // Same tree, two drops: the first to finish must not retire the notice the
1066
+ // second is still relying on.
1067
+ it('keeps the notice up while a sibling drop into the same tree is still running', async () => {
1068
+ accessApiMock.fetchFileAccess.mockResolvedValue({
1069
+ canWrite: true,
1070
+ eligible: { roles: [], users: [] },
1071
+ owners: { roles: [], users: [] },
1072
+ });
1073
+ // The second drop's ACL answer is held, so it is still in its pre-UI
1074
+ // window when the first drop settles.
1075
+ let releaseSecondAcl: () => void = () => {};
1076
+ const result = await mountProtected();
1077
+
1078
+ // `dispatchUpload` is async, but its prefix — the error reset, the
1079
+ // progress notice, `isUploading` — runs synchronously on the call, so the
1080
+ // start goes inside `act` like every other dispatch in this file. The
1081
+ // `await first` below still works: the captured promise resolves in
1082
+ // flight.
1083
+ let first: Promise<void> | undefined;
1084
+ act(() => {
1085
+ first = result.current.dispatchUpload(
1086
+ { kind: 'files', files: [new File(['x'], 'one.md')] },
1087
+ 'knowledge-base/KnowledgeBase/Ops',
1088
+ );
1089
+ });
1090
+ accessApiMock.fetchFileAccess.mockReturnValue(new Promise((resolve) => {
1091
+ releaseSecondAcl = () => resolve({
1092
+ canWrite: true,
1093
+ eligible: { roles: [], users: [] },
1094
+ owners: { roles: [], users: [] },
1095
+ });
1096
+ }));
1097
+ let second: Promise<void> | undefined;
1098
+ await act(async () => {
1099
+ second = result.current.dispatchUpload(
1100
+ { kind: 'files', files: [new File(['y'], 'two.md')] },
1101
+ 'knowledge-base/KnowledgeBase/Ops',
1102
+ );
1103
+ await first;
1104
+ });
1105
+
1106
+ // The first is done. The second has drawn nothing yet — its notice is
1107
+ // all it has, and it is still there.
1108
+ expect(noticeIn(result.current)?.kind).toBe('progress');
1109
+
1110
+ await act(async () => {
1111
+ releaseSecondAcl();
1112
+ await second;
1113
+ });
1114
+ expect(noticeIn(result.current)).toBeNull();
1115
+ });
1116
+
1117
+ // A drop still routing when the user changes branch never runs its own
1118
+ // cleanup — its result belongs to the branch it was dispatched from. Left
1119
+ // alone, its "Adding …" sat over the new tree forever.
1120
+ it('drops the banners of a branch the user has left', async () => {
1121
+ accessApiMock.fetchFileAccess.mockResolvedValue({
1122
+ canWrite: false,
1123
+ eligible: { roles: [], users: [] },
1124
+ owners: { roles: [], users: [] },
1125
+ });
1126
+ let releaseRouting: (target: typeof SUGGESTION_TARGET) => void = () => {};
1127
+ proposeMocks.ensureKnowledgeSuggestionWorkspace.mockReturnValue(
1128
+ new Promise((resolve) => { releaseRouting = resolve; }),
1129
+ );
1130
+ const result = await mountProtected();
1131
+
1132
+ let dropped: Promise<void> | undefined;
1133
+ await act(async () => {
1134
+ dropped = result.current.dispatchUpload(
1135
+ { kind: 'files', files: [new File(['x'], 'report.pdf')] },
1136
+ SKILLS_FOLDER,
1137
+ SKILLS_TREE,
1138
+ );
1139
+ await Promise.resolve();
1140
+ });
1141
+ expect(noticeIn(result.current, SKILLS_TREE)?.kind).toBe('progress');
1142
+
1143
+ // Off to another branch while the routing is still open.
1144
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
1145
+ ...PROTECTED_FIXTURE,
1146
+ workspace: { ...PROTECTED_FIXTURE.workspace, id: 'alice%2Fdraft' },
1147
+ });
1148
+ act(() => { result.current.setPersistenceBranch('alice/draft'); });
1149
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
1150
+ expect(result.current.uploadNotices.size).toBe(0);
1151
+
1152
+ // And the stale upload settling later does not put it back.
1153
+ await act(async () => {
1154
+ releaseRouting(SUGGESTION_TARGET);
1155
+ await dropped;
1156
+ });
1157
+ expect(result.current.uploadNotices.size).toBe(0);
1158
+ expect(result.current.uploadErrors.size).toBe(0);
1159
+ });
1160
+
1161
+ it('hands an ordinary upload over to its rows, which survive the refresh', async () => {
1162
+ accessApiMock.fetchFileAccess.mockResolvedValue({
1163
+ canWrite: true,
1164
+ eligible: { roles: [], users: [] },
1165
+ owners: { roles: [], users: [] },
1166
+ });
1167
+ const uploadedPath = 'knowledge-base/KnowledgeBase/Ops/note.md';
1168
+ /** The server's tree, with the uploaded file in it or without. */
1169
+ const serverTree = (withNote: boolean) => ({
1170
+ name: '.',
1171
+ relativePath: '.',
1172
+ type: 'directory' as const,
1173
+ children: [{
1174
+ name: 'knowledge-base',
1175
+ relativePath: 'knowledge-base',
1176
+ type: 'directory' as const,
1177
+ children: [{
1178
+ name: 'KnowledgeBase',
1179
+ relativePath: 'knowledge-base/KnowledgeBase',
1180
+ type: 'directory' as const,
1181
+ children: [{
1182
+ name: 'Ops',
1183
+ relativePath: 'knowledge-base/KnowledgeBase/Ops',
1184
+ type: 'directory' as const,
1185
+ children: withNote
1186
+ ? [{ name: 'note.md', relativePath: uploadedPath, type: 'file' as const }]
1187
+ : [],
1188
+ }],
1189
+ }],
1190
+ }],
1191
+ });
1192
+ // The commit is what puts the file on the server, so every read BEFORE it
1193
+ // answers without the file. Staggered deliberately: with the finished tree
1194
+ // mocked from the start, the bootstrap fetch alone would satisfy "the row
1195
+ // is there" and the test would pass with the post-upload refresh deleted —
1196
+ // which is the regression it exists to catch.
1197
+ let committed = false;
1198
+ apiMocks.listFiles.mockImplementation(async () => serverTree(committed));
1199
+ // Hold the upload open so the mid-flight state is observable.
1200
+ let releaseUpload: () => void = () => {};
1201
+ apiMocks.uploadFile.mockReturnValue(new Promise<void>((resolve) => {
1202
+ releaseUpload = () => { committed = true; resolve(); };
1203
+ }));
1204
+ const result = await mountProtected();
1205
+ // Nothing has been uploaded yet, so nothing in the tree on screen is the
1206
+ // file — anything asserting otherwise later had to be put there by the
1207
+ // upload.
1208
+ expect(pathsIn(result.current.fileTree)).not.toContain(uploadedPath);
1209
+
1210
+ let dispatched: Promise<void> | undefined;
1211
+ act(() => {
1212
+ dispatched = result.current.dispatchUpload(
1213
+ { kind: 'files', files: [new File(['hi'], 'note.md')] },
1214
+ 'knowledge-base/KnowledgeBase/Ops',
1215
+ );
1216
+ });
1217
+
1218
+ // The optimistic row is in the tree within the frame — and because it is,
1219
+ // the progress notice steps aside rather than sitting over it.
1220
+ await waitFor(() => expect(result.current.pendingUploads.has(uploadedPath)).toBe(true));
1221
+ await waitFor(() => expect(noticeIn(result.current)).toBeNull());
1222
+ // Mid-flight the server still has no such file: the row on screen is the
1223
+ // optimistic one, and nothing else.
1224
+ expect(pathsIn(result.current.fileTree)).not.toContain(uploadedPath);
1225
+
1226
+ await act(async () => {
1227
+ releaseUpload();
1228
+ await dispatched;
1229
+ });
1230
+
1231
+ // The real row arrives and the optimistic one is retired — no reload.
1232
+ await waitFor(() => expect(pathsIn(result.current.fileTree)).toContain(uploadedPath));
1233
+ await waitFor(() => expect(result.current.pendingUploads.has(uploadedPath)).toBe(false));
1234
+ expect(noticeIn(result.current)).toBeNull();
1235
+ expect(errorIn(result.current)).toBeNull();
1236
+ });
1237
+
1238
+ it('names the file, not its workspace path, and stamps the tree that asked', async () => {
1239
+ accessApiMock.fetchFileAccess.mockResolvedValue({
1240
+ canWrite: true,
1241
+ eligible: { roles: [], users: [] },
1242
+ owners: { roles: [], users: [] },
1243
+ });
1244
+ const reason = 'You do not have permission to write to Knowledge/Legal';
1245
+ // The refusal as it arrives: the backend's words AND the status the
1246
+ // banner's next step is chosen from.
1247
+ apiMocks.uploadFile.mockRejectedValue(new WorkspaceApiError(403, reason));
1248
+ const result = await mountProtected();
1249
+
1250
+ await act(async () => {
1251
+ await result.current.dispatchUpload(
1252
+ { kind: 'files', files: [new File(['x'], 'quarterly-report.pdf')] },
1253
+ SKILLS_FOLDER,
1254
+ SKILLS_TREE,
1255
+ );
1256
+ });
1257
+
1258
+ // "Couldn't add knowledge-base/K…" was the whole of the reported banner:
1259
+ // a path long enough that the reason never made it onto the screen.
1260
+ expect(errorIn(result.current, SKILLS_TREE)).toEqual({
1261
+ filename: 'quarterly-report.pdf',
1262
+ reason,
1263
+ status: 403,
1264
+ });
1265
+ // In THAT tree and no other — the Knowledge explorer never saw this drop.
1266
+ expect(result.current.uploadErrors.size).toBe(1);
1267
+ // And the in-progress notice does not outlive the upload it described.
1268
+ expect(noticeIn(result.current, SKILLS_TREE)).toBeNull();
1269
+ });
1270
+ });
1271
+
1272
+ /**
1273
+ * `?trace=files`: the bootstrap is one of the gates a blank file page waits on,
1274
+ * so its start and outcome are logged, and nothing else about it changes.
1275
+ */
1276
+ describe('useWorkspaceState: bootstrap trace', () => {
1277
+ beforeEach(() => {
1278
+ sessionStorage.clear();
1279
+ apiMocks.getOrCreateWorkspace.mockReset();
1280
+ });
1281
+
1282
+ afterEach(() => {
1283
+ vi.restoreAllMocks();
1284
+ sessionStorage.clear();
1285
+ localStorage.clear();
1286
+ });
1287
+
1288
+ function traceCalls(info: ReturnType<typeof vi.spyOn>) {
1289
+ return info.mock.calls
1290
+ .filter((c: unknown[]) => c[0] === '[trace:files]')
1291
+ .map((c: unknown[]) => ({ event: c[1] as string, fields: c[2] as Record<string, unknown> }));
1292
+ }
1293
+
1294
+ it('logs the start and the workspace a successful bootstrap produced', async () => {
1295
+ sessionStorage.setItem(FILE_TRACE_STORAGE_KEY, '1');
1296
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1297
+ apiMocks.getOrCreateWorkspace.mockResolvedValue(WORKSPACE_FIXTURE);
1298
+
1299
+ const { result } = renderHook(() => useWorkspaceState());
1300
+ await waitFor(() => expect(result.current.workspaceId).toBe('ws-1'));
1301
+
1302
+ const calls = traceCalls(info);
1303
+ expect(calls.map((c) => c.event)).toEqual(['bootstrap:start', 'bootstrap:ok']);
1304
+ expect(calls[0].fields).toMatchObject({ branch: null });
1305
+ expect(calls[1].fields).toMatchObject({ branch: null, workspaceId: 'ws-1', cancelled: false });
1306
+ });
1307
+
1308
+ it('logs the status and message of a failed bootstrap, which still surfaces as bootstrapError', async () => {
1309
+ sessionStorage.setItem(FILE_TRACE_STORAGE_KEY, '1');
1310
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1311
+ vi.spyOn(console, 'error').mockImplementation(() => {});
1312
+ apiMocks.getOrCreateWorkspace.mockRejectedValue(new WorkspaceApiError(500));
1313
+
1314
+ const { result } = renderHook(() => useWorkspaceState());
1315
+ await waitFor(() => expect(traceCalls(info).some((c) => c.event === 'bootstrap:failed')).toBe(true));
1316
+
1317
+ expect(traceCalls(info).find((c) => c.event === 'bootstrap:failed')?.fields).toMatchObject({
1318
+ branch: null,
1319
+ status: 500,
1320
+ message: 'HTTP 500',
1321
+ cancelled: false,
1322
+ });
1323
+ expect(traceCalls(info).some((c) => c.event === 'bootstrap:ok')).toBe(false);
1324
+ await waitFor(() => expect(result.current.bootstrapError).toMatchObject({ status: 500 }));
1325
+ expect(result.current.workspaceId).toBeNull();
1326
+ });
1327
+
1328
+ /**
1329
+ * A bootstrap failure used to be terminal for the session: the workspace
1330
+ * never came up, the file route waited on it forever, and only a full page
1331
+ * reload could try again. `retryBootstrap` re-runs the same request for the
1332
+ * same branch, which is what the file page's Retry is wired to.
1333
+ */
1334
+ it('retryBootstrap re-runs the request for the same branch and recovers', async () => {
1335
+ vi.spyOn(console, 'error').mockImplementation(() => {});
1336
+ apiMocks.getOrCreateWorkspace.mockRejectedValue(new WorkspaceApiError(500));
1337
+
1338
+ const { result } = renderHook(() => useWorkspaceState());
1339
+ act(() => { result.current.setPersistenceBranch('alice/draft'); });
1340
+ await waitFor(() =>
1341
+ expect(result.current.bootstrapError)
1342
+ .toMatchObject({ branch: 'alice/draft', status: 500, message: 'HTTP 500' }),
1343
+ );
1344
+ expect(result.current.workspaceId).toBeNull();
1345
+
1346
+ // The outage clears; the reader presses Retry.
1347
+ apiMocks.getOrCreateWorkspace.mockResolvedValue({
1348
+ ...WORKSPACE_FIXTURE,
1349
+ workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
1350
+ });
1351
+ act(() => { result.current.retryBootstrap(); });
1352
+
1353
+ await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
1354
+ expect(result.current.bootstrapError).toBeNull();
1355
+ // Retried for the branch that was asked for, not the default.
1356
+ expect(apiMocks.getOrCreateWorkspace).toHaveBeenLastCalledWith('alice/draft');
1357
+ });
1358
+
1359
+ it('logs nothing without the flag', async () => {
1360
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1361
+ apiMocks.getOrCreateWorkspace.mockResolvedValue(WORKSPACE_FIXTURE);
1362
+
1363
+ const { result } = renderHook(() => useWorkspaceState());
1364
+ await waitFor(() => expect(result.current.workspaceId).toBe('ws-1'));
1365
+
1366
+ expect(traceCalls(info)).toHaveLength(0);
1367
+ });
1368
+ });