@bevel-software/platform-core-frontend 0.4.0 → 0.4.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/__tests__/ShellRoutes.test.tsx +95 -95
- package/src/lib/utils.ts +138 -138
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +156 -156
- package/src/modules/admin/components/UserAccountsPage.tsx +353 -353
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
- package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -200
- package/src/modules/library/__tests__/loadout.test.tsx +72 -72
- package/src/modules/library/__tests__/status.test.ts +117 -117
- package/src/modules/library/components/ChangeRequestDock.tsx +47 -47
- package/src/modules/library/components/CompareView.tsx +357 -357
- package/src/modules/library/components/DetailDialog.tsx +566 -566
- package/src/modules/library/components/GearIcon.tsx +12 -12
- package/src/modules/library/components/LibraryCard.tsx +132 -132
- package/src/modules/library/components/LibraryPage.tsx +254 -254
- package/src/modules/library/components/LoadoutSidebar.tsx +156 -156
- package/src/modules/library/components/StatusGem.tsx +21 -21
- package/src/modules/library/components/SuggestChange.tsx +171 -171
- package/src/modules/library/components/particles.ts +50 -50
- package/src/modules/library/library.css +320 -320
- package/src/modules/library/state/loadout.tsx +129 -129
- package/src/modules/library/utils/status.ts +116 -116
- package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -276
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -51
- package/src/modules/toolbar/components/AppSwitcher.tsx +108 -108
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
- package/src/modules/workspace/components/FileExplorer.tsx +1068 -1068
- package/src/modules/workspace/components/FileViewer.tsx +906 -906
- package/src/modules/workspace/utils/fileTree.ts +179 -179
- package/src/shared/components/PageShell.tsx +51 -51
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { Loader2 } from 'lucide-react';
|
|
3
|
-
import { API_UNREACHABLE_EVENT } from '../../../lib/api';
|
|
4
|
-
|
|
5
|
-
/** How often to re-probe `/api/health` while the backend is down. */
|
|
6
|
-
const HEALTH_POLL_MS = 3_000;
|
|
7
|
-
|
|
8
|
-
/** Abort a probe that hangs (black-holed connection) — the probe loop gates
|
|
9
|
-
on each probe finishing, so a stuck fetch would freeze the overlay. */
|
|
10
|
-
const HEALTH_PROBE_TIMEOUT_MS = 5_000;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Probe the backend. Bypasses `authFetch` on purpose: the health route is
|
|
14
|
-
* unauthenticated, and a probe must never itself dispatch the
|
|
15
|
-
* unreachable event this overlay listens for. A timed-out probe counts as
|
|
16
|
-
* unhealthy.
|
|
17
|
-
*/
|
|
18
|
-
async function backendHealthy(): Promise<boolean> {
|
|
19
|
-
const controller = new AbortController();
|
|
20
|
-
const timer = setTimeout(() => controller.abort(), HEALTH_PROBE_TIMEOUT_MS);
|
|
21
|
-
try {
|
|
22
|
-
const res = await fetch('/api/health', { cache: 'no-store', signal: controller.signal });
|
|
23
|
-
if (!res.ok) return false;
|
|
24
|
-
const body = (await res.json()) as { status?: string };
|
|
25
|
-
return body.status === 'ok';
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
} finally {
|
|
29
|
-
clearTimeout(timer);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Full-screen "we're updating" screen for backend downtime (Coolify rebuild /
|
|
35
|
-
* container restart). Flow:
|
|
36
|
-
*
|
|
37
|
-
* 1. `authFetch` dispatches API_UNREACHABLE_EVENT when a request fails at
|
|
38
|
-
* the transport level (network error, or a 502/503/504 from the proxy
|
|
39
|
-
* in front of a dead upstream).
|
|
40
|
-
* 2. On that signal we confirm via `/api/health` — a single flaky request
|
|
41
|
-
* must not take over the whole screen. Only a failed probe shows the
|
|
42
|
-
* overlay.
|
|
43
|
-
* 3. While down, re-probe every HEALTH_POLL_MS. When health comes back the
|
|
44
|
-
* page reloads so the browser picks up the freshly deployed frontend
|
|
45
|
-
* bundle instead of running the old one against the new backend. If the
|
|
46
|
-
* user has unsaved work, FileViewer's `beforeunload` guard makes the
|
|
47
|
-
* browser ask before the reload discards it.
|
|
48
|
-
*
|
|
49
|
-
* This only covers users with the app already open. A fresh page load during
|
|
50
|
-
* the rebuild is answered by the proxy before our code runs — that error page
|
|
51
|
-
* is Coolify/Traefik configuration, not frontend code (see docs/deploy.md).
|
|
52
|
-
*/
|
|
53
|
-
export function MaintenanceOverlay() {
|
|
54
|
-
const [down, setDown] = useState(false);
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
let cancelled = false;
|
|
58
|
-
// Collapse overlapping signals: many in-flight requests fail at once
|
|
59
|
-
// when the backend goes away, but one probe loop is enough.
|
|
60
|
-
let probing = false;
|
|
61
|
-
|
|
62
|
-
const onUnreachable = async () => {
|
|
63
|
-
if (probing || cancelled) return;
|
|
64
|
-
probing = true;
|
|
65
|
-
try {
|
|
66
|
-
if (await backendHealthy()) return; // isolated failure, not downtime
|
|
67
|
-
if (cancelled) return;
|
|
68
|
-
setDown(true);
|
|
69
|
-
while (!cancelled) {
|
|
70
|
-
await new Promise((r) => setTimeout(r, HEALTH_POLL_MS));
|
|
71
|
-
if (await backendHealthy()) {
|
|
72
|
-
window.location.reload();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} finally {
|
|
77
|
-
probing = false;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
window.addEventListener(API_UNREACHABLE_EVENT, onUnreachable);
|
|
82
|
-
return () => {
|
|
83
|
-
cancelled = true;
|
|
84
|
-
window.removeEventListener(API_UNREACHABLE_EVENT, onUnreachable);
|
|
85
|
-
};
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
if (!down) return null;
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<div className="fixed inset-0 z-[100] flex flex-col items-center justify-center gap-4 bg-white/95 backdrop-blur-sm text-center px-6">
|
|
92
|
-
<Loader2 size={32} className="animate-spin text-bevel" />
|
|
93
|
-
<div>
|
|
94
|
-
<p className="text-lg font-medium text-slate-800">
|
|
95
|
-
We’re installing an update
|
|
96
|
-
</p>
|
|
97
|
-
<p className="mt-1 text-sm text-slate-600">
|
|
98
|
-
This usually takes a minute or two. The page will refresh
|
|
99
|
-
automatically as soon as everything is back.
|
|
100
|
-
</p>
|
|
101
|
-
</div>
|
|
102
|
-
</div>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Loader2 } from 'lucide-react';
|
|
3
|
+
import { API_UNREACHABLE_EVENT } from '../../../lib/api';
|
|
4
|
+
|
|
5
|
+
/** How often to re-probe `/api/health` while the backend is down. */
|
|
6
|
+
const HEALTH_POLL_MS = 3_000;
|
|
7
|
+
|
|
8
|
+
/** Abort a probe that hangs (black-holed connection) — the probe loop gates
|
|
9
|
+
on each probe finishing, so a stuck fetch would freeze the overlay. */
|
|
10
|
+
const HEALTH_PROBE_TIMEOUT_MS = 5_000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Probe the backend. Bypasses `authFetch` on purpose: the health route is
|
|
14
|
+
* unauthenticated, and a probe must never itself dispatch the
|
|
15
|
+
* unreachable event this overlay listens for. A timed-out probe counts as
|
|
16
|
+
* unhealthy.
|
|
17
|
+
*/
|
|
18
|
+
async function backendHealthy(): Promise<boolean> {
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
const timer = setTimeout(() => controller.abort(), HEALTH_PROBE_TIMEOUT_MS);
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch('/api/health', { cache: 'no-store', signal: controller.signal });
|
|
23
|
+
if (!res.ok) return false;
|
|
24
|
+
const body = (await res.json()) as { status?: string };
|
|
25
|
+
return body.status === 'ok';
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
} finally {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Full-screen "we're updating" screen for backend downtime (Coolify rebuild /
|
|
35
|
+
* container restart). Flow:
|
|
36
|
+
*
|
|
37
|
+
* 1. `authFetch` dispatches API_UNREACHABLE_EVENT when a request fails at
|
|
38
|
+
* the transport level (network error, or a 502/503/504 from the proxy
|
|
39
|
+
* in front of a dead upstream).
|
|
40
|
+
* 2. On that signal we confirm via `/api/health` — a single flaky request
|
|
41
|
+
* must not take over the whole screen. Only a failed probe shows the
|
|
42
|
+
* overlay.
|
|
43
|
+
* 3. While down, re-probe every HEALTH_POLL_MS. When health comes back the
|
|
44
|
+
* page reloads so the browser picks up the freshly deployed frontend
|
|
45
|
+
* bundle instead of running the old one against the new backend. If the
|
|
46
|
+
* user has unsaved work, FileViewer's `beforeunload` guard makes the
|
|
47
|
+
* browser ask before the reload discards it.
|
|
48
|
+
*
|
|
49
|
+
* This only covers users with the app already open. A fresh page load during
|
|
50
|
+
* the rebuild is answered by the proxy before our code runs — that error page
|
|
51
|
+
* is Coolify/Traefik configuration, not frontend code (see docs/deploy.md).
|
|
52
|
+
*/
|
|
53
|
+
export function MaintenanceOverlay() {
|
|
54
|
+
const [down, setDown] = useState(false);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
// Collapse overlapping signals: many in-flight requests fail at once
|
|
59
|
+
// when the backend goes away, but one probe loop is enough.
|
|
60
|
+
let probing = false;
|
|
61
|
+
|
|
62
|
+
const onUnreachable = async () => {
|
|
63
|
+
if (probing || cancelled) return;
|
|
64
|
+
probing = true;
|
|
65
|
+
try {
|
|
66
|
+
if (await backendHealthy()) return; // isolated failure, not downtime
|
|
67
|
+
if (cancelled) return;
|
|
68
|
+
setDown(true);
|
|
69
|
+
while (!cancelled) {
|
|
70
|
+
await new Promise((r) => setTimeout(r, HEALTH_POLL_MS));
|
|
71
|
+
if (await backendHealthy()) {
|
|
72
|
+
window.location.reload();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} finally {
|
|
77
|
+
probing = false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
window.addEventListener(API_UNREACHABLE_EVENT, onUnreachable);
|
|
82
|
+
return () => {
|
|
83
|
+
cancelled = true;
|
|
84
|
+
window.removeEventListener(API_UNREACHABLE_EVENT, onUnreachable);
|
|
85
|
+
};
|
|
86
|
+
}, []);
|
|
87
|
+
|
|
88
|
+
if (!down) return null;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div className="fixed inset-0 z-[100] flex flex-col items-center justify-center gap-4 bg-white/95 backdrop-blur-sm text-center px-6">
|
|
92
|
+
<Loader2 size={32} className="animate-spin text-bevel" />
|
|
93
|
+
<div>
|
|
94
|
+
<p className="text-lg font-medium text-slate-800">
|
|
95
|
+
We’re installing an update
|
|
96
|
+
</p>
|
|
97
|
+
<p className="mt-1 text-sm text-slate-600">
|
|
98
|
+
This usually takes a minute or two. The page will refresh
|
|
99
|
+
automatically as soon as everything is back.
|
|
100
|
+
</p>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
-
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
-
import type { ReactNode } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
WorkspaceContext,
|
|
7
|
-
type WorkspaceContextValue,
|
|
8
|
-
} from '../../workspace/state/workspace.context';
|
|
9
|
-
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
10
|
-
import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
11
|
-
|
|
12
|
-
// Service mocks — the dialog's data loading goes through the module's api
|
|
13
|
-
// service (which wraps authFetch), so mocking here follows the same pattern
|
|
14
|
-
// as the other modules' tests.
|
|
15
|
-
const apiMock = vi.hoisted(() => ({
|
|
16
|
-
getSkill: vi.fn(),
|
|
17
|
-
getSkillFile: vi.fn(),
|
|
18
|
-
readFileOnBranch: vi.fn(),
|
|
19
|
-
suggestChange: vi.fn(),
|
|
20
|
-
}));
|
|
21
|
-
vi.mock('../services/library.api', () => ({
|
|
22
|
-
DEFAULT_WORKSPACE_ID: 'target-company-state',
|
|
23
|
-
getSkill: apiMock.getSkill,
|
|
24
|
-
getSkillFile: apiMock.getSkillFile,
|
|
25
|
-
readFileOnBranch: apiMock.readFileOnBranch,
|
|
26
|
-
suggestChange: apiMock.suggestChange,
|
|
27
|
-
listSkills: vi.fn(),
|
|
28
|
-
listOpenChangeRequests: vi.fn(),
|
|
29
|
-
listMyChangeRequests: vi.fn(),
|
|
30
|
-
suggestionBranchFor: vi.fn(),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
// Keep the markdown pipeline (mermaid etc.) out of this test — the stub
|
|
34
|
-
// renders the raw source so assertions can see the body text.
|
|
35
|
-
vi.mock('../../workspace/components/renderers/KbMarkdownView', () => ({
|
|
36
|
-
KbMarkdownView: ({ source }: { source: string }) => <div data-testid="md-view">{source}</div>,
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
import { DetailDialog } from '../components/DetailDialog';
|
|
40
|
-
|
|
41
|
-
const workspace = {
|
|
42
|
-
workspaceId: 'target-company-state',
|
|
43
|
-
kbDirName: 'knowledge-base',
|
|
44
|
-
} as unknown as WorkspaceContextValue;
|
|
45
|
-
|
|
46
|
-
const auth = {
|
|
47
|
-
user: { id: 'u1', email: 'razvan@bevel.software', name: 'Razvan' },
|
|
48
|
-
token: 't',
|
|
49
|
-
isLoading: false,
|
|
50
|
-
login: async () => {},
|
|
51
|
-
logout: () => {},
|
|
52
|
-
} as AuthContextValue;
|
|
53
|
-
|
|
54
|
-
function wrap(children: ReactNode) {
|
|
55
|
-
return (
|
|
56
|
-
<MemoryRouter>
|
|
57
|
-
<AuthContext.Provider value={auth}>
|
|
58
|
-
<WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>
|
|
59
|
-
</AuthContext.Provider>
|
|
60
|
-
</MemoryRouter>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const skillSummary = {
|
|
65
|
-
name: 'newsletter',
|
|
66
|
-
description: 'Drafts the Friday newsletter for review.',
|
|
67
|
-
path: 'Skills/newsletter',
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const skillDetail = {
|
|
71
|
-
...skillSummary,
|
|
72
|
-
body: '# Newsletter drafter\nCollect the news and draft the letter.',
|
|
73
|
-
allowedTools: ['slack_post_message'],
|
|
74
|
-
files: ['Skills/newsletter/sources.yaml'],
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const slackTool: ToolSecrets = {
|
|
78
|
-
slug: 'slack',
|
|
79
|
-
name: 'slack',
|
|
80
|
-
path: 'Tools/slack.tool',
|
|
81
|
-
type: 'http',
|
|
82
|
-
setup: null,
|
|
83
|
-
canWrite: false,
|
|
84
|
-
variables: [
|
|
85
|
-
{
|
|
86
|
-
name: 'SIGNIN',
|
|
87
|
-
scope: 'user',
|
|
88
|
-
label: 'Slack sign-in',
|
|
89
|
-
key: 'slack_SIGNIN',
|
|
90
|
-
adminConfigured: true,
|
|
91
|
-
userConfigured: false,
|
|
92
|
-
oauth: true,
|
|
93
|
-
authorized: false,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
function renderDialog(owned: boolean) {
|
|
99
|
-
return render(
|
|
100
|
-
wrap(
|
|
101
|
-
<DetailDialog
|
|
102
|
-
target={{ kind: 'skill', skill: skillSummary, owned }}
|
|
103
|
-
tools={[slackTool]}
|
|
104
|
-
skills={[skillSummary]}
|
|
105
|
-
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
106
|
-
crs={[]}
|
|
107
|
-
myCrNumbers={new Set()}
|
|
108
|
-
inLoadout={false}
|
|
109
|
-
onToggleLoadout={() => {}}
|
|
110
|
-
onClose={() => {}}
|
|
111
|
-
onDataChanged={() => {}}
|
|
112
|
-
/>,
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
beforeEach(() => {
|
|
118
|
-
apiMock.getSkill.mockReset().mockResolvedValue(skillDetail);
|
|
119
|
-
apiMock.getSkillFile.mockReset().mockResolvedValue('watchlist:\n - topic: AI');
|
|
120
|
-
apiMock.readFileOnBranch.mockReset().mockResolvedValue('');
|
|
121
|
-
apiMock.suggestChange.mockReset();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('DetailDialog (skill)', () => {
|
|
125
|
-
it('loads the skill detail and shows description, needed integrations and files', async () => {
|
|
126
|
-
renderDialog(false);
|
|
127
|
-
|
|
128
|
-
expect(await screen.findByText('Drafts the Friday newsletter for review.')).toBeInTheDocument();
|
|
129
|
-
expect(apiMock.getSkill).toHaveBeenCalledWith('newsletter');
|
|
130
|
-
|
|
131
|
-
// Needed integration derived from allowed-tools, with its connection state.
|
|
132
|
-
expect(screen.getByText('slack')).toBeInTheDocument();
|
|
133
|
-
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
134
|
-
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
135
|
-
|
|
136
|
-
// File browser: SKILL.md tagged MAIN + the bundled file.
|
|
137
|
-
expect(screen.getAllByText('SKILL.md').length).toBeGreaterThan(0);
|
|
138
|
-
expect(screen.getByText('MAIN')).toBeInTheDocument();
|
|
139
|
-
expect(screen.getByText('sources.yaml')).toBeInTheDocument();
|
|
140
|
-
|
|
141
|
-
// SKILL.md body renders through the markdown view.
|
|
142
|
-
expect(screen.getByTestId('md-view').textContent).toContain('Collect the news');
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('loads a bundled file on click and renders it as code', async () => {
|
|
146
|
-
renderDialog(false);
|
|
147
|
-
await screen.findByText('sources.yaml');
|
|
148
|
-
|
|
149
|
-
fireEvent.click(screen.getByText('sources.yaml'));
|
|
150
|
-
await waitFor(() =>
|
|
151
|
-
expect(apiMock.getSkillFile).toHaveBeenCalledWith('newsletter', 'sources.yaml'),
|
|
152
|
-
);
|
|
153
|
-
expect(await screen.findByText(/topic: AI/)).toBeInTheDocument();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('shows owner-only Edit and Manage access when the caller owns the skill', async () => {
|
|
157
|
-
renderDialog(true);
|
|
158
|
-
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
159
|
-
|
|
160
|
-
expect(screen.getByRole('button', { name: 'Manage access' })).toBeInTheDocument();
|
|
161
|
-
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
162
|
-
expect(screen.getByText('OWNER')).toBeInTheDocument();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('hides Edit and Manage access for non-owners', async () => {
|
|
166
|
-
renderDialog(false);
|
|
167
|
-
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
168
|
-
|
|
169
|
-
expect(screen.queryByRole('button', { name: 'Manage access' })).toBeNull();
|
|
170
|
-
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
171
|
-
expect(screen.queryByText('OWNER')).toBeNull();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('DetailDialog (integration)', () => {
|
|
176
|
-
it('shows per-connection status with a Connect action and the skills using it', async () => {
|
|
177
|
-
render(
|
|
178
|
-
wrap(
|
|
179
|
-
<DetailDialog
|
|
180
|
-
target={{ kind: 'integration', tool: slackTool }}
|
|
181
|
-
tools={[slackTool]}
|
|
182
|
-
skills={[skillSummary]}
|
|
183
|
-
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
184
|
-
crs={[]}
|
|
185
|
-
myCrNumbers={new Set()}
|
|
186
|
-
inLoadout={false}
|
|
187
|
-
onToggleLoadout={() => {}}
|
|
188
|
-
onClose={() => {}}
|
|
189
|
-
onDataChanged={() => {}}
|
|
190
|
-
/>,
|
|
191
|
-
),
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
expect(screen.getByText('Slack sign-in')).toBeInTheDocument();
|
|
195
|
-
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
196
|
-
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
197
|
-
// Used by: derived from the skills' allowed-tools.
|
|
198
|
-
expect(screen.getByText('newsletter')).toBeInTheDocument();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
WorkspaceContext,
|
|
7
|
+
type WorkspaceContextValue,
|
|
8
|
+
} from '../../workspace/state/workspace.context';
|
|
9
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
10
|
+
import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
11
|
+
|
|
12
|
+
// Service mocks — the dialog's data loading goes through the module's api
|
|
13
|
+
// service (which wraps authFetch), so mocking here follows the same pattern
|
|
14
|
+
// as the other modules' tests.
|
|
15
|
+
const apiMock = vi.hoisted(() => ({
|
|
16
|
+
getSkill: vi.fn(),
|
|
17
|
+
getSkillFile: vi.fn(),
|
|
18
|
+
readFileOnBranch: vi.fn(),
|
|
19
|
+
suggestChange: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../services/library.api', () => ({
|
|
22
|
+
DEFAULT_WORKSPACE_ID: 'target-company-state',
|
|
23
|
+
getSkill: apiMock.getSkill,
|
|
24
|
+
getSkillFile: apiMock.getSkillFile,
|
|
25
|
+
readFileOnBranch: apiMock.readFileOnBranch,
|
|
26
|
+
suggestChange: apiMock.suggestChange,
|
|
27
|
+
listSkills: vi.fn(),
|
|
28
|
+
listOpenChangeRequests: vi.fn(),
|
|
29
|
+
listMyChangeRequests: vi.fn(),
|
|
30
|
+
suggestionBranchFor: vi.fn(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
// Keep the markdown pipeline (mermaid etc.) out of this test — the stub
|
|
34
|
+
// renders the raw source so assertions can see the body text.
|
|
35
|
+
vi.mock('../../workspace/components/renderers/KbMarkdownView', () => ({
|
|
36
|
+
KbMarkdownView: ({ source }: { source: string }) => <div data-testid="md-view">{source}</div>,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
import { DetailDialog } from '../components/DetailDialog';
|
|
40
|
+
|
|
41
|
+
const workspace = {
|
|
42
|
+
workspaceId: 'target-company-state',
|
|
43
|
+
kbDirName: 'knowledge-base',
|
|
44
|
+
} as unknown as WorkspaceContextValue;
|
|
45
|
+
|
|
46
|
+
const auth = {
|
|
47
|
+
user: { id: 'u1', email: 'razvan@bevel.software', name: 'Razvan' },
|
|
48
|
+
token: 't',
|
|
49
|
+
isLoading: false,
|
|
50
|
+
login: async () => {},
|
|
51
|
+
logout: () => {},
|
|
52
|
+
} as AuthContextValue;
|
|
53
|
+
|
|
54
|
+
function wrap(children: ReactNode) {
|
|
55
|
+
return (
|
|
56
|
+
<MemoryRouter>
|
|
57
|
+
<AuthContext.Provider value={auth}>
|
|
58
|
+
<WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>
|
|
59
|
+
</AuthContext.Provider>
|
|
60
|
+
</MemoryRouter>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const skillSummary = {
|
|
65
|
+
name: 'newsletter',
|
|
66
|
+
description: 'Drafts the Friday newsletter for review.',
|
|
67
|
+
path: 'Skills/newsletter',
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const skillDetail = {
|
|
71
|
+
...skillSummary,
|
|
72
|
+
body: '# Newsletter drafter\nCollect the news and draft the letter.',
|
|
73
|
+
allowedTools: ['slack_post_message'],
|
|
74
|
+
files: ['Skills/newsletter/sources.yaml'],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const slackTool: ToolSecrets = {
|
|
78
|
+
slug: 'slack',
|
|
79
|
+
name: 'slack',
|
|
80
|
+
path: 'Tools/slack.tool',
|
|
81
|
+
type: 'http',
|
|
82
|
+
setup: null,
|
|
83
|
+
canWrite: false,
|
|
84
|
+
variables: [
|
|
85
|
+
{
|
|
86
|
+
name: 'SIGNIN',
|
|
87
|
+
scope: 'user',
|
|
88
|
+
label: 'Slack sign-in',
|
|
89
|
+
key: 'slack_SIGNIN',
|
|
90
|
+
adminConfigured: true,
|
|
91
|
+
userConfigured: false,
|
|
92
|
+
oauth: true,
|
|
93
|
+
authorized: false,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function renderDialog(owned: boolean) {
|
|
99
|
+
return render(
|
|
100
|
+
wrap(
|
|
101
|
+
<DetailDialog
|
|
102
|
+
target={{ kind: 'skill', skill: skillSummary, owned }}
|
|
103
|
+
tools={[slackTool]}
|
|
104
|
+
skills={[skillSummary]}
|
|
105
|
+
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
106
|
+
crs={[]}
|
|
107
|
+
myCrNumbers={new Set()}
|
|
108
|
+
inLoadout={false}
|
|
109
|
+
onToggleLoadout={() => {}}
|
|
110
|
+
onClose={() => {}}
|
|
111
|
+
onDataChanged={() => {}}
|
|
112
|
+
/>,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
apiMock.getSkill.mockReset().mockResolvedValue(skillDetail);
|
|
119
|
+
apiMock.getSkillFile.mockReset().mockResolvedValue('watchlist:\n - topic: AI');
|
|
120
|
+
apiMock.readFileOnBranch.mockReset().mockResolvedValue('');
|
|
121
|
+
apiMock.suggestChange.mockReset();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('DetailDialog (skill)', () => {
|
|
125
|
+
it('loads the skill detail and shows description, needed integrations and files', async () => {
|
|
126
|
+
renderDialog(false);
|
|
127
|
+
|
|
128
|
+
expect(await screen.findByText('Drafts the Friday newsletter for review.')).toBeInTheDocument();
|
|
129
|
+
expect(apiMock.getSkill).toHaveBeenCalledWith('newsletter');
|
|
130
|
+
|
|
131
|
+
// Needed integration derived from allowed-tools, with its connection state.
|
|
132
|
+
expect(screen.getByText('slack')).toBeInTheDocument();
|
|
133
|
+
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
134
|
+
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
135
|
+
|
|
136
|
+
// File browser: SKILL.md tagged MAIN + the bundled file.
|
|
137
|
+
expect(screen.getAllByText('SKILL.md').length).toBeGreaterThan(0);
|
|
138
|
+
expect(screen.getByText('MAIN')).toBeInTheDocument();
|
|
139
|
+
expect(screen.getByText('sources.yaml')).toBeInTheDocument();
|
|
140
|
+
|
|
141
|
+
// SKILL.md body renders through the markdown view.
|
|
142
|
+
expect(screen.getByTestId('md-view').textContent).toContain('Collect the news');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('loads a bundled file on click and renders it as code', async () => {
|
|
146
|
+
renderDialog(false);
|
|
147
|
+
await screen.findByText('sources.yaml');
|
|
148
|
+
|
|
149
|
+
fireEvent.click(screen.getByText('sources.yaml'));
|
|
150
|
+
await waitFor(() =>
|
|
151
|
+
expect(apiMock.getSkillFile).toHaveBeenCalledWith('newsletter', 'sources.yaml'),
|
|
152
|
+
);
|
|
153
|
+
expect(await screen.findByText(/topic: AI/)).toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('shows owner-only Edit and Manage access when the caller owns the skill', async () => {
|
|
157
|
+
renderDialog(true);
|
|
158
|
+
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
159
|
+
|
|
160
|
+
expect(screen.getByRole('button', { name: 'Manage access' })).toBeInTheDocument();
|
|
161
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
162
|
+
expect(screen.getByText('OWNER')).toBeInTheDocument();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('hides Edit and Manage access for non-owners', async () => {
|
|
166
|
+
renderDialog(false);
|
|
167
|
+
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
168
|
+
|
|
169
|
+
expect(screen.queryByRole('button', { name: 'Manage access' })).toBeNull();
|
|
170
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
171
|
+
expect(screen.queryByText('OWNER')).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('DetailDialog (integration)', () => {
|
|
176
|
+
it('shows per-connection status with a Connect action and the skills using it', async () => {
|
|
177
|
+
render(
|
|
178
|
+
wrap(
|
|
179
|
+
<DetailDialog
|
|
180
|
+
target={{ kind: 'integration', tool: slackTool }}
|
|
181
|
+
tools={[slackTool]}
|
|
182
|
+
skills={[skillSummary]}
|
|
183
|
+
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
184
|
+
crs={[]}
|
|
185
|
+
myCrNumbers={new Set()}
|
|
186
|
+
inLoadout={false}
|
|
187
|
+
onToggleLoadout={() => {}}
|
|
188
|
+
onClose={() => {}}
|
|
189
|
+
onDataChanged={() => {}}
|
|
190
|
+
/>,
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
expect(screen.getByText('Slack sign-in')).toBeInTheDocument();
|
|
195
|
+
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
196
|
+
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
197
|
+
// Used by: derived from the skills' allowed-tools.
|
|
198
|
+
expect(screen.getByText('newsletter')).toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|