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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  5. package/src/core/__tests__/core-contributions.test.ts +16 -0
  6. package/src/core/core-contributions.ts +17 -0
  7. package/src/core/registry.ts +51 -1
  8. package/src/index.css +23 -5
  9. package/src/index.ts +5 -0
  10. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  11. package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
  12. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  13. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  14. package/src/modules/auth/components/LoginScreen.tsx +4 -1
  15. package/src/modules/auth/services/account.api.ts +28 -1
  16. package/src/modules/auth/services/sso.ts +1 -2
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  19. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  20. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  21. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  22. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  23. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  24. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  25. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  26. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  27. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  28. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  29. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  30. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  31. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  32. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  33. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  34. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  35. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  36. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  37. package/src/modules/embed/components/EmbedView.tsx +545 -0
  38. package/src/modules/embed/embed-config.ts +132 -0
  39. package/src/modules/embed/embed-host.ts +120 -0
  40. package/src/modules/embed/mount.tsx +80 -0
  41. package/src/modules/embed/services/embed-token.ts +22 -0
  42. package/src/modules/embed/services/embed.api.ts +158 -0
  43. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  44. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  45. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  46. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  47. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  48. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  49. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  50. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  51. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  52. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  53. package/src/modules/git/index.ts +15 -0
  54. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  55. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  56. package/src/modules/git/services/error-messages.ts +58 -1
  57. package/src/modules/git/services/pull-failure.ts +68 -0
  58. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  59. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  60. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  61. package/src/modules/layout/breakpoints.ts +8 -0
  62. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  63. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  64. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  65. package/src/modules/library/components/LibraryPage.tsx +22 -0
  66. package/src/modules/library/components/PluginExtras.tsx +23 -6
  67. package/src/modules/library/components/PluginPage.tsx +6 -1
  68. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  69. package/src/modules/library/services/plugins.api.ts +4 -1
  70. package/src/modules/library/state/plugins-revision.ts +28 -0
  71. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  72. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  73. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  74. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  75. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  76. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  77. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  78. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  79. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  80. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  81. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  82. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  83. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  84. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  85. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  86. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  87. package/src/modules/onboarding/invite-emails.ts +175 -0
  88. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  89. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  90. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  91. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  92. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  93. package/src/modules/onboarding/state/onboarding.ts +133 -59
  94. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  95. package/src/modules/settings/settings-nav-items.tsx +8 -3
  96. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  97. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  98. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  99. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  100. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  101. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  102. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  103. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  104. package/src/modules/setup/components/SetupGate.tsx +46 -1
  105. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  106. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  107. package/src/modules/setup/services/setup.api.ts +3 -3
  108. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  109. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  110. package/src/modules/toolbar/commands/actions.tsx +324 -0
  111. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  112. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  113. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  114. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  115. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  116. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  117. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  118. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  119. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  120. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  121. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  122. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  123. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  124. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  125. package/src/modules/toolbar/search/rank.ts +111 -0
  126. package/src/modules/toolbar/search/sources.ts +169 -0
  127. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  128. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  129. package/src/modules/workflow/services/lock.api.ts +17 -2
  130. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  131. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  132. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  133. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  134. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  135. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  136. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  137. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  138. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  139. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  140. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  141. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  142. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  143. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  144. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  145. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  146. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  147. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  148. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  149. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  150. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  151. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  152. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  153. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  154. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  155. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  156. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  157. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  158. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  159. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  160. package/src/modules/workspace/components/renderers/index.ts +26 -0
  161. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  162. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  163. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  164. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  165. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  166. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  167. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  168. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  169. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  170. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  171. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  172. package/src/modules/workspace/state/editable-page.ts +42 -0
  173. package/src/modules/workspace/state/workspace.context.ts +13 -4
  174. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  175. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  176. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  177. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  178. package/src/modules/workspace/utils/fileTree.ts +49 -14
  179. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  180. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  181. package/src/shared/components/ConfirmProvider.tsx +156 -0
  182. package/src/shared/components/Dialog.tsx +7 -0
  183. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  184. package/src/shared/components/confirm-context.ts +94 -0
  185. package/src/shared/components/index.ts +3 -0
  186. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  187. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -0,0 +1,1001 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { useEffect } from 'react';
3
+ import { act, render, screen, waitFor, within } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { MemoryRouter, useLocation, useNavigate, type NavigateFunction } from 'react-router-dom';
6
+ import type { FileTreeEntry } from '@bevel-software/platform-shared';
7
+ import { AuthContext } from '../../auth/state/auth.context';
8
+ import { authValue } from '../../library/__tests__/auth-harness';
9
+ import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
10
+ import { WorkspaceContext } from '../../workspace/state/workspace.context';
11
+ import { makeWorkspaceFixture } from '../../workspace/__tests__/testFixtures';
12
+ import { GetStartedColumn } from '../components/GetStartedColumn';
13
+ import { InviteDialogProvider } from '../state/invite-dialog';
14
+ import { resetOnboardingForTests } from '../state/onboarding';
15
+ import { WELCOME_PATH } from '../paths';
16
+ import { WorkspaceApiError } from '../../workspace/services/workspace.api';
17
+ import type { AccountSummary } from '../../auth/services/account.api';
18
+ import type { PluginSummary } from '../../library/services/plugins.api';
19
+ import type { AgentConnection } from '../services/agent-connection.api';
20
+ import { FIRST_PAGE_PROMPT, chatGptPromptUrl, claudePromptUrl } from '../first-page-prompt';
21
+ import type { StarterPacksAnswer } from '../services/starter-packs.api';
22
+ import { SearchPalette } from '../../toolbar/components/SearchPalette';
23
+ import { COMMAND_MENU_SHORTCUT_LABEL } from '../../toolbar/commands/command-menu';
24
+ import { AGENT_RECHECK_MS } from '../state/agent-connection';
25
+ import { notePluginCreated } from '../../library/state/plugins-revision';
26
+
27
+ /**
28
+ * The "Get set up" column: every tick is derived from state the app already
29
+ * has, the admin-only steps stay out of a member's list, and the column gets
30
+ * out of the way — on the welcome page, when narrow, when done, when closed.
31
+ */
32
+
33
+ const { listAccountsMock, listPluginsMock, openWorkspacePathMock, fetchAgentConnectionMock, authFetchMock } =
34
+ vi.hoisted(() => ({
35
+ listAccountsMock: vi.fn<() => Promise<AccountSummary[]>>(),
36
+ listPluginsMock: vi.fn<() => Promise<PluginSummary[]>>(),
37
+ openWorkspacePathMock: vi.fn<(path: string, options?: { edit?: boolean }) => void>(),
38
+ fetchAgentConnectionMock: vi.fn<() => Promise<AgentConnection>>(),
39
+ // The onboarding write (`markDone`) is the only thing that reaches it.
40
+ authFetchMock: vi.fn(async () => ({ ok: true, status: 200 }) as Response),
41
+ }));
42
+
43
+ vi.mock('../../../lib/api', () => ({ authFetch: authFetchMock }));
44
+ vi.mock('../services/agent-connection.api', () => ({ fetchAgentConnection: fetchAgentConnectionMock }));
45
+ const { fetchStarterPacksMock } = vi.hoisted(() => ({
46
+ fetchStarterPacksMock: vi.fn<() => Promise<StarterPacksAnswer>>(),
47
+ }));
48
+ vi.mock('../services/starter-packs.api', async (importOriginal) => ({
49
+ ...(await importOriginal<typeof import('../services/starter-packs.api')>()),
50
+ fetchStarterPacks: fetchStarterPacksMock,
51
+ }));
52
+ vi.mock('../../auth/services/account.api', async (importOriginal) => ({
53
+ ...(await importOriginal<typeof import('../../auth/services/account.api')>()),
54
+ listAccounts: listAccountsMock,
55
+ }));
56
+ vi.mock('../../library/services/library.api', async (importOriginal) => ({
57
+ ...(await importOriginal<typeof import('../../library/services/library.api')>()),
58
+ listSkills: vi.fn(async () => []),
59
+ }));
60
+ vi.mock('../../secrets-vault/services/tool-secrets.api', async (importOriginal) => ({
61
+ ...(await importOriginal<typeof import('../../secrets-vault/services/tool-secrets.api')>()),
62
+ listToolSecrets: vi.fn(async () => []),
63
+ }));
64
+ vi.mock('../../library/services/plugins.api', async (importOriginal) => ({
65
+ ...(await importOriginal<typeof import('../../library/services/plugins.api')>()),
66
+ listPlugins: listPluginsMock,
67
+ }));
68
+ // The real hook needs the git context for its branch; the column only ever
69
+ // asks it to open a workspace path, which is the call these tests assert.
70
+ vi.mock('../../workspace/routing/kb-routes', async (importOriginal) => ({
71
+ ...(await importOriginal<typeof import('../../workspace/routing/kb-routes')>()),
72
+ useFileNav: () => ({
73
+ openFile: vi.fn(),
74
+ openLink: vi.fn(),
75
+ openWorkspacePath: openWorkspacePathMock,
76
+ closeFile: vi.fn(),
77
+ }),
78
+ }));
79
+
80
+ const KB = 'kb';
81
+ const GUIDE = `${KB}/KnowledgeBase/How to get started.md`;
82
+
83
+ /** A workspace tree holding exactly `files` (workspace-relative paths). */
84
+ function treeOf(files: string[]): FileTreeEntry {
85
+ const root: FileTreeEntry = { name: '', relativePath: '', type: 'directory', children: [] };
86
+ for (const file of files) {
87
+ const parts = file.split('/');
88
+ let node = root;
89
+ parts.forEach((name, i) => {
90
+ const relativePath = parts.slice(0, i + 1).join('/');
91
+ const isFile = i === parts.length - 1;
92
+ let child = node.children!.find((c) => c.name === name);
93
+ if (!child) {
94
+ child = isFile
95
+ ? { name, relativePath, type: 'file' }
96
+ : { name, relativePath, type: 'directory', children: [] };
97
+ node.children!.push(child);
98
+ }
99
+ node = child;
100
+ });
101
+ }
102
+ return root;
103
+ }
104
+
105
+ const STARTER_TREE = [GUIDE, `${KB}/KnowledgeBase/.gitkeep`, `${KB}/Plugins/.gitkeep`];
106
+
107
+ function account(email: string, over: Partial<AccountSummary> = {}): AccountSummary {
108
+ return {
109
+ id: email,
110
+ email,
111
+ name: email,
112
+ hasPassword: false,
113
+ isEnvAdmin: false,
114
+ deactivatedAt: null,
115
+ isSystem: false,
116
+ createdAt: '2026-01-01T00:00:00Z',
117
+ ...over,
118
+ };
119
+ }
120
+
121
+ function plugin(folder: string): PluginSummary {
122
+ return {
123
+ name: folder.split('/').pop()!,
124
+ folders: [folder],
125
+ canRead: true,
126
+ canWrite: true,
127
+ isOwner: true,
128
+ skillCount: 0,
129
+ toolCount: 0,
130
+ owners: { roles: [], users: [] },
131
+ writers: { roles: [], users: [] },
132
+ readers: { roles: [], users: [], restricted: false },
133
+ hasRequested: false,
134
+ requestNumber: null,
135
+ };
136
+ }
137
+
138
+ function adminValue(isAdmin: boolean): AdminContextValue {
139
+ return {
140
+ isAdmin,
141
+ isAdminLoading: false,
142
+ unreadCount: 0,
143
+ lastSeen: null,
144
+ markSeen: () => {},
145
+ refresh: () => {},
146
+ rolesConfigCorrupted: false,
147
+ rolesConfigErrors: [],
148
+ runRolesRecovery: async () => {},
149
+ };
150
+ }
151
+
152
+ function LocationProbe() {
153
+ return <div data-testid="pathname">{useLocation().pathname}</div>;
154
+ }
155
+
156
+ /** The router's `navigate`, handed out so a test can move the app around under the column. */
157
+ let navigateTo: NavigateFunction = () => {};
158
+ function NavigateHandle() {
159
+ const navigate = useNavigate();
160
+ useEffect(() => {
161
+ navigateTo = navigate;
162
+ }, [navigate]);
163
+ return null;
164
+ }
165
+
166
+ function setViewportWidth(width: number): void {
167
+ (window as typeof window & { happyDOM: { setInnerWidth(v: number): void } }).happyDOM.setInnerWidth(width);
168
+ }
169
+
170
+ type MountOptions = {
171
+ admin?: boolean;
172
+ onboardingDone?: boolean;
173
+ /** The workspace's files; null while the tree has not loaded. */
174
+ files?: string[] | null;
175
+ openFilePath?: string | null;
176
+ route?: string;
177
+ createFile?: (relativePath: string, content?: string, options?: { ifAbsent?: boolean }) => Promise<void>;
178
+ /** Mount the toolbar's command menu beside the column, as the app does. */
179
+ withPalette?: boolean;
180
+ /** The branch on screen; the default one (the test setup's) unless a test is about a draft. */
181
+ workspaceBranch?: string | null;
182
+ };
183
+
184
+ /** The default branch the test setup pins: where a starter pack lands. */
185
+ const DEFAULT_BRANCH = 'target-company-state';
186
+
187
+ /** The column in every context it reads; `rerender` it to move the app's state under it. */
188
+ function columnUi({
189
+ admin = false,
190
+ onboardingDone = false,
191
+ files = STARTER_TREE,
192
+ openFilePath = null as string | null,
193
+ route = '/workspace',
194
+ createFile = async () => {},
195
+ withPalette = false,
196
+ workspaceBranch = DEFAULT_BRANCH,
197
+ }: MountOptions = {}) {
198
+ const auth = authValue({ user: sessionUser(onboardingDone) });
199
+ const ui = (
200
+ <MemoryRouter initialEntries={[route]}>
201
+ <AuthContext.Provider value={auth}>
202
+ <AdminContext.Provider value={adminValue(admin)}>
203
+ <WorkspaceContext.Provider
204
+ value={makeWorkspaceFixture({
205
+ kbDirName: KB,
206
+ fileTree: files ? treeOf(files) : null,
207
+ openFilePath,
208
+ createFile,
209
+ workspaceBranch,
210
+ })}
211
+ >
212
+ <InviteDialogProvider>
213
+ {withPalette && <SearchPalette compact />}
214
+ <GetStartedColumn />
215
+ <LocationProbe />
216
+ <NavigateHandle />
217
+ </InviteDialogProvider>
218
+ </WorkspaceContext.Provider>
219
+ </AdminContext.Provider>
220
+ </AuthContext.Provider>
221
+ </MemoryRouter>
222
+ );
223
+ return ui;
224
+ }
225
+
226
+ function mount(options: MountOptions = {}) {
227
+ const ui = columnUi(options);
228
+ return { ...render(ui), ui };
229
+ }
230
+
231
+ /** The checklist row titled `title`, or null when the column does not list it. */
232
+ function row(title: RegExp | string) {
233
+ const column = screen.getByRole('complementary', { name: 'Get set up' });
234
+ const heading = within(column).queryByText(title);
235
+ return heading ? (heading.closest('li') as HTMLElement) : null;
236
+ }
237
+
238
+ const isDone = (title: RegExp | string) => within(row(title)!).queryByText('(done)') !== null;
239
+
240
+ /**
241
+ * The signed-in user of the test at hand, one object per test and per
242
+ * onboarding state, never mutated: what the app keeps per signed-in user
243
+ * (the starter-pack answer) lives across a rerender, and never leaks into
244
+ * the next test, which signs in afresh.
245
+ */
246
+ type SessionUser = { id: string; email: string; name: string; onboardingDone: boolean };
247
+ let sessionUsers: Record<'done' | 'pending', SessionUser>;
248
+ const sessionUser = (onboardingDone: boolean) => sessionUsers[onboardingDone ? 'done' : 'pending'];
249
+
250
+ beforeEach(() => {
251
+ resetOnboardingForTests();
252
+ const juan = { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera' };
253
+ sessionUsers = { done: { ...juan, onboardingDone: true }, pending: { ...juan, onboardingDone: false } };
254
+ fetchStarterPacksMock.mockReset().mockResolvedValue({ offered: false, chosen: null, packs: [], chosenPack: null });
255
+ setViewportWidth(1400);
256
+ listAccountsMock.mockReset().mockResolvedValue([account('juan@bevel.software')]);
257
+ listPluginsMock.mockReset().mockResolvedValue([]);
258
+ openWorkspacePathMock.mockReset();
259
+ fetchAgentConnectionMock.mockReset().mockResolvedValue({ connected: false });
260
+ authFetchMock.mockClear();
261
+ });
262
+
263
+ /** Calls to the onboarding write — the one `markDone` makes. */
264
+ const doneWrites = () =>
265
+ authFetchMock.mock.calls.filter((c) => (c as unknown[])[0] === '/api/auth/onboarding-done').length;
266
+
267
+ 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();
270
+ expect(screen.getByText('1 of 5')).toBeInTheDocument();
271
+ expect(row('Create your workspace')).not.toBeNull();
272
+ expect(row('Connect your agent')).not.toBeNull();
273
+ expect(row('Read “How to get started”')).not.toBeNull();
274
+ expect(row('Write your first page')).not.toBeNull();
275
+ expect(row(/^Find or do anything with/)).not.toBeNull();
276
+ expect(row('Choose where your knowledge lives')).toBeNull();
277
+ expect(row('Create a plugin for your team')).toBeNull();
278
+ expect(row('Invite your team')).toBeNull();
279
+ expect(listAccountsMock).not.toHaveBeenCalled();
280
+ expect(listPluginsMock).not.toHaveBeenCalled();
281
+ });
282
+
283
+ it('ticks "Connect your agent" from the server onboarding flag', () => {
284
+ mount({ onboardingDone: true });
285
+ expect(isDone('Connect your agent')).toBe(true);
286
+ expect(isDone('Create your workspace')).toBe(true);
287
+ expect(screen.getByText('2 of 5')).toBeInTheDocument();
288
+ });
289
+
290
+ it('sends "Connect" to the welcome page', async () => {
291
+ mount();
292
+ await userEvent.click(within(row('Connect your agent')!).getByRole('button', { name: 'Connect' }));
293
+ expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
294
+ });
295
+
296
+ it('opens the starter guide and ticks it', async () => {
297
+ mount();
298
+ expect(isDone('Read “How to get started”')).toBe(false);
299
+ await userEvent.click(within(row('Read “How to get started”')!).getByRole('button', { name: 'Open it' }));
300
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(GUIDE);
301
+ expect(isDone('Read “How to get started”')).toBe(true);
302
+ });
303
+
304
+ it('ticks the guide when it is opened by any route, and remembers it', () => {
305
+ const { unmount } = mount({ openFilePath: GUIDE });
306
+ expect(isDone('Read “How to get started”')).toBe(true);
307
+ unmount();
308
+ mount();
309
+ expect(isDone('Read “How to get started”')).toBe(true);
310
+ });
311
+
312
+ it('leaves the guide step out when the knowledge base has no such page', () => {
313
+ mount({ files: [`${KB}/KnowledgeBase/.gitkeep`] });
314
+ expect(row('Read “How to get started”')).toBeNull();
315
+ expect(screen.getByText('1 of 4')).toBeInTheDocument();
316
+ });
317
+
318
+ 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`] });
320
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
321
+ expect(isDone('Write your first page')).toBe(false);
322
+ expect(
323
+ within(row('Write your first page')!).getByText(
324
+ 'Start one here, or drop files into the file tree.',
325
+ ),
326
+ ).toBeInTheDocument();
327
+ unmount();
328
+ mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Product/Roadmap.md`] });
329
+ // Ticked once the starter-pack answer is in (none chosen here).
330
+ await waitFor(() => expect(isDone('Write your first page')).toBe(true));
331
+ });
332
+
333
+ it('"New page" creates Untitled.md in the Knowledge folder and opens it for editing', async () => {
334
+ const createFile = vi.fn(async () => {});
335
+ mount({ createFile });
336
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
337
+ expect(createFile).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, '# Untitled\n\n', { ifAbsent: true });
338
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled.md`, { edit: true });
339
+ });
340
+
341
+ it('"New page" takes the next free name when Untitled.md is taken', async () => {
342
+ const createFile = vi.fn(async () => {});
343
+ // Any page would already tick the step and hide the button, so what holds
344
+ // the name here is an (otherwise empty) folder called `Untitled.md` and
345
+ // `Untitled 2.md` — a name the tree has is taken, whatever it is.
346
+ mount({
347
+ createFile,
348
+ files: [
349
+ ...STARTER_TREE,
350
+ `${KB}/KnowledgeBase/Untitled.md/.gitkeep`,
351
+ `${KB}/KnowledgeBase/Untitled 2.md/.gitkeep`,
352
+ ],
353
+ });
354
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
355
+ expect(createFile).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled 3.md`, '# Untitled\n\n', { ifAbsent: true });
356
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled 3.md`, { edit: true });
357
+ });
358
+
359
+ /**
360
+ * The tree can be a moment behind: a page made elsewhere since it loaded
361
+ * holds the name the column picked. The create is exclusive, so the
362
+ * backend refuses (409) instead of replacing that page, and the column
363
+ * moves on to the next name.
364
+ */
365
+ it('"New page" never overwrites: a name taken since the tree loaded moves on to the next', async () => {
366
+ const taken = new Set([`${KB}/KnowledgeBase/Untitled.md`, `${KB}/KnowledgeBase/Untitled 2.md`]);
367
+ const createFile = vi.fn(async (path: string) => {
368
+ if (taken.has(path)) throw new WorkspaceApiError(409, `"${path}" already exists.`);
369
+ });
370
+ mount({ createFile });
371
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
372
+ await waitFor(() =>
373
+ expect(openWorkspacePathMock).toHaveBeenCalledWith(`${KB}/KnowledgeBase/Untitled 3.md`, { edit: true }),
374
+ );
375
+ expect(createFile.mock.calls.map((c) => c[0])).toEqual([
376
+ `${KB}/KnowledgeBase/Untitled.md`,
377
+ `${KB}/KnowledgeBase/Untitled 2.md`,
378
+ `${KB}/KnowledgeBase/Untitled 3.md`,
379
+ ]);
380
+ expect(within(row('Write your first page')!).queryByRole('alert')).not.toBeInTheDocument();
381
+ });
382
+
383
+ it('"New page" gives up after a few taken names, and says so on the step', async () => {
384
+ const createFile = vi.fn(async (path: string) => {
385
+ throw new WorkspaceApiError(409, `"${path}" already exists.`);
386
+ });
387
+ mount({ createFile });
388
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
389
+ expect(await within(row('Write your first page')!).findByRole('alert')).toHaveTextContent(
390
+ `Couldn’t create the page: "${KB}/KnowledgeBase/Untitled 5.md" already exists.`,
391
+ );
392
+ expect(createFile).toHaveBeenCalledTimes(5);
393
+ expect(openWorkspacePathMock).not.toHaveBeenCalled();
394
+ });
395
+
396
+ // Mid-switch, the URL names the destination branch while the workspace on
397
+ // screen (and `createFile`) is still the branch being left; a page made in
398
+ // that gap would land on the old branch and open on the new one, nowhere.
399
+ it('"New page" creates nothing while the workspace on screen is not the branch the URL names', async () => {
400
+ const createFile = vi.fn(async () => {});
401
+ mount({ createFile, route: '/workspace/alice%2Fdraft' });
402
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
403
+ expect(await within(row('Write your first page')!).findByRole('alert')).toHaveTextContent(
404
+ 'Couldn’t create the page: the workspace is still loading.',
405
+ );
406
+ expect(createFile).not.toHaveBeenCalled();
407
+ expect(openWorkspacePathMock).not.toHaveBeenCalled();
408
+ });
409
+
410
+ it('"New page" does not retry a refusal that is not about the name', async () => {
411
+ const createFile = vi.fn(async () => {
412
+ throw new WorkspaceApiError(403, 'You don’t have permission to write to "KnowledgeBase/Untitled.md".');
413
+ });
414
+ mount({ createFile });
415
+ 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
+ );
419
+ expect(createFile).toHaveBeenCalledTimes(1);
420
+ });
421
+
422
+ it('"New page" says "Creating…" while it works, and says why it failed on the step', async () => {
423
+ let refuse!: (err: Error) => void;
424
+ const createFile = vi.fn(
425
+ () =>
426
+ new Promise<void>((_, reject) => {
427
+ refuse = reject;
428
+ }),
429
+ );
430
+ mount({ createFile });
431
+ await userEvent.click(within(row('Write your first page')!).getByRole('button', { name: 'New page' }));
432
+ expect(within(row('Write your first page')!).getByRole('button', { name: 'Creating…' })).toBeDisabled();
433
+
434
+ await act(async () => {
435
+ refuse(new Error('You don’t have permission to write to "KnowledgeBase/Untitled.md".'));
436
+ });
437
+ 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".',
439
+ );
440
+ expect(within(row('Write your first page')!).getByRole('button', { name: 'New page' })).toBeEnabled();
441
+ expect(openWorkspacePathMock).not.toHaveBeenCalled();
442
+ expect(isDone('Write your first page')).toBe(false);
443
+ });
444
+ });
445
+
446
+ /**
447
+ * The agent-connection answer, asked once: it ticks "Connect your agent" for
448
+ * someone who connected without ever opening the welcome page (and concludes
449
+ * the onboarding for them), and it is what puts the one-click prompt on
450
+ * "Write your first page".
451
+ */
452
+ describe('GetStartedColumn: a connected agent', () => {
453
+ it('ticks "Connect your agent" from the endpoint, and concludes the onboarding once', async () => {
454
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
455
+ mount();
456
+ await waitFor(() => expect(isDone('Connect your agent')).toBe(true));
457
+ expect(doneWrites()).toBe(1);
458
+ await act(async () => {});
459
+ expect(doneWrites()).toBe(1);
460
+ });
461
+
462
+ it('asks once, not on a timer', async () => {
463
+ vi.useFakeTimers();
464
+ try {
465
+ mount();
466
+ await act(async () => {
467
+ await vi.advanceTimersByTimeAsync(30_000);
468
+ });
469
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
470
+ expect(isDone('Connect your agent')).toBe(false);
471
+ expect(doneWrites()).toBe(0);
472
+ } finally {
473
+ vi.useRealTimers();
474
+ }
475
+ });
476
+
477
+ /**
478
+ * Connecting somewhere else — another window, the External agent access
479
+ * page — still ticks the list: it asks again when the person comes back to
480
+ * the tab, though not more than once in a while.
481
+ */
482
+ it('asks again when you come back to the tab, at most once in a while', async () => {
483
+ vi.useFakeTimers();
484
+ try {
485
+ mount();
486
+ await act(async () => {
487
+ await vi.advanceTimersByTimeAsync(0);
488
+ });
489
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
490
+ // Straight back: too soon to ask again.
491
+ act(() => {
492
+ window.dispatchEvent(new Event('focus'));
493
+ });
494
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
495
+
496
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
497
+ await act(async () => {
498
+ await vi.advanceTimersByTimeAsync(AGENT_RECHECK_MS);
499
+ });
500
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
501
+ await act(async () => {
502
+ document.dispatchEvent(new Event('visibilitychange'));
503
+ await vi.advanceTimersByTimeAsync(0);
504
+ });
505
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(2);
506
+ expect(isDone('Connect your agent')).toBe(true);
507
+ } finally {
508
+ vi.useRealTimers();
509
+ }
510
+ });
511
+
512
+ it('does not conclude again for an account the server already concluded', async () => {
513
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
514
+ mount({ onboardingDone: true });
515
+ await waitFor(() => expect(row('Write your first page')).not.toBeNull());
516
+ await act(async () => {});
517
+ expect(doneWrites()).toBe(0);
518
+ });
519
+
520
+ it('asks nothing once the column was closed', async () => {
521
+ window.localStorage.setItem('bevel.onboarding.setupDismissed.juan@bevel.software', '1');
522
+ mount();
523
+ await act(async () => {});
524
+ expect(fetchAgentConnectionMock).not.toHaveBeenCalled();
525
+ });
526
+
527
+ it('keeps the one-click prompt out of "Write your first page" until an agent is connected', async () => {
528
+ mount();
529
+ await act(async () => {});
530
+ const page = row('Write your first page')!;
531
+ expect(within(page).queryByRole('link', { name: 'Ask Claude to write it' })).not.toBeInTheDocument();
532
+ expect(within(page).queryByRole('link', { name: 'Open in ChatGPT' })).not.toBeInTheDocument();
533
+ expect(within(page).queryByRole('button', { name: 'Copy prompt' })).not.toBeInTheDocument();
534
+ expect(within(page).getByRole('button', { name: 'New page' })).toBeInTheDocument();
535
+ expect(within(page).getByText('Connect your agent and it can write pages for you.')).toBeInTheDocument();
536
+ });
537
+
538
+ it('offers "Ask Claude to write it" first once connected, keeping New page beside it', async () => {
539
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
540
+ mount();
541
+ const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask Claude to write it' });
542
+ expect(ask).toHaveAttribute('href', claudePromptUrl(FIRST_PAGE_PROMPT));
543
+ expect(ask).toHaveAttribute('target', '_blank');
544
+ expect(ask).toHaveAttribute('rel', 'noopener noreferrer');
545
+
546
+ const page = row('Write your first page')!;
547
+ const chatGpt = within(page).getByRole('link', { name: 'Open in ChatGPT' });
548
+ expect(chatGpt).toHaveAttribute('href', chatGptPromptUrl(FIRST_PAGE_PROMPT));
549
+ expect(chatGpt).toHaveAttribute('target', '_blank');
550
+ expect(chatGpt).toHaveAttribute('rel', 'noopener noreferrer');
551
+ expect(within(page).getByRole('button', { name: 'New page' })).toBeInTheDocument();
552
+ expect(within(page).queryByText('Connect your agent and it can write pages for you.')).not.toBeInTheDocument();
553
+ });
554
+
555
+ /**
556
+ * A team that chose a starter pack gets the pack's own request, and the
557
+ * pack's pages — placeholders until someone fills one in — do not count as
558
+ * the first page.
559
+ */
560
+ describe('after a starter pack', () => {
561
+ const SALES_PAGES = [`${KB}/KnowledgeBase/Customers.md`, `${KB}/KnowledgeBase/Pricing.md`];
562
+ const SALES_PROMPT = 'Using our Hexis knowledge base, fill in the Customers page.';
563
+ const chosen = (starterPages: string[]): StarterPacksAnswer => ({
564
+ offered: false,
565
+ chosen: 'sales',
566
+ packs: [],
567
+ chosenPack: { id: 'sales', name: 'Sales', firstPagePrompt: `${SALES_PROMPT}\n`, starterPages },
568
+ });
569
+
570
+ it("asks the agent with the pack's prompt", async () => {
571
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
572
+ fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
573
+ mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
574
+ const page = row('Write your first page')!;
575
+ await waitFor(() =>
576
+ expect(within(page).getByRole('link', { name: 'Ask Claude to write it' })).toHaveAttribute(
577
+ 'href',
578
+ claudePromptUrl(SALES_PROMPT),
579
+ ),
580
+ );
581
+ expect(within(page).getByRole('link', { name: 'Open in ChatGPT' })).toHaveAttribute(
582
+ 'href',
583
+ chatGptPromptUrl(SALES_PROMPT),
584
+ );
585
+ });
586
+
587
+ it("leaves the step open while the pack's pages are untouched, and ticks it once one is filled in", async () => {
588
+ fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
589
+ const files = [...STARTER_TREE, ...SALES_PAGES];
590
+ const { rerender } = mount({ files });
591
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalledTimes(1));
592
+ expect(isDone('Write your first page')).toBe(false);
593
+
594
+ // Somebody fills in Customers: the tree is fetched again, and the
595
+ // server no longer lists the page as a placeholder.
596
+ fetchStarterPacksMock.mockResolvedValue(chosen([SALES_PAGES[1]!]));
597
+ rerender(columnUi({ files }));
598
+ await waitFor(() => expect(isDone('Write your first page')).toBe(true));
599
+ expect(fetchStarterPacksMock).toHaveBeenCalledTimes(2);
600
+ });
601
+
602
+ it('keeps the generic prompt when the team skipped', async () => {
603
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
604
+ fetchStarterPacksMock.mockResolvedValue({ offered: false, chosen: 'none', packs: [], chosenPack: null });
605
+ mount();
606
+ const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask Claude to write it' });
607
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
608
+ expect(ask).toHaveAttribute('href', claudePromptUrl(FIRST_PAGE_PROMPT));
609
+ });
610
+
611
+ it('does not tick the step before the answer is in: untouched pack pages are not a first page', async () => {
612
+ let answer!: (a: StarterPacksAnswer) => void;
613
+ fetchStarterPacksMock.mockImplementation(() => new Promise((resolve) => (answer = resolve)));
614
+ mount({ files: [...STARTER_TREE, ...SALES_PAGES] });
615
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
616
+ expect(isDone('Write your first page')).toBe(false);
617
+ answer(chosen(SALES_PAGES));
618
+ // Still open: both pages are placeholders. Filling one in would tick it.
619
+ await act(async () => {});
620
+ expect(isDone('Write your first page')).toBe(false);
621
+ });
622
+
623
+ it('reads the tree alone on a draft branch, where the default branch’s placeholders do not apply', async () => {
624
+ fetchStarterPacksMock.mockResolvedValue(chosen(SALES_PAGES));
625
+ mount({ files: [...STARTER_TREE, ...SALES_PAGES], workspaceBranch: 'alice/draft' });
626
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
627
+ await waitFor(() => expect(isDone('Write your first page')).toBe(true));
628
+ });
629
+
630
+ it('asks again for a tree change that lands while the previous answer is still on its way', async () => {
631
+ const resolvers: ((a: StarterPacksAnswer) => void)[] = [];
632
+ fetchStarterPacksMock.mockImplementation(() => new Promise((resolve) => resolvers.push(resolve)));
633
+ const files = [...STARTER_TREE, ...SALES_PAGES];
634
+ const { rerender } = mount({ files });
635
+ await waitFor(() => expect(resolvers).toHaveLength(1));
636
+ resolvers[0]!(chosen(SALES_PAGES));
637
+ await waitFor(() => expect(isDone('Write your first page')).toBe(false));
638
+
639
+ // Two tree changes in a row: the first starts a request, the second
640
+ // lands while it is out. One more request follows, and it is that one
641
+ // which reports the page filled in.
642
+ rerender(columnUi({ files: [...files] }));
643
+ await waitFor(() => expect(resolvers).toHaveLength(2));
644
+ rerender(columnUi({ files: [...files] }));
645
+ resolvers[1]!(chosen(SALES_PAGES));
646
+ await waitFor(() => expect(resolvers).toHaveLength(3));
647
+ resolvers[2]!(chosen([SALES_PAGES[1]!]));
648
+ await waitFor(() => expect(isDone('Write your first page')).toBe(true));
649
+ });
650
+ });
651
+
652
+ it('leads with "Ask ChatGPT to write it" for a ChatGPT connection, Claude quiet beside Copy prompt', async () => {
653
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'ChatGPT', kind: 'agent' });
654
+ mount();
655
+ const ask = await within(row('Write your first page')!).findByRole('link', { name: 'Ask ChatGPT to write it' });
656
+ expect(ask).toHaveAttribute('href', chatGptPromptUrl(FIRST_PAGE_PROMPT));
657
+ const page = row('Write your first page')!;
658
+ expect(within(page).getByRole('link', { name: 'Open in Claude' })).toHaveAttribute(
659
+ 'href',
660
+ claudePromptUrl(FIRST_PAGE_PROMPT),
661
+ );
662
+ expect(within(page).getByRole('button', { name: 'Copy prompt' })).toBeInTheDocument();
663
+ expect(within(page).queryByRole('link', { name: 'Ask Claude to write it' })).not.toBeInTheDocument();
664
+ expect(within(page).queryByText(/Paste it into/)).not.toBeInTheDocument();
665
+ });
666
+
667
+ it('leads with Copy prompt for an agent no link opens, and says where to paste it', async () => {
668
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude Code · local server on LAPTOP-1', kind: 'agent' });
669
+ const writeText = vi.fn().mockResolvedValue(undefined);
670
+ const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
671
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
672
+ try {
673
+ mount();
674
+ const copy = await within(row('Write your first page')!).findByRole('button', { name: 'Copy prompt' });
675
+ const page = row('Write your first page')!;
676
+ expect(within(page).getByText('Paste it into Claude Code.')).toBeInTheDocument();
677
+ expect(within(page).getByRole('link', { name: 'Open in Claude' })).toBeInTheDocument();
678
+ expect(within(page).getByRole('link', { name: 'Open in ChatGPT' })).toBeInTheDocument();
679
+ expect(within(page).queryByRole('link', { name: /to write it/ })).not.toBeInTheDocument();
680
+ expect(within(page).getByRole('button', { name: 'New page' })).toBeInTheDocument();
681
+ await userEvent.click(copy);
682
+ expect(writeText).toHaveBeenCalledWith(FIRST_PAGE_PROMPT);
683
+ expect(within(row('Write your first page')!).getByRole('status')).toHaveTextContent('Prompt copied');
684
+ } finally {
685
+ if (original) Object.defineProperty(navigator, 'clipboard', original);
686
+ else Reflect.deleteProperty(navigator, 'clipboard');
687
+ }
688
+ });
689
+
690
+ it('leads with Copy prompt for a connection key, whatever its label says', async () => {
691
+ // A key's label is free text: "ChatGPT CLI" names the key, not an app
692
+ // that a chatgpt.com link would reach.
693
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'ChatGPT CLI', kind: 'key' });
694
+ mount();
695
+ const page = await waitFor(() => {
696
+ const r = row('Write your first page')!;
697
+ within(r).getByRole('button', { name: 'Copy prompt' });
698
+ return r;
699
+ });
700
+ expect(within(page).queryByRole('link', { name: /to write it/ })).not.toBeInTheDocument();
701
+ expect(within(page).getByText('Paste it into your agent.')).toBeInTheDocument();
702
+ });
703
+
704
+ it('says "your agent" when the connection has no name to offer', async () => {
705
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Unnamed agent', kind: 'agent' });
706
+ mount();
707
+ expect(await within(row('Write your first page')!).findByText('Paste it into your agent.')).toBeInTheDocument();
708
+ });
709
+
710
+ it('copies the prompt and says so', async () => {
711
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
712
+ const writeText = vi.fn().mockResolvedValue(undefined);
713
+ const original = Object.getOwnPropertyDescriptor(navigator, 'clipboard');
714
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
715
+ try {
716
+ mount();
717
+ const copy = await within(row('Write your first page')!).findByRole('button', { name: 'Copy prompt' });
718
+ await userEvent.click(copy);
719
+ expect(writeText).toHaveBeenCalledWith(FIRST_PAGE_PROMPT);
720
+ expect(within(row('Write your first page')!).getByRole('status')).toHaveTextContent('Prompt copied');
721
+ } finally {
722
+ if (original) Object.defineProperty(navigator, 'clipboard', original);
723
+ else Reflect.deleteProperty(navigator, 'clipboard');
724
+ }
725
+ });
726
+
727
+ it('ticks the page step by itself when the agent’s page lands, whoever wrote it', async () => {
728
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
729
+ mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/About us.md`] });
730
+ await waitFor(() => expect(isDone('Connect your agent')).toBe(true));
731
+ expect(isDone('Write your first page')).toBe(true);
732
+ expect(screen.queryByRole('link', { name: 'Ask Claude to write it' })).not.toBeInTheDocument();
733
+ });
734
+ });
735
+
736
+ describe('GetStartedColumn: what an admin sees', () => {
737
+ it('lists all eight steps, storage already done', async () => {
738
+ mount({ admin: true });
739
+ await screen.findByRole('complementary', { name: 'Get set up' });
740
+ expect(screen.getByText('2 of 8')).toBeInTheDocument();
741
+ expect(isDone('Choose where your knowledge lives')).toBe(true);
742
+ expect(isDone('Create a plugin for your team')).toBe(false);
743
+ expect(isDone('Invite your team')).toBe(false);
744
+ });
745
+
746
+ it('ticks the plugin step for a team plugin, not a personal shelf', async () => {
747
+ listPluginsMock.mockResolvedValue([plugin('Plugins/personal-juan')]);
748
+ const { unmount } = mount({ admin: true });
749
+ await screen.findByRole('complementary', { name: 'Get set up' });
750
+ expect(isDone('Create a plugin for your team')).toBe(false);
751
+ unmount();
752
+
753
+ listPluginsMock.mockResolvedValue([plugin('Plugins/GTM')]);
754
+ mount({ admin: true });
755
+ await waitFor(() => expect(isDone('Create a plugin for your team')).toBe(true));
756
+ });
757
+
758
+ it('ticks the invite step for a second person, never for a system account', async () => {
759
+ listAccountsMock.mockResolvedValue([
760
+ account('juan@bevel.software'),
761
+ account('recovery-bot@bevel.local', { isSystem: true }),
762
+ ]);
763
+ const { unmount } = mount({ admin: true });
764
+ await screen.findByRole('complementary', { name: 'Get set up' });
765
+ expect(isDone('Invite your team')).toBe(false);
766
+ unmount();
767
+
768
+ listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('ana@bevel.software')]);
769
+ mount({ admin: true });
770
+ await waitFor(() => expect(isDone('Invite your team')).toBe(true));
771
+ });
772
+
773
+ it('does not count a switched-off account as a teammate', async () => {
774
+ listAccountsMock.mockResolvedValue([
775
+ account('juan@bevel.software'),
776
+ account('ana@bevel.software', { deactivatedAt: '2026-09-01T00:00:00Z' }),
777
+ ]);
778
+ mount({ admin: true });
779
+ await screen.findByRole('complementary', { name: 'Get set up' });
780
+ expect(isDone('Invite your team')).toBe(false);
781
+ });
782
+
783
+ /**
784
+ * The plugin question is asked on entering Skills & Tools and when this tab
785
+ * creates a plugin — not on every move between Library pages.
786
+ */
787
+ it('asks for plugins again on entering Skills & Tools and on a plugin created, not on every Library page', async () => {
788
+ mount({ admin: true });
789
+ await screen.findByRole('complementary', { name: 'Get set up' });
790
+ expect(listPluginsMock).toHaveBeenCalledTimes(1);
791
+
792
+ await act(async () => navigateTo('/skills-and-tools'));
793
+ await waitFor(() => expect(listPluginsMock).toHaveBeenCalledTimes(2));
794
+ await act(async () => navigateTo('/skills-and-tools/owned'));
795
+ await act(async () => navigateTo('/skills-and-tools/plugins/GTM'));
796
+ expect(listPluginsMock).toHaveBeenCalledTimes(2);
797
+
798
+ listPluginsMock.mockResolvedValue([plugin('Plugins/GTM')]);
799
+ act(() => notePluginCreated());
800
+ await waitFor(() => expect(isDone('Create a plugin for your team')).toBe(true));
801
+ expect(listPluginsMock).toHaveBeenCalledTimes(3);
802
+
803
+ // Found is final: leaving and coming back asks nothing more.
804
+ await act(async () => navigateTo('/workspace'));
805
+ await act(async () => navigateTo('/skills-and-tools'));
806
+ expect(listPluginsMock).toHaveBeenCalledTimes(3);
807
+ });
808
+
809
+ it('opens the invite dialog from the invite step', async () => {
810
+ mount({ admin: true });
811
+ await screen.findByRole('complementary', { name: 'Get set up' });
812
+ await userEvent.click(within(row('Invite your team')!).getByRole('button', { name: 'Invite people' }));
813
+ expect(screen.getByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
814
+ });
815
+
816
+ });
817
+
818
+ /**
819
+ * Finishing the list is a moment, not a disappearance: the column says
820
+ * "You're set up" — when the last tick lands, or on arrival for a list that
821
+ * was finished and never celebrated — and goes for good once that is closed.
822
+ */
823
+ describe('GetStartedColumn: all done', () => {
824
+ const WITH_PAGE = [...STARTER_TREE, `${KB}/KnowledgeBase/Notes.md`];
825
+ const complete = () => screen.queryByRole('heading', { name: 'You’re set up' });
826
+
827
+ // The command menu has been opened, by whatever route.
828
+ beforeEach(() => {
829
+ window.localStorage.setItem('bevel.onboarding.commandMenuOpened.juan@bevel.software', '1');
830
+ });
831
+
832
+ it('says "You’re set up" when the last step ticks, in place of the list', async () => {
833
+ listPluginsMock.mockResolvedValue([plugin('Plugins/GTM')]);
834
+ listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('ana@bevel.software')]);
835
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
836
+ const everythingBut = { admin: true, onboardingDone: true, openFilePath: GUIDE };
837
+ // One step short, the settled column shows the seven it has...
838
+ const { rerender } = mount(everythingBut);
839
+ expect(await screen.findByText('7 of 8')).toBeInTheDocument();
840
+ expect(complete()).toBeNull();
841
+ // ...and the page landing in the tree finishes it.
842
+ rerender(columnUi({ ...everythingBut, files: WITH_PAGE }));
843
+ expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
844
+ const column = screen.getByRole('complementary', { name: 'Get set up' });
845
+ expect(within(column).getByRole('status')).toHaveTextContent(
846
+ 'Your agent can read and write your knowledge base, and your team can join you.',
847
+ );
848
+ expect(within(column).queryByRole('list')).not.toBeInTheDocument();
849
+ expect(within(column).queryByRole('progressbar')).not.toBeInTheDocument();
850
+ });
851
+
852
+ it('celebrates a list finished elsewhere on arrival, and does not mention a team to a member', async () => {
853
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude', kind: 'agent' });
854
+ mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
855
+ expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
856
+ expect(screen.getByText('Your agent can read and write your knowledge base.')).toBeInTheDocument();
857
+ expect(screen.queryByText(/your team/)).not.toBeInTheDocument();
858
+ });
859
+
860
+ /**
861
+ * "Connect your agent" also ticks when the onboarding was concluded with no
862
+ * agent ever calling in (the pill's ×), so the line does not claim one.
863
+ */
864
+ it('claims no agent when none has connected', async () => {
865
+ mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
866
+ expect(await screen.findByRole('heading', { name: 'You’re set up' })).toBeInTheDocument();
867
+ expect(screen.getByText('Your knowledge base is ready.')).toBeInTheDocument();
868
+ expect(screen.queryByText(/Your agent can/)).not.toBeInTheDocument();
869
+ });
870
+
871
+ it('Close retires the column for good, and remembers it per account', async () => {
872
+ const { unmount } = mount({ onboardingDone: true, openFilePath: GUIDE, files: WITH_PAGE });
873
+ await userEvent.click(await screen.findByRole('button', { name: 'Close' }));
874
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
875
+ expect(window.localStorage.getItem('bevel.onboarding.setupCompleteClosed.juan@bevel.software')).toBe('1');
876
+ unmount();
877
+ // Not shown again — not even if a step comes undone later.
878
+ fetchAgentConnectionMock.mockClear();
879
+ mount({ onboardingDone: true, openFilePath: GUIDE });
880
+ await act(async () => {});
881
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
882
+ expect(fetchAgentConnectionMock).not.toHaveBeenCalled();
883
+ });
884
+ });
885
+
886
+ /**
887
+ * The command menu is taught by being opened: "Try it" opens it, and the
888
+ * step ticks once it has been opened by any route — and stays ticked.
889
+ */
890
+ describe('GetStartedColumn: the command menu', () => {
891
+ const STEP = `Find or do anything with ${COMMAND_MENU_SHORTCUT_LABEL}`;
892
+
893
+ it('is a step for everyone, named with this platform’s keys', async () => {
894
+ mount();
895
+ expect(row(STEP)).not.toBeNull();
896
+ expect(isDone(STEP)).toBe(false);
897
+ expect(
898
+ within(row(STEP)!).getByText('Type what you want: a page, a skill, or an action like Invite people.'),
899
+ ).toBeInTheDocument();
900
+ });
901
+
902
+ it('"Try it" opens the command menu, and that ticks the step', async () => {
903
+ const user = userEvent.setup();
904
+ mount({ withPalette: true });
905
+ await user.click(within(row(STEP)!).getByRole('button', { name: 'Try it' }));
906
+ expect(screen.getByRole('combobox', { name: 'Search or run a command' })).toHaveFocus();
907
+ await user.keyboard('{Escape}');
908
+ expect(isDone(STEP)).toBe(true);
909
+ });
910
+
911
+ it('ticks when the menu is opened any other way, and remembers it per account', async () => {
912
+ const user = userEvent.setup();
913
+ const { unmount } = mount({ withPalette: true });
914
+ await user.keyboard('{Control>}k{/Control}');
915
+ expect(screen.getByRole('combobox', { name: 'Search or run a command' })).toBeInTheDocument();
916
+ expect(isDone(STEP)).toBe(true);
917
+ expect(window.localStorage.getItem('bevel.onboarding.commandMenuOpened.juan@bevel.software')).toBe('1');
918
+ unmount();
919
+ mount();
920
+ expect(isDone(STEP)).toBe(true);
921
+ });
922
+ });
923
+
924
+ /**
925
+ * The first-page step reads the file tree. Until the tree is in, the guide
926
+ * looks absent and the first page unwritten, so the list waits for it rather
927
+ * than showing a shorter, falsely open one.
928
+ */
929
+ describe('GetStartedColumn: the file tree', () => {
930
+ it('stays hidden until the tree has loaded', () => {
931
+ const { rerender } = mount({ files: null });
932
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
933
+ rerender(columnUi({}));
934
+ expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
935
+ expect(row('Read “How to get started”')).not.toBeNull();
936
+ });
937
+
938
+ 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`] });
940
+ await waitFor(() => expect(fetchStarterPacksMock).toHaveBeenCalled());
941
+ expect(isDone('Write your first page')).toBe(false);
942
+ unmount();
943
+ mount({ files: [...STARTER_TREE, `${KB}/KnowledgeBase/Sales/Access.md`] });
944
+ await waitFor(() => expect(isDone('Write your first page')).toBe(true));
945
+ });
946
+ });
947
+
948
+ describe('GetStartedColumn: getting out of the way', () => {
949
+ it('stays dismissed once closed, across remounts', async () => {
950
+ const { unmount } = mount();
951
+ await userEvent.click(screen.getByRole('button', { name: 'Dismiss Get set up' }));
952
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
953
+ expect(window.localStorage.getItem('bevel.onboarding.setupDismissed.juan@bevel.software')).toBe('1');
954
+ unmount();
955
+ mount();
956
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
957
+ });
958
+
959
+ /**
960
+ * The notes are per browser, so a tab already open hears another tab's
961
+ * close through `storage` — not at its next reload.
962
+ */
963
+ it('goes when another tab closes it', () => {
964
+ mount();
965
+ expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
966
+ const key = 'bevel.onboarding.setupDismissed.juan@bevel.software';
967
+ window.localStorage.setItem(key, '1');
968
+ act(() => {
969
+ window.dispatchEvent(new StorageEvent('storage', { key, newValue: '1' }));
970
+ });
971
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
972
+ });
973
+
974
+ it('ticks the guide when another tab opened it', () => {
975
+ mount();
976
+ expect(isDone('Read “How to get started”')).toBe(false);
977
+ const key = 'bevel.onboarding.readGuide.juan@bevel.software';
978
+ window.localStorage.setItem(key, '1');
979
+ act(() => {
980
+ window.dispatchEvent(new StorageEvent('storage', { key, newValue: '1' }));
981
+ });
982
+ expect(isDone('Read “How to get started”')).toBe(true);
983
+ });
984
+
985
+ it('is not shown on the welcome page', () => {
986
+ mount({ route: WELCOME_PATH });
987
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
988
+ });
989
+
990
+ it('is shown in an ordinary laptop window', () => {
991
+ setViewportWidth(1000);
992
+ mount();
993
+ expect(screen.getByRole('complementary', { name: 'Get set up' })).toBeInTheDocument();
994
+ });
995
+
996
+ it('is not shown at or below 900px, where the sidebar turns into a drawer', () => {
997
+ setViewportWidth(900);
998
+ mount();
999
+ expect(screen.queryByRole('complementary', { name: 'Get set up' })).not.toBeInTheDocument();
1000
+ });
1001
+ });