@bevel-software/platform-core-frontend 0.26.0 → 0.28.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/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +78 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +101 -73
- package/src/modules/auth/services/account.api.ts +59 -3
- package/src/modules/auth/services/sso.ts +30 -10
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
- package/src/modules/onboarding/components/InviteButton.tsx +139 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +123 -0
- package/src/modules/onboarding/invite-emails.ts +313 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +330 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect, type FormEvent } from 'react';
|
|
2
2
|
import { useAuth } from '../state/auth.context';
|
|
3
|
+
import { ProductName } from '../../../core/ProductName';
|
|
4
|
+
import { useAppRegistry } from '../../../core/registry';
|
|
3
5
|
import {
|
|
4
6
|
startSsoLogin,
|
|
5
7
|
fetchLoginProviders,
|
|
@@ -23,26 +25,32 @@ const OAUTH_ERROR_MESSAGES: Record<string, string> = {
|
|
|
23
25
|
'Your sign-in provider has not verified your email address, so it cannot be used to sign in here.',
|
|
24
26
|
};
|
|
25
27
|
|
|
28
|
+
/** The message for an error an SSO callback left for this screen (stored by useAuthState), if any. */
|
|
29
|
+
function storedOAuthError(): string | null {
|
|
30
|
+
const code = sessionStorage.getItem(OAUTH_ERROR_KEY);
|
|
31
|
+
return code ? (OAUTH_ERROR_MESSAGES[code] ?? 'Sign-in failed.') : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
export function LoginScreen() {
|
|
27
35
|
const { login } = useAuth();
|
|
36
|
+
const { loginLinks } = useAppRegistry();
|
|
28
37
|
const [email, setEmail] = useState('');
|
|
29
38
|
const [password, setPassword] = useState('');
|
|
30
|
-
|
|
39
|
+
// An SSO callback's error is the screen's first message, read as the state
|
|
40
|
+
// is made so it shows on the first render. StrictMode runs this twice,
|
|
41
|
+
// which is why the stored error is cleared in the effect, not here.
|
|
42
|
+
const [error, setError] = useState<string | null>(storedOAuthError);
|
|
31
43
|
const [submitting, setSubmitting] = useState(false);
|
|
32
44
|
// Default to password-only until the probe resolves, matching fetchLoginProviders'
|
|
33
45
|
// failure fallback so we never flash a button the backend can't service.
|
|
34
46
|
const [passwordEnabled, setPasswordEnabled] = useState(true);
|
|
35
47
|
const [ssoProviders, setSsoProviders] = useState<SsoProvider[]>([]);
|
|
36
48
|
|
|
37
|
-
//
|
|
38
|
-
// and probe which login methods this deployment offers.
|
|
49
|
+
// Clear the SSO callback's error once shown, so it is not shown again on a
|
|
50
|
+
// later visit, and probe which login methods this deployment offers.
|
|
39
51
|
useEffect(() => {
|
|
40
52
|
let mounted = true;
|
|
41
|
-
|
|
42
|
-
if (oauthError) {
|
|
43
|
-
sessionStorage.removeItem(OAUTH_ERROR_KEY);
|
|
44
|
-
setError(OAUTH_ERROR_MESSAGES[oauthError] ?? 'Sign-in failed.');
|
|
45
|
-
}
|
|
53
|
+
sessionStorage.removeItem(OAUTH_ERROR_KEY);
|
|
46
54
|
// Capability probe: never set state after unmount.
|
|
47
55
|
fetchLoginProviders()
|
|
48
56
|
.then((providers) => {
|
|
@@ -69,79 +77,99 @@ export function LoginScreen() {
|
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
80
|
+
// The page scrolls rather than the root (which never does): on a screen too
|
|
81
|
+
// short for the card and its links, both stay reachable. The inner column is
|
|
82
|
+
// at least the page's height, so a card that fits is still centred.
|
|
72
83
|
return (
|
|
73
|
-
<div className="
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
<div className="h-full overflow-y-auto bg-white">
|
|
85
|
+
<div className="flex flex-col items-center justify-center gap-4 min-h-full p-4">
|
|
86
|
+
<form
|
|
87
|
+
onSubmit={handleSubmit}
|
|
88
|
+
className="bg-white p-8 rounded-xl border border-line w-full max-w-sm space-y-5"
|
|
89
|
+
>
|
|
90
|
+
<div className="text-center space-y-1">
|
|
91
|
+
<h1 className="text-2xl font-semibold text-ink">
|
|
92
|
+
<ProductName />
|
|
93
|
+
</h1>
|
|
94
|
+
<p className="text-sm text-ink-muted">Sign in to continue</p>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
{passwordEnabled && (
|
|
98
|
+
<>
|
|
99
|
+
<div className="space-y-3">
|
|
100
|
+
<label className="block space-y-1">
|
|
101
|
+
<span className="text-xs text-ink-muted">Email</span>
|
|
102
|
+
<input
|
|
103
|
+
type="email"
|
|
104
|
+
required
|
|
105
|
+
autoComplete="email"
|
|
106
|
+
value={email}
|
|
107
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
108
|
+
className="w-full rounded-md bg-sunken border border-line-strong px-3 py-2 text-sm text-ink focus:outline-none focus:border-accent"
|
|
109
|
+
/>
|
|
110
|
+
</label>
|
|
111
|
+
<label className="block space-y-1">
|
|
112
|
+
<span className="text-xs text-ink-muted">Password</span>
|
|
113
|
+
<input
|
|
114
|
+
type="password"
|
|
115
|
+
required
|
|
116
|
+
autoComplete="current-password"
|
|
117
|
+
value={password}
|
|
118
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
119
|
+
className="w-full rounded-md bg-sunken border border-line-strong px-3 py-2 text-sm text-ink focus:outline-none focus:border-accent"
|
|
120
|
+
/>
|
|
121
|
+
</label>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<button
|
|
125
|
+
type="submit"
|
|
126
|
+
disabled={submitting}
|
|
127
|
+
className="w-full rounded-md bg-accent text-white text-sm font-medium py-2 hover:bg-accent-hover disabled:opacity-60 disabled:cursor-not-allowed"
|
|
128
|
+
>
|
|
129
|
+
{submitting ? 'Signing in…' : 'Sign in'}
|
|
130
|
+
</button>
|
|
131
|
+
</>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
{error && (
|
|
135
|
+
<div className="text-sm text-red-600" role="alert">
|
|
136
|
+
{error}
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
82
139
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<input
|
|
89
|
-
type="email"
|
|
90
|
-
required
|
|
91
|
-
autoComplete="email"
|
|
92
|
-
value={email}
|
|
93
|
-
onChange={(e) => setEmail(e.target.value)}
|
|
94
|
-
className="w-full rounded-md bg-sunken border border-line-strong px-3 py-2 text-sm text-ink focus:outline-none focus:border-accent"
|
|
95
|
-
/>
|
|
96
|
-
</label>
|
|
97
|
-
<label className="block space-y-1">
|
|
98
|
-
<span className="text-xs text-ink-muted">Password</span>
|
|
99
|
-
<input
|
|
100
|
-
type="password"
|
|
101
|
-
required
|
|
102
|
-
autoComplete="current-password"
|
|
103
|
-
value={password}
|
|
104
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
105
|
-
className="w-full rounded-md bg-sunken border border-line-strong px-3 py-2 text-sm text-ink focus:outline-none focus:border-accent"
|
|
106
|
-
/>
|
|
107
|
-
</label>
|
|
140
|
+
{passwordEnabled && ssoProviders.length > 0 && (
|
|
141
|
+
<div className="flex items-center gap-3 text-xs text-ink-faint">
|
|
142
|
+
<span className="h-px flex-1 bg-line" />
|
|
143
|
+
or
|
|
144
|
+
<span className="h-px flex-1 bg-line" />
|
|
108
145
|
</div>
|
|
146
|
+
)}
|
|
109
147
|
|
|
148
|
+
{ssoProviders.map((provider) => (
|
|
110
149
|
<button
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
150
|
+
key={provider.key}
|
|
151
|
+
type="button"
|
|
152
|
+
onClick={() => startSsoLogin(provider)}
|
|
153
|
+
className="w-full rounded-md border border-line-strong bg-white text-ink text-sm font-medium py-2 hover:bg-hover"
|
|
114
154
|
>
|
|
115
|
-
{
|
|
155
|
+
{provider.label}
|
|
116
156
|
</button>
|
|
117
|
-
|
|
157
|
+
))}
|
|
158
|
+
</form>
|
|
159
|
+
{loginLinks && loginLinks.length > 0 && (
|
|
160
|
+
<nav aria-label="Legal">
|
|
161
|
+
<ul className="flex flex-wrap justify-center gap-x-4 gap-y-1 text-xs text-ink-muted">
|
|
162
|
+
{loginLinks.map((link) => (
|
|
163
|
+
<li key={link.href}>
|
|
164
|
+
<a href={link.href} className="hover:underline">
|
|
165
|
+
{link.label}
|
|
166
|
+
</a>
|
|
167
|
+
</li>
|
|
168
|
+
))}
|
|
169
|
+
</ul>
|
|
170
|
+
</nav>
|
|
118
171
|
)}
|
|
119
|
-
|
|
120
|
-
{error && (
|
|
121
|
-
<div className="text-sm text-red-600" role="alert">
|
|
122
|
-
{error}
|
|
123
|
-
</div>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
{passwordEnabled && ssoProviders.length > 0 && (
|
|
127
|
-
<div className="flex items-center gap-3 text-xs text-ink-faint">
|
|
128
|
-
<span className="h-px flex-1 bg-line" />
|
|
129
|
-
or
|
|
130
|
-
<span className="h-px flex-1 bg-line" />
|
|
131
|
-
</div>
|
|
132
|
-
)}
|
|
133
|
-
|
|
134
|
-
{ssoProviders.map((provider) => (
|
|
135
|
-
<button
|
|
136
|
-
key={provider.key}
|
|
137
|
-
type="button"
|
|
138
|
-
onClick={() => startSsoLogin(provider)}
|
|
139
|
-
className="w-full rounded-md border border-line-strong bg-white text-ink text-sm font-medium py-2 hover:bg-hover"
|
|
140
|
-
>
|
|
141
|
-
{provider.label}
|
|
142
|
-
</button>
|
|
143
|
-
))}
|
|
144
|
-
</form>
|
|
172
|
+
</div>
|
|
145
173
|
</div>
|
|
146
174
|
);
|
|
147
175
|
}
|
|
@@ -12,6 +12,10 @@ export interface AccountSummary {
|
|
|
12
12
|
* in with the environment password whether or not a hash is stored.
|
|
13
13
|
*/
|
|
14
14
|
isEnvAdmin: boolean;
|
|
15
|
+
/** One of the deployment's owners (`ADMIN_EMAIL`): never switched off, and its password is not set here. */
|
|
16
|
+
isOwner: boolean;
|
|
17
|
+
/** An owner who can sign back in with the server's password, so their account may be deleted; false otherwise. */
|
|
18
|
+
ownerCanBeDeleted: boolean;
|
|
15
19
|
/** When an admin switched the account off; null while it is on. */
|
|
16
20
|
deactivatedAt: string | null;
|
|
17
21
|
/** One of the accounts the platform runs its own work as: it is never switched off. */
|
|
@@ -19,6 +23,26 @@ export interface AccountSummary {
|
|
|
19
23
|
createdAt: string;
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A refused account request, with the HTTP status and the server's `kind`
|
|
28
|
+
* kept. Most callers only show the message; the invite dialog also needs to
|
|
29
|
+
* tell the deployment having no place for another account (a seat limit,
|
|
30
|
+
* say: 403 with `kind: 'admission'`) from any other refusal — a 403 from the
|
|
31
|
+
* admin check included — and the message alone is the host's own words, not
|
|
32
|
+
* a code.
|
|
33
|
+
*/
|
|
34
|
+
export class AccountRequestError extends Error {
|
|
35
|
+
status: number;
|
|
36
|
+
/** The server's machine-readable reason, when it gave one (`admission`). */
|
|
37
|
+
kind: string | null;
|
|
38
|
+
constructor(message: string, status: number, kind: string | null = null) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = 'AccountRequestError';
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.kind = kind;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
22
46
|
async function readError(res: Response, fallback: string): Promise<string> {
|
|
23
47
|
const body = await res.json().catch(() => ({}));
|
|
24
48
|
return (body as { error?: string }).error || fallback;
|
|
@@ -48,18 +72,50 @@ export async function listAccounts(): Promise<AccountSummary[]> {
|
|
|
48
72
|
* Create an account (or reset an existing account's password — deliberate
|
|
49
73
|
* upsert). Without a password the account is for single sign-on: the person
|
|
50
74
|
* finds it waiting the first time they sign in.
|
|
75
|
+
*
|
|
76
|
+
* With `keepExistingPassword` (an invite's starting password) the password
|
|
77
|
+
* goes only to a new account or a switched-on one that has none; the reply's
|
|
78
|
+
* `passwordSet` says whether it did, and `deactivated` whether it did not
|
|
79
|
+
* because the account is switched off.
|
|
80
|
+
*
|
|
81
|
+
* A refusal throws {@link AccountRequestError}; `kind: 'admission'` means
|
|
82
|
+
* the deployment's admission rules had no place for the account.
|
|
51
83
|
*/
|
|
52
84
|
export async function createAccount(
|
|
53
85
|
email: string,
|
|
54
86
|
name: string,
|
|
55
87
|
password?: string,
|
|
56
|
-
|
|
88
|
+
options: { keepExistingPassword?: boolean } = {},
|
|
89
|
+
): Promise<{ passwordSet?: boolean; deactivated?: boolean; notified?: string[] }> {
|
|
57
90
|
const res = await authFetch('/api/admin/accounts', {
|
|
58
91
|
method: 'POST',
|
|
59
92
|
headers: { 'Content-Type': 'application/json' },
|
|
60
|
-
body: JSON.stringify({
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
email,
|
|
95
|
+
name: name || undefined,
|
|
96
|
+
password: password || undefined,
|
|
97
|
+
keepExistingPassword: options.keepExistingPassword || undefined,
|
|
98
|
+
}),
|
|
61
99
|
});
|
|
62
|
-
if (!res.ok)
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
const body = (await res.json().catch(() => ({}))) as { error?: unknown; kind?: unknown };
|
|
102
|
+
const message = typeof body.error === 'string' && body.error ? body.error : 'Could not create account';
|
|
103
|
+
throw new AccountRequestError(message, res.status, typeof body.kind === 'string' ? body.kind : null);
|
|
104
|
+
}
|
|
105
|
+
const body = (await res.json().catch(() => ({}))) as {
|
|
106
|
+
passwordSet?: unknown;
|
|
107
|
+
deactivated?: unknown;
|
|
108
|
+
notified?: unknown;
|
|
109
|
+
};
|
|
110
|
+
// `notified`: how the deployment told a NEW account's person of the invite
|
|
111
|
+
// (`'email'`, say), as its listeners answered; empty or absent when nobody
|
|
112
|
+
// did and the admin hands over the link themselves.
|
|
113
|
+
const notified = Array.isArray(body.notified) ? body.notified.filter((c): c is string => typeof c === 'string') : [];
|
|
114
|
+
return {
|
|
115
|
+
...(typeof body.passwordSet === 'boolean' ? { passwordSet: body.passwordSet } : {}),
|
|
116
|
+
...(body.deactivated === true ? { deactivated: true } : {}),
|
|
117
|
+
...(notified.length > 0 ? { notified } : {}),
|
|
118
|
+
};
|
|
63
119
|
}
|
|
64
120
|
|
|
65
121
|
/**
|
|
@@ -44,8 +44,7 @@ export const POST_LOGIN_REDIRECT_KEY = 'bevel_post_login_redirect';
|
|
|
44
44
|
* trying to open — password login keeps it (no navigation happens), but SSO
|
|
45
45
|
* comes back to a fixed `/auth/<key>/callback` and the deep link someone
|
|
46
46
|
* clicked in Slack would die in the round-trip. Stash it here; the far side
|
|
47
|
-
* (`RootLanding`) puts them back
|
|
48
|
-
* the one sign-in that shows it.
|
|
47
|
+
* (`RootLanding`) puts them back.
|
|
49
48
|
*/
|
|
50
49
|
export function startSsoLogin(provider: SsoProvider): void {
|
|
51
50
|
const { pathname, search, hash } = window.location;
|
|
@@ -83,22 +82,43 @@ export function takePostLoginRedirect(): string | null {
|
|
|
83
82
|
/**
|
|
84
83
|
* Probe which login methods are enabled. On failure default to password-only
|
|
85
84
|
* so a transient error never hides the only working method (and never
|
|
86
|
-
* surfaces an SSO button the backend can't service).
|
|
85
|
+
* surfaces an SSO button the backend can't service). This is the strict probe
|
|
86
|
+
* below with that fallback, not a second reading of the answer.
|
|
87
87
|
*/
|
|
88
88
|
export async function fetchLoginProviders(): Promise<LoginProviders> {
|
|
89
89
|
try {
|
|
90
|
-
|
|
91
|
-
if (!res.ok) return { password: true, sso: [] };
|
|
92
|
-
const body = (await res.json()) as Partial<LoginProviders>;
|
|
93
|
-
return {
|
|
94
|
-
password: body.password !== false,
|
|
95
|
-
sso: Array.isArray(body.sso) ? body.sso : [],
|
|
96
|
-
};
|
|
90
|
+
return await fetchLoginProvidersStrict();
|
|
97
91
|
} catch {
|
|
98
92
|
return { password: true, sso: [] };
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
|
|
96
|
+
/**
|
|
97
|
+
* The one reading of `GET /api/auth/providers`: rejects on a failed request,
|
|
98
|
+
* a non-OK answer or a body that does not carry both answers, instead of
|
|
99
|
+
* guessing. The login screen wants the password-only fallback (see
|
|
100
|
+
* `fetchLoginProviders`); the Invite dialog and Manage access must tell "no
|
|
101
|
+
* single sign-on" from "couldn't check", because they say different things to
|
|
102
|
+
* the admin.
|
|
103
|
+
*/
|
|
104
|
+
export async function fetchLoginProvidersStrict(): Promise<LoginProviders> {
|
|
105
|
+
const res = await fetch('/api/auth/providers');
|
|
106
|
+
if (!res.ok) throw new Error(`Couldn't read the sign-in methods (${res.status})`);
|
|
107
|
+
const body = (await res.json()) as { password?: unknown; sso?: unknown } | null;
|
|
108
|
+
const sso = body?.sso;
|
|
109
|
+
if (
|
|
110
|
+
typeof body?.password !== 'boolean' ||
|
|
111
|
+
!Array.isArray(sso) ||
|
|
112
|
+
!sso.every(
|
|
113
|
+
(p: Partial<SsoProvider> | null) =>
|
|
114
|
+
typeof p?.key === 'string' && typeof p.label === 'string' && typeof p.startPath === 'string',
|
|
115
|
+
)
|
|
116
|
+
) {
|
|
117
|
+
throw new Error("Couldn't read the sign-in methods");
|
|
118
|
+
}
|
|
119
|
+
return { password: body.password, sso: sso as SsoProvider[] };
|
|
120
|
+
}
|
|
121
|
+
|
|
102
122
|
/**
|
|
103
123
|
* If the current page is any provider's OAuth callback, extract the
|
|
104
124
|
* token/error from the fragment and scrub the URL (so the token never lingers
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { fetchLoginProvidersStrict, type LoginProviders } from '../services/sso';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How this deployment signs people in, as far as the caller knows:
|
|
6
|
+
* `loading` until the first answer, `failed` when the check could not be
|
|
7
|
+
* made (never guessed — see `fetchLoginProvidersStrict`), `ready` with the
|
|
8
|
+
* methods. `retry` asks again.
|
|
9
|
+
*/
|
|
10
|
+
export type SignInMethodsState =
|
|
11
|
+
| { status: 'loading'; retry(): void }
|
|
12
|
+
| { status: 'failed'; retry(): void }
|
|
13
|
+
| { status: 'ready'; methods: LoginProviders; retry(): void };
|
|
14
|
+
|
|
15
|
+
export function useSignInMethods(): SignInMethodsState {
|
|
16
|
+
const [state, setState] = useState<
|
|
17
|
+
{ status: 'loading' } | { status: 'failed' } | { status: 'ready'; methods: LoginProviders }
|
|
18
|
+
>({ status: 'loading' });
|
|
19
|
+
const [attempt, setAttempt] = useState(0);
|
|
20
|
+
const retry = useCallback(() => {
|
|
21
|
+
setState({ status: 'loading' });
|
|
22
|
+
setAttempt((a) => a + 1);
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
let cancelled = false;
|
|
27
|
+
fetchLoginProvidersStrict().then(
|
|
28
|
+
(methods) => {
|
|
29
|
+
if (!cancelled) setState({ status: 'ready', methods });
|
|
30
|
+
},
|
|
31
|
+
() => {
|
|
32
|
+
if (!cancelled) setState({ status: 'failed' });
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
return () => {
|
|
36
|
+
cancelled = true;
|
|
37
|
+
};
|
|
38
|
+
}, [attempt]);
|
|
39
|
+
|
|
40
|
+
return { ...state, retry };
|
|
41
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { act, render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import type { FileApprovalState, PullRequestSummary } from '@bevel-software/platform-shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The request's verbs push its SOURCE branch, which is rarely the branch in
|
|
7
|
+
* the address bar. When the repository host refuses that push, the sync
|
|
8
|
+
* banner must show in the request view — so the view watches the source
|
|
9
|
+
* branch's workspace while it is open — and clear there when a later push
|
|
10
|
+
* of the branch lands.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const detailMock = vi.hoisted(() => ({ fetchPrDetail: vi.fn() }));
|
|
14
|
+
vi.mock('../../pr/services/pr-detail.api', () => ({ fetchPrDetail: detailMock.fetchPrDetail }));
|
|
15
|
+
vi.mock('../services/change-requests.api', () => ({
|
|
16
|
+
readFileOnBranch: vi.fn(async () => 'branch copy'),
|
|
17
|
+
}));
|
|
18
|
+
const approvalsApi = vi.hoisted(() => ({ approvePrFile: vi.fn(), revertPrFile: vi.fn(), unapprovePrFile: vi.fn() }));
|
|
19
|
+
vi.mock('../../pr/services/pr-approvals.api', () => ({
|
|
20
|
+
approvePrFile: approvalsApi.approvePrFile,
|
|
21
|
+
revertPrFile: approvalsApi.revertPrFile,
|
|
22
|
+
unapprovePrFile: approvalsApi.unapprovePrFile,
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('../../pr/services/pr-merge.api', () => ({
|
|
25
|
+
mergePullRequest: vi.fn(),
|
|
26
|
+
refreshChangeRequestFromTarget: vi.fn(),
|
|
27
|
+
}));
|
|
28
|
+
vi.mock('../../pr/services/pr-cancel.api', () => ({
|
|
29
|
+
cancelPullRequest: vi.fn(),
|
|
30
|
+
deleteChangeRequest: vi.fn(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
import { ChangeRequestDialog } from '../components/ChangeRequestDialog';
|
|
34
|
+
import { GitApiError } from '../../git/services/git.api';
|
|
35
|
+
import { EventBusContext, type EventBusContextValue } from '../../workflow/state/event-bus.context';
|
|
36
|
+
|
|
37
|
+
const BRANCH = 'ali.raza/customer-hypotheses';
|
|
38
|
+
const CR = {
|
|
39
|
+
number: 12,
|
|
40
|
+
title: 'Customer hypotheses',
|
|
41
|
+
authorId: 'abc',
|
|
42
|
+
author: { login: 'user-abc', name: 'Ali' },
|
|
43
|
+
appAuthor: { name: 'Ali' },
|
|
44
|
+
branch: BRANCH,
|
|
45
|
+
base: 'main',
|
|
46
|
+
state: 'open',
|
|
47
|
+
createdAt: '2026-10-07T00:00:00.000Z',
|
|
48
|
+
touchedNodePaths: [],
|
|
49
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
50
|
+
url: '/change-requests/12',
|
|
51
|
+
} as unknown as PullRequestSummary;
|
|
52
|
+
|
|
53
|
+
const APPROVAL: FileApprovalState = {
|
|
54
|
+
path: 'Docs/a.md',
|
|
55
|
+
eligibleApprovers: { roles: ['Admin'], users: [] },
|
|
56
|
+
approvedBy: [],
|
|
57
|
+
isApproved: false,
|
|
58
|
+
viewerCanApprove: true,
|
|
59
|
+
inMergeGate: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const DETAIL = {
|
|
63
|
+
...CR,
|
|
64
|
+
body: '',
|
|
65
|
+
headSha: 'h',
|
|
66
|
+
baseSha: 'b',
|
|
67
|
+
files: [{ path: 'Docs/a.md', status: 'modified', additions: 1, deletions: 0, isBinary: false, sha: '', rawUrl: '' }],
|
|
68
|
+
comments: [],
|
|
69
|
+
approvals: [APPROVAL],
|
|
70
|
+
mergeableInBevel: true,
|
|
71
|
+
mergeBlockedReasons: [],
|
|
72
|
+
mergeWarnings: [],
|
|
73
|
+
viewerCanBypassMerge: false,
|
|
74
|
+
viewerCanCancel: false,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const SENTENCE =
|
|
78
|
+
`Saved locally on "${BRANCH}" but couldn't share with the team automatically — ` +
|
|
79
|
+
'the repository host refused the push; the next save on this branch will try sharing it again.';
|
|
80
|
+
|
|
81
|
+
/** A stand-in for the SSE bus that records watches and lets a test push events. */
|
|
82
|
+
function makeBus() {
|
|
83
|
+
const handlers = new Map<string, Set<(e: unknown) => void>>();
|
|
84
|
+
const release = vi.fn();
|
|
85
|
+
const watchWorkspace = vi.fn(() => release);
|
|
86
|
+
const ctx = {
|
|
87
|
+
subscribe(kind: string, handler: (e: unknown) => void) {
|
|
88
|
+
const set = handlers.get(kind) ?? new Set<(e: unknown) => void>();
|
|
89
|
+
set.add(handler);
|
|
90
|
+
handlers.set(kind, set);
|
|
91
|
+
return () => set.delete(handler);
|
|
92
|
+
},
|
|
93
|
+
setFocus: vi.fn(),
|
|
94
|
+
watchWorkspace,
|
|
95
|
+
} as unknown as EventBusContextValue;
|
|
96
|
+
return {
|
|
97
|
+
ctx,
|
|
98
|
+
watchWorkspace,
|
|
99
|
+
release,
|
|
100
|
+
emit(event: Record<string, unknown> & { kind: string }) {
|
|
101
|
+
act(() => {
|
|
102
|
+
for (const h of handlers.get(event.kind) ?? []) h(event);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function renderDialog(bus: ReturnType<typeof makeBus>) {
|
|
109
|
+
return render(
|
|
110
|
+
<EventBusContext.Provider value={bus.ctx}>
|
|
111
|
+
<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />
|
|
112
|
+
</EventBusContext.Provider>,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const syncBanner = () =>
|
|
117
|
+
screen.queryAllByRole('alert').find((el) => el.textContent?.includes('reaching your git host')) ?? null;
|
|
118
|
+
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
detailMock.fetchPrDetail.mockReset();
|
|
121
|
+
approvalsApi.revertPrFile.mockReset();
|
|
122
|
+
detailMock.fetchPrDetail.mockResolvedValue(DETAIL);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('ChangeRequestDialog: the source branch’s sync banner', () => {
|
|
126
|
+
it('watches the source branch’s workspace while open, and lets go on close', () => {
|
|
127
|
+
const bus = makeBus();
|
|
128
|
+
const view = renderDialog(bus);
|
|
129
|
+
// Workspace ids are the URL-encoded branch name.
|
|
130
|
+
expect(bus.watchWorkspace).toHaveBeenCalledWith(encodeURIComponent(BRANCH));
|
|
131
|
+
view.unmount();
|
|
132
|
+
expect(bus.release).toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('a revert the host refused: the sentence, and the banner naming the branch — which clears when the push lands', async () => {
|
|
136
|
+
const bus = makeBus();
|
|
137
|
+
approvalsApi.revertPrFile.mockRejectedValue(
|
|
138
|
+
new GitApiError(409, SENTENCE, { kind: 'push-needs-resolution', branch: BRANCH }),
|
|
139
|
+
);
|
|
140
|
+
renderDialog(bus);
|
|
141
|
+
|
|
142
|
+
fireEvent.contextMenu(await screen.findByTitle('Docs/a.md'));
|
|
143
|
+
fireEvent.click(screen.getByRole('menuitem', { name: 'Revert file…' }));
|
|
144
|
+
fireEvent.click(screen.getByRole('menuitem', { name: 'Really revert this file?' }));
|
|
145
|
+
await waitFor(() => expect(approvalsApi.revertPrFile).toHaveBeenCalledWith(12, 'Docs/a.md'));
|
|
146
|
+
|
|
147
|
+
// The route's answer, verbatim — never "Internal server error".
|
|
148
|
+
expect(await screen.findByText(SENTENCE)).toBeInTheDocument();
|
|
149
|
+
expect(screen.queryByText(/internal (server )?error/i)).not.toBeInTheDocument();
|
|
150
|
+
|
|
151
|
+
// The backend's banner event arrives for the source branch (decoded id).
|
|
152
|
+
expect(syncBanner()).toBeNull();
|
|
153
|
+
bus.emit({
|
|
154
|
+
kind: 'git-sync-failed',
|
|
155
|
+
workspaceId: BRANCH,
|
|
156
|
+
branch: BRANCH,
|
|
157
|
+
reason: 'The repository host refused the request.',
|
|
158
|
+
});
|
|
159
|
+
const banner = syncBanner();
|
|
160
|
+
expect(banner).not.toBeNull();
|
|
161
|
+
expect(banner?.textContent).toContain(BRANCH);
|
|
162
|
+
expect(banner?.textContent).toContain('saved here');
|
|
163
|
+
|
|
164
|
+
// The host is back and the branch's next push lands.
|
|
165
|
+
bus.emit({ kind: 'git-sync-recovered', workspaceId: BRANCH, branch: BRANCH });
|
|
166
|
+
expect(syncBanner()).toBeNull();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('ignores another branch’s failure', async () => {
|
|
170
|
+
const bus = makeBus();
|
|
171
|
+
renderDialog(bus);
|
|
172
|
+
await screen.findByTitle('Docs/a.md');
|
|
173
|
+
bus.emit({ kind: 'git-sync-failed', workspaceId: 'bob/other', branch: 'bob/other', reason: 'x' });
|
|
174
|
+
expect(syncBanner()).toBeNull();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -54,6 +54,7 @@ vi.mock('../../access/api', async (importOriginal) => ({
|
|
|
54
54
|
|
|
55
55
|
import { ChangeRequestDialog } from '../components/ChangeRequestDialog';
|
|
56
56
|
import { WorkspaceApiError } from '../../workspace/services/workspace.api';
|
|
57
|
+
import { BranchUnavailableError } from '../utils/readFailure';
|
|
57
58
|
|
|
58
59
|
/** What `test-setup.ts` pins the default branch to. */
|
|
59
60
|
const MAIN = 'target-company-state';
|
|
@@ -136,6 +137,73 @@ beforeEach(() => {
|
|
|
136
137
|
detailMock.fetchPrDetail.mockResolvedValue(detail);
|
|
137
138
|
});
|
|
138
139
|
|
|
140
|
+
describe('ChangeRequestDialog: a file the request removes', () => {
|
|
141
|
+
/**
|
|
142
|
+
* The request's branch does not have the file — that is what removing it
|
|
143
|
+
* means — so reading it there answers 404. The pane used to take that 404
|
|
144
|
+
* for a broken read and say "couldn't be read right now (HTTP 404). Try
|
|
145
|
+
* again.", with nothing to show and a retry that could never succeed. The
|
|
146
|
+
* 404 is the proposal: the current copy, every line of it deleted.
|
|
147
|
+
*/
|
|
148
|
+
it('shows the current copy as deleted, not a failed read', async () => {
|
|
149
|
+
detailMock.fetchPrDetail.mockResolvedValue({
|
|
150
|
+
...detail,
|
|
151
|
+
files: [{ ...detail.files[0], status: 'removed' as const, additions: 0, deletions: 2 }],
|
|
152
|
+
});
|
|
153
|
+
reads({ [MAIN]: 'bands:\n - L3\n' });
|
|
154
|
+
|
|
155
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
156
|
+
|
|
157
|
+
await waitFor(() =>
|
|
158
|
+
expect([...document.querySelectorAll('del')].map((n) => n.textContent)).toEqual([
|
|
159
|
+
'bands:',
|
|
160
|
+
' - L3',
|
|
161
|
+
]),
|
|
162
|
+
);
|
|
163
|
+
expect(document.querySelectorAll('ins')).toHaveLength(0);
|
|
164
|
+
expect(screen.queryByText(/couldn't be read right now/)).not.toBeInTheDocument();
|
|
165
|
+
expect(screen.queryByRole('button', { name: 'Try again' })).not.toBeInTheDocument();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The branch itself answers 404 too, when it is gone — and that says
|
|
170
|
+
* nothing about the file. `readFileOnBranch` tells that apart; the pane must
|
|
171
|
+
* not read it as "the file is not on the branch, so this is the deletion".
|
|
172
|
+
*/
|
|
173
|
+
it("reports a removed file whose branch couldn't be opened as a failed read, not a deletion", async () => {
|
|
174
|
+
detailMock.fetchPrDetail.mockResolvedValue({
|
|
175
|
+
...detail,
|
|
176
|
+
files: [{ ...detail.files[0], status: 'removed' as const, additions: 0, deletions: 2 }],
|
|
177
|
+
});
|
|
178
|
+
reads({
|
|
179
|
+
[CR_BRANCH]: new BranchUnavailableError(CR_BRANCH, new WorkspaceApiError(404, 'There is no branch named ali.raza/payroll-bands.')),
|
|
180
|
+
[MAIN]: 'bands:\n - L3\n',
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
184
|
+
|
|
185
|
+
const note = await screen.findByText(/couldn't be read right now/);
|
|
186
|
+
expect(note).toHaveTextContent(
|
|
187
|
+
"This file couldn't be read right now (the branch ali.raza/payroll-bands couldn't be opened (There is no branch named ali.raza/payroll-bands.)). Try again.",
|
|
188
|
+
);
|
|
189
|
+
expect(document.querySelectorAll('del')).toHaveLength(0);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/** Only the 404 is the deletion; any other failure on a removed file is still a failure. */
|
|
193
|
+
it('still reports a read of a removed file that merely broke', async () => {
|
|
194
|
+
detailMock.fetchPrDetail.mockResolvedValue({
|
|
195
|
+
...detail,
|
|
196
|
+
files: [{ ...detail.files[0], status: 'removed' as const, additions: 0, deletions: 2 }],
|
|
197
|
+
});
|
|
198
|
+
reads({ [CR_BRANCH]: new WorkspaceApiError(500), [MAIN]: 'bands:\n - L3\n' });
|
|
199
|
+
|
|
200
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
201
|
+
|
|
202
|
+
const note = await screen.findByText(/couldn't be read right now/);
|
|
203
|
+
expect(note).toHaveTextContent("This file couldn't be read right now (HTTP 500). Try again.");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
139
207
|
describe("ChangeRequestDialog: a file the viewer may not read", () => {
|
|
140
208
|
it('says it is an access decision, and names the folder to ask an owner of', async () => {
|
|
141
209
|
reads({ [CR_BRANCH]: new WorkspaceApiError(403), [MAIN]: 'bands:\n - L3\n' });
|