@bevel-software/platform-core-frontend 0.21.0 → 0.23.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 (72) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +2 -0
  3. package/src/core/registry.ts +140 -0
  4. package/src/lib/api.ts +49 -0
  5. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  6. package/src/modules/access/api.ts +6 -4
  7. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  8. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  9. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  10. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  11. package/src/modules/access/requests.api.ts +121 -0
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +89 -1
  13. package/src/modules/admin/components/UserAccountsPage.tsx +93 -5
  14. package/src/modules/auth/components/LoginScreen.tsx +8 -0
  15. package/src/modules/auth/services/account.api.ts +26 -3
  16. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  19. package/src/modules/change-requests/components/BranchFilePreview.tsx +7 -1
  20. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  21. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +89 -10
  22. package/src/modules/git/__tests__/HistoryVersionPreview.test.tsx +479 -0
  23. package/src/modules/git/components/FileHistoryPanel.tsx +52 -65
  24. package/src/modules/git/components/HistoryVersionPreview.tsx +410 -0
  25. package/src/modules/layout/__tests__/ReadOnlyBanner.test.tsx +157 -0
  26. package/src/modules/layout/components/ReadOnlyBanner.tsx +96 -0
  27. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  28. package/src/modules/library/__tests__/ToolPage.test.tsx +15 -1
  29. package/src/modules/library/__tests__/title-row-actions.ts +53 -1
  30. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  31. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  32. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -1
  33. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  34. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  35. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  36. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  37. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  38. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  39. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  40. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +296 -0
  41. package/src/modules/setup/__tests__/setup.repository.test.tsx +463 -0
  42. package/src/modules/setup/__tests__/setup.test.tsx +13 -17
  43. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  44. package/src/modules/setup/components/SetupGate.tsx +1 -0
  45. package/src/modules/setup/components/SetupScreen.tsx +608 -41
  46. package/src/modules/setup/services/setup.api.ts +171 -3
  47. package/src/modules/setup/utils/kept-draft.ts +86 -0
  48. package/src/modules/workspace/components/FileExplorer.tsx +140 -12
  49. package/src/modules/workspace/components/FileViewer.tsx +11 -1
  50. package/src/modules/workspace/components/TreeActionConfirm.tsx +5 -7
  51. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +603 -29
  52. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +23 -6
  53. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +41 -8
  54. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +20 -5
  55. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +39 -16
  56. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +27 -7
  57. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +20 -5
  58. package/src/modules/workspace/components/renderers/RetryReadButton.tsx +37 -0
  59. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +20 -5
  60. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +186 -7
  61. package/src/modules/workspace/components/renderers/__tests__/readPane.test.tsx +59 -0
  62. package/src/modules/workspace/components/renderers/htmlSandbox.ts +80 -20
  63. package/src/modules/workspace/components/renderers/index.ts +6 -1
  64. package/src/modules/workspace/components/renderers/readPane.ts +22 -0
  65. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +50 -9
  66. package/src/modules/workspace/components/renderers/useReadRetry.ts +27 -0
  67. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +79 -0
  68. package/src/modules/workspace/routing/kb-routes.ts +25 -10
  69. package/src/modules/workspace/services/workspace.api.ts +22 -1
  70. package/src/shared/components/SlotBoundary.tsx +51 -0
  71. package/src/shared/markdown/__tests__/hrefs.test.ts +111 -0
  72. package/src/shared/markdown/hrefs.ts +80 -4
@@ -0,0 +1,463 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+
5
+ const api = vi.hoisted(() => ({
6
+ fetchSetupStatus: vi.fn(),
7
+ saveSettings: vi.fn(),
8
+ testConnection: vi.fn(),
9
+ testOidc: vi.fn(),
10
+ syncNow: vi.fn(),
11
+ }));
12
+ vi.mock('../services/setup.api', async () => {
13
+ const actual = await vi.importActual<typeof import('../services/setup.api')>('../services/setup.api');
14
+ return { ...actual, ...api };
15
+ });
16
+ vi.mock('../../settings/services/github-facade.api', () => ({
17
+ fetchGitHubFacade: vi.fn(),
18
+ rotateGitHubFacade: vi.fn(),
19
+ fetchMarketplaceRegistration: vi.fn(async () => false),
20
+ setMarketplaceRegistration: vi.fn(),
21
+ }));
22
+
23
+ import { SetupScreen } from '../components/SetupScreen';
24
+ import { RepositoryChangeNeedsConfirmation, SettingsProblems, type GitMode, type RepositoryStatus, type SettingStatus } from '../services/setup.api';
25
+
26
+ const KB = 'knowledge-base' as const;
27
+ const setting = (key: string, extra: Partial<SettingStatus> = {}): SettingStatus => ({
28
+ key,
29
+ section: KB,
30
+ source: 'unset',
31
+ value: '',
32
+ configured: false,
33
+ secret: false,
34
+ restartToApply: false,
35
+ ...extra,
36
+ });
37
+
38
+ /** A deployment's settings: nothing answered, or an address and a token stored. */
39
+ const settingsOf = (configured: boolean): SettingStatus[] => [
40
+ setting('gitMode', { envVar: 'GIT_MODE', restartToApply: true }),
41
+ setting('kbRepoUrl', configured ? { source: 'stored', configured: true, value: 'https://git.example.com/acme/kb.git' } : {}),
42
+ setting('gitToken', { secret: true, value: undefined, ...(configured ? { source: 'stored', configured: true } : {}) }),
43
+ setting('gitUsername'),
44
+ setting('knowledgeBaseDir', { restartToApply: true }),
45
+ setting('defaultBranch', configured ? { source: 'stored', configured: true, value: 'main' } : {}),
46
+ setting('protectedBranches', configured ? { source: 'stored', configured: true, value: 'main' } : {}),
47
+ ];
48
+
49
+ const MODES: GitMode[] = ['managed', 'token'];
50
+ /** A deployment on `mode`, which has chosen `chosen`: the same way, unless a move is pending. */
51
+ const offering = (mode: GitMode | null, chosen: GitMode | null = mode, pinned?: string): RepositoryStatus => ({
52
+ mode,
53
+ chosen,
54
+ ...(pinned ? { pinned } : {}),
55
+ modes: MODES,
56
+ });
57
+
58
+ function show(
59
+ opts: {
60
+ mode?: GitMode | null;
61
+ chosen?: GitMode | null;
62
+ pinned?: string;
63
+ configured?: boolean;
64
+ variant?: 'setup' | 'settings';
65
+ tabs?: boolean;
66
+ } = {},
67
+ ) {
68
+ const configured = opts.configured ?? false;
69
+ const mode = opts.mode === undefined ? (configured ? 'token' : null) : opts.mode;
70
+ return render(
71
+ <SetupScreen
72
+ settings={settingsOf(configured)}
73
+ onSaved={() => {}}
74
+ variant={opts.variant ?? 'setup'}
75
+ {...(opts.tabs === false ? {} : { repository: offering(mode, opts.chosen === undefined ? mode : opts.chosen, opts.pinned) })}
76
+ />,
77
+ );
78
+ }
79
+
80
+ const tab = (name: string) => screen.getByRole('tab', { name });
81
+ const address = () => screen.queryByLabelText('Repository address', { exact: false });
82
+ const save = () => userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
83
+ const saved = (mode: GitMode | null, configured: boolean) => ({
84
+ restartRequired: false,
85
+ complete: true,
86
+ settings: settingsOf(configured),
87
+ repository: offering(mode),
88
+ });
89
+
90
+ beforeEach(() => {
91
+ for (const fn of Object.values(api)) fn.mockReset();
92
+ Object.defineProperty(window, 'location', {
93
+ configurable: true,
94
+ value: { ...window.location, reload: vi.fn(), origin: 'https://example.test' },
95
+ });
96
+ });
97
+
98
+ describe('SetupScreen: the ways of having a repository', () => {
99
+ it('offers them as tabs, in the order the deployment gives', () => {
100
+ show();
101
+ const tabs = within(screen.getByRole('tablist', { name: 'Where the repository is' })).getAllByRole('tab');
102
+ expect(tabs.map((t) => t.textContent)).toEqual(['Managed for you', 'Address and token']);
103
+ });
104
+
105
+ it('opens a new deployment on the first: the repository it keeps itself', () => {
106
+ show();
107
+ expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
108
+ expect(screen.getByTestId('managed-repository')).toHaveTextContent('There is nothing to connect and nothing to enter');
109
+ // Nothing to type, nothing to test.
110
+ expect(address()).toBeNull();
111
+ expect(screen.queryByLabelText('Access token', { exact: false })).toBeNull();
112
+ expect(screen.queryByRole('button', { name: 'Test connection' })).toBeNull();
113
+ });
114
+
115
+ it('opens a configured deployment on the way it has, as it was', () => {
116
+ show({ configured: true, variant: 'settings' });
117
+ expect(tab('Address and token')).toHaveAttribute('aria-selected', 'true');
118
+ expect(address()).toHaveValue('https://git.example.com/acme/kb.git');
119
+ expect(screen.getByRole('button', { name: 'Test connection' })).toBeInTheDocument();
120
+ expect(screen.queryByTestId('moves-repository')).toBeNull();
121
+ });
122
+
123
+ it('gives each tab a panel of its own', async () => {
124
+ show();
125
+ for (const name of ['Managed for you', 'Address and token']) {
126
+ await userEvent.click(tab(name));
127
+ const panel = document.getElementById(tab(name).getAttribute('aria-controls')!);
128
+ expect(panel).toHaveAttribute('role', 'tabpanel');
129
+ expect(panel).toHaveAttribute('aria-labelledby', tab(name).id);
130
+ }
131
+ expect(within(document.getElementById('repository-panel-token')!).getByLabelText('Repository address', { exact: false })).toBeInTheDocument();
132
+ });
133
+
134
+ it('keeps what belongs to every repository under whichever tab is open', async () => {
135
+ show();
136
+ expect(screen.getByLabelText('Knowledge folder', { exact: false })).toBeInTheDocument();
137
+ await userEvent.click(tab('Address and token'));
138
+ expect(screen.getByLabelText('Knowledge folder', { exact: false })).toBeInTheDocument();
139
+ });
140
+
141
+ it('draws the one way there was, with no tabs, for a server that knows no other', () => {
142
+ show({ tabs: false });
143
+ expect(screen.queryByRole('tablist')).toBeNull();
144
+ expect(address()).toBeInTheDocument();
145
+ expect(screen.getByRole('button', { name: 'Test connection' })).toBeInTheDocument();
146
+ });
147
+ });
148
+
149
+ describe('SetupScreen: saving a repository the deployment keeps', () => {
150
+ it('finishes setup on the choice alone, without asking any host anything', async () => {
151
+ api.saveSettings.mockResolvedValue(saved('managed', false));
152
+ show();
153
+ await save();
154
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
155
+ expect(api.testConnection).not.toHaveBeenCalled();
156
+ });
157
+
158
+ it('does not store an address and a token that were typed on a tab that was then left', async () => {
159
+ api.saveSettings.mockResolvedValue(saved('managed', false));
160
+ show();
161
+ await userEvent.click(tab('Address and token'));
162
+ await userEvent.type(address()!, 'https://git.example.com/acme/kb.git');
163
+ await userEvent.type(screen.getByLabelText('Access token', { exact: false }), 'a-token');
164
+ await userEvent.click(tab('Managed for you'));
165
+ await save();
166
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
167
+ expect(api.testConnection).not.toHaveBeenCalled();
168
+ });
169
+
170
+ it('is not held back by a connection test that failed on the other tab', async () => {
171
+ api.testConnection.mockResolvedValue({ ok: false, outcome: 'rejected', error: 'The host turned that token down.' });
172
+ api.saveSettings.mockResolvedValue(saved('managed', false));
173
+ show();
174
+ await userEvent.click(tab('Address and token'));
175
+ await userEvent.type(address()!, 'https://git.example.com/acme/kb.git');
176
+ await userEvent.click(screen.getByRole('button', { name: 'Test connection' }));
177
+ await screen.findByText('The host turned that token down.');
178
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeDisabled();
179
+
180
+ await userEvent.click(tab('Managed for you'));
181
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeEnabled();
182
+ await save();
183
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalled());
184
+ });
185
+
186
+ it('says out loud why the choice was refused, since no field holds it', async () => {
187
+ api.saveSettings.mockRejectedValue(
188
+ new SettingsProblems({ gitMode: 'The repository could not be created on this deployment’s storage.' }),
189
+ );
190
+ show();
191
+ await save();
192
+ expect(await screen.findByText(/could not be created on this deployment/)).toBeInTheDocument();
193
+ });
194
+ });
195
+
196
+ describe('SetupScreen: saving a repository reached by its address', () => {
197
+ it('sends the way along with the address and the token on a deployment that has none', async () => {
198
+ api.testConnection.mockResolvedValue({ ok: true, outcome: 'connected', branches: ['main'], defaultBranch: 'main' });
199
+ api.saveSettings.mockResolvedValue(saved('token', true));
200
+ show();
201
+ await userEvent.click(tab('Address and token'));
202
+ await userEvent.type(address()!, 'https://git.example.com/acme/kb.git');
203
+ await userEvent.type(screen.getByLabelText('Access token', { exact: false }), 'a-token');
204
+ await save();
205
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalled());
206
+ expect(api.saveSettings.mock.calls[0]![0]).toMatchObject({
207
+ gitMode: 'token',
208
+ kbRepoUrl: 'https://git.example.com/acme/kb.git',
209
+ gitToken: 'a-token',
210
+ });
211
+ // Proven before it was stored, as ever.
212
+ expect(api.testConnection).toHaveBeenCalled();
213
+ });
214
+
215
+ it('says nothing about the way on a deployment that stays on the one it has', async () => {
216
+ api.saveSettings.mockResolvedValue(saved('token', true));
217
+ show({ configured: true, variant: 'settings' });
218
+ await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
219
+ await save();
220
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ knowledgeBaseDir: 'Docs' }));
221
+ });
222
+
223
+ it('opens the tab a refused address or token is on', async () => {
224
+ api.saveSettings.mockRejectedValue(new SettingsProblems({ gitToken: 'The host turned that token down.' }));
225
+ show({ configured: true, mode: 'managed', variant: 'settings' });
226
+ expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
227
+ await save();
228
+ expect(await screen.findByText('The host turned that token down.')).toBeInTheDocument();
229
+ expect(tab('Address and token')).toHaveAttribute('aria-selected', 'true');
230
+ });
231
+ });
232
+
233
+ describe('SetupScreen: moving a deployment to another repository', () => {
234
+ it('says what saving will do, before it is pressed', async () => {
235
+ show({ configured: true, variant: 'settings' });
236
+ await userEvent.click(tab('Managed for you'));
237
+ const warning = screen.getByTestId('moves-repository');
238
+ expect(warning).toHaveTextContent('moves this deployment to another repository');
239
+ expect(warning).toHaveTextContent('Nothing is deleted');
240
+ // Going back is staying: nothing to warn about.
241
+ await userEvent.click(tab('Address and token'));
242
+ expect(screen.queryByTestId('moves-repository')).toBeNull();
243
+ });
244
+
245
+ /** The server's refusal of a save that moves, until the admin has answered. */
246
+ const asksFirst = (openChangeRequests = 0, to: GitMode = 'managed') =>
247
+ api.saveSettings.mockImplementation(async (_settings: unknown, confirm?: string) => {
248
+ if (!confirm) throw new RepositoryChangeNeedsConfirmation(openChangeRequests, 'token', to);
249
+ return {
250
+ ...saved(to, true),
251
+ repositoryChange: { choice: confirm, closedChangeRequests: confirm === 'close' ? openChangeRequests : 0 },
252
+ };
253
+ });
254
+ const question = () => screen.findByTestId('repository-change-confirm');
255
+ const confirmMove = () => userEvent.click(screen.getByRole('button', { name: 'Move the deployment' }));
256
+
257
+ /**
258
+ * The tab is the choice, and the tab is a screen above the button. An
259
+ * admin who opens another way to read about it, changes a sign-in field
260
+ * and saves must not have moved the deployment to an empty repository.
261
+ * The server refuses that save, and the screen puts the question.
262
+ */
263
+ it('does not move on a save the admin was not asked about', async () => {
264
+ asksFirst();
265
+ show({ configured: true, variant: 'settings' });
266
+ await userEvent.click(tab('Managed for you'));
267
+ await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
268
+ await save();
269
+
270
+ // Asked at the button, naming what is left and what is moved to.
271
+ const asked = await question();
272
+ expect(asked).toHaveTextContent('Move this deployment from “Address and token” to “Managed for you”?');
273
+ expect(asked).toHaveTextContent('Nothing is deleted');
274
+ expect(asked).toHaveTextContent('with no restart');
275
+ // One refused attempt, and the save button waits for the answer.
276
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
277
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeDisabled();
278
+ });
279
+
280
+ it('sends the move once the admin has said yes, and nothing of the repository it leaves', async () => {
281
+ asksFirst();
282
+ show({ configured: true, variant: 'settings' });
283
+ await userEvent.click(tab('Managed for you'));
284
+ await save();
285
+ await question();
286
+ await confirmMove();
287
+ await waitFor(() => expect(api.saveSettings).toHaveBeenLastCalledWith({ gitMode: 'managed' }, 'keep', 0));
288
+ expect(api.testConnection).not.toHaveBeenCalled();
289
+ // Moved on the save: said so, with no restart owed.
290
+ expect(await screen.findByTestId('repository-changed')).toHaveTextContent('now works on the new repository');
291
+ });
292
+
293
+ it('asks again for another move: a yes to one is not a yes to the next', async () => {
294
+ asksFirst();
295
+ render(
296
+ <SetupScreen
297
+ settings={settingsOf(true)}
298
+ onSaved={() => {}}
299
+ variant="settings"
300
+ repository={{ mode: 'token', chosen: 'token', modes: ['managed', 'github-app', 'token'] }}
301
+ />,
302
+ );
303
+ await userEvent.click(tab('Managed for you'));
304
+ await save();
305
+ await question();
306
+ await confirmMove();
307
+ await screen.findByTestId('repository-changed');
308
+ expect(api.saveSettings).toHaveBeenCalledTimes(2);
309
+
310
+ // Another move, after a yes: its save carries no answer, and is asked.
311
+ await userEvent.click(tab('Address and token'));
312
+ await save();
313
+ await question();
314
+ expect(api.saveSettings).toHaveBeenCalledTimes(3);
315
+ expect(api.saveSettings.mock.calls[2]).toHaveLength(1);
316
+ });
317
+
318
+ it('takes the question down when another tab is opened: it was about another move', async () => {
319
+ asksFirst();
320
+ render(
321
+ <SetupScreen
322
+ settings={settingsOf(true)}
323
+ onSaved={() => {}}
324
+ variant="settings"
325
+ repository={{ mode: 'token', chosen: 'token', modes: ['managed', 'github-app', 'token'] }}
326
+ />,
327
+ );
328
+ await userEvent.click(tab('Managed for you'));
329
+ await save();
330
+ await question();
331
+ await userEvent.click(tab('GitHub'));
332
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
333
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
334
+ });
335
+
336
+ it('closes the open change requests when the admin picks that, and says so', async () => {
337
+ asksFirst(2);
338
+ show({ configured: true, variant: 'settings' });
339
+ await userEvent.click(tab('Managed for you'));
340
+ await save();
341
+ await question();
342
+ await userEvent.click(screen.getByRole('radio', { name: /Close them as/ }));
343
+ await confirmMove();
344
+ await waitFor(() => expect(api.saveSettings).toHaveBeenLastCalledWith({ gitMode: 'managed' }, 'close', 2));
345
+ expect(await screen.findByTestId('repository-changed')).toHaveTextContent(
346
+ '2 change requests were closed as “repository replaced”.',
347
+ );
348
+ });
349
+
350
+ it('asks again when the count of open change requests changed while the question stood', async () => {
351
+ let open = 0;
352
+ api.saveSettings.mockImplementation(async (_settings: unknown, confirm?: string, seen?: number) => {
353
+ if (!confirm || seen !== open) throw new RepositoryChangeNeedsConfirmation(open, 'token', 'managed');
354
+ return { ...saved('managed', true), repositoryChange: { choice: confirm, closedChangeRequests: 0 } };
355
+ });
356
+ show({ configured: true, variant: 'settings' });
357
+ await userEvent.click(tab('Managed for you'));
358
+ await save();
359
+ await question();
360
+ expect(screen.queryAllByRole('radio')).toEqual([]);
361
+
362
+ // A request is opened before the admin answers.
363
+ open = 1;
364
+ await confirmMove();
365
+ await waitFor(() => expect(screen.getByTestId('repository-change-confirm')).toHaveTextContent('There is 1 open change request.'));
366
+ expect(screen.queryByTestId('repository-changed')).toBeNull();
367
+ });
368
+
369
+ it('cancelling leaves the deployment where it is', async () => {
370
+ asksFirst(2);
371
+ show({ configured: true, variant: 'settings' });
372
+ await userEvent.click(tab('Managed for you'));
373
+ await save();
374
+ expect(await question()).toHaveTextContent('There are 2 open change requests.');
375
+ await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
376
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
377
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
378
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeEnabled();
379
+ });
380
+
381
+ it('asks nothing of a save that stays where the deployment is', async () => {
382
+ api.saveSettings.mockResolvedValue(saved('token', true));
383
+ show({ configured: true, variant: 'settings' });
384
+ await userEvent.click(tab('Managed for you'));
385
+ await userEvent.click(tab('Address and token'));
386
+ await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
387
+ await save();
388
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ knowledgeBaseDir: 'Docs' }));
389
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
390
+ });
391
+
392
+ it('asks nothing on a deployment that has no repository to leave', async () => {
393
+ api.saveSettings.mockResolvedValue(saved('managed', false));
394
+ show();
395
+ await userEvent.click(tab('Address and token'));
396
+ expect(screen.queryByTestId('moves-repository')).toBeNull();
397
+ await userEvent.click(tab('Managed for you'));
398
+ await save();
399
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
400
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
401
+ });
402
+ });
403
+
404
+ /**
405
+ * A confirmed move takes effect on its save, so this state is not one a move
406
+ * leaves behind any more. It is still one a server can report (a way chosen
407
+ * that it has not put in effect), and the screen must read it truthfully.
408
+ */
409
+ describe('SetupScreen: a way chosen that is not in effect yet', () => {
410
+ it('opens on the way chosen, and says the deployment is still on the one it has', () => {
411
+ show({ configured: true, mode: 'token', chosen: 'managed', variant: 'settings' });
412
+ expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
413
+ const pending = screen.getByTestId('move-pending');
414
+ expect(pending).toHaveTextContent('A restart is pending');
415
+ expect(pending).toHaveTextContent('still working on “Address and token”');
416
+ // The move was made: it is not offered again, and not asked about again.
417
+ expect(screen.queryByTestId('moves-repository')).toBeNull();
418
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
419
+ });
420
+
421
+ it('does not send the move a second time with a save about something else', async () => {
422
+ api.saveSettings.mockResolvedValue({ ...saved('token', true), restartRequired: true, repository: offering('token', 'managed') });
423
+ show({ configured: true, mode: 'token', chosen: 'managed', variant: 'settings' });
424
+ await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
425
+ await save();
426
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ knowledgeBaseDir: 'Docs' }));
427
+ });
428
+
429
+ it('takes the move back by saving on the way in effect, without being asked', async () => {
430
+ api.saveSettings.mockResolvedValue(saved('token', true));
431
+ show({ configured: true, mode: 'token', chosen: 'managed', variant: 'settings' });
432
+ await userEvent.click(tab('Address and token'));
433
+ expect(screen.getByTestId('move-taken-back')).toHaveTextContent('Saving takes the move back');
434
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
435
+ await save();
436
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'token' }));
437
+ });
438
+
439
+ it('reads a server that does not tell the two apart as one that has no move pending', () => {
440
+ render(<SetupScreen settings={settingsOf(true)} onSaved={() => {}} variant="settings" repository={{ mode: 'token', modes: MODES }} />);
441
+ expect(tab('Address and token')).toHaveAttribute('aria-selected', 'true');
442
+ expect(screen.queryByTestId('move-pending')).toBeNull();
443
+ });
444
+ });
445
+
446
+ describe('SetupScreen: a way chosen by the environment', () => {
447
+ it('shows the other ways as not the screen to choose, and says which variable chose', async () => {
448
+ show({ mode: 'managed', pinned: 'GIT_MODE', variant: 'settings' });
449
+ expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
450
+ expect(tab('Managed for you')).toBeEnabled();
451
+ expect(tab('Address and token')).toBeDisabled();
452
+ expect(screen.getByTestId('repository-pinned')).toHaveTextContent('Set by the GIT_MODE environment variable');
453
+ await userEvent.click(tab('Address and token'));
454
+ expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
455
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
456
+ });
457
+
458
+ it('says nothing of the kind when the admin chose', () => {
459
+ show({ mode: 'managed', variant: 'settings' });
460
+ expect(tab('Address and token')).toBeEnabled();
461
+ expect(screen.queryByTestId('repository-pinned')).toBeNull();
462
+ });
463
+ });
@@ -146,23 +146,18 @@ describe('SetupScreen', () => {
146
146
  });
147
147
 
148
148
  /**
149
- * The first-run host of the Marketplace section: marked optional and never
150
- * in the way — setup finishes without anyone touching it, and nothing in it
151
- * is fetched or saved on the way. There is no skip control to press: an
152
- * admin ignores the section the way they ignore single sign-on, by leaving
153
- * it alone. Because "Save and continue" now sits BELOW this section and is
154
- * tied to the form by `form=`, this also proves that out-of-form submit
155
- * still saves.
149
+ * The first run asks for the repository and for sign-in, and nothing else:
150
+ * Marketplace is a preference set on the Deployment page. Setup finishes
151
+ * without it, and nothing of it is fetched or saved on the way. Because
152
+ * "Save and continue" sits outside the form and is tied to it by `form=`,
153
+ * this also proves that out-of-form submit still saves.
156
154
  */
157
- it('offers the Marketplace section as optional, and finishes setup having ignored it', async () => {
155
+ it('leaves Marketplace to the Deployment page, and finishes setup without it', async () => {
158
156
  facade.fetchGitHubFacade.mockClear();
159
157
  facade.setMarketplaceRegistration.mockClear();
160
158
  await renderScreen();
161
- const section = await screen.findByTestId('marketplace-deployment-section');
162
- expect(section).toHaveTextContent('Optional');
163
- expect(screen.getByRole('heading', { name: 'Marketplace' })).toBeInTheDocument();
164
- expect(screen.getByText('Register this deployment with your Claude organization')).toBeInTheDocument();
165
- expect(screen.queryByRole('button', { name: 'Skip for now' })).toBeNull();
159
+ expect(screen.queryByTestId('marketplace-deployment-section')).toBeNull();
160
+ expect(screen.queryByRole('heading', { name: 'Marketplace' })).toBeNull();
166
161
 
167
162
  api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: SETTINGS });
168
163
  await userEvent.type(screen.getByLabelText('Repository address'), 'https://example.com/kb.git');
@@ -303,11 +298,13 @@ describe('SetupScreen', () => {
303
298
  await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
304
299
 
305
300
  await waitFor(() => expect(api.testConnection).toHaveBeenCalled());
306
- expect(await screen.findByRole('alert')).toHaveTextContent(/Not saved/);
301
+ // The refusal carries the host's OWN words: "fix the connection above" on
302
+ // its own leaves an admin rereading a form that looks perfectly correct.
303
+ const refusal = await screen.findByRole('alert');
304
+ expect(refusal).toHaveTextContent(/Not saved/);
305
+ expect(refusal).toHaveTextContent('No repository at that URL — or the token cannot see it.');
307
306
  expect(api.saveSettings).not.toHaveBeenCalled();
308
307
  expect(reload).not.toHaveBeenCalled();
309
- // And the host's own words are on screen, not just the refusal.
310
- expect(screen.getByText(/No repository at that URL/)).toBeInTheDocument();
311
308
  });
312
309
 
313
310
  /**
@@ -804,7 +801,6 @@ describe('SetupScreen', () => {
804
801
  /** Single sign-on is skippable, and the screen has to say so. */
805
802
  it('marks the optional section optional', async () => {
806
803
  await renderScreen();
807
- // Scoped: the Marketplace section below the form is optional too.
808
804
  const signIn = screen.getByRole('heading', { name: 'Single sign-on' }).closest('section')!;
809
805
  expect(within(signIn).getByText('Optional')).toBeInTheDocument();
810
806
  });