@bevel-software/platform-core-frontend 0.15.1 → 0.20.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 (347) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +20 -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__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  33. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  34. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  35. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  36. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  37. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  38. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  39. package/src/modules/admin/components/group-members-path.ts +32 -0
  40. package/src/modules/admin/services/roles.api.ts +12 -1
  41. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  42. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  43. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  44. package/src/modules/audit/components/principal-grouping.ts +49 -0
  45. package/src/modules/audit/services/audit.api.ts +98 -0
  46. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  47. package/src/modules/auth/components/AccountPage.tsx +73 -54
  48. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  49. package/src/modules/auth/services/account.api.ts +78 -4
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  58. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  59. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  60. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  61. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  62. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  63. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  64. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  65. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  66. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  67. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  68. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  69. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  70. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  71. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  72. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  73. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  74. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  75. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  76. package/src/modules/change-requests/services/propose.api.ts +97 -8
  77. package/src/modules/change-requests/utils/approval.ts +15 -0
  78. package/src/modules/change-requests/utils/author.ts +32 -0
  79. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  80. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  81. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  82. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  83. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  84. package/src/modules/git/services/error-messages.ts +12 -0
  85. package/src/modules/git/services/pr-prompts.ts +5 -5
  86. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  87. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  88. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  89. package/src/modules/layout/components/AppLayout.tsx +2 -0
  90. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  91. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  92. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  93. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  94. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  95. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  96. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  97. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  98. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  99. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  100. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  101. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  102. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  103. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  104. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  105. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  106. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  107. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  108. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  109. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  110. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  111. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  112. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  113. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  114. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  115. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  116. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  117. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  118. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  119. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  120. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  121. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  122. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  123. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  124. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  125. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  126. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  127. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  128. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  129. package/src/modules/library/__tests__/status.test.ts +82 -2
  130. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  131. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  132. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  133. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  134. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  135. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  136. package/src/modules/library/components/LibraryCard.tsx +146 -45
  137. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  138. package/src/modules/library/components/LibraryPage.tsx +172 -39
  139. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  140. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  141. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  142. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  143. package/src/modules/library/components/PageActions.tsx +11 -9
  144. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  145. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  146. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  147. package/src/modules/library/components/PluginExtras.tsx +140 -17
  148. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  149. package/src/modules/library/components/PluginPage.tsx +157 -41
  150. package/src/modules/library/components/PluginRows.tsx +286 -0
  151. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  152. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  153. package/src/modules/library/components/ShareButton.tsx +17 -0
  154. package/src/modules/library/components/SkillsTree.tsx +141 -28
  155. package/src/modules/library/components/TeamRoute.tsx +15 -0
  156. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  157. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  158. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  159. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  160. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  161. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  162. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  163. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  164. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  165. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  166. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  167. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  168. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  169. package/src/modules/library/routes/library-paths.ts +26 -28
  170. package/src/modules/library/services/library.api.ts +38 -20
  171. package/src/modules/library/services/plugins.api.ts +69 -8
  172. package/src/modules/library/services/teams.api.ts +15 -0
  173. package/src/modules/library/services/tools.api.ts +78 -0
  174. package/src/modules/library/state/library-data.tsx +170 -32
  175. package/src/modules/library/utils/personal-plugin.ts +13 -15
  176. package/src/modules/library/utils/plugin-entries.ts +134 -0
  177. package/src/modules/library/utils/plugin-summary.ts +75 -9
  178. package/src/modules/library/utils/status.ts +135 -33
  179. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  180. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  181. package/src/modules/onboarding/agent-clients.ts +55 -23
  182. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  183. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  184. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  185. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  186. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  187. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  188. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  189. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  190. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  191. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  192. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  193. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  194. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  195. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  196. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  197. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  198. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  199. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  200. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  201. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  202. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  203. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  204. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  205. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  206. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  207. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  208. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +7 -6
  209. package/src/modules/settings/services/github-facade.api.ts +23 -0
  210. package/src/modules/settings/settings-nav-items.tsx +13 -3
  211. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  212. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  213. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  214. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  215. package/src/modules/setup/components/SetupGate.tsx +16 -16
  216. package/src/modules/setup/components/SetupScreen.tsx +532 -43
  217. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  218. package/src/modules/setup/services/setup.api.ts +141 -4
  219. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  220. package/src/modules/setup/utils/root-folders.ts +46 -0
  221. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  232. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  233. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  234. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  235. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  236. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  237. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  238. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  239. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  240. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  241. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  242. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  243. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  244. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  245. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  246. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  247. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  248. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  249. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  250. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  251. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  252. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  254. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  255. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  256. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  257. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  258. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  259. package/src/modules/workspace/components/FileViewer.tsx +172 -46
  260. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  261. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  262. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  263. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2533 -129
  264. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  265. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +381 -12
  266. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  267. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  268. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  269. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  270. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  271. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  272. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  273. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  274. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  275. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  276. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  277. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  279. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  280. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  281. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  282. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  283. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  284. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  285. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  286. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  287. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  288. package/src/modules/workspace/components/renderers/index.ts +53 -2
  289. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  290. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  291. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  292. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  294. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  295. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  296. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  297. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  298. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  299. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  300. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  301. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +134 -1
  302. package/src/modules/workspace/services/workspace.api.ts +57 -4
  303. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  304. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  305. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  306. package/src/modules/workspace/state/workspace.context.ts +125 -19
  307. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  308. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  309. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  310. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  311. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  312. package/src/modules/workspace/utils/file-trace.ts +50 -0
  313. package/src/modules/workspace/utils/fileTree.ts +112 -36
  314. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  315. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  316. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  317. package/src/modules/workspace/utils/uploadError.ts +29 -0
  318. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  319. package/src/shared/components/Button.tsx +16 -2
  320. package/src/shared/components/Dialog.tsx +27 -11
  321. package/src/shared/components/Menu.tsx +13 -1
  322. package/src/shared/components/PageShell.tsx +13 -8
  323. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  324. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  325. package/src/shared/components/index.ts +2 -0
  326. package/src/shared/components/useDismissableMenu.ts +32 -10
  327. package/src/shared/components/useFocusHandoff.ts +51 -0
  328. package/src/shared/components/useLatestRef.ts +28 -0
  329. package/src/shared/markdown/Markdown.tsx +12 -3
  330. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  331. package/src/shared/markdown/hrefs.ts +50 -0
  332. package/src/shared/marketplace-url.ts +33 -5
  333. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  334. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  335. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  336. package/src/shared/mcp/connect-snippets.ts +14 -9
  337. package/src/shared/mcp/index.ts +1 -1
  338. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  339. package/src/shared/theme/header.ts +75 -0
  340. package/src/shared/theme/measure.ts +7 -4
  341. package/src/shared/theme/tokens.css +25 -0
  342. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  343. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  344. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  345. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  346. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  347. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -1,12 +1,32 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { render, screen, waitFor, fireEvent } from '@testing-library/react';
3
- import { MemoryRouter, Routes, Route } from 'react-router-dom';
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { render, screen, waitFor, fireEvent, act } from '@testing-library/react';
3
+ import { MemoryRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom';
4
4
  import type { ReactNode } from 'react';
5
+
6
+ // The node-id lookup behind the canonical-URL redirect, so a test can say a
7
+ // file HAS an id without a backend.
8
+ const routesMock = vi.hoisted(() => ({
9
+ fetchNodeId: vi.fn(),
10
+ fetchNodeWorkspacePath: vi.fn(),
11
+ }));
12
+ vi.mock('../../routing/kb-routes', async (importOriginal) => {
13
+ const actual = await importOriginal<typeof import('../../routing/kb-routes')>();
14
+ return {
15
+ ...actual,
16
+ fetchNodeId: routesMock.fetchNodeId,
17
+ fetchNodeWorkspacePath: routesMock.fetchNodeWorkspacePath,
18
+ };
19
+ });
5
20
  import type { WorkingTreeStatus } from '@bevel-software/platform-shared';
6
21
  import { FileRoute } from '../FileRoute';
7
22
  import { WorkspaceApiError } from '../../services/workspace.api';
8
23
  import { GitContext, type GitContextValue } from '../../../git/state/git.context';
9
- import { WorkspaceContext, type WorkspaceContextValue, type OpenTab } from '../../state/workspace.context';
24
+ import {
25
+ WorkspaceContext,
26
+ type WorkspaceContextValue,
27
+ type OpenTab,
28
+ type HydrateResult,
29
+ } from '../../state/workspace.context';
10
30
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
11
31
  import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
12
32
  import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
@@ -57,6 +77,11 @@ function makeWorkspace(overrides: Partial<WorkspaceContextValue> = {}): Workspac
57
77
  });
58
78
  const hasUnsavedFileChanges = overrides.hasUnsavedFileChanges ?? dirtyTabFilenames.length > 0;
59
79
  return makeWorkspaceFixture({
80
+ // Left unset on purpose: `renderAt` fills it from the git status branch,
81
+ // because in production "the branch this workspace IS" and "the branch its
82
+ // status reports" are one fact seen twice. A test that means them to
83
+ // disagree — a branch switch caught in flight — names it explicitly.
84
+ workspaceBranch: overrides.workspaceBranch ?? null,
60
85
  openTabs,
61
86
  activeTab,
62
87
  dirtyTabFilenames,
@@ -70,18 +95,65 @@ function makeWorkspace(overrides: Partial<WorkspaceContextValue> = {}): Workspac
70
95
  }
71
96
 
72
97
  /** One place owns the hydrateTabs result shape, so contract changes touch one line. */
73
- function makeHydrateResult(
74
- overrides: Partial<{ surviving: string[]; dropped: string[]; denied: string[] }> = {},
75
- ): { surviving: string[]; dropped: string[]; denied: string[] } {
76
- return { surviving: [], dropped: [], denied: [], ...overrides };
98
+ function makeHydrateResult(overrides: Partial<HydrateResult> = {}): HydrateResult {
99
+ return { surviving: [], dropped: [], denied: [], superseded: false, ...overrides };
100
+ }
101
+
102
+ function LocationProbe() {
103
+ const location = useLocation();
104
+ return <div aria-label="pathname">{location.pathname}</div>;
105
+ }
106
+
107
+ /** Stands in for a file-tree click: navigates to a clean file URL. */
108
+ function TreeClickProbe() {
109
+ const navigate = useNavigate();
110
+ return (
111
+ <button type="button" aria-label="tree-click-bar" onClick={() => navigate('/workspace/main/Knowledge/Bar.md')} />
112
+ );
113
+ }
114
+
115
+ /** Two tree clicks on the SAME branch, for the URL→URL→URL sequences. */
116
+ function SameBranchClickProbe() {
117
+ const navigate = useNavigate();
118
+ return (
119
+ <>
120
+ <button
121
+ type="button"
122
+ aria-label="click-foo"
123
+ onClick={() => navigate('/workspace/alice%2Fdraft/Knowledge/Foo.md')}
124
+ />
125
+ <button
126
+ type="button"
127
+ aria-label="click-baz"
128
+ onClick={() => navigate('/workspace/alice%2Fdraft/Knowledge/Baz.md')}
129
+ />
130
+ </>
131
+ );
77
132
  }
78
133
 
79
134
  function renderAt(
80
135
  url: string,
81
- opts: { git?: GitContextValue; workspace?: WorkspaceContextValue } = {},
82
- ): { workspace: WorkspaceContextValue; git: GitContextValue } {
83
- const workspace = opts.workspace ?? makeWorkspace();
84
- const git = opts.git ?? makeGit();
136
+ opts: { git?: GitContextValue; workspace?: WorkspaceContextValue; canonicalize?: boolean } = {},
137
+ ): {
138
+ workspace: WorkspaceContextValue;
139
+ git: GitContextValue;
140
+ rerenderWorkspace: (next: WorkspaceContextValue) => void;
141
+ rerenderGit: (next: GitContextValue) => void;
142
+ } {
143
+ let git = opts.git ?? makeGit();
144
+ /**
145
+ * A workspace that hasn't said which branch it is, is on the branch its
146
+ * status reports — the two only differ while a switch is in flight, and a
147
+ * test that means that says so. Without this, every fixture would silently
148
+ * describe a state the app cannot be in (a workspace on `main` whose status
149
+ * reports `alice/draft`), which `FileRoute` now correctly refuses to read
150
+ * from.
151
+ */
152
+ const onStatusBranch = (ws: WorkspaceContextValue): WorkspaceContextValue =>
153
+ ws.workspaceBranch === null && ws.workspaceId !== null
154
+ ? { ...ws, workspaceBranch: git.status?.branch ?? null }
155
+ : ws;
156
+ let workspace = onStatusBranch(opts.workspace ?? makeWorkspace());
85
157
  const review: ReviewContextValue = {
86
158
  session: null,
87
159
  selectedPath: null,
@@ -119,19 +191,72 @@ function renderAt(
119
191
  );
120
192
  }
121
193
 
122
- render(
194
+ const tree = () => (
123
195
  <MemoryRouter initialEntries={[url]}>
124
196
  <Tree>
125
197
  <Routes>
126
- <Route path="/workspace/:branch/*" element={<FileRoute />} />
198
+ <Route path="/workspace/:branch/*" element={<FileRoute canonicalize={opts.canonicalize} />} />
127
199
  </Routes>
200
+ <LocationProbe />
201
+ <TreeClickProbe />
202
+ <SameBranchClickProbe />
128
203
  </Tree>
129
- </MemoryRouter>,
204
+ </MemoryRouter>
130
205
  );
206
+ const { rerender } = render(tree());
131
207
 
132
- return { workspace, git };
208
+ return {
209
+ workspace,
210
+ git,
211
+ rerenderWorkspace: (next) => {
212
+ workspace = onStatusBranch(next);
213
+ rerender(tree());
214
+ },
215
+ rerenderGit: (next) => {
216
+ git = next;
217
+ rerender(tree());
218
+ },
219
+ };
133
220
  }
134
221
 
222
+ /** Let every pending microtask and effect settle, to assert something did NOT happen. */
223
+ const settle = () => act(async () => { await new Promise((r) => setTimeout(r, 30)); });
224
+
225
+ beforeEach(() => {
226
+ routesMock.fetchNodeId.mockReset().mockResolvedValue(null);
227
+ routesMock.fetchNodeWorkspacePath.mockReset().mockResolvedValue(null);
228
+ });
229
+
230
+ describe('FileRoute: the canonical id URL', () => {
231
+ const PATH = 'Plugins/GTM/web-search.tool';
232
+ function openOn(): { workspace: WorkspaceContextValue; git: GitContextValue } {
233
+ const tab = makeTab({ path: PATH });
234
+ const workspace = makeWorkspace({
235
+ openTabs: [tab],
236
+ activeTab: tab,
237
+ hydrateTabs: vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult({ surviving: [PATH] })),
238
+ });
239
+ return { workspace, git: makeGit({ status: makeStatus('main') }) };
240
+ }
241
+
242
+ it('replaces the path URL with the node-id URL once the file is the open tab', async () => {
243
+ routesMock.fetchNodeId.mockResolvedValue('web_search');
244
+ renderAt(`/workspace/main/${PATH}`, openOn());
245
+ await waitFor(() =>
246
+ expect(screen.getByLabelText('pathname')).toHaveTextContent('/workspace/main/web_search'),
247
+ );
248
+ });
249
+
250
+ it('keeps the path URL when canonicalising is off — the Library frame renders it there, and an id URL is no library location', async () => {
251
+ routesMock.fetchNodeId.mockResolvedValue('web_search');
252
+ renderAt(`/workspace/main/${PATH}`, { ...openOn(), canonicalize: false });
253
+ // Give the (absent) redirect every chance to fire before asserting it did not.
254
+ await new Promise((r) => setTimeout(r, 50));
255
+ expect(screen.getByLabelText('pathname')).toHaveTextContent(`/workspace/main/${PATH}`);
256
+ expect(routesMock.fetchNodeId).not.toHaveBeenCalled();
257
+ });
258
+ });
259
+
135
260
  describe('FileRoute', () => {
136
261
  it('hydrates tabs with the URL path when branch matches', async () => {
137
262
  const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
@@ -268,7 +393,7 @@ describe('FileRoute', () => {
268
393
  it('renders the branch-gone screen when the BOOTSTRAP of the URL branch answered 410', async () => {
269
394
  // No workspace ever came up for this branch: GET /workspace said the
270
395
  // branch is gone. The state surfaces that; the route must not sit waiting.
271
- const workspace = makeWorkspace({ bootstrapError: { branch: 'alice/draft', status: 410 } });
396
+ const workspace = makeWorkspace({ bootstrapError: { branch: 'alice/draft', status: 410, message: 'Gone' } });
272
397
  const git = makeGit({ status: makeStatus('main') });
273
398
 
274
399
  renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace });
@@ -278,8 +403,33 @@ describe('FileRoute', () => {
278
403
  });
279
404
  });
280
405
 
406
+ it('renders the branch-not-found screen when the BOOTSTRAP of the URL branch answered 404', async () => {
407
+ // A name nobody ever pushed. Nothing was deleted, so the branch-gone
408
+ // screen would tell the reader something untrue — this is the
409
+ // file-missing story, told about a branch.
410
+ const workspace = makeWorkspace({
411
+ bootstrapError: {
412
+ branch: 'alice/draft',
413
+ status: 404,
414
+ message: 'There is no branch named alice/draft.',
415
+ },
416
+ });
417
+ const git = makeGit({ status: makeStatus('main') });
418
+
419
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace });
420
+
421
+ await waitFor(() => {
422
+ expect(screen.getByText(/Branch not found/i)).toBeInTheDocument();
423
+ });
424
+ expect(screen.getByText(/There is no branch named/i)).toBeInTheDocument();
425
+ expect(screen.getByText('alice/draft')).toBeInTheDocument();
426
+ // Not the deleted-branch screen, and not the generic bootstrap failure.
427
+ expect(screen.queryByText(/This branch no longer exists/i)).not.toBeInTheDocument();
428
+ expect(screen.queryByText(/Couldn't open/i)).not.toBeInTheDocument();
429
+ });
430
+
281
431
  it('a stale bootstrap failure from another branch does not paint over this one', async () => {
282
- const workspace = makeWorkspace({ bootstrapError: { branch: 'someone/else', status: 410 } });
432
+ const workspace = makeWorkspace({ bootstrapError: { branch: 'someone/else', status: 410, message: 'Gone' } });
283
433
  const git = makeGit({ status: makeStatus('alice/draft') });
284
434
 
285
435
  renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace });
@@ -372,3 +522,566 @@ describe('FileRoute', () => {
372
522
  });
373
523
  });
374
524
  });
525
+
526
+ /**
527
+ * The page is never silently blank. Every reason a file can fail to appear —
528
+ * a bootstrap that failed, a git status that won't answer, a read still in
529
+ * flight — has a screen that says so, and the ones that can recover have a
530
+ * Retry. The generic "Open a page to start reading." belongs to a URL that
531
+ * names no file, and to nothing else.
532
+ */
533
+ describe('FileRoute: nothing waits silently', () => {
534
+ it('shows a bootstrap failure of ANY status, names the branch and the failure, and recovers on Retry', async () => {
535
+ const retryBootstrap = vi.fn();
536
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
537
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
538
+ );
539
+ const git = makeGit({ status: makeStatus('alice/draft') });
540
+ const { rerenderWorkspace } = renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
541
+ git,
542
+ workspace: makeWorkspace({
543
+ bootstrapError: { branch: 'alice/draft', status: 500, message: 'HTTP 500' },
544
+ retryBootstrap,
545
+ hydrateTabs,
546
+ }),
547
+ });
548
+
549
+ expect(await screen.findByText(/Couldn't open alice\/draft/)).toBeInTheDocument();
550
+ // Names what failed, not just that something did.
551
+ expect(screen.getByText(/failed with HTTP 500/)).toBeInTheDocument();
552
+
553
+ fireEvent.click(screen.getByRole('button', { name: /retry/i }));
554
+ expect(retryBootstrap).toHaveBeenCalledTimes(1);
555
+
556
+ // The retried bootstrap succeeds: the failure screen gives way to the file.
557
+ const tab = makeTab({ path: 'Knowledge/Foo.md' });
558
+ rerenderWorkspace(makeWorkspace({ openTabs: [tab], activeTab: tab, hydrateTabs }));
559
+ await waitFor(() => expect(screen.queryByText(/Couldn't open/)).not.toBeInTheDocument());
560
+ });
561
+
562
+ it('shows a failed FIRST bootstrap even though it is reported under the default branch', async () => {
563
+ // Nothing has asked for a branch yet, so the failure carries the default
564
+ // branch's name while the URL names another. There is still no workspace,
565
+ // so nothing can open until a bootstrap succeeds — say so.
566
+ const git = makeGit({ status: null, availability: 'loading' });
567
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
568
+ git,
569
+ workspace: makeWorkspace({
570
+ workspaceId: null,
571
+ bootstrapError: { branch: 'main', status: 0, message: 'Failed to fetch' },
572
+ }),
573
+ });
574
+
575
+ expect(await screen.findByText(/Couldn't open main/)).toBeInTheDocument();
576
+ expect(screen.getByText(/the request never completed/)).toBeInTheDocument();
577
+ expect(screen.getByText('Failed to fetch')).toBeInTheDocument();
578
+ expect(screen.getByRole('button', { name: /retry/i })).toBeInTheDocument();
579
+ });
580
+
581
+ it('shows a failing git status refresh with a Retry rather than waiting on the next poll', async () => {
582
+ // The refresh failed, so the last branch we know of is the one we were on
583
+ // before, not the one the URL names. Reading now would read the wrong
584
+ // branch's file; waiting silently is what produced the blank page.
585
+ const refreshStatus = vi.fn(async () => null);
586
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
587
+ const git = makeGit({
588
+ status: makeStatus('alice/draft'),
589
+ availability: 'error',
590
+ lastError: 'branch-status: 503',
591
+ refreshStatus,
592
+ });
593
+
594
+ const { rerenderGit, rerenderWorkspace } = renderAt('/workspace/main/Knowledge/Foo.md', {
595
+ git,
596
+ workspace: makeWorkspace({ hydrateTabs, workspaceBranch: 'alice/draft' }),
597
+ });
598
+
599
+ expect(
600
+ await screen.findByText(/Couldn't check which branch this workspace is on/i),
601
+ ).toBeInTheDocument();
602
+ expect(screen.getByText('branch-status: 503')).toBeInTheDocument();
603
+
604
+ fireEvent.click(screen.getByRole('button', { name: /retry/i }));
605
+ await waitFor(() => expect(refreshStatus).toHaveBeenCalledTimes(1));
606
+ // Still no read against a workspace whose branch is unconfirmed.
607
+ expect(hydrateTabs).not.toHaveBeenCalled();
608
+
609
+ // The retry succeeds: the status answers `main`, the workspace bootstraps
610
+ // onto it, and the route does what it was holding off on — it reads. A
611
+ // dead button or an error screen that never clears would stop right here,
612
+ // which is what the assertions above alone could not tell apart.
613
+ rerenderWorkspace(makeWorkspace({ hydrateTabs, workspaceBranch: 'main' }));
614
+ rerenderGit(makeGit({ status: makeStatus('main'), availability: 'ready' }));
615
+ await waitFor(() => expect(hydrateTabs).toHaveBeenCalled());
616
+ expect(
617
+ screen.queryByText(/Couldn't check which branch this workspace is on/i),
618
+ ).not.toBeInTheDocument();
619
+ });
620
+
621
+ it('a failed status refresh on the branch we are ALREADY on is not an error screen', async () => {
622
+ // Same availability, but the last known branch is the URL's branch: the
623
+ // route knows which workspace it has and can read from it. A stale poll is
624
+ // no reason to take the file off the screen.
625
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
626
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
627
+ );
628
+ const git = makeGit({
629
+ status: makeStatus('alice/draft'),
630
+ availability: 'error',
631
+ lastError: 'branch-status: 503',
632
+ });
633
+
634
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace: makeWorkspace({ hydrateTabs }) });
635
+
636
+ await waitFor(() => expect(hydrateTabs).toHaveBeenCalled());
637
+ expect(
638
+ screen.queryByText(/Couldn't check which branch this workspace is on/i),
639
+ ).not.toBeInTheDocument();
640
+ });
641
+
642
+ it('names the file it is opening while the read is in flight, instead of the generic empty state', async () => {
643
+ // The reported symptom: the URL names a file, the page says "Open a page
644
+ // to start reading." and shows no tab strip, for as long as the read takes.
645
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
646
+ () => new Promise(() => {}),
647
+ );
648
+ const git = makeGit({ status: makeStatus('alice/draft') });
649
+
650
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace: makeWorkspace({ hydrateTabs }) });
651
+
652
+ expect(await screen.findByText(/Opening Foo\.md/)).toBeInTheDocument();
653
+ expect(screen.getByText('Knowledge/Foo.md')).toBeInTheDocument();
654
+ expect(screen.queryByText(/Open a page to start reading/i)).not.toBeInTheDocument();
655
+ });
656
+
657
+ it('names the file while the workspace itself is still bootstrapping', async () => {
658
+ const git = makeGit({ status: null, availability: 'loading' });
659
+
660
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
661
+ git,
662
+ workspace: makeWorkspace({ workspaceId: null }),
663
+ });
664
+
665
+ expect(await screen.findByText(/Opening Foo\.md/)).toBeInTheDocument();
666
+ expect(screen.queryByText(/Open a page to start reading/i)).not.toBeInTheDocument();
667
+ });
668
+
669
+ it('names the file it is opening even while the PREVIOUS file is still on screen', async () => {
670
+ // Blankness is not the question. Clicking from one open file to another
671
+ // leaves the old tab's content rendered for the whole read, so a
672
+ // blank-only test called that "ready" and the page sat on the wrong file
673
+ // with nothing to say a new one was coming.
674
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(() => new Promise(() => {}));
675
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
676
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
677
+ );
678
+ const foo = makeTab({ path: 'Knowledge/Foo.md' });
679
+ const git = makeGit({ status: makeStatus('alice/draft') });
680
+
681
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
682
+ git,
683
+ workspace: makeWorkspace({ openTabs: [foo], activeTab: foo, hydrateTabs, addTab }),
684
+ });
685
+ await waitFor(() => expect(hydrateTabs).toHaveBeenCalled());
686
+ expect(screen.queryByText(/Opening/)).not.toBeInTheDocument();
687
+
688
+ // A click on another file on the same branch: its read never lands.
689
+ fireEvent.click(screen.getByLabelText('click-baz'));
690
+ expect(await screen.findByText(/Opening Baz\.md/)).toBeInTheDocument();
691
+ expect(screen.getByText('Knowledge/Baz.md')).toBeInTheDocument();
692
+ });
693
+
694
+ it('does not flash a loading screen over the open file while its id URL resolves', async () => {
695
+ // Canonicalising a path URL to the node's id URL passes through "the URL
696
+ // names an id we have not resolved yet" with the file already on screen
697
+ // and nothing in flight. Reading that as "not the target" would flash the
698
+ // loading screen on every single file open.
699
+ const PATH = 'Plugins/GTM/web-search.tool';
700
+ routesMock.fetchNodeId.mockResolvedValue('web_search');
701
+ let releaseResolve: ((path: string | null) => void) | undefined;
702
+ routesMock.fetchNodeWorkspacePath.mockImplementation(
703
+ () => new Promise((resolve) => { releaseResolve = resolve; }),
704
+ );
705
+ const tab = makeTab({ path: PATH });
706
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
707
+ async () => makeHydrateResult({ surviving: [PATH] }),
708
+ );
709
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
710
+
711
+ renderAt(`/workspace/main/${PATH}`, {
712
+ git: makeGit({ status: makeStatus('main') }),
713
+ workspace: makeWorkspace({ openTabs: [tab], activeTab: tab, hydrateTabs, addTab }),
714
+ });
715
+
716
+ await waitFor(() =>
717
+ expect(screen.getByLabelText('pathname')).toHaveTextContent('/workspace/main/web_search'),
718
+ );
719
+ await settle();
720
+ // The id is still resolving — and the file it names is the one already up.
721
+ expect(routesMock.fetchNodeWorkspacePath).toHaveBeenCalled();
722
+ expect(screen.queryByText(/Opening/)).not.toBeInTheDocument();
723
+
724
+ // And when it resolves — to the very file that is open — the page still
725
+ // doesn't blink: the route reads the resolved path and the viewer keeps
726
+ // the file. Released inside `act` because the resolution sets state and
727
+ // starts the read; outside it, React only warns and nothing here would
728
+ // have covered the frame the test is named for.
729
+ await act(async () => { releaseResolve?.(PATH); });
730
+ await settle();
731
+ expect(addTab).toHaveBeenCalledWith(PATH);
732
+ expect(screen.queryByText(/Opening/)).not.toBeInTheDocument();
733
+ expect(screen.queryByText(/Open a page to start reading/i)).not.toBeInTheDocument();
734
+ expect(screen.getByText(`content:${PATH}`)).toBeInTheDocument();
735
+ });
736
+
737
+ it('never reads from a workspace on another branch even when a RETAINED status says it matches', async () => {
738
+ // `useGitState` keeps the previous branch when a refresh fails, so after
739
+ // switching away and back the status can name the URL's branch while
740
+ // `workspaceId` still serves the branch we switched to. The status alone
741
+ // reads as a match; the workspace itself says otherwise, and it is the one
742
+ // the read would go to.
743
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
744
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
745
+ const setPersistenceBranch = vi.fn();
746
+
747
+ renderAt('/workspace/main/Knowledge/Foo.md', {
748
+ git: makeGit({ status: makeStatus('main') }),
749
+ workspace: makeWorkspace({
750
+ hydrateTabs,
751
+ addTab,
752
+ setPersistenceBranch,
753
+ workspaceBranch: 'alice/draft',
754
+ }),
755
+ });
756
+
757
+ await settle();
758
+ expect(hydrateTabs).not.toHaveBeenCalled();
759
+ expect(addTab).not.toHaveBeenCalled();
760
+ // It re-bootstraps onto the URL's branch instead, and says what it is doing.
761
+ expect(setPersistenceBranch).toHaveBeenCalledWith('main');
762
+ expect(screen.getByText(/Opening Foo\.md/)).toBeInTheDocument();
763
+ });
764
+
765
+ it('keeps the generic empty state for a URL that names no file', async () => {
766
+ localStorage.clear();
767
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
768
+ const git = makeGit({ status: makeStatus('alice/draft') });
769
+
770
+ renderAt('/workspace/alice%2Fdraft', { git, workspace: makeWorkspace({ hydrateTabs }) });
771
+
772
+ expect(await screen.findByText(/Open a page to start reading/i)).toBeInTheDocument();
773
+ expect(screen.queryByText(/Opening/)).not.toBeInTheDocument();
774
+ });
775
+
776
+ it('reads nothing until the git status for the URL branch is known', async () => {
777
+ // `gitStatusBranch=null` on every fresh browser session. The route used to
778
+ // fall straight through and read the URL's path out of whatever workspace
779
+ // the first bootstrap returned — a 404 for a file that exists, dropped.
780
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
781
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
782
+ );
783
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
784
+ // The workspace knows its own branch the moment it exists (it is decoded
785
+ // off the workspace id); it is the STATUS that hasn't answered yet, and
786
+ // the status is what says the clone on disk is really on that branch.
787
+ const workspace = makeWorkspace({ hydrateTabs, addTab, workspaceBranch: 'alice/draft' });
788
+ const { rerenderGit } = renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
789
+ git: makeGit({ status: null, availability: 'loading' }),
790
+ workspace,
791
+ });
792
+
793
+ await settle();
794
+ expect(hydrateTabs).not.toHaveBeenCalled();
795
+ expect(addTab).not.toHaveBeenCalled();
796
+ expect(screen.getByText(/Opening Foo\.md/)).toBeInTheDocument();
797
+
798
+ // Status answers with the URL's branch — now the read may run.
799
+ rerenderGit(makeGit({ status: makeStatus('alice/draft') }));
800
+ await waitFor(() => expect(hydrateTabs).toHaveBeenCalled());
801
+ });
802
+
803
+ it('never reads the URL path out of a workspace serving another branch', async () => {
804
+ // Status says the workspace is on `alice/draft`; the URL is on `main`. The
805
+ // only correct move is to re-bootstrap, never to read `main`'s path here.
806
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
807
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
808
+ const setPersistenceBranch = vi.fn();
809
+
810
+ renderAt('/workspace/main/Knowledge/Foo.md', {
811
+ git: makeGit({ status: makeStatus('alice/draft') }),
812
+ workspace: makeWorkspace({ hydrateTabs, addTab, setPersistenceBranch }),
813
+ });
814
+
815
+ await waitFor(() => expect(setPersistenceBranch).toHaveBeenCalledWith('main'));
816
+ await settle();
817
+ expect(hydrateTabs).not.toHaveBeenCalled();
818
+ expect(addTab).not.toHaveBeenCalled();
819
+ // And it says what it is doing rather than showing the empty state.
820
+ expect(screen.getByText(/Opening Foo\.md/)).toBeInTheDocument();
821
+ });
822
+
823
+ it('re-asserts the URL file through addTab even when it is ALREADY the open tab', async () => {
824
+ // `addTab` on an open tab costs no read, and it is the only way to mark
825
+ // this open as the latest — without it an older in-flight read still
826
+ // counted as latest and activated its own file when it landed, leaving the
827
+ // URL naming one file and the screen showing another.
828
+ const tab = makeTab({ path: 'Knowledge/Foo.md' });
829
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
830
+ const workspace = makeWorkspace({
831
+ openTabs: [tab],
832
+ activeTab: tab,
833
+ addTab,
834
+ // Pretend hydration already ran for this (workspace, branch).
835
+ hydrateTabs: vi.fn<WorkspaceContextValue['hydrateTabs']>(
836
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
837
+ ),
838
+ });
839
+
840
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', {
841
+ git: makeGit({ status: makeStatus('alice/draft') }),
842
+ workspace,
843
+ canonicalize: false,
844
+ });
845
+
846
+ await waitFor(() => expect(workspace.hydrateTabs).toHaveBeenCalled());
847
+
848
+ // Click another file, then click straight back onto the one already open.
849
+ fireEvent.click(screen.getByLabelText('click-baz'));
850
+ await waitFor(() => expect(addTab).toHaveBeenCalledWith('Knowledge/Baz.md'));
851
+ fireEvent.click(screen.getByLabelText('click-foo'));
852
+
853
+ await waitFor(() => expect(addTab).toHaveBeenCalledWith('Knowledge/Foo.md'));
854
+ // The LAST thing the route asked for is the file the URL names.
855
+ expect(addTab.mock.calls.at(-1)?.[0]).toBe('Knowledge/Foo.md');
856
+ });
857
+
858
+ it('shows a 404 from a hydration whose branch matches the URL, rather than dropping it', async () => {
859
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
860
+ async () => makeHydrateResult({ dropped: ['Knowledge/Gone.md'] }),
861
+ );
862
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Gone.md', {
863
+ git: makeGit({ status: makeStatus('alice/draft') }),
864
+ workspace: makeWorkspace({ hydrateTabs }),
865
+ });
866
+
867
+ expect(await screen.findByText(/File not found/i)).toBeInTheDocument();
868
+ expect(screen.queryByText(/Opening Gone\.md/)).not.toBeInTheDocument();
869
+ });
870
+ });
871
+
872
+ /**
873
+ * `?trace=files` — the reproduction diagnostics for a click that changes the
874
+ * URL but leaves the page blank. They log which gate held the page and change
875
+ * nothing about what it does.
876
+ */
877
+ describe('FileRoute: ?trace=files diagnostics', () => {
878
+ beforeEach(() => {
879
+ sessionStorage.clear();
880
+ localStorage.clear();
881
+ });
882
+
883
+ afterEach(() => {
884
+ vi.restoreAllMocks();
885
+ });
886
+
887
+ function traceCalls(info: ReturnType<typeof vi.spyOn>) {
888
+ return info.mock.calls
889
+ .filter((c: unknown[]) => c[0] === '[trace:files]')
890
+ .map((c: unknown[]) => ({ event: c[1] as string, fields: c[2] as Record<string, unknown> }));
891
+ }
892
+
893
+ it('logs the wait on a git status branch that differs from the URL, with the four reproduction fields', async () => {
894
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
895
+ const setPersistenceBranch = vi.fn();
896
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
897
+ const workspace = makeWorkspace({
898
+ hydrateTabs,
899
+ setPersistenceBranch,
900
+ bootstrapError: { branch: 'main', status: 500, message: 'Internal Server Error' },
901
+ openTabs: [makeTab({ path: 'Knowledge/Old.md' })],
902
+ });
903
+ const git = makeGit({ status: makeStatus('alice/draft') });
904
+
905
+ renderAt('/workspace/main/Knowledge/Foo.md?trace=files', { git, workspace });
906
+
907
+ await waitFor(() => expect(setPersistenceBranch).toHaveBeenCalledWith('main'));
908
+ const wait = traceCalls(info).find((c) => c.event === 'wait:branch-mismatch');
909
+ expect(wait?.fields).toMatchObject({
910
+ url: '/workspace/main/Knowledge/Foo.md',
911
+ branchFromUrl: 'main',
912
+ pathFromUrl: 'Knowledge/Foo.md',
913
+ gitStatusBranch: 'alice/draft',
914
+ bootstrapError: { branch: 'main', status: 500, message: 'Internal Server Error' },
915
+ openTabs: ['Knowledge/Old.md'],
916
+ });
917
+ // Still no read against a workspace on the wrong branch — but the page now
918
+ // says so rather than sitting on the empty state (see the bootstrap-failure
919
+ // screen tests above).
920
+ expect(hydrateTabs).not.toHaveBeenCalled();
921
+ });
922
+
923
+ it('numbers each hydration so a start and its settle can be paired in the console', async () => {
924
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
925
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
926
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
927
+ );
928
+ const workspace = makeWorkspace({ hydrateTabs });
929
+ const git = makeGit({ status: makeStatus('alice/draft') });
930
+
931
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', { git, workspace });
932
+
933
+ await waitFor(() => {
934
+ expect(traceCalls(info).some((c) => c.event === 'hydrate:settled')).toBe(true);
935
+ });
936
+ const calls = traceCalls(info);
937
+ const start = calls.find((c) => c.event === 'hydrate:start');
938
+ const settled = calls.find((c) => c.event === 'hydrate:settled');
939
+ expect(start?.fields).toMatchObject({ paths: ['Knowledge/Foo.md'], activePath: 'Knowledge/Foo.md' });
940
+ expect(settled?.fields).toMatchObject({
941
+ surviving: ['Knowledge/Foo.md'],
942
+ cancelled: false,
943
+ // What the hydration left open, not this render's pre-hydration tabs.
944
+ openTabs: ['Knowledge/Foo.md'],
945
+ openFilePath: 'Knowledge/Foo.md',
946
+ });
947
+ expect(settled?.fields.hydrateSeq).toBe(start?.fields.hydrateSeq);
948
+ });
949
+
950
+ it('logs the failed status of a hydration before the error screen it already had', async () => {
951
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
952
+ const hydrateTabs = vi.fn(async () => {
953
+ throw new WorkspaceApiError(500);
954
+ });
955
+ const workspace = makeWorkspace({ hydrateTabs });
956
+ const git = makeGit({ status: makeStatus('alice/draft') });
957
+
958
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', { git, workspace });
959
+
960
+ await waitFor(() => expect(screen.getByText(/Couldn't load this file/i)).toBeInTheDocument());
961
+ expect(traceCalls(info).find((c) => c.event === 'hydrate:failed')?.fields).toMatchObject({
962
+ status: 500,
963
+ cancelled: false,
964
+ });
965
+ });
966
+
967
+ it('logs a bootstrap failure that arrives while the page waits for its workspace', async () => {
968
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
969
+ const git = makeGit({ status: null });
970
+ const { rerenderWorkspace } = renderAt('/workspace/main/Knowledge/Foo.md?trace=files', {
971
+ git,
972
+ workspace: makeWorkspace({ workspaceId: null }),
973
+ });
974
+
975
+ await waitFor(() => {
976
+ expect(traceCalls(info).some((c) => c.event === 'wait:no-workspace')).toBe(true);
977
+ });
978
+ rerenderWorkspace(makeWorkspace({ workspaceId: null, bootstrapError: { branch: 'main', status: 500, message: 'Internal Server Error' } }));
979
+
980
+ await waitFor(() => {
981
+ const waits = traceCalls(info).filter((c) => c.event === 'wait:no-workspace');
982
+ expect(waits.at(-1)?.fields).toMatchObject({ bootstrapError: { branch: 'main', status: 500, message: 'Internal Server Error' } });
983
+ });
984
+
985
+ // A file click while the workspace is still missing logs the new URL.
986
+ fireEvent.click(screen.getByLabelText('tree-click-bar'));
987
+ await waitFor(() => {
988
+ const waits = traceCalls(info).filter((c) => c.event === 'wait:no-workspace');
989
+ expect(waits.at(-1)?.fields).toMatchObject({
990
+ url: '/workspace/main/Knowledge/Bar.md',
991
+ pathFromUrl: 'Knowledge/Bar.md',
992
+ });
993
+ });
994
+ });
995
+
996
+ it('logs the wait for a git status that has not answered yet', async () => {
997
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
998
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult());
999
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', {
1000
+ git: makeGit({ status: null, availability: 'loading' }),
1001
+ workspace: makeWorkspace({ hydrateTabs }),
1002
+ });
1003
+
1004
+ await waitFor(() =>
1005
+ expect(traceCalls(info).some((c) => c.event === 'wait:git-status')).toBe(true),
1006
+ );
1007
+ expect(traceCalls(info).find((c) => c.event === 'wait:git-status')?.fields).toMatchObject({
1008
+ branchFromUrl: 'alice/draft',
1009
+ pathFromUrl: 'Knowledge/Foo.md',
1010
+ gitStatusBranch: null,
1011
+ });
1012
+ expect(hydrateTabs).not.toHaveBeenCalled();
1013
+ });
1014
+
1015
+ it('names the screen that won, so the console says what the reader is looking at', async () => {
1016
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1017
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', {
1018
+ git: makeGit({ status: makeStatus('alice/draft') }),
1019
+ workspace: makeWorkspace({
1020
+ bootstrapError: { branch: 'alice/draft', status: 500, message: 'HTTP 500' },
1021
+ }),
1022
+ });
1023
+
1024
+ await waitFor(() =>
1025
+ expect(traceCalls(info).some((c) => c.event === 'screen')).toBe(true),
1026
+ );
1027
+ expect(traceCalls(info).filter((c) => c.event === 'screen').at(-1)?.fields)
1028
+ .toMatchObject({ screen: 'bootstrap-failed' });
1029
+ });
1030
+
1031
+ it('logs the loading screen, naming the file it is waiting on', async () => {
1032
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1033
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', {
1034
+ git: makeGit({ status: makeStatus('alice/draft') }),
1035
+ workspace: makeWorkspace({
1036
+ hydrateTabs: vi.fn<WorkspaceContextValue['hydrateTabs']>(() => new Promise(() => {})),
1037
+ }),
1038
+ });
1039
+
1040
+ await waitFor(() => {
1041
+ const last = traceCalls(info).filter((c) => c.event === 'screen').at(-1);
1042
+ expect(last?.fields).toMatchObject({ screen: 'loading', loadingFile: 'Knowledge/Foo.md' });
1043
+ });
1044
+ });
1045
+
1046
+ it('logs the re-assertion of a file that is already open', async () => {
1047
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1048
+ const tab = makeTab({ path: 'Knowledge/Foo.md' });
1049
+ const addTab = vi.fn<WorkspaceContextValue['addTab']>(async () => true);
1050
+ const workspace = makeWorkspace({
1051
+ openTabs: [tab],
1052
+ activeTab: tab,
1053
+ addTab,
1054
+ hydrateTabs: vi.fn<WorkspaceContextValue['hydrateTabs']>(
1055
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
1056
+ ),
1057
+ });
1058
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md?trace=files', {
1059
+ git: makeGit({ status: makeStatus('alice/draft') }),
1060
+ workspace,
1061
+ canonicalize: false,
1062
+ });
1063
+
1064
+ await waitFor(() => expect(workspace.hydrateTabs).toHaveBeenCalled());
1065
+ fireEvent.click(screen.getByLabelText('click-baz'));
1066
+ await waitFor(() => expect(addTab).toHaveBeenCalledWith('Knowledge/Baz.md'));
1067
+ fireEvent.click(screen.getByLabelText('click-foo'));
1068
+
1069
+ await waitFor(() =>
1070
+ expect(traceCalls(info).some((c) => c.event === 'add-tab:already-open')).toBe(true),
1071
+ );
1072
+ });
1073
+
1074
+ it('logs nothing without the flag', async () => {
1075
+ const info = vi.spyOn(console, 'info').mockImplementation(() => {});
1076
+ const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
1077
+ async () => makeHydrateResult({ surviving: ['Knowledge/Foo.md'] }),
1078
+ );
1079
+ const workspace = makeWorkspace({ hydrateTabs });
1080
+ const git = makeGit({ status: makeStatus('alice/draft') });
1081
+
1082
+ renderAt('/workspace/alice%2Fdraft/Knowledge/Foo.md', { git, workspace });
1083
+
1084
+ await waitFor(() => expect(hydrateTabs).toHaveBeenCalled());
1085
+ expect(traceCalls(info)).toHaveLength(0);
1086
+ });
1087
+ });