@agledger/mcp-server 2.3.1 → 2.3.3
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 +35 -0
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +2 -1
- package/dist/api-client.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +73 -26
- package/dist/server.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +7 -1
- package/src/api-client.ts +0 -72
- package/src/index.ts +0 -69
- package/src/server.ts +0 -326
- package/src/verify/verify-export.ts +0 -296
- package/tests/api-client.test.ts +0 -147
- package/tests/harness.ts +0 -28
- package/tests/integration.test.ts +0 -373
- package/tests/server.test.ts +0 -500
- package/tsconfig.json +0 -12
package/tests/server.test.ts
DELETED
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
import { createTestHarness, type TestHarness } from './harness.js';
|
|
7
|
-
|
|
8
|
-
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const VECTORS_DIR = join(HERE, '..', '..', '..', 'testdata', 'verifier');
|
|
10
|
-
const loadVector = (name: string) => JSON.parse(readFileSync(join(VECTORS_DIR, name), 'utf8'));
|
|
11
|
-
|
|
12
|
-
let harness: TestHarness;
|
|
13
|
-
let tools: Tool[];
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
harness = await createTestHarness();
|
|
17
|
-
({ tools } = await harness.client.listTools());
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterAll(async () => {
|
|
21
|
-
await harness.cleanup();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
vi.unstubAllGlobals();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('tool registration', () => {
|
|
29
|
-
it('registers exactly 3 tools', () => {
|
|
30
|
-
expect(tools).toHaveLength(3);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('registers agledger_discover', () => {
|
|
34
|
-
const tool = tools.find((t) => t.name === 'agledger_discover');
|
|
35
|
-
expect(tool).toBeDefined();
|
|
36
|
-
expect(tool!.description).toContain('health');
|
|
37
|
-
expect(tool!.description).toContain('identity');
|
|
38
|
-
expect(tool!.description).toContain('quickstart');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('registers agledger_api', () => {
|
|
42
|
-
const tool = tools.find((t) => t.name === 'agledger_api');
|
|
43
|
-
expect(tool).toBeDefined();
|
|
44
|
-
expect(tool!.description).toContain('nextSteps');
|
|
45
|
-
expect(tool!.description).toContain('/v1/');
|
|
46
|
-
expect(tool!.description).toContain('/v1/schemas');
|
|
47
|
-
expect(tool!.description).toContain('/v1/records');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('registers agledger_verify', () => {
|
|
51
|
-
const tool = tools.find((t) => t.name === 'agledger_verify');
|
|
52
|
-
expect(tool).toBeDefined();
|
|
53
|
-
expect(tool!.description).toContain('offline');
|
|
54
|
-
expect(tool!.description).toContain('Ed25519');
|
|
55
|
-
expect(tool!.description).toContain('audit-export');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('resource registration', () => {
|
|
60
|
-
it('registers the agledger://openapi resource', async () => {
|
|
61
|
-
const { resources } = await harness.client.listResources();
|
|
62
|
-
const openapi = resources.find((r) => r.uri === 'agledger://openapi');
|
|
63
|
-
expect(openapi).toBeDefined();
|
|
64
|
-
expect(openapi!.mimeType).toBe('application/json');
|
|
65
|
-
expect(openapi!.description).toContain('OpenAPI');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('reads the openapi resource by proxying to GET /openapi.json', async () => {
|
|
69
|
-
const spec = { openapi: '3.0.3', info: { title: 'AGLedger API' }, paths: {} };
|
|
70
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
71
|
-
new Response(JSON.stringify(spec), {
|
|
72
|
-
status: 200,
|
|
73
|
-
headers: { 'content-type': 'application/json' },
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
77
|
-
|
|
78
|
-
const result = await harness.client.readResource({ uri: 'agledger://openapi' });
|
|
79
|
-
expect(result.contents).toHaveLength(1);
|
|
80
|
-
const content = result.contents[0];
|
|
81
|
-
expect(content.uri).toBe('agledger://openapi');
|
|
82
|
-
expect(content.mimeType).toBe('application/json');
|
|
83
|
-
expect(JSON.parse(content.text as string)).toEqual(spec);
|
|
84
|
-
|
|
85
|
-
// Confirm the proxy hit the right endpoint
|
|
86
|
-
const url = mockFetch.mock.calls[0][0] as string;
|
|
87
|
-
expect(url).toContain('/openapi.json');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('surfaces upstream failure when /openapi.json is not reachable', async () => {
|
|
91
|
-
vi.stubGlobal(
|
|
92
|
-
'fetch',
|
|
93
|
-
vi.fn().mockResolvedValueOnce(
|
|
94
|
-
new Response('not found', {
|
|
95
|
-
status: 404,
|
|
96
|
-
headers: { 'content-type': 'text/plain' },
|
|
97
|
-
}),
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
await expect(harness.client.readResource({ uri: 'agledger://openapi' })).rejects.toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('agledger_discover', () => {
|
|
106
|
-
it('returns health and identity on success', async () => {
|
|
107
|
-
const mockFetch = vi
|
|
108
|
-
.fn()
|
|
109
|
-
.mockResolvedValueOnce(
|
|
110
|
-
new Response(JSON.stringify({ status: 'ok', version: '1.0.0' }), {
|
|
111
|
-
status: 200,
|
|
112
|
-
headers: { 'content-type': 'application/json' },
|
|
113
|
-
}),
|
|
114
|
-
)
|
|
115
|
-
.mockResolvedValueOnce(
|
|
116
|
-
new Response(JSON.stringify({ agentId: 'agent-1', scopes: ['records:read'] }), {
|
|
117
|
-
status: 200,
|
|
118
|
-
headers: { 'content-type': 'application/json' },
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
122
|
-
|
|
123
|
-
const result = await harness.client.callTool({ name: 'agledger_discover', arguments: {} });
|
|
124
|
-
|
|
125
|
-
expect(result.isError).toBeFalsy();
|
|
126
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
127
|
-
expect(content.health).toEqual({ status: 'ok', version: '1.0.0' });
|
|
128
|
-
expect(content.identity).toEqual({ agentId: 'agent-1', scopes: ['records:read'] });
|
|
129
|
-
|
|
130
|
-
// Quickstart workflow is always present
|
|
131
|
-
const quickstart = content.quickstart as { steps: Array<{ step: number; path: string }> };
|
|
132
|
-
expect(quickstart.steps).toHaveLength(4);
|
|
133
|
-
expect(quickstart.steps[0].path).toBe('/v1/schemas');
|
|
134
|
-
expect(quickstart.steps[2].path).toBe('/v1/records');
|
|
135
|
-
|
|
136
|
-
// Docs hints always present — point at live API discovery and the openapi resource.
|
|
137
|
-
const docs = content.docs as { openapi: string; openapiResource: string; description: string };
|
|
138
|
-
expect(docs.openapi).toBe('/openapi.json');
|
|
139
|
-
expect(docs.openapiResource).toBe('agledger://openapi');
|
|
140
|
-
expect(docs.description).toContain('nextSteps');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('returns partial results when one call fails', async () => {
|
|
144
|
-
const mockFetch = vi
|
|
145
|
-
.fn()
|
|
146
|
-
.mockResolvedValueOnce(
|
|
147
|
-
new Response(JSON.stringify({ status: 'ok' }), {
|
|
148
|
-
status: 200,
|
|
149
|
-
headers: { 'content-type': 'application/json' },
|
|
150
|
-
}),
|
|
151
|
-
)
|
|
152
|
-
.mockRejectedValueOnce(new TypeError('fetch failed'));
|
|
153
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
154
|
-
|
|
155
|
-
const result = await harness.client.callTool({ name: 'agledger_discover', arguments: {} });
|
|
156
|
-
|
|
157
|
-
expect(result.isError).toBeFalsy();
|
|
158
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
159
|
-
expect(content.health).toEqual({ status: 'ok' });
|
|
160
|
-
expect(content.identity).toEqual({ error: 'fetch failed' });
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('agledger_api', () => {
|
|
165
|
-
it('passes through successful GET response', async () => {
|
|
166
|
-
const apiResponse = {
|
|
167
|
-
data: [{ id: 'r-1', status: 'ACTIVE' }],
|
|
168
|
-
nextSteps: [{ action: 'Get record', method: 'GET', href: '/records/r-1' }],
|
|
169
|
-
};
|
|
170
|
-
vi.stubGlobal(
|
|
171
|
-
'fetch',
|
|
172
|
-
vi.fn().mockResolvedValueOnce(
|
|
173
|
-
new Response(JSON.stringify(apiResponse), {
|
|
174
|
-
status: 200,
|
|
175
|
-
headers: { 'content-type': 'application/json' },
|
|
176
|
-
}),
|
|
177
|
-
),
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const result = await harness.client.callTool({
|
|
181
|
-
name: 'agledger_api',
|
|
182
|
-
arguments: { method: 'GET', path: '/records', params: { limit: 10 } },
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
expect(result.isError).toBeFalsy();
|
|
186
|
-
expect(result.structuredContent).toEqual(apiResponse);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('passes through POST body', async () => {
|
|
190
|
-
const apiResponse = { id: 'r-2', status: 'CREATED' };
|
|
191
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
192
|
-
new Response(JSON.stringify(apiResponse), {
|
|
193
|
-
status: 201,
|
|
194
|
-
headers: { 'content-type': 'application/json' },
|
|
195
|
-
}),
|
|
196
|
-
);
|
|
197
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
198
|
-
|
|
199
|
-
await harness.client.callTool({
|
|
200
|
-
name: 'agledger_api',
|
|
201
|
-
arguments: {
|
|
202
|
-
method: 'POST',
|
|
203
|
-
path: '/records',
|
|
204
|
-
params: { type: 'ACH-PROC-v1', platform: 'test' },
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
209
|
-
expect(url).toContain('/records');
|
|
210
|
-
expect(options.method).toBe('POST');
|
|
211
|
-
expect(JSON.parse(options.body as string)).toEqual({
|
|
212
|
-
type: 'ACH-PROC-v1',
|
|
213
|
-
platform: 'test',
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('forwards full API error body', async () => {
|
|
218
|
-
const errorBody = {
|
|
219
|
-
message: 'Record not found',
|
|
220
|
-
code: 'NOT_FOUND',
|
|
221
|
-
docUrl: 'https://www.agledger.ai/docs/errors/NOT_FOUND',
|
|
222
|
-
suggestion: 'Check the record ID and try again.',
|
|
223
|
-
};
|
|
224
|
-
vi.stubGlobal(
|
|
225
|
-
'fetch',
|
|
226
|
-
vi.fn().mockResolvedValueOnce(
|
|
227
|
-
new Response(JSON.stringify(errorBody), {
|
|
228
|
-
status: 404,
|
|
229
|
-
headers: { 'content-type': 'application/json' },
|
|
230
|
-
}),
|
|
231
|
-
),
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const result = await harness.client.callTool({
|
|
235
|
-
name: 'agledger_api',
|
|
236
|
-
arguments: { method: 'GET', path: '/records/bad-id' },
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
expect(result.isError).toBe(true);
|
|
240
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
241
|
-
expect(content.docUrl).toBe('https://www.agledger.ai/docs/errors/NOT_FOUND');
|
|
242
|
-
expect(content.suggestion).toBe('Check the record ID and try again.');
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('forwards 403 with missingScopes', async () => {
|
|
246
|
-
const errorBody = {
|
|
247
|
-
message: 'Insufficient permissions',
|
|
248
|
-
code: 'FORBIDDEN',
|
|
249
|
-
missingScopes: ['records:write'],
|
|
250
|
-
suggestion: 'Request records:write scope on your API key.',
|
|
251
|
-
};
|
|
252
|
-
vi.stubGlobal(
|
|
253
|
-
'fetch',
|
|
254
|
-
vi.fn().mockResolvedValueOnce(
|
|
255
|
-
new Response(JSON.stringify(errorBody), {
|
|
256
|
-
status: 403,
|
|
257
|
-
headers: { 'content-type': 'application/json' },
|
|
258
|
-
}),
|
|
259
|
-
),
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
const result = await harness.client.callTool({
|
|
263
|
-
name: 'agledger_api',
|
|
264
|
-
arguments: { method: 'POST', path: '/records', params: {} },
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
expect(result.isError).toBe(true);
|
|
268
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
269
|
-
expect(content.missingScopes).toEqual(['records:write']);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('rejects path not starting with / with recovery directive', async () => {
|
|
273
|
-
const result = await harness.client.callTool({
|
|
274
|
-
name: 'agledger_api',
|
|
275
|
-
arguments: { method: 'GET', path: 'records' },
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
expect(result.isError).toBe(true);
|
|
279
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
280
|
-
expect(content.code).toBe('PATH_INVALID');
|
|
281
|
-
const text = (result.content as Array<{ type: string; text: string }>)[0].text;
|
|
282
|
-
expect(text).toContain('/v1/');
|
|
283
|
-
expect(text).toContain('agledger_discover');
|
|
284
|
-
expect(content.suggestion).toBeDefined();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('forwards API error body verbatim when suggestion is missing (no MCP-side enrichment)', async () => {
|
|
288
|
-
// Thin-passthrough contract: the API owns error guidance. The MCP must not
|
|
289
|
-
// inject a suggestion or any other field the API didn't return.
|
|
290
|
-
const errorBody = {
|
|
291
|
-
message: 'Invalid Record type',
|
|
292
|
-
code: 'BAD_REQUEST',
|
|
293
|
-
};
|
|
294
|
-
vi.stubGlobal(
|
|
295
|
-
'fetch',
|
|
296
|
-
vi.fn().mockResolvedValueOnce(
|
|
297
|
-
new Response(JSON.stringify(errorBody), {
|
|
298
|
-
status: 400,
|
|
299
|
-
headers: { 'content-type': 'application/json' },
|
|
300
|
-
}),
|
|
301
|
-
),
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
const result = await harness.client.callTool({
|
|
305
|
-
name: 'agledger_api',
|
|
306
|
-
arguments: { method: 'POST', path: '/v1/records', params: { type: 'INVALID' } },
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
expect(result.isError).toBe(true);
|
|
310
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
311
|
-
expect(content).toEqual(errorBody); // exact match — no added fields
|
|
312
|
-
expect(content.suggestion).toBeUndefined();
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('preserves existing API suggestion without overwriting', async () => {
|
|
316
|
-
const errorBody = {
|
|
317
|
-
message: 'Record not found',
|
|
318
|
-
code: 'NOT_FOUND',
|
|
319
|
-
suggestion: 'The record may have been deleted.',
|
|
320
|
-
};
|
|
321
|
-
vi.stubGlobal(
|
|
322
|
-
'fetch',
|
|
323
|
-
vi.fn().mockResolvedValueOnce(
|
|
324
|
-
new Response(JSON.stringify(errorBody), {
|
|
325
|
-
status: 404,
|
|
326
|
-
headers: { 'content-type': 'application/json' },
|
|
327
|
-
}),
|
|
328
|
-
),
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
const result = await harness.client.callTool({
|
|
332
|
-
name: 'agledger_api',
|
|
333
|
-
arguments: { method: 'GET', path: '/v1/records/bad-id' },
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
expect(result.isError).toBe(true);
|
|
337
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
338
|
-
expect(content.suggestion).toBe('The record may have been deleted.');
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('handles network errors with recovery directive', async () => {
|
|
342
|
-
vi.stubGlobal(
|
|
343
|
-
'fetch',
|
|
344
|
-
vi.fn().mockRejectedValueOnce(new TypeError('fetch failed: DNS resolution failed')),
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
const result = await harness.client.callTool({
|
|
348
|
-
name: 'agledger_api',
|
|
349
|
-
arguments: { method: 'GET', path: '/health' },
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
expect(result.isError).toBe(true);
|
|
353
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
354
|
-
expect(content.code).toBe('NETWORK_ERROR');
|
|
355
|
-
expect(content.suggestion).toContain('/health');
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it('handles timeout with recovery directive', async () => {
|
|
359
|
-
vi.stubGlobal(
|
|
360
|
-
'fetch',
|
|
361
|
-
vi
|
|
362
|
-
.fn()
|
|
363
|
-
.mockRejectedValueOnce(
|
|
364
|
-
Object.assign(new DOMException('The operation was aborted', 'AbortError'), {}),
|
|
365
|
-
),
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
const result = await harness.client.callTool({
|
|
369
|
-
name: 'agledger_api',
|
|
370
|
-
arguments: { method: 'GET', path: '/health' },
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
expect(result.isError).toBe(true);
|
|
374
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
375
|
-
expect(content.code).toBe('TIMEOUT');
|
|
376
|
-
expect(content.suggestion).toContain('Retry');
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it('handles non-JSON responses', async () => {
|
|
380
|
-
vi.stubGlobal(
|
|
381
|
-
'fetch',
|
|
382
|
-
vi.fn().mockResolvedValueOnce(
|
|
383
|
-
new Response('<html>Bad Gateway</html>', {
|
|
384
|
-
status: 502,
|
|
385
|
-
headers: { 'content-type': 'text/html' },
|
|
386
|
-
}),
|
|
387
|
-
),
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
const result = await harness.client.callTool({
|
|
391
|
-
name: 'agledger_api',
|
|
392
|
-
arguments: { method: 'GET', path: '/health' },
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
expect(result.isError).toBe(true);
|
|
396
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
397
|
-
expect(content._raw).toBe('<html>Bad Gateway</html>');
|
|
398
|
-
expect(content._contentType).toBe('text/html');
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
it('sends query params for GET requests', async () => {
|
|
402
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
403
|
-
new Response(JSON.stringify({ data: [] }), {
|
|
404
|
-
status: 200,
|
|
405
|
-
headers: { 'content-type': 'application/json' },
|
|
406
|
-
}),
|
|
407
|
-
);
|
|
408
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
409
|
-
|
|
410
|
-
await harness.client.callTool({
|
|
411
|
-
name: 'agledger_api',
|
|
412
|
-
arguments: {
|
|
413
|
-
method: 'GET',
|
|
414
|
-
path: '/records/search',
|
|
415
|
-
params: { status: 'ACTIVE', limit: 20 },
|
|
416
|
-
},
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
const url = new URL(mockFetch.mock.calls[0][0] as string);
|
|
420
|
-
expect(url.searchParams.get('status')).toBe('ACTIVE');
|
|
421
|
-
expect(url.searchParams.get('limit')).toBe('20');
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
describe('agledger_verify', () => {
|
|
426
|
-
it('verifies a valid audit export offline', async () => {
|
|
427
|
-
const result = await harness.client.callTool({
|
|
428
|
-
name: 'agledger_verify',
|
|
429
|
-
arguments: { export: loadVector('valid-export.json') },
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
expect(result.isError).toBeFalsy();
|
|
433
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
434
|
-
expect(content.valid).toBe(true);
|
|
435
|
-
expect(content.verifiedEntries).toBe(3);
|
|
436
|
-
expect(content.totalEntries).toBe(3);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('returns brokenAt for tampered payload', async () => {
|
|
440
|
-
const result = await harness.client.callTool({
|
|
441
|
-
name: 'agledger_verify',
|
|
442
|
-
arguments: { export: loadVector('tampered-payload.json') },
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
expect(result.isError).toBe(true);
|
|
446
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
447
|
-
expect(content.valid).toBe(false);
|
|
448
|
-
expect((content.brokenAt as Record<string, unknown>).position).toBe(2);
|
|
449
|
-
expect((content.brokenAt as Record<string, unknown>).reason).toBe('payload_hash_mismatch');
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
it('returns brokenAt for broken chain', async () => {
|
|
453
|
-
const result = await harness.client.callTool({
|
|
454
|
-
name: 'agledger_verify',
|
|
455
|
-
arguments: { export: loadVector('broken-chain.json') },
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
expect(result.isError).toBe(true);
|
|
459
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
460
|
-
expect((content.brokenAt as Record<string, unknown>).reason).toBe('chain_break');
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
it('makes no API calls (fully offline)', async () => {
|
|
464
|
-
const mockFetch = vi.fn();
|
|
465
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
466
|
-
|
|
467
|
-
await harness.client.callTool({
|
|
468
|
-
name: 'agledger_verify',
|
|
469
|
-
arguments: { export: loadVector('valid-export.json') },
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
it('accepts publicKeys override', async () => {
|
|
476
|
-
const keys = loadVector('public-keys.json');
|
|
477
|
-
const result = await harness.client.callTool({
|
|
478
|
-
name: 'agledger_verify',
|
|
479
|
-
arguments: {
|
|
480
|
-
export: loadVector('valid-export.json'),
|
|
481
|
-
publicKeys: keys,
|
|
482
|
-
},
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
expect(result.isError).toBeFalsy();
|
|
486
|
-
expect((result.structuredContent as Record<string, unknown>).valid).toBe(true);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('rejects malformed export input', async () => {
|
|
490
|
-
const result = await harness.client.callTool({
|
|
491
|
-
name: 'agledger_verify',
|
|
492
|
-
arguments: { export: { notAnExport: true } },
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
expect(result.isError).toBe(true);
|
|
496
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
497
|
-
expect(content.code).toBe('INVALID_EXPORT');
|
|
498
|
-
expect(content.suggestion).toContain('audit-export');
|
|
499
|
-
});
|
|
500
|
-
});
|
package/tsconfig.json
DELETED