@bevel-software/platform-core-frontend 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +18 -17
- package/src/core/__tests__/bootstrap.test.ts +33 -1
- package/src/core/bootstrap.ts +30 -1
- package/src/lib/__tests__/api.test.ts +38 -0
- package/src/lib/api.ts +19 -2
- package/src/lib/utils.ts +2 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
- package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
- package/src/modules/access/api.ts +52 -4
- package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
- package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
- package/src/modules/layout/components/SidebarFrame.tsx +1 -1
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -1
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
- package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
- package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
- package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
- package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
- package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
- package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
- package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
- package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +7 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
- package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
- package/src/modules/library/__tests__/library-paths.test.ts +32 -0
- package/src/modules/library/__tests__/link-membership.test.ts +120 -0
- package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
- package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
- package/src/modules/library/components/LibraryCard.tsx +14 -0
- package/src/modules/library/components/LibraryLayout.tsx +24 -14
- package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
- package/src/modules/library/components/LockedPluginView.tsx +2 -2
- package/src/modules/library/components/NewPluginDialog.tsx +4 -4
- package/src/modules/library/components/PageActions.tsx +21 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
- package/src/modules/library/components/PluginExtras.tsx +3 -1
- package/src/modules/library/components/PluginPage.tsx +92 -12
- package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
- package/src/modules/library/components/PluginsSidebar.tsx +110 -53
- package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
- package/src/modules/library/components/SkillsTree.tsx +91 -0
- package/src/modules/library/components/StatusDot.tsx +1 -0
- package/src/modules/library/components/plugin-page-parts.tsx +32 -9
- package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +70 -6
- package/src/modules/library/components/tool-page/ToolPage.tsx +11 -2
- package/src/modules/library/hooks/useJoinRequests.ts +48 -18
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
- package/src/modules/library/routes/library-paths.ts +21 -8
- package/src/modules/library/services/library.api.ts +55 -1
- package/src/modules/library/services/plugins.api.ts +94 -3
- package/src/modules/library/state/library-data.tsx +115 -22
- package/src/modules/library/utils/plugin-summary.ts +36 -0
- package/src/modules/library/utils/status.ts +74 -7
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
- package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
- package/src/modules/settings/components/DeploymentPage.tsx +15 -1
- package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
- package/src/modules/settings/services/github-facade.api.ts +43 -0
- package/src/modules/setup/__tests__/setup.test.tsx +118 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -1
- package/src/modules/setup/components/SetupScreen.tsx +195 -2
- package/src/modules/setup/services/setup.api.ts +78 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +295 -83
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
- package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
- package/src/modules/workspace/components/FileExplorer.tsx +292 -236
- package/src/modules/workspace/components/FileRoute.tsx +37 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
- package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
- package/src/modules/workspace/routing/kb-routes.ts +1 -1
- package/src/modules/workspace/state/workspace.context.ts +8 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
- package/src/modules/workspace/utils/fileTree.ts +14 -16
- package/src/shared/__tests__/marketplace-url.test.ts +54 -0
- package/src/shared/components/Badge.tsx +3 -1
- package/src/shared/components/Banner.tsx +5 -1
- package/src/shared/marketplace-url.ts +90 -0
- package/src/shared/theme/tokens.css +9 -0
|
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
2
2
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
|
-
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
5
|
+
import { DEFAULT_BRANCH, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
6
6
|
import {
|
|
7
7
|
WorkspaceContext,
|
|
8
8
|
type WorkspaceContextValue,
|
|
@@ -66,7 +66,7 @@ const CATALOG: LibraryData = {
|
|
|
66
66
|
|
|
67
67
|
const KB = 'knowledge-base';
|
|
68
68
|
|
|
69
|
-
function wrap(children: ReactNode) {
|
|
69
|
+
function wrap(children: ReactNode, fileTree: FileTreeEntry | null = null) {
|
|
70
70
|
const adminValue = {
|
|
71
71
|
isAdmin: false,
|
|
72
72
|
unreadCount: 0,
|
|
@@ -80,6 +80,8 @@ function wrap(children: ReactNode) {
|
|
|
80
80
|
const workspaceValue = {
|
|
81
81
|
workspaceId: 'ws',
|
|
82
82
|
kbDirName: KB,
|
|
83
|
+
fileTree,
|
|
84
|
+
pendingUploads: new Map(),
|
|
83
85
|
} as unknown as WorkspaceContextValue;
|
|
84
86
|
return (
|
|
85
87
|
<AdminContext.Provider value={adminValue}>
|
|
@@ -92,10 +94,17 @@ function wrap(children: ReactNode) {
|
|
|
92
94
|
|
|
93
95
|
function LocationProbe() {
|
|
94
96
|
const location = useLocation();
|
|
95
|
-
|
|
97
|
+
const rawFile = (location.state as { rawFile?: boolean } | null)?.rawFile === true;
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<div aria-label="pathname">{location.pathname}</div>
|
|
101
|
+
<div aria-label="hash">{location.hash}</div>
|
|
102
|
+
<div aria-label="raw-file">{String(rawFile)}</div>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
function renderAt(url: string) {
|
|
107
|
+
function renderAt(url: string, fileTree: FileTreeEntry | null = null) {
|
|
99
108
|
// The same two mounts the shell's CoreSurfaces gives this surface.
|
|
100
109
|
return render(
|
|
101
110
|
<MemoryRouter initialEntries={[url]}>
|
|
@@ -104,6 +113,7 @@ function renderAt(url: string) {
|
|
|
104
113
|
<Route path="/skills-and-tools/*" element={<LibraryRoutes />} />
|
|
105
114
|
<Route path="/workspace/*" element={<LibraryRoutes />} />
|
|
106
115
|
</Routes>,
|
|
116
|
+
fileTree,
|
|
107
117
|
)}
|
|
108
118
|
<LocationProbe />
|
|
109
119
|
</MemoryRouter>,
|
|
@@ -476,6 +486,107 @@ describe('WorkspaceItemRoute', () => {
|
|
|
476
486
|
);
|
|
477
487
|
});
|
|
478
488
|
|
|
489
|
+
/**
|
|
490
|
+
* The shared-skills root: skills and the scope folders that own them, no
|
|
491
|
+
* plugin around them. The same evidence rules as under `Plugins/`, with
|
|
492
|
+
* the two plugin destinations replaced — a scope has no page, and a file
|
|
493
|
+
* filed directly in a scope opens as the plain file it is.
|
|
494
|
+
*/
|
|
495
|
+
describe('a skill under the shared Skills/ root', () => {
|
|
496
|
+
const SHARED: LibraryData = {
|
|
497
|
+
...CATALOG,
|
|
498
|
+
skills: [
|
|
499
|
+
...CATALOG.skills,
|
|
500
|
+
{ name: 'discovery-call', description: '', path: 'Skills/Sales/discovery-call' },
|
|
501
|
+
],
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
beforeEach(() => {
|
|
505
|
+
dataMock.useLibraryData.mockReturnValue(SHARED);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("renders a shared skill file on that file's tab, inside the library nav", async () => {
|
|
509
|
+
renderAt(itemUrl('Skills/Sales/discovery-call/checklist.md'));
|
|
510
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('discovery-call::checklist.md');
|
|
511
|
+
expect(screen.getByRole('button', { name: /^All plugins/ })).toBeInTheDocument();
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('opens a bare shared skill folder on SKILL.md', async () => {
|
|
515
|
+
renderAt(itemUrl('Skills/Sales/discovery-call'));
|
|
516
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('discovery-call::SKILL.md');
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('resolves a just-created shared skill from its SKILL.md alone', async () => {
|
|
520
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
521
|
+
renderAt(itemUrl('Skills/Sales/brand-new/SKILL.md'));
|
|
522
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('brand-new::SKILL.md');
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('sends a SCOPE folder home — the sidebar tree is where scopes are browsed', async () => {
|
|
526
|
+
renderAt(itemUrl('Skills/Sales'));
|
|
527
|
+
await waitFor(() =>
|
|
528
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(/^\/skills-and-tools$/),
|
|
529
|
+
);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it("opens a scope's own file as a plain file, in the pane workspace", async () => {
|
|
533
|
+
renderAt(itemUrl('Skills/Sales/access.md'));
|
|
534
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
535
|
+
// Same URL — the raw view is router state, never a different address.
|
|
536
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(itemUrl('Skills/Sales/access.md'));
|
|
537
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("carries a scope file's #fragment into the raw view — a heading deep link still lands", async () => {
|
|
541
|
+
renderAt(`${itemUrl('Skills/Sales/README.md')}#goal`);
|
|
542
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
543
|
+
expect(screen.getByLabelText('hash')).toHaveTextContent('#goal');
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it("opens a scope's loose file as a plain file when the TREE shows no SKILL.md there — before the catalog answers", async () => {
|
|
547
|
+
// A scope with nothing the caller may read beneath it: the catalog has
|
|
548
|
+
// no evidence, but the workspace tree has the folder and no SKILL.md in
|
|
549
|
+
// it, and a folder without one is no skill.
|
|
550
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
551
|
+
const d = (rel: string, children: FileTreeEntry[]): FileTreeEntry => ({
|
|
552
|
+
name: rel.split('/').pop() ?? rel,
|
|
553
|
+
relativePath: rel,
|
|
554
|
+
type: 'directory',
|
|
555
|
+
children,
|
|
556
|
+
});
|
|
557
|
+
const tree = d('.', [
|
|
558
|
+
d(KB, [d(`${KB}/Skills`, [d(`${KB}/Skills/Sales`, [{ name: 'notes.md', relativePath: `${KB}/Skills/Sales/notes.md`, type: 'file' }])])]),
|
|
559
|
+
]);
|
|
560
|
+
renderAt(itemUrl('Skills/Sales/notes.md'), tree);
|
|
561
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
562
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("does not read a SKILL.md URL into a folder the tree shows has none as a skill", async () => {
|
|
566
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
567
|
+
const d = (rel: string, children: FileTreeEntry[]): FileTreeEntry => ({
|
|
568
|
+
name: rel.split('/').pop() ?? rel,
|
|
569
|
+
relativePath: rel,
|
|
570
|
+
type: 'directory',
|
|
571
|
+
children,
|
|
572
|
+
});
|
|
573
|
+
const tree = d('.', [
|
|
574
|
+
d(KB, [d(`${KB}/Skills`, [d(`${KB}/Skills/Sales`, [{ name: 'notes.md', relativePath: `${KB}/Skills/Sales/notes.md`, type: 'file' }])])]),
|
|
575
|
+
]);
|
|
576
|
+
renderAt(itemUrl('Skills/Sales/SKILL.md'), tree);
|
|
577
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
578
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it('waits for the catalog rather than guessing a scope is a skill', async () => {
|
|
582
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
583
|
+
renderAt(itemUrl('Skills/Sales'));
|
|
584
|
+
await waitFor(() => expect(screen.getByRole('button', { name: /^All plugins/ })).toBeInTheDocument());
|
|
585
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
586
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(itemUrl('Skills/Sales'));
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
|
|
479
590
|
it('a non-default branch never renders an item page', async () => {
|
|
480
591
|
renderAt(itemUrl('Plugins/Sales/create-sales-deck/SKILL.md', 'razvan/some-draft'));
|
|
481
592
|
await waitFor(() =>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
3
|
+
import type { LibraryData } from '../hooks/useLibraryData';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The catalog's own view of change requests refreshes on the same event the
|
|
7
|
+
* shell's change-request provider refreshes on. Two stores that each fetch
|
|
8
|
+
* requests are tolerable only while they move together.
|
|
9
|
+
*/
|
|
10
|
+
const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
|
|
11
|
+
vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
|
|
12
|
+
vi.mock('../services/plugins.api', () => ({ listPlugins: vi.fn().mockResolvedValue([]) }));
|
|
13
|
+
|
|
14
|
+
import { LibraryProvider, useLibrary } from '../state/library-data';
|
|
15
|
+
import { PR_STALE_EVENT } from '../../../core/events';
|
|
16
|
+
|
|
17
|
+
describe('LibraryProvider', () => {
|
|
18
|
+
it('reloads the catalog when change requests go stale', async () => {
|
|
19
|
+
const reload = vi.fn();
|
|
20
|
+
const data: LibraryData = {
|
|
21
|
+
loading: false,
|
|
22
|
+
error: null,
|
|
23
|
+
skills: [],
|
|
24
|
+
pendingSkills: [],
|
|
25
|
+
tools: [],
|
|
26
|
+
ownedSkills: new Set(),
|
|
27
|
+
allowedToolsBySkill: new Map(),
|
|
28
|
+
crs: [],
|
|
29
|
+
myCrNumbers: new Set(),
|
|
30
|
+
reload,
|
|
31
|
+
};
|
|
32
|
+
dataMock.useLibraryData.mockReturnValue(data);
|
|
33
|
+
const { listPlugins } = await import('../services/plugins.api');
|
|
34
|
+
vi.mocked(listPlugins).mockClear();
|
|
35
|
+
const view = render(<LibraryProvider>x</LibraryProvider>);
|
|
36
|
+
await act(async () => undefined);
|
|
37
|
+
expect(reload).not.toHaveBeenCalled();
|
|
38
|
+
expect(listPlugins).toHaveBeenCalledTimes(1);
|
|
39
|
+
await act(async () => {
|
|
40
|
+
window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
41
|
+
});
|
|
42
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
43
|
+
// A merged change can move plugin links and access: the summaries
|
|
44
|
+
// refresh with the catalog, not only on a page's own reload.
|
|
45
|
+
expect(listPlugins).toHaveBeenCalledTimes(2);
|
|
46
|
+
view.unmount();
|
|
47
|
+
await act(async () => {
|
|
48
|
+
window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
49
|
+
});
|
|
50
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("the context's reload refreshes the plugin summaries with the catalog", async () => {
|
|
54
|
+
// A page that reloads after a link, a repair or an access edit must get
|
|
55
|
+
// fresh plugin counts too — the broken-link number lives in the summary.
|
|
56
|
+
const reload = vi.fn();
|
|
57
|
+
const data: LibraryData = {
|
|
58
|
+
loading: false,
|
|
59
|
+
error: null,
|
|
60
|
+
skills: [],
|
|
61
|
+
pendingSkills: [],
|
|
62
|
+
tools: [],
|
|
63
|
+
ownedSkills: new Set(),
|
|
64
|
+
allowedToolsBySkill: new Map(),
|
|
65
|
+
crs: [],
|
|
66
|
+
myCrNumbers: new Set(),
|
|
67
|
+
reload,
|
|
68
|
+
};
|
|
69
|
+
dataMock.useLibraryData.mockReturnValue(data);
|
|
70
|
+
const { listPlugins } = await import('../services/plugins.api');
|
|
71
|
+
vi.mocked(listPlugins).mockClear();
|
|
72
|
+
let ctx: ReturnType<typeof useLibrary> | null = null;
|
|
73
|
+
function Probe() {
|
|
74
|
+
ctx = useLibrary();
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
render(
|
|
78
|
+
<LibraryProvider>
|
|
79
|
+
<Probe />
|
|
80
|
+
</LibraryProvider>,
|
|
81
|
+
);
|
|
82
|
+
await act(async () => undefined);
|
|
83
|
+
expect(listPlugins).toHaveBeenCalledTimes(1);
|
|
84
|
+
await act(async () => {
|
|
85
|
+
ctx!.reload();
|
|
86
|
+
});
|
|
87
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(listPlugins).toHaveBeenCalledTimes(2);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { LIBRARY_ROOT, libraryHomeForItemPath, pathForPlugin } from '../routes/library-paths';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where "back" goes from an item page. The plugin is named by its IDENTITY
|
|
6
|
+
* (resolved by the caller through the catalog) but a personal shelf is a
|
|
7
|
+
* place decided by the FOLDER — a personal item's identity is null, and it
|
|
8
|
+
* must still go home to "Yours".
|
|
9
|
+
*/
|
|
10
|
+
describe('libraryHomeForItemPath', () => {
|
|
11
|
+
it('sends a personal item to Yours even though it has no plugin identity', () => {
|
|
12
|
+
expect(libraryHomeForItemPath('Plugins/personal-u1/skills/notes', null)).toEqual({
|
|
13
|
+
label: 'Yours',
|
|
14
|
+
path: `${LIBRARY_ROOT}/yours`,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('sends a plugin item to its plugin by identity, labelled by the caller', () => {
|
|
19
|
+
expect(libraryHomeForItemPath('Plugins/GTM/skills/outreach', 'go-to-market', () => 'Go To Market')).toEqual({
|
|
20
|
+
label: 'Go To Market',
|
|
21
|
+
path: pathForPlugin('go-to-market'),
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('falls back to the folder when the caller resolved no identity', () => {
|
|
26
|
+
expect(libraryHomeForItemPath('Plugins/GTM/skills/outreach')).toEqual({ label: 'GTM', path: pathForPlugin('GTM') });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('sends a shared skill to the root', () => {
|
|
30
|
+
expect(libraryHomeForItemPath('Skills/Eng/deploy', null).path).toBe(LIBRARY_ROOT);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
filterLibraryItems,
|
|
4
|
+
isInPlugin,
|
|
5
|
+
isUngrouped,
|
|
6
|
+
pluginCounts,
|
|
7
|
+
pluginsOfItem,
|
|
8
|
+
withLinkHealth,
|
|
9
|
+
type AttentionStatus,
|
|
10
|
+
} from '../utils/status';
|
|
11
|
+
import { attentionOf, brokenLinksOf, type LibraryItem } from '../state/library-data';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Membership by LINK, alongside membership by folder. A shared skill under
|
|
15
|
+
* `Skills/` has no folder plugin, yet belongs to every plugin whose manifest
|
|
16
|
+
* links it — and the gallery, the sidebar counts and the plugin page all have
|
|
17
|
+
* to agree on that.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const OK: AttentionStatus = { state: 'ok', text: 'Ready' };
|
|
21
|
+
|
|
22
|
+
const shared = {
|
|
23
|
+
kind: 'skill' as const,
|
|
24
|
+
name: 'deploy',
|
|
25
|
+
description: 'Ship it.',
|
|
26
|
+
owned: false,
|
|
27
|
+
plugin: null,
|
|
28
|
+
shared: true,
|
|
29
|
+
plugins: [
|
|
30
|
+
{ name: 'GTM', linked: true, granted: true },
|
|
31
|
+
{ name: 'Ops', linked: true, granted: false },
|
|
32
|
+
],
|
|
33
|
+
status: OK,
|
|
34
|
+
};
|
|
35
|
+
const inline = {
|
|
36
|
+
kind: 'skill' as const,
|
|
37
|
+
name: 'outreach',
|
|
38
|
+
description: '',
|
|
39
|
+
owned: true,
|
|
40
|
+
plugin: 'GTM',
|
|
41
|
+
plugins: [{ name: 'GTM', linked: false, granted: true }],
|
|
42
|
+
status: OK,
|
|
43
|
+
};
|
|
44
|
+
const personal = { kind: 'skill' as const, name: 'mine', description: '', owned: true, plugin: null, status: OK };
|
|
45
|
+
|
|
46
|
+
describe('membership by link', () => {
|
|
47
|
+
it('a linked skill belongs to the plugins that link it, and to no folder plugin', () => {
|
|
48
|
+
expect(isInPlugin(shared, 'GTM')).toBe(true);
|
|
49
|
+
expect(isInPlugin(shared, 'Ops')).toBe(true);
|
|
50
|
+
expect(isInPlugin(shared, 'Sales')).toBe(false);
|
|
51
|
+
expect(pluginsOfItem(shared).sort()).toEqual(['GTM', 'Ops']);
|
|
52
|
+
// Shared is not "yours alone" — only the personal skill is.
|
|
53
|
+
expect(isUngrouped(shared)).toBe(false);
|
|
54
|
+
expect(isUngrouped(personal)).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('the plugin view and the sidebar counts follow links', () => {
|
|
58
|
+
const items = [shared, inline, personal];
|
|
59
|
+
expect(filterLibraryItems(items, { kind: 'group', plugin: 'GTM' }, '').map((i) => i.name)).toEqual([
|
|
60
|
+
'deploy',
|
|
61
|
+
'outreach',
|
|
62
|
+
]);
|
|
63
|
+
expect(filterLibraryItems(items, { kind: 'ungrouped' }, '').map((i) => i.name)).toEqual(['mine']);
|
|
64
|
+
expect(pluginCounts(items)).toEqual([
|
|
65
|
+
{ plugin: 'GTM', count: 2 },
|
|
66
|
+
{ plugin: 'Ops', count: 1 },
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('a link whose grant is missing wears the amber note on THAT plugin\'s page only', () => {
|
|
71
|
+
// Granted on GTM: untouched.
|
|
72
|
+
expect(withLinkHealth(shared, 'GTM').status).toBe(OK);
|
|
73
|
+
// Not granted on Ops: needs setup, in ORANGE (it locks members out), and
|
|
74
|
+
// says whose job it is.
|
|
75
|
+
expect(withLinkHealth(shared, 'Ops').status).toMatchObject({ state: 'urgent', text: 'Needs setup' });
|
|
76
|
+
expect(withLinkHealth({ ...shared, owned: true }, 'Ops').status.text).toBe(
|
|
77
|
+
'Needs setup: share with plugin members',
|
|
78
|
+
);
|
|
79
|
+
// Inline membership never wears it.
|
|
80
|
+
expect(withLinkHealth(inline, 'GTM').status).toBe(OK);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('a broken link never erases a reason the card already shows', () => {
|
|
84
|
+
const needsTools = { ...shared, status: { state: 'warn' as const, text: 'Needs setup: 1 tool' } };
|
|
85
|
+
// Ops's link is broken too — but the card's own reason comes first.
|
|
86
|
+
expect(withLinkHealth(needsTools, 'Ops').status).toBe(needsTools.status);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("a broken link counts in the plugin's attention, apart from its tools", () => {
|
|
90
|
+
const unsetTool = {
|
|
91
|
+
kind: 'integration' as const,
|
|
92
|
+
name: 'hubspot',
|
|
93
|
+
description: '',
|
|
94
|
+
owned: false,
|
|
95
|
+
plugin: 'Ops',
|
|
96
|
+
status: { state: 'warn' as const, text: 'Needs setup' },
|
|
97
|
+
};
|
|
98
|
+
const items = [shared, inline, personal, unsetTool] as unknown as LibraryItem[];
|
|
99
|
+
// Ops: one tool to set up, one linked skill its members cannot read.
|
|
100
|
+
expect(brokenLinksOf(items, 'Ops')).toBe(1);
|
|
101
|
+
expect(attentionOf(items, 'Ops')).toEqual({ total: 2, brokenLinks: 1 });
|
|
102
|
+
// GTM's link is granted: nothing to report.
|
|
103
|
+
expect(brokenLinksOf(items, 'GTM')).toBe(0);
|
|
104
|
+
expect(attentionOf(items, 'GTM')).toEqual({ total: 0, brokenLinks: 0 });
|
|
105
|
+
// An inline skill is never a broken link, whatever `granted` says.
|
|
106
|
+
const oddInline = { ...inline, plugins: [{ name: 'GTM', linked: false, granted: false }] };
|
|
107
|
+
expect(brokenLinksOf([oddInline] as unknown as LibraryItem[], 'GTM')).toBe(0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("the server's broken-link count wins over the caller's catalog", () => {
|
|
111
|
+
// The catalog cannot list a skill the caller may not read — which is the
|
|
112
|
+
// skill a missing grant is about — so the summary's count decides.
|
|
113
|
+
const items = [shared, inline] as unknown as LibraryItem[];
|
|
114
|
+
expect(brokenLinksOf(items, 'GTM', [{ name: 'GTM', brokenLinks: 2 }])).toBe(2);
|
|
115
|
+
expect(attentionOf(items, 'GTM', [{ name: 'GTM', brokenLinks: 2 }])).toEqual({ total: 2, brokenLinks: 2 });
|
|
116
|
+
// An older server sends no count: the catalog is the fallback.
|
|
117
|
+
expect(brokenLinksOf(items, 'Ops', [{ name: 'Ops' }])).toBe(1);
|
|
118
|
+
expect(brokenLinksOf(items, 'Ops', [])).toBe(1);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { pluginLabel, pluginNameForPath } from '../utils/plugin-summary';
|
|
3
|
+
|
|
4
|
+
const summaries = [
|
|
5
|
+
{ name: 'gtm', displayName: 'Go To Market', folders: ['Plugins/GTM'] },
|
|
6
|
+
{ name: 'deep', displayName: 'Deep', folders: ['Plugins/GTM/teams/Deep'] },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
describe('pluginNameForPath', () => {
|
|
10
|
+
it('names the plugin by the catalog folder holding the path — the deepest one', () => {
|
|
11
|
+
expect(pluginNameForPath('Plugins/GTM/skills/outreach', summaries)).toBe('gtm');
|
|
12
|
+
expect(pluginNameForPath('Plugins/GTM/teams/Deep/skills/x', summaries)).toBe('deep');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('asks the catalog FIRST: a listed folder names the plugin whatever the folder is called', () => {
|
|
16
|
+
const listed = [{ name: 'shelf', displayName: 'Shelf', folders: ['Plugins/personal-u1'] }];
|
|
17
|
+
expect(pluginNameForPath('Plugins/personal-u1/skills/notes', listed)).toBe('shelf');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('falls back to the folder for an unlisted path, and to null for a personal shelf', () => {
|
|
21
|
+
expect(pluginNameForPath('Plugins/Legacy/skills/x', summaries)).toBe('Legacy');
|
|
22
|
+
expect(pluginNameForPath('Plugins/personal-u1/skills/notes', summaries)).toBeNull();
|
|
23
|
+
expect(pluginNameForPath('Skills/Eng/deploy', summaries)).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('pluginLabel', () => {
|
|
28
|
+
it('is the display name, else the identity', () => {
|
|
29
|
+
expect(pluginLabel('gtm', summaries)).toBe('Go To Market');
|
|
30
|
+
expect(pluginLabel('unknown', summaries)).toBe('unknown');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type { JoinRequest } from '../services/plugins.api';
|
|
5
|
+
import { LibraryToastProvider } from '../state/toast';
|
|
6
|
+
import { useJoinRequests, type JoinRequestsApi } from '../hooks/useJoinRequests';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Requests belong to the plugin they were fetched for. A page that moves
|
|
10
|
+
* from one skill to the next without unmounting must show nothing of the
|
|
11
|
+
* previous one while the next one's answer is on its way: a banner still
|
|
12
|
+
* listing A's requests over B's folder would grant A's proposal to B.
|
|
13
|
+
*/
|
|
14
|
+
const request = (number: number): JoinRequest => ({
|
|
15
|
+
number,
|
|
16
|
+
branch: `ali/join-${number}`,
|
|
17
|
+
requesterName: 'Ali',
|
|
18
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
19
|
+
proposals: [],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const wrapper = ({ children }: { children: ReactNode }) => <LibraryToastProvider>{children}</LibraryToastProvider>;
|
|
23
|
+
|
|
24
|
+
describe('useJoinRequests', () => {
|
|
25
|
+
it('shows only the requests of the plugin it is asked about, never a previous one\'s', async () => {
|
|
26
|
+
let releaseB: (rows: JoinRequest[]) => void = () => {};
|
|
27
|
+
const api: JoinRequestsApi = {
|
|
28
|
+
list: vi.fn((name: string) =>
|
|
29
|
+
name === 'A' ? Promise.resolve([request(1)]) : new Promise<JoinRequest[]>((resolve) => (releaseB = resolve)),
|
|
30
|
+
),
|
|
31
|
+
reconcile: vi.fn().mockResolvedValue(false),
|
|
32
|
+
};
|
|
33
|
+
const { result, rerender } = renderHook(({ plugin }) => useJoinRequests(plugin, `Skills/${plugin}`, api), {
|
|
34
|
+
wrapper,
|
|
35
|
+
initialProps: { plugin: 'A' },
|
|
36
|
+
});
|
|
37
|
+
await waitFor(() => expect(result.current.requests.map((r) => r.number)).toEqual([1]));
|
|
38
|
+
|
|
39
|
+
rerender({ plugin: 'B' });
|
|
40
|
+
// B's answer has not arrived: nothing, not A's rows.
|
|
41
|
+
expect(result.current.requests).toEqual([]);
|
|
42
|
+
|
|
43
|
+
releaseB([request(2)]);
|
|
44
|
+
await waitFor(() => expect(result.current.requests.map((r) => r.number)).toEqual([2]));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Button, Dialog, Surface } from '../../../shared/components';
|
|
2
2
|
import { useAdmin } from '../../admin/state/admin.context';
|
|
3
3
|
import { NewSkillPanel } from './NewSkillPanel';
|
|
4
|
+
import { LinkSkillPanel } from './LinkSkillPanel';
|
|
5
|
+
import type { LibraryItem } from '../state/library-data';
|
|
4
6
|
import { useLibraryToast } from '../state/toast.context';
|
|
5
7
|
import { COPIED_TOAST, COPY_FAILED_TOAST, copyToClipboard } from '../utils/clipboard';
|
|
6
8
|
|
|
@@ -18,6 +20,13 @@ export interface AddToPluginDialogProps {
|
|
|
18
20
|
canWrite: boolean | null;
|
|
19
21
|
/** Every skill name already in the catalog. The admin create half rejects collisions. */
|
|
20
22
|
existingSkills: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The caller's catalog, for the "link an existing skill" half. Optional
|
|
25
|
+
* together with `onLinked`: a caller without them gets the dialog as it was
|
|
26
|
+
* before linking existed.
|
|
27
|
+
*/
|
|
28
|
+
linkable?: LibraryItem[];
|
|
29
|
+
onLinked?(): void;
|
|
21
30
|
onClose(): void;
|
|
22
31
|
}
|
|
23
32
|
|
|
@@ -43,6 +52,8 @@ export function AddToPluginDialog({
|
|
|
43
52
|
primaryPath,
|
|
44
53
|
canWrite,
|
|
45
54
|
existingSkills,
|
|
55
|
+
linkable,
|
|
56
|
+
onLinked,
|
|
46
57
|
onClose,
|
|
47
58
|
}: AddToPluginDialogProps) {
|
|
48
59
|
const { isAdmin } = useAdmin();
|
|
@@ -85,6 +96,28 @@ export function AddToPluginDialog({
|
|
|
85
96
|
: `Use the prompt below to have your agent draft the skill and send it to ${name} as a change request for an owner to review.`}
|
|
86
97
|
</p>
|
|
87
98
|
|
|
99
|
+
{/* Linking is the MANAGER's half: it edits this plugin's manifest, and the
|
|
100
|
+
server refuses anyone else. A non-manager only gets the prompt below. */}
|
|
101
|
+
{canWrite && linkable && onLinked && (
|
|
102
|
+
<>
|
|
103
|
+
<div className="mt-3">
|
|
104
|
+
<LinkSkillPanel
|
|
105
|
+
plugin={name}
|
|
106
|
+
items={linkable}
|
|
107
|
+
onLinked={() => {
|
|
108
|
+
onLinked();
|
|
109
|
+
onClose();
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
<div className="my-3.5 flex items-center gap-3">
|
|
114
|
+
<span aria-hidden="true" className="h-px flex-1 bg-line" />
|
|
115
|
+
<span className="text-meta text-ink-faint">or</span>
|
|
116
|
+
<span aria-hidden="true" className="h-px flex-1 bg-line" />
|
|
117
|
+
</div>
|
|
118
|
+
</>
|
|
119
|
+
)}
|
|
120
|
+
|
|
88
121
|
{isAdmin && (
|
|
89
122
|
<>
|
|
90
123
|
<NewSkillPanel
|
|
@@ -42,6 +42,13 @@ export interface LibraryCardCommonProps {
|
|
|
42
42
|
* person who has to decide (being waited on).
|
|
43
43
|
*/
|
|
44
44
|
pending?: { authorName: string; mine: boolean };
|
|
45
|
+
/**
|
|
46
|
+
* A skill's governance lifecycle (`metadata.lifecycle`). Only the two states
|
|
47
|
+
* that need a reader's attention are shown — `deprecated` (still works,
|
|
48
|
+
* find the replacement) and `retired` (kept for its owners, never
|
|
49
|
+
* distributed); `active` and absence render nothing.
|
|
50
|
+
*/
|
|
51
|
+
lifecycle?: string;
|
|
45
52
|
/** Open the item. The whole card is the target. */
|
|
46
53
|
onOpen(): void;
|
|
47
54
|
}
|
|
@@ -49,6 +56,7 @@ export interface LibraryCardCommonProps {
|
|
|
49
56
|
const STATUS_INK: Record<GemState, string> = {
|
|
50
57
|
ok: 'text-ok',
|
|
51
58
|
warn: 'text-wait',
|
|
59
|
+
urgent: 'text-urgent',
|
|
52
60
|
err: 'text-danger',
|
|
53
61
|
};
|
|
54
62
|
|
|
@@ -75,6 +83,7 @@ export function LibraryCard({
|
|
|
75
83
|
status,
|
|
76
84
|
version,
|
|
77
85
|
pending,
|
|
86
|
+
lifecycle,
|
|
78
87
|
onOpen,
|
|
79
88
|
flavor,
|
|
80
89
|
}: LibraryCardProps) {
|
|
@@ -142,6 +151,11 @@ export function LibraryCard({
|
|
|
142
151
|
Owner
|
|
143
152
|
</Badge>
|
|
144
153
|
)}
|
|
154
|
+
{(lifecycle === 'deprecated' || lifecycle === 'retired') && (
|
|
155
|
+
<Badge tone="wait" size="xs" className="shrink-0 uppercase">
|
|
156
|
+
{lifecycle === 'retired' ? 'Retired' : 'Deprecated'}
|
|
157
|
+
</Badge>
|
|
158
|
+
)}
|
|
145
159
|
</span>
|
|
146
160
|
|
|
147
161
|
{description && (
|