@agledger/mcp-server 1.4.0 → 1.4.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/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -1
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +72 -75
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +6 -2
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.js +15 -15
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.js +10 -10
- package/dist/tools/agent-mandates.js.map +1 -1
- package/dist/tools/agents-refs.d.ts.map +1 -1
- package/dist/tools/agents-refs.js +10 -9
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.js +3 -3
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +29 -4
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +29 -4
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +10 -5
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +30 -6
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.js +2 -2
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.js +25 -25
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.js +21 -21
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.js +2 -2
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +25 -14
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.js +6 -6
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +5 -6
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +25 -4
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +71 -26
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.js +2 -2
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.js +3 -3
- package/dist/tools/verification.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +9 -0
- package/src/server.ts +76 -68
- package/src/tool-scopes.ts +7 -3
- package/src/tools/a2a.ts +15 -15
- package/src/tools/agent-mandates.ts +10 -10
- package/src/tools/agents-refs.ts +10 -9
- package/src/tools/capabilities.ts +3 -3
- package/src/tools/compliance.ts +29 -4
- package/src/tools/dashboard.ts +29 -4
- package/src/tools/disputes.ts +10 -5
- package/src/tools/enterprises.ts +30 -6
- package/src/tools/events.ts +2 -2
- package/src/tools/federation-admin.ts +25 -25
- package/src/tools/federation.ts +21 -21
- package/src/tools/health.ts +2 -2
- package/src/tools/mandates.ts +25 -14
- package/src/tools/openclaw.ts +6 -6
- package/src/tools/receipts.ts +5 -6
- package/src/tools/reputation.ts +26 -4
- package/src/tools/schemas.ts +72 -26
- package/src/tools/verification-keys.ts +2 -2
- package/src/tools/verification.ts +3 -3
- package/tests/conformance.test.ts +219 -0
- package/tests/conformance.ts +75 -0
- package/tests/{code-mode-manifest.test.ts → drift/code-mode-manifest.test.ts} +2 -2
- package/tests/harness.ts +55 -0
- package/tests/integration/output-schema-validation.test.ts +167 -0
- package/tests/mock-client.ts +71 -0
- package/tests/profiles.test.ts +135 -0
- package/tests/resources/contract-types.test.ts +82 -0
- package/tests/tools/a2a.test.ts +241 -0
- package/tests/tools/agent-mandates.test.ts +206 -0
- package/tests/tools/agents-refs.test.ts +199 -0
- package/tests/tools/capabilities.test.ts +86 -0
- package/tests/tools/code-mode.test.ts +168 -0
- package/tests/tools/compliance.test.ts +131 -0
- package/tests/tools/dashboard.test.ts +120 -0
- package/tests/tools/disputes.test.ts +131 -0
- package/tests/tools/enterprises.test.ts +181 -0
- package/tests/tools/events.test.ts +61 -0
- package/tests/tools/federation-admin.test.ts +509 -0
- package/tests/tools/federation.test.ts +556 -0
- package/tests/tools/health.test.ts +67 -0
- package/tests/tools/mandates.test.ts +155 -0
- package/tests/tools/openclaw.test.ts +160 -0
- package/tests/tools/receipts.test.ts +170 -0
- package/tests/tools/reputation.test.ts +117 -0
- package/tests/tools/schemas.test.ts +397 -0
- package/tests/tools/verification-keys.test.ts +62 -0
- package/tests/tools/verification.test.ts +74 -0
- package/tests/enterprises.test.ts +0 -96
- package/tests/schemas.test.ts +0 -531
package/tests/schemas.test.ts
DELETED
|
@@ -1,531 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { registerSchemaTools } from '../src/tools/schemas.js';
|
|
4
|
-
|
|
5
|
-
/** Create a mock AgledgerClient with a mocked schemas resource. */
|
|
6
|
-
function createMockClient() {
|
|
7
|
-
return {
|
|
8
|
-
schemas: {
|
|
9
|
-
list: vi.fn().mockResolvedValue({ data: ['ACH-PROC-v1', 'ACH-DLVR-v1', 'ACH-DATA-v1'] }),
|
|
10
|
-
get: vi.fn().mockResolvedValue({
|
|
11
|
-
contractType: 'ACH-PROC-v1',
|
|
12
|
-
mandateSchema: { type: 'object', properties: { item: {}, quantity: {}, maxCost: {} } },
|
|
13
|
-
receiptSchema: { type: 'object', properties: { item: {}, quantity: {}, totalCost: {} } },
|
|
14
|
-
rulesConfig: { syncRuleIds: ['quantity-check', 'cost-ceiling'], asyncRuleIds: [] },
|
|
15
|
-
fieldMappings: [
|
|
16
|
-
{ ruleId: 'quantity-check', criteriaPath: '$.quantity', evidencePath: '$.quantity', valueType: 'number' },
|
|
17
|
-
],
|
|
18
|
-
}),
|
|
19
|
-
getMetaSchema: vi.fn().mockResolvedValue({
|
|
20
|
-
constraints: { maxDepth: 5, maxNodes: 200, maxSizeBytes: 65536, maxCombinerEntries: 10, rootTypeMustBe: 'object', rootMustHaveRequired: true, blockedKeywords: ['$ref'] },
|
|
21
|
-
allowedFormats: ['date-time', 'uri', 'email'],
|
|
22
|
-
allowedRefs: [],
|
|
23
|
-
limits: { contractTypeMaxLength: 50, maxFieldMappings: 20, ruleIdPattern: '^[a-z][a-z0-9-]*$', ruleIdMaxLength: 64, reservedPrefixes: ['ACH-'] },
|
|
24
|
-
fieldMappingValueTypes: ['number', 'denomination', 'string', 'boolean', 'datetime', 'expression'],
|
|
25
|
-
builtinRuleIds: ['quantity-check', 'cost-ceiling'],
|
|
26
|
-
expressionHelpers: ['abs', 'round', 'min', 'max'],
|
|
27
|
-
expressionLimits: { maxLength: 500, maxAstNodes: 50, maxAstDepth: 5, maxOperations: 20, allowedContexts: ['criteria', 'evidence'] },
|
|
28
|
-
sharedSchemas: {},
|
|
29
|
-
examples: { minimalMandate: { type: 'object' }, minimalReceipt: { type: 'object' } },
|
|
30
|
-
}),
|
|
31
|
-
preview: vi.fn().mockResolvedValue({ valid: true, compiled: { contractType: 'ACH-CUSTOM-v1' } }),
|
|
32
|
-
register: vi.fn().mockResolvedValue({
|
|
33
|
-
id: 'sv-1', contractType: 'ACH-CUSTOM-v1', version: 1, enterpriseId: null,
|
|
34
|
-
displayName: 'Custom Type', description: 'A custom type', category: 'custom',
|
|
35
|
-
compatibilityMode: 'BACKWARD', status: 'ACTIVE', isBuiltin: false,
|
|
36
|
-
createdAt: '2026-03-19T00:00:00Z', updatedAt: '2026-03-19T00:00:00Z',
|
|
37
|
-
}),
|
|
38
|
-
getVersions: vi.fn().mockResolvedValue([
|
|
39
|
-
{ id: 'sv-1', contractType: 'ACH-PROC-v1', version: 1, enterpriseId: null, displayName: 'Procurement', description: 'v1', category: 'builtin', compatibilityMode: 'FULL', status: 'ACTIVE', isBuiltin: true, createdAt: '2026-01-01T00:00:00Z', updatedAt: '2026-01-01T00:00:00Z' },
|
|
40
|
-
{ id: 'sv-2', contractType: 'ACH-PROC-v1', version: 2, enterpriseId: null, displayName: 'Procurement', description: 'v2', category: 'builtin', compatibilityMode: 'FULL', status: 'ACTIVE', isBuiltin: true, createdAt: '2026-02-01T00:00:00Z', updatedAt: '2026-02-01T00:00:00Z' },
|
|
41
|
-
]),
|
|
42
|
-
diff: vi.fn().mockResolvedValue({
|
|
43
|
-
contractType: 'ACH-PROC-v1',
|
|
44
|
-
from: { version: 1, createdAt: '2026-01-01T00:00:00Z', status: 'ACTIVE' },
|
|
45
|
-
to: { version: 2, createdAt: '2026-02-01T00:00:00Z', status: 'ACTIVE' },
|
|
46
|
-
mandate: { changes: [{ type: 'added', path: '$.newField', after: { type: 'string' } }] },
|
|
47
|
-
receipt: { changes: [] },
|
|
48
|
-
}),
|
|
49
|
-
getTemplate: vi.fn().mockResolvedValue({
|
|
50
|
-
contractType: 'ACH-PROC-v1',
|
|
51
|
-
displayName: 'Procurement',
|
|
52
|
-
mandateSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
53
|
-
receiptSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
54
|
-
fieldMappings: [],
|
|
55
|
-
}),
|
|
56
|
-
getBlankTemplate: vi.fn().mockResolvedValue({
|
|
57
|
-
contractType: '',
|
|
58
|
-
displayName: '',
|
|
59
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
60
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
61
|
-
fieldMappings: [],
|
|
62
|
-
}),
|
|
63
|
-
checkCompatibility: vi.fn().mockResolvedValue({
|
|
64
|
-
compatible: true,
|
|
65
|
-
mode: 'BACKWARD',
|
|
66
|
-
issues: [],
|
|
67
|
-
}),
|
|
68
|
-
getVersion: vi.fn().mockResolvedValue({
|
|
69
|
-
id: 'sv-1', contractType: 'ACH-PROC-v1', version: 1, enterpriseId: null,
|
|
70
|
-
displayName: 'Procurement', description: 'Resource acquisition', category: 'builtin',
|
|
71
|
-
compatibilityMode: 'FULL', status: 'ACTIVE', isBuiltin: true,
|
|
72
|
-
createdAt: '2026-01-01T00:00:00Z', updatedAt: '2026-01-01T00:00:00Z',
|
|
73
|
-
}),
|
|
74
|
-
getRules: vi.fn().mockResolvedValue({
|
|
75
|
-
contractType: 'ACH-PROC-v1',
|
|
76
|
-
syncRuleIds: ['quantity-check', 'cost-ceiling'],
|
|
77
|
-
asyncRuleIds: ['delivery-confirmation'],
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
} as any;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
describe('registerSchemaTools', () => {
|
|
84
|
-
it('registers schema tools on the MCP server', () => {
|
|
85
|
-
const mcp = new McpServer({ name: 'test', version: '0.0.0' }, { capabilities: { tools: {} } });
|
|
86
|
-
const client = createMockClient();
|
|
87
|
-
registerSchemaTools(mcp, client);
|
|
88
|
-
|
|
89
|
-
// Registration completes without throwing
|
|
90
|
-
expect(true).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('schema tool handlers', () => {
|
|
95
|
-
let mcp: McpServer;
|
|
96
|
-
let client: ReturnType<typeof createMockClient>;
|
|
97
|
-
let handlers: Map<string, (args: any) => Promise<any>>;
|
|
98
|
-
|
|
99
|
-
function setup() {
|
|
100
|
-
mcp = new McpServer({ name: 'test', version: '0.0.0' }, { capabilities: { tools: {} } });
|
|
101
|
-
client = createMockClient();
|
|
102
|
-
handlers = new Map();
|
|
103
|
-
|
|
104
|
-
// Intercept registerTool to capture handlers
|
|
105
|
-
const origRegister = mcp.registerTool.bind(mcp);
|
|
106
|
-
vi.spyOn(mcp, 'registerTool').mockImplementation((name: string, config: any, handler: any) => {
|
|
107
|
-
handlers.set(name, handler);
|
|
108
|
-
return origRegister(name, config, handler);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
registerSchemaTools(mcp, client);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// --- list_contract_schemas ---
|
|
115
|
-
describe('list_contract_schemas', () => {
|
|
116
|
-
it('returns contract type list on success', async () => {
|
|
117
|
-
setup();
|
|
118
|
-
const handler = handlers.get('list_contract_schemas')!;
|
|
119
|
-
const result = await handler({});
|
|
120
|
-
|
|
121
|
-
expect(client.schemas.list).toHaveBeenCalled();
|
|
122
|
-
expect(result.content[0].text).toContain('3 contract types available');
|
|
123
|
-
expect(result.content[0].text).toContain('ACH-PROC-v1');
|
|
124
|
-
expect(result.structuredContent).toEqual({ contractTypes: ['ACH-PROC-v1', 'ACH-DLVR-v1', 'ACH-DATA-v1'] });
|
|
125
|
-
expect(result.isError).toBeUndefined();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('returns error on API failure', async () => {
|
|
129
|
-
setup();
|
|
130
|
-
client.schemas.list.mockRejectedValueOnce(new Error('Network timeout'));
|
|
131
|
-
const handler = handlers.get('list_contract_schemas')!;
|
|
132
|
-
const result = await handler({});
|
|
133
|
-
|
|
134
|
-
expect(result.isError).toBe(true);
|
|
135
|
-
expect(result.content[0].text).toContain('Network timeout');
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// --- get_contract_schema ---
|
|
140
|
-
describe('get_contract_schema', () => {
|
|
141
|
-
it('returns schema details on success', async () => {
|
|
142
|
-
setup();
|
|
143
|
-
const handler = handlers.get('get_contract_schema')!;
|
|
144
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
145
|
-
|
|
146
|
-
expect(client.schemas.get).toHaveBeenCalledWith('ACH-PROC-v1');
|
|
147
|
-
expect(result.content[0].text).toContain('Schema for ACH-PROC-v1');
|
|
148
|
-
expect(result.content[0].text).toContain('mandate schema has 2 fields');
|
|
149
|
-
expect(result.content[0].text).toContain('receipt schema has 2 fields');
|
|
150
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
151
|
-
expect(result.isError).toBeUndefined();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('returns error on API failure', async () => {
|
|
155
|
-
setup();
|
|
156
|
-
client.schemas.get.mockRejectedValueOnce(new Error('Schema not found'));
|
|
157
|
-
const handler = handlers.get('get_contract_schema')!;
|
|
158
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
159
|
-
|
|
160
|
-
expect(result.isError).toBe(true);
|
|
161
|
-
expect(result.content[0].text).toContain('Schema not found');
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// --- get_meta_schema ---
|
|
166
|
-
describe('get_meta_schema', () => {
|
|
167
|
-
it('returns meta-schema on success', async () => {
|
|
168
|
-
setup();
|
|
169
|
-
const handler = handlers.get('get_meta_schema')!;
|
|
170
|
-
const result = await handler({});
|
|
171
|
-
|
|
172
|
-
expect(client.schemas.getMetaSchema).toHaveBeenCalled();
|
|
173
|
-
expect(result.content[0].text).toContain('max depth 5');
|
|
174
|
-
expect(result.content[0].text).toContain('max nodes 200');
|
|
175
|
-
expect(result.content[0].text).toContain('max size 65536 bytes');
|
|
176
|
-
expect(result.content[0].text).toContain('3 allowed formats');
|
|
177
|
-
expect(result.content[0].text).toContain('max 20 field mappings');
|
|
178
|
-
expect(result.content[0].text).toContain('6 value types');
|
|
179
|
-
expect(result.structuredContent.constraints).toBeDefined();
|
|
180
|
-
expect(result.isError).toBeUndefined();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('returns error on API failure', async () => {
|
|
184
|
-
setup();
|
|
185
|
-
client.schemas.getMetaSchema.mockRejectedValueOnce(new Error('Unauthorized'));
|
|
186
|
-
const handler = handlers.get('get_meta_schema')!;
|
|
187
|
-
const result = await handler({});
|
|
188
|
-
|
|
189
|
-
expect(result.isError).toBe(true);
|
|
190
|
-
expect(result.content[0].text).toContain('Unauthorized');
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// --- preview_schema ---
|
|
195
|
-
describe('preview_schema', () => {
|
|
196
|
-
it('returns valid preview on success', async () => {
|
|
197
|
-
setup();
|
|
198
|
-
const handler = handlers.get('preview_schema')!;
|
|
199
|
-
const input = {
|
|
200
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
201
|
-
displayName: 'Custom Type',
|
|
202
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
203
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
204
|
-
};
|
|
205
|
-
const result = await handler(input);
|
|
206
|
-
|
|
207
|
-
expect(client.schemas.preview).toHaveBeenCalledWith({
|
|
208
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
209
|
-
displayName: 'Custom Type',
|
|
210
|
-
description: undefined,
|
|
211
|
-
category: undefined,
|
|
212
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
213
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
214
|
-
fieldMappings: undefined,
|
|
215
|
-
compatibilityMode: undefined,
|
|
216
|
-
});
|
|
217
|
-
expect(result.content[0].text).toContain('Schema preview for ACH-CUSTOM-v1: valid');
|
|
218
|
-
expect(result.structuredContent.valid).toBe(true);
|
|
219
|
-
expect(result.isError).toBeUndefined();
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('returns invalid preview with errors', async () => {
|
|
223
|
-
setup();
|
|
224
|
-
client.schemas.preview.mockResolvedValueOnce({
|
|
225
|
-
valid: false,
|
|
226
|
-
errors: [
|
|
227
|
-
{ code: 'MISSING_REQUIRED', message: 'Root must have required fields', path: '$.mandateSchema' },
|
|
228
|
-
{ code: 'DEPTH_EXCEEDED', message: 'Schema exceeds max depth', path: '$.mandateSchema.nested' },
|
|
229
|
-
],
|
|
230
|
-
});
|
|
231
|
-
const handler = handlers.get('preview_schema')!;
|
|
232
|
-
const result = await handler({
|
|
233
|
-
contractType: 'ACH-BAD-v1',
|
|
234
|
-
displayName: 'Bad Type',
|
|
235
|
-
mandateSchema: {},
|
|
236
|
-
receiptSchema: {},
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
expect(result.content[0].text).toContain('invalid (2 errors)');
|
|
240
|
-
expect(result.structuredContent.valid).toBe(false);
|
|
241
|
-
expect(result.structuredContent.errors).toHaveLength(2);
|
|
242
|
-
expect(result.isError).toBeUndefined();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('returns error on API failure', async () => {
|
|
246
|
-
setup();
|
|
247
|
-
client.schemas.preview.mockRejectedValueOnce(new Error('Validation service unavailable'));
|
|
248
|
-
const handler = handlers.get('preview_schema')!;
|
|
249
|
-
const result = await handler({
|
|
250
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
251
|
-
displayName: 'Custom',
|
|
252
|
-
mandateSchema: {},
|
|
253
|
-
receiptSchema: {},
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
expect(result.isError).toBe(true);
|
|
257
|
-
expect(result.content[0].text).toContain('Validation service unavailable');
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// --- register_schema ---
|
|
262
|
-
describe('register_schema', () => {
|
|
263
|
-
it('returns registered version on success', async () => {
|
|
264
|
-
setup();
|
|
265
|
-
const handler = handlers.get('register_schema')!;
|
|
266
|
-
const input = {
|
|
267
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
268
|
-
displayName: 'Custom Type',
|
|
269
|
-
description: 'A custom type',
|
|
270
|
-
category: 'custom',
|
|
271
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
272
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
273
|
-
compatibilityMode: 'BACKWARD',
|
|
274
|
-
};
|
|
275
|
-
const result = await handler(input);
|
|
276
|
-
|
|
277
|
-
expect(client.schemas.register).toHaveBeenCalledWith({
|
|
278
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
279
|
-
displayName: 'Custom Type',
|
|
280
|
-
description: 'A custom type',
|
|
281
|
-
category: 'custom',
|
|
282
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
283
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
284
|
-
fieldMappings: undefined,
|
|
285
|
-
compatibilityMode: 'BACKWARD',
|
|
286
|
-
});
|
|
287
|
-
expect(result.content[0].text).toContain('Registered ACH-CUSTOM-v1 v1');
|
|
288
|
-
expect(result.content[0].text).toContain('ACTIVE');
|
|
289
|
-
expect(result.structuredContent.id).toBe('sv-1');
|
|
290
|
-
expect(result.isError).toBeUndefined();
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('returns error on API failure', async () => {
|
|
294
|
-
setup();
|
|
295
|
-
client.schemas.register.mockRejectedValueOnce(new Error('Duplicate contract type'));
|
|
296
|
-
const handler = handlers.get('register_schema')!;
|
|
297
|
-
const result = await handler({
|
|
298
|
-
contractType: 'ACH-CUSTOM-v1',
|
|
299
|
-
displayName: 'Custom',
|
|
300
|
-
mandateSchema: {},
|
|
301
|
-
receiptSchema: {},
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
expect(result.isError).toBe(true);
|
|
305
|
-
expect(result.content[0].text).toContain('Duplicate contract type');
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// --- get_schema_versions ---
|
|
310
|
-
describe('get_schema_versions', () => {
|
|
311
|
-
it('returns version list on success', async () => {
|
|
312
|
-
setup();
|
|
313
|
-
const handler = handlers.get('get_schema_versions')!;
|
|
314
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
315
|
-
|
|
316
|
-
expect(client.schemas.getVersions).toHaveBeenCalledWith('ACH-PROC-v1');
|
|
317
|
-
expect(result.content[0].text).toContain('ACH-PROC-v1: 2 version(s)');
|
|
318
|
-
expect(result.content[0].text).toContain('Latest: v2');
|
|
319
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
320
|
-
expect(result.structuredContent.versions).toHaveLength(2);
|
|
321
|
-
expect(result.isError).toBeUndefined();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('handles empty version list', async () => {
|
|
325
|
-
setup();
|
|
326
|
-
client.schemas.getVersions.mockResolvedValueOnce([]);
|
|
327
|
-
const handler = handlers.get('get_schema_versions')!;
|
|
328
|
-
const result = await handler({ contractType: 'ACH-NEW-v1' });
|
|
329
|
-
|
|
330
|
-
expect(result.content[0].text).toContain('0 version(s)');
|
|
331
|
-
expect(result.content[0].text).toContain('Latest: vnone');
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it('returns error on API failure', async () => {
|
|
335
|
-
setup();
|
|
336
|
-
client.schemas.getVersions.mockRejectedValueOnce(new Error('Not found'));
|
|
337
|
-
const handler = handlers.get('get_schema_versions')!;
|
|
338
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
339
|
-
|
|
340
|
-
expect(result.isError).toBe(true);
|
|
341
|
-
expect(result.content[0].text).toContain('Not found');
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// --- diff_schema_versions ---
|
|
346
|
-
describe('diff_schema_versions', () => {
|
|
347
|
-
it('returns diff result on success', async () => {
|
|
348
|
-
setup();
|
|
349
|
-
const handler = handlers.get('diff_schema_versions')!;
|
|
350
|
-
const result = await handler({ contractType: 'ACH-PROC-v1', from: 1, to: 2 });
|
|
351
|
-
|
|
352
|
-
expect(client.schemas.diff).toHaveBeenCalledWith('ACH-PROC-v1', 1, 2);
|
|
353
|
-
expect(result.content[0].text).toContain('Diff ACH-PROC-v1 v1');
|
|
354
|
-
expect(result.content[0].text).toContain('v2');
|
|
355
|
-
expect(result.content[0].text).toContain('1 mandate change(s)');
|
|
356
|
-
expect(result.content[0].text).toContain('0 receipt change(s)');
|
|
357
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
358
|
-
expect(result.isError).toBeUndefined();
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
it('returns error on API failure', async () => {
|
|
362
|
-
setup();
|
|
363
|
-
client.schemas.diff.mockRejectedValueOnce(new Error('Version 3 not found'));
|
|
364
|
-
const handler = handlers.get('diff_schema_versions')!;
|
|
365
|
-
const result = await handler({ contractType: 'ACH-PROC-v1', from: 1, to: 3 });
|
|
366
|
-
|
|
367
|
-
expect(result.isError).toBe(true);
|
|
368
|
-
expect(result.content[0].text).toContain('Version 3 not found');
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// --- get_schema_template ---
|
|
373
|
-
describe('get_schema_template', () => {
|
|
374
|
-
it('returns template based on existing type on success', async () => {
|
|
375
|
-
setup();
|
|
376
|
-
const handler = handlers.get('get_schema_template')!;
|
|
377
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
378
|
-
|
|
379
|
-
expect(client.schemas.getTemplate).toHaveBeenCalledWith('ACH-PROC-v1');
|
|
380
|
-
expect(result.content[0].text).toContain('ACH-PROC-v1');
|
|
381
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
382
|
-
expect(result.structuredContent.displayName).toBe('Procurement');
|
|
383
|
-
expect(result.isError).toBeUndefined();
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it('returns error on API failure', async () => {
|
|
387
|
-
setup();
|
|
388
|
-
client.schemas.getTemplate.mockRejectedValueOnce(new Error('Unknown contract type'));
|
|
389
|
-
const handler = handlers.get('get_schema_template')!;
|
|
390
|
-
const result = await handler({ contractType: 'ACH-FAKE-v1' });
|
|
391
|
-
|
|
392
|
-
expect(result.isError).toBe(true);
|
|
393
|
-
expect(result.content[0].text).toContain('Unknown contract type');
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// --- get_blank_schema_template ---
|
|
398
|
-
describe('get_blank_schema_template', () => {
|
|
399
|
-
it('returns blank template on success', async () => {
|
|
400
|
-
setup();
|
|
401
|
-
const handler = handlers.get('get_blank_schema_template')!;
|
|
402
|
-
const result = await handler({});
|
|
403
|
-
|
|
404
|
-
expect(client.schemas.getBlankTemplate).toHaveBeenCalled();
|
|
405
|
-
expect(result.content[0].text).toBeDefined();
|
|
406
|
-
expect(result.structuredContent.mandateSchema).toBeDefined();
|
|
407
|
-
expect(result.structuredContent.receiptSchema).toBeDefined();
|
|
408
|
-
expect(result.isError).toBeUndefined();
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
it('returns error on API failure', async () => {
|
|
412
|
-
setup();
|
|
413
|
-
client.schemas.getBlankTemplate.mockRejectedValueOnce(new Error('Service unavailable'));
|
|
414
|
-
const handler = handlers.get('get_blank_schema_template')!;
|
|
415
|
-
const result = await handler({});
|
|
416
|
-
|
|
417
|
-
expect(result.isError).toBe(true);
|
|
418
|
-
expect(result.content[0].text).toContain('Service unavailable');
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
// --- check_schema_compatibility ---
|
|
423
|
-
describe('check_schema_compatibility', () => {
|
|
424
|
-
it('returns compatibility result on success', async () => {
|
|
425
|
-
setup();
|
|
426
|
-
const handler = handlers.get('check_schema_compatibility')!;
|
|
427
|
-
const result = await handler({
|
|
428
|
-
contractType: 'ACH-PROC-v1',
|
|
429
|
-
mandateSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
430
|
-
receiptSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
expect(client.schemas.checkCompatibility).toHaveBeenCalledWith(
|
|
434
|
-
'ACH-PROC-v1',
|
|
435
|
-
{
|
|
436
|
-
mandateSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
437
|
-
receiptSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
438
|
-
},
|
|
439
|
-
);
|
|
440
|
-
expect(result.content[0].text).toBeDefined();
|
|
441
|
-
expect(result.structuredContent.compatible).toBe(true);
|
|
442
|
-
expect(result.isError).toBeUndefined();
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('returns incompatible result', async () => {
|
|
446
|
-
setup();
|
|
447
|
-
client.schemas.checkCompatibility.mockResolvedValueOnce({
|
|
448
|
-
compatible: false,
|
|
449
|
-
mode: 'FULL',
|
|
450
|
-
issues: [{ code: 'FIELD_REMOVED', message: 'Required field "quantity" was removed', path: '$.mandateSchema.properties.quantity' }],
|
|
451
|
-
});
|
|
452
|
-
const handler = handlers.get('check_schema_compatibility')!;
|
|
453
|
-
const result = await handler({
|
|
454
|
-
contractType: 'ACH-PROC-v1',
|
|
455
|
-
mandateSchema: { type: 'object', properties: {} },
|
|
456
|
-
receiptSchema: { type: 'object', properties: {} },
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
expect(result.structuredContent.compatible).toBe(false);
|
|
460
|
-
expect(result.structuredContent.issues).toHaveLength(1);
|
|
461
|
-
expect(result.isError).toBeUndefined();
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('returns error on API failure', async () => {
|
|
465
|
-
setup();
|
|
466
|
-
client.schemas.checkCompatibility.mockRejectedValueOnce(new Error('Rate limited'));
|
|
467
|
-
const handler = handlers.get('check_schema_compatibility')!;
|
|
468
|
-
const result = await handler({
|
|
469
|
-
contractType: 'ACH-PROC-v1',
|
|
470
|
-
mandateSchema: {},
|
|
471
|
-
receiptSchema: {},
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
expect(result.isError).toBe(true);
|
|
475
|
-
expect(result.content[0].text).toContain('Rate limited');
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
// --- get_schema_version ---
|
|
480
|
-
describe('get_schema_version', () => {
|
|
481
|
-
it('returns specific version on success', async () => {
|
|
482
|
-
setup();
|
|
483
|
-
const handler = handlers.get('get_schema_version')!;
|
|
484
|
-
const result = await handler({ contractType: 'ACH-PROC-v1', version: 1 });
|
|
485
|
-
|
|
486
|
-
expect(client.schemas.getVersion).toHaveBeenCalledWith('ACH-PROC-v1', 1);
|
|
487
|
-
expect(result.content[0].text).toBeDefined();
|
|
488
|
-
expect(result.structuredContent.id).toBe('sv-1');
|
|
489
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
490
|
-
expect(result.structuredContent.version).toBe(1);
|
|
491
|
-
expect(result.structuredContent.status).toBe('ACTIVE');
|
|
492
|
-
expect(result.isError).toBeUndefined();
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('returns error on API failure', async () => {
|
|
496
|
-
setup();
|
|
497
|
-
client.schemas.getVersion.mockRejectedValueOnce(new Error('Version not found'));
|
|
498
|
-
const handler = handlers.get('get_schema_version')!;
|
|
499
|
-
const result = await handler({ contractType: 'ACH-PROC-v1', version: 99 });
|
|
500
|
-
|
|
501
|
-
expect(result.isError).toBe(true);
|
|
502
|
-
expect(result.content[0].text).toContain('Version not found');
|
|
503
|
-
});
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
// --- get_schema_rules ---
|
|
507
|
-
describe('get_schema_rules', () => {
|
|
508
|
-
it('returns rules for contract type on success', async () => {
|
|
509
|
-
setup();
|
|
510
|
-
const handler = handlers.get('get_schema_rules')!;
|
|
511
|
-
const result = await handler({ contractType: 'ACH-PROC-v1' });
|
|
512
|
-
|
|
513
|
-
expect(client.schemas.getRules).toHaveBeenCalledWith('ACH-PROC-v1');
|
|
514
|
-
expect(result.content[0].text).toBeDefined();
|
|
515
|
-
expect(result.structuredContent.contractType).toBe('ACH-PROC-v1');
|
|
516
|
-
expect(result.structuredContent.syncRuleIds).toEqual(['quantity-check', 'cost-ceiling']);
|
|
517
|
-
expect(result.structuredContent.asyncRuleIds).toEqual(['delivery-confirmation']);
|
|
518
|
-
expect(result.isError).toBeUndefined();
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
it('returns error on API failure', async () => {
|
|
522
|
-
setup();
|
|
523
|
-
client.schemas.getRules.mockRejectedValueOnce(new Error('Contract type not found'));
|
|
524
|
-
const handler = handlers.get('get_schema_rules')!;
|
|
525
|
-
const result = await handler({ contractType: 'ACH-FAKE-v1' });
|
|
526
|
-
|
|
527
|
-
expect(result.isError).toBe(true);
|
|
528
|
-
expect(result.content[0].text).toContain('Contract type not found');
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
});
|