@bevel-software/platform-core-frontend 0.7.5 → 0.9.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 (132) hide show
  1. package/LICENSE +202 -202
  2. package/THIRD-PARTY-NOTICES.md +344 -988
  3. package/package.json +5 -5
  4. package/src/core/CoreAppShell.tsx +4 -4
  5. package/src/core/__tests__/ShellRoutes.test.tsx +1 -1
  6. package/src/core/__tests__/bootstrap.test.ts +47 -2
  7. package/src/core/bootstrap.ts +20 -0
  8. package/src/core/registry.ts +16 -4
  9. package/src/css-side-effect-imports.d.ts +7 -7
  10. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +1 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +5 -5
  12. package/src/modules/access/api.ts +5 -5
  13. package/src/modules/access/components/ManageAccessDialog.tsx +21 -20
  14. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  15. package/src/modules/admin/components/AdminRolesPage.tsx +1 -1
  16. package/src/modules/admin/state/admin.context.tsx +15 -0
  17. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +2 -2
  18. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
  19. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
  20. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +4 -4
  21. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +4 -4
  22. package/src/modules/layout/__tests__/breakpoints.test.ts +1 -1
  23. package/src/modules/layout/components/SidebarFrame.tsx +2 -2
  24. package/src/modules/library/__tests__/{AddToGroupDialog.test.tsx → AddToPluginDialog.test.tsx} +34 -34
  25. package/src/modules/library/__tests__/LibraryCard.test.tsx +30 -11
  26. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +84 -59
  27. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +51 -51
  28. package/src/modules/library/__tests__/{LockedGroupView.test.tsx → LockedPluginView.test.tsx} +33 -33
  29. package/src/modules/library/__tests__/McpServerSection.test.tsx +138 -0
  30. package/src/modules/library/__tests__/{NewGroupDialog.test.tsx → NewPluginDialog.test.tsx} +22 -22
  31. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +7 -7
  32. package/src/modules/library/__tests__/PluginExtras.test.tsx +131 -0
  33. package/src/modules/library/__tests__/{GroupJoinRequests.test.tsx → PluginJoinRequests.test.tsx} +24 -24
  34. package/src/modules/library/__tests__/{GroupPage.test.tsx → PluginPage.test.tsx} +197 -106
  35. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +363 -0
  36. package/src/modules/library/__tests__/{GroupsSidebar.contextmenu.test.tsx → PluginsSidebar.contextmenu.test.tsx} +32 -31
  37. package/src/modules/library/__tests__/{GroupsSidebar.locked.test.tsx → PluginsSidebar.locked.test.tsx} +29 -28
  38. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +171 -0
  39. package/src/modules/library/__tests__/{GroupsSidebarMenu.test.tsx → PluginsSidebarMenu.test.tsx} +18 -18
  40. package/src/modules/library/__tests__/SkillPage.test.tsx +8 -8
  41. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +2 -2
  42. package/src/modules/library/__tests__/ToolPage.test.tsx +41 -12
  43. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +1 -1
  44. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +57 -57
  45. package/src/modules/library/__tests__/auth-harness.tsx +4 -4
  46. package/src/modules/library/__tests__/library-data.test.ts +82 -0
  47. package/src/modules/library/__tests__/status.test.ts +19 -19
  48. package/src/modules/library/__tests__/tools.api.test.ts +70 -0
  49. package/src/modules/library/__tests__/useToolPage.test.tsx +4 -4
  50. package/src/modules/library/components/AccessRequestsBanner.tsx +8 -8
  51. package/src/modules/library/components/{AddToGroupDialog.tsx → AddToPluginDialog.tsx} +11 -11
  52. package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
  53. package/src/modules/library/components/{DeleteGroupDialog.tsx → DeletePluginDialog.tsx} +9 -9
  54. package/src/modules/library/components/LibraryCard.tsx +26 -2
  55. package/src/modules/library/components/LibraryLayout.tsx +80 -71
  56. package/src/modules/library/components/LibraryPage.tsx +8 -8
  57. package/src/modules/library/components/LockGlyph.tsx +1 -1
  58. package/src/modules/library/components/{LockedGroupView.tsx → LockedPluginView.tsx} +35 -35
  59. package/src/modules/library/components/{ManagedGroupRequests.tsx → ManagedPluginRequests.tsx} +13 -13
  60. package/src/modules/library/components/{NewGroupDialog.tsx → NewPluginDialog.tsx} +24 -24
  61. package/src/modules/library/components/NewSkillPanel.tsx +23 -5
  62. package/src/modules/library/components/PageActions.tsx +34 -11
  63. package/src/modules/library/components/PersonalAddDialog.tsx +5 -5
  64. package/src/modules/library/components/{PersonalGroupPage.tsx → PersonalPluginPage.tsx} +29 -19
  65. package/src/modules/library/components/PluginExtras.tsx +195 -0
  66. package/src/modules/library/components/{GroupIndexRow.tsx → PluginIndexRow.tsx} +6 -6
  67. package/src/modules/library/components/PluginJoinRequests.tsx +77 -0
  68. package/src/modules/library/components/{GroupPage.tsx → PluginPage.tsx} +112 -72
  69. package/src/modules/library/components/{GroupsIndexPage.tsx → PluginsIndexPage.tsx} +91 -48
  70. package/src/modules/library/components/{GroupsSidebar.tsx → PluginsSidebar.tsx} +105 -55
  71. package/src/modules/library/components/{GroupsSidebarMenu.tsx → PluginsSidebarMenu.tsx} +15 -15
  72. package/src/modules/library/components/{group-page-parts.tsx → plugin-page-parts.tsx} +218 -27
  73. package/src/modules/library/components/skill-page/SkillPage.tsx +12 -12
  74. package/src/modules/library/components/tool-page/McpServerSection.tsx +380 -0
  75. package/src/modules/library/components/tool-page/ToolPage.tsx +22 -5
  76. package/src/modules/library/hooks/useJoinRequests.ts +8 -8
  77. package/src/modules/library/routes/LibraryRoutes.tsx +32 -19
  78. package/src/modules/library/routes/WorkspaceItemRoute.tsx +24 -24
  79. package/src/modules/library/routes/library-paths.ts +36 -36
  80. package/src/modules/library/services/library.api.ts +9 -9
  81. package/src/modules/library/services/{groups.api.ts → plugins.api.ts} +43 -43
  82. package/src/modules/library/services/tools.api.ts +54 -0
  83. package/src/modules/library/state/library-data.tsx +67 -46
  84. package/src/modules/library/utils/names.ts +1 -1
  85. package/src/modules/library/utils/{personal-group.ts → personal-plugin.ts} +8 -8
  86. package/src/modules/library/utils/{group-summary.ts → plugin-summary.ts} +14 -14
  87. package/src/modules/library/utils/status.ts +17 -17
  88. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +318 -0
  89. package/src/modules/onboarding/__tests__/onboarding.test.tsx +86 -8
  90. package/src/modules/onboarding/agent-clients.ts +18 -14
  91. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +143 -0
  92. package/src/modules/onboarding/components/WelcomePage.tsx +30 -22
  93. package/src/modules/onboarding/components/WelcomeRoute.tsx +57 -0
  94. package/src/modules/onboarding/welcome-state.ts +36 -0
  95. package/src/modules/review/components/MarkdownDiffViewer.tsx +1 -1
  96. package/src/modules/review/components/ReviewPanel.tsx +11 -11
  97. package/src/modules/review/components/__tests__/{isGroupItemPath.test.ts → isPluginItemPath.test.ts} +24 -24
  98. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +3 -3
  99. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +1 -1
  100. package/src/modules/settings/components/SettingsLayout.tsx +1 -1
  101. package/src/modules/settings/components/SettingsNav.tsx +5 -5
  102. package/src/modules/setup/__tests__/setup.test.tsx +203 -0
  103. package/src/modules/setup/components/SetupScreen.tsx +235 -68
  104. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +29 -107
  105. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +1 -1
  106. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +228 -0
  107. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +3 -3
  108. package/src/modules/workspace/components/FileExplorer.tsx +12 -12
  109. package/src/modules/workspace/components/FileRoute.tsx +8 -1
  110. package/src/modules/workspace/components/FileViewer.tsx +95 -38
  111. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +14 -14
  112. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +20 -0
  113. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +227 -18
  114. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +7 -2
  115. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +25 -0
  116. package/src/modules/workspace/routing/kb-routes.ts +23 -1
  117. package/src/modules/workspace/utils/__tests__/diff.test.ts +1 -1
  118. package/src/modules/workspace/utils/fileTree.ts +54 -3
  119. package/src/shared/components/Surface.tsx +15 -0
  120. package/src/shared/mcp/ClaudeInstallLink.tsx +88 -0
  121. package/src/shared/mcp/ConnectionInstructions.tsx +51 -0
  122. package/src/shared/mcp/CopyBlock.tsx +42 -0
  123. package/src/shared/mcp/__tests__/ClaudeInstallLink.test.tsx +40 -0
  124. package/src/shared/mcp/__tests__/connect-snippets.test.ts +431 -0
  125. package/src/shared/mcp/__tests__/useCopyFeedback.test.ts +112 -0
  126. package/src/shared/mcp/connect-snippets.ts +353 -0
  127. package/src/shared/mcp/index.ts +28 -0
  128. package/src/shared/mcp/useCopyFeedback.ts +46 -0
  129. package/src/test-setup.ts +11 -0
  130. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +0 -283
  131. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +0 -142
  132. package/src/modules/library/components/GroupJoinRequests.tsx +0 -56
@@ -0,0 +1,363 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
+ import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
4
+ import type { LibraryData } from '../hooks/useLibraryData';
5
+ import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
6
+ import type { PluginSummary } from '../services/plugins.api';
7
+
8
+ /**
9
+ * The all-plugins index: which section a plugin lands in, what each row says, and
10
+ * where it goes. The locked section is the reason this page exists, so most of
11
+ * what is asserted here is about plugins the caller cannot enter.
12
+ */
13
+
14
+ const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
15
+ vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
16
+
17
+ const pluginsMock = vi.hoisted(() => ({ listPlugins: vi.fn(), listJoinRequests: vi.fn() }));
18
+ vi.mock('../services/plugins.api', () => ({
19
+ listPlugins: pluginsMock.listPlugins,
20
+ // The page carries the managers' join-request banners now — it is where the
21
+ // Library lands, so it is where an unanswered request is certain to be seen.
22
+ listJoinRequests: pluginsMock.listJoinRequests,
23
+ reconcileJoinRequest: vi.fn(),
24
+ }));
25
+
26
+ import { LibraryProvider } from '../state/library-data';
27
+ import {
28
+ WorkspaceContext,
29
+ type WorkspaceContextValue,
30
+ } from '../../workspace/state/workspace.context';
31
+ import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
32
+ import { PluginsIndexPage } from '../components/PluginsIndexPage';
33
+ import { withAuth, TEST_PERSONAL_GROUP } from './auth-harness';
34
+
35
+ const tool = (over: Partial<ToolSecrets> = {}): ToolSecrets => ({
36
+ slug: 'heyreach',
37
+ name: 'heyreach',
38
+ path: 'Plugins/GTM/heyreach.tool',
39
+ type: 'inline',
40
+ setup: null,
41
+ canWrite: false,
42
+ variables: [],
43
+ ...over,
44
+ });
45
+
46
+ const CATALOG: LibraryData = {
47
+ loading: false,
48
+ error: null,
49
+ skills: [
50
+ { name: 'outreach', description: '', path: 'Plugins/GTM/outreach' },
51
+ { name: 'scratch', description: '', path: 'Skills/scratch' },
52
+ ],
53
+ pendingSkills: [],
54
+ tools: [
55
+ tool(),
56
+ // An ungrouped sign-in — `Tools/slack.tool` is two segments, so no plugin.
57
+ tool({
58
+ slug: 'slack',
59
+ name: 'slack',
60
+ path: 'Tools/slack.tool',
61
+ variables: [
62
+ {
63
+ name: 'API_KEY',
64
+ scope: 'user',
65
+ label: null,
66
+ key: 'slack_API_KEY',
67
+ adminConfigured: false,
68
+ userConfigured: false,
69
+ },
70
+ ],
71
+ }),
72
+ ],
73
+ ownedSkills: new Set(['outreach']),
74
+ allowedToolsBySkill: new Map(),
75
+ crs: [],
76
+ myCrNumbers: new Set<number>(),
77
+ reload: vi.fn(),
78
+ };
79
+
80
+ const summary = (over: Partial<PluginSummary> = {}): PluginSummary => ({
81
+ name: 'GTM',
82
+ folders: ['Plugins/GTM'],
83
+ canRead: true,
84
+ canWrite: false,
85
+ isOwner: false,
86
+ skillCount: 4,
87
+ toolCount: 2,
88
+ owners: { roles: [], users: [{ name: 'Olga Ivanova', email: 'olga@bevel.software' }] },
89
+ writers: { roles: ['Admin'], users: [] },
90
+ readers: { restricted: true, roles: ['GTM Team'], users: [] },
91
+ hasRequested: false,
92
+ requestNumber: null,
93
+ ...over,
94
+ });
95
+
96
+ function LocationProbe() {
97
+ const location = useLocation();
98
+ return <div aria-label="href">{location.pathname + location.search}</div>;
99
+ }
100
+
101
+ /** `kbDirName` is what the request banners' Manage-access affordance needs. */
102
+ const WORKSPACE = {
103
+ workspaceId: 'target-company-state',
104
+ kbDirName: 'knowledge-base',
105
+ } as unknown as WorkspaceContextValue;
106
+
107
+ const nonAdmin: AdminContextValue = {
108
+ isAdmin: false,
109
+ unreadCount: 0,
110
+ lastSeen: null,
111
+ markSeen: vi.fn(),
112
+ refresh: vi.fn(),
113
+ rolesConfigCorrupted: false,
114
+ rolesConfigErrors: [],
115
+ runRolesRecovery: vi.fn(),
116
+ };
117
+
118
+ /** The same caller with the admin bit set — the empty index's CTA is theirs. */
119
+ const asAdmin: AdminContextValue = { ...nonAdmin, isAdmin: true };
120
+
121
+ function renderIndex(admin: AdminContextValue = nonAdmin) {
122
+ return render(
123
+ <MemoryRouter initialEntries={['/skills-and-tools']}>
124
+ {withAuth(
125
+ <AdminContext.Provider value={admin}>
126
+ <WorkspaceContext.Provider value={WORKSPACE}>
127
+ <LibraryProvider>
128
+ <Routes>
129
+ <Route path="/skills-and-tools" element={<PluginsIndexPage />} />
130
+ <Route path="*" element={<div />} />
131
+ </Routes>
132
+ <LocationProbe />
133
+ </LibraryProvider>
134
+ </WorkspaceContext.Provider>
135
+ </AdminContext.Provider>,
136
+ )}
137
+ </MemoryRouter>,
138
+ );
139
+ }
140
+
141
+ const href = () => screen.getByLabelText('href').textContent;
142
+ const row = (name: RegExp | string) => screen.getByRole('button', { name });
143
+
144
+ describe('PluginsIndexPage', () => {
145
+ beforeEach(() => {
146
+ dataMock.useLibraryData.mockReturnValue(CATALOG);
147
+ pluginsMock.listPlugins.mockResolvedValue([summary()]);
148
+ pluginsMock.listJoinRequests.mockResolvedValue([]);
149
+ });
150
+
151
+ it('names itself and its two sections', async () => {
152
+ renderIndex();
153
+ expect(await screen.findByRole('heading', { name: 'All plugins', level: 1 })).toBeInTheDocument();
154
+ expect(
155
+ screen.getByText('A plugin carries skills and tools for the people in it.'),
156
+ ).toBeInTheDocument();
157
+ expect(screen.getByRole('heading', { name: 'Yours' })).toBeInTheDocument();
158
+ expect(await screen.findByRole('heading', { name: "Your plugins" })).toBeInTheDocument();
159
+ });
160
+
161
+ it("offers the caller's own plugin under Yours, and opens it", async () => {
162
+ renderIndex();
163
+ expect(
164
+ await screen.findByText('Your sign-ins and the skills no plugin carries'),
165
+ ).toBeInTheDocument();
166
+ // The lens is gone from this page — it lives in the sidebar.
167
+ expect(screen.queryByText('The skills you answer for')).not.toBeInTheDocument();
168
+ fireEvent.click(row(new RegExp(`^${TEST_PERSONAL_GROUP}`)));
169
+ await waitFor(() => expect(href()).toBe('/skills-and-tools/yours'));
170
+ });
171
+
172
+ it("keeps the caller's own plugin listed even when nothing sits outside a plugin", async () => {
173
+ dataMock.useLibraryData.mockReturnValue({
174
+ ...CATALOG,
175
+ skills: [{ name: 'outreach', description: '', path: 'Plugins/GTM/outreach' }],
176
+ tools: [tool()],
177
+ });
178
+ renderIndex();
179
+ await screen.findByRole('heading', { name: 'All plugins', level: 1 });
180
+ expect(screen.getByRole('button', { name: new RegExp(`^${TEST_PERSONAL_GROUP}`) })).toBeInTheDocument();
181
+ // And never the lens: "Owned by me" is a view across plugins, not a plugin.
182
+ expect(screen.queryByRole('button', { name: /^Owned by me/ })).not.toBeInTheDocument();
183
+ });
184
+
185
+ it("puts a readable plugin under Your plugins, with its run-by line and totals", async () => {
186
+ renderIndex();
187
+ const gtm = await screen.findByRole('button', { name: /^GTM/ });
188
+ expect(gtm).toHaveAccessibleName('GTM Run by Olga Ivanova 4 skills · 2 tools');
189
+ fireEvent.click(gtm);
190
+ await waitFor(() => expect(href()).toBe('/skills-and-tools/plugins/GTM'));
191
+ });
192
+
193
+ it('marks a plugin the caller can change with an Owner badge', async () => {
194
+ pluginsMock.listPlugins.mockResolvedValue([summary({ canWrite: true })]);
195
+ renderIndex();
196
+ expect(await screen.findByRole('button', { name: /^GTM Owner/ })).toBeInTheDocument();
197
+ });
198
+
199
+ it('shows the amber count when a plugin has integrations to set up', async () => {
200
+ pluginsMock.listPlugins.mockResolvedValue([
201
+ summary({
202
+ name: 'Yours',
203
+ folders: ['Plugins/Yours'],
204
+ }),
205
+ summary(),
206
+ ]);
207
+ dataMock.useLibraryData.mockReturnValue({
208
+ ...CATALOG,
209
+ tools: [
210
+ tool({
211
+ variables: [
212
+ {
213
+ name: 'API_KEY',
214
+ scope: 'user',
215
+ label: null,
216
+ key: 'heyreach_API_KEY',
217
+ adminConfigured: false,
218
+ userConfigured: false,
219
+ },
220
+ ],
221
+ }),
222
+ ],
223
+ });
224
+ renderIndex();
225
+ expect(await screen.findByRole('button', { name: /^GTM .* 1$/ })).toBeInTheDocument();
226
+ });
227
+
228
+ it('lists a DISCOVERABLE locked plugin under Request access, Locked or Requested', async () => {
229
+ pluginsMock.listPlugins.mockResolvedValue([
230
+ summary(),
231
+ summary({ name: 'Finance', folders: ['Plugins/Finance'], canRead: false, canWrite: false }),
232
+ ]);
233
+ renderIndex();
234
+ expect(await screen.findByRole('heading', { name: 'Request access' })).toBeInTheDocument();
235
+ expect(screen.getByRole('button', { name: /^Finance/ })).toBeInTheDocument();
236
+ expect(screen.getByTitle('Locked')).toBeInTheDocument();
237
+
238
+ // Once the caller's join request is open, the chip says THAT instead —
239
+ // the one thing the row can tell you that you did not already know.
240
+ pluginsMock.listPlugins.mockResolvedValue([
241
+ summary({
242
+ name: 'Finance',
243
+ folders: ['Plugins/Finance'],
244
+ canRead: false,
245
+ canWrite: false,
246
+ hasRequested: true,
247
+ requestNumber: 9,
248
+ }),
249
+ ]);
250
+ renderIndex();
251
+ expect(await screen.findByTitle('Requested')).toBeInTheDocument();
252
+ });
253
+
254
+ it('never lists a plugin the endpoint omitted (fail-closed: absent = invisible)', async () => {
255
+ // The backend only returns accessible plugins, and this page adds nothing
256
+ // on top: a plugin the caller cannot access has no row, no name, no counts.
257
+ pluginsMock.listPlugins.mockResolvedValue([summary()]);
258
+ renderIndex();
259
+ await screen.findByRole('button', { name: /^GTM/ });
260
+ expect(screen.queryByRole('button', { name: /^Finance/ })).not.toBeInTheDocument();
261
+ expect(screen.queryByRole('heading', { name: 'Request access' })).not.toBeInTheDocument();
262
+ });
263
+
264
+ it('lists a plugin an item grant reaches inside, even without a summary', async () => {
265
+ dataMock.useLibraryData.mockReturnValue({
266
+ ...CATALOG,
267
+ skills: [{ name: 'budget', description: '', path: 'Plugins/Finance/budget' }],
268
+ });
269
+ renderIndex();
270
+ expect(await screen.findByRole('button', { name: /^Finance/ })).toBeInTheDocument();
271
+ });
272
+
273
+ it('lists a catalog-derived plugin with counts alone when no summary vouches for it', async () => {
274
+ pluginsMock.listPlugins.mockResolvedValue([]);
275
+ renderIndex();
276
+ // One skill and one tool in Plugins/GTM, and nothing claiming to know who
277
+ // runs it — so the row states what it can count, not what it cannot.
278
+ expect(await screen.findByRole('button', { name: 'GTM 1 skills · 1 tools' })).toBeInTheDocument();
279
+ });
280
+
281
+ /** An untouched workspace: no summaries, and only unfiled items. */
282
+ function untouchedWorkspace() {
283
+ pluginsMock.listPlugins.mockResolvedValue([]);
284
+ dataMock.useLibraryData.mockReturnValue({
285
+ ...CATALOG,
286
+ skills: [{ name: 'scratch', description: '', path: 'Skills/scratch' }],
287
+ tools: [
288
+ tool({ slug: 'slack', name: 'slack', path: 'Tools/slack.tool' }),
289
+ ],
290
+ });
291
+ }
292
+
293
+ it('turns an untouched index into a create CTA for an admin, and the CTA into the dialog', async () => {
294
+ untouchedWorkspace();
295
+ renderIndex(asAdmin);
296
+
297
+ fireEvent.click(await screen.findByRole('button', { name: 'Create the first plugin' }));
298
+ expect(await screen.findByRole('textbox', { name: 'Plugin name' })).toBeInTheDocument();
299
+ });
300
+
301
+ it('never offers the first plugin to a non-admin — that call is not theirs to make', async () => {
302
+ untouchedWorkspace();
303
+ renderIndex();
304
+ await screen.findByText('Your plugins');
305
+ expect(
306
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
307
+ ).not.toBeInTheDocument();
308
+ });
309
+
310
+ it('keeps the create CTA out of the way once the caller is in a plugin', async () => {
311
+ renderIndex(asAdmin); // default fixture: member of GTM
312
+ await screen.findByRole('button', { name: /^GTM/ });
313
+ expect(
314
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
315
+ ).not.toBeInTheDocument();
316
+ });
317
+
318
+ it('stands the CTA down when plugins exist that the admin is simply not in', async () => {
319
+ // Locked entries are plugins too: "the first plugin" would be a lie here,
320
+ // even though `Your plugins` is empty.
321
+ pluginsMock.listPlugins.mockResolvedValue([
322
+ summary({ name: 'Finance', folders: ['Plugins/Finance'], canRead: false, canWrite: false }),
323
+ ]);
324
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
325
+ renderIndex(asAdmin);
326
+ await screen.findByRole('button', { name: /^Finance/ });
327
+ expect(
328
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
329
+ ).not.toBeInTheDocument();
330
+ });
331
+
332
+ it('does not promise the first plugin while the catalog is still loading', async () => {
333
+ // The initial empty `items` is an unanswered question, not an untouched
334
+ // workspace: a catalog-derived plugin may still be on its way in.
335
+ pluginsMock.listPlugins.mockResolvedValue([]);
336
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
337
+ renderIndex(asAdmin);
338
+ await screen.findByText('Your plugins');
339
+ expect(
340
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
341
+ ).not.toBeInTheDocument();
342
+ });
343
+
344
+ it('offers a retry when the plugins endpoint fails, and keeps Yours', async () => {
345
+ pluginsMock.listPlugins.mockRejectedValue(new Error("Couldn't load plugins."));
346
+ renderIndex();
347
+ const banner = await screen.findByRole('alert');
348
+ expect(banner).toHaveTextContent("Couldn't load plugins.");
349
+ expect(screen.getByRole('button', { name: new RegExp(`^${TEST_PERSONAL_GROUP}`) })).toBeInTheDocument();
350
+ expect(screen.queryByRole('heading', { name: "Your plugins" })).not.toBeInTheDocument();
351
+
352
+ pluginsMock.listPlugins.mockResolvedValue([summary()]);
353
+ fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
354
+ expect(await screen.findByRole('button', { name: /^GTM/ })).toBeInTheDocument();
355
+ });
356
+
357
+ it('says it is loading before the first plugin index arrives', () => {
358
+ pluginsMock.listPlugins.mockReturnValue(new Promise(() => {}));
359
+ renderIndex();
360
+ expect(screen.getByText('Loading plugins…')).toBeInTheDocument();
361
+ expect(screen.getByRole('button', { name: new RegExp(`^${TEST_PERSONAL_GROUP}`) })).toBeInTheDocument();
362
+ });
363
+ });
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import { render, screen, fireEvent, createEvent } from '@testing-library/react';
3
- import { GroupsSidebar, type GroupsSidebarProps } from '../components/GroupsSidebar';
3
+ import { PluginsSidebar, type PluginsSidebarProps } from '../components/PluginsSidebar';
4
4
 
5
5
  /**
6
6
  * Right-click in the Library nav, which has to answer the gesture the way
@@ -10,50 +10,51 @@ import { GroupsSidebar, type GroupsSidebarProps } from '../components/GroupsSide
10
10
  * The sidebar itself only REPORTS the click: it suppresses the browser menu,
11
11
  * reads the pointer and the row synchronously, and hands both up. Everything
12
12
  * about which verbs are true for a given row lives in `LibraryLayout`, because
13
- * that is where the group summaries are — so that is where those assertions
13
+ * that is where the plugin summaries are — so that is where those assertions
14
14
  * live too.
15
15
  */
16
16
 
17
- function renderSidebar(over: Partial<GroupsSidebarProps> = {}) {
17
+ function renderSidebar(over: Partial<PluginsSidebarProps> = {}) {
18
18
  const onContextMenu = vi.fn();
19
19
  const onSelect = vi.fn();
20
- const props: GroupsSidebarProps = {
20
+ const props: PluginsSidebarProps = {
21
21
  filter: { kind: 'all' },
22
22
  onSelect,
23
- groups: [
24
- { group: 'Engineering', count: 4, attention: 0 },
25
- { group: 'GTM', count: 3, attention: 2 },
23
+ plugins: [
24
+ { plugin: 'Engineering', count: 4, attention: 0 },
25
+ { plugin: 'GTM', count: 3, attention: 2 },
26
26
  ],
27
- lockedGroups: ['Finance'],
27
+ lockedPlugins: ['Finance'],
28
28
  ownedCount: 2,
29
29
  ownedAttention: 0,
30
- personalGroupLabel: "Juan's Group",
30
+ personalPluginLabel: "Juan's Plugin",
31
31
  ungroupedCount: 1,
32
32
  attentionCount: 2,
33
33
  onFinishSetup: vi.fn(),
34
- onCreateGroup: vi.fn(),
35
- groupsIndexActive: false,
36
- onOpenGroupsIndex: vi.fn(),
34
+ onCreatePlugin: vi.fn(),
35
+ canCreatePlugin: true,
36
+ pluginsIndexActive: false,
37
+ onOpenPluginsIndex: vi.fn(),
37
38
  onContextMenu,
38
39
  ...over,
39
40
  };
40
- render(<GroupsSidebar {...props} />);
41
+ render(<PluginsSidebar {...props} />);
41
42
  return { onContextMenu, onSelect };
42
43
  }
43
44
 
44
- const nav = () => screen.getByRole('navigation', { name: 'Library groups' });
45
+ const nav = () => screen.getByRole('navigation', { name: 'Library plugins' });
45
46
  const rightClick = (el: Element, at = { clientX: 120, clientY: 240 }) =>
46
47
  fireEvent.contextMenu(el, at);
47
48
 
48
- describe('GroupsSidebar: right-click', () => {
49
- it('reports a group row with its filter, its name and the pointer', () => {
49
+ describe('PluginsSidebar: right-click', () => {
50
+ it('reports a plugin row with its filter, its name and the pointer', () => {
50
51
  const { onContextMenu } = renderSidebar();
51
52
  const gtm = screen.getByRole('button', { name: /^GTM/ });
52
53
  rightClick(gtm, { clientX: 88, clientY: 310 });
53
54
 
54
55
  expect(onContextMenu).toHaveBeenCalledTimes(1);
55
56
  expect(onContextMenu).toHaveBeenCalledWith({
56
- filter: { kind: 'group', group: 'GTM' },
57
+ filter: { kind: 'group', plugin: 'GTM' },
57
58
  label: 'GTM',
58
59
  x: 88,
59
60
  y: 310,
@@ -70,24 +71,24 @@ describe('GroupsSidebar: right-click', () => {
70
71
  label: 'Owned by me',
71
72
  });
72
73
 
73
- rightClick(screen.getByRole('button', { name: /^Juan's Group/ }));
74
+ rightClick(screen.getByRole('button', { name: /^Juan's Plugin/ }));
74
75
  expect(onContextMenu.mock.calls[1][0]).toMatchObject({
75
76
  filter: { kind: 'ungrouped' },
76
- label: "Juan's Group",
77
+ label: "Juan's Plugin",
77
78
  });
78
79
  });
79
80
 
80
81
  /**
81
82
  * A locked row emits the same `{ kind: 'group' }` target a readable one does,
82
- * for the same reason its CLICK does: a group you are not in is still a place.
83
+ * for the same reason its CLICK does: a plugin you are not in is still a place.
83
84
  * The label drops the "(locked)" suffix — that is the accessible name, not the
84
- * group's name, and the menu titles itself with the latter.
85
+ * plugin's name, and the menu titles itself with the latter.
85
86
  */
86
- it('reports a locked row exactly like a readable group', () => {
87
+ it('reports a locked row exactly like a readable plugin', () => {
87
88
  const { onContextMenu } = renderSidebar();
88
89
  rightClick(screen.getByRole('button', { name: 'Finance (locked)' }));
89
90
  expect(onContextMenu.mock.calls[0][0]).toMatchObject({
90
- filter: { kind: 'group', group: 'Finance' },
91
+ filter: { kind: 'group', plugin: 'Finance' },
91
92
  label: 'Finance',
92
93
  });
93
94
  });
@@ -95,16 +96,16 @@ describe('GroupsSidebar: right-click', () => {
95
96
  /**
96
97
  * The home row has no `LibraryFilter` behind it — the index lists places, not
97
98
  * a slice of the catalog — so it reports `null` and gets the nav's own menu:
98
- * create a group, and none of the verbs that need a folder to point at.
99
+ * create a plugin, and none of the verbs that need a folder to point at.
99
100
  */
100
- it('reports the All groups row with no filter, but with its own row and name', () => {
101
+ it('reports the All plugins row with no filter, but with its own row and name', () => {
101
102
  const { onContextMenu } = renderSidebar();
102
- const home = screen.getByRole('button', { name: 'All groups' });
103
+ const home = screen.getByRole('button', { name: 'All plugins' });
103
104
  rightClick(home);
104
105
  expect(onContextMenu).toHaveBeenCalledTimes(1);
105
106
  expect(onContextMenu.mock.calls[0][0]).toMatchObject({
106
107
  filter: null,
107
- label: 'All groups',
108
+ label: 'All plugins',
108
109
  row: home,
109
110
  });
110
111
  });
@@ -123,14 +124,14 @@ describe('GroupsSidebar: right-click', () => {
123
124
 
124
125
  /**
125
126
  * The nav wraps every row, so without `stopPropagation` a right-click on a
126
- * group would report the group AND then the empty space — and the layout
127
+ * plugin would report the plugin AND then the empty space — and the layout
127
128
  * would render the empty-space menu, since the last call wins.
128
129
  */
129
130
  it('does not also report the nav when the click landed on a row', () => {
130
131
  const { onContextMenu } = renderSidebar();
131
132
  rightClick(screen.getByRole('button', { name: /^Engineering/ }));
132
133
  expect(onContextMenu).toHaveBeenCalledTimes(1);
133
- expect(onContextMenu.mock.calls[0][0].filter).toEqual({ kind: 'group', group: 'Engineering' });
134
+ expect(onContextMenu.mock.calls[0][0].filter).toEqual({ kind: 'group', plugin: 'Engineering' });
134
135
  });
135
136
 
136
137
  it('suppresses the browser menu when the click is being handled', () => {
@@ -156,12 +157,12 @@ describe('GroupsSidebar: right-click', () => {
156
157
  it('still navigates on a left click. The menu changes nothing about selection', () => {
157
158
  const { onSelect, onContextMenu } = renderSidebar();
158
159
  fireEvent.click(screen.getByRole('button', { name: /^GTM/ }));
159
- expect(onSelect).toHaveBeenCalledWith({ kind: 'group', group: 'GTM' });
160
+ expect(onSelect).toHaveBeenCalledWith({ kind: 'group', plugin: 'GTM' });
160
161
  expect(onContextMenu).not.toHaveBeenCalled();
161
162
  });
162
163
 
163
164
  it('marks the current row from the target it navigates to', () => {
164
- renderSidebar({ filter: { kind: 'group', group: 'GTM' } });
165
+ renderSidebar({ filter: { kind: 'group', plugin: 'GTM' } });
165
166
  expect(screen.getByRole('button', { name: /^GTM/ })).toHaveAttribute('aria-current', 'true');
166
167
  expect(screen.getByRole('button', { name: /^Engineering/ })).toHaveAttribute(
167
168
  'aria-current',
@@ -1,47 +1,48 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import { render, screen, fireEvent, within } from '@testing-library/react';
3
- import { GroupsSidebar, type GroupsSidebarProps } from '../components/GroupsSidebar';
3
+ import { PluginsSidebar, type PluginsSidebarProps } from '../components/PluginsSidebar';
4
4
 
5
5
  /**
6
- * The locked half of the nav: groups the caller cannot read still appear, below
6
+ * The locked half of the nav: plugins the caller cannot read still appear, below
7
7
  * a break, with a lock where a count would be.
8
8
  *
9
9
  * Locked selection is a URL like any other — a locked row emits the SAME
10
- * `{ kind: 'group' }` intent as a readable one, and the group page decides which
11
- * view the caller gets. That is deliberate: one route per group means a locked
12
- * group can be linked to and bookmarked, and unlocking one changes nothing about
10
+ * `{ kind: 'group' }` intent as a readable one, and the plugin page decides which
11
+ * view the caller gets. That is deliberate: one route per plugin means a locked
12
+ * plugin can be linked to and bookmarked, and unlocking one changes nothing about
13
13
  * where it lives.
14
14
  */
15
15
 
16
- function renderSidebar(over: Partial<GroupsSidebarProps> = {}) {
16
+ function renderSidebar(over: Partial<PluginsSidebarProps> = {}) {
17
17
  const onSelect = vi.fn();
18
- const props: GroupsSidebarProps = {
18
+ const props: PluginsSidebarProps = {
19
19
  filter: { kind: 'all' },
20
20
  onSelect,
21
- groups: [
22
- { group: 'Engineering', count: 4, attention: 0 },
23
- { group: 'GTM', count: 3, attention: 2 },
21
+ plugins: [
22
+ { plugin: 'Engineering', count: 4, attention: 0 },
23
+ { plugin: 'GTM', count: 3, attention: 2 },
24
24
  ],
25
- lockedGroups: ['Finance', 'Legal'],
25
+ lockedPlugins: ['Finance', 'Legal'],
26
26
  ownedCount: 2,
27
27
  ownedAttention: 0,
28
- personalGroupLabel: "Juan's Group",
28
+ personalPluginLabel: "Juan's Plugin",
29
29
  ungroupedCount: 1,
30
30
  attentionCount: 2,
31
31
  onFinishSetup: vi.fn(),
32
- onCreateGroup: vi.fn(),
33
- groupsIndexActive: false,
34
- onOpenGroupsIndex: vi.fn(),
32
+ onCreatePlugin: vi.fn(),
33
+ canCreatePlugin: true,
34
+ pluginsIndexActive: false,
35
+ onOpenPluginsIndex: vi.fn(),
35
36
 
36
37
  ...over,
37
38
  };
38
- render(<GroupsSidebar {...props} />);
39
+ render(<PluginsSidebar {...props} />);
39
40
  return { onSelect };
40
41
  }
41
42
 
42
- const nav = () => screen.getByRole('navigation', { name: 'Library groups' });
43
+ const nav = () => screen.getByRole('navigation', { name: 'Library plugins' });
43
44
 
44
- describe('GroupsSidebar: locked groups', () => {
45
+ describe('PluginsSidebar: locked plugins', () => {
45
46
  it('names a locked row by its state, with no count in it', () => {
46
47
  renderSidebar();
47
48
  const finance = screen.getByRole('button', { name: 'Finance (locked)' });
@@ -51,18 +52,18 @@ describe('GroupsSidebar: locked groups', () => {
51
52
  expect(finance.textContent).toBe('Finance');
52
53
  });
53
54
 
54
- it('puts the locked rows last, after every group the caller is in', () => {
55
+ it('puts the locked rows last, after every plugin the caller is in', () => {
55
56
  renderSidebar();
56
57
  const labels = within(nav())
57
58
  .getAllByRole('button')
58
59
  .map((b) => b.getAttribute('aria-label') ?? b.textContent);
59
60
  expect(labels).toEqual([
60
- 'All groups',
61
+ 'All plugins',
61
62
  'Everything',
62
63
  'Owned by me2',
63
- 'New group',
64
- // Your own space leads the groups; the ones you cannot enter trail them.
65
- "Juan's Group1",
64
+ 'New plugin',
65
+ // Your own space leads the plugins; the ones you cannot enter trail them.
66
+ "Juan's Plugin1",
66
67
  'Engineering4',
67
68
  'GTM2',
68
69
  'Finance (locked)',
@@ -70,14 +71,14 @@ describe('GroupsSidebar: locked groups', () => {
70
71
  ]);
71
72
  });
72
73
 
73
- it('navigates to the group route on click, exactly like a readable group', () => {
74
+ it('navigates to the plugin route on click, exactly like a readable plugin', () => {
74
75
  const { onSelect } = renderSidebar();
75
76
  fireEvent.click(screen.getByRole('button', { name: 'Finance (locked)' }));
76
- expect(onSelect).toHaveBeenCalledWith({ kind: 'group', group: 'Finance' });
77
+ expect(onSelect).toHaveBeenCalledWith({ kind: 'group', plugin: 'Finance' });
77
78
  });
78
79
 
79
- it('marks the locked row current when its group is the route', () => {
80
- renderSidebar({ filter: { kind: 'group', group: 'Finance' } });
80
+ it('marks the locked row current when its plugin is the route', () => {
81
+ renderSidebar({ filter: { kind: 'group', plugin: 'Finance' } });
81
82
  expect(screen.getByRole('button', { name: 'Finance (locked)' })).toHaveAttribute(
82
83
  'aria-current',
83
84
  'true',
@@ -89,7 +90,7 @@ describe('GroupsSidebar: locked groups', () => {
89
90
  });
90
91
 
91
92
  it('renders no locked section at all when nothing is locked', () => {
92
- renderSidebar({ lockedGroups: [] });
93
+ renderSidebar({ lockedPlugins: [] });
93
94
  expect(screen.queryByRole('button', { name: /\(locked\)$/ })).not.toBeInTheDocument();
94
95
  expect(screen.getByRole('button', { name: /^GTM/ })).toBeInTheDocument();
95
96
  });