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

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 (42) hide show
  1. package/package.json +2 -2
  2. package/src/core/ProductName.tsx +4 -4
  3. package/src/core/__tests__/ProductName.test.tsx +46 -0
  4. package/src/core/maker-url.ts +30 -0
  5. package/src/core/registry.ts +27 -0
  6. package/src/lib/__tests__/latest-request.test.ts +48 -0
  7. package/src/lib/latest-request.ts +45 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  9. package/src/modules/access/api.ts +19 -3
  10. package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
  11. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  13. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  14. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  15. package/src/modules/admin/services/roles.api.ts +14 -1
  16. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  17. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  18. package/src/modules/auth/components/LoginScreen.tsx +100 -75
  19. package/src/modules/auth/services/account.api.ts +31 -2
  20. package/src/modules/auth/services/sso.ts +29 -8
  21. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  22. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  23. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
  24. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
  25. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
  26. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  27. package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
  28. package/src/modules/onboarding/components/InviteButton.tsx +119 -15
  29. package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
  30. package/src/modules/onboarding/first-page-prompt.ts +34 -0
  31. package/src/modules/onboarding/invite-emails.ts +171 -33
  32. package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
  33. package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
  34. package/src/modules/toolbar/commands/actions.tsx +10 -4
  35. package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
  36. package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
  37. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
  38. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
  39. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  40. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  41. package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
  42. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
@@ -41,6 +41,26 @@ const { listAccountsMock, listPluginsMock, openWorkspacePathMock, fetchAgentConn
41
41
  }));
42
42
 
43
43
  vi.mock('../../../lib/api', () => ({ authFetch: authFetchMock }));
44
+
45
+ /**
46
+ * The repo-relative folders the person may write, as the batch access
47
+ * endpoint answers them. The top of Knowledge by default — what an admin
48
+ * may, and what every test before this ticket assumed. `readable` is what a
49
+ * draft branch asks the same endpoint instead: there the server's only gate
50
+ * on a new page is that its author may read where it lands.
51
+ */
52
+ type AccessVerb = 'write' | 'owner' | 'read';
53
+ const { access } = vi.hoisted(() => ({
54
+ access: {
55
+ writable: new Set<string>(),
56
+ readable: new Set<string>(),
57
+ batch: vi.fn<(workspaceId: string, paths: string[], verb?: AccessVerb) => Promise<{ results: Record<string, boolean> }>>(),
58
+ },
59
+ }));
60
+ vi.mock('../../access/api', async (importOriginal) => ({
61
+ ...(await importOriginal<typeof import('../../access/api')>()),
62
+ fetchFileAccessBatch: access.batch,
63
+ }));
44
64
  vi.mock('../services/agent-connection.api', () => ({ fetchAgentConnection: fetchAgentConnectionMock }));
45
65
  const { fetchStarterPacksMock } = vi.hoisted(() => ({
46
66
  fetchStarterPacksMock: vi.fn<() => Promise<StarterPacksAnswer>>(),
@@ -111,6 +131,8 @@ function account(email: string, over: Partial<AccountSummary> = {}): AccountSumm
111
131
  name: email,
112
132
  hasPassword: false,
113
133
  isEnvAdmin: false,
134
+ isOwner: false,
135
+ ownerCanBeDeleted: false,
114
136
  deactivatedAt: null,
115
137
  isSystem: false,
116
138
  createdAt: '2026-01-01T00:00:00Z',
@@ -223,9 +245,34 @@ function columnUi({
223
245
  return ui;
224
246
  }
225
247
 
226
- function mount(options: MountOptions = {}) {
248
+ /**
249
+ * Mount the column and let the question of where New page may write answer
250
+ * (the list waits for it, so nothing is on screen before it does).
251
+ */
252
+ async function mount(options: MountOptions = {}) {
227
253
  const ui = columnUi(options);
228
- return { ...render(ui), ui };
254
+ const rendered = render(ui);
255
+ await settle();
256
+ return { ...rendered, ui };
257
+ }
258
+
259
+ /** Let pending requests answer: one macrotask runs every queued microtask. */
260
+ async function settle() {
261
+ await act(async () => {
262
+ if (vi.isFakeTimers()) await vi.advanceTimersByTimeAsync(0);
263
+ else await new Promise((resolve) => setTimeout(resolve, 0));
264
+ });
265
+ }
266
+
267
+ /** Longer than the write check's debounce (250 ms, private to the hook). */
268
+ const PAST_WRITE_CHECK_DEBOUNCE_MS = 300;
269
+
270
+ /** Wait past the write check's debounce, so a tree change has been asked about. */
271
+ async function settleRecheck() {
272
+ await act(async () => {
273
+ await new Promise((resolve) => setTimeout(resolve, PAST_WRITE_CHECK_DEBOUNCE_MS));
274
+ });
275
+ await settle();
229
276
  }
230
277
 
231
278
  /** The checklist row titled `title`, or null when the column does not list it. */
@@ -258,15 +305,23 @@ beforeEach(() => {
258
305
  openWorkspacePathMock.mockReset();
259
306
  fetchAgentConnectionMock.mockReset().mockResolvedValue({ connected: false });
260
307
  authFetchMock.mockClear();
308
+ access.writable = new Set(['KnowledgeBase']);
309
+ access.readable = new Set(['KnowledgeBase']);
310
+ access.batch.mockReset().mockImplementation(async (_ws, paths, verb = 'write') => ({
311
+ results: Object.fromEntries(paths.map((p) => [p, (verb === 'read' ? access.readable : access.writable).has(p)])),
312
+ }));
261
313
  });
262
314
 
315
+ /** The verb every access check so far asked: `read` on a draft, `write` anywhere else. */
316
+ const accessVerbsAsked = () => new Set(access.batch.mock.calls.map((c) => c[2] ?? 'write'));
317
+
263
318
  /** Calls to the onboarding write — the one `markDone` makes. */
264
319
  const doneWrites = () =>
265
320
  authFetchMock.mock.calls.filter((c) => (c as unknown[])[0] === '/api/auth/onboarding-done').length;
266
321
 
267
322
  describe('GetStartedColumn: what a member sees', () => {
268
- it('lists the five member steps, hides the admin-only ones, and asks the server nothing', () => {
269
- mount();
323
+ it('lists the five member steps, hides the admin-only ones, and asks the server nothing', async () => {
324
+ await mount();
270
325
  expect(screen.getByText('1 of 5')).toBeInTheDocument();
271
326
  expect(row('Create your workspace')).not.toBeNull();
272
327
  expect(row('Connect your agent')).not.toBeNull();
@@ -280,43 +335,43 @@ describe('GetStartedColumn: what a member sees', () => {
280
335
  expect(listPluginsMock).not.toHaveBeenCalled();
281
336
  });
282
337
 
283
- it('ticks "Connect your agent" from the server onboarding flag', () => {
284
- mount({ onboardingDone: true });
338
+ it('ticks "Connect your agent" from the server onboarding flag', async () => {
339
+ await mount({ onboardingDone: true });
285
340
  expect(isDone('Connect your agent')).toBe(true);
286
341
  expect(isDone('Create your workspace')).toBe(true);
287
342
  expect(screen.getByText('2 of 5')).toBeInTheDocument();
288
343
  });
289
344
 
290
345
  it('sends "Connect" to the welcome page', async () => {
291
- mount();
346
+ await mount();
292
347
  await userEvent.click(within(row('Connect your agent')!).getByRole('button', { name: 'Connect' }));
293
348
  expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
294
349
  });
295
350
 
296
351
  it('opens the starter guide and ticks it', async () => {
297
- mount();
352
+ await mount();
298
353
  expect(isDone('Read “How to get started”')).toBe(false);
299
354
  await userEvent.click(within(row('Read “How to get started”')!).getByRole('button', { name: 'Open it' }));
300
355
  expect(openWorkspacePathMock).toHaveBeenCalledWith(GUIDE);
301
356
  expect(isDone('Read “How to get started”')).toBe(true);
302
357
  });
303
358
 
304
- it('ticks the guide when it is opened by any route, and remembers it', () => {
305
- const { unmount } = mount({ openFilePath: GUIDE });
359
+ it('ticks the guide when it is opened by any route, and remembers it', async () => {
360
+ const { unmount } = await mount({ openFilePath: GUIDE });
306
361
  expect(isDone('Read “How to get started”')).toBe(true);
307
362
  unmount();
308
- mount();
363
+ await mount();
309
364
  expect(isDone('Read “How to get started”')).toBe(true);
310
365
  });
311
366
 
312
- it('leaves the guide step out when the knowledge base has no such page', () => {
313
- mount({ files: [`${KB}/KnowledgeBase/.gitkeep`] });
367
+ it('leaves the guide step out when the knowledge base has no such page', async () => {
368
+ await mount({ files: [`${KB}/KnowledgeBase/.gitkeep`] });
314
369
  expect(row('Read “How to get started”')).toBeNull();
315
370
  expect(screen.getByText('1 of 4')).toBeInTheDocument();
316
371
  });
317
372
 
318
373
  it('ticks "Write your first page" only for content other than the starter page', async () => {
319
- const { unmount } = mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/access.md`] });
374
+ const { unmount } = await mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/access.md`] });
320
375
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
321
376
  expect(isDone('Write your first page')).toBe(false);
322
377
  expect(
@@ -325,14 +380,14 @@ describe('GetStartedColumn: what a member sees', () => {
325
380
  ),
326
381
  ).toBeInTheDocument();
327
382
  unmount();
328
- mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Product/Roadmap.md`] });
383
+ await mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Product/Roadmap.md`] });
329
384
  // Ticked once the starter-pack answer is in (none chosen here).
330
385
  await waitFor(() => expect(isDone('Write your first page')).toBe(true));
331
386
  });
332
387
 
333
388
  it('"New page" creates Untitled.md in the Knowledge folder and opens it for editing', async () => {
334
389
  const createFile = vi.fn(async () => {});
335
- mount({ createFile });
390
+ await mount({ createFile });
336
391
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
337
392
  expect(createFile).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
338
393
  expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, { edit: true });
@@ -343,7 +398,7 @@ describe('GetStartedColumn: what a member sees', () => {
343
398
  // Any page would already tick the step and hide the button, so what holds
344
399
  // the name here is an (otherwise empty) folder called `Untitled.md` and
345
400
  // `Untitled 2.md` — a name the tree has is taken, whatever it is.
346
- mount({
401
+ await mount({
347
402
  createFile,
348
403
  files: [
349
404
  ...STARTER_TREE,
@@ -367,7 +422,7 @@ describe('GetStartedColumn: what a member sees', () => {
367
422
  const createFile = vi.fn(async (path: string) => {
368
423
  if (taken.has(path)) throw new WorkspaceApiError(409, `"${path}" already exists.`);
369
424
  });
370
- mount({ createFile });
425
+ await mount({ createFile });
371
426
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
372
427
  await waitFor(() =>
373
428
  expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled 3.md`, { edit: true }),
@@ -384,7 +439,7 @@ describe('GetStartedColumn: what a member sees', () => {
384
439
  const createFile = vi.fn(async (path: string) => {
385
440
  throw new WorkspaceApiError(409, `"${path}" already exists.`);
386
441
  });
387
- mount({ createFile });
442
+ await mount({ createFile });
388
443
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
389
444
  expect(await within(row('Write your first page')!).findByRole('alert')).toHaveTextContent(
390
445
  `Couldn’t create the page: "${KB}/KnowledgeBase/Untitled 5.md" already exists.`,
@@ -398,7 +453,7 @@ describe('GetStartedColumn: what a member sees', () => {
398
453
  // that gap would land on the old branch and open on the new one, nowhere.
399
454
  it('"New page" creates nothing while the workspace on screen is not the branch the URL names', async () => {
400
455
  const createFile = vi.fn(async () => {});
401
- mount({ createFile, route: '/workspace/alice%2Fdraft' });
456
+ await mount({ createFile, route: '/workspace/alice%2Fdraft' });
402
457
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
403
458
  expect(await within(row('Write your first page')!).findByRole('alert')).toHaveTextContent(
404
459
  'Couldn’t create the page: the workspace is still loading.',
@@ -407,16 +462,31 @@ describe('GetStartedColumn: what a member sees', () => {
407
462
  expect(openWorkspacePathMock).not.toHaveBeenCalled();
408
463
  });
409
464
 
410
- it('"New page" does not retry a refusal that is not about the name', async () => {
465
+ // A protected branch's gate refuses with 403 too; the fresh access check
466
+ // still says the folder may be written, so the refusal is said as it was.
467
+ it('"New page" goes quietly when a refusal is not about the folder: the check still says it may be written', async () => {
411
468
  const createFile = vi.fn(async () => {
412
- throw new WorkspaceApiError(403, 'You don’t have permission to write to "KnowledgeBase/Untitled.md".');
469
+ throw new WorkspaceApiError(403, 'Branch "main" is protected — writing is not allowed.');
413
470
  });
414
- mount({ createFile });
471
+ const { rerender } = await mount({ createFile });
415
472
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
416
- expect(await within(row('Write your first page')!).findByRole('alert')).toHaveTextContent(
417
- 'You don’t have permission',
418
- );
473
+ await waitFor(() => expect(row('Write your first page')).toBeNull());
419
474
  expect(createFile).toHaveBeenCalledTimes(1);
475
+ expect(access.batch).toHaveBeenCalledTimes(2);
476
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
477
+ expect(screen.queryByText(/protected|not allowed|permission|Eligible/)).not.toBeInTheDocument();
478
+ // It stays gone through a later tree change on the same branch.
479
+ // A folder, not a page: a page would tick the step and hide it on its own.
480
+ const later = [...STARTER_TREE, `${KB}/KnowledgeBase/Notes/.gitkeep`];
481
+ rerender(columnUi({ createFile, files: later }));
482
+ await settleRecheck();
483
+ expect(row('Write your first page')).toBeNull();
484
+ // A switch away and back lifts it: the branch is asked about afresh.
485
+ rerender(columnUi({ createFile, files: later, workspaceBranch: 'alice/draft' }));
486
+ await settle();
487
+ rerender(columnUi({ createFile, files: later }));
488
+ await settle();
489
+ expect(row('Write your first page')).not.toBeNull();
420
490
  });
421
491
 
422
492
  it('"New page" says "Creating…" while it works, and says why it failed on the step', async () => {
@@ -427,15 +497,15 @@ describe('GetStartedColumn: what a member sees', () => {
427
497
  refuse = reject;
428
498
  }),
429
499
  );
430
- mount({ createFile });
500
+ await mount({ createFile });
431
501
  await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
432
502
  expect(within(row('Write your first page')!).getByRole('button', { name: 'Creating…' })).toBeDisabled();
433
503
 
434
504
  await act(async () => {
435
- refuse(new Error('You don’t have permission to write to "KnowledgeBase/Untitled.md".'));
505
+ refuse(new Error('The server did not answer.'));
436
506
  });
437
507
  expect(within(row('Write your first page')!).getByRole('alert')).toHaveTextContent(
438
- 'Couldn’t create the page: You don’t have permission to write to "KnowledgeBase/Untitled.md".',
508
+ 'Couldn’t create the page: The server did not answer.',
439
509
  );
440
510
  expect(within(row('Write your first page')!).getByRole('button', { name: 'New page' })).toBeEnabled();
441
511
  expect(openWorkspacePathMock).not.toHaveBeenCalled();
@@ -443,6 +513,390 @@ describe('GetStartedColumn: what a member sees', () => {
443
513
  });
444
514
  });
445
515
 
516
+ /**
517
+ * New page writes where the person may write: the top of Knowledge when they
518
+ * may (admins), else the folder of the page on screen, else the first folder
519
+ * they may write in file tree order — and someone who may write nowhere is
520
+ * not shown the step at all.
521
+ */
522
+ describe('GetStartedColumn: where New page writes', () => {
523
+ const SALES = `${KB}/KnowledgeBase/Sales`;
524
+ const SUPPORT = `${KB}/KnowledgeBase/Support`;
525
+ const PRODUCT = `${KB}/KnowledgeBase/Product`;
526
+ const FOLDERS_TREE = [
527
+ ...STARTER_TREE,
528
+ `${PRODUCT}/.gitkeep`,
529
+ `${SALES}/.gitkeep`,
530
+ `${SALES}/Team/.gitkeep`,
531
+ `${SUPPORT}/.gitkeep`,
532
+ ];
533
+ const STEP = 'Write your first page';
534
+ const newPage = () => within(row(STEP)!).getByRole('button', { name: 'New page' });
535
+
536
+ it('leaves the step out for someone who may write no Knowledge folder, and counts without it', async () => {
537
+ access.writable = new Set();
538
+ await mount({ files: FOLDERS_TREE });
539
+ expect(row(STEP)).toBeNull();
540
+ // Workspace, agent, guide, command menu: one fewer than with the step.
541
+ expect(screen.getByText('1 of 4')).toBeInTheDocument();
542
+ expect(row('Connect your agent')).not.toBeNull();
543
+ });
544
+
545
+ it('completes the list without the step', async () => {
546
+ access.writable = new Set();
547
+ window.localStorage.setItem('bevel.onboarding.commandMenuOpened.juan@bevel.software', '1');
548
+ await mount({ onboardingDone: true, openFilePath: GUIDE });
549
+ expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
550
+ });
551
+
552
+ it('shows nothing until it knows, so the step never appears and then vanishes', async () => {
553
+ let answer!: (a: { results: Record<string, boolean> }) => void;
554
+ access.batch.mockImplementation(() => new Promise((resolve) => (answer = resolve)));
555
+ const seen: boolean[] = [];
556
+ const observer = new MutationObserver(() => seen.push(screen.queryByText(STEP) !== null));
557
+ observer.observe(document.body, { childList: true, subtree: true });
558
+ await mount({ files: FOLDERS_TREE });
559
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
560
+ await act(async () => answer({ results: {} }));
561
+ await settle();
562
+ observer.disconnect();
563
+ expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
564
+ expect(row(STEP)).toBeNull();
565
+ expect(seen).not.toContain(true);
566
+ });
567
+
568
+ it('hides the step while the check fails, for an admin too', async () => {
569
+ access.batch.mockRejectedValue(new Error('HTTP 500'));
570
+ await mount({ admin: true });
571
+ await screen.findByRole('complementary', { name: 'Get set up' });
572
+ expect(row(STEP)).toBeNull();
573
+ });
574
+
575
+ it('creates the page at the top of Knowledge for an admin, even with a page open in another folder they may write', async () => {
576
+ access.writable = new Set(['KnowledgeBase', 'KnowledgeBase/Support']);
577
+ const createFile = vi.fn(async () => {});
578
+ await mount({ admin: true, createFile, files: FOLDERS_TREE, openFilePath: `${SUPPORT}/FAQ.md` });
579
+ await userEvent.click(newPage());
580
+ expect(createFile).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
581
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, { edit: true });
582
+ });
583
+
584
+ it('otherwise uses the first folder they may write, in file tree order', async () => {
585
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
586
+ const createFile = vi.fn(async () => {});
587
+ await mount({ createFile, files: FOLDERS_TREE });
588
+ // The step reads as today, wording and all.
589
+ expect(within(row(STEP)!).getByText('Start one here, or drop files into the file tree.')).toBeInTheDocument();
590
+ expect(within(row(STEP)!).getByText('Connect your agent and it can write pages for you.')).toBeInTheDocument();
591
+ await userEvent.click(newPage());
592
+ expect(createFile).toHaveBeenCalledWith(`${SALES}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
593
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${SALES}/Untitled.md`, { edit: true });
594
+ // One question for the lot: the top, then every folder in tree order.
595
+ expect(access.batch.mock.calls[0]![1]).toEqual([
596
+ 'KnowledgeBase',
597
+ 'KnowledgeBase/Product',
598
+ 'KnowledgeBase/Sales',
599
+ 'KnowledgeBase/Sales/Team',
600
+ 'KnowledgeBase/Support',
601
+ ]);
602
+ });
603
+
604
+ it('prefers the folder of the page on screen when they may write it', async () => {
605
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
606
+ const createFile = vi.fn(async () => {});
607
+ await mount({ createFile, files: FOLDERS_TREE, openFilePath: `${SUPPORT}/FAQ.md` });
608
+ await userEvent.click(newPage());
609
+ expect(createFile).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
610
+ });
611
+
612
+ it('passes over the folder on screen when they may not write it', async () => {
613
+ access.writable = new Set(['KnowledgeBase/Support']);
614
+ const createFile = vi.fn(async () => {});
615
+ await mount({ createFile, files: FOLDERS_TREE, openFilePath: `${PRODUCT}/Roadmap.md` });
616
+ await userEvent.click(newPage());
617
+ expect(createFile).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
618
+ });
619
+
620
+ it('finds a folder nested inside one they may only read', async () => {
621
+ access.writable = new Set(['KnowledgeBase/Sales/Team']);
622
+ const createFile = vi.fn(async () => {});
623
+ await mount({ createFile, files: FOLDERS_TREE });
624
+ await userEvent.click(newPage());
625
+ expect(createFile).toHaveBeenCalledWith(`${SALES}/Team/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
626
+ });
627
+
628
+ it('brings the step once a folder shared later shows in the tree, without a remount', async () => {
629
+ access.writable = new Set();
630
+ const { rerender } = await mount();
631
+ expect(row(STEP)).toBeNull();
632
+ // An admin shares Sales: the tree now shows it, and it may be written.
633
+ access.writable = new Set(['KnowledgeBase/Sales']);
634
+ rerender(columnUi({ files: [...STARTER_TREE, `${SALES}/.gitkeep`] }));
635
+ await settleRecheck();
636
+ expect(row(STEP)).not.toBeNull();
637
+ expect(screen.getByText('1 of 5')).toBeInTheDocument();
638
+ });
639
+
640
+ it('shows the step with the list for someone who may write only a folder below, asking once the tree is in', async () => {
641
+ access.writable = new Set(['KnowledgeBase/Sales/Team']);
642
+ const { rerender } = await mount({ files: null });
643
+ expect(access.batch).not.toHaveBeenCalled();
644
+ rerender(columnUi({ files: FOLDERS_TREE }));
645
+ // No debounce to wait out: the first answer for this workspace is asked at once.
646
+ await settle();
647
+ expect(row(STEP)).not.toBeNull();
648
+ expect(access.batch).toHaveBeenCalledTimes(1);
649
+ expect(access.batch.mock.calls[0]![1]).toContain('KnowledgeBase/Sales/Team');
650
+ });
651
+
652
+ it('asks again before writing when the page on screen changed since the last answer', async () => {
653
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
654
+ const createFile = vi.fn(async () => {});
655
+ const { rerender } = await mount({ createFile, files: FOLDERS_TREE, openFilePath: `${SALES}/Leads.md` });
656
+ // Straight to Support and New page, inside the debounce: the answer on hand is Sales's.
657
+ rerender(columnUi({ createFile, files: FOLDERS_TREE, openFilePath: `${SUPPORT}/FAQ.md` }));
658
+ await userEvent.click(newPage());
659
+ await waitFor(() => expect(createFile).toHaveBeenCalled());
660
+ expect(createFile).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
661
+ expect(createFile).toHaveBeenCalledTimes(1);
662
+ });
663
+
664
+ it('asks again before writing after a switch of branch, not writing where the last branch allowed', async () => {
665
+ access.writable = new Set(['KnowledgeBase/Sales']);
666
+ const createFile = vi.fn(async () => {});
667
+ const { rerender } = await mount({ createFile, files: FOLDERS_TREE });
668
+ access.writable = new Set(['KnowledgeBase/Support']);
669
+ // Every answer for the new branch — the switch's own check and the one
670
+ // New page asks before writing — is held until the test lets it through.
671
+ let release!: () => void;
672
+ const gate = new Promise<void>((resolve) => (release = resolve));
673
+ const real = access.batch.getMockImplementation()!;
674
+ access.batch.mockImplementation(async (ws, paths, verb) => {
675
+ await gate;
676
+ return real(ws, paths, verb);
677
+ });
678
+ // The other protected branch: a draft asks about reading instead.
679
+ rerender(columnUi({ createFile, files: FOLDERS_TREE, workspaceBranch: 'current-company-state' }));
680
+ await userEvent.click(newPage());
681
+ await settle();
682
+ // The answer on hand still says Sales, but it was for the other branch: nothing is written yet.
683
+ expect(createFile).not.toHaveBeenCalled();
684
+ await act(async () => release());
685
+ await waitFor(() => expect(createFile).toHaveBeenCalled());
686
+ expect(createFile).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
687
+ expect(createFile).toHaveBeenCalledTimes(1);
688
+ });
689
+
690
+ it('on a draft branch writes at the top of Knowledge for anyone who can read it, asking no write check', async () => {
691
+ // Writes nothing on the protected branches — but a draft takes any
692
+ // reader's write, as the server's read-before-write gate does.
693
+ access.writable = new Set();
694
+ const createFile = vi.fn(async () => {});
695
+ await mount({ createFile, files: FOLDERS_TREE, workspaceBranch: 'alice/draft' });
696
+ await userEvent.click(newPage());
697
+ expect(createFile).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
698
+ expect(access.batch.mock.calls[0]![1]).toContain('KnowledgeBase');
699
+ expect(accessVerbsAsked()).toEqual(new Set(['read']));
700
+ });
701
+
702
+ // Local Testing at db782b2f: the tree shows Knowledge because Product is
703
+ // shared with John, yet the top itself is not readable, and the server
704
+ // refused KnowledgeBase/Untitled.md ("You don't have read access").
705
+ it('on a draft branch passes over a top of Knowledge shown only for a folder inside it', async () => {
706
+ access.writable = new Set();
707
+ access.readable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
708
+ const createFile = vi.fn(async () => {});
709
+ await mount({ createFile, files: FOLDERS_TREE, workspaceBranch: 'alice/draft' });
710
+ await userEvent.click(newPage());
711
+ expect(createFile).toHaveBeenCalledWith(`${SALES}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
712
+ expect(createFile).toHaveBeenCalledTimes(1);
713
+ expect(accessVerbsAsked()).toEqual(new Set(['read']));
714
+ });
715
+
716
+ it('on a draft branch prefers the folder of the page on screen when they may read it', async () => {
717
+ access.readable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
718
+ const createFile = vi.fn(async () => {});
719
+ await mount({ createFile, files: FOLDERS_TREE, workspaceBranch: 'alice/draft', openFilePath: `${SUPPORT}/FAQ.md` });
720
+ await userEvent.click(newPage());
721
+ expect(createFile).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
722
+ });
723
+
724
+ // Mia at db782b2f: shown the step on a draft where she reads nothing in
725
+ // Knowledge; a click was refused and the step vanished.
726
+ it('on a draft branch leaves the step out for someone who may read no Knowledge folder', async () => {
727
+ access.readable = new Set();
728
+ await mount({ files: FOLDERS_TREE, workspaceBranch: 'alice/draft' });
729
+ await screen.findByRole('complementary', { name: 'Get set up' });
730
+ expect(row(STEP)).toBeNull();
731
+ expect(screen.getByText('1 of 4')).toBeInTheDocument();
732
+ });
733
+
734
+ it('on a draft branch offers nothing when the tree shows no Knowledge folder, asking nothing', async () => {
735
+ await mount({ files: [`${KB}/Skills/.gitkeep`], workspaceBranch: 'alice/draft' });
736
+ await screen.findByRole('complementary', { name: 'Get set up' });
737
+ expect(row(STEP)).toBeNull();
738
+ expect(access.batch).not.toHaveBeenCalled();
739
+ });
740
+
741
+ it('a refusal whose recheck answers after a switch of branch withdraws nothing there or back', async () => {
742
+ access.writable = new Set(['KnowledgeBase/Sales']);
743
+ let release!: () => void;
744
+ let held = false;
745
+ const gate = new Promise<void>((resolve) => (release = resolve));
746
+ const real = access.batch.getMockImplementation()!;
747
+ access.batch.mockImplementation(async (ws, paths, verb) => {
748
+ if (held) await gate;
749
+ return real(ws, paths, verb);
750
+ });
751
+ const createFile = vi.fn(async (path: string) => {
752
+ // Refused although the check keeps saying Sales may be written; the
753
+ // check that would withdraw New page is held past a switch.
754
+ held = true;
755
+ throw new WorkspaceApiError(403, `You don't have permission to write to "${path}". Eligible: Admin.`);
756
+ });
757
+ const { rerender } = await mount({ createFile, files: FOLDERS_TREE });
758
+ await userEvent.click(newPage());
759
+ await settle();
760
+ rerender(columnUi({ createFile, files: FOLDERS_TREE, workspaceBranch: 'current-company-state' }));
761
+ await act(async () => release());
762
+ await settle();
763
+ // The withdrawal was for the branch left behind: the one on screen keeps New page…
764
+ expect(row(STEP)).not.toBeNull();
765
+ // …and so does the branch it was for, once the person comes back.
766
+ rerender(columnUi({ createFile, files: FOLDERS_TREE }));
767
+ await settle();
768
+ expect(row(STEP)).not.toBeNull();
769
+ expect(screen.queryByText(/Eligible|permission/)).not.toBeInTheDocument();
770
+ });
771
+
772
+ it('a refused write asks again and moves to the next folder they may write, with no permission text', async () => {
773
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
774
+ const createFile = vi.fn(async (path: string) => {
775
+ if (path.startsWith(`${SALES}/`)) {
776
+ // Sales was taken away since the check.
777
+ access.writable = new Set(['KnowledgeBase/Support']);
778
+ throw new WorkspaceApiError(
779
+ 403,
780
+ 'You don\'t have permission to write to "KnowledgeBase/Sales/Untitled.md". Eligible: Admin.',
781
+ );
782
+ }
783
+ });
784
+ await mount({ createFile, files: FOLDERS_TREE });
785
+ await userEvent.click(newPage());
786
+ await waitFor(() =>
787
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, { edit: true }),
788
+ );
789
+ expect(createFile.mock.calls.map((c) => c[0])).toEqual([`${SALES}/Untitled.md`, `${SUPPORT}/Untitled.md`]);
790
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
791
+ expect(screen.queryByText(/Eligible|permission/)).not.toBeInTheDocument();
792
+ });
793
+
794
+ it('a refused write with nowhere left removes the step, with no permission text', async () => {
795
+ access.writable = new Set(['KnowledgeBase/Sales']);
796
+ const createFile = vi.fn(async () => {
797
+ access.writable = new Set();
798
+ throw new WorkspaceApiError(
799
+ 403,
800
+ 'You don\'t have permission to write to "KnowledgeBase/Sales/Untitled.md". Eligible: Admin.',
801
+ );
802
+ });
803
+ await mount({ createFile, files: FOLDERS_TREE });
804
+ await userEvent.click(newPage());
805
+ await waitFor(() => expect(row(STEP)).toBeNull());
806
+ expect(createFile).toHaveBeenCalledTimes(1);
807
+ expect(openWorkspacePathMock).not.toHaveBeenCalled();
808
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
809
+ expect(screen.queryByText(/Eligible|permission/)).not.toBeInTheDocument();
810
+ });
811
+
812
+ it('a fallback write refused too asks again once more and moves on, with no permission text', async () => {
813
+ access.writable = new Set(['KnowledgeBase/Product', 'KnowledgeBase/Sales', 'KnowledgeBase/Support']);
814
+ const refuse = (path: string) =>
815
+ new WorkspaceApiError(403, `You don't have permission to write to "${path}". Eligible: Admin.`);
816
+ const createFile = vi.fn(async (path: string) => {
817
+ // Product, then Sales, are taken away between the check and the write.
818
+ if (path.startsWith(`${PRODUCT}/`)) {
819
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
820
+ throw refuse(path);
821
+ }
822
+ if (path.startsWith(`${SALES}/`)) {
823
+ access.writable = new Set(['KnowledgeBase/Support']);
824
+ throw refuse(path);
825
+ }
826
+ });
827
+ await mount({ createFile, files: FOLDERS_TREE });
828
+ await userEvent.click(newPage());
829
+ await waitFor(() =>
830
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${SUPPORT}/Untitled.md`, { edit: true }),
831
+ );
832
+ expect(createFile.mock.calls.map((c) => c[0])).toEqual([
833
+ `${PRODUCT}/Untitled.md`,
834
+ `${SALES}/Untitled.md`,
835
+ `${SUPPORT}/Untitled.md`,
836
+ ]);
837
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
838
+ expect(screen.queryByText(/Eligible|permission/)).not.toBeInTheDocument();
839
+ });
840
+
841
+ it('a fallback write refused where the check still allows it removes the step, with no permission text', async () => {
842
+ access.writable = new Set(['KnowledgeBase/Sales', 'KnowledgeBase/Support']);
843
+ const createFile = vi.fn(async (path: string) => {
844
+ if (path.startsWith(`${SALES}/`)) access.writable = new Set(['KnowledgeBase/Support']);
845
+ // Support is refused although the check keeps saying it may be written.
846
+ throw new WorkspaceApiError(403, `You don't have permission to write to "${path}". Eligible: Admin.`);
847
+ });
848
+ await mount({ createFile, files: FOLDERS_TREE });
849
+ await userEvent.click(newPage());
850
+ await waitFor(() => expect(row(STEP)).toBeNull());
851
+ expect(createFile.mock.calls.map((c) => c[0])).toEqual([`${SALES}/Untitled.md`, `${SUPPORT}/Untitled.md`]);
852
+ expect(openWorkspacePathMock).not.toHaveBeenCalled();
853
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
854
+ expect(screen.queryByText(/Eligible|permission/)).not.toBeInTheDocument();
855
+ });
856
+
857
+ it('names the folder in the agent’s request when the page goes below the top of Knowledge', async () => {
858
+ access.writable = new Set(['KnowledgeBase/Sales']);
859
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
860
+ await mount({ files: FOLDERS_TREE });
861
+ const ask = await within(row(STEP)!).findByRole('link', { name: 'Ask Claude to write it' });
862
+ const inSales = FIRST_PAGE_PROMPT.replace('write a page in Knowledge', 'write a page in Knowledge/Sales');
863
+ expect(inSales).toContain('write a page in Knowledge/Sales about our company');
864
+ expect(ask).toHaveAttribute('href', claudePromptUrl(inSales));
865
+ });
866
+
867
+ it('leaves an admin’s request as it was', async () => {
868
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
869
+ await mount({ admin: true, files: FOLDERS_TREE });
870
+ const ask = await within(row(STEP)!).findByRole('link', { name: 'Ask Claude to write it' });
871
+ expect(ask).toHaveAttribute('href', claudePromptUrl(FIRST_PAGE_PROMPT));
872
+ });
873
+
874
+ it('offers no New page in the command menu, and C does nothing, when there is nowhere to write', async () => {
875
+ access.writable = new Set();
876
+ const createFile = vi.fn(async () => {});
877
+ const user = userEvent.setup();
878
+ const { rerender } = await mount({ withPalette: true, createFile, files: STARTER_TREE });
879
+ await user.keyboard('c');
880
+ expect(createFile).not.toHaveBeenCalled();
881
+ await user.keyboard('{Control>}k{/Control}');
882
+ expect(screen.queryByRole('option', { name: /^New page/ })).not.toBeInTheDocument();
883
+ expect(screen.getByRole('option', { name: 'Connect your agent' })).toBeInTheDocument();
884
+ await user.keyboard('{Escape}');
885
+
886
+ // A folder shared later brings the command, and its key, too.
887
+ access.writable = new Set(['KnowledgeBase/Sales']);
888
+ rerender(columnUi({ withPalette: true, createFile, files: [...STARTER_TREE, `${SALES}/.gitkeep`] }));
889
+ await settleRecheck();
890
+ await user.keyboard('{Control>}k{/Control}');
891
+ expect(screen.getByRole('option', { name: /^New page/ })).toBeInTheDocument();
892
+ await user.keyboard('{Escape}');
893
+ await user.keyboard('c');
894
+ await waitFor(() =>
895
+ expect(createFile).toHaveBeenCalledWith(`${SALES}/Untitled.md`, '# Untitled\n\n', { ifAbsent: true }),
896
+ );
897
+ });
898
+ });
899
+
446
900
  /**
447
901
  * The agent-connection answer, asked once: it ticks "Connect your agent" for
448
902
  * someone who connected without ever opening the welcome page (and concludes
@@ -452,7 +906,7 @@ describe('GetStartedColumn: what a member sees', () => {
452
906
  describe('GetStartedColumn: a connected agent', () => {
453
907
  it('ticks "Connect your agent" from the endpoint, and concludes the onboarding once', async () => {
454
908
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
455
- mount();
909
+ await mount();
456
910
  await waitFor(() => expect(isDone('Connect your agent')).toBe(true));
457
911
  expect(doneWrites()).toBe(1);
458
912
  await act(async () => {});
@@ -462,7 +916,7 @@ describe('GetStartedColumn: a connected agent', () => {
462
916
  it('asks once, not on a timer', async () => {
463
917
  vi.useFakeTimers();
464
918
  try {
465
- mount();
919
+ await mount();
466
920
  await act(async () => {
467
921
  await vi.advanceTimersByTimeAsync(30_000);
468
922
  });
@@ -482,7 +936,7 @@ describe('GetStartedColumn: a connected agent', () => {
482
936
  it('asks again when you come back to the tab, at most once in a while', async () => {
483
937
  vi.useFakeTimers();
484
938
  try {
485
- mount();
939
+ await mount();
486
940
  await act(async () => {
487
941
  await vi.advanceTimersByTimeAsync(0);
488
942
  });
@@ -511,7 +965,7 @@ describe('GetStartedColumn: a connected agent', () => {
511
965
 
512
966
  it('does not conclude again for an account the server already concluded', async () => {
513
967
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
514
- mount({ onboardingDone: true });
968
+ await mount({ onboardingDone: true });
515
969
  await waitFor(() => expect(row('Write your first page')).not.toBeNull());
516
970
  await act(async () => {});
517
971
  expect(doneWrites()).toBe(0);
@@ -519,13 +973,13 @@ describe('GetStartedColumn: a connected agent', () => {
519
973
 
520
974
  it('asks nothing once the column was closed', async () => {
521
975
  window.localStorage.setItem('bevel.onboarding.setupDismissed.juan@bevel.software', '1');
522
- mount();
976
+ await mount();
523
977
  await act(async () => {});
524
978
  expect(fetchAgentConnectionMock).not.toHaveBeenCalled();
525
979
  });
526
980
 
527
981
  it('keeps the one-click prompt out of "Write your first page" until an agent is connected', async () => {
528
- mount();
982
+ await mount();
529
983
  await act(async () => {});
530
984
  const page = row('Write your first page')!;
531
985
  expect(within(page).queryByRole('link', { name: 'Ask Claude to write it' })).not.toBeInTheDocument();
@@ -537,7 +991,7 @@ describe('GetStartedColumn: a connected agent', () => {
537
991
 
538
992
  it('offers "Ask Claude to write it" first once connected, keeping New page beside it', async () => {
539
993
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
540
- mount();
994
+ await mount();
541
995
  const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask Claude to write it' });
542
996
  expect(ask).toHaveAttribute('href', claudePromptUrl(FIRST_PAGE_PROMPT));
543
997
  expect(ask).toHaveAttribute('target', '_blank');
@@ -570,7 +1024,7 @@ describe('GetStartedColumn: a connected agent', () => {
570
1024
  it("asks the agent with the pack's prompt", async () => {
571
1025
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
572
1026
  fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
573
- mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
1027
+ await mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
574
1028
  const page = row('Write your first page')!;
575
1029
  await waitFor(() =>
576
1030
  expect(within(page).getByRole('link', { name: 'Ask Claude to write it' })).toHaveAttribute(
@@ -587,7 +1041,7 @@ describe('GetStartedColumn: a connected agent', () => {
587
1041
  it("leaves the step open while the pack's pages are untouched, and ticks it once one is filled in", async () => {
588
1042
  fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
589
1043
  const files = [...STARTER_TREE, ...SALES_PAGES];
590
- const { rerender } = mount({ files });
1044
+ const { rerender } = await mount({ files });
591
1045
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalledTimes(1));
592
1046
  expect(isDone('Write your first page')).toBe(false);
593
1047
 
@@ -602,7 +1056,7 @@ describe('GetStartedColumn: a connected agent', () => {
602
1056
  it('keeps the generic prompt when the team skipped', async () => {
603
1057
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
604
1058
  fetchStarterPacksMock.mockResolvedValue({ offered: false, chosen: 'none', packs: [], chosenPack: null });
605
- mount();
1059
+ await mount();
606
1060
  const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask Claude to write it' });
607
1061
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
608
1062
  expect(ask).toHaveAttribute('href', claudePromptUrl(FIRST_PAGE_PROMPT));
@@ -611,7 +1065,7 @@ describe('GetStartedColumn: a connected agent', () => {
611
1065
  it('does not tick the step before the answer is in: untouched pack pages are not a first page', async () => {
612
1066
  let answer!: (a: StarterPacksAnswer) => void;
613
1067
  fetchStarterPacksMock.mockImplementation(() => new Promise((resolve) => (answer = resolve)));
614
- mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
1068
+ await mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
615
1069
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
616
1070
  expect(isDone('Write your first page')).toBe(false);
617
1071
  answer(chosen(SALES_PAGES));
@@ -622,7 +1076,7 @@ describe('GetStartedColumn: a connected agent', () => {
622
1076
 
623
1077
  it('reads the tree alone on a draft branch, where the default branch’s placeholders do not apply', async () => {
624
1078
  fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
625
- mount({ files: [...STARTER_TREE, ...SALES_PAGES], workspaceBranch: 'alice/draft' });
1079
+ await mount({ files: [...STARTER_TREE, ...SALES_PAGES], workspaceBranch: 'alice/draft' });
626
1080
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
627
1081
  await waitFor(() => expect(isDone('Write your first page')).toBe(true));
628
1082
  });
@@ -631,7 +1085,7 @@ describe('GetStartedColumn: a connected agent', () => {
631
1085
  const resolvers: ((a: StarterPacksAnswer) => void)[] = [];
632
1086
  fetchStarterPacksMock.mockImplementation(() => new Promise((resolve) => resolvers.push(resolve)));
633
1087
  const files = [...STARTER_TREE, ...SALES_PAGES];
634
- const { rerender } = mount({ files });
1088
+ const { rerender } = await mount({ files });
635
1089
  await waitFor(() => expect(resolvers).toHaveLength(1));
636
1090
  resolvers[0]!(chosen(SALES_PAGES));
637
1091
  await waitFor(() => expect(isDone('Write your first page')).toBe(false));
@@ -651,7 +1105,7 @@ describe('GetStartedColumn: a connected agent', () => {
651
1105
 
652
1106
  it('leads with "Ask ChatGPT to write it" for a ChatGPT connection, Claude quiet beside Copy prompt', async () => {
653
1107
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'ChatGPT', kind: 'agent' });
654
- mount();
1108
+ await mount();
655
1109
  const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask ChatGPT to write it' });
656
1110
  expect(ask).toHaveAttribute('href', chatGptPromptUrl(FIRST_PAGE_PROMPT));
657
1111
  const page = row('Write your first page')!;
@@ -670,7 +1124,7 @@ describe('GetStartedColumn: a connected agent', () => {
670
1124
  const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
671
1125
  Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
672
1126
  try {
673
- mount();
1127
+ await mount();
674
1128
  const copy = await within(row('Write your first page')!).findByRole('button', { name: 'Copy prompt' });
675
1129
  const page = row('Write your first page')!;
676
1130
  expect(within(page).getByText('Paste it into Claude Code.')).toBeInTheDocument();
@@ -691,7 +1145,7 @@ describe('GetStartedColumn: a connected agent', () => {
691
1145
  // A key's label is free text: "ChatGPT CLI" names the key, not an app
692
1146
  // that a chatgpt.com link would reach.
693
1147
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'ChatGPT CLI', kind: 'key' });
694
- mount();
1148
+ await mount();
695
1149
  const page = await waitFor(() => {
696
1150
  const r = row('Write your first page')!;
697
1151
  within(r).getByRole('button', { name: 'Copy prompt' });
@@ -703,7 +1157,7 @@ describe('GetStartedColumn: a connected agent', () => {
703
1157
 
704
1158
  it('says "your agent" when the connection has no name to offer', async () => {
705
1159
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Unnamed agent', kind: 'agent' });
706
- mount();
1160
+ await mount();
707
1161
  expect(await within(row('Write your first page')!).findByText('Paste it into your agent.')).toBeInTheDocument();
708
1162
  });
709
1163
 
@@ -713,7 +1167,7 @@ describe('GetStartedColumn: a connected agent', () => {
713
1167
  const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
714
1168
  Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
715
1169
  try {
716
- mount();
1170
+ await mount();
717
1171
  const copy = await within(row('Write your first page')!).findByRole('button', { name: 'Copy prompt' });
718
1172
  await userEvent.click(copy);
719
1173
  expect(writeText).toHaveBeenCalledWith(FIRST_PAGE_PROMPT);
@@ -726,7 +1180,7 @@ describe('GetStartedColumn: a connected agent', () => {
726
1180
 
727
1181
  it('ticks the page step by itself when the agent’s page lands, whoever wrote it', async () => {
728
1182
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
729
- mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/About us.md`] });
1183
+ await mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/About us.md`] });
730
1184
  await waitFor(() => expect(isDone('Connect your agent')).toBe(true));
731
1185
  expect(isDone('Write your first page')).toBe(true);
732
1186
  expect(screen.queryByRole('link', { name: 'Ask Claude to write it' })).not.toBeInTheDocument();
@@ -735,7 +1189,7 @@ describe('GetStartedColumn: a connected agent', () => {
735
1189
 
736
1190
  describe('GetStartedColumn: what an admin sees', () => {
737
1191
  it('lists all eight steps, storage already done', async () => {
738
- mount({ admin: true });
1192
+ await mount({ admin: true });
739
1193
  await screen.findByRole('complementary', { name: 'Get set up' });
740
1194
  expect(screen.getByText('2 of 8')).toBeInTheDocument();
741
1195
  expect(isDone('Choose where your knowledge lives')).toBe(true);
@@ -745,13 +1199,13 @@ describe('GetStartedColumn: what an admin sees', () => {
745
1199
 
746
1200
  it('ticks the plugin step for a team plugin, not a personal shelf', async () => {
747
1201
  listPluginsMock.mockResolvedValue([plugin('Plugins/personal-juan')]);
748
- const { unmount } = mount({ admin: true });
1202
+ const { unmount } = await mount({ admin: true });
749
1203
  await screen.findByRole('complementary', { name: 'Get set up' });
750
1204
  expect(isDone('Create a plugin for your team')).toBe(false);
751
1205
  unmount();
752
1206
 
753
1207
  listPluginsMock.mockResolvedValue([plugin('Plugins/GTM')]);
754
- mount({ admin: true });
1208
+ await mount({ admin: true });
755
1209
  await waitFor(() => expect(isDone('Create a plugin for your team')).toBe(true));
756
1210
  });
757
1211
 
@@ -760,13 +1214,13 @@ describe('GetStartedColumn: what an admin sees', () => {
760
1214
  account('juan@bevel.software'),
761
1215
  account('recovery-bot@bevel.local', { isSystem: true }),
762
1216
  ]);
763
- const { unmount } = mount({ admin: true });
1217
+ const { unmount } = await mount({ admin: true });
764
1218
  await screen.findByRole('complementary', { name: 'Get set up' });
765
1219
  expect(isDone('Invite your team')).toBe(false);
766
1220
  unmount();
767
1221
 
768
1222
  listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('ana@bevel.software')]);
769
- mount({ admin: true });
1223
+ await mount({ admin: true });
770
1224
  await waitFor(() => expect(isDone('Invite your team')).toBe(true));
771
1225
  });
772
1226
 
@@ -775,7 +1229,7 @@ describe('GetStartedColumn: what an admin sees', () => {
775
1229
  account('juan@bevel.software'),
776
1230
  account('ana@bevel.software', { deactivatedAt: '2026-09-01T00:00:00Z' }),
777
1231
  ]);
778
- mount({ admin: true });
1232
+ await mount({ admin: true });
779
1233
  await screen.findByRole('complementary', { name: 'Get set up' });
780
1234
  expect(isDone('Invite your team')).toBe(false);
781
1235
  });
@@ -785,7 +1239,7 @@ describe('GetStartedColumn: what an admin sees', () => {
785
1239
  * creates a plugin — not on every move between Library pages.
786
1240
  */
787
1241
  it('asks for plugins again on entering Skills & Tools and on a plugin created, not on every Library page', async () => {
788
- mount({ admin: true });
1242
+ await mount({ admin: true });
789
1243
  await screen.findByRole('complementary', { name: 'Get set up' });
790
1244
  expect(listPluginsMock).toHaveBeenCalledTimes(1);
791
1245
 
@@ -807,7 +1261,7 @@ describe('GetStartedColumn: what an admin sees', () => {
807
1261
  });
808
1262
 
809
1263
  it('opens the invite dialog from the invite step', async () => {
810
- mount({ admin: true });
1264
+ await mount({ admin: true });
811
1265
  await screen.findByRole('complementary', { name: 'Get set up' });
812
1266
  await userEvent.click(within(row('Invite your team')!).getByRole('button', { name: 'Invite people' }));
813
1267
  expect(screen.getByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
@@ -835,7 +1289,7 @@ describe('GetStartedColumn: all done', () => {
835
1289
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
836
1290
  const everythingBut = { admin: true, onboardingDone: true, openFilePath: GUIDE };
837
1291
  // One step short, the settled column shows the seven it has...
838
- const { rerender } = mount(everythingBut);
1292
+ const { rerender } = await mount(everythingBut);
839
1293
  expect(await screen.findByText('7 of 8')).toBeInTheDocument();
840
1294
  expect(complete()).toBeNull();
841
1295
  // ...and the page landing in the tree finishes it.
@@ -851,7 +1305,7 @@ describe('GetStartedColumn: all done', () => {
851
1305
 
852
1306
  it('celebrates a list finished elsewhere on arrival, and does not mention a team to a member', async () => {
853
1307
  fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
854
- mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
1308
+ await mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
855
1309
  expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
856
1310
  expect(screen.getByText('Your agent can read and write your knowledge base.')).toBeInTheDocument();
857
1311
  expect(screen.queryByText(/your team/)).not.toBeInTheDocument();
@@ -862,21 +1316,21 @@ describe('GetStartedColumn: all done', () => {
862
1316
  * agent ever calling in (the pill's ×), so the line does not claim one.
863
1317
  */
864
1318
  it('claims no agent when none has connected', async () => {
865
- mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
1319
+ await mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
866
1320
  expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
867
1321
  expect(screen.getByText('Your knowledge base is ready.')).toBeInTheDocument();
868
1322
  expect(screen.queryByText(/Your agent can/)).not.toBeInTheDocument();
869
1323
  });
870
1324
 
871
1325
  it('Close retires the column for good, and remembers it per account', async () => {
872
- const { unmount } = mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
1326
+ const { unmount } = await mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
873
1327
  await userEvent.click(await screen.findByRole('button', { name: 'Close' }));
874
1328
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
875
1329
  expect(window.localStorage.getItem('bevel.onboarding.setupCompleteClosed.juan@bevel.software')).toBe('1');
876
1330
  unmount();
877
1331
  // Not shown again — not even if a step comes undone later.
878
1332
  fetchAgentConnectionMock.mockClear();
879
- mount({ onboardingDone: true, openFilePath: GUIDE });
1333
+ await mount({ onboardingDone: true, openFilePath: GUIDE });
880
1334
  await act(async () => {});
881
1335
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
882
1336
  expect(fetchAgentConnectionMock).not.toHaveBeenCalled();
@@ -891,7 +1345,7 @@ describe('GetStartedColumn: the command menu', () => {
891
1345
  const STEP = `Find or do anything with ${COMMAND_MENU_SHORTCUT_LABEL}`;
892
1346
 
893
1347
  it('is a step for everyone, named with this platform’s keys', async () => {
894
- mount();
1348
+ await mount();
895
1349
  expect(row(STEP)).not.toBeNull();
896
1350
  expect(isDone(STEP)).toBe(false);
897
1351
  expect(
@@ -901,7 +1355,7 @@ describe('GetStartedColumn: the command menu', () => {
901
1355
 
902
1356
  it('"Try it" opens the command menu, and that ticks the step', async () => {
903
1357
  const user = userEvent.setup();
904
- mount({ withPalette: true });
1358
+ await mount({ withPalette: true });
905
1359
  await user.click(within(row(STEP)!).getByRole('button', { name: 'Try it' }));
906
1360
  expect(screen.getByRole('combobox', { name: 'Search or run a command' })).toHaveFocus();
907
1361
  await user.keyboard('{Escape}');
@@ -910,13 +1364,13 @@ describe('GetStartedColumn: the command menu', () => {
910
1364
 
911
1365
  it('ticks when the menu is opened any other way, and remembers it per account', async () => {
912
1366
  const user = userEvent.setup();
913
- const { unmount } = mount({ withPalette: true });
1367
+ const { unmount } = await mount({ withPalette: true });
914
1368
  await user.keyboard('{Control>}k{/Control}');
915
1369
  expect(screen.getByRole('combobox', { name: 'Search or run a command' })).toBeInTheDocument();
916
1370
  expect(isDone(STEP)).toBe(true);
917
1371
  expect(window.localStorage.getItem('bevel.onboarding.commandMenuOpened.juan@bevel.software')).toBe('1');
918
1372
  unmount();
919
- mount();
1373
+ await mount();
920
1374
  expect(isDone(STEP)).toBe(true);
921
1375
  });
922
1376
  });
@@ -927,32 +1381,35 @@ describe('GetStartedColumn: the command menu', () => {
927
1381
  * than showing a shorter, falsely open one.
928
1382
  */
929
1383
  describe('GetStartedColumn: the file tree', () => {
930
- it('stays hidden until the tree has loaded', () => {
931
- const { rerender } = mount({ files: null });
1384
+ it('stays hidden until the tree has loaded', async () => {
1385
+ const { rerender } = await mount({ files: null });
932
1386
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
1387
+ // Nothing is asked about where a page may go before the tree says what is there.
1388
+ expect(access.batch).not.toHaveBeenCalled();
933
1389
  rerender(columnUi({}));
1390
+ await settle();
934
1391
  expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
935
1392
  expect(row('Read “How to get started”')).not.toBeNull();
936
1393
  });
937
1394
 
938
1395
  it('skips exactly `access.md`, the name the platform reserves — not another spelling', async () => {
939
- const { unmount } = mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Sales/access.md`] });
1396
+ const { unmount } = await mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Sales/access.md`] });
940
1397
  await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
941
1398
  expect(isDone('Write your first page')).toBe(false);
942
1399
  unmount();
943
- mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Sales/Access.md`] });
1400
+ await mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Sales/Access.md`] });
944
1401
  await waitFor(() => expect(isDone('Write your first page')).toBe(true));
945
1402
  });
946
1403
  });
947
1404
 
948
1405
  describe('GetStartedColumn: getting out of the way', () => {
949
1406
  it('stays dismissed once closed, across remounts', async () => {
950
- const { unmount } = mount();
1407
+ const { unmount } = await mount();
951
1408
  await userEvent.click(screen.getByRole('button', { name: 'Dismiss Get set up' }));
952
1409
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
953
1410
  expect(window.localStorage.getItem('bevel.onboarding.setupDismissed.juan@bevel.software')).toBe('1');
954
1411
  unmount();
955
- mount();
1412
+ await mount();
956
1413
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
957
1414
  });
958
1415
 
@@ -960,8 +1417,8 @@ describe('GetStartedColumn: getting out of the way', () => {
960
1417
  * The notes are per browser, so a tab already open hears another tab's
961
1418
  * close through `storage` — not at its next reload.
962
1419
  */
963
- it('goes when another tab closes it', () => {
964
- mount();
1420
+ it('goes when another tab closes it', async () => {
1421
+ await mount();
965
1422
  expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
966
1423
  const key = 'bevel.onboarding.setupDismissed.juan@bevel.software';
967
1424
  window.localStorage.setItem(key, '1');
@@ -971,8 +1428,8 @@ describe('GetStartedColumn: getting out of the way', () => {
971
1428
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
972
1429
  });
973
1430
 
974
- it('ticks the guide when another tab opened it', () => {
975
- mount();
1431
+ it('ticks the guide when another tab opened it', async () => {
1432
+ await mount();
976
1433
  expect(isDone('Read “How to get started”')).toBe(false);
977
1434
  const key = 'bevel.onboarding.readGuide.juan@bevel.software';
978
1435
  window.localStorage.setItem(key, '1');
@@ -982,20 +1439,20 @@ describe('GetStartedColumn: getting out of the way', () => {
982
1439
  expect(isDone('Read “How to get started”')).toBe(true);
983
1440
  });
984
1441
 
985
- it('is not shown on the welcome page', () => {
986
- mount({ route: WELCOME_PATH });
1442
+ it('is not shown on the welcome page', async () => {
1443
+ await mount({ route: WELCOME_PATH });
987
1444
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
988
1445
  });
989
1446
 
990
- it('is shown in an ordinary laptop window', () => {
1447
+ it('is shown in an ordinary laptop window', async () => {
991
1448
  setViewportWidth(1000);
992
- mount();
1449
+ await mount();
993
1450
  expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
994
1451
  });
995
1452
 
996
- it('is not shown at or below 900px, where the sidebar turns into a drawer', () => {
1453
+ it('is not shown at or below 900px, where the sidebar turns into a drawer', async () => {
997
1454
  setViewportWidth(900);
998
- mount();
1455
+ await mount();
999
1456
  expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
1000
1457
  });
1001
1458
  });