@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
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { render, renderHook, screen, cleanup, waitFor } from '@testing-library/react';
2
+ import { act, render, screen, cleanup } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
5
5
  import { AuthContext } from '../../auth/state/auth.context';
@@ -13,16 +13,19 @@ import { POST_LOGIN_REDIRECT_KEY } from '../../auth/services/sso';
13
13
  import { WELCOME_PATH } from '../paths';
14
14
  import { resetOnboardingForTests } from '../state/onboarding';
15
15
  import { configureMcpUrl } from '../../../shared/mcp';
16
- import { setSidebarCollapsed, useSidebar } from '../../layout/state/sidebar';
17
16
  import { SidebarFrame } from '../../layout/components/SidebarFrame';
18
17
  import { SIDEBAR_HEADER_TESTID } from '../../../shared/theme/header';
18
+ import { AGENT_RECHECK_MS } from '../state/agent-connection';
19
+ import type { AgentConnection } from '../services/agent-connection.api';
20
+ import { EventBusContext, type EventBusContextValue } from '../../workflow/state/event-bus.context';
21
+ import type { WorkflowEvent, WorkflowEventPayload } from '@bevel-software/platform-shared';
19
22
 
20
23
  /**
21
24
  * The onboarding contract, end to end on the client:
22
25
  *
23
- * - `/` redirects to the welcome page ONCE, on an account the server says is
24
- * not onboarded — and never hijacks anything after that first greeting.
25
- * - the pill outlives the redirect: it stays until × or Done, exactly two.
26
+ * - `/` never redirects to the welcome page; it lands on Knowledge (or a
27
+ * carried deep link), even for an account that is not onboarded.
28
+ * - the pill is the reminder: it stays until × or Done, exactly two.
26
29
  * - Done concludes (server write + navigation); the skip link and the copy
27
30
  * button conclude NOTHING — leaving and copying are not promises.
28
31
  */
@@ -35,6 +38,17 @@ const { authFetchMock } = vi.hoisted(() => ({
35
38
  }));
36
39
  vi.mock('../../../lib/api', () => ({ authFetch: authFetchMock }));
37
40
 
41
+ /**
42
+ * The agent-connection question has its own seam, so the page's one ask never
43
+ * shows up in `authFetch` — every assertion above about what DID or did NOT
44
+ * reach the server stays about the onboarding write alone. Default: nobody
45
+ * has connected yet.
46
+ */
47
+ const { fetchAgentConnectionMock } = vi.hoisted(() => ({
48
+ fetchAgentConnectionMock: vi.fn<() => Promise<AgentConnection>>(),
49
+ }));
50
+ vi.mock('../services/agent-connection.api', () => ({ fetchAgentConnection: fetchAgentConnectionMock }));
51
+
38
52
  /**
39
53
  * The `RequestInit` of a recorded `authFetch` call.
40
54
  *
@@ -52,38 +66,17 @@ const newUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software'
52
66
  /** The same account after the server has recorded the onboarding as done. */
53
67
  const doneUser = () => authValue({ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: true } });
54
68
 
55
- /** Reads the sidebar store the way a component would. */
56
- function sidebarState() {
57
- return renderHook(() => useSidebar()).result.current;
58
- }
59
-
60
- /** Where we are, whether we got here by being greeted, and any carried link. */
69
+ /** Where we are. */
61
70
  function LocationProbe() {
62
- const { pathname, state } = useLocation();
63
- const s = state as { greeting?: boolean; returnTo?: string | null } | null;
64
- return (
65
- <>
66
- <div data-testid="pathname">{pathname}</div>
67
- <div data-testid="greeting">{String(s?.greeting === true)}</div>
68
- <div data-testid="returnTo">{s?.returnTo ?? ''}</div>
69
- </>
70
- );
71
+ return <div data-testid="pathname">{useLocation().pathname}</div>;
71
72
  }
72
73
 
73
- /** The welcome page as the first-sign-in redirect leaves it: greeted. */
74
- const greeted = { pathname: WELCOME_PATH, state: { greeting: true } };
75
-
76
74
  /**
77
75
  * Render `ui` inside the three contexts the onboarding actually reads — a
78
76
  * router at `route`, an auth context holding `auth`, and the toast provider —
79
- * plus the location probe every redirect assertion below looks at. `route`
80
- * takes a location object when a test needs to arrive as the greeting does.
77
+ * plus the location probe every redirect assertion below looks at.
81
78
  */
82
- function mount(
83
- ui: React.ReactNode,
84
- auth = newUser(),
85
- route: string | { pathname: string; state?: unknown } = '/',
86
- ) {
79
+ function mount(ui: React.ReactNode, auth = newUser(), route = '/') {
87
80
  return render(
88
81
  <MemoryRouter initialEntries={[route]}>
89
82
  <AuthContext.Provider value={auth}>
@@ -107,6 +100,7 @@ const landingRoutes = (
107
100
  beforeEach(() => {
108
101
  resetOnboardingForTests();
109
102
  authFetchMock.mockClear();
103
+ fetchAgentConnectionMock.mockReset().mockResolvedValue({ connected: false });
110
104
  sessionStorage.clear();
111
105
  });
112
106
 
@@ -137,17 +131,15 @@ afterEach(() => {
137
131
  vi.unstubAllGlobals();
138
132
  });
139
133
 
140
- describe('RootLanding: the one-time greeting', () => {
141
- it('sends a brand-new account to the welcome page', () => {
142
- mount(landingRoutes);
143
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
144
- });
145
-
146
- // The flag the page reads to know this arrival is a ceremony rather than a
147
- // visit — the sidebar collapse hangs off it, and only this navigation sets it.
148
- it('marks the automatic redirect as a greeting', () => {
134
+ /**
135
+ * `/` never sends anyone to the welcome page — not even a brand-new account.
136
+ * Choosing where the knowledge lives is the only step before the app;
137
+ * connecting an agent waits in the pill and the Get set up list.
138
+ */
139
+ describe('RootLanding', () => {
140
+ it('sends a brand-new account straight to Knowledge, not the welcome page', () => {
149
141
  mount(landingRoutes);
150
- expect(screen.getByTestId('greeting')).toHaveTextContent('true');
142
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
151
143
  });
152
144
 
153
145
  it('sends everyone the server marked done straight to Knowledge', () => {
@@ -155,10 +147,13 @@ describe('RootLanding: the one-time greeting', () => {
155
147
  expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
156
148
  });
157
149
 
158
- // Optional-field semantics: an ABSENT flag (old fixture, cached session)
159
- // must never resurrect the welcome flow. Only an explicit false onboards.
160
- it('treats a missing flag as done, not as new', () => {
161
- mount(landingRoutes, authValue());
150
+ it('lands signed out (or providerless) on Knowledge too', () => {
151
+ render(
152
+ <MemoryRouter initialEntries={['/']}>
153
+ {landingRoutes}
154
+ <LocationProbe />
155
+ </MemoryRouter>,
156
+ );
162
157
  expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
163
158
  });
164
159
 
@@ -177,13 +172,11 @@ describe('RootLanding: the one-time greeting', () => {
177
172
  expect(sessionStorage.getItem(POST_LOGIN_REDIRECT_KEY)).toBeNull();
178
173
  });
179
174
 
180
- it('greets a brand-new account first, handing the link to the welcome page', () => {
175
+ it('sends a brand-new account to the stashed deep link as well', () => {
181
176
  const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
182
177
  sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
183
178
  mount(landingRoutes);
184
- expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
185
- expect(screen.getByTestId('greeting')).toHaveTextContent('true');
186
- expect(screen.getByTestId('returnTo')).toHaveTextContent(DEEP);
179
+ expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
187
180
  });
188
181
 
189
182
  it('discards a stash that is not an in-app path — never an off-site redirect', () => {
@@ -192,27 +185,30 @@ describe('RootLanding: the one-time greeting', () => {
192
185
  expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
193
186
  });
194
187
 
195
- it('greets ONCE: after the welcome page has been seen, / goes to Knowledge', async () => {
188
+ /**
189
+ * The SSO callback scrubs its URL behind the router's back, so the router
190
+ * still matches `/auth/<key>/callback` — which the shell routes here. The
191
+ * carried link must survive that path just the same.
192
+ */
193
+ it('lands an /auth/* callback on the stashed deep link', () => {
194
+ const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
195
+ sessionStorage.setItem(POST_LOGIN_REDIRECT_KEY, DEEP);
196
196
  mount(
197
197
  <Routes>
198
- <Route path="/" element={<RootLanding />} />
199
- <Route path={WELCOME_PATH} element={<WelcomePage />} />
200
- <Route path="/workspace" element={<div>knowledge</div>} />
198
+ <Route path="/auth/*" element={<RootLanding />} />
199
+ <Route path="*" element={<div>elsewhere</div>} />
201
200
  </Routes>,
201
+ newUser(),
202
+ '/auth/microsoft/callback',
202
203
  );
203
- // Landed on the real page, which marks `welcomed` on mount.
204
- await screen.findByRole('heading', { name: /Welcome, Juan/ });
205
- cleanup();
206
- // A fresh visit to `/` — same account, same browser.
207
- mount(landingRoutes);
208
- expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace');
204
+ expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
209
205
  });
210
206
  });
211
207
 
212
208
  describe('WelcomePage', () => {
213
- // Default: the ordinary visit, from the sidebar pill. The greeting — the
214
- // one-time redirect — is the special case, and says so at each call site.
215
- const mountPage = (auth = newUser(), route: string | typeof greeted = WELCOME_PATH) =>
209
+ // Every arrival is a visit — from the sidebar pill, the Get set up list or
210
+ // a typed URL; nothing navigates here on its own.
211
+ const mountPage = (auth = newUser()) =>
216
212
  mount(
217
213
  <Routes>
218
214
  <Route path={WELCOME_PATH} element={<WelcomePage />} />
@@ -220,7 +216,7 @@ describe('WelcomePage', () => {
220
216
  <Route path="/skills-and-tools/yours" element={<div>your plugin</div>} />
221
217
  </Routes>,
222
218
  auth,
223
- route,
219
+ WELCOME_PATH,
224
220
  );
225
221
 
226
222
  it('addresses the person by first name', () => {
@@ -229,40 +225,14 @@ describe('WelcomePage', () => {
229
225
  });
230
226
 
231
227
  /**
232
- * The entrance must BEGIN on a painted frame. A CSS animation runs on the
233
- * document timeline whether or not the browser is producing frames, so an
234
- * animation attached at mount can elapse entirely during a cold boot and
235
- * never be seen — the bug that made this page "just appear" at every
236
- * duration we tried. Held invisible first, animating second.
228
+ * Nobody is greeted any more, so the page simply exists: no hold, no fade,
229
+ * and the nav it was opened from stays exactly where it is.
237
230
  */
238
- it('starts its entrance on a painted frame, not at mount', async () => {
239
- mountPage(newUser(), greeted);
240
- const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
241
- const body = screen.getByText(/company’s shared library/).parentElement!;
242
- // An inline style, deliberately — a utility class would depend on Tailwind
243
- // having compiled it, and that is exactly what failed silently before.
244
- expect(title.style.opacity).toBe('0');
245
- expect(body.style.opacity).toBe('0');
246
- await waitFor(() => {
247
- expect(title.className).toContain('animate-onboarding-greeting');
248
- expect(body.className).toContain('animate-onboarding-body');
249
- });
250
- // …and never both at once: held invisible and animating would fight.
251
- expect(title.style.opacity).toBe('');
252
- expect(body.style.opacity).toBe('');
253
- });
254
-
255
- /**
256
- * Being welcomed happens once. Opening the same page from the pill later is
257
- * a visit, and a 2.6s arrival every time you come back to copy your MCP
258
- * snippet is a page you learn to dread — so there is no hold and no fade,
259
- * only the page.
260
- */
261
- it('does not replay the entrance when you open it from the pill', () => {
231
+ it('appears as it is, with no entrance to play', () => {
262
232
  mountPage();
263
233
  const title = screen.getByRole('heading', { name: 'Welcome, Juan' });
264
234
  expect(title.style.opacity).toBe('');
265
- expect(title.className).not.toContain('animate-onboarding-greeting');
235
+ expect(title.className).not.toContain('animate-onboarding');
266
236
  });
267
237
 
268
238
  // However the sign-in record spells it. The page addressed to one person is
@@ -277,66 +247,6 @@ describe('WelcomePage', () => {
277
247
  expect(screen.getByRole('heading', { name: 'Welcome, there' })).toBeInTheDocument();
278
248
  });
279
249
 
280
- /**
281
- * The nav gets out of the way for the greeting and STAYS out — there is no
282
- * restore. Putting it back meant leaving a screen with no nav and arriving
283
- * at one where the nav had opened itself, which is the app rearranging a
284
- * page you asked for. Whether the sidebar shows is the toolbar toggle's to
285
- * say, and after the greeting it says whatever it said last.
286
- */
287
- it('collapses the sidebar for the greeting, without animating it', () => {
288
- setSidebarCollapsed(false);
289
- mountPage(newUser(), greeted);
290
- expect(sidebarState()).toMatchObject({ collapsed: true, instant: true });
291
- });
292
-
293
- it('leaves it collapsed when you go to your own plugin', async () => {
294
- setSidebarCollapsed(false);
295
- mountPage(newUser(), greeted);
296
- await userEvent.click(screen.getByRole('button', { name: /Go to your skills/ }));
297
- expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
298
- expect(sidebarState().collapsed).toBe(true);
299
- });
300
-
301
- it('leaves it collapsed after Done too', async () => {
302
- setSidebarCollapsed(false);
303
- mountPage(newUser(), greeted);
304
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
305
- expect(sidebarState().collapsed).toBe(true);
306
- });
307
-
308
- /**
309
- * The one case where the nav is showing on the way out: you opened it
310
- * yourself while you were here. The page collapses once, on arrival, and
311
- * never touches the store again — so your gesture is the last word.
312
- */
313
- it('respects a sidebar you opened yourself while reading the page', async () => {
314
- setSidebarCollapsed(false);
315
- mountPage(newUser(), greeted);
316
- expect(sidebarState().collapsed).toBe(true);
317
- setSidebarCollapsed(false); // …the toolbar toggle, from the user's hand
318
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
319
- expect(sidebarState().collapsed).toBe(false);
320
- });
321
-
322
- it('leaves it collapsed for someone who arrived that way', () => {
323
- setSidebarCollapsed(true);
324
- const { unmount } = mountPage(newUser(), greeted);
325
- expect(sidebarState().collapsed).toBe(true);
326
- unmount();
327
- expect(sidebarState().collapsed).toBe(true);
328
- });
329
-
330
- // Reached from the pill it is a page, not a ceremony: the nav it was just
331
- // clicked in stays exactly where it is.
332
- it('leaves the sidebar alone when you open it from the pill', () => {
333
- setSidebarCollapsed(false);
334
- const { unmount } = mountPage();
335
- expect(sidebarState().collapsed).toBe(false);
336
- unmount();
337
- expect(sidebarState().collapsed).toBe(false);
338
- });
339
-
340
250
  it('shows one snippet at a time, following the picker', async () => {
341
251
  mountPage();
342
252
  // Claude default: the bare hosted URL, not a config.
@@ -687,24 +597,6 @@ describe('WelcomePage', () => {
687
597
  expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
688
598
  });
689
599
 
690
- /**
691
- * A deep link that survived the SSO round-trip retargets BOTH exits: the
692
- * greeting concluded by discarding the page someone was sent would cost
693
- * them the reason they came. The skip label says where it now goes.
694
- */
695
- it('keeps a carried deep link: Done lands on it, and the skip link says so', async () => {
696
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
697
- const arrivedWithLink = { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } };
698
- mountPage(newUser(), arrivedWithLink);
699
- expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
700
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
701
- expect(authFetchMock).toHaveBeenCalledWith(
702
- '/api/auth/onboarding-done',
703
- expect.objectContaining({ method: 'POST' }),
704
- );
705
- expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
706
- });
707
-
708
600
  /**
709
601
  * `AppRegistry.welcomeExit` moves where a new person starts. WHERE that is,
710
602
  * is a property of the product: core sends them to their own skills shelf,
@@ -717,12 +609,7 @@ describe('WelcomePage', () => {
717
609
  * default: the seam must be invisible to a deployment that does not use it.
718
610
  */
719
611
  describe('welcomeExit', () => {
720
- const mountWithExit = (
721
- welcomeExit: { path: string; label: string } | undefined,
722
- // Same shape `mount` accepts — `typeof greeted` would pin `state` to
723
- // `{ greeting: boolean }` and reject the deep-link case below.
724
- route: string | { pathname: string; state?: unknown } = greeted,
725
- ) =>
612
+ const mountWithExit = (welcomeExit: { path: string; label: string } | undefined) =>
726
613
  mount(
727
614
  <AppRegistryContext.Provider value={{ ...EMPTY_REGISTRY, welcomeExit }}>
728
615
  <Routes>
@@ -732,7 +619,7 @@ describe('WelcomePage', () => {
732
619
  </Routes>
733
620
  </AppRegistryContext.Provider>,
734
621
  newUser(),
735
- route,
622
+ WELCOME_PATH,
736
623
  );
737
624
 
738
625
  it('sends both exits to the configured destination', async () => {
@@ -760,21 +647,170 @@ describe('WelcomePage', () => {
760
647
  await userEvent.click(screen.getByRole('button', { name: 'Done' }));
761
648
  expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools/yours');
762
649
  });
650
+ });
651
+ });
763
652
 
764
- /**
765
- * A deep link still outranks it. Someone who followed a link is owed that
766
- * link, and no amount of deployment configuration may eat an intention.
767
- */
768
- it('does not override a carried deep link', async () => {
769
- const DEEP = '/workspace/main/knowledge-base/KnowledgeBase/Start here.md';
770
- mountWithExit(
771
- { path: '/skills-and-tools/yours', label: 'Go to your skills' },
772
- { pathname: WELCOME_PATH, state: { greeting: true, returnTo: DEEP } },
773
- );
774
- expect(screen.getByRole('button', { name: /Continue to your link/ })).toBeInTheDocument();
775
- await userEvent.click(screen.getByRole('button', { name: 'Done' }));
776
- expect(screen.getByTestId('pathname')).toHaveTextContent(DEEP);
653
+ /**
654
+ * A stand-in for the tab's event stream: what the server would push, pushed
655
+ * by the test.
656
+ */
657
+ function fakeBus() {
658
+ const handlers = new Map<string, Set<(e: WorkflowEvent) => void>>();
659
+ const value: EventBusContextValue = {
660
+ subscribe: (kind, handler) => {
661
+ const set = handlers.get(kind) ?? new Set();
662
+ set.add(handler as (e: WorkflowEvent) => void);
663
+ handlers.set(kind, set);
664
+ return () => set.delete(handler as (e: WorkflowEvent) => void);
665
+ },
666
+ setFocus: () => {},
667
+ watchWorkspace: () => () => {},
668
+ };
669
+ const emit = (event: WorkflowEventPayload) => {
670
+ act(() => {
671
+ for (const h of handlers.get(event.kind) ?? []) {
672
+ h({ id: 1, ts: new Date().toISOString(), ...event } as WorkflowEvent);
673
+ }
674
+ });
675
+ };
676
+ return { value, emit, listening: (kind: string) => (handlers.get(kind)?.size ?? 0) > 0 };
677
+ }
678
+
679
+ const ARRIVED: WorkflowEventPayload = {
680
+ kind: 'agent-connected',
681
+ forUserId: 'u1',
682
+ client: 'Claude',
683
+ agentKind: 'agent',
684
+ at: '2026-10-07T12:00:00.000Z',
685
+ };
686
+
687
+ /**
688
+ * "Did it work?" answered on the page: a quiet waiting line that turns into
689
+ * a plain "Connected" the moment the server says the agent's first call
690
+ * landed — and that conclusion does what Done does to the onboarding, once.
691
+ * The page asks once on arrival and listens from then on; it never asks on
692
+ * a timer.
693
+ */
694
+ describe('WelcomePage: is your agent connected?', () => {
695
+ const mountPage = (auth = newUser(), bus = fakeBus()) => {
696
+ const rendered = mount(
697
+ <EventBusContext.Provider value={bus.value}>
698
+ <Routes>
699
+ <Route path={WELCOME_PATH} element={<WelcomePage />} />
700
+ </Routes>
701
+ </EventBusContext.Provider>,
702
+ auth,
703
+ WELCOME_PATH,
704
+ );
705
+ return { ...rendered, bus };
706
+ };
707
+
708
+ /** Calls to the onboarding write — the one `markDone` makes. */
709
+ const doneWrites = () =>
710
+ authFetchMock.mock.calls.filter((c) => (c as unknown[])[0] === '/api/auth/onboarding-done').length;
711
+
712
+ /** Let the pending answer land. */
713
+ const settle = () => act(async () => {});
714
+
715
+ afterEach(() => {
716
+ vi.useRealTimers();
717
+ Reflect.deleteProperty(document, 'hidden');
718
+ });
719
+
720
+ it('waits quietly, turns green when the server says the agent arrived, and concludes once', async () => {
721
+ const { bus } = mountPage();
722
+ await settle();
723
+ // One live region, the same element in both states, so the change is announced.
724
+ const status = screen.getByText('Waiting for your agent…').closest('[role="status"]') as HTMLElement;
725
+ expect(status).toHaveAttribute('aria-live', 'polite');
726
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
727
+ expect(doneWrites()).toBe(0);
728
+ expect(bus.listening('agent-connected')).toBe(true);
729
+
730
+ bus.emit(ARRIVED);
731
+ expect(status).toHaveTextContent('Connected. Your agent reached this knowledge base.');
732
+ expect(status).not.toHaveTextContent('Waiting');
733
+ expect(doneWrites()).toBe(1);
734
+ expect(fetchInit(0)?.body).toBe(JSON.stringify({ userId: 'u1' }));
735
+
736
+ // Connected is final: nothing more is asked, and no second conclusion.
737
+ bus.emit(ARRIVED);
738
+ await settle();
739
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
740
+ expect(doneWrites()).toBe(1);
741
+ });
742
+
743
+ it("stays waiting on another account's agent", async () => {
744
+ const { bus } = mountPage();
745
+ await settle();
746
+ bus.emit({ ...ARRIVED, forUserId: 'u2' });
747
+ expect(screen.getByText('Waiting for your agent…')).toBeInTheDocument();
748
+ expect(doneWrites()).toBe(0);
749
+ });
750
+
751
+ it('shows the green state straight away for an agent connected before you arrived', async () => {
752
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude' });
753
+ mountPage();
754
+ // Before the first answer the line is empty, never a flash of "Waiting".
755
+ expect(screen.queryByText('Waiting for your agent…')).not.toBeInTheDocument();
756
+ await settle();
757
+ expect(screen.getByText('Connected. Your agent reached this knowledge base.')).toBeInTheDocument();
758
+ expect(doneWrites()).toBe(1);
759
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
760
+ });
761
+
762
+ /**
763
+ * Someone who finished the onboarding and came back to copy a snippet is
764
+ * waiting on nothing: no ask, no listening, no "Waiting" line, no second
765
+ * conclusion.
766
+ */
767
+ it('asks nothing for an account that already finished the onboarding', async () => {
768
+ fetchAgentConnectionMock.mockResolvedValue({ connected: true, client: 'Claude' });
769
+ const { bus } = mountPage(doneUser());
770
+ await settle();
771
+ expect(fetchAgentConnectionMock).not.toHaveBeenCalled();
772
+ expect(bus.listening('agent-connected')).toBe(false);
773
+ expect(screen.queryByText('Waiting for your agent…')).not.toBeInTheDocument();
774
+ expect(doneWrites()).toBe(0);
775
+ });
776
+
777
+ /**
778
+ * A failed ask reads as "not yet", and nothing retries it on a timer: the
779
+ * event says when it changes, and a return to the tab asks again — once
780
+ * per {@link AGENT_RECHECK_MS} at most — for an agent that connected
781
+ * while the stream was down.
782
+ */
783
+ it('reads a failed ask as "not yet", never retries on a timer, and asks again on a return to the tab', async () => {
784
+ vi.useFakeTimers();
785
+ fetchAgentConnectionMock.mockRejectedValueOnce(new Error('503')).mockResolvedValue({ connected: false });
786
+ mountPage();
787
+ await act(async () => {
788
+ await vi.advanceTimersByTimeAsync(0);
777
789
  });
790
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
791
+ expect(screen.getByText('Waiting for your agent…')).toBeInTheDocument();
792
+ await act(async () => {
793
+ await vi.advanceTimersByTimeAsync(AGENT_RECHECK_MS * 10);
794
+ });
795
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(1);
796
+
797
+ act(() => {
798
+ window.dispatchEvent(new Event('focus'));
799
+ });
800
+ await act(async () => {
801
+ await vi.advanceTimersByTimeAsync(0);
802
+ });
803
+ expect(fetchAgentConnectionMock).toHaveBeenCalledTimes(2);
804
+ expect(doneWrites()).toBe(0);
805
+ });
806
+
807
+ it('stops listening when you leave the page', async () => {
808
+ const { unmount, bus } = mountPage();
809
+ await settle();
810
+ unmount();
811
+ expect(bus.listening('agent-connected')).toBe(false);
812
+ bus.emit(ARRIVED);
813
+ expect(doneWrites()).toBe(0);
778
814
  });
779
815
  });
780
816
 
@@ -792,9 +828,6 @@ describe('ConnectAgentPill', () => {
792
828
  mountPill();
793
829
  await userEvent.click(screen.getByRole('button', { name: 'Connect your agent' }));
794
830
  expect(screen.getByTestId('pathname')).toHaveTextContent(WELCOME_PATH);
795
- // …as a plain visit. The pill opens the page; it does not re-run the
796
- // first-sign-in ceremony that folds the nav it lives in away.
797
- expect(screen.getByTestId('greeting')).toHaveTextContent('false');
798
831
  });
799
832
 
800
833
  it('renders nothing once the server says done', () => {