@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.
- package/THIRD-PARTY-NOTICES.md +2 -2
- package/package.json +3 -3
- package/src/core/CoreAppShell.tsx +20 -9
- package/src/core/__tests__/AppChrome.test.tsx +0 -3
- package/src/core/__tests__/events.test.ts +43 -0
- package/src/core/bootstrap.ts +11 -3
- package/src/core/events.ts +85 -3
- package/src/core/registry.ts +1 -1
- package/src/lib/__tests__/email.test.ts +44 -0
- package/src/lib/email.ts +37 -1
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
- package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
- package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
- package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
- package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
- package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
- package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
- package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
- package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
- package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
- package/src/modules/access/api.ts +140 -6
- package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
- package/src/modules/access/manage-access-affordance.ts +17 -0
- package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
- package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
- package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
- package/src/modules/admin/components/AddMemberInput.tsx +268 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
- package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
- package/src/modules/admin/components/group-members-path.ts +32 -0
- package/src/modules/admin/services/roles.api.ts +12 -1
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
- package/src/modules/audit/components/AuditLogPage.tsx +373 -0
- package/src/modules/audit/components/principal-grouping.ts +49 -0
- package/src/modules/audit/services/audit.api.ts +98 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
- package/src/modules/auth/components/AccountPage.tsx +73 -54
- package/src/modules/auth/components/LoginScreen.tsx +1 -0
- package/src/modules/auth/services/account.api.ts +78 -4
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
- package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
- package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
- package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
- package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
- package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
- package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
- package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
- package/src/modules/change-requests/services/change-requests.api.ts +57 -1
- package/src/modules/change-requests/services/denied-file.api.ts +53 -0
- package/src/modules/change-requests/services/propose.api.ts +97 -8
- package/src/modules/change-requests/utils/approval.ts +15 -0
- package/src/modules/change-requests/utils/author.ts +32 -0
- package/src/modules/change-requests/utils/readFailure.ts +110 -0
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
- package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
- package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
- package/src/modules/git/services/error-messages.ts +12 -0
- package/src/modules/git/services/pr-prompts.ts +5 -5
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
- package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
- package/src/modules/layout/components/AppLayout.tsx +2 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
- package/src/modules/layout/components/SidebarFrame.tsx +108 -3
- package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
- package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
- package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
- package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
- package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
- package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
- package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
- package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
- package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
- package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
- package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
- package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
- package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
- package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
- package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
- package/src/modules/library/__tests__/auth-harness.tsx +9 -9
- package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
- package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
- package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
- package/src/modules/library/__tests__/library-data.test.ts +7 -0
- package/src/modules/library/__tests__/library-paths.test.ts +47 -4
- package/src/modules/library/__tests__/link-membership.test.ts +13 -4
- package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
- package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
- package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
- package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
- package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
- package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
- package/src/modules/library/__tests__/status.test.ts +82 -2
- package/src/modules/library/__tests__/tools.api.test.ts +44 -1
- package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
- package/src/modules/library/components/AddDialogTabs.tsx +103 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
- package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
- package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
- package/src/modules/library/components/LibraryCard.tsx +146 -45
- package/src/modules/library/components/LibraryLayout.tsx +119 -256
- package/src/modules/library/components/LibraryPage.tsx +172 -39
- package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
- package/src/modules/library/components/LockedPluginView.tsx +62 -34
- package/src/modules/library/components/NameWithBadges.tsx +164 -0
- package/src/modules/library/components/NewPluginDialog.tsx +16 -2
- package/src/modules/library/components/PageActions.tsx +11 -9
- package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
- package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
- package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
- package/src/modules/library/components/PluginExtras.tsx +140 -17
- package/src/modules/library/components/PluginIndexRow.tsx +47 -12
- package/src/modules/library/components/PluginPage.tsx +157 -41
- package/src/modules/library/components/PluginRows.tsx +286 -0
- package/src/modules/library/components/PluginsSidebar.tsx +239 -263
- package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
- package/src/modules/library/components/ShareButton.tsx +17 -0
- package/src/modules/library/components/SkillsTree.tsx +141 -28
- package/src/modules/library/components/TeamRoute.tsx +15 -0
- package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
- package/src/modules/library/components/plugin-page-parts.tsx +103 -17
- package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
- package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
- package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
- package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
- package/src/modules/library/hooks/useLibraryData.ts +92 -19
- package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
- package/src/modules/library/routes/library-paths.ts +26 -28
- package/src/modules/library/services/library.api.ts +38 -20
- package/src/modules/library/services/plugins.api.ts +69 -8
- package/src/modules/library/services/teams.api.ts +15 -0
- package/src/modules/library/services/tools.api.ts +78 -0
- package/src/modules/library/state/library-data.tsx +170 -32
- package/src/modules/library/utils/personal-plugin.ts +13 -15
- package/src/modules/library/utils/plugin-entries.ts +134 -0
- package/src/modules/library/utils/plugin-summary.ts +75 -9
- package/src/modules/library/utils/status.ts +135 -33
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
- package/src/modules/onboarding/agent-clients.ts +55 -23
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
- package/src/modules/pr/services/pr-merge.api.ts +2 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
- package/src/modules/review/components/ReviewPanel.tsx +15 -17
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
- package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
- package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
- package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
- package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
- package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
- package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
- package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
- package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
- package/src/modules/secrets-vault/services/connect.api.ts +36 -5
- package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
- package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
- package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
- package/src/modules/settings/components/DeploymentPage.tsx +10 -30
- package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
- package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +7 -6
- package/src/modules/settings/services/github-facade.api.ts +23 -0
- package/src/modules/settings/settings-nav-items.tsx +13 -3
- package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
- package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
- package/src/modules/setup/__tests__/setup.test.tsx +497 -4
- package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
- package/src/modules/setup/components/SetupGate.tsx +16 -16
- package/src/modules/setup/components/SetupScreen.tsx +532 -43
- package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +141 -4
- package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
- package/src/modules/setup/utils/root-folders.ts +46 -0
- package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
- package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
- package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
- package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
- package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
- package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
- package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
- package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
- package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
- package/src/modules/toolbar/components/deployment-address.ts +29 -0
- package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
- package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
- package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
- package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
- package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
- package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
- package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
- package/src/modules/workflow/state/event-bus.context.ts +10 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
- package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
- package/src/modules/workspace/components/FileRoute.tsx +353 -36
- package/src/modules/workspace/components/FileViewer.tsx +172 -46
- package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
- package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
- package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2533 -129
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +381 -12
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
- package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
- package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
- package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
- package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
- package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
- package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
- package/src/modules/workspace/components/renderers/index.ts +53 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
- package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
- package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
- package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
- package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
- package/src/modules/workspace/routing/kb-routes.ts +206 -29
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +134 -1
- package/src/modules/workspace/services/workspace.api.ts +57 -4
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
- package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
- package/src/modules/workspace/state/open-change-requests.tsx +100 -12
- package/src/modules/workspace/state/workspace.context.ts +125 -19
- package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
- package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
- package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
- package/src/modules/workspace/utils/file-trace.ts +50 -0
- package/src/modules/workspace/utils/fileTree.ts +112 -36
- package/src/modules/workspace/utils/frontmatter.ts +8 -4
- package/src/modules/workspace/utils/pasteLink.ts +90 -0
- package/src/modules/workspace/utils/treeConfirm.ts +338 -0
- package/src/modules/workspace/utils/uploadError.ts +29 -0
- package/src/shared/__tests__/marketplace-url.test.ts +6 -1
- package/src/shared/components/Button.tsx +16 -2
- package/src/shared/components/Dialog.tsx +27 -11
- package/src/shared/components/Menu.tsx +13 -1
- package/src/shared/components/PageShell.tsx +13 -8
- package/src/shared/components/__tests__/primitives.test.tsx +116 -2
- package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
- package/src/shared/components/index.ts +2 -0
- package/src/shared/components/useDismissableMenu.ts +32 -10
- package/src/shared/components/useFocusHandoff.ts +51 -0
- package/src/shared/components/useLatestRef.ts +28 -0
- package/src/shared/markdown/Markdown.tsx +12 -3
- package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
- package/src/shared/markdown/hrefs.ts +50 -0
- package/src/shared/marketplace-url.ts +33 -5
- package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
- package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
- package/src/shared/mcp/connect-snippets.ts +14 -9
- package/src/shared/mcp/index.ts +1 -1
- package/src/shared/theme/__tests__/header-band.test.ts +197 -0
- package/src/shared/theme/header.ts +75 -0
- package/src/shared/theme/measure.ts +7 -4
- package/src/shared/theme/tokens.css +25 -0
- package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
- package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
- package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
- package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
- package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
- package/src/modules/update-check/services/update-check.api.ts +0 -24
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { PR_STALE_EVENT } from '../../../core/events';
|
|
3
|
+
import { useEventBus } from './event-bus.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bus events after which every change-request list on the page is out of
|
|
7
|
+
* date, whoever caused them — a request appearing as much as one leaving.
|
|
8
|
+
* `resync` is here because it means the server could not replay what this tab
|
|
9
|
+
* missed — any of the others among it.
|
|
10
|
+
*/
|
|
11
|
+
const STALE_KINDS = [
|
|
12
|
+
'change-request-opened',
|
|
13
|
+
'change-request-merged',
|
|
14
|
+
'change-request-rejected',
|
|
15
|
+
'change-request-apply-failed',
|
|
16
|
+
'resync',
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Bridges change-request lifecycle events on the bus to {@link PR_STALE_EVENT},
|
|
21
|
+
* the one signal every change-request list already refetches on (the tree's
|
|
22
|
+
* open-request provider, the review dock, the Library catalog).
|
|
23
|
+
*
|
|
24
|
+
* Without it, only the tab that CLICKED Apply ever refreshed: the stale event
|
|
25
|
+
* was dispatched by that tab's own apply callback, so the author of the
|
|
26
|
+
* request and every other viewer kept its tree markers and its pending row
|
|
27
|
+
* until a manual reload — the "accepted request still shows as pending" bug.
|
|
28
|
+
* The merge was already broadcast to every session; nothing was listening.
|
|
29
|
+
*
|
|
30
|
+
* Renders nothing. Mounted once per tab, inside the bus provider.
|
|
31
|
+
*/
|
|
32
|
+
export function ChangeRequestStaleBinder() {
|
|
33
|
+
const bus = useEventBus();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!bus) return;
|
|
36
|
+
const markStale = () => window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
37
|
+
const offs = STALE_KINDS.map((kind) => bus.subscribe(kind, markStale));
|
|
38
|
+
return () => {
|
|
39
|
+
for (const off of offs) off();
|
|
40
|
+
};
|
|
41
|
+
}, [bus]);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
@@ -35,12 +35,27 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
35
35
|
// Per-tab session id. Generated once and persisted in sessionStorage so
|
|
36
36
|
// a refresh keeps the same id (which lets the server's ring buffer
|
|
37
37
|
// replay anything missed in the gap via Last-Event-ID).
|
|
38
|
+
// Storage is best-effort, NEVER load-bearing: `sessionStorage` throws on
|
|
39
|
+
// access in a sandboxed iframe and on write when the quota is full, and an
|
|
40
|
+
// unguarded call here took the entire app down with it (`#root` empty —
|
|
41
|
+
// this provider wraps the router). A tab that cannot persist its id still
|
|
42
|
+
// gets one, generated in memory; it just loses Last-Event-ID replay across
|
|
43
|
+
// a refresh, which is a degraded connection, not a blank page.
|
|
38
44
|
const sessionId = useMemo(() => {
|
|
39
45
|
if (typeof window === 'undefined') return ''; // SSR / test fallback
|
|
40
|
-
let id =
|
|
46
|
+
let id: string | null = null;
|
|
47
|
+
try {
|
|
48
|
+
id = window.sessionStorage.getItem(SESSION_ID_KEY);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.warn('sessionStorage unavailable; using an in-memory session id:', err);
|
|
51
|
+
}
|
|
41
52
|
if (!id) {
|
|
42
53
|
id = (window.crypto?.randomUUID?.() ?? `s-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
43
|
-
|
|
54
|
+
try {
|
|
55
|
+
window.sessionStorage.setItem(SESSION_ID_KEY, id);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn('Failed to persist the event-bus session id:', err);
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
return id;
|
|
46
61
|
}, []);
|
|
@@ -62,8 +77,30 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
62
77
|
// retry is possible whenever desired ≠ synced.
|
|
63
78
|
const focusRef = useRef<string | null>(null);
|
|
64
79
|
const desiredFocusRef = useRef<string | null>(null);
|
|
80
|
+
// Extra workspaces this tab wants events for beyond the focused one, and how
|
|
81
|
+
// many mounted consumers each. Ref-counted because two components can want
|
|
82
|
+
// the same workspace (a skill page and its review panel) and must release
|
|
83
|
+
// independently — a plain Set would let the first unmount cut the second's
|
|
84
|
+
// events. Kept in a ref, not state: it changes on mount/unmount, and the
|
|
85
|
+
// POST is driven by `focusVersion` like every other focus change.
|
|
86
|
+
const watchCountsRef = useRef<Map<string, number>>(new Map());
|
|
87
|
+
// What the last ACCEPTED POST carried, primary + extras. The synced/desired
|
|
88
|
+
// comparison in `setFocus` is against this, so adding a watch on the same
|
|
89
|
+
// primary focus still counts as a desync and gets posted.
|
|
90
|
+
const syncedKeyRef = useRef<string | null>(null);
|
|
91
|
+
// Tail of the focus-POST chain. See `postFocus`.
|
|
92
|
+
const focusChainRef = useRef<Promise<void>>(Promise.resolve());
|
|
65
93
|
const [focusVersion, setFocusVersion] = useState(0);
|
|
66
94
|
|
|
95
|
+
/** What this tab wants delivered, primary first — the wire form and the key. */
|
|
96
|
+
const watchListOf = useCallback(
|
|
97
|
+
(primary: string) => [
|
|
98
|
+
primary,
|
|
99
|
+
...[...watchCountsRef.current.keys()].filter((id) => id !== primary),
|
|
100
|
+
],
|
|
101
|
+
[],
|
|
102
|
+
);
|
|
103
|
+
|
|
67
104
|
const dispatch = useCallback((event: WorkflowEvent) => {
|
|
68
105
|
// Heartbeats are connection-keepalives only — they shouldn't reach
|
|
69
106
|
// app code. Same for resync (we'd want to refetch state from
|
|
@@ -109,22 +146,40 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
109
146
|
};
|
|
110
147
|
}, []);
|
|
111
148
|
|
|
112
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Send the CURRENT desired list, once. Reads `desiredFocusRef` and the watch
|
|
151
|
+
* counts at send time rather than taking them as arguments: by the time a
|
|
152
|
+
* queued send runs, a watch may have been added or released, and the only
|
|
153
|
+
* list worth sending is the one that is true now.
|
|
154
|
+
*/
|
|
155
|
+
const sendFocus = useCallback(async () => {
|
|
113
156
|
if (!sessionId) return;
|
|
157
|
+
const workspaceId = desiredFocusRef.current;
|
|
114
158
|
if (workspaceId === null) {
|
|
115
159
|
// No "clear focus" endpoint server-side; setting null is a frontend
|
|
116
160
|
// signal that we don't currently want workspace events. The next
|
|
117
161
|
// setFocus(workspaceId) re-syncs the server. This is fine because
|
|
118
162
|
// an idle focus simply means no workspace-scoped events arrive.
|
|
119
163
|
focusRef.current = null;
|
|
164
|
+
syncedKeyRef.current = null;
|
|
120
165
|
return;
|
|
121
166
|
}
|
|
167
|
+
const alsoWatch = watchListOf(workspaceId).slice(1);
|
|
168
|
+
const key = [workspaceId, ...alsoWatch].join('\n');
|
|
169
|
+
// Coalesce: several sends can queue behind one slow request (a watch
|
|
170
|
+
// added and released while it is in flight), and every one of them would
|
|
171
|
+
// otherwise re-send a list the server already has. `syncedKeyRef` is
|
|
172
|
+
// cleared on reconnect, so this never skips the resync.
|
|
173
|
+
if (syncedKeyRef.current === key) return;
|
|
122
174
|
try {
|
|
123
175
|
const response = await fetch(`/api/events/${encodeURIComponent(sessionId)}/focus`, {
|
|
124
176
|
method: 'POST',
|
|
125
177
|
credentials: 'include',
|
|
126
178
|
headers: { 'Content-Type': 'application/json' },
|
|
127
|
-
|
|
179
|
+
// `workspaceId` stays the primary field it always was; `alsoWatch`
|
|
180
|
+
// carries the rest. A server that doesn't know the second field still
|
|
181
|
+
// gets the focus right, it just doesn't deliver the extras.
|
|
182
|
+
body: JSON.stringify({ workspaceId, alsoWatch }),
|
|
128
183
|
});
|
|
129
184
|
if (!response.ok) {
|
|
130
185
|
// Server rejected the focus update (most likely 404 — session
|
|
@@ -146,24 +201,71 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
146
201
|
}
|
|
147
202
|
// Server accepted: synced focus catches up to desired.
|
|
148
203
|
focusRef.current = workspaceId;
|
|
204
|
+
syncedKeyRef.current = key;
|
|
149
205
|
} catch (err) {
|
|
150
206
|
// Network blip — `focusRef` stays at its last successfully-synced
|
|
151
207
|
// value, so a follow-up setFocus to the same workspaceId still
|
|
152
208
|
// detects desync and retries.
|
|
153
209
|
console.warn('[event-bus] focus POST failed:', err);
|
|
154
210
|
}
|
|
155
|
-
}, [sessionId]);
|
|
211
|
+
}, [sessionId, watchListOf]);
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* ONE FOCUS POST AT A TIME, in the order they were asked for.
|
|
215
|
+
*
|
|
216
|
+
* These requests are not independent: each one REPLACES the session's whole
|
|
217
|
+
* delivery list, so the last to reach the server wins. Fired concurrently —
|
|
218
|
+
* which is what a watch registered while a focus change is in flight does —
|
|
219
|
+
* two can be processed out of order, leaving the server holding the older
|
|
220
|
+
* list while this tab records the newer one as synced. Nothing retries after
|
|
221
|
+
* that, and the workspace that lost its watch goes quiet for the life of the
|
|
222
|
+
* tab: the exact silent staleness the watch list exists to fix.
|
|
223
|
+
*
|
|
224
|
+
* Chaining is enough because `sendFocus` reads the desired state when it
|
|
225
|
+
* runs, so a queued send carries the latest list rather than a stale
|
|
226
|
+
* snapshot, and a redundant one returns without a request.
|
|
227
|
+
*/
|
|
228
|
+
const postFocus = useCallback(() => {
|
|
229
|
+
const next = focusChainRef.current.then(() => sendFocus());
|
|
230
|
+
focusChainRef.current = next.catch(() => {});
|
|
231
|
+
return next;
|
|
232
|
+
}, [sendFocus]);
|
|
156
233
|
|
|
157
234
|
const setFocus = useCallback<EventBusContextValue['setFocus']>((workspaceId) => {
|
|
158
|
-
// Compare against SYNCED
|
|
159
|
-
// after a previous POST failure isn't short-circuited.
|
|
160
|
-
|
|
235
|
+
// Compare against the SYNCED list, not the desired one — that way a retry
|
|
236
|
+
// after a previous POST failure isn't short-circuited. The whole list, not
|
|
237
|
+
// just the primary, so a watch added while the focus stands still is still
|
|
238
|
+
// a desync worth posting.
|
|
239
|
+
const desiredKey = workspaceId === null ? null : watchListOf(workspaceId).join('\n');
|
|
240
|
+
if (syncedKeyRef.current === desiredKey && focusRef.current === workspaceId) {
|
|
161
241
|
desiredFocusRef.current = workspaceId;
|
|
162
242
|
return;
|
|
163
243
|
}
|
|
164
244
|
console.debug('[event-bus] setFocus', { from: focusRef.current, to: workspaceId });
|
|
165
245
|
desiredFocusRef.current = workspaceId;
|
|
166
246
|
setFocusVersion((v) => v + 1);
|
|
247
|
+
}, [watchListOf]);
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Add a workspace to this tab's delivery list until the returned fn runs.
|
|
251
|
+
* Re-POSTs the focus so the server hears about it; if there is no focus yet
|
|
252
|
+
* the new entry rides along with the first `setFocus`, which the workspace
|
|
253
|
+
* bootstrap always issues.
|
|
254
|
+
*/
|
|
255
|
+
const watchWorkspace = useCallback<EventBusContextValue['watchWorkspace']>((workspaceId) => {
|
|
256
|
+
const counts = watchCountsRef.current;
|
|
257
|
+
counts.set(workspaceId, (counts.get(workspaceId) ?? 0) + 1);
|
|
258
|
+
if (desiredFocusRef.current !== null) setFocusVersion((v) => v + 1);
|
|
259
|
+
let released = false;
|
|
260
|
+
return () => {
|
|
261
|
+
// Idempotent: a double release must not decrement someone else's count.
|
|
262
|
+
if (released) return;
|
|
263
|
+
released = true;
|
|
264
|
+
const remaining = (counts.get(workspaceId) ?? 1) - 1;
|
|
265
|
+
if (remaining > 0) counts.set(workspaceId, remaining);
|
|
266
|
+
else counts.delete(workspaceId);
|
|
267
|
+
if (desiredFocusRef.current !== null) setFocusVersion((v) => v + 1);
|
|
268
|
+
};
|
|
167
269
|
}, []);
|
|
168
270
|
|
|
169
271
|
// EventSource lifecycle. One connection per tab, opened once on mount,
|
|
@@ -183,7 +285,13 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
183
285
|
// self-heals on the next open. First-time-open will have desired
|
|
184
286
|
// === null until a consumer (workspace state) calls setFocus.
|
|
185
287
|
if (desiredFocusRef.current !== null) {
|
|
186
|
-
|
|
288
|
+
// A reconnect is a NEW server-side session record, with an empty
|
|
289
|
+
// delivery list — whatever this tab had synced is gone with the old
|
|
290
|
+
// one. Clearing the synced key is what stops `sendFocus` coalescing
|
|
291
|
+
// the resync away as "already sent".
|
|
292
|
+
syncedKeyRef.current = null;
|
|
293
|
+
focusRef.current = null;
|
|
294
|
+
void postFocus();
|
|
187
295
|
}
|
|
188
296
|
};
|
|
189
297
|
|
|
@@ -223,10 +331,13 @@ export function EventBusProvider({ children }: { children: ReactNode }) {
|
|
|
223
331
|
// lifecycle so a focus change doesn't reconnect.
|
|
224
332
|
useEffect(() => {
|
|
225
333
|
if (focusVersion === 0) return;
|
|
226
|
-
void postFocus(
|
|
334
|
+
void postFocus();
|
|
227
335
|
}, [focusVersion, postFocus]);
|
|
228
336
|
|
|
229
|
-
const value = useMemo<EventBusContextValue>(
|
|
337
|
+
const value = useMemo<EventBusContextValue>(
|
|
338
|
+
() => ({ subscribe, setFocus, watchWorkspace }),
|
|
339
|
+
[subscribe, setFocus, watchWorkspace],
|
|
340
|
+
);
|
|
230
341
|
|
|
231
342
|
return <EventBusContext.Provider value={value}>{children}</EventBusContext.Provider>;
|
|
232
343
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { EventBusProvider, SESSION_ID_KEY } from '../EventBusProvider';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `sessionStorage` is best-effort, never load-bearing. It throws outright on
|
|
7
|
+
* ACCESS inside a sandboxed iframe, and on write when the quota is full or the
|
|
8
|
+
* user has blocked site data. This provider wraps the router, so an unguarded
|
|
9
|
+
* call took the whole app down with it: `#root` empty, no error screen, no
|
|
10
|
+
* file page at all. The tab must still render, with an id it made up.
|
|
11
|
+
*/
|
|
12
|
+
describe('EventBusProvider: sessionStorage that throws', () => {
|
|
13
|
+
const realStorage = Object.getOwnPropertyDescriptor(window, 'sessionStorage');
|
|
14
|
+
let warn: ReturnType<typeof vi.spyOn>;
|
|
15
|
+
|
|
16
|
+
/** Swap `window.sessionStorage` for something that behaves as described. */
|
|
17
|
+
function useStorage(stub: Pick<Storage, 'getItem' | 'setItem'>) {
|
|
18
|
+
Object.defineProperty(window, 'sessionStorage', { configurable: true, value: stub });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
23
|
+
// No EventSource in this environment: the connection effect is not what's
|
|
24
|
+
// under test, only that the provider renders its children at all.
|
|
25
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response('{}', { status: 200 })));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (realStorage) Object.defineProperty(window, 'sessionStorage', realStorage);
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
vi.unstubAllGlobals();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders the app when READING the session id throws', () => {
|
|
35
|
+
const setItem = vi.fn();
|
|
36
|
+
useStorage({
|
|
37
|
+
getItem: () => { throw new DOMException('The operation is insecure.', 'SecurityError'); },
|
|
38
|
+
setItem,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
render(
|
|
42
|
+
<EventBusProvider>
|
|
43
|
+
<div>the app</div>
|
|
44
|
+
</EventBusProvider>,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(screen.getByText('the app')).toBeInTheDocument();
|
|
48
|
+
// It still generated an id and still tried to keep it.
|
|
49
|
+
expect(setItem).toHaveBeenCalledWith(SESSION_ID_KEY, expect.any(String));
|
|
50
|
+
expect(warn).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('renders the app when PERSISTING the session id throws, on an in-memory id', () => {
|
|
54
|
+
const setItem = vi.fn(() => {
|
|
55
|
+
throw new DOMException('QuotaExceededError', 'QuotaExceededError');
|
|
56
|
+
});
|
|
57
|
+
useStorage({ getItem: () => null, setItem });
|
|
58
|
+
|
|
59
|
+
render(
|
|
60
|
+
<EventBusProvider>
|
|
61
|
+
<div>the app</div>
|
|
62
|
+
</EventBusProvider>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(screen.getByText('the app')).toBeInTheDocument();
|
|
66
|
+
expect(setItem).toHaveBeenCalledWith(SESSION_ID_KEY, expect.any(String));
|
|
67
|
+
expect(warn).toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('persists the generated id, and says nothing, when storage works', () => {
|
|
71
|
+
const store = new Map<string, string>();
|
|
72
|
+
useStorage({
|
|
73
|
+
getItem: (k: string) => store.get(k) ?? null,
|
|
74
|
+
setItem: (k: string, v: string) => { store.set(k, v); },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
render(
|
|
78
|
+
<EventBusProvider>
|
|
79
|
+
<div>the app</div>
|
|
80
|
+
</EventBusProvider>,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(screen.getByText('the app')).toBeInTheDocument();
|
|
84
|
+
expect(store.get(SESSION_ID_KEY)).toBeTruthy();
|
|
85
|
+
expect(warn).not.toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import { act, render } from '@testing-library/react';
|
|
3
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
4
|
+
import { EventBusProvider } from '../EventBusProvider';
|
|
5
|
+
import { EventBusContext, type EventBusContextValue } from '../event-bus.context';
|
|
6
|
+
|
|
7
|
+
/** The focus POSTs the provider made, newest last. */
|
|
8
|
+
function focusBodies(fetchMock: ReturnType<typeof vi.fn>): { workspaceId: string; alsoWatch: string[] }[] {
|
|
9
|
+
return fetchMock.mock.calls
|
|
10
|
+
.filter(([url]) => String(url).includes('/focus'))
|
|
11
|
+
.map(([, init]) => JSON.parse((init as RequestInit).body as string));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function Harness({ onReady }: { onReady: (bus: EventBusContextValue) => void }) {
|
|
15
|
+
const bus = useContext(EventBusContext);
|
|
16
|
+
const fired = useRef(false);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!bus || fired.current) return;
|
|
19
|
+
fired.current = true;
|
|
20
|
+
onReady(bus);
|
|
21
|
+
}, [bus, onReady]);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* jsdom ships no EventSource, and the provider skips its connection effect
|
|
27
|
+
* without one — which also skips the `open` handler that re-syncs focus after
|
|
28
|
+
* a reconnect. This stub makes that path reachable and lets a test fire a
|
|
29
|
+
* second `open` the way a dropped-and-restored stream does.
|
|
30
|
+
*/
|
|
31
|
+
class FakeEventSource {
|
|
32
|
+
static instances: FakeEventSource[] = [];
|
|
33
|
+
listeners = new Map<string, ((e: Event) => void)[]>();
|
|
34
|
+
constructor() {
|
|
35
|
+
FakeEventSource.instances.push(this);
|
|
36
|
+
}
|
|
37
|
+
addEventListener(type: string, fn: (e: Event) => void) {
|
|
38
|
+
const bucket = this.listeners.get(type) ?? [];
|
|
39
|
+
bucket.push(fn);
|
|
40
|
+
this.listeners.set(type, bucket);
|
|
41
|
+
}
|
|
42
|
+
removeEventListener(type: string, fn: (e: Event) => void) {
|
|
43
|
+
this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
|
|
44
|
+
}
|
|
45
|
+
close() {}
|
|
46
|
+
fire(type: string) {
|
|
47
|
+
for (const fn of [...(this.listeners.get(type) ?? [])]) fn(new Event(type));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let fetchMock: ReturnType<typeof vi.fn>;
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
fetchMock = vi.fn(async () => new Response(JSON.stringify({ status: 'ok' }), { status: 200 }));
|
|
55
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
56
|
+
FakeEventSource.instances = [];
|
|
57
|
+
vi.stubGlobal('EventSource', FakeEventSource);
|
|
58
|
+
window.sessionStorage.setItem('bevel-event-bus-session-id', 'sess-1');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
vi.unstubAllGlobals();
|
|
63
|
+
window.sessionStorage.clear();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The delivery list this tab declares to the server. One focus per session was
|
|
68
|
+
* the model until a page needed content from a workspace other than the branch
|
|
69
|
+
* in the address bar — the skill page renders the default branch's files from
|
|
70
|
+
* wherever you are standing, and its images heard nothing about a teammate
|
|
71
|
+
* replacing one.
|
|
72
|
+
*/
|
|
73
|
+
describe('EventBusProvider watchWorkspace', () => {
|
|
74
|
+
it('carries a watched workspace alongside the focus', async () => {
|
|
75
|
+
let bus!: EventBusContextValue;
|
|
76
|
+
render(
|
|
77
|
+
<EventBusProvider>
|
|
78
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
79
|
+
</EventBusProvider>,
|
|
80
|
+
);
|
|
81
|
+
await act(async () => {
|
|
82
|
+
bus.watchWorkspace('main');
|
|
83
|
+
bus.setFocus('alice%2Fdraft');
|
|
84
|
+
});
|
|
85
|
+
const last = focusBodies(fetchMock).at(-1);
|
|
86
|
+
expect(last?.workspaceId).toBe('alice%2Fdraft');
|
|
87
|
+
expect(last?.alsoWatch).toEqual(['main']);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('re-posts when a watch is added after the focus is already set', async () => {
|
|
91
|
+
let bus!: EventBusContextValue;
|
|
92
|
+
render(
|
|
93
|
+
<EventBusProvider>
|
|
94
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
95
|
+
</EventBusProvider>,
|
|
96
|
+
);
|
|
97
|
+
await act(async () => bus.setFocus('alice%2Fdraft'));
|
|
98
|
+
expect(focusBodies(fetchMock).at(-1)?.alsoWatch).toEqual([]);
|
|
99
|
+
await act(async () => bus.watchWorkspace('main'));
|
|
100
|
+
expect(focusBodies(fetchMock).at(-1)?.alsoWatch).toEqual(['main']);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Two components can want the same workspace; the first to unmount must not
|
|
104
|
+
// cut the second's events.
|
|
105
|
+
it('ref-counts, so a release only drops the last holder', async () => {
|
|
106
|
+
let bus!: EventBusContextValue;
|
|
107
|
+
render(
|
|
108
|
+
<EventBusProvider>
|
|
109
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
110
|
+
</EventBusProvider>,
|
|
111
|
+
);
|
|
112
|
+
let releaseA!: () => void;
|
|
113
|
+
let releaseB!: () => void;
|
|
114
|
+
await act(async () => {
|
|
115
|
+
releaseA = bus.watchWorkspace('main');
|
|
116
|
+
releaseB = bus.watchWorkspace('main');
|
|
117
|
+
bus.setFocus('alice%2Fdraft');
|
|
118
|
+
});
|
|
119
|
+
await act(async () => releaseA());
|
|
120
|
+
expect(focusBodies(fetchMock).at(-1)?.alsoWatch).toEqual(['main']);
|
|
121
|
+
await act(async () => releaseB());
|
|
122
|
+
expect(focusBodies(fetchMock).at(-1)?.alsoWatch).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// These POSTs are not independent: each REPLACES the session's whole
|
|
126
|
+
// delivery list, so the last to reach the server wins. Fired concurrently,
|
|
127
|
+
// two can be processed out of order, leaving the server on the older list
|
|
128
|
+
// while this tab records the newer one as synced — after which nothing
|
|
129
|
+
// retries and the workspace that lost its watch is silent for the life of
|
|
130
|
+
// the tab.
|
|
131
|
+
it('sends one focus POST at a time, so a slow one cannot overwrite a newer list', async () => {
|
|
132
|
+
const releases: (() => void)[] = [];
|
|
133
|
+
fetchMock.mockImplementation(
|
|
134
|
+
() =>
|
|
135
|
+
new Promise((resolve) => {
|
|
136
|
+
releases.push(() => resolve(new Response(JSON.stringify({ status: 'ok' }), { status: 200 })));
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
let bus!: EventBusContextValue;
|
|
140
|
+
render(
|
|
141
|
+
<EventBusProvider>
|
|
142
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
143
|
+
</EventBusProvider>,
|
|
144
|
+
);
|
|
145
|
+
await act(async () => bus.setFocus('alice%2Fdraft'));
|
|
146
|
+
// The first POST is in flight and unanswered; a watch lands on top of it.
|
|
147
|
+
await act(async () => bus.watchWorkspace('main'));
|
|
148
|
+
expect(releases).toHaveLength(1);
|
|
149
|
+
|
|
150
|
+
// Only once the first completes does the second go out, carrying the list
|
|
151
|
+
// as it stands now rather than the snapshot it was queued with.
|
|
152
|
+
await act(async () => releases[0]());
|
|
153
|
+
expect(releases).toHaveLength(2);
|
|
154
|
+
await act(async () => releases[1]());
|
|
155
|
+
|
|
156
|
+
const bodies = focusBodies(fetchMock);
|
|
157
|
+
expect(bodies.at(-1)?.alsoWatch).toEqual(['main']);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Serialising the sends means a queued one can find the list already synced
|
|
161
|
+
// and skip its request. That is the point, but it must only skip when the
|
|
162
|
+
// SERVER still holds the list.
|
|
163
|
+
it('skips a redundant send when the server already holds that list', async () => {
|
|
164
|
+
let bus!: EventBusContextValue;
|
|
165
|
+
render(
|
|
166
|
+
<EventBusProvider>
|
|
167
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
168
|
+
</EventBusProvider>,
|
|
169
|
+
);
|
|
170
|
+
await act(async () => {
|
|
171
|
+
bus.watchWorkspace('main');
|
|
172
|
+
bus.setFocus('alice%2Fdraft');
|
|
173
|
+
});
|
|
174
|
+
const sentBefore = focusBodies(fetchMock).length;
|
|
175
|
+
await act(async () => bus.setFocus('alice%2Fdraft'));
|
|
176
|
+
expect(focusBodies(fetchMock)).toHaveLength(sentBefore);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// ...and a reconnect is exactly when it no longer does: the server has a NEW
|
|
180
|
+
// session record with an empty delivery list, so a coalesced resync would
|
|
181
|
+
// leave the tab believing in watches nobody is honouring.
|
|
182
|
+
it('re-posts the whole list on every reconnect, coalescing notwithstanding', async () => {
|
|
183
|
+
let bus!: EventBusContextValue;
|
|
184
|
+
render(
|
|
185
|
+
<EventBusProvider>
|
|
186
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
187
|
+
</EventBusProvider>,
|
|
188
|
+
);
|
|
189
|
+
await act(async () => {
|
|
190
|
+
bus.watchWorkspace('main');
|
|
191
|
+
bus.setFocus('alice%2Fdraft');
|
|
192
|
+
});
|
|
193
|
+
expect(FakeEventSource.instances).toHaveLength(1);
|
|
194
|
+
const stream = FakeEventSource.instances[0];
|
|
195
|
+
|
|
196
|
+
// The stream's FIRST open, which is not a reconnect. Baseline is taken
|
|
197
|
+
// after it so the assertion below is about the second one alone.
|
|
198
|
+
await act(async () => stream.fire('open'));
|
|
199
|
+
const sentBefore = focusBodies(fetchMock).length;
|
|
200
|
+
|
|
201
|
+
// Dropped and restored. The list goes out again, in full.
|
|
202
|
+
await act(async () => stream.fire('open'));
|
|
203
|
+
const bodies = focusBodies(fetchMock);
|
|
204
|
+
expect(bodies.length).toBe(sentBefore + 1);
|
|
205
|
+
expect(bodies.at(-1)).toEqual({ workspaceId: 'alice%2Fdraft', alsoWatch: ['main'] });
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('does not list the focused workspace twice when it is also watched', async () => {
|
|
209
|
+
let bus!: EventBusContextValue;
|
|
210
|
+
render(
|
|
211
|
+
<EventBusProvider>
|
|
212
|
+
<Harness onReady={(b) => (bus = b)} />
|
|
213
|
+
</EventBusProvider>,
|
|
214
|
+
);
|
|
215
|
+
await act(async () => {
|
|
216
|
+
bus.watchWorkspace('main');
|
|
217
|
+
bus.setFocus('main');
|
|
218
|
+
});
|
|
219
|
+
const last = focusBodies(fetchMock).at(-1);
|
|
220
|
+
expect(last?.workspaceId).toBe('main');
|
|
221
|
+
expect(last?.alsoWatch).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -24,6 +24,15 @@ export type EventHandler<K extends WorkflowEvent['kind']> = (
|
|
|
24
24
|
* `useWorkspaceState`). Setting `null` clears the focus — the session
|
|
25
25
|
* stays alive but receives no workspace-scoped events.
|
|
26
26
|
*
|
|
27
|
+
* - `watchWorkspace(workspaceId)` — ALSO deliver events for a workspace
|
|
28
|
+
* that isn't the focused one, until the returned release fn is called.
|
|
29
|
+
* For a page whose content comes from somewhere other than the branch
|
|
30
|
+
* in the address bar: the skill page renders the default branch's
|
|
31
|
+
* files while the reader stands on their own suggestion branch, and
|
|
32
|
+
* without this its images never hear that a teammate replaced one.
|
|
33
|
+
* Ref-counted, so two components watching the same workspace release
|
|
34
|
+
* independently.
|
|
35
|
+
*
|
|
27
36
|
* The provider owns one EventSource per tab; this interface intentionally
|
|
28
37
|
* doesn't expose connection state — consumers shouldn't care whether the
|
|
29
38
|
* underlying stream is open, reconnecting, or replaying. If a feature
|
|
@@ -32,6 +41,7 @@ export type EventHandler<K extends WorkflowEvent['kind']> = (
|
|
|
32
41
|
export interface EventBusContextValue {
|
|
33
42
|
subscribe<K extends WorkflowEvent['kind']>(kind: K, handler: EventHandler<K>): () => void;
|
|
34
43
|
setFocus(workspaceId: string | null): void;
|
|
44
|
+
watchWorkspace(workspaceId: string): () => void;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
export const EventBusContext = createContext<EventBusContextValue | null>(null);
|
|
@@ -14,6 +14,8 @@ export function makeWorkspaceFixture(
|
|
|
14
14
|
kbDirName: 'knowledge-base',
|
|
15
15
|
fileTree: null,
|
|
16
16
|
bootstrapError: null,
|
|
17
|
+
workspaceBranch: 'main',
|
|
18
|
+
retryBootstrap: () => {},
|
|
17
19
|
openTabs: [],
|
|
18
20
|
activeTab: null,
|
|
19
21
|
dirtyTabFilenames: [],
|
|
@@ -26,8 +28,8 @@ export function makeWorkspaceFixture(
|
|
|
26
28
|
bumpFsRevision: () => {},
|
|
27
29
|
setPersistenceBranch: () => {},
|
|
28
30
|
fsRevision: 0,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
uploadErrors: new Map(),
|
|
32
|
+
uploadNotices: new Map(),
|
|
31
33
|
clearUploadNotice: () => {},
|
|
32
34
|
isUploading: false,
|
|
33
35
|
uploadProgress: null,
|
|
@@ -38,7 +40,7 @@ export function makeWorkspaceFixture(
|
|
|
38
40
|
activateTab: () => {},
|
|
39
41
|
reorderTab: () => {},
|
|
40
42
|
closeAllTabs: () => {},
|
|
41
|
-
hydrateTabs: async () => ({ surviving: [], dropped: [], denied: [] }),
|
|
43
|
+
hydrateTabs: async () => ({ surviving: [], dropped: [], denied: [], superseded: false }),
|
|
42
44
|
createFile: async () => {},
|
|
43
45
|
createDirectory: async () => {},
|
|
44
46
|
unzipHere: async () => ({ extracted: 0, skipped: [], destination: '' }),
|