@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,832 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { act } from 'react';
5
+ import { MemoryRouter, useLocation } from 'react-router-dom';
6
+ import { DEFAULT_BRANCH, type FileTreeEntry } from '@bevel-software/platform-shared';
7
+ import { SearchPalette } from '../SearchPalette';
8
+ import { GitContext, type GitContextValue } from '../../../git/state/git.context';
9
+ import { WorkspaceContext } from '../../../workspace/state/workspace.context';
10
+ import { makeWorkspaceFixture } from '../../../workspace/__tests__/testFixtures';
11
+ import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
12
+ import { AuthContext } from '../../../auth/state/auth.context';
13
+ import { authValue } from '../../../library/__tests__/auth-harness';
14
+ import { InviteDialogContext } from '../../../onboarding/state/invite-dialog.context';
15
+ import { resetOnboardingForTests } from '../../../onboarding/state/onboarding';
16
+ import { WELCOME_PATH } from '../../../onboarding/paths';
17
+ import { publishEditablePage } from '../../../workspace/state/editable-page';
18
+ import {
19
+ ActiveAppIdContext,
20
+ AppRegistryContext,
21
+ makeRegistry,
22
+ type AdminMenuItem,
23
+ type AppDef,
24
+ } from '../../../../core/registry';
25
+ import type { CommandAction } from '../../commands/actions';
26
+
27
+ const api = vi.hoisted(() => ({
28
+ listSkills: vi.fn(),
29
+ listToolSecrets: vi.fn(),
30
+ listPlugins: vi.fn(),
31
+ }));
32
+ vi.mock('../../../library/services/library.api', async (importOriginal) => ({
33
+ ...(await importOriginal<typeof import('../../../library/services/library.api')>()),
34
+ listSkills: api.listSkills,
35
+ }));
36
+ vi.mock('../../../secrets-vault/services/tool-secrets.api', async (importOriginal) => ({
37
+ ...(await importOriginal<typeof import('../../../secrets-vault/services/tool-secrets.api')>()),
38
+ listToolSecrets: api.listToolSecrets,
39
+ }));
40
+ vi.mock('../../../library/services/plugins.api', async (importOriginal) => ({
41
+ ...(await importOriginal<typeof import('../../../library/services/plugins.api')>()),
42
+ listPlugins: api.listPlugins,
43
+ }));
44
+ // New page's own naming and retrying is `useCreatePage`'s, pinned by the Get
45
+ // set up column's suite; here it is the command that calls it.
46
+ const createPage = vi.hoisted(() => vi.fn<() => Promise<string>>());
47
+ vi.mock('../../../workspace/hooks/useCreatePage', () => ({
48
+ useCreatePage: () => ({ knowledgeRoot: 'knowledge-base/KnowledgeBase', createPage }),
49
+ }));
50
+ // The onboarding write is not what these tests are about.
51
+ vi.mock('../../../../lib/api', () => ({ authFetch: vi.fn(async () => ({ ok: true, status: 200 })) }));
52
+
53
+ const KB = 'knowledge-base';
54
+ const file = (relativePath: string): FileTreeEntry => ({
55
+ name: relativePath.split('/').pop()!,
56
+ relativePath,
57
+ type: 'file',
58
+ });
59
+ const dir = (relativePath: string, children: FileTreeEntry[]): FileTreeEntry => ({
60
+ name: relativePath.split('/').pop()!,
61
+ relativePath,
62
+ type: 'directory',
63
+ children,
64
+ });
65
+
66
+ const TREE = dir('', [
67
+ dir(KB, [
68
+ file(`${KB}/access.md`),
69
+ dir(`${KB}/KnowledgeBase`, [
70
+ file(`${KB}/KnowledgeBase/Onboarding.md`),
71
+ dir(`${KB}/KnowledgeBase/GTM`, [
72
+ file(`${KB}/KnowledgeBase/GTM/access.md`),
73
+ file(`${KB}/KnowledgeBase/GTM/Pricing.md`),
74
+ file(`${KB}/KnowledgeBase/GTM/Team pricing.md`),
75
+ ]),
76
+ ]),
77
+ dir(`${KB}/Plugins`, [dir(`${KB}/Plugins/GTM`, [file(`${KB}/Plugins/GTM/Pricing notes.md`)])]),
78
+ ]),
79
+ ]);
80
+
81
+ function LocationProbe() {
82
+ const location = useLocation();
83
+ return (
84
+ <>
85
+ <div data-testid="location">{location.pathname + location.search}</div>
86
+ <div data-testid="location-state">{JSON.stringify(location.state)}</div>
87
+ </>
88
+ );
89
+ }
90
+
91
+ function adminValue(isAdmin: boolean): AdminContextValue {
92
+ return {
93
+ isAdmin,
94
+ isAdminLoading: false,
95
+ unreadCount: 0,
96
+ lastSeen: null,
97
+ markSeen: () => {},
98
+ refresh: () => {},
99
+ rolesConfigCorrupted: false,
100
+ rolesConfigErrors: [],
101
+ runRolesRecovery: async () => {},
102
+ };
103
+ }
104
+
105
+ /** The two core apps, as the shell merges them into the registry. */
106
+ const APPS: AppDef[] = [
107
+ { id: 'knowledge', label: 'Knowledge', path: '/workspace', order: 10, element: <></> },
108
+ { id: 'skills-tools', label: 'Skills & Tools', path: '/skills-and-tools', order: 20, element: <></> },
109
+ ];
110
+
111
+ const inviteOpen = vi.fn();
112
+
113
+ interface PaletteOptions {
114
+ compact?: boolean;
115
+ admin?: boolean;
116
+ /** The connect-your-agent onboarding is still open. */
117
+ onboardingPending?: boolean;
118
+ openFilePath?: string | null;
119
+ adminMenuItems?: AdminMenuItem[];
120
+ commandActions?: CommandAction[];
121
+ }
122
+
123
+ function renderPalette({
124
+ compact = false,
125
+ admin = true,
126
+ onboardingPending = false,
127
+ openFilePath = null,
128
+ adminMenuItems = [],
129
+ commandActions,
130
+ }: PaletteOptions = {}) {
131
+ const git = {
132
+ status: { branch: 'main', hasUpstream: true, unmergedFromUpstream: false },
133
+ } as unknown as GitContextValue;
134
+ const auth = authValue({
135
+ user: { id: 'u1', email: 'juan@bevel.software', name: 'Juan Viera', onboardingDone: !onboardingPending },
136
+ });
137
+ const registry = makeRegistry({ apps: APPS, adminMenuItems, commandActions });
138
+ return render(
139
+ <MemoryRouter initialEntries={['/workspace/main']}>
140
+ <AppRegistryContext.Provider value={registry}>
141
+ <ActiveAppIdContext.Provider value="knowledge">
142
+ <AuthContext.Provider value={auth}>
143
+ <AdminContext.Provider value={adminValue(admin)}>
144
+ <InviteDialogContext.Provider value={{ open: inviteOpen, invitedRevision: 0 }}>
145
+ <WorkspaceContext.Provider value={makeWorkspaceFixture({ fileTree: TREE, openFilePath })}>
146
+ <GitContext.Provider value={git}>
147
+ <button type="button">Elsewhere</button>
148
+ <SearchPalette compact={compact} />
149
+ <LocationProbe />
150
+ </GitContext.Provider>
151
+ </WorkspaceContext.Provider>
152
+ </InviteDialogContext.Provider>
153
+ </AdminContext.Provider>
154
+ </AuthContext.Provider>
155
+ </ActiveAppIdContext.Provider>
156
+ </AppRegistryContext.Provider>
157
+ </MemoryRouter>,
158
+ );
159
+ }
160
+
161
+ const trigger = () => screen.getByRole('button', { name: /search or run a command/i });
162
+ const input = () => screen.getByRole('combobox', { name: /search or run a command/i });
163
+ const options = () => within(screen.getByRole('listbox')).queryAllByRole('option');
164
+ const group = (name: string) => screen.queryByRole('group', { name });
165
+ const groupRows = (name: string) =>
166
+ within(screen.getByRole('group', { name })).getAllByRole('option').map((o) => o.textContent);
167
+
168
+ beforeEach(() => {
169
+ resetOnboardingForTests();
170
+ publishEditablePage(null);
171
+ inviteOpen.mockReset();
172
+ createPage.mockReset().mockResolvedValue('knowledge-base/KnowledgeBase/Untitled.md');
173
+ api.listSkills.mockReset().mockResolvedValue([
174
+ { name: 'pricing-calculator', description: '', path: 'Plugins/GTM/skills/pricing-calculator' },
175
+ ]);
176
+ api.listToolSecrets.mockReset().mockResolvedValue([
177
+ { slug: 'linear', name: 'Linear', path: 'Plugins/GTM/linear.tool', type: 'http', setup: null, canWrite: false, variables: [] },
178
+ ]);
179
+ api.listPlugins.mockReset().mockResolvedValue([]);
180
+ });
181
+
182
+ describe('SearchPalette', () => {
183
+ it('opens on click with the input focused, and Escape closes it back to the trigger', async () => {
184
+ const user = userEvent.setup();
185
+ renderPalette();
186
+ expect(screen.queryByRole('combobox')).toBeNull();
187
+
188
+ await user.click(trigger());
189
+ expect(input()).toHaveFocus();
190
+ expect(trigger()).toHaveAttribute('aria-expanded', 'true');
191
+
192
+ await user.keyboard('{Escape}');
193
+ expect(screen.queryByRole('combobox')).toBeNull();
194
+ expect(trigger()).toHaveFocus();
195
+ });
196
+
197
+ it('opens on Ctrl+K from anywhere, and Escape returns focus to where it was', async () => {
198
+ const user = userEvent.setup();
199
+ renderPalette();
200
+ const elsewhere = screen.getByRole('button', { name: 'Elsewhere' });
201
+ elsewhere.focus();
202
+
203
+ await user.keyboard('{Control>}k{/Control}');
204
+ expect(input()).toHaveFocus();
205
+
206
+ await user.keyboard('{Escape}');
207
+ expect(screen.queryByRole('combobox')).toBeNull();
208
+ expect(elsewhere).toHaveFocus();
209
+ });
210
+
211
+ it('is reachable by Ctrl+K on a compact toolbar, where the box itself is not drawn', async () => {
212
+ const user = userEvent.setup();
213
+ renderPalette({ compact: true });
214
+ expect(screen.queryByRole('button', { name: /search or run a command/i })).toBeNull();
215
+ await user.keyboard('{Control>}k{/Control}');
216
+ expect(input()).toHaveFocus();
217
+ });
218
+
219
+ it('ignores the shortcut while a modal dialog is up', () => {
220
+ renderPalette();
221
+ const modal = document.createElement('div');
222
+ modal.setAttribute('aria-modal', 'true');
223
+ document.body.appendChild(modal);
224
+ try {
225
+ fireEvent.keyDown(document, { key: 'k', ctrlKey: true });
226
+ expect(screen.queryByRole('combobox')).toBeNull();
227
+ } finally {
228
+ modal.remove();
229
+ }
230
+ });
231
+
232
+ it('filters pages from the Knowledge tree by name, best match first, and never offers access rules or Plugins/', async () => {
233
+ const user = userEvent.setup();
234
+ renderPalette();
235
+ await user.click(trigger());
236
+ await user.type(input(), 'pric');
237
+
238
+ const pages = within(screen.getByRole('group', { name: 'Pages' })).getAllByRole('option');
239
+ expect(pages.map((o) => o.textContent)).toEqual(['PricingGTM', 'Team pricingGTM']);
240
+ expect(screen.queryByText('access')).toBeNull();
241
+ expect(screen.queryByText('Pricing notes')).toBeNull();
242
+ });
243
+
244
+ it('opens the highlighted page on Enter via its workspace path, after arrowing to it', async () => {
245
+ const user = userEvent.setup();
246
+ renderPalette();
247
+ await user.click(trigger());
248
+ await user.type(input(), 'pric');
249
+ await waitFor(() => expect(options().length).toBeGreaterThan(2));
250
+
251
+ // Nothing but pages and items match `pric`, so the first row is a page.
252
+ expect(group('Actions')).toBeNull();
253
+ expect(input()).toHaveAttribute('aria-activedescendant', options()[0].id);
254
+ await user.keyboard('{ArrowDown}');
255
+ expect(options()[1]).toHaveAttribute('aria-selected', 'true');
256
+ expect(input()).toHaveAttribute('aria-activedescendant', options()[1].id);
257
+
258
+ await user.keyboard('{Enter}');
259
+ expect(screen.getByTestId('location')).toHaveTextContent(
260
+ `/workspace/main/${KB}/KnowledgeBase/GTM/Team%20pricing.md`,
261
+ );
262
+ expect(screen.queryByRole('combobox')).toBeNull();
263
+ expect(trigger()).toHaveFocus();
264
+ });
265
+
266
+ it('fetches skills and tools only once the palette opens, and opens one at its item URL', async () => {
267
+ const user = userEvent.setup();
268
+ renderPalette();
269
+ expect(api.listSkills).not.toHaveBeenCalled();
270
+ expect(api.listToolSecrets).not.toHaveBeenCalled();
271
+ expect(api.listPlugins).not.toHaveBeenCalled();
272
+
273
+ await user.click(trigger());
274
+ expect(api.listSkills).toHaveBeenCalledTimes(1);
275
+ expect(api.listToolSecrets).toHaveBeenCalledTimes(1);
276
+ expect(api.listPlugins).toHaveBeenCalledTimes(1);
277
+
278
+ await user.type(input(), 'linear');
279
+ const row = await screen.findByRole('option', { name: /linear/i });
280
+ await user.click(row);
281
+ expect(screen.getByTestId('location')).toHaveTextContent(
282
+ `/workspace/${encodeURIComponent(DEFAULT_BRANCH)}/${KB}/Plugins/GTM/linear.tool`,
283
+ );
284
+ });
285
+
286
+ it('says so when nothing matches', async () => {
287
+ const user = userEvent.setup();
288
+ renderPalette();
289
+ await user.click(trigger());
290
+ await screen.findByRole('option', { name: /linear/i });
291
+ await user.type(input(), 'zzz');
292
+ expect(options()).toHaveLength(0);
293
+ expect(screen.getByRole('status')).toHaveTextContent('Nothing matches “zzz”');
294
+ });
295
+
296
+ it('says the catalog failed, not that nothing matched, when every catalog request fails', async () => {
297
+ api.listSkills.mockRejectedValue(new Error('down'));
298
+ api.listToolSecrets.mockRejectedValue(new Error('down'));
299
+ api.listPlugins.mockRejectedValue(new Error('down'));
300
+ const user = userEvent.setup();
301
+ renderPalette();
302
+ await user.click(trigger());
303
+ await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('Couldn’t load skills, tools and plugins.'));
304
+
305
+ await user.type(input(), 'zzz');
306
+ expect(options()).toHaveLength(0);
307
+ expect(screen.getByRole('status')).toHaveTextContent(
308
+ 'Nothing matches “zzz”. Couldn’t load skills, tools and plugins.',
309
+ );
310
+ });
311
+
312
+ it('groups plugins with skills and tools', async () => {
313
+ api.listPlugins.mockResolvedValue([
314
+ { name: 'gtm', displayName: 'GTM', folders: ['Plugins/GTM'], canRead: true, canWrite: false, isOwner: false, skillCount: 0, toolCount: 0 },
315
+ ]);
316
+ const user = userEvent.setup();
317
+ renderPalette();
318
+ await user.click(trigger());
319
+ await user.type(input(), 'gtm');
320
+ const group = await screen.findByRole('group', { name: 'Skills, tools & plugins' });
321
+ expect(within(group).getByRole('option', { name: /GTM/ })).toBeInTheDocument();
322
+ });
323
+
324
+ it('keeps focus in the input when the panel around the rows is pressed, so the keyboard still drives it', async () => {
325
+ const user = userEvent.setup();
326
+ const elsewhere = () => screen.getByRole('button', { name: 'Elsewhere' });
327
+ renderPalette();
328
+ elsewhere().focus();
329
+ await user.keyboard('{Control>}k{/Control}');
330
+ await screen.findByRole('option', { name: /linear/i });
331
+
332
+ await user.click(screen.getByRole('status'));
333
+ await user.click(screen.getByRole('listbox'));
334
+ expect(input()).toHaveFocus();
335
+
336
+ // Escape is still the input's, so focus goes back to where it was.
337
+ await user.keyboard('{Escape}');
338
+ expect(screen.queryByRole('combobox')).toBeNull();
339
+ expect(elsewhere()).toHaveFocus();
340
+ });
341
+
342
+ it('closes on Tab with focus on the search box, for the Tab to move on from', async () => {
343
+ const user = userEvent.setup();
344
+ renderPalette();
345
+ await user.click(trigger());
346
+ // `fireEvent`, not `user.keyboard`: user-event computes the Tab
347
+ // destination from the unmounted input and throws. What is pinned here is
348
+ // the half the palette owns — focus is on the box when the keydown ends,
349
+ // which is where the browser's own Tab then starts from.
350
+ fireEvent.keyDown(input(), { key: 'Tab' });
351
+ expect(screen.queryByRole('combobox')).toBeNull();
352
+ expect(trigger()).toHaveFocus();
353
+ });
354
+
355
+ it('closes on an outside click without moving focus', async () => {
356
+ const user = userEvent.setup();
357
+ renderPalette();
358
+ await user.click(trigger());
359
+ await user.click(screen.getByRole('button', { name: 'Elsewhere' }));
360
+ expect(screen.queryByRole('combobox')).toBeNull();
361
+ expect(screen.getByRole('button', { name: 'Elsewhere' })).toHaveFocus();
362
+ });
363
+ });
364
+
365
+ describe('SearchPalette: commands', () => {
366
+ it('suggests a few commands above the pages before anything is typed', async () => {
367
+ const user = userEvent.setup();
368
+ renderPalette({ onboardingPending: true });
369
+ await user.click(trigger());
370
+
371
+ const groups = within(screen.getByRole('listbox')).getAllByRole('group');
372
+ expect(groups[0]).toHaveAccessibleName('Actions');
373
+ expect(groups[1]).toHaveAccessibleName('Pages');
374
+ expect(groupRows('Actions')).toEqual([
375
+ 'New pageC (shortcut C)',
376
+ 'Invite people',
377
+ 'Connect your agent',
378
+ 'Go to Skills & ToolsGS (shortcut G then S)',
379
+ ]);
380
+ // Nothing is highlighted until a row is picked (see the next test).
381
+ expect(input()).not.toHaveAttribute('aria-activedescendant');
382
+ });
383
+
384
+ it('runs nothing on Enter with an empty query, until a row is picked with the arrows', async () => {
385
+ const user = userEvent.setup();
386
+ renderPalette();
387
+ await user.click(trigger());
388
+ await user.keyboard('{Enter}');
389
+ expect(createPage).not.toHaveBeenCalled();
390
+ expect(input()).toHaveFocus();
391
+ expect(options().some((o) => o.getAttribute('aria-selected') === 'true')).toBe(false);
392
+
393
+ // ↑ from no row starts at the bottom; ↓ from no row at the top.
394
+ await user.keyboard('{ArrowUp}');
395
+ expect(options()[options().length - 1]).toHaveAttribute('aria-selected', 'true');
396
+ await user.keyboard('{Escape}');
397
+ await user.click(trigger());
398
+ await user.keyboard('{ArrowDown}');
399
+ expect(input()).toHaveAttribute('aria-activedescendant', options()[0].id);
400
+ await user.keyboard('{Enter}');
401
+ expect(createPage).toHaveBeenCalledTimes(1);
402
+ });
403
+
404
+ it('highlights a hovered row with an empty query, and takes the best match again once something is typed', async () => {
405
+ const user = userEvent.setup();
406
+ renderPalette();
407
+ await user.click(trigger());
408
+ await user.hover(screen.getByRole('option', { name: 'Invite people' }));
409
+ expect(screen.getByRole('option', { name: 'Invite people' })).toHaveAttribute('aria-selected', 'true');
410
+
411
+ await user.type(input(), 'invite');
412
+ expect(input()).toHaveAttribute('aria-activedescendant', options()[0].id);
413
+ // Clearing the query clears the highlight with it.
414
+ await user.clear(input());
415
+ expect(input()).not.toHaveAttribute('aria-activedescendant');
416
+ await user.keyboard('{Enter}');
417
+ expect(inviteOpen).not.toHaveBeenCalled();
418
+ });
419
+
420
+ it('suggests no agent connection once that onboarding is over', async () => {
421
+ const user = userEvent.setup();
422
+ renderPalette({ onboardingPending: false });
423
+ await user.click(trigger());
424
+ expect(groupRows('Actions')).toEqual([
425
+ 'New pageC (shortcut C)',
426
+ 'Invite people',
427
+ 'Go to Skills & ToolsGS (shortcut G then S)',
428
+ ]);
429
+ // ...but it is still there to be typed for.
430
+ await user.type(input(), 'connect');
431
+ expect(groupRows('Actions')).toEqual(['Connect your agent']);
432
+ });
433
+
434
+ it('ranks commands by label and keywords, listed before the pages that match too', async () => {
435
+ const user = userEvent.setup();
436
+ renderPalette();
437
+ await user.click(trigger());
438
+
439
+ await user.type(input(), 'go to');
440
+ expect(groupRows('Actions')).toEqual([
441
+ 'Go to KnowledgeGK (shortcut G then K)',
442
+ 'Go to Skills & ToolsGS (shortcut G then S)',
443
+ ]);
444
+
445
+ await user.clear(input());
446
+ await user.type(input(), 'team');
447
+ expect(groupRows('Actions')).toEqual(['Invite people']);
448
+
449
+ await user.clear(input());
450
+ await user.type(input(), 'on');
451
+ const groups = within(screen.getByRole('listbox')).getAllByRole('group');
452
+ expect(groups[0]).toHaveAccessibleName('Actions');
453
+ expect(groupRows('Pages')).toContain('OnboardingKnowledge');
454
+ });
455
+
456
+ it('keeps admin-only commands from members', async () => {
457
+ const user = userEvent.setup();
458
+ renderPalette({ admin: false });
459
+ await user.click(trigger());
460
+ expect(groupRows('Actions')).toEqual(['New pageC (shortcut C)', 'Go to Skills & ToolsGS (shortcut G then S)']);
461
+ await user.type(input(), 'invite');
462
+ expect(group('Actions')).toBeNull();
463
+ await user.clear(input());
464
+ await user.type(input(), 'app roles');
465
+ expect(group('Actions')).toBeNull();
466
+ });
467
+
468
+ it('New page creates the page through the shared hook and closes the palette', async () => {
469
+ const user = userEvent.setup();
470
+ renderPalette();
471
+ await user.click(trigger());
472
+ await user.type(input(), 'new page');
473
+ await user.keyboard('{Enter}');
474
+ expect(createPage).toHaveBeenCalledTimes(1);
475
+ expect(screen.queryByRole('combobox')).toBeNull();
476
+ });
477
+
478
+ it('says why a command failed, in the palette it reopens', async () => {
479
+ createPage.mockRejectedValue(new Error('Couldn’t create the page: refused'));
480
+ const user = userEvent.setup();
481
+ renderPalette();
482
+ await user.click(trigger());
483
+ await user.click(screen.getByRole('option', { name: /^New page/ }));
484
+ expect(await screen.findByRole('alert')).toHaveTextContent('Couldn’t create the page: refused');
485
+ expect(input()).toHaveFocus();
486
+ await user.keyboard('{Escape}');
487
+ await user.click(trigger());
488
+ expect(screen.queryByRole('alert')).toBeNull();
489
+ });
490
+
491
+ it('Invite people opens the invite dialog', async () => {
492
+ const user = userEvent.setup();
493
+ renderPalette();
494
+ await user.click(trigger());
495
+ await user.click(screen.getByRole('option', { name: 'Invite people' }));
496
+ expect(inviteOpen).toHaveBeenCalledTimes(1);
497
+ expect(screen.queryByRole('combobox')).toBeNull();
498
+ });
499
+
500
+ it('Connect your agent and Go to … navigate', async () => {
501
+ const user = userEvent.setup();
502
+ renderPalette();
503
+ await user.click(trigger());
504
+ await user.type(input(), 'connect');
505
+ await user.keyboard('{Enter}');
506
+ expect(screen.getByTestId('location')).toHaveTextContent(WELCOME_PATH);
507
+
508
+ await user.click(trigger());
509
+ await user.type(input(), 'go to skills');
510
+ await user.keyboard('{Enter}');
511
+ expect(screen.getByTestId('location')).toHaveTextContent('/skills-and-tools');
512
+ });
513
+
514
+ it('offers a settings command per profile-menu row: the default rows for members, the admin rows for admins', async () => {
515
+ const adminMenuItems: AdminMenuItem[] = [
516
+ { id: 'stub-path', label: 'Stub page', path: '/stub-page', order: 95 },
517
+ { id: 'stub-admin', section: 'admin', label: 'Stub admin page', path: '/stub-admin' },
518
+ {
519
+ id: 'stub-dialog',
520
+ label: 'Stub dialog',
521
+ dialog: () => <></>,
522
+ },
523
+ ];
524
+ const user = userEvent.setup();
525
+ const { unmount } = renderPalette({ admin: false, adminMenuItems });
526
+ await user.click(trigger());
527
+ await user.type(input(), 'settings');
528
+ expect(groupRows('Actions')).toEqual([
529
+ 'Settings: Account',
530
+ 'Settings: Secrets',
531
+ 'Settings: Audit log',
532
+ 'Settings: Stub page',
533
+ 'Settings: External agent access',
534
+ 'Settings: Browse available tools',
535
+ ]);
536
+ unmount();
537
+
538
+ renderPalette({ admin: true, adminMenuItems });
539
+ await user.click(trigger());
540
+ // Six default rows, five admin rows: past the eight a page group gets.
541
+ await user.type(input(), 'settings');
542
+ expect(groupRows('Actions')).toHaveLength(11);
543
+ await user.clear(input());
544
+ await user.type(input(), 'settings: stub');
545
+ expect(groupRows('Actions')).toEqual(['Settings: Stub page', 'Settings: Stub admin page']);
546
+ await user.clear(input());
547
+ await user.type(input(), 'app roles');
548
+ await user.keyboard('{Enter}');
549
+ expect(screen.getByTestId('location')).toHaveTextContent('/roles-and-members');
550
+ });
551
+
552
+ it('asks a settings row’s isShown again on each open, so a row its own command switched off is gone', async () => {
553
+ // The shape of git's "Ask before deleting branches": shown while a stored
554
+ // preference is off, and its command turns the preference back on.
555
+ let skipped = true;
556
+ const adminMenuItems: AdminMenuItem[] = [
557
+ {
558
+ id: 'ask-again',
559
+ label: 'Ask again',
560
+ isShown: () => skipped,
561
+ onSelect: ({ closeMenu }) => {
562
+ skipped = false;
563
+ closeMenu();
564
+ },
565
+ },
566
+ ];
567
+ const user = userEvent.setup();
568
+ renderPalette({ adminMenuItems });
569
+ await user.click(trigger());
570
+ await user.type(input(), 'ask again');
571
+ expect(groupRows('Actions')).toEqual(['Settings: Ask again']);
572
+ await user.keyboard('{Enter}');
573
+ expect(skipped).toBe(false);
574
+
575
+ await user.click(trigger());
576
+ await user.type(input(), 'ask again');
577
+ expect(group('Actions')).toBeNull();
578
+ });
579
+
580
+ it('offers Edit this page only while the page on screen can be opened for editing', async () => {
581
+ const page = 'knowledge-base/KnowledgeBase/Onboarding.md';
582
+ const user = userEvent.setup();
583
+ renderPalette({ openFilePath: page });
584
+ await user.click(trigger());
585
+ await user.type(input(), 'edit');
586
+ expect(group('Actions')).toBeNull();
587
+ await user.keyboard('{Escape}');
588
+
589
+ act(() => publishEditablePage(page));
590
+ await user.click(trigger());
591
+ await user.type(input(), 'edit');
592
+ await user.keyboard('{Enter}');
593
+ expect(screen.getByTestId('location')).toHaveTextContent(
594
+ '/workspace/main/knowledge-base/KnowledgeBase/Onboarding.md',
595
+ );
596
+ expect(screen.getByTestId('location-state')).toHaveTextContent(
597
+ '{"startEditing":true,"startEditingPath":"knowledge-base/KnowledgeBase/Onboarding.md"}',
598
+ );
599
+ });
600
+
601
+ it('merges the registry’s commands after core’s, and runs them with the menu’s context', async () => {
602
+ const run = vi.fn();
603
+ const commandActions: CommandAction[] = [
604
+ {
605
+ id: 'new-ontology',
606
+ label: 'New ontology',
607
+ group: 'Graph',
608
+ shortcut: ['O'],
609
+ visible: (ctx) => ctx.isAdmin,
610
+ run,
611
+ },
612
+ // Core's id: dropped rather than doubled.
613
+ { id: 'new-page', label: 'Impostor page', visible: () => true, run: vi.fn() },
614
+ ];
615
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
616
+ const user = userEvent.setup();
617
+ renderPalette({ commandActions });
618
+ await user.click(trigger());
619
+ await user.type(input(), 'new');
620
+ expect(groupRows('Actions')).toEqual(['New pageC (shortcut C)', 'New ontologyGraphO (shortcut O)']);
621
+ expect(screen.queryByText('Impostor page')).toBeNull();
622
+
623
+ const row = screen.getByRole('option', { name: /new ontology/i });
624
+ expect(within(row).getByText('O', { selector: 'kbd' }).parentElement).toHaveAttribute('aria-hidden');
625
+ await user.click(row);
626
+ expect(run).toHaveBeenCalledWith(expect.objectContaining({ isAdmin: true, activeAppId: 'knowledge' }));
627
+ error.mockRestore();
628
+ });
629
+
630
+ it('says why a command failed when it threw on the spot, not only when it rejected', async () => {
631
+ const commandActions: CommandAction[] = [
632
+ {
633
+ id: 'explode',
634
+ label: 'Explode',
635
+ visible: () => true,
636
+ run: () => {
637
+ throw new Error('Couldn’t do that: refused');
638
+ },
639
+ },
640
+ ];
641
+ const user = userEvent.setup();
642
+ renderPalette({ commandActions });
643
+ await user.click(trigger());
644
+ await user.type(input(), 'explode');
645
+ await user.keyboard('{Enter}');
646
+ expect(await screen.findByRole('alert')).toHaveTextContent('Couldn’t do that: refused');
647
+ expect(input()).toHaveFocus();
648
+ });
649
+
650
+ it('says that skills, tools and plugins could not load even while the suggested commands fill the list', async () => {
651
+ api.listSkills.mockRejectedValue(new Error('down'));
652
+ api.listPlugins.mockRejectedValue(new Error('down'));
653
+ api.listToolSecrets.mockRejectedValue(new Error('down'));
654
+ const user = userEvent.setup();
655
+ renderPalette();
656
+ await user.click(trigger());
657
+ expect(groupRows('Actions').length).toBeGreaterThan(0);
658
+ await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('Couldn’t load skills, tools and plugins.'));
659
+ });
660
+ });
661
+
662
+ /**
663
+ * C, G then K, G then S: the commonest commands without the palette — and
664
+ * never at the expense of somebody typing.
665
+ */
666
+ describe('SearchPalette: single-key shortcuts', () => {
667
+ const press = (key: string, init: KeyboardEventInit = {}, target: Element = document.body) =>
668
+ fireEvent.keyDown(target, { key, ...init });
669
+
670
+ it('C creates a new page', () => {
671
+ renderPalette();
672
+ press('c');
673
+ expect(createPage).toHaveBeenCalledTimes(1);
674
+ expect(screen.queryByRole('combobox')).toBeNull();
675
+ });
676
+
677
+ it('G then K goes to Knowledge, G then S to Skills & Tools', () => {
678
+ renderPalette();
679
+ press('g');
680
+ press('s');
681
+ expect(screen.getByTestId('location')).toHaveTextContent('/skills-and-tools');
682
+ press('g');
683
+ press('k');
684
+ expect(screen.getByTestId('location').textContent).toBe('/workspace');
685
+ });
686
+
687
+ it('shows the keys on the commands they run', async () => {
688
+ const user = userEvent.setup();
689
+ renderPalette();
690
+ await user.click(trigger());
691
+ const newPage = screen.getByRole('option', { name: 'New page (shortcut C)' });
692
+ expect(within(newPage).getByText('C', { selector: 'kbd' }).parentElement).toHaveAttribute('aria-hidden');
693
+ expect(screen.getByRole('option', { name: 'Go to Skills & Tools (shortcut G then S)' })).toBeInTheDocument();
694
+ // Commands with no binding advertise none.
695
+ expect(screen.getByRole('option', { name: 'Invite people' })).toBeInTheDocument();
696
+ });
697
+
698
+ it('leaves keys alone in a field or an editor', () => {
699
+ renderPalette();
700
+ const field = document.createElement('input');
701
+ const editor = document.createElement('div');
702
+ editor.setAttribute('contenteditable', 'true');
703
+ const line = document.createElement('p');
704
+ editor.appendChild(line);
705
+ document.body.append(field, editor);
706
+ try {
707
+ press('c', {}, field);
708
+ press('c', {}, line);
709
+ press('g', {}, line);
710
+ press('k', {}, line);
711
+ expect(createPage).not.toHaveBeenCalled();
712
+ expect(screen.getByTestId('location')).toHaveTextContent('/workspace/main');
713
+ } finally {
714
+ field.remove();
715
+ editor.remove();
716
+ }
717
+ });
718
+
719
+ it('leaves keys alone with a modifier held', () => {
720
+ renderPalette();
721
+ press('c', { ctrlKey: true });
722
+ press('c', { metaKey: true });
723
+ press('C', { shiftKey: true });
724
+ press('c', { altKey: true });
725
+ expect(createPage).not.toHaveBeenCalled();
726
+ });
727
+
728
+ it('leaves keys alone while a modal dialog is up', () => {
729
+ renderPalette();
730
+ const modal = document.createElement('div');
731
+ modal.setAttribute('aria-modal', 'true');
732
+ document.body.appendChild(modal);
733
+ try {
734
+ press('c');
735
+ expect(createPage).not.toHaveBeenCalled();
736
+ } finally {
737
+ modal.remove();
738
+ }
739
+ });
740
+
741
+ it('leaves keys to the query while the palette is open', async () => {
742
+ const user = userEvent.setup();
743
+ renderPalette();
744
+ await user.click(trigger());
745
+ await user.type(input(), 'c');
746
+ expect(createPage).not.toHaveBeenCalled();
747
+ expect(input()).toHaveValue('c');
748
+ });
749
+
750
+ it('forgets a G that waited more than a second for its K', () => {
751
+ vi.useFakeTimers();
752
+ try {
753
+ renderPalette();
754
+ press('g');
755
+ act(() => {
756
+ vi.advanceTimersByTime(1001);
757
+ });
758
+ press('k');
759
+ expect(screen.getByTestId('location')).toHaveTextContent('/workspace/main');
760
+ } finally {
761
+ vi.useRealTimers();
762
+ }
763
+ });
764
+
765
+ it('tries the second key on its own when it did not complete a sequence: G then C makes a page', () => {
766
+ renderPalette();
767
+ press('g');
768
+ press('c');
769
+ expect(createPage).toHaveBeenCalledTimes(1);
770
+ // And G then G re-arms: the second G is the first key of a new sequence.
771
+ press('g');
772
+ press('g');
773
+ press('s');
774
+ expect(screen.getByTestId('location')).toHaveTextContent('/skills-and-tools');
775
+ });
776
+
777
+ it('forgets a pending G when the palette opens, so a K typed after Escape goes nowhere', async () => {
778
+ const user = userEvent.setup();
779
+ renderPalette();
780
+ press('g');
781
+ await user.click(trigger());
782
+ await user.keyboard('{Escape}');
783
+ press('k');
784
+ expect(screen.getByTestId('location')).toHaveTextContent('/workspace/main');
785
+ });
786
+
787
+ // A distribution's command gets a working key for the `shortcut` it set,
788
+ // under the same guards: the hint on its row is never a key that does
789
+ // nothing.
790
+ it('binds a registry command’s own keys, and leaves them alone in a field', () => {
791
+ const run = vi.fn();
792
+ renderPalette({
793
+ commandActions: [{ id: 'new-ontology', label: 'New ontology', shortcut: ['O'], visible: () => true, run }],
794
+ });
795
+ press('o');
796
+ expect(run).toHaveBeenCalledTimes(1);
797
+ const field = document.createElement('input');
798
+ document.body.appendChild(field);
799
+ try {
800
+ press('o', {}, field);
801
+ } finally {
802
+ field.remove();
803
+ }
804
+ expect(run).toHaveBeenCalledTimes(1);
805
+ });
806
+
807
+ it('drops a registry shortcut that collides with keys already bound, hint and all, and keeps the core key', async () => {
808
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
809
+ const run = vi.fn();
810
+ const user = userEvent.setup();
811
+ renderPalette({
812
+ commandActions: [
813
+ // The same key as New page.
814
+ { id: 'clash', label: 'Clash', shortcut: ['C'], visible: () => true, run },
815
+ // A bare G would swallow G then K.
816
+ { id: 'swallow', label: 'Swallow', shortcut: ['g'], visible: () => true, run },
817
+ ],
818
+ });
819
+ press('c');
820
+ expect(createPage).toHaveBeenCalledTimes(1);
821
+ press('g');
822
+ press('k');
823
+ expect(screen.getByTestId('location').textContent).toBe('/workspace');
824
+ expect(run).not.toHaveBeenCalled();
825
+ // The rows stay, with no key shown.
826
+ await user.click(trigger());
827
+ await user.type(input(), 'clash');
828
+ expect(groupRows('Actions')).toEqual(['Clash']);
829
+ expect(error).toHaveBeenCalledTimes(2);
830
+ error.mockRestore();
831
+ });
832
+ });