@agledger/mcp-server 2.3.1 → 2.3.2
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 +25 -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 +17 -11
- 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/api-client.test.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
2
|
-
import { ApiClient } from '../src/api-client.js';
|
|
3
|
-
|
|
4
|
-
afterEach(() => {
|
|
5
|
-
vi.unstubAllGlobals();
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
describe('ApiClient', () => {
|
|
9
|
-
it('sends authorization header', async () => {
|
|
10
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
11
|
-
new Response(JSON.stringify({ ok: true }), {
|
|
12
|
-
status: 200,
|
|
13
|
-
headers: { 'content-type': 'application/json' },
|
|
14
|
-
}),
|
|
15
|
-
);
|
|
16
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
17
|
-
|
|
18
|
-
const client = new ApiClient('https://api.test.com', 'my-secret-key');
|
|
19
|
-
await client.request('GET', '/health');
|
|
20
|
-
|
|
21
|
-
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
22
|
-
const headers = options.headers as Record<string, string>;
|
|
23
|
-
expect(headers.Authorization).toBe('Bearer my-secret-key');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('appends query params for GET', async () => {
|
|
27
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
28
|
-
new Response(JSON.stringify({}), {
|
|
29
|
-
status: 200,
|
|
30
|
-
headers: { 'content-type': 'application/json' },
|
|
31
|
-
}),
|
|
32
|
-
);
|
|
33
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
34
|
-
|
|
35
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
36
|
-
await client.request('GET', '/search', { query: { q: 'test', limit: 10 } });
|
|
37
|
-
|
|
38
|
-
const url = new URL(mockFetch.mock.calls[0][0] as string);
|
|
39
|
-
expect(url.searchParams.get('q')).toBe('test');
|
|
40
|
-
expect(url.searchParams.get('limit')).toBe('10');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('skips undefined query params', async () => {
|
|
44
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
45
|
-
new Response(JSON.stringify({}), {
|
|
46
|
-
status: 200,
|
|
47
|
-
headers: { 'content-type': 'application/json' },
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
51
|
-
|
|
52
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
53
|
-
await client.request('GET', '/search', { query: { q: 'test', missing: undefined } });
|
|
54
|
-
|
|
55
|
-
const url = new URL(mockFetch.mock.calls[0][0] as string);
|
|
56
|
-
expect(url.searchParams.has('missing')).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('sends JSON body for POST', async () => {
|
|
60
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
61
|
-
new Response(JSON.stringify({ id: '1' }), {
|
|
62
|
-
status: 201,
|
|
63
|
-
headers: { 'content-type': 'application/json' },
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
67
|
-
|
|
68
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
69
|
-
await client.request('POST', '/records', { body: { type: 'ACH-PROC-v1' } });
|
|
70
|
-
|
|
71
|
-
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
72
|
-
const headers = options.headers as Record<string, string>;
|
|
73
|
-
expect(headers['Content-Type']).toBe('application/json');
|
|
74
|
-
expect(JSON.parse(options.body as string)).toEqual({ type: 'ACH-PROC-v1' });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('handles non-JSON responses', async () => {
|
|
78
|
-
vi.stubGlobal(
|
|
79
|
-
'fetch',
|
|
80
|
-
vi.fn().mockResolvedValueOnce(
|
|
81
|
-
new Response('Service Unavailable', {
|
|
82
|
-
status: 503,
|
|
83
|
-
headers: { 'content-type': 'text/plain' },
|
|
84
|
-
}),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
89
|
-
const result = await client.request('GET', '/health');
|
|
90
|
-
|
|
91
|
-
expect(result.ok).toBe(false);
|
|
92
|
-
expect(result.status).toBe(503);
|
|
93
|
-
expect((result.body as Record<string, unknown>)._raw).toBe('Service Unavailable');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('strips trailing slash from base URL', async () => {
|
|
97
|
-
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
98
|
-
new Response(JSON.stringify({}), {
|
|
99
|
-
status: 200,
|
|
100
|
-
headers: { 'content-type': 'application/json' },
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
104
|
-
|
|
105
|
-
const client = new ApiClient('https://api.test.com/', 'key');
|
|
106
|
-
await client.request('GET', '/health');
|
|
107
|
-
|
|
108
|
-
const url = mockFetch.mock.calls[0][0] as string;
|
|
109
|
-
expect(url).toBe('https://api.test.com/health');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('sets ok=true for 2xx responses', async () => {
|
|
113
|
-
vi.stubGlobal(
|
|
114
|
-
'fetch',
|
|
115
|
-
vi.fn().mockResolvedValueOnce(
|
|
116
|
-
new Response(JSON.stringify({ id: '1' }), {
|
|
117
|
-
status: 201,
|
|
118
|
-
headers: { 'content-type': 'application/json' },
|
|
119
|
-
}),
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
124
|
-
const result = await client.request('POST', '/records', { body: {} });
|
|
125
|
-
|
|
126
|
-
expect(result.ok).toBe(true);
|
|
127
|
-
expect(result.status).toBe(201);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('sets ok=false for 4xx/5xx responses', async () => {
|
|
131
|
-
vi.stubGlobal(
|
|
132
|
-
'fetch',
|
|
133
|
-
vi.fn().mockResolvedValueOnce(
|
|
134
|
-
new Response(JSON.stringify({ message: 'Not found' }), {
|
|
135
|
-
status: 404,
|
|
136
|
-
headers: { 'content-type': 'application/json' },
|
|
137
|
-
}),
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const client = new ApiClient('https://api.test.com', 'key');
|
|
142
|
-
const result = await client.request('GET', '/records/bad');
|
|
143
|
-
|
|
144
|
-
expect(result.ok).toBe(false);
|
|
145
|
-
expect(result.status).toBe(404);
|
|
146
|
-
});
|
|
147
|
-
});
|
package/tests/harness.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
-
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
3
|
-
import { AgledgerMcpServer } from '../src/server.js';
|
|
4
|
-
|
|
5
|
-
export interface TestHarness {
|
|
6
|
-
client: Client;
|
|
7
|
-
cleanup: () => Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function createTestHarness(): Promise<TestHarness> {
|
|
11
|
-
const server = new AgledgerMcpServer({
|
|
12
|
-
apiKey: 'test-key',
|
|
13
|
-
apiUrl: 'https://test.agledger.example.com',
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
17
|
-
const client = new Client({ name: 'test-client', version: '0.0.0-test' });
|
|
18
|
-
|
|
19
|
-
await Promise.all([server.mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
client,
|
|
23
|
-
cleanup: async () => {
|
|
24
|
-
await client.close();
|
|
25
|
-
await server.mcp.close();
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
4
|
-
import { AgledgerMcpServer } from '../src/server.js';
|
|
5
|
-
|
|
6
|
-
const API_URL = process.env.AGLEDGER_API_URL ?? 'http://localhost:3001';
|
|
7
|
-
const API_KEY =
|
|
8
|
-
process.env.AGLEDGER_API_KEY ?? 'agl_agt_test';
|
|
9
|
-
|
|
10
|
-
let client: Client;
|
|
11
|
-
let cleanup: () => Promise<void>;
|
|
12
|
-
let apiReachable = false;
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
try {
|
|
16
|
-
const res = await fetch(`${API_URL}/health`, { signal: AbortSignal.timeout(3000) });
|
|
17
|
-
apiReachable = res.ok;
|
|
18
|
-
} catch {
|
|
19
|
-
apiReachable = false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!apiReachable) return;
|
|
23
|
-
|
|
24
|
-
const server = new AgledgerMcpServer({ apiKey: API_KEY, apiUrl: API_URL });
|
|
25
|
-
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
26
|
-
client = new Client({ name: 'integration-test', version: '0.0.0-test' });
|
|
27
|
-
|
|
28
|
-
await Promise.all([server.mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
29
|
-
|
|
30
|
-
cleanup = async () => {
|
|
31
|
-
await client.close();
|
|
32
|
-
await server.mcp.close();
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
afterAll(async () => {
|
|
37
|
-
if (cleanup) await cleanup();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
function skipIfNoApi() {
|
|
41
|
-
if (!apiReachable) {
|
|
42
|
-
console.log('Skipping: API not reachable at', API_URL);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe('agledger_discover (live)', () => {
|
|
49
|
-
it('returns health and identity', async () => {
|
|
50
|
-
if (skipIfNoApi()) return;
|
|
51
|
-
|
|
52
|
-
const result = await client.callTool({ name: 'agledger_discover', arguments: {} });
|
|
53
|
-
|
|
54
|
-
expect(result.isError).toBeFalsy();
|
|
55
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
56
|
-
|
|
57
|
-
expect(content.health).toBeDefined();
|
|
58
|
-
const health = content.health as Record<string, unknown>;
|
|
59
|
-
expect(health.status).toBe('ok');
|
|
60
|
-
expect(health.version).toBeDefined();
|
|
61
|
-
|
|
62
|
-
expect(content.identity).toBeDefined();
|
|
63
|
-
const identity = content.identity as Record<string, unknown>;
|
|
64
|
-
expect(identity.role).toBeDefined();
|
|
65
|
-
expect(identity.ownerId).toBeDefined();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('admin key (live)', () => {
|
|
70
|
-
let adminClient: Client;
|
|
71
|
-
let adminCleanup: () => Promise<void>;
|
|
72
|
-
|
|
73
|
-
beforeAll(async () => {
|
|
74
|
-
if (!apiReachable) return;
|
|
75
|
-
const adminKey = process.env.AGLEDGER_ADMIN_API_KEY ?? 'agl_adm_test';
|
|
76
|
-
const server = new AgledgerMcpServer({ apiKey: adminKey, apiUrl: API_URL });
|
|
77
|
-
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
78
|
-
adminClient = new Client({ name: 'admin-test', version: '0.0.0-test' });
|
|
79
|
-
await Promise.all([server.mcp.connect(st), adminClient.connect(ct)]);
|
|
80
|
-
adminCleanup = async () => {
|
|
81
|
-
await adminClient.close();
|
|
82
|
-
await server.mcp.close();
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
afterAll(async () => {
|
|
87
|
-
if (adminCleanup) await adminCleanup();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('discover works with admin key', async () => {
|
|
91
|
-
if (skipIfNoApi()) return;
|
|
92
|
-
const result = await adminClient.callTool({ name: 'agledger_discover', arguments: {} });
|
|
93
|
-
expect(result.isError).toBeFalsy();
|
|
94
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
95
|
-
const identity = content.identity as Record<string, unknown>;
|
|
96
|
-
expect(identity.role).toBe('admin');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('can list records with admin key', async () => {
|
|
100
|
-
if (skipIfNoApi()) return;
|
|
101
|
-
const result = await adminClient.callTool({
|
|
102
|
-
name: 'agledger_api',
|
|
103
|
-
arguments: { method: 'GET', path: '/v1/records', params: { limit: 1 } },
|
|
104
|
-
});
|
|
105
|
-
expect(result.isError).toBeFalsy();
|
|
106
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
107
|
-
expect(content.data).toBeDefined();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('agledger_api (live)', () => {
|
|
112
|
-
it('GET /health', async () => {
|
|
113
|
-
if (skipIfNoApi()) return;
|
|
114
|
-
|
|
115
|
-
const result = await client.callTool({
|
|
116
|
-
name: 'agledger_api',
|
|
117
|
-
arguments: { method: 'GET', path: '/health' },
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
expect(result.isError).toBeFalsy();
|
|
121
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
122
|
-
expect(content.status).toBe('ok');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('GET /v1/auth/me returns identity', async () => {
|
|
126
|
-
if (skipIfNoApi()) return;
|
|
127
|
-
|
|
128
|
-
const result = await client.callTool({
|
|
129
|
-
name: 'agledger_api',
|
|
130
|
-
arguments: { method: 'GET', path: '/v1/auth/me' },
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(result.isError).toBeFalsy();
|
|
134
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
135
|
-
expect(content.role).toBeDefined();
|
|
136
|
-
expect(content.ownerId).toBeDefined();
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('GET /v1/schemas lists Record types', async () => {
|
|
140
|
-
if (skipIfNoApi()) return;
|
|
141
|
-
|
|
142
|
-
const result = await client.callTool({
|
|
143
|
-
name: 'agledger_api',
|
|
144
|
-
arguments: { method: 'GET', path: '/v1/schemas' },
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(result.isError).toBeFalsy();
|
|
148
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
149
|
-
expect(content.data).toBeDefined();
|
|
150
|
-
expect(Array.isArray(content.data)).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('GET /v1/records lists records', async () => {
|
|
154
|
-
if (skipIfNoApi()) return;
|
|
155
|
-
|
|
156
|
-
const result = await client.callTool({
|
|
157
|
-
name: 'agledger_api',
|
|
158
|
-
arguments: { method: 'GET', path: '/v1/records', params: { limit: 5 } },
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
expect(result.isError).toBeFalsy();
|
|
162
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
163
|
-
expect(content.data).toBeDefined();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('POST /v1/records creates a record', async () => {
|
|
167
|
-
if (skipIfNoApi()) return;
|
|
168
|
-
|
|
169
|
-
const result = await client.callTool({
|
|
170
|
-
name: 'agledger_api',
|
|
171
|
-
arguments: {
|
|
172
|
-
method: 'POST',
|
|
173
|
-
path: '/v1/records',
|
|
174
|
-
params: {
|
|
175
|
-
type: 'ACH-PROC-v1',
|
|
176
|
-
platform: 'mcp-integration-test',
|
|
177
|
-
criteria: {
|
|
178
|
-
item_spec: 'integration-test-resource',
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
expect(result.isError).toBeFalsy();
|
|
185
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
186
|
-
expect(content.id).toBeDefined();
|
|
187
|
-
expect(content.type).toBe('ACH-PROC-v1');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('returns structured error for not-found record', async () => {
|
|
191
|
-
if (skipIfNoApi()) return;
|
|
192
|
-
|
|
193
|
-
const result = await client.callTool({
|
|
194
|
-
name: 'agledger_api',
|
|
195
|
-
arguments: { method: 'GET', path: '/v1/records/nonexistent-id' },
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
expect(result.isError).toBe(true);
|
|
199
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
200
|
-
expect(content.error ?? content.message).toBeDefined();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('returns structured error with schema help for bad criteria', async () => {
|
|
204
|
-
if (skipIfNoApi()) return;
|
|
205
|
-
|
|
206
|
-
const result = await client.callTool({
|
|
207
|
-
name: 'agledger_api',
|
|
208
|
-
arguments: {
|
|
209
|
-
method: 'POST',
|
|
210
|
-
path: '/v1/records',
|
|
211
|
-
params: {
|
|
212
|
-
type: 'ACH-PROC-v1',
|
|
213
|
-
platform: 'test',
|
|
214
|
-
criteria: { bad_field: 'wrong' },
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
expect(result.isError).toBe(true);
|
|
220
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
221
|
-
expect(content.requiredFields).toBeDefined();
|
|
222
|
-
expect(content.examplePayload).toBeDefined();
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('full record lifecycle (live)', () => {
|
|
227
|
-
let recordId: string;
|
|
228
|
-
|
|
229
|
-
it('step 1: create record with autoActivate', async () => {
|
|
230
|
-
if (skipIfNoApi()) return;
|
|
231
|
-
|
|
232
|
-
const result = await client.callTool({
|
|
233
|
-
name: 'agledger_api',
|
|
234
|
-
arguments: {
|
|
235
|
-
method: 'POST',
|
|
236
|
-
path: '/v1/records',
|
|
237
|
-
params: {
|
|
238
|
-
type: 'ACH-PROC-v1',
|
|
239
|
-
platform: 'mcp-lifecycle-test',
|
|
240
|
-
autoActivate: true,
|
|
241
|
-
criteria: {
|
|
242
|
-
item_spec: 'lifecycle-test-widget',
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
expect(result.isError).toBeFalsy();
|
|
249
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
250
|
-
recordId = content.id as string;
|
|
251
|
-
expect(recordId).toBeDefined();
|
|
252
|
-
expect(content.status).toBe('ACTIVE');
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('step 2: get record to confirm state', async () => {
|
|
256
|
-
if (skipIfNoApi() || !recordId) return;
|
|
257
|
-
|
|
258
|
-
const result = await client.callTool({
|
|
259
|
-
name: 'agledger_api',
|
|
260
|
-
arguments: { method: 'GET', path: `/v1/records/${recordId}` },
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
expect(result.isError).toBeFalsy();
|
|
264
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
265
|
-
expect(content.id).toBe(recordId);
|
|
266
|
-
expect(content.status).toBe('ACTIVE');
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('step 3: submit receipt', async () => {
|
|
270
|
-
if (skipIfNoApi() || !recordId) return;
|
|
271
|
-
|
|
272
|
-
const result = await client.callTool({
|
|
273
|
-
name: 'agledger_api',
|
|
274
|
-
arguments: {
|
|
275
|
-
method: 'POST',
|
|
276
|
-
path: `/v1/records/${recordId}/receipts`,
|
|
277
|
-
params: {
|
|
278
|
-
evidence: {
|
|
279
|
-
item_secured: 'Lifecycle test widget delivered',
|
|
280
|
-
quantity: 1,
|
|
281
|
-
total_cost: { amount: 10, currency: 'USD' },
|
|
282
|
-
supplier: { id: 'SUP-TEST', name: 'Test Supplier' },
|
|
283
|
-
confirmation_ref: 'MCP-LIFECYCLE-001',
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(result.isError).toBeFalsy();
|
|
290
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
291
|
-
expect(content.id).toBeDefined();
|
|
292
|
-
expect(content.recordId).toBe(recordId);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('step 4: check record reached terminal state', async () => {
|
|
296
|
-
if (skipIfNoApi() || !recordId) return;
|
|
297
|
-
|
|
298
|
-
const result = await client.callTool({
|
|
299
|
-
name: 'agledger_api',
|
|
300
|
-
arguments: { method: 'GET', path: `/v1/records/${recordId}` },
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
expect(result.isError).toBeFalsy();
|
|
304
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
305
|
-
const status = content.status as string;
|
|
306
|
-
expect(['FULFILLED', 'VERIFIED_FAIL', 'PROCESSING']).toContain(status);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('step 5: list receipts for record', async () => {
|
|
310
|
-
if (skipIfNoApi() || !recordId) return;
|
|
311
|
-
|
|
312
|
-
const result = await client.callTool({
|
|
313
|
-
name: 'agledger_api',
|
|
314
|
-
arguments: { method: 'GET', path: `/v1/records/${recordId}/receipts` },
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
expect(result.isError).toBeFalsy();
|
|
318
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
319
|
-
const data = content.data as Array<Record<string, unknown>>;
|
|
320
|
-
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
321
|
-
expect(data[0].recordId).toBe(recordId);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('step 6: check events for record', async () => {
|
|
325
|
-
if (skipIfNoApi() || !recordId) return;
|
|
326
|
-
|
|
327
|
-
const result = await client.callTool({
|
|
328
|
-
name: 'agledger_api',
|
|
329
|
-
arguments: {
|
|
330
|
-
method: 'GET',
|
|
331
|
-
path: '/v1/events',
|
|
332
|
-
params: { recordId, limit: 10, since: '2020-01-01T00:00:00Z' },
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
expect(result.isError).toBeFalsy();
|
|
337
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
338
|
-
const data = content.data as Array<Record<string, unknown>>;
|
|
339
|
-
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
describe('HTTP method coverage (live)', () => {
|
|
344
|
-
it('DELETE returns structured error for nonexistent webhook', async () => {
|
|
345
|
-
if (skipIfNoApi()) return;
|
|
346
|
-
|
|
347
|
-
const result = await client.callTool({
|
|
348
|
-
name: 'agledger_api',
|
|
349
|
-
arguments: { method: 'DELETE', path: '/v1/webhooks/nonexistent-id' },
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
expect(result.isError).toBe(true);
|
|
353
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
354
|
-
expect(content.error ?? content.message).toBeDefined();
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it('PATCH returns structured error for invalid record update', async () => {
|
|
358
|
-
if (skipIfNoApi()) return;
|
|
359
|
-
|
|
360
|
-
const result = await client.callTool({
|
|
361
|
-
name: 'agledger_api',
|
|
362
|
-
arguments: {
|
|
363
|
-
method: 'PATCH',
|
|
364
|
-
path: '/v1/records/nonexistent-id',
|
|
365
|
-
params: { platform: 'updated' },
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
expect(result.isError).toBe(true);
|
|
370
|
-
const content = result.structuredContent as Record<string, unknown>;
|
|
371
|
-
expect(content.error ?? content.message).toBeDefined();
|
|
372
|
-
});
|
|
373
|
-
});
|