@vibescope/mcp-server 0.4.4 → 0.4.6
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/CHANGELOG.md +84 -84
- package/README.md +194 -194
- package/dist/api-client/bodies-of-work.d.ts +125 -0
- package/dist/api-client/bodies-of-work.js +78 -0
- package/dist/api-client/chat.d.ts +26 -0
- package/dist/api-client/chat.js +20 -0
- package/dist/api-client/connectors.d.ts +104 -0
- package/dist/api-client/connectors.js +46 -0
- package/dist/api-client/deployment.d.ts +190 -0
- package/dist/api-client/deployment.js +113 -0
- package/dist/api-client/file-checkouts.d.ts +71 -0
- package/dist/api-client/file-checkouts.js +43 -0
- package/dist/api-client/git-issues.d.ts +55 -0
- package/dist/api-client/git-issues.js +34 -0
- package/dist/api-client/index.d.ts +619 -1
- package/dist/api-client/index.js +148 -0
- package/dist/api-client/organizations.d.ts +101 -0
- package/dist/api-client/organizations.js +86 -0
- package/dist/api-client/progress.d.ts +61 -0
- package/dist/api-client/progress.js +34 -0
- package/dist/api-client/project.d.ts +1 -0
- package/dist/api-client/requests.d.ts +28 -0
- package/dist/api-client/requests.js +28 -0
- package/dist/api-client/sprints.d.ts +153 -0
- package/dist/api-client/sprints.js +82 -0
- package/dist/api-client/subtasks.d.ts +37 -0
- package/dist/api-client/subtasks.js +23 -0
- package/dist/api-client.d.ts +23 -0
- package/dist/api-client.js +15 -0
- package/dist/cli-init.js +21 -21
- package/dist/cli.js +26 -26
- package/dist/handlers/blockers.js +4 -0
- package/dist/handlers/chat.d.ts +23 -0
- package/dist/handlers/chat.js +84 -0
- package/dist/handlers/deployment.d.ts +3 -0
- package/dist/handlers/deployment.js +23 -0
- package/dist/handlers/discovery.js +13 -0
- package/dist/handlers/index.d.ts +1 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/project.js +4 -2
- package/dist/handlers/session.js +7 -0
- package/dist/handlers/tasks.js +7 -0
- package/dist/handlers/tool-docs.js +1204 -1131
- package/dist/index.js +73 -73
- package/dist/templates/agent-guidelines.d.ts +1 -1
- package/dist/templates/agent-guidelines.js +205 -187
- package/dist/templates/help-content.js +1621 -1621
- package/dist/tools/bodies-of-work.js +6 -6
- package/dist/tools/chat.d.ts +1 -0
- package/dist/tools/chat.js +24 -0
- package/dist/tools/cloud-agents.js +22 -22
- package/dist/tools/deployment.js +13 -0
- package/dist/tools/features.d.ts +13 -0
- package/dist/tools/features.js +151 -0
- package/dist/tools/index.d.ts +3 -1
- package/dist/tools/index.js +4 -1
- package/dist/tools/milestones.js +2 -2
- package/dist/tools/project.js +4 -0
- package/dist/tools/requests.js +1 -1
- package/dist/tools/session.js +11 -11
- package/dist/tools/sprints.js +9 -9
- package/dist/tools/tasks.js +35 -35
- package/dist/tools/worktrees.js +14 -14
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +3602 -0
- package/dist/utils.js +11 -11
- package/docs/TOOLS.md +2663 -2545
- package/package.json +53 -53
- package/scripts/generate-docs.ts +212 -212
- package/scripts/version-bump.ts +203 -203
- package/src/api-client/blockers.ts +86 -86
- package/src/api-client/bodies-of-work.ts +194 -0
- package/src/api-client/chat.ts +50 -0
- package/src/api-client/connectors.ts +152 -0
- package/src/api-client/cost.ts +185 -185
- package/src/api-client/decisions.ts +87 -87
- package/src/api-client/deployment.ts +313 -0
- package/src/api-client/discovery.ts +81 -81
- package/src/api-client/fallback.ts +52 -52
- package/src/api-client/file-checkouts.ts +115 -0
- package/src/api-client/findings.ts +100 -100
- package/src/api-client/git-issues.ts +88 -0
- package/src/api-client/ideas.ts +112 -112
- package/src/api-client/index.ts +592 -426
- package/src/api-client/milestones.ts +83 -83
- package/src/api-client/organizations.ts +185 -0
- package/src/api-client/progress.ts +94 -0
- package/src/api-client/project.ts +180 -179
- package/src/api-client/requests.ts +54 -0
- package/src/api-client/session.ts +220 -220
- package/src/api-client/sprints.ts +227 -0
- package/src/api-client/subtasks.ts +57 -0
- package/src/api-client/tasks.ts +450 -450
- package/src/api-client/types.ts +32 -32
- package/src/api-client/validation.ts +60 -60
- package/src/api-client/worktrees.ts +53 -53
- package/src/api-client.test.ts +847 -850
- package/src/api-client.ts +2707 -2672
- package/src/cli-init.ts +557 -557
- package/src/cli.test.ts +284 -284
- package/src/cli.ts +204 -204
- package/src/handlers/__test-setup__.ts +240 -236
- package/src/handlers/__test-utils__.ts +89 -89
- package/src/handlers/blockers.test.ts +468 -468
- package/src/handlers/blockers.ts +172 -163
- package/src/handlers/bodies-of-work.test.ts +704 -704
- package/src/handlers/bodies-of-work.ts +526 -526
- package/src/handlers/chat.test.ts +185 -0
- package/src/handlers/chat.ts +101 -0
- package/src/handlers/cloud-agents.test.ts +438 -438
- package/src/handlers/cloud-agents.ts +156 -156
- package/src/handlers/connectors.test.ts +834 -834
- package/src/handlers/connectors.ts +229 -229
- package/src/handlers/cost.test.ts +462 -462
- package/src/handlers/cost.ts +285 -285
- package/src/handlers/decisions.test.ts +382 -382
- package/src/handlers/decisions.ts +153 -153
- package/src/handlers/deployment.test.ts +551 -551
- package/src/handlers/deployment.ts +570 -541
- package/src/handlers/discovery.test.ts +206 -206
- package/src/handlers/discovery.ts +427 -414
- package/src/handlers/fallback.test.ts +537 -537
- package/src/handlers/fallback.ts +194 -194
- package/src/handlers/file-checkouts.test.ts +750 -750
- package/src/handlers/file-checkouts.ts +185 -185
- package/src/handlers/findings.test.ts +633 -633
- package/src/handlers/findings.ts +239 -239
- package/src/handlers/git-issues.test.ts +631 -631
- package/src/handlers/git-issues.ts +136 -136
- package/src/handlers/ideas.test.ts +644 -644
- package/src/handlers/ideas.ts +207 -207
- package/src/handlers/index.ts +93 -90
- package/src/handlers/milestones.test.ts +475 -475
- package/src/handlers/milestones.ts +180 -180
- package/src/handlers/organizations.test.ts +826 -826
- package/src/handlers/organizations.ts +315 -315
- package/src/handlers/progress.test.ts +269 -269
- package/src/handlers/progress.ts +77 -77
- package/src/handlers/project.test.ts +546 -546
- package/src/handlers/project.ts +242 -239
- package/src/handlers/requests.test.ts +303 -303
- package/src/handlers/requests.ts +99 -99
- package/src/handlers/roles.test.ts +305 -305
- package/src/handlers/roles.ts +219 -219
- package/src/handlers/session.test.ts +998 -998
- package/src/handlers/session.ts +1105 -1093
- package/src/handlers/sprints.test.ts +732 -732
- package/src/handlers/sprints.ts +537 -537
- package/src/handlers/tasks.test.ts +931 -931
- package/src/handlers/tasks.ts +1133 -1121
- package/src/handlers/tool-categories.test.ts +66 -66
- package/src/handlers/tool-docs.test.ts +511 -511
- package/src/handlers/tool-docs.ts +1571 -1491
- package/src/handlers/types.test.ts +259 -259
- package/src/handlers/types.ts +176 -176
- package/src/handlers/validation.test.ts +582 -582
- package/src/handlers/validation.ts +164 -164
- package/src/handlers/version.ts +63 -63
- package/src/index.test.ts +674 -674
- package/src/index.ts +807 -807
- package/src/setup.test.ts +233 -233
- package/src/setup.ts +404 -404
- package/src/templates/agent-guidelines.ts +233 -215
- package/src/templates/help-content.ts +1751 -1751
- package/src/token-tracking.test.ts +463 -463
- package/src/token-tracking.ts +167 -167
- package/src/tools/blockers.ts +122 -122
- package/src/tools/bodies-of-work.ts +283 -283
- package/src/tools/chat.ts +72 -46
- package/src/tools/cloud-agents.ts +101 -101
- package/src/tools/connectors.ts +191 -191
- package/src/tools/cost.ts +111 -111
- package/src/tools/decisions.ts +111 -111
- package/src/tools/deployment.ts +455 -442
- package/src/tools/discovery.ts +76 -76
- package/src/tools/fallback.ts +111 -111
- package/src/tools/features.ts +154 -0
- package/src/tools/file-checkouts.ts +145 -145
- package/src/tools/findings.ts +101 -101
- package/src/tools/git-issues.ts +130 -130
- package/src/tools/ideas.ts +162 -162
- package/src/tools/index.ts +141 -137
- package/src/tools/milestones.ts +118 -118
- package/src/tools/organizations.ts +224 -224
- package/src/tools/progress.ts +73 -73
- package/src/tools/project.ts +206 -202
- package/src/tools/requests.ts +68 -68
- package/src/tools/roles.ts +112 -112
- package/src/tools/session.ts +181 -181
- package/src/tools/sprints.ts +298 -298
- package/src/tools/tasks.ts +550 -550
- package/src/tools/tools.test.ts +222 -222
- package/src/tools/types.ts +9 -9
- package/src/tools/validation.ts +75 -75
- package/src/tools/version.ts +34 -34
- package/src/tools/worktrees.ts +66 -66
- package/src/tools.test.ts +416 -416
- package/src/utils.test.ts +1014 -1014
- package/src/utils.ts +586 -586
- package/src/validators.test.ts +223 -223
- package/src/validators.ts +249 -249
- package/src/version.ts +109 -109
- package/tsconfig.json +16 -16
- package/vitest.config.ts +14 -14
|
@@ -1,633 +1,633 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
addFinding,
|
|
4
|
-
getFindings,
|
|
5
|
-
getFindingsStats,
|
|
6
|
-
updateFinding,
|
|
7
|
-
deleteFinding,
|
|
8
|
-
queryKnowledgeBase,
|
|
9
|
-
} from './findings.js';
|
|
10
|
-
import { ValidationError } from '../validators.js';
|
|
11
|
-
import { createMockContext } from './__test-utils__.js';
|
|
12
|
-
import { mockApiClient } from './__test-setup__.js';
|
|
13
|
-
|
|
14
|
-
const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
|
|
15
|
-
const VALID_UUID_2 = '223e4567-e89b-12d3-a456-426614174001';
|
|
16
|
-
|
|
17
|
-
// ============================================================================
|
|
18
|
-
// addFinding Tests
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
21
|
-
describe('addFinding', () => {
|
|
22
|
-
beforeEach(() => vi.clearAllMocks());
|
|
23
|
-
|
|
24
|
-
it('should throw error for missing project_id', async () => {
|
|
25
|
-
const ctx = createMockContext();
|
|
26
|
-
|
|
27
|
-
await expect(addFinding({ title: 'Test Finding' }, ctx)).rejects.toThrow(ValidationError);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should throw error for invalid project_id UUID', async () => {
|
|
31
|
-
const ctx = createMockContext();
|
|
32
|
-
|
|
33
|
-
await expect(
|
|
34
|
-
addFinding({ project_id: 'invalid', title: 'Test' }, ctx)
|
|
35
|
-
).rejects.toThrow(ValidationError);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should throw error for missing title', async () => {
|
|
39
|
-
const ctx = createMockContext();
|
|
40
|
-
|
|
41
|
-
await expect(
|
|
42
|
-
addFinding({ project_id: VALID_UUID }, ctx)
|
|
43
|
-
).rejects.toThrow(ValidationError);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should throw error for invalid related_task_id UUID', async () => {
|
|
47
|
-
const ctx = createMockContext();
|
|
48
|
-
|
|
49
|
-
await expect(
|
|
50
|
-
addFinding({ project_id: VALID_UUID, title: 'Test', related_task_id: 'invalid' }, ctx)
|
|
51
|
-
).rejects.toThrow(ValidationError);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should create finding with required fields', async () => {
|
|
55
|
-
mockApiClient.addFinding.mockResolvedValue({
|
|
56
|
-
ok: true,
|
|
57
|
-
data: { success: true, finding_id: 'finding-1', title: 'Performance issue' },
|
|
58
|
-
});
|
|
59
|
-
const ctx = createMockContext();
|
|
60
|
-
|
|
61
|
-
const result = await addFinding(
|
|
62
|
-
{ project_id: VALID_UUID, title: 'Performance issue' },
|
|
63
|
-
ctx
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
expect(result.result).toMatchObject({
|
|
67
|
-
success: true,
|
|
68
|
-
finding_id: 'finding-1',
|
|
69
|
-
title: 'Performance issue',
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should call API client with all parameters', async () => {
|
|
74
|
-
mockApiClient.addFinding.mockResolvedValue({
|
|
75
|
-
ok: true,
|
|
76
|
-
data: { success: true, finding_id: 'finding-2' },
|
|
77
|
-
});
|
|
78
|
-
const ctx = createMockContext({ sessionId: 'my-session' });
|
|
79
|
-
|
|
80
|
-
await addFinding(
|
|
81
|
-
{
|
|
82
|
-
project_id: VALID_UUID,
|
|
83
|
-
title: 'SQL Injection vulnerability',
|
|
84
|
-
description: 'User input not sanitized',
|
|
85
|
-
category: 'security',
|
|
86
|
-
severity: 'critical',
|
|
87
|
-
file_path: 'src/api/users.ts',
|
|
88
|
-
line_number: 42,
|
|
89
|
-
related_task_id: VALID_UUID_2,
|
|
90
|
-
},
|
|
91
|
-
ctx
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
expect(mockApiClient.addFinding).toHaveBeenCalledWith(
|
|
95
|
-
VALID_UUID,
|
|
96
|
-
{
|
|
97
|
-
title: 'SQL Injection vulnerability',
|
|
98
|
-
description: 'User input not sanitized',
|
|
99
|
-
category: 'security',
|
|
100
|
-
severity: 'critical',
|
|
101
|
-
file_path: 'src/api/users.ts',
|
|
102
|
-
line_number: 42,
|
|
103
|
-
related_task_id: VALID_UUID_2,
|
|
104
|
-
},
|
|
105
|
-
'my-session'
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should return error when API call fails', async () => {
|
|
110
|
-
mockApiClient.addFinding.mockResolvedValue({
|
|
111
|
-
ok: false,
|
|
112
|
-
error: 'Insert failed',
|
|
113
|
-
});
|
|
114
|
-
const ctx = createMockContext();
|
|
115
|
-
|
|
116
|
-
const result = await addFinding({ project_id: VALID_UUID, title: 'Test' }, ctx);
|
|
117
|
-
|
|
118
|
-
expect(result.isError).toBe(true);
|
|
119
|
-
expect(result.result).toMatchObject({ error: 'Insert failed' });
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// ============================================================================
|
|
124
|
-
// getFindings Tests
|
|
125
|
-
// ============================================================================
|
|
126
|
-
|
|
127
|
-
describe('getFindings', () => {
|
|
128
|
-
beforeEach(() => vi.clearAllMocks());
|
|
129
|
-
|
|
130
|
-
it('should throw error for missing project_id', async () => {
|
|
131
|
-
const ctx = createMockContext();
|
|
132
|
-
|
|
133
|
-
await expect(getFindings({}, ctx)).rejects.toThrow(ValidationError);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should throw error for invalid project_id UUID', async () => {
|
|
137
|
-
const ctx = createMockContext();
|
|
138
|
-
|
|
139
|
-
await expect(
|
|
140
|
-
getFindings({ project_id: 'invalid' }, ctx)
|
|
141
|
-
).rejects.toThrow(ValidationError);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should return findings for project', async () => {
|
|
145
|
-
const mockFindings = [
|
|
146
|
-
{ id: 'f1', title: 'Finding 1', category: 'security', severity: 'high', status: 'open', file_path: null, created_at: '2026-01-14' },
|
|
147
|
-
{ id: 'f2', title: 'Finding 2', category: 'performance', severity: 'medium', status: 'addressed', file_path: 'src/app.ts', created_at: '2026-01-13' },
|
|
148
|
-
];
|
|
149
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
150
|
-
ok: true,
|
|
151
|
-
data: { findings: mockFindings },
|
|
152
|
-
});
|
|
153
|
-
const ctx = createMockContext();
|
|
154
|
-
|
|
155
|
-
const result = await getFindings({ project_id: VALID_UUID }, ctx);
|
|
156
|
-
|
|
157
|
-
expect(result.result).toMatchObject({ findings: mockFindings });
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should pass filters to API client', async () => {
|
|
161
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
162
|
-
ok: true,
|
|
163
|
-
data: { findings: [] },
|
|
164
|
-
});
|
|
165
|
-
const ctx = createMockContext();
|
|
166
|
-
|
|
167
|
-
await getFindings({
|
|
168
|
-
project_id: VALID_UUID,
|
|
169
|
-
category: 'security',
|
|
170
|
-
severity: 'critical',
|
|
171
|
-
status: 'open',
|
|
172
|
-
limit: 10
|
|
173
|
-
}, ctx);
|
|
174
|
-
|
|
175
|
-
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
176
|
-
VALID_UUID,
|
|
177
|
-
expect.objectContaining({
|
|
178
|
-
category: 'security',
|
|
179
|
-
severity: 'critical',
|
|
180
|
-
status: 'open',
|
|
181
|
-
limit: 10,
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should pass summary_only parameter to API client', async () => {
|
|
187
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
188
|
-
ok: true,
|
|
189
|
-
data: { findings: [], total_count: 0, has_more: false },
|
|
190
|
-
});
|
|
191
|
-
const ctx = createMockContext();
|
|
192
|
-
|
|
193
|
-
await getFindings({
|
|
194
|
-
project_id: VALID_UUID,
|
|
195
|
-
summary_only: true
|
|
196
|
-
}, ctx);
|
|
197
|
-
|
|
198
|
-
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
199
|
-
VALID_UUID,
|
|
200
|
-
expect.objectContaining({
|
|
201
|
-
summary_only: true,
|
|
202
|
-
})
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should pass search_query parameter to API client', async () => {
|
|
207
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
208
|
-
ok: true,
|
|
209
|
-
data: { findings: [], total_count: 0, has_more: false },
|
|
210
|
-
});
|
|
211
|
-
const ctx = createMockContext();
|
|
212
|
-
|
|
213
|
-
await getFindings({
|
|
214
|
-
project_id: VALID_UUID,
|
|
215
|
-
search_query: 'security'
|
|
216
|
-
}, ctx);
|
|
217
|
-
|
|
218
|
-
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
219
|
-
VALID_UUID,
|
|
220
|
-
expect.objectContaining({
|
|
221
|
-
search_query: 'security',
|
|
222
|
-
})
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('should pass offset parameter to API client', async () => {
|
|
227
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
228
|
-
ok: true,
|
|
229
|
-
data: { findings: [], total_count: 100, has_more: true },
|
|
230
|
-
});
|
|
231
|
-
const ctx = createMockContext();
|
|
232
|
-
|
|
233
|
-
await getFindings({
|
|
234
|
-
project_id: VALID_UUID,
|
|
235
|
-
offset: 50,
|
|
236
|
-
limit: 25
|
|
237
|
-
}, ctx);
|
|
238
|
-
|
|
239
|
-
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
240
|
-
VALID_UUID,
|
|
241
|
-
expect.objectContaining({
|
|
242
|
-
offset: 50,
|
|
243
|
-
limit: 25,
|
|
244
|
-
})
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('should use default limit of 10 and summary_only true', async () => {
|
|
249
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
250
|
-
ok: true,
|
|
251
|
-
data: { findings: [] },
|
|
252
|
-
});
|
|
253
|
-
const ctx = createMockContext();
|
|
254
|
-
|
|
255
|
-
await getFindings({ project_id: VALID_UUID }, ctx);
|
|
256
|
-
|
|
257
|
-
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
258
|
-
VALID_UUID,
|
|
259
|
-
expect.objectContaining({ limit: 10, summary_only: true })
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('should return error when API call fails', async () => {
|
|
264
|
-
mockApiClient.getFindings.mockResolvedValue({
|
|
265
|
-
ok: false,
|
|
266
|
-
error: 'Query failed',
|
|
267
|
-
});
|
|
268
|
-
const ctx = createMockContext();
|
|
269
|
-
|
|
270
|
-
const result = await getFindings({ project_id: VALID_UUID }, ctx);
|
|
271
|
-
|
|
272
|
-
expect(result.isError).toBe(true);
|
|
273
|
-
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// ============================================================================
|
|
278
|
-
// updateFinding Tests
|
|
279
|
-
// ============================================================================
|
|
280
|
-
|
|
281
|
-
describe('updateFinding', () => {
|
|
282
|
-
beforeEach(() => vi.clearAllMocks());
|
|
283
|
-
|
|
284
|
-
it('should throw error for missing finding_id', async () => {
|
|
285
|
-
const ctx = createMockContext();
|
|
286
|
-
|
|
287
|
-
await expect(updateFinding({}, ctx)).rejects.toThrow(ValidationError);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should throw error for invalid finding_id UUID', async () => {
|
|
291
|
-
const ctx = createMockContext();
|
|
292
|
-
|
|
293
|
-
await expect(
|
|
294
|
-
updateFinding({ finding_id: 'invalid' }, ctx)
|
|
295
|
-
).rejects.toThrow(ValidationError);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('should update title', async () => {
|
|
299
|
-
mockApiClient.updateFinding.mockResolvedValue({
|
|
300
|
-
ok: true,
|
|
301
|
-
data: { success: true, finding_id: VALID_UUID },
|
|
302
|
-
});
|
|
303
|
-
const ctx = createMockContext();
|
|
304
|
-
|
|
305
|
-
const result = await updateFinding(
|
|
306
|
-
{ finding_id: VALID_UUID, title: 'Updated Title' },
|
|
307
|
-
ctx
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
expect(result.result).toMatchObject({ success: true, finding_id: VALID_UUID });
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('should call API client with all update fields', async () => {
|
|
314
|
-
mockApiClient.updateFinding.mockResolvedValue({
|
|
315
|
-
ok: true,
|
|
316
|
-
data: { success: true },
|
|
317
|
-
});
|
|
318
|
-
const ctx = createMockContext();
|
|
319
|
-
|
|
320
|
-
await updateFinding(
|
|
321
|
-
{
|
|
322
|
-
finding_id: VALID_UUID,
|
|
323
|
-
title: 'New Title',
|
|
324
|
-
description: 'New description',
|
|
325
|
-
severity: 'high',
|
|
326
|
-
status: 'addressed',
|
|
327
|
-
resolution_note: 'Fixed by sanitizing input'
|
|
328
|
-
},
|
|
329
|
-
ctx
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
expect(mockApiClient.updateFinding).toHaveBeenCalledWith(
|
|
333
|
-
VALID_UUID,
|
|
334
|
-
{
|
|
335
|
-
title: 'New Title',
|
|
336
|
-
description: 'New description',
|
|
337
|
-
severity: 'high',
|
|
338
|
-
status: 'addressed',
|
|
339
|
-
resolution_note: 'Fixed by sanitizing input',
|
|
340
|
-
}
|
|
341
|
-
);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('should return error when API call fails', async () => {
|
|
345
|
-
mockApiClient.updateFinding.mockResolvedValue({
|
|
346
|
-
ok: false,
|
|
347
|
-
error: 'Update failed',
|
|
348
|
-
});
|
|
349
|
-
const ctx = createMockContext();
|
|
350
|
-
|
|
351
|
-
const result = await updateFinding({ finding_id: VALID_UUID, title: 'Test' }, ctx);
|
|
352
|
-
|
|
353
|
-
expect(result.isError).toBe(true);
|
|
354
|
-
expect(result.result).toMatchObject({ error: 'Update failed' });
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// ============================================================================
|
|
359
|
-
// deleteFinding Tests
|
|
360
|
-
// ============================================================================
|
|
361
|
-
|
|
362
|
-
describe('deleteFinding', () => {
|
|
363
|
-
beforeEach(() => vi.clearAllMocks());
|
|
364
|
-
|
|
365
|
-
it('should throw error for missing finding_id', async () => {
|
|
366
|
-
const ctx = createMockContext();
|
|
367
|
-
|
|
368
|
-
await expect(deleteFinding({}, ctx)).rejects.toThrow(ValidationError);
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it('should throw error for invalid finding_id UUID', async () => {
|
|
372
|
-
const ctx = createMockContext();
|
|
373
|
-
|
|
374
|
-
await expect(
|
|
375
|
-
deleteFinding({ finding_id: 'invalid' }, ctx)
|
|
376
|
-
).rejects.toThrow(ValidationError);
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it('should delete finding successfully', async () => {
|
|
380
|
-
mockApiClient.deleteFinding.mockResolvedValue({
|
|
381
|
-
ok: true,
|
|
382
|
-
data: { success: true },
|
|
383
|
-
});
|
|
384
|
-
const ctx = createMockContext();
|
|
385
|
-
|
|
386
|
-
const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
387
|
-
|
|
388
|
-
expect(result.result).toMatchObject({ success: true });
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it('should call API client deleteFinding', async () => {
|
|
392
|
-
mockApiClient.deleteFinding.mockResolvedValue({
|
|
393
|
-
ok: true,
|
|
394
|
-
data: { success: true },
|
|
395
|
-
});
|
|
396
|
-
const ctx = createMockContext();
|
|
397
|
-
|
|
398
|
-
await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
399
|
-
|
|
400
|
-
expect(mockApiClient.deleteFinding).toHaveBeenCalledWith(VALID_UUID);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it('should return error when API call fails', async () => {
|
|
404
|
-
mockApiClient.deleteFinding.mockResolvedValue({
|
|
405
|
-
ok: false,
|
|
406
|
-
error: 'Delete failed',
|
|
407
|
-
});
|
|
408
|
-
const ctx = createMockContext();
|
|
409
|
-
|
|
410
|
-
const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
411
|
-
|
|
412
|
-
expect(result.isError).toBe(true);
|
|
413
|
-
expect(result.result).toMatchObject({ error: 'Delete failed' });
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
// ============================================================================
|
|
418
|
-
// getFindingsStats Tests
|
|
419
|
-
// ============================================================================
|
|
420
|
-
|
|
421
|
-
describe('getFindingsStats', () => {
|
|
422
|
-
beforeEach(() => vi.clearAllMocks());
|
|
423
|
-
|
|
424
|
-
it('should throw error for missing project_id', async () => {
|
|
425
|
-
const ctx = createMockContext();
|
|
426
|
-
|
|
427
|
-
await expect(getFindingsStats({}, ctx)).rejects.toThrow(ValidationError);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it('should throw error for invalid project_id UUID', async () => {
|
|
431
|
-
const ctx = createMockContext();
|
|
432
|
-
|
|
433
|
-
await expect(
|
|
434
|
-
getFindingsStats({ project_id: 'invalid' }, ctx)
|
|
435
|
-
).rejects.toThrow(ValidationError);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('should return findings stats for project', async () => {
|
|
439
|
-
const mockStats = {
|
|
440
|
-
total: 10,
|
|
441
|
-
by_status: { open: 5, addressed: 3, dismissed: 2 },
|
|
442
|
-
by_severity: { critical: 1, high: 3, medium: 4, low: 2 },
|
|
443
|
-
by_category: { security: 3, performance: 4, code_quality: 3 },
|
|
444
|
-
};
|
|
445
|
-
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
446
|
-
ok: true,
|
|
447
|
-
data: mockStats,
|
|
448
|
-
});
|
|
449
|
-
const ctx = createMockContext();
|
|
450
|
-
|
|
451
|
-
const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
452
|
-
|
|
453
|
-
expect(result.result).toMatchObject(mockStats);
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it('should call API client getFindingsStats with project_id', async () => {
|
|
457
|
-
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
458
|
-
ok: true,
|
|
459
|
-
data: { total: 0, by_status: {}, by_severity: {}, by_category: {} },
|
|
460
|
-
});
|
|
461
|
-
const ctx = createMockContext();
|
|
462
|
-
|
|
463
|
-
await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
464
|
-
|
|
465
|
-
expect(mockApiClient.getFindingsStats).toHaveBeenCalledWith(VALID_UUID);
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it('should return error when API call fails', async () => {
|
|
469
|
-
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
470
|
-
ok: false,
|
|
471
|
-
error: 'Query failed',
|
|
472
|
-
});
|
|
473
|
-
const ctx = createMockContext();
|
|
474
|
-
|
|
475
|
-
const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
476
|
-
|
|
477
|
-
expect(result.isError).toBe(true);
|
|
478
|
-
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
// ============================================================================
|
|
483
|
-
// queryKnowledgeBase Tests
|
|
484
|
-
// ============================================================================
|
|
485
|
-
|
|
486
|
-
describe('queryKnowledgeBase', () => {
|
|
487
|
-
beforeEach(() => vi.clearAllMocks());
|
|
488
|
-
|
|
489
|
-
it('should throw error for missing project_id', async () => {
|
|
490
|
-
const ctx = createMockContext();
|
|
491
|
-
|
|
492
|
-
await expect(queryKnowledgeBase({}, ctx)).rejects.toThrow(ValidationError);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('should throw error for invalid project_id UUID', async () => {
|
|
496
|
-
const ctx = createMockContext();
|
|
497
|
-
|
|
498
|
-
await expect(
|
|
499
|
-
queryKnowledgeBase({ project_id: 'invalid' }, ctx)
|
|
500
|
-
).rejects.toThrow(ValidationError);
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it('should throw error for invalid scope value', async () => {
|
|
504
|
-
const ctx = createMockContext();
|
|
505
|
-
|
|
506
|
-
await expect(
|
|
507
|
-
queryKnowledgeBase({ project_id: VALID_UUID, scope: 'invalid_scope' }, ctx)
|
|
508
|
-
).rejects.toThrow(ValidationError);
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it('should query with default parameters', async () => {
|
|
512
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
513
|
-
ok: true,
|
|
514
|
-
data: {
|
|
515
|
-
findings: [],
|
|
516
|
-
decisions: [],
|
|
517
|
-
completed_tasks: [],
|
|
518
|
-
resolved_blockers: [],
|
|
519
|
-
},
|
|
520
|
-
});
|
|
521
|
-
const ctx = createMockContext();
|
|
522
|
-
|
|
523
|
-
const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
|
|
524
|
-
|
|
525
|
-
expect(result.result).toMatchObject({
|
|
526
|
-
findings: [],
|
|
527
|
-
decisions: [],
|
|
528
|
-
});
|
|
529
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
530
|
-
VALID_UUID,
|
|
531
|
-
expect.objectContaining({
|
|
532
|
-
scope: 'summary',
|
|
533
|
-
limit: 5,
|
|
534
|
-
})
|
|
535
|
-
);
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
it('should pass scope parameter', async () => {
|
|
539
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
540
|
-
ok: true,
|
|
541
|
-
data: { findings: [] },
|
|
542
|
-
});
|
|
543
|
-
const ctx = createMockContext();
|
|
544
|
-
|
|
545
|
-
await queryKnowledgeBase({ project_id: VALID_UUID, scope: 'detailed' }, ctx);
|
|
546
|
-
|
|
547
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
548
|
-
VALID_UUID,
|
|
549
|
-
expect.objectContaining({ scope: 'detailed' })
|
|
550
|
-
);
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
it('should pass categories filter', async () => {
|
|
554
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
555
|
-
ok: true,
|
|
556
|
-
data: { findings: [], decisions: [] },
|
|
557
|
-
});
|
|
558
|
-
const ctx = createMockContext();
|
|
559
|
-
|
|
560
|
-
await queryKnowledgeBase({
|
|
561
|
-
project_id: VALID_UUID,
|
|
562
|
-
categories: ['findings', 'decisions']
|
|
563
|
-
}, ctx);
|
|
564
|
-
|
|
565
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
566
|
-
VALID_UUID,
|
|
567
|
-
expect.objectContaining({
|
|
568
|
-
categories: ['findings', 'decisions']
|
|
569
|
-
})
|
|
570
|
-
);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it('should cap limit at 20', async () => {
|
|
574
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
575
|
-
ok: true,
|
|
576
|
-
data: { findings: [] },
|
|
577
|
-
});
|
|
578
|
-
const ctx = createMockContext();
|
|
579
|
-
|
|
580
|
-
await queryKnowledgeBase({ project_id: VALID_UUID, limit: 100 }, ctx);
|
|
581
|
-
|
|
582
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
583
|
-
VALID_UUID,
|
|
584
|
-
expect.objectContaining({ limit: 20 })
|
|
585
|
-
);
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
it('should enforce minimum limit of 1', async () => {
|
|
589
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
590
|
-
ok: true,
|
|
591
|
-
data: { findings: [] },
|
|
592
|
-
});
|
|
593
|
-
const ctx = createMockContext();
|
|
594
|
-
|
|
595
|
-
await queryKnowledgeBase({ project_id: VALID_UUID, limit: -5 }, ctx);
|
|
596
|
-
|
|
597
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
598
|
-
VALID_UUID,
|
|
599
|
-
expect.objectContaining({ limit: 1 })
|
|
600
|
-
);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
it('should pass search_query', async () => {
|
|
604
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
605
|
-
ok: true,
|
|
606
|
-
data: { findings: [] },
|
|
607
|
-
});
|
|
608
|
-
const ctx = createMockContext();
|
|
609
|
-
|
|
610
|
-
await queryKnowledgeBase({
|
|
611
|
-
project_id: VALID_UUID,
|
|
612
|
-
search_query: 'security'
|
|
613
|
-
}, ctx);
|
|
614
|
-
|
|
615
|
-
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
616
|
-
VALID_UUID,
|
|
617
|
-
expect.objectContaining({ search_query: 'security' })
|
|
618
|
-
);
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
it('should return error when API call fails', async () => {
|
|
622
|
-
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
623
|
-
ok: false,
|
|
624
|
-
error: 'Query failed',
|
|
625
|
-
});
|
|
626
|
-
const ctx = createMockContext();
|
|
627
|
-
|
|
628
|
-
const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
|
|
629
|
-
|
|
630
|
-
expect(result.isError).toBe(true);
|
|
631
|
-
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
632
|
-
});
|
|
633
|
-
});
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
addFinding,
|
|
4
|
+
getFindings,
|
|
5
|
+
getFindingsStats,
|
|
6
|
+
updateFinding,
|
|
7
|
+
deleteFinding,
|
|
8
|
+
queryKnowledgeBase,
|
|
9
|
+
} from './findings.js';
|
|
10
|
+
import { ValidationError } from '../validators.js';
|
|
11
|
+
import { createMockContext } from './__test-utils__.js';
|
|
12
|
+
import { mockApiClient } from './__test-setup__.js';
|
|
13
|
+
|
|
14
|
+
const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
|
|
15
|
+
const VALID_UUID_2 = '223e4567-e89b-12d3-a456-426614174001';
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// addFinding Tests
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
describe('addFinding', () => {
|
|
22
|
+
beforeEach(() => vi.clearAllMocks());
|
|
23
|
+
|
|
24
|
+
it('should throw error for missing project_id', async () => {
|
|
25
|
+
const ctx = createMockContext();
|
|
26
|
+
|
|
27
|
+
await expect(addFinding({ title: 'Test Finding' }, ctx)).rejects.toThrow(ValidationError);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should throw error for invalid project_id UUID', async () => {
|
|
31
|
+
const ctx = createMockContext();
|
|
32
|
+
|
|
33
|
+
await expect(
|
|
34
|
+
addFinding({ project_id: 'invalid', title: 'Test' }, ctx)
|
|
35
|
+
).rejects.toThrow(ValidationError);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should throw error for missing title', async () => {
|
|
39
|
+
const ctx = createMockContext();
|
|
40
|
+
|
|
41
|
+
await expect(
|
|
42
|
+
addFinding({ project_id: VALID_UUID }, ctx)
|
|
43
|
+
).rejects.toThrow(ValidationError);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should throw error for invalid related_task_id UUID', async () => {
|
|
47
|
+
const ctx = createMockContext();
|
|
48
|
+
|
|
49
|
+
await expect(
|
|
50
|
+
addFinding({ project_id: VALID_UUID, title: 'Test', related_task_id: 'invalid' }, ctx)
|
|
51
|
+
).rejects.toThrow(ValidationError);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should create finding with required fields', async () => {
|
|
55
|
+
mockApiClient.addFinding.mockResolvedValue({
|
|
56
|
+
ok: true,
|
|
57
|
+
data: { success: true, finding_id: 'finding-1', title: 'Performance issue' },
|
|
58
|
+
});
|
|
59
|
+
const ctx = createMockContext();
|
|
60
|
+
|
|
61
|
+
const result = await addFinding(
|
|
62
|
+
{ project_id: VALID_UUID, title: 'Performance issue' },
|
|
63
|
+
ctx
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(result.result).toMatchObject({
|
|
67
|
+
success: true,
|
|
68
|
+
finding_id: 'finding-1',
|
|
69
|
+
title: 'Performance issue',
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should call API client with all parameters', async () => {
|
|
74
|
+
mockApiClient.addFinding.mockResolvedValue({
|
|
75
|
+
ok: true,
|
|
76
|
+
data: { success: true, finding_id: 'finding-2' },
|
|
77
|
+
});
|
|
78
|
+
const ctx = createMockContext({ sessionId: 'my-session' });
|
|
79
|
+
|
|
80
|
+
await addFinding(
|
|
81
|
+
{
|
|
82
|
+
project_id: VALID_UUID,
|
|
83
|
+
title: 'SQL Injection vulnerability',
|
|
84
|
+
description: 'User input not sanitized',
|
|
85
|
+
category: 'security',
|
|
86
|
+
severity: 'critical',
|
|
87
|
+
file_path: 'src/api/users.ts',
|
|
88
|
+
line_number: 42,
|
|
89
|
+
related_task_id: VALID_UUID_2,
|
|
90
|
+
},
|
|
91
|
+
ctx
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(mockApiClient.addFinding).toHaveBeenCalledWith(
|
|
95
|
+
VALID_UUID,
|
|
96
|
+
{
|
|
97
|
+
title: 'SQL Injection vulnerability',
|
|
98
|
+
description: 'User input not sanitized',
|
|
99
|
+
category: 'security',
|
|
100
|
+
severity: 'critical',
|
|
101
|
+
file_path: 'src/api/users.ts',
|
|
102
|
+
line_number: 42,
|
|
103
|
+
related_task_id: VALID_UUID_2,
|
|
104
|
+
},
|
|
105
|
+
'my-session'
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should return error when API call fails', async () => {
|
|
110
|
+
mockApiClient.addFinding.mockResolvedValue({
|
|
111
|
+
ok: false,
|
|
112
|
+
error: 'Insert failed',
|
|
113
|
+
});
|
|
114
|
+
const ctx = createMockContext();
|
|
115
|
+
|
|
116
|
+
const result = await addFinding({ project_id: VALID_UUID, title: 'Test' }, ctx);
|
|
117
|
+
|
|
118
|
+
expect(result.isError).toBe(true);
|
|
119
|
+
expect(result.result).toMatchObject({ error: 'Insert failed' });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// ============================================================================
|
|
124
|
+
// getFindings Tests
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
describe('getFindings', () => {
|
|
128
|
+
beforeEach(() => vi.clearAllMocks());
|
|
129
|
+
|
|
130
|
+
it('should throw error for missing project_id', async () => {
|
|
131
|
+
const ctx = createMockContext();
|
|
132
|
+
|
|
133
|
+
await expect(getFindings({}, ctx)).rejects.toThrow(ValidationError);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should throw error for invalid project_id UUID', async () => {
|
|
137
|
+
const ctx = createMockContext();
|
|
138
|
+
|
|
139
|
+
await expect(
|
|
140
|
+
getFindings({ project_id: 'invalid' }, ctx)
|
|
141
|
+
).rejects.toThrow(ValidationError);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should return findings for project', async () => {
|
|
145
|
+
const mockFindings = [
|
|
146
|
+
{ id: 'f1', title: 'Finding 1', category: 'security', severity: 'high', status: 'open', file_path: null, created_at: '2026-01-14' },
|
|
147
|
+
{ id: 'f2', title: 'Finding 2', category: 'performance', severity: 'medium', status: 'addressed', file_path: 'src/app.ts', created_at: '2026-01-13' },
|
|
148
|
+
];
|
|
149
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
150
|
+
ok: true,
|
|
151
|
+
data: { findings: mockFindings },
|
|
152
|
+
});
|
|
153
|
+
const ctx = createMockContext();
|
|
154
|
+
|
|
155
|
+
const result = await getFindings({ project_id: VALID_UUID }, ctx);
|
|
156
|
+
|
|
157
|
+
expect(result.result).toMatchObject({ findings: mockFindings });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should pass filters to API client', async () => {
|
|
161
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
162
|
+
ok: true,
|
|
163
|
+
data: { findings: [] },
|
|
164
|
+
});
|
|
165
|
+
const ctx = createMockContext();
|
|
166
|
+
|
|
167
|
+
await getFindings({
|
|
168
|
+
project_id: VALID_UUID,
|
|
169
|
+
category: 'security',
|
|
170
|
+
severity: 'critical',
|
|
171
|
+
status: 'open',
|
|
172
|
+
limit: 10
|
|
173
|
+
}, ctx);
|
|
174
|
+
|
|
175
|
+
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
176
|
+
VALID_UUID,
|
|
177
|
+
expect.objectContaining({
|
|
178
|
+
category: 'security',
|
|
179
|
+
severity: 'critical',
|
|
180
|
+
status: 'open',
|
|
181
|
+
limit: 10,
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should pass summary_only parameter to API client', async () => {
|
|
187
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
188
|
+
ok: true,
|
|
189
|
+
data: { findings: [], total_count: 0, has_more: false },
|
|
190
|
+
});
|
|
191
|
+
const ctx = createMockContext();
|
|
192
|
+
|
|
193
|
+
await getFindings({
|
|
194
|
+
project_id: VALID_UUID,
|
|
195
|
+
summary_only: true
|
|
196
|
+
}, ctx);
|
|
197
|
+
|
|
198
|
+
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
199
|
+
VALID_UUID,
|
|
200
|
+
expect.objectContaining({
|
|
201
|
+
summary_only: true,
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should pass search_query parameter to API client', async () => {
|
|
207
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
208
|
+
ok: true,
|
|
209
|
+
data: { findings: [], total_count: 0, has_more: false },
|
|
210
|
+
});
|
|
211
|
+
const ctx = createMockContext();
|
|
212
|
+
|
|
213
|
+
await getFindings({
|
|
214
|
+
project_id: VALID_UUID,
|
|
215
|
+
search_query: 'security'
|
|
216
|
+
}, ctx);
|
|
217
|
+
|
|
218
|
+
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
219
|
+
VALID_UUID,
|
|
220
|
+
expect.objectContaining({
|
|
221
|
+
search_query: 'security',
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should pass offset parameter to API client', async () => {
|
|
227
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
228
|
+
ok: true,
|
|
229
|
+
data: { findings: [], total_count: 100, has_more: true },
|
|
230
|
+
});
|
|
231
|
+
const ctx = createMockContext();
|
|
232
|
+
|
|
233
|
+
await getFindings({
|
|
234
|
+
project_id: VALID_UUID,
|
|
235
|
+
offset: 50,
|
|
236
|
+
limit: 25
|
|
237
|
+
}, ctx);
|
|
238
|
+
|
|
239
|
+
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
240
|
+
VALID_UUID,
|
|
241
|
+
expect.objectContaining({
|
|
242
|
+
offset: 50,
|
|
243
|
+
limit: 25,
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('should use default limit of 10 and summary_only true', async () => {
|
|
249
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
250
|
+
ok: true,
|
|
251
|
+
data: { findings: [] },
|
|
252
|
+
});
|
|
253
|
+
const ctx = createMockContext();
|
|
254
|
+
|
|
255
|
+
await getFindings({ project_id: VALID_UUID }, ctx);
|
|
256
|
+
|
|
257
|
+
expect(mockApiClient.getFindings).toHaveBeenCalledWith(
|
|
258
|
+
VALID_UUID,
|
|
259
|
+
expect.objectContaining({ limit: 10, summary_only: true })
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should return error when API call fails', async () => {
|
|
264
|
+
mockApiClient.getFindings.mockResolvedValue({
|
|
265
|
+
ok: false,
|
|
266
|
+
error: 'Query failed',
|
|
267
|
+
});
|
|
268
|
+
const ctx = createMockContext();
|
|
269
|
+
|
|
270
|
+
const result = await getFindings({ project_id: VALID_UUID }, ctx);
|
|
271
|
+
|
|
272
|
+
expect(result.isError).toBe(true);
|
|
273
|
+
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ============================================================================
|
|
278
|
+
// updateFinding Tests
|
|
279
|
+
// ============================================================================
|
|
280
|
+
|
|
281
|
+
describe('updateFinding', () => {
|
|
282
|
+
beforeEach(() => vi.clearAllMocks());
|
|
283
|
+
|
|
284
|
+
it('should throw error for missing finding_id', async () => {
|
|
285
|
+
const ctx = createMockContext();
|
|
286
|
+
|
|
287
|
+
await expect(updateFinding({}, ctx)).rejects.toThrow(ValidationError);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('should throw error for invalid finding_id UUID', async () => {
|
|
291
|
+
const ctx = createMockContext();
|
|
292
|
+
|
|
293
|
+
await expect(
|
|
294
|
+
updateFinding({ finding_id: 'invalid' }, ctx)
|
|
295
|
+
).rejects.toThrow(ValidationError);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should update title', async () => {
|
|
299
|
+
mockApiClient.updateFinding.mockResolvedValue({
|
|
300
|
+
ok: true,
|
|
301
|
+
data: { success: true, finding_id: VALID_UUID },
|
|
302
|
+
});
|
|
303
|
+
const ctx = createMockContext();
|
|
304
|
+
|
|
305
|
+
const result = await updateFinding(
|
|
306
|
+
{ finding_id: VALID_UUID, title: 'Updated Title' },
|
|
307
|
+
ctx
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
expect(result.result).toMatchObject({ success: true, finding_id: VALID_UUID });
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('should call API client with all update fields', async () => {
|
|
314
|
+
mockApiClient.updateFinding.mockResolvedValue({
|
|
315
|
+
ok: true,
|
|
316
|
+
data: { success: true },
|
|
317
|
+
});
|
|
318
|
+
const ctx = createMockContext();
|
|
319
|
+
|
|
320
|
+
await updateFinding(
|
|
321
|
+
{
|
|
322
|
+
finding_id: VALID_UUID,
|
|
323
|
+
title: 'New Title',
|
|
324
|
+
description: 'New description',
|
|
325
|
+
severity: 'high',
|
|
326
|
+
status: 'addressed',
|
|
327
|
+
resolution_note: 'Fixed by sanitizing input'
|
|
328
|
+
},
|
|
329
|
+
ctx
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
expect(mockApiClient.updateFinding).toHaveBeenCalledWith(
|
|
333
|
+
VALID_UUID,
|
|
334
|
+
{
|
|
335
|
+
title: 'New Title',
|
|
336
|
+
description: 'New description',
|
|
337
|
+
severity: 'high',
|
|
338
|
+
status: 'addressed',
|
|
339
|
+
resolution_note: 'Fixed by sanitizing input',
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('should return error when API call fails', async () => {
|
|
345
|
+
mockApiClient.updateFinding.mockResolvedValue({
|
|
346
|
+
ok: false,
|
|
347
|
+
error: 'Update failed',
|
|
348
|
+
});
|
|
349
|
+
const ctx = createMockContext();
|
|
350
|
+
|
|
351
|
+
const result = await updateFinding({ finding_id: VALID_UUID, title: 'Test' }, ctx);
|
|
352
|
+
|
|
353
|
+
expect(result.isError).toBe(true);
|
|
354
|
+
expect(result.result).toMatchObject({ error: 'Update failed' });
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// ============================================================================
|
|
359
|
+
// deleteFinding Tests
|
|
360
|
+
// ============================================================================
|
|
361
|
+
|
|
362
|
+
describe('deleteFinding', () => {
|
|
363
|
+
beforeEach(() => vi.clearAllMocks());
|
|
364
|
+
|
|
365
|
+
it('should throw error for missing finding_id', async () => {
|
|
366
|
+
const ctx = createMockContext();
|
|
367
|
+
|
|
368
|
+
await expect(deleteFinding({}, ctx)).rejects.toThrow(ValidationError);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('should throw error for invalid finding_id UUID', async () => {
|
|
372
|
+
const ctx = createMockContext();
|
|
373
|
+
|
|
374
|
+
await expect(
|
|
375
|
+
deleteFinding({ finding_id: 'invalid' }, ctx)
|
|
376
|
+
).rejects.toThrow(ValidationError);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('should delete finding successfully', async () => {
|
|
380
|
+
mockApiClient.deleteFinding.mockResolvedValue({
|
|
381
|
+
ok: true,
|
|
382
|
+
data: { success: true },
|
|
383
|
+
});
|
|
384
|
+
const ctx = createMockContext();
|
|
385
|
+
|
|
386
|
+
const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
387
|
+
|
|
388
|
+
expect(result.result).toMatchObject({ success: true });
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('should call API client deleteFinding', async () => {
|
|
392
|
+
mockApiClient.deleteFinding.mockResolvedValue({
|
|
393
|
+
ok: true,
|
|
394
|
+
data: { success: true },
|
|
395
|
+
});
|
|
396
|
+
const ctx = createMockContext();
|
|
397
|
+
|
|
398
|
+
await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
399
|
+
|
|
400
|
+
expect(mockApiClient.deleteFinding).toHaveBeenCalledWith(VALID_UUID);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('should return error when API call fails', async () => {
|
|
404
|
+
mockApiClient.deleteFinding.mockResolvedValue({
|
|
405
|
+
ok: false,
|
|
406
|
+
error: 'Delete failed',
|
|
407
|
+
});
|
|
408
|
+
const ctx = createMockContext();
|
|
409
|
+
|
|
410
|
+
const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
|
|
411
|
+
|
|
412
|
+
expect(result.isError).toBe(true);
|
|
413
|
+
expect(result.result).toMatchObject({ error: 'Delete failed' });
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// ============================================================================
|
|
418
|
+
// getFindingsStats Tests
|
|
419
|
+
// ============================================================================
|
|
420
|
+
|
|
421
|
+
describe('getFindingsStats', () => {
|
|
422
|
+
beforeEach(() => vi.clearAllMocks());
|
|
423
|
+
|
|
424
|
+
it('should throw error for missing project_id', async () => {
|
|
425
|
+
const ctx = createMockContext();
|
|
426
|
+
|
|
427
|
+
await expect(getFindingsStats({}, ctx)).rejects.toThrow(ValidationError);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('should throw error for invalid project_id UUID', async () => {
|
|
431
|
+
const ctx = createMockContext();
|
|
432
|
+
|
|
433
|
+
await expect(
|
|
434
|
+
getFindingsStats({ project_id: 'invalid' }, ctx)
|
|
435
|
+
).rejects.toThrow(ValidationError);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('should return findings stats for project', async () => {
|
|
439
|
+
const mockStats = {
|
|
440
|
+
total: 10,
|
|
441
|
+
by_status: { open: 5, addressed: 3, dismissed: 2 },
|
|
442
|
+
by_severity: { critical: 1, high: 3, medium: 4, low: 2 },
|
|
443
|
+
by_category: { security: 3, performance: 4, code_quality: 3 },
|
|
444
|
+
};
|
|
445
|
+
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
446
|
+
ok: true,
|
|
447
|
+
data: mockStats,
|
|
448
|
+
});
|
|
449
|
+
const ctx = createMockContext();
|
|
450
|
+
|
|
451
|
+
const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
452
|
+
|
|
453
|
+
expect(result.result).toMatchObject(mockStats);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('should call API client getFindingsStats with project_id', async () => {
|
|
457
|
+
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
458
|
+
ok: true,
|
|
459
|
+
data: { total: 0, by_status: {}, by_severity: {}, by_category: {} },
|
|
460
|
+
});
|
|
461
|
+
const ctx = createMockContext();
|
|
462
|
+
|
|
463
|
+
await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
464
|
+
|
|
465
|
+
expect(mockApiClient.getFindingsStats).toHaveBeenCalledWith(VALID_UUID);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('should return error when API call fails', async () => {
|
|
469
|
+
mockApiClient.getFindingsStats.mockResolvedValue({
|
|
470
|
+
ok: false,
|
|
471
|
+
error: 'Query failed',
|
|
472
|
+
});
|
|
473
|
+
const ctx = createMockContext();
|
|
474
|
+
|
|
475
|
+
const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
|
|
476
|
+
|
|
477
|
+
expect(result.isError).toBe(true);
|
|
478
|
+
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// ============================================================================
|
|
483
|
+
// queryKnowledgeBase Tests
|
|
484
|
+
// ============================================================================
|
|
485
|
+
|
|
486
|
+
describe('queryKnowledgeBase', () => {
|
|
487
|
+
beforeEach(() => vi.clearAllMocks());
|
|
488
|
+
|
|
489
|
+
it('should throw error for missing project_id', async () => {
|
|
490
|
+
const ctx = createMockContext();
|
|
491
|
+
|
|
492
|
+
await expect(queryKnowledgeBase({}, ctx)).rejects.toThrow(ValidationError);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('should throw error for invalid project_id UUID', async () => {
|
|
496
|
+
const ctx = createMockContext();
|
|
497
|
+
|
|
498
|
+
await expect(
|
|
499
|
+
queryKnowledgeBase({ project_id: 'invalid' }, ctx)
|
|
500
|
+
).rejects.toThrow(ValidationError);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('should throw error for invalid scope value', async () => {
|
|
504
|
+
const ctx = createMockContext();
|
|
505
|
+
|
|
506
|
+
await expect(
|
|
507
|
+
queryKnowledgeBase({ project_id: VALID_UUID, scope: 'invalid_scope' }, ctx)
|
|
508
|
+
).rejects.toThrow(ValidationError);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it('should query with default parameters', async () => {
|
|
512
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
513
|
+
ok: true,
|
|
514
|
+
data: {
|
|
515
|
+
findings: [],
|
|
516
|
+
decisions: [],
|
|
517
|
+
completed_tasks: [],
|
|
518
|
+
resolved_blockers: [],
|
|
519
|
+
},
|
|
520
|
+
});
|
|
521
|
+
const ctx = createMockContext();
|
|
522
|
+
|
|
523
|
+
const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
|
|
524
|
+
|
|
525
|
+
expect(result.result).toMatchObject({
|
|
526
|
+
findings: [],
|
|
527
|
+
decisions: [],
|
|
528
|
+
});
|
|
529
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
530
|
+
VALID_UUID,
|
|
531
|
+
expect.objectContaining({
|
|
532
|
+
scope: 'summary',
|
|
533
|
+
limit: 5,
|
|
534
|
+
})
|
|
535
|
+
);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('should pass scope parameter', async () => {
|
|
539
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
540
|
+
ok: true,
|
|
541
|
+
data: { findings: [] },
|
|
542
|
+
});
|
|
543
|
+
const ctx = createMockContext();
|
|
544
|
+
|
|
545
|
+
await queryKnowledgeBase({ project_id: VALID_UUID, scope: 'detailed' }, ctx);
|
|
546
|
+
|
|
547
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
548
|
+
VALID_UUID,
|
|
549
|
+
expect.objectContaining({ scope: 'detailed' })
|
|
550
|
+
);
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it('should pass categories filter', async () => {
|
|
554
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
555
|
+
ok: true,
|
|
556
|
+
data: { findings: [], decisions: [] },
|
|
557
|
+
});
|
|
558
|
+
const ctx = createMockContext();
|
|
559
|
+
|
|
560
|
+
await queryKnowledgeBase({
|
|
561
|
+
project_id: VALID_UUID,
|
|
562
|
+
categories: ['findings', 'decisions']
|
|
563
|
+
}, ctx);
|
|
564
|
+
|
|
565
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
566
|
+
VALID_UUID,
|
|
567
|
+
expect.objectContaining({
|
|
568
|
+
categories: ['findings', 'decisions']
|
|
569
|
+
})
|
|
570
|
+
);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it('should cap limit at 20', async () => {
|
|
574
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
575
|
+
ok: true,
|
|
576
|
+
data: { findings: [] },
|
|
577
|
+
});
|
|
578
|
+
const ctx = createMockContext();
|
|
579
|
+
|
|
580
|
+
await queryKnowledgeBase({ project_id: VALID_UUID, limit: 100 }, ctx);
|
|
581
|
+
|
|
582
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
583
|
+
VALID_UUID,
|
|
584
|
+
expect.objectContaining({ limit: 20 })
|
|
585
|
+
);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('should enforce minimum limit of 1', async () => {
|
|
589
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
590
|
+
ok: true,
|
|
591
|
+
data: { findings: [] },
|
|
592
|
+
});
|
|
593
|
+
const ctx = createMockContext();
|
|
594
|
+
|
|
595
|
+
await queryKnowledgeBase({ project_id: VALID_UUID, limit: -5 }, ctx);
|
|
596
|
+
|
|
597
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
598
|
+
VALID_UUID,
|
|
599
|
+
expect.objectContaining({ limit: 1 })
|
|
600
|
+
);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('should pass search_query', async () => {
|
|
604
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
605
|
+
ok: true,
|
|
606
|
+
data: { findings: [] },
|
|
607
|
+
});
|
|
608
|
+
const ctx = createMockContext();
|
|
609
|
+
|
|
610
|
+
await queryKnowledgeBase({
|
|
611
|
+
project_id: VALID_UUID,
|
|
612
|
+
search_query: 'security'
|
|
613
|
+
}, ctx);
|
|
614
|
+
|
|
615
|
+
expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
|
|
616
|
+
VALID_UUID,
|
|
617
|
+
expect.objectContaining({ search_query: 'security' })
|
|
618
|
+
);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('should return error when API call fails', async () => {
|
|
622
|
+
mockApiClient.queryKnowledgeBase.mockResolvedValue({
|
|
623
|
+
ok: false,
|
|
624
|
+
error: 'Query failed',
|
|
625
|
+
});
|
|
626
|
+
const ctx = createMockContext();
|
|
627
|
+
|
|
628
|
+
const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
|
|
629
|
+
|
|
630
|
+
expect(result.isError).toBe(true);
|
|
631
|
+
expect(result.result).toMatchObject({ error: 'Query failed' });
|
|
632
|
+
});
|
|
633
|
+
});
|