@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,286 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { act, render, renderHook, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type {
|
|
5
|
+
ChangeRequestApplyFailure,
|
|
6
|
+
PullRequestSummary,
|
|
7
|
+
WorkflowEvent,
|
|
8
|
+
WorkflowEventPayload,
|
|
9
|
+
} from '@bevel-software/platform-shared';
|
|
10
|
+
|
|
11
|
+
const detailMock = vi.hoisted(() => ({ fetchPrDetail: vi.fn() }));
|
|
12
|
+
vi.mock('../../pr/services/pr-detail.api', () => ({ fetchPrDetail: detailMock.fetchPrDetail }));
|
|
13
|
+
const mergeMock = vi.hoisted(() => ({ mergePullRequest: vi.fn() }));
|
|
14
|
+
vi.mock('../../pr/services/pr-merge.api', () => ({ mergePullRequest: mergeMock.mergePullRequest }));
|
|
15
|
+
vi.mock('../../pr/services/pr-approvals.api', () => ({
|
|
16
|
+
approvePrFile: vi.fn(),
|
|
17
|
+
revertPrFile: vi.fn(),
|
|
18
|
+
unapprovePrFile: vi.fn(),
|
|
19
|
+
}));
|
|
20
|
+
vi.mock('../../pr/services/pr-cancel.api', () => ({
|
|
21
|
+
cancelPullRequest: vi.fn(),
|
|
22
|
+
deleteChangeRequest: vi.fn(),
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('../services/change-requests.api', () => ({
|
|
25
|
+
readFileOnBranch: vi.fn(async () => 'branch copy'),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
import { refusalLine, useApplyChangeRequest } from '../hooks/useApplyChangeRequest';
|
|
29
|
+
import { ChangeRequestDialog } from '../components/ChangeRequestDialog';
|
|
30
|
+
import {
|
|
31
|
+
EventBusContext,
|
|
32
|
+
type EventBusContextValue,
|
|
33
|
+
} from '../../workflow/state/event-bus.context';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The other half of the ticket: a FAILED apply used to be told only to the
|
|
37
|
+
* person who clicked (a user-scoped event, read by the clicking tab's hook).
|
|
38
|
+
* The request's author and any other owner saw it still pending with no word
|
|
39
|
+
* of why. The refusal is now persisted on the request and read back by every
|
|
40
|
+
* viewer; these tests pin what a SECOND viewer sees, and the clicker's own
|
|
41
|
+
* backstop for an outcome event that never arrives.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const CR: PullRequestSummary = {
|
|
45
|
+
number: 7,
|
|
46
|
+
title: 'Upload into Plugins/x',
|
|
47
|
+
authorId: 'bo',
|
|
48
|
+
author: { login: 'user-bo', name: 'Bo Business' },
|
|
49
|
+
appAuthor: { name: 'Bo Business' },
|
|
50
|
+
branch: 'suggestions/bo/knowledge',
|
|
51
|
+
base: 'main',
|
|
52
|
+
state: 'open',
|
|
53
|
+
createdAt: '2026-09-16T09:00:00.000Z',
|
|
54
|
+
touchedNodePaths: ['Plugins/x/SKILL.md'],
|
|
55
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
56
|
+
url: '/change-requests/7',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const FAILURE: ChangeRequestApplyFailure = {
|
|
60
|
+
reason: 'Waiting on approval for Plugins/x/SKILL.md from Plugin owners.',
|
|
61
|
+
conflicts: false,
|
|
62
|
+
at: '2026-09-16T10:00:00.000Z',
|
|
63
|
+
byName: 'Ada Admin',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function fakeBus() {
|
|
67
|
+
const handlers = new Map<string, Set<(e: WorkflowEvent) => void>>();
|
|
68
|
+
const value: EventBusContextValue = {
|
|
69
|
+
subscribe: (kind, handler) => {
|
|
70
|
+
const set = handlers.get(kind) ?? new Set();
|
|
71
|
+
set.add(handler as (e: WorkflowEvent) => void);
|
|
72
|
+
handlers.set(kind, set);
|
|
73
|
+
return () => set.delete(handler as (e: WorkflowEvent) => void);
|
|
74
|
+
},
|
|
75
|
+
setFocus: () => {},
|
|
76
|
+
watchWorkspace: () => () => {},
|
|
77
|
+
};
|
|
78
|
+
const emit = (event: WorkflowEventPayload) => {
|
|
79
|
+
for (const h of handlers.get(event.kind) ?? []) {
|
|
80
|
+
h({ id: 1, ts: new Date().toISOString(), ...event } as WorkflowEvent);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return { value, emit };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function detail(over: { state?: string; lastApplyFailure?: ChangeRequestApplyFailure | null } = {}) {
|
|
87
|
+
return {
|
|
88
|
+
...CR,
|
|
89
|
+
state: over.state ?? 'open',
|
|
90
|
+
lastApplyFailure: over.lastApplyFailure ?? null,
|
|
91
|
+
body: '',
|
|
92
|
+
headSha: 'h',
|
|
93
|
+
baseSha: 'b',
|
|
94
|
+
files: [
|
|
95
|
+
{
|
|
96
|
+
path: 'Plugins/x/SKILL.md',
|
|
97
|
+
status: 'added' as const,
|
|
98
|
+
additions: 3,
|
|
99
|
+
deletions: 0,
|
|
100
|
+
isBinary: false,
|
|
101
|
+
sha: '',
|
|
102
|
+
rawUrl: '',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
comments: [],
|
|
106
|
+
approvals: [],
|
|
107
|
+
mergeableInBevel: true,
|
|
108
|
+
mergeBlockedReasons: [],
|
|
109
|
+
mergeWarnings: [],
|
|
110
|
+
viewerCanBypassMerge: false,
|
|
111
|
+
viewerCanCancel: false,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
beforeEach(() => {
|
|
116
|
+
detailMock.fetchPrDetail.mockReset();
|
|
117
|
+
mergeMock.mergePullRequest.mockReset();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('a failed apply is visible to a second viewer', () => {
|
|
121
|
+
it('the dialog of a viewer who did not click shows who failed to apply it and why, live', async () => {
|
|
122
|
+
const bus = fakeBus();
|
|
123
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
124
|
+
render(
|
|
125
|
+
<EventBusContext.Provider value={bus.value}>
|
|
126
|
+
<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />
|
|
127
|
+
</EventBusContext.Provider>,
|
|
128
|
+
);
|
|
129
|
+
await waitFor(() => expect(detailMock.fetchPrDetail).toHaveBeenCalledTimes(1));
|
|
130
|
+
expect(screen.queryByText(/could not apply this/)).not.toBeInTheDocument();
|
|
131
|
+
|
|
132
|
+
// The admin's apply fails elsewhere; the server persisted the refusal.
|
|
133
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail({ lastApplyFailure: FAILURE }));
|
|
134
|
+
act(() => bus.emit({ kind: 'change-request-apply-failed', number: 7 }));
|
|
135
|
+
|
|
136
|
+
expect(await screen.findByText(/Ada Admin could not apply this/)).toBeInTheDocument();
|
|
137
|
+
expect(screen.getByText(/Waiting on approval for Plugins\/x\/SKILL\.md/)).toBeInTheDocument();
|
|
138
|
+
expect(detailMock.fetchPrDetail).toHaveBeenLastCalledWith(7, { fresh: true });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('opened after the failure (a reload), the dialog shows the same refusal', async () => {
|
|
142
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail({ lastApplyFailure: FAILURE }));
|
|
143
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
144
|
+
expect(await screen.findByText(/Ada Admin could not apply this/)).toBeInTheDocument();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('an older detail read resolving last does not put back what a newer one replaced', async () => {
|
|
148
|
+
const bus = fakeBus();
|
|
149
|
+
let releaseOpening!: (d: ReturnType<typeof detail>) => void;
|
|
150
|
+
detailMock.fetchPrDetail.mockReturnValueOnce(
|
|
151
|
+
new Promise((r) => {
|
|
152
|
+
releaseOpening = r;
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
render(
|
|
156
|
+
<EventBusContext.Provider value={bus.value}>
|
|
157
|
+
<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />
|
|
158
|
+
</EventBusContext.Provider>,
|
|
159
|
+
);
|
|
160
|
+
detailMock.fetchPrDetail.mockResolvedValueOnce(detail({ lastApplyFailure: FAILURE }));
|
|
161
|
+
act(() => bus.emit({ kind: 'change-request-apply-failed', number: 7 }));
|
|
162
|
+
expect(await screen.findByText(/Ada Admin could not apply this/)).toBeInTheDocument();
|
|
163
|
+
|
|
164
|
+
// The opening read, sent before the failure, arrives last.
|
|
165
|
+
await act(async () => releaseOpening(detail()));
|
|
166
|
+
expect(screen.getByText(/Ada Admin could not apply this/)).toBeInTheDocument();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('a request somebody else applies while the dialog is open offers no second apply', async () => {
|
|
170
|
+
const bus = fakeBus();
|
|
171
|
+
const approved = [
|
|
172
|
+
{
|
|
173
|
+
path: 'Plugins/x/SKILL.md',
|
|
174
|
+
isApproved: true,
|
|
175
|
+
viewerCanApprove: true,
|
|
176
|
+
eligibleApprovers: { roles: [], users: [] },
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
detailMock.fetchPrDetail.mockResolvedValue({ ...detail(), approvals: approved });
|
|
180
|
+
render(
|
|
181
|
+
<EventBusContext.Provider value={bus.value}>
|
|
182
|
+
<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />
|
|
183
|
+
</EventBusContext.Provider>,
|
|
184
|
+
);
|
|
185
|
+
expect(await screen.findByRole('button', { name: 'Apply changes' })).toBeInTheDocument();
|
|
186
|
+
|
|
187
|
+
detailMock.fetchPrDetail.mockResolvedValue({ ...detail({ state: 'merged' }), approvals: approved });
|
|
188
|
+
act(() => bus.emit({ kind: 'change-request-merged', number: 7 }));
|
|
189
|
+
await waitFor(() =>
|
|
190
|
+
expect(screen.queryByRole('button', { name: 'Apply changes' })).not.toBeInTheDocument(),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('ignores another request’s failure', async () => {
|
|
195
|
+
const bus = fakeBus();
|
|
196
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
197
|
+
render(
|
|
198
|
+
<EventBusContext.Provider value={bus.value}>
|
|
199
|
+
<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />
|
|
200
|
+
</EventBusContext.Provider>,
|
|
201
|
+
);
|
|
202
|
+
await waitFor(() => expect(detailMock.fetchPrDetail).toHaveBeenCalledTimes(1));
|
|
203
|
+
act(() => bus.emit({ kind: 'change-request-apply-failed', number: 99 }));
|
|
204
|
+
expect(detailMock.fetchPrDetail).toHaveBeenCalledTimes(1);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('refusalLine — what a change box says about a failed apply', () => {
|
|
209
|
+
const none = new Map();
|
|
210
|
+
|
|
211
|
+
it('a second viewer reads the persisted refusal', () => {
|
|
212
|
+
expect(refusalLine({ ...CR, lastApplyFailure: FAILURE }, none)).toBe(FAILURE.reason);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('a persisted conflict is still said in words (it never withdraws the button)', () => {
|
|
216
|
+
const conflict = { ...FAILURE, conflicts: true, reason: 'This draft conflicts with the target.' };
|
|
217
|
+
expect(refusalLine({ ...CR, lastApplyFailure: conflict }, none)).toBe(conflict.reason);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("this tab's own attempt speaks first, and its conflict speaks through the blocked state", () => {
|
|
221
|
+
const withStored = { ...CR, lastApplyFailure: FAILURE };
|
|
222
|
+
expect(refusalLine(withStored, new Map([[7, { reason: 'mine', conflicts: false, at: '2026-09-16T10:30:00.000Z' }]]))).toBe('mine');
|
|
223
|
+
expect(refusalLine(withStored, new Map([[7, { reason: 'mine', conflicts: true, at: '2026-09-16T10:30:00.000Z' }]]))).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("a later refusal from somebody else's attempt replaces this tab's older one", () => {
|
|
227
|
+
const later = { ...FAILURE, reason: 'theirs', at: '2026-09-16T11:00:00.000Z' };
|
|
228
|
+
const mine = { reason: 'mine', conflicts: true, at: '2026-09-16T10:30:00.000Z' };
|
|
229
|
+
expect(refusalLine({ ...CR, lastApplyFailure: later }, new Map([[7, mine]]))).toBe('theirs');
|
|
230
|
+
// The echo of this tab's own refusal carries the same instant: its own still speaks.
|
|
231
|
+
const echo = { ...FAILURE, reason: 'mine', conflicts: true, at: mine.at };
|
|
232
|
+
expect(refusalLine({ ...CR, lastApplyFailure: echo }, new Map([[7, mine]]))).toBeNull();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('nothing to say without a refusal', () => {
|
|
236
|
+
expect(refusalLine(CR, none)).toBeNull();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("the clicker's backstop for a lost outcome event", () => {
|
|
241
|
+
const POLL_MS = 4_000;
|
|
242
|
+
let restore: () => void = () => {};
|
|
243
|
+
afterEach(() => restore());
|
|
244
|
+
|
|
245
|
+
it('an apply whose merged event never arrives still completes from the state poll', async () => {
|
|
246
|
+
// Hold the poll interval so the test can fire it; everything else runs for real.
|
|
247
|
+
const realSet = globalThis.setInterval;
|
|
248
|
+
const polls: Array<() => void> = [];
|
|
249
|
+
const spy = vi.spyOn(globalThis, 'setInterval').mockImplementation(((
|
|
250
|
+
fn: () => void,
|
|
251
|
+
ms?: number,
|
|
252
|
+
...rest: unknown[]
|
|
253
|
+
) => {
|
|
254
|
+
if (ms !== POLL_MS) return realSet(fn, ms, ...rest);
|
|
255
|
+
polls.push(fn);
|
|
256
|
+
return 424242;
|
|
257
|
+
}) as unknown as typeof setInterval);
|
|
258
|
+
restore = () => spy.mockRestore();
|
|
259
|
+
|
|
260
|
+
const bus = fakeBus();
|
|
261
|
+
const onApplied = vi.fn();
|
|
262
|
+
const onFailed = vi.fn();
|
|
263
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
264
|
+
mergeMock.mergePullRequest.mockResolvedValue({ status: 'merging', number: 7 });
|
|
265
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
266
|
+
<EventBusContext.Provider value={bus.value}>{children}</EventBusContext.Provider>
|
|
267
|
+
);
|
|
268
|
+
const { result } = renderHook(() => useApplyChangeRequest({ onApplied, onFailed }), { wrapper });
|
|
269
|
+
|
|
270
|
+
act(() => result.current.apply(CR));
|
|
271
|
+
await waitFor(() => expect(polls).toHaveLength(1));
|
|
272
|
+
expect(result.current.activeCr).toBe(7);
|
|
273
|
+
|
|
274
|
+
// The merge landed; its event was lost. Still open on the first poll…
|
|
275
|
+
act(() => polls[0]!());
|
|
276
|
+
await waitFor(() => expect(detailMock.fetchPrDetail).toHaveBeenCalledTimes(2));
|
|
277
|
+
expect(onApplied).not.toHaveBeenCalled();
|
|
278
|
+
|
|
279
|
+
// …merged on the next.
|
|
280
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail({ state: 'merged' }));
|
|
281
|
+
act(() => polls[0]!());
|
|
282
|
+
await waitFor(() => expect(onApplied).toHaveBeenCalledTimes(1));
|
|
283
|
+
expect(onFailed).not.toHaveBeenCalled();
|
|
284
|
+
expect(result.current.activeCr).toBeNull();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Proposing again while the first proposal is still loading.
|
|
5
|
+
*
|
|
6
|
+
* REPRODUCED against a running instance (ticket log, 2026-09-18): a business
|
|
7
|
+
* user dropped two files back to back and the second proposal died on
|
|
8
|
+
* `POST /api/workflow/change-requests` 409 — "An open change request already
|
|
9
|
+
* exists from …" — shown to them as "Couldn't add change request". Both
|
|
10
|
+
* flows had read `existingCr: null` from the fresh list, and both went on to
|
|
11
|
+
* open the request. The window is exactly how long that list read takes, and
|
|
12
|
+
* that grows with the number of open requests, which is why "propose more
|
|
13
|
+
* while one loads" hit it reliably.
|
|
14
|
+
*
|
|
15
|
+
* Note what did NOT happen and is therefore not defended here: the
|
|
16
|
+
* branch-reset path (delete + recreate) never fired, and all four files
|
|
17
|
+
* survived in the one request. The damage was the 409 alone.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const gitApi = vi.hoisted(() => ({ createBranch: vi.fn(), deleteBranch: vi.fn() }));
|
|
21
|
+
// The REAL module, with only the two verbs replaced: `propose.api` narrows the
|
|
22
|
+
// refusal with `err instanceof GitApiError`, so the class has to be the real one.
|
|
23
|
+
vi.mock('../../git/services/git.api', async (importOriginal) => ({
|
|
24
|
+
...(await importOriginal<typeof import('../../git/services/git.api')>()),
|
|
25
|
+
createBranch: gitApi.createBranch,
|
|
26
|
+
deleteBranch: gitApi.deleteBranch,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const wsApi = vi.hoisted(() => ({
|
|
30
|
+
getOrCreateWorkspace: vi.fn(async () => ({
|
|
31
|
+
workspace: { id: 'sugg-ws', kbDirName: 'knowledge-base' },
|
|
32
|
+
})),
|
|
33
|
+
writeFile: vi.fn(async () => {}),
|
|
34
|
+
}));
|
|
35
|
+
vi.mock('../../workspace/services/workspace.api', () => wsApi);
|
|
36
|
+
|
|
37
|
+
const openApi = vi.hoisted(() => ({ openChangeRequest: vi.fn() }));
|
|
38
|
+
vi.mock('../../pr/services/pr-open.api', () => openApi);
|
|
39
|
+
|
|
40
|
+
const detailApi = vi.hoisted(() => ({ fetchPrDetail: vi.fn() }));
|
|
41
|
+
vi.mock('../../pr/services/pr-detail.api', () => detailApi);
|
|
42
|
+
|
|
43
|
+
const listMine = vi.hoisted(() => vi.fn(async (): Promise<unknown[]> => []));
|
|
44
|
+
vi.mock('../services/change-requests.api', () => ({ listMyChangeRequests: listMine }));
|
|
45
|
+
|
|
46
|
+
import { GitApiError } from '../../git/services/git.api';
|
|
47
|
+
import {
|
|
48
|
+
ensureKnowledgeChangeRequest,
|
|
49
|
+
ensureKnowledgeSuggestionWorkspace,
|
|
50
|
+
proposeKnowledgeChange,
|
|
51
|
+
type KnowledgeSuggestionTarget,
|
|
52
|
+
} from '../services/propose.api';
|
|
53
|
+
|
|
54
|
+
const BRANCH = 'suggestions/biz2-05a2cfde/knowledge';
|
|
55
|
+
const rae = { email: 'biz2@bevel.software', id: '05a2cfde-1111-2222-3333' };
|
|
56
|
+
|
|
57
|
+
/** What both racing flows hold: no request of their own yet. */
|
|
58
|
+
const target = (): KnowledgeSuggestionTarget => ({
|
|
59
|
+
branch: BRANCH,
|
|
60
|
+
workspaceId: 'sugg-ws',
|
|
61
|
+
kbDirName: 'knowledge-base',
|
|
62
|
+
existingCr: null,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** The server's refusal, body and all — see `DuplicateChangeRequestError`. */
|
|
66
|
+
const duplicate409 = (existingNumber: number) =>
|
|
67
|
+
new GitApiError(
|
|
68
|
+
409,
|
|
69
|
+
`An open change request already exists from "${BRANCH}" to "main" (#${existingNumber}).`,
|
|
70
|
+
{
|
|
71
|
+
kind: 'duplicate-change-request',
|
|
72
|
+
sourceBranch: BRANCH,
|
|
73
|
+
targetBranch: 'main',
|
|
74
|
+
existingNumber,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
gitApi.createBranch.mockReset().mockResolvedValue(undefined);
|
|
80
|
+
gitApi.deleteBranch.mockReset().mockResolvedValue(undefined);
|
|
81
|
+
openApi.openChangeRequest.mockReset();
|
|
82
|
+
wsApi.writeFile.mockClear();
|
|
83
|
+
wsApi.getOrCreateWorkspace.mockClear();
|
|
84
|
+
detailApi.fetchPrDetail.mockReset();
|
|
85
|
+
listMine.mockReset().mockResolvedValue([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('a second proposal started while the first is still loading', () => {
|
|
89
|
+
it('opens ONE request for two concurrent proposals, and both get it', async () => {
|
|
90
|
+
let release: (v: unknown) => void = () => {};
|
|
91
|
+
openApi.openChangeRequest.mockReturnValue(
|
|
92
|
+
new Promise((resolve) => {
|
|
93
|
+
release = resolve;
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const first = ensureKnowledgeChangeRequest(target(), 'Biz Two');
|
|
98
|
+
const second = ensureKnowledgeChangeRequest(target(), 'Biz Two');
|
|
99
|
+
release({ number: 2, branch: BRANCH, state: 'open', touchedNodePaths: [] });
|
|
100
|
+
|
|
101
|
+
const [a, b] = await Promise.all([first, second]);
|
|
102
|
+
expect(openApi.openChangeRequest).toHaveBeenCalledTimes(1);
|
|
103
|
+
expect(a?.number).toBe(2);
|
|
104
|
+
expect(b).toBe(a);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('adopts the request the server names instead of failing the proposal', async () => {
|
|
108
|
+
// Sequential, not concurrent: the first flow finished and opened #2 while
|
|
109
|
+
// the second was still uploading. No client-side coordination can see
|
|
110
|
+
// that — nor can another tab — so the refusal itself has to be read.
|
|
111
|
+
openApi.openChangeRequest.mockRejectedValue(duplicate409(2));
|
|
112
|
+
detailApi.fetchPrDetail.mockResolvedValue({
|
|
113
|
+
number: 2,
|
|
114
|
+
branch: BRANCH,
|
|
115
|
+
state: 'open',
|
|
116
|
+
touchedNodePaths: ['Shared/one.pdf'],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const adopted = await ensureKnowledgeChangeRequest(target(), 'Biz Two');
|
|
120
|
+
|
|
121
|
+
expect(adopted?.number).toBe(2);
|
|
122
|
+
expect(adopted?.touchedNodePaths).toEqual(['Shared/one.pdf']);
|
|
123
|
+
// Fresh: the request was opened seconds ago, and a cached list answer is
|
|
124
|
+
// exactly the one that would not have it.
|
|
125
|
+
expect(detailApi.fetchPrDetail).toHaveBeenCalledWith(2, { fresh: true });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('still announces nothing rather than failing when the adopted request cannot be read', async () => {
|
|
129
|
+
openApi.openChangeRequest.mockRejectedValue(duplicate409(7));
|
|
130
|
+
detailApi.fetchPrDetail.mockRejectedValue(new Error('offline'));
|
|
131
|
+
// The bytes are committed and the request is open either way; the only
|
|
132
|
+
// loss is the optimistic rows, which the next list load brings anyway.
|
|
133
|
+
await expect(ensureKnowledgeChangeRequest(target(), 'Biz Two')).resolves.toBeNull();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('leaves every other refusal a failure', async () => {
|
|
137
|
+
openApi.openChangeRequest.mockRejectedValue(new GitApiError(403, 'You may not write here'));
|
|
138
|
+
await expect(ensureKnowledgeChangeRequest(target(), 'Biz Two')).rejects.toThrow(
|
|
139
|
+
'You may not write here',
|
|
140
|
+
);
|
|
141
|
+
expect(detailApi.fetchPrDetail).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does not adopt a 409 that is about something else', async () => {
|
|
145
|
+
openApi.openChangeRequest.mockRejectedValue(
|
|
146
|
+
new GitApiError(409, 'Conflicts merging', { kind: 'change-request-conflicts' }),
|
|
147
|
+
);
|
|
148
|
+
await expect(ensureKnowledgeChangeRequest(target(), 'Biz Two')).rejects.toThrow(
|
|
149
|
+
'Conflicts merging',
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('asks the slow list ONCE for two proposals started together', async () => {
|
|
154
|
+
let release: (v: unknown[]) => void = () => {};
|
|
155
|
+
listMine.mockReturnValue(
|
|
156
|
+
new Promise((resolve) => {
|
|
157
|
+
release = resolve;
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const first = ensureKnowledgeSuggestionWorkspace(rae);
|
|
162
|
+
const second = ensureKnowledgeSuggestionWorkspace(rae);
|
|
163
|
+
release([]);
|
|
164
|
+
|
|
165
|
+
const [a, b] = await Promise.all([first, second]);
|
|
166
|
+
expect(listMine).toHaveBeenCalledTimes(1);
|
|
167
|
+
expect(gitApi.createBranch).toHaveBeenCalledTimes(1);
|
|
168
|
+
expect(a).toBe(b);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('runs the WHOLE flow twice over, and still opens one request', async () => {
|
|
172
|
+
// The two in-flight maps above are tested one at a time; the flow the
|
|
173
|
+
// ticket describes crosses both. `ensureKnowledgeSuggestionWorkspace`
|
|
174
|
+
// keys on the branch it derives from the user,
|
|
175
|
+
// `ensureKnowledgeChangeRequest` on the branch it is handed back — a
|
|
176
|
+
// mismatch between the two un-dedups the open and brings the 409 back
|
|
177
|
+
// while every isolated test above still passes.
|
|
178
|
+
let releaseList: (v: unknown[]) => void = () => {};
|
|
179
|
+
listMine.mockReturnValue(
|
|
180
|
+
new Promise((resolve) => {
|
|
181
|
+
releaseList = resolve;
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
openApi.openChangeRequest.mockResolvedValue({
|
|
185
|
+
number: 3,
|
|
186
|
+
branch: BRANCH,
|
|
187
|
+
state: 'open',
|
|
188
|
+
touchedNodePaths: [],
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const proposal = (file: string) =>
|
|
192
|
+
proposeKnowledgeChange({
|
|
193
|
+
repoRelativePath: file,
|
|
194
|
+
content: '# hi',
|
|
195
|
+
userEmail: rae.email,
|
|
196
|
+
userId: rae.id,
|
|
197
|
+
userName: 'Biz Two',
|
|
198
|
+
});
|
|
199
|
+
// Both fired before the slow list read has answered either — the exact
|
|
200
|
+
// "proposing again while one loads" window.
|
|
201
|
+
const both = Promise.all([proposal('Shared/one.md'), proposal('Shared/two.md')]);
|
|
202
|
+
releaseList([]);
|
|
203
|
+
const [a, b] = await both;
|
|
204
|
+
|
|
205
|
+
expect(listMine).toHaveBeenCalledTimes(1);
|
|
206
|
+
expect(gitApi.createBranch).toHaveBeenCalledTimes(1);
|
|
207
|
+
expect(openApi.openChangeRequest).toHaveBeenCalledTimes(1);
|
|
208
|
+
// Both files were written, which is the point of not serialising them.
|
|
209
|
+
expect(wsApi.writeFile).toHaveBeenCalledTimes(2);
|
|
210
|
+
expect(a.branch).toBe(BRANCH);
|
|
211
|
+
expect(b.branch).toBe(BRANCH);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('gives a joined proposal its own attempt when the one it joined fails', async () => {
|
|
215
|
+
// The first flow's failure is not the second's answer. The case that
|
|
216
|
+
// matters: the connection dropped AFTER the server created the row, so
|
|
217
|
+
// the second flow's own open meets the duplicate refusal and adopts the
|
|
218
|
+
// request — where joining would have reported "Couldn't add change
|
|
219
|
+
// request" about a request that exists.
|
|
220
|
+
let reject: (e: unknown) => void = () => {};
|
|
221
|
+
openApi.openChangeRequest
|
|
222
|
+
.mockReturnValueOnce(
|
|
223
|
+
new Promise((_resolve, rej) => {
|
|
224
|
+
reject = rej;
|
|
225
|
+
}),
|
|
226
|
+
)
|
|
227
|
+
.mockRejectedValueOnce(duplicate409(9));
|
|
228
|
+
detailApi.fetchPrDetail.mockResolvedValue({
|
|
229
|
+
number: 9,
|
|
230
|
+
branch: BRANCH,
|
|
231
|
+
state: 'open',
|
|
232
|
+
touchedNodePaths: ['Shared/two.pdf'],
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const first = ensureKnowledgeChangeRequest(target(), 'Biz Two');
|
|
236
|
+
const second = ensureKnowledgeChangeRequest(target(), 'Biz Two');
|
|
237
|
+
reject(new Error('network error'));
|
|
238
|
+
|
|
239
|
+
await expect(first).rejects.toThrow('network error');
|
|
240
|
+
const adopted = await second;
|
|
241
|
+
expect(adopted?.number).toBe(9);
|
|
242
|
+
expect(openApi.openChangeRequest).toHaveBeenCalledTimes(2);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('gives a joined workspace-ensure its own attempt when the one it joined fails', async () => {
|
|
246
|
+
let reject: (e: unknown) => void = () => {};
|
|
247
|
+
listMine
|
|
248
|
+
.mockReturnValueOnce(
|
|
249
|
+
new Promise((_resolve, rej) => {
|
|
250
|
+
reject = rej;
|
|
251
|
+
}),
|
|
252
|
+
)
|
|
253
|
+
.mockResolvedValue([{ number: 5, state: 'open', branch: BRANCH }]);
|
|
254
|
+
|
|
255
|
+
const first = ensureKnowledgeSuggestionWorkspace(rae);
|
|
256
|
+
const second = ensureKnowledgeSuggestionWorkspace(rae);
|
|
257
|
+
reject(new Error('offline'));
|
|
258
|
+
|
|
259
|
+
await expect(first).rejects.toThrow('offline');
|
|
260
|
+
expect((await second).existingCr).toMatchObject({ number: 5 });
|
|
261
|
+
expect(listMine).toHaveBeenCalledTimes(2);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('re-reads the list for a proposal made after the last one settled', async () => {
|
|
265
|
+
// In-flight only, never a cache: a request withdrawn between two
|
|
266
|
+
// proposals must not be remembered as still open.
|
|
267
|
+
await ensureKnowledgeSuggestionWorkspace(rae);
|
|
268
|
+
listMine.mockResolvedValue([{ number: 5, state: 'open', branch: BRANCH }]);
|
|
269
|
+
const later = await ensureKnowledgeSuggestionWorkspace(rae);
|
|
270
|
+
expect(listMine).toHaveBeenCalledTimes(2);
|
|
271
|
+
expect(later.existingCr).toMatchObject({ number: 5 });
|
|
272
|
+
});
|
|
273
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
deniedSentence,
|
|
4
|
+
failureReason,
|
|
5
|
+
isDenial,
|
|
6
|
+
nearestRuleFolder,
|
|
7
|
+
readErrorLead,
|
|
8
|
+
} from '../utils/readFailure';
|
|
9
|
+
import { WorkspaceApiError } from '../../workspace/services/workspace.api';
|
|
10
|
+
import { GitApiError } from '../../git/services/git.api';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The two sentences a failed read can produce, and the facts they are built
|
|
14
|
+
* from. Kept as a unit test beside the dialog's own: the wording is the
|
|
15
|
+
* ticket, and it should be pinned somewhere a render failure cannot hide it.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
describe('classifying a failed read', () => {
|
|
19
|
+
it('reads 403 as a denial, whichever API client threw it', () => {
|
|
20
|
+
expect(isDenial(new WorkspaceApiError(403))).toBe(true);
|
|
21
|
+
expect(isDenial(new GitApiError(403, 'nope'))).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('reads everything else as an error — including a read that never landed', () => {
|
|
25
|
+
expect(isDenial(new WorkspaceApiError(404))).toBe(false);
|
|
26
|
+
expect(isDenial(new WorkspaceApiError(500))).toBe(false);
|
|
27
|
+
expect(isDenial(new TypeError('Failed to fetch'))).toBe(false);
|
|
28
|
+
expect(isDenial(undefined)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("uses the server's own words as the reason, and says so when there are none", () => {
|
|
32
|
+
expect(failureReason(new GitApiError(500, 'the workspace clone is missing'))).toBe(
|
|
33
|
+
'the workspace clone is missing',
|
|
34
|
+
);
|
|
35
|
+
expect(failureReason(new WorkspaceApiError(500))).toBe('HTTP 500');
|
|
36
|
+
expect(failureReason({})).toBe('the request never completed');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('naming the folder to ask about', () => {
|
|
41
|
+
const ancestor = (path: string) => ({ kind: 'ancestor' as const, path });
|
|
42
|
+
|
|
43
|
+
it('takes the NEAREST ancestor rule — resolution is closeness-first', () => {
|
|
44
|
+
expect(
|
|
45
|
+
nearestRuleFolder({
|
|
46
|
+
'u:ali@example.com': { read: [ancestor('Knowledge/access.md')] },
|
|
47
|
+
'r:admin': { owner: [ancestor('Knowledge/Finance/Payroll/access.md')] },
|
|
48
|
+
}),
|
|
49
|
+
).toBe('Knowledge/Finance/Payroll');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('calls a rule at the repository root the whole workspace, not an empty name', () => {
|
|
53
|
+
expect(deniedSentence(nearestRuleFolder({ 'r:admin': { read: [ancestor('access.md')] } }))).toBe(
|
|
54
|
+
"You don't have access to read this file, so its content can't be shown here. " +
|
|
55
|
+
'Ask an owner of the whole workspace for read access if you need to review it.',
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The rule that produced the 403 is as often a `deny` as a missing grant,
|
|
61
|
+
* and a deny is usually written NEARER the file than the grant it cuts
|
|
62
|
+
* down. Reading grants only sent the reader to ask an owner of the folder
|
|
63
|
+
* that let them in — or, where the deny was the only ancestor rule at all,
|
|
64
|
+
* to "this file" — never to the folder actually holding them out.
|
|
65
|
+
*/
|
|
66
|
+
it('reads the deny scopes too, and prefers whichever rule sits nearest', () => {
|
|
67
|
+
expect(
|
|
68
|
+
nearestRuleFolder(
|
|
69
|
+
{ 'r:developer': { read: [ancestor('Knowledge/access.md')] } },
|
|
70
|
+
{ 'u:ali@example.com': { read: [ancestor('Knowledge/Finance/Payroll/access.md')] } },
|
|
71
|
+
),
|
|
72
|
+
).toBe('Knowledge/Finance/Payroll');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('names a deny-only ancestor rather than falling back to the file', () => {
|
|
76
|
+
expect(
|
|
77
|
+
nearestRuleFolder(
|
|
78
|
+
{},
|
|
79
|
+
{ 'u:ali@example.com': { read: [ancestor('Knowledge/Finance/access.md')] } },
|
|
80
|
+
),
|
|
81
|
+
).toBe('Knowledge/Finance');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('keeps the nearest GRANT when the deny is written farther out', () => {
|
|
85
|
+
expect(
|
|
86
|
+
nearestRuleFolder(
|
|
87
|
+
{ 'r:developer': { read: [ancestor('Knowledge/Finance/Payroll/access.md')] } },
|
|
88
|
+
{ 'u:ali@example.com': { read: [ancestor('Knowledge/access.md')] } },
|
|
89
|
+
),
|
|
90
|
+
).toBe('Knowledge/Finance/Payroll');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('names nothing when the only rule is the file\'s own frontmatter', () => {
|
|
94
|
+
expect(nearestRuleFolder({ 'u:ali@example.com': { read: [{ kind: 'direct' }] } })).toBeNull();
|
|
95
|
+
expect(nearestRuleFolder({})).toBeNull();
|
|
96
|
+
expect(nearestRuleFolder(undefined)).toBeNull();
|
|
97
|
+
// An older server sends no denials at all; that is not a rule folder.
|
|
98
|
+
expect(nearestRuleFolder({}, undefined)).toBeNull();
|
|
99
|
+
expect(nearestRuleFolder({}, { 'u:ali@example.com': { read: [{ kind: 'direct' }] } })).toBeNull();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('the sentences themselves', () => {
|
|
104
|
+
it('says access, names the folder, and never says "honest"', () => {
|
|
105
|
+
const sentence = deniedSentence('Knowledge/Finance');
|
|
106
|
+
expect(sentence).toBe(
|
|
107
|
+
"You don't have access to read this file, so its content can't be shown here. " +
|
|
108
|
+
'Ask an owner of Knowledge/Finance for read access if you need to review it.',
|
|
109
|
+
);
|
|
110
|
+
expect(sentence).not.toMatch(/honest/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('falls back to "this file" when no folder can be named', () => {
|
|
114
|
+
expect(deniedSentence(null)).toContain('Ask an owner of this file for read access');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('carries the reason of a read that merely broke, and never says "honest"', () => {
|
|
118
|
+
const lead = readErrorLead('HTTP 500');
|
|
119
|
+
expect(lead).toBe("This file couldn't be read right now (HTTP 500).");
|
|
120
|
+
expect(lead).not.toMatch(/honest/);
|
|
121
|
+
});
|
|
122
|
+
});
|