@bevel-software/platform-core-frontend 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  5. package/src/core/__tests__/core-contributions.test.ts +16 -0
  6. package/src/core/core-contributions.ts +17 -0
  7. package/src/core/registry.ts +51 -1
  8. package/src/index.css +23 -5
  9. package/src/index.ts +5 -0
  10. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  11. package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
  12. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  13. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  14. package/src/modules/auth/components/LoginScreen.tsx +4 -1
  15. package/src/modules/auth/services/account.api.ts +28 -1
  16. package/src/modules/auth/services/sso.ts +1 -2
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  19. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  20. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  21. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  22. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  23. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  24. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  25. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  26. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  27. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  28. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  29. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  30. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  31. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  32. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  33. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  34. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  35. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  36. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  37. package/src/modules/embed/components/EmbedView.tsx +545 -0
  38. package/src/modules/embed/embed-config.ts +132 -0
  39. package/src/modules/embed/embed-host.ts +120 -0
  40. package/src/modules/embed/mount.tsx +80 -0
  41. package/src/modules/embed/services/embed-token.ts +22 -0
  42. package/src/modules/embed/services/embed.api.ts +158 -0
  43. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  44. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  45. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  46. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  47. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  48. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  49. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  50. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  51. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  52. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  53. package/src/modules/git/index.ts +15 -0
  54. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  55. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  56. package/src/modules/git/services/error-messages.ts +58 -1
  57. package/src/modules/git/services/pull-failure.ts +68 -0
  58. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  59. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  60. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  61. package/src/modules/layout/breakpoints.ts +8 -0
  62. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  63. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  64. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  65. package/src/modules/library/components/LibraryPage.tsx +22 -0
  66. package/src/modules/library/components/PluginExtras.tsx +23 -6
  67. package/src/modules/library/components/PluginPage.tsx +6 -1
  68. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  69. package/src/modules/library/services/plugins.api.ts +4 -1
  70. package/src/modules/library/state/plugins-revision.ts +28 -0
  71. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  72. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  73. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  74. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  75. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  76. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  77. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  78. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  79. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  80. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  81. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  82. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  83. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  84. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  85. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  86. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  87. package/src/modules/onboarding/invite-emails.ts +175 -0
  88. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  89. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  90. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  91. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  92. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  93. package/src/modules/onboarding/state/onboarding.ts +133 -59
  94. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  95. package/src/modules/settings/settings-nav-items.tsx +8 -3
  96. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  97. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  98. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  99. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  100. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  101. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  102. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  103. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  104. package/src/modules/setup/components/SetupGate.tsx +46 -1
  105. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  106. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  107. package/src/modules/setup/services/setup.api.ts +3 -3
  108. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  109. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  110. package/src/modules/toolbar/commands/actions.tsx +324 -0
  111. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  112. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  113. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  114. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  115. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  116. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  117. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  118. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  119. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  120. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  121. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  122. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  123. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  124. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  125. package/src/modules/toolbar/search/rank.ts +111 -0
  126. package/src/modules/toolbar/search/sources.ts +169 -0
  127. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  128. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  129. package/src/modules/workflow/services/lock.api.ts +17 -2
  130. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  131. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  132. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  133. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  134. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  135. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  136. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  137. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  138. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  139. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  140. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  141. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  142. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  143. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  144. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  145. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  146. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  147. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  148. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  149. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  150. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  151. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  152. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  153. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  154. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  155. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  156. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  157. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  158. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  159. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  160. package/src/modules/workspace/components/renderers/index.ts +26 -0
  161. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  162. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  163. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  164. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  165. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  166. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  167. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  168. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  169. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  170. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  171. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  172. package/src/modules/workspace/state/editable-page.ts +42 -0
  173. package/src/modules/workspace/state/workspace.context.ts +13 -4
  174. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  175. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  176. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  177. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  178. package/src/modules/workspace/utils/fileTree.ts +49 -14
  179. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  180. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  181. package/src/shared/components/ConfirmProvider.tsx +156 -0
  182. package/src/shared/components/Dialog.tsx +7 -0
  183. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  184. package/src/shared/components/confirm-context.ts +94 -0
  185. package/src/shared/components/index.ts +3 -0
  186. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  187. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -19,6 +19,26 @@ export interface AccountSummary {
19
19
  createdAt: string;
20
20
  }
21
21
 
22
+ /**
23
+ * A refused account request, with the HTTP status and the server's `kind`
24
+ * kept. Most callers only show the message; the invite dialog also needs to
25
+ * tell the deployment having no place for another account (a seat limit,
26
+ * say: 403 with `kind: 'admission'`) from any other refusal — a 403 from the
27
+ * admin check included — and the message alone is the host's own words, not
28
+ * a code.
29
+ */
30
+ export class AccountRequestError extends Error {
31
+ status: number;
32
+ /** The server's machine-readable reason, when it gave one (`admission`). */
33
+ kind: string | null;
34
+ constructor(message: string, status: number, kind: string | null = null) {
35
+ super(message);
36
+ this.name = 'AccountRequestError';
37
+ this.status = status;
38
+ this.kind = kind;
39
+ }
40
+ }
41
+
22
42
  async function readError(res: Response, fallback: string): Promise<string> {
23
43
  const body = await res.json().catch(() => ({}));
24
44
  return (body as { error?: string }).error || fallback;
@@ -48,6 +68,9 @@ export async function listAccounts(): Promise<AccountSummary[]> {
48
68
  * Create an account (or reset an existing account's password — deliberate
49
69
  * upsert). Without a password the account is for single sign-on: the person
50
70
  * finds it waiting the first time they sign in.
71
+ *
72
+ * A refusal throws {@link AccountRequestError}; `kind: 'admission'` means
73
+ * the deployment's admission rules had no place for the account.
51
74
  */
52
75
  export async function createAccount(
53
76
  email: string,
@@ -59,7 +82,11 @@ export async function createAccount(
59
82
  headers: { 'Content-Type': 'application/json' },
60
83
  body: JSON.stringify({ email, name: name || undefined, password: password || undefined }),
61
84
  });
62
- if (!res.ok) throw new Error(await readError(res, 'Could not create account'));
85
+ if (!res.ok) {
86
+ const body = (await res.json().catch(() => ({}))) as { error?: unknown; kind?: unknown };
87
+ const message = typeof body.error === 'string' && body.error ? body.error : 'Could not create account';
88
+ throw new AccountRequestError(message, res.status, typeof body.kind === 'string' ? body.kind : null);
89
+ }
63
90
  }
64
91
 
65
92
  /**
@@ -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 — after the first-visit welcome, if this is
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;
@@ -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' });
@@ -0,0 +1,182 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
5
+ import type { PullRequestSummary } from '@bevel-software/platform-shared';
6
+ import { GitApiError } from '../../git/services/git.api';
7
+
8
+ const api = vi.hoisted(() => ({ getPullRequest: vi.fn() }));
9
+ vi.mock('../../git/services/pr.api', () => ({ getPullRequest: api.getPullRequest }));
10
+
11
+ // The view itself is covered where it lives; here it is a stand-in that shows
12
+ // which request it was handed and lets a test close it.
13
+ vi.mock('../components/ChangeRequestDialog', () => ({
14
+ ChangeRequestDialog: ({
15
+ cr,
16
+ onClose,
17
+ onResolved,
18
+ }: {
19
+ cr: PullRequestSummary;
20
+ onClose(): void;
21
+ onResolved(): void;
22
+ }) => (
23
+ <div role="dialog" aria-label={`change request ${cr.number}`}>
24
+ {cr.title}
25
+ <button onClick={onClose}>Close</button>
26
+ <button onClick={onResolved}>Apply</button>
27
+ </div>
28
+ ),
29
+ }));
30
+
31
+ import { ChangeRequestLink } from '../components/ChangeRequestLink';
32
+
33
+ /**
34
+ * `/change-requests/<number>` is the address every agent hands a person for a
35
+ * change request. Until this route existed the shell's catch-all sent it to
36
+ * the workspace with nothing open — "the link didn't open anything". These
37
+ * pin what the address does now: the request opens, a bad or hidden one says
38
+ * so in one sentence, and leaving the view lands in Knowledge.
39
+ */
40
+
41
+ const CR = { number: 276, title: 'Add the Q3 roadmap', author: { login: 'bot' } } as PullRequestSummary;
42
+
43
+ /** The address, and a way to change it the way a link in the app would. */
44
+ function LocationProbe() {
45
+ const location = useLocation();
46
+ const navigate = useNavigate();
47
+ return (
48
+ <>
49
+ <div data-testid="pathname">{location.pathname}</div>
50
+ <button onClick={() => navigate('/change-requests/277')}>Go to 277</button>
51
+ <button onClick={() => navigate(-1)}>Back</button>
52
+ </>
53
+ );
54
+ }
55
+
56
+ function renderAt(path: string) {
57
+ return render(
58
+ <MemoryRouter initialEntries={['/somewhere-before', path]} initialIndex={1}>
59
+ <Routes>
60
+ <Route path="/change-requests/:number" element={<ChangeRequestLink />} />
61
+ <Route path="*" element={<div data-testid="elsewhere" />} />
62
+ </Routes>
63
+ <LocationProbe />
64
+ </MemoryRouter>,
65
+ );
66
+ }
67
+
68
+ beforeEach(() => {
69
+ api.getPullRequest.mockReset();
70
+ });
71
+
72
+ describe('ChangeRequestLink', () => {
73
+ it('opens the request the address names, in the change-request view', async () => {
74
+ api.getPullRequest.mockResolvedValue(CR);
75
+ renderAt('/change-requests/276');
76
+ expect(screen.getByText('Opening change request #276…')).toBeInTheDocument();
77
+ const dialog = await screen.findByRole('dialog', { name: 'change request 276' });
78
+ expect(dialog).toHaveTextContent('Add the Q3 roadmap');
79
+ expect(api.getPullRequest).toHaveBeenCalledWith(276);
80
+ });
81
+
82
+ it.each(['Close', 'Apply'])(
83
+ 'goes to Knowledge on %s — there is nothing under the view to return to',
84
+ async (verb) => {
85
+ api.getPullRequest.mockResolvedValue(CR);
86
+ renderAt('/change-requests/276');
87
+ await userEvent.click(await screen.findByRole('button', { name: verb }));
88
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/workspace$/);
89
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
90
+ },
91
+ );
92
+
93
+ // The link's entry is replaced, not pushed: Back after closing must not
94
+ // land on the address again and reopen the request.
95
+ it('leaves no history entry behind, so Back goes to where the person was before the link', async () => {
96
+ api.getPullRequest.mockResolvedValue(CR);
97
+ renderAt('/change-requests/276');
98
+ await userEvent.click(await screen.findByRole('button', { name: 'Close' }));
99
+ await userEvent.click(screen.getByRole('button', { name: 'Back' }));
100
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/somewhere-before$/);
101
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
102
+ });
103
+
104
+ // The page's own way out behaves the same as the dialog's.
105
+ it('leaves no history entry behind through "Back to the knowledge base" either', async () => {
106
+ api.getPullRequest.mockRejectedValue(new GitApiError(404, 'nope'));
107
+ renderAt('/change-requests/276');
108
+ // Once the answer is on screen: the loading page has the same link, and
109
+ // a click that lands while the answer replaces it hits a detached node.
110
+ await screen.findByText(/There is no change request #276/);
111
+ await userEvent.click(screen.getByRole('link', { name: 'Back to the knowledge base' }));
112
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/workspace$/);
113
+ await userEvent.click(screen.getByRole('button', { name: 'Back' }));
114
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/somewhere-before$/);
115
+ });
116
+
117
+ // A request that is not there and one the viewer may not see read the
118
+ // same: the address must not tell someone a request they may not see
119
+ // exists.
120
+ it.each([404, 403])('says there is no such request on a %s, naming the number', async (status) => {
121
+ api.getPullRequest.mockRejectedValue(new GitApiError(status, 'nope'));
122
+ renderAt('/change-requests/276');
123
+ expect(
124
+ await screen.findByText(/There is no change request #276 — it does not exist, or you may not see it\./),
125
+ ).toBeInTheDocument();
126
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
127
+ expect(screen.getByRole('link', { name: 'Back to the knowledge base' })).toHaveAttribute('href', '/workspace');
128
+ });
129
+
130
+ it('keeps the platform\'s own words for any other failure', async () => {
131
+ api.getPullRequest.mockRejectedValue(new GitApiError(502, 'the repository host is unreachable'));
132
+ renderAt('/change-requests/276');
133
+ expect(await screen.findByText(/could not be opened: the repository host is unreachable/)).toBeInTheDocument();
134
+ });
135
+
136
+ it('asks the server nothing for an address that names no request', async () => {
137
+ for (const bad of [
138
+ '/change-requests/abc',
139
+ '/change-requests/0',
140
+ '/change-requests/-3',
141
+ '/change-requests/12x',
142
+ // One past the database sequence's maximum.
143
+ '/change-requests/2147483648',
144
+ ]) {
145
+ const { unmount } = renderAt(bad);
146
+ expect(screen.getByText(/There is no change request/)).toBeInTheDocument();
147
+ unmount();
148
+ }
149
+ expect(api.getPullRequest).not.toHaveBeenCalled();
150
+ });
151
+
152
+ it('accepts every number the database can hand out', async () => {
153
+ api.getPullRequest.mockResolvedValue({ ...CR, number: 2147483647, title: 'The last one' });
154
+ renderAt('/change-requests/2147483647');
155
+ expect(await screen.findByRole('dialog', { name: 'change request 2147483647' })).toBeInTheDocument();
156
+ });
157
+
158
+ // The router reuses the element across a change of the parameter. A new
159
+ // number must start from "loading", and the first request's answer, if it
160
+ // lands late, must not replace the second's.
161
+ it('shows the request the address names now, not the one it named before', async () => {
162
+ // Both lookups answer when the test says, so each step is observable.
163
+ const pending = new Map<number, (cr: PullRequestSummary) => void>();
164
+ api.getPullRequest.mockImplementation(
165
+ (num: number) => new Promise<PullRequestSummary>((resolve) => pending.set(num, resolve)),
166
+ );
167
+ renderAt('/change-requests/276');
168
+ expect(screen.getByText('Opening change request #276…')).toBeInTheDocument();
169
+
170
+ await userEvent.click(screen.getByRole('button', { name: 'Go to 277' }));
171
+ expect(screen.getByText('Opening change request #277…')).toBeInTheDocument();
172
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
173
+
174
+ pending.get(277)!({ ...CR, number: 277, title: 'The next one' });
175
+ expect(await screen.findByRole('dialog', { name: 'change request 277' })).toHaveTextContent('The next one');
176
+
177
+ // The first answer, late: it belongs to an address the page has left.
178
+ pending.get(276)!(CR);
179
+ await waitFor(() => expect(screen.queryByRole('dialog', { name: 'change request 276' })).not.toBeInTheDocument());
180
+ expect(screen.getByRole('dialog', { name: 'change request 277' })).toHaveTextContent('The next one');
181
+ });
182
+ });
@@ -157,7 +157,7 @@ describe('FileChangeBoxes: who may decide', () => {
157
157
  bus.emit({ kind: 'change-request-merged', number: CR.number } as unknown as WorkflowEvent);
158
158
  });
159
159
  expect(
160
- await screen.findByText('Applied: the file now reads with that change.'),
160
+ await screen.findByText('Published: the file now reads with that change.'),
161
161
  ).toBeInTheDocument();
162
162
  });
163
163
  });
@@ -0,0 +1,79 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ /**
4
+ * `readFileOnBranch` is two reads: open the branch's workspace, then read the
5
+ * file in it. Both can answer 404, for opposite reasons — "there is no branch
6
+ * named X" and "this branch has no such file" — and the callers that treat a
7
+ * file-read 404 as a deletion (the change-request pane, the diff boxes) must
8
+ * never be handed the branch's 404 in that shape. The branch failure is told
9
+ * apart as its own error, status kept.
10
+ */
11
+
12
+ const wsMock = vi.hoisted(() => ({ getOrCreateWorkspace: vi.fn(), readFile: vi.fn() }));
13
+ vi.mock('../../workspace/services/workspace.api', async (importOriginal) => ({
14
+ ...(await importOriginal<typeof import('../../workspace/services/workspace.api')>()),
15
+ getOrCreateWorkspace: wsMock.getOrCreateWorkspace,
16
+ readFile: wsMock.readFile,
17
+ }));
18
+
19
+ import { readFileOnBranch } from '../services/change-requests.api';
20
+ import { WorkspaceApiError } from '../../workspace/services/workspace.api';
21
+ import { BranchUnavailableError, failureReason, isDenial, statusOf } from '../utils/readFailure';
22
+
23
+ beforeEach(() => {
24
+ wsMock.getOrCreateWorkspace.mockReset();
25
+ wsMock.readFile.mockReset();
26
+ wsMock.getOrCreateWorkspace.mockResolvedValue({
27
+ workspace: { id: 'ws-7', kbDirName: 'knowledge-base' },
28
+ fileTree: null,
29
+ });
30
+ });
31
+
32
+ describe('readFileOnBranch', () => {
33
+ it('reads the file inside the branch workspace, under its knowledge-base folder', async () => {
34
+ wsMock.readFile.mockResolvedValue('bands:\n');
35
+ await expect(readFileOnBranch('ali/payroll', 'Finance/bands.yaml')).resolves.toBe('bands:\n');
36
+ expect(wsMock.getOrCreateWorkspace).toHaveBeenCalledWith('ali/payroll');
37
+ expect(wsMock.readFile).toHaveBeenCalledWith('ws-7', 'knowledge-base/Finance/bands.yaml');
38
+ });
39
+
40
+ it("passes the FILE read's 404 through as it is — that is the branch saying it has no such file", async () => {
41
+ wsMock.readFile.mockRejectedValue(new WorkspaceApiError(404));
42
+ const err = await readFileOnBranch('ali/payroll', 'Finance/bands.yaml').catch((e: unknown) => e);
43
+ expect(err).toBeInstanceOf(WorkspaceApiError);
44
+ expect(err).not.toBeInstanceOf(BranchUnavailableError);
45
+ expect(statusOf(err)).toBe(404);
46
+ });
47
+
48
+ it("answers a branch that could not be opened apart from the file's own errors", async () => {
49
+ wsMock.getOrCreateWorkspace.mockRejectedValue(
50
+ new WorkspaceApiError(404, 'There is no branch named ali/payroll.'),
51
+ );
52
+ const err = await readFileOnBranch('ali/payroll', 'Finance/bands.yaml').catch((e: unknown) => e);
53
+ // Not the shape a deletion is read from.
54
+ expect(err).toBeInstanceOf(BranchUnavailableError);
55
+ expect(err).not.toBeInstanceOf(WorkspaceApiError);
56
+ expect((err as BranchUnavailableError).branch).toBe('ali/payroll');
57
+ // The reason the retryable sentence prints names the branch and the cause.
58
+ expect(failureReason(err)).toBe(
59
+ "the branch ali/payroll couldn't be opened (There is no branch named ali/payroll.)",
60
+ );
61
+ // The file was never asked for.
62
+ expect(wsMock.readFile).not.toHaveBeenCalled();
63
+ });
64
+
65
+ it('keeps the status of a refused branch, so a refusal still reads as one', async () => {
66
+ wsMock.getOrCreateWorkspace.mockRejectedValue(new WorkspaceApiError(403));
67
+ const err = await readFileOnBranch('ali/payroll', 'Finance/bands.yaml').catch((e: unknown) => e);
68
+ expect(err).toBeInstanceOf(BranchUnavailableError);
69
+ expect(isDenial(err)).toBe(true);
70
+ });
71
+
72
+ it('carries no status for a branch open that never completed', async () => {
73
+ wsMock.getOrCreateWorkspace.mockRejectedValue(new TypeError('Failed to fetch'));
74
+ const err = await readFileOnBranch('ali/payroll', 'Finance/bands.yaml').catch((e: unknown) => e);
75
+ expect(err).toBeInstanceOf(BranchUnavailableError);
76
+ expect(statusOf(err)).toBeNull();
77
+ expect(isDenial(err)).toBe(false);
78
+ });
79
+ });
@@ -9,6 +9,8 @@ import { ConflictHelp } from './ConflictHelp';
9
9
  export interface ChangeBoxProps {
10
10
  /** File the proposal is against, relative to the skill folder. */
11
11
  file: string;
12
+ /** The file's real name, for hover, when `file` is a platform file's plain name. */
13
+ fileTitle?: string;
12
14
  /** Display name of whoever proposed it. */
13
15
  author: string;
14
16
  /** Already-formatted, e.g. "today" or "2 Aug". */
@@ -105,6 +107,7 @@ export interface ChangeBoxProps {
105
107
  */
106
108
  export function ChangeBox({
107
109
  file,
110
+ fileTitle,
108
111
  author,
109
112
  when,
110
113
  mine,
@@ -143,7 +146,9 @@ export function ChangeBox({
143
146
  <span className="text-detail text-ink">
144
147
  <b className="font-semibold">{who}</b> proposed a change · {when}
145
148
  </span>
146
- <span className="ml-auto truncate font-mono text-meta text-ink-faint">{file}</span>
149
+ <span className="ml-auto truncate font-mono text-meta text-ink-faint" title={fileTitle}>
150
+ {file}
151
+ </span>
147
152
  </div>
148
153
 
149
154
  {/* No diff area when there is no difference — an empty pane under a