@agledger/mcp-server 1.4.1 → 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.
Files changed (111) hide show
  1. package/dist/errors.d.ts +6 -0
  2. package/dist/errors.d.ts.map +1 -1
  3. package/dist/errors.js +8 -0
  4. package/dist/errors.js.map +1 -1
  5. package/dist/server.d.ts +4 -0
  6. package/dist/server.d.ts.map +1 -1
  7. package/dist/server.js +72 -75
  8. package/dist/server.js.map +1 -1
  9. package/dist/tool-scopes.d.ts.map +1 -1
  10. package/dist/tool-scopes.js +6 -2
  11. package/dist/tool-scopes.js.map +1 -1
  12. package/dist/tools/a2a.js +15 -15
  13. package/dist/tools/a2a.js.map +1 -1
  14. package/dist/tools/agent-mandates.js +10 -10
  15. package/dist/tools/agent-mandates.js.map +1 -1
  16. package/dist/tools/agents-refs.d.ts.map +1 -1
  17. package/dist/tools/agents-refs.js +10 -9
  18. package/dist/tools/agents-refs.js.map +1 -1
  19. package/dist/tools/capabilities.js +3 -3
  20. package/dist/tools/capabilities.js.map +1 -1
  21. package/dist/tools/compliance.d.ts.map +1 -1
  22. package/dist/tools/compliance.js +29 -4
  23. package/dist/tools/compliance.js.map +1 -1
  24. package/dist/tools/dashboard.d.ts.map +1 -1
  25. package/dist/tools/dashboard.js +29 -4
  26. package/dist/tools/dashboard.js.map +1 -1
  27. package/dist/tools/disputes.d.ts.map +1 -1
  28. package/dist/tools/disputes.js +10 -5
  29. package/dist/tools/disputes.js.map +1 -1
  30. package/dist/tools/enterprises.d.ts.map +1 -1
  31. package/dist/tools/enterprises.js +30 -6
  32. package/dist/tools/enterprises.js.map +1 -1
  33. package/dist/tools/events.js +2 -2
  34. package/dist/tools/events.js.map +1 -1
  35. package/dist/tools/federation-admin.js +25 -25
  36. package/dist/tools/federation-admin.js.map +1 -1
  37. package/dist/tools/federation.js +21 -21
  38. package/dist/tools/federation.js.map +1 -1
  39. package/dist/tools/health.js +2 -2
  40. package/dist/tools/health.js.map +1 -1
  41. package/dist/tools/mandates.d.ts.map +1 -1
  42. package/dist/tools/mandates.js +25 -14
  43. package/dist/tools/mandates.js.map +1 -1
  44. package/dist/tools/openclaw.js +6 -6
  45. package/dist/tools/openclaw.js.map +1 -1
  46. package/dist/tools/receipts.d.ts.map +1 -1
  47. package/dist/tools/receipts.js +5 -6
  48. package/dist/tools/receipts.js.map +1 -1
  49. package/dist/tools/reputation.d.ts.map +1 -1
  50. package/dist/tools/reputation.js +25 -4
  51. package/dist/tools/reputation.js.map +1 -1
  52. package/dist/tools/schemas.d.ts.map +1 -1
  53. package/dist/tools/schemas.js +71 -26
  54. package/dist/tools/schemas.js.map +1 -1
  55. package/dist/tools/verification-keys.js +2 -2
  56. package/dist/tools/verification-keys.js.map +1 -1
  57. package/dist/tools/verification.js +3 -3
  58. package/dist/tools/verification.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/errors.ts +9 -0
  61. package/src/server.ts +76 -68
  62. package/src/tool-scopes.ts +7 -3
  63. package/src/tools/a2a.ts +15 -15
  64. package/src/tools/agent-mandates.ts +10 -10
  65. package/src/tools/agents-refs.ts +10 -9
  66. package/src/tools/capabilities.ts +3 -3
  67. package/src/tools/compliance.ts +29 -4
  68. package/src/tools/dashboard.ts +29 -4
  69. package/src/tools/disputes.ts +10 -5
  70. package/src/tools/enterprises.ts +30 -6
  71. package/src/tools/events.ts +2 -2
  72. package/src/tools/federation-admin.ts +25 -25
  73. package/src/tools/federation.ts +21 -21
  74. package/src/tools/health.ts +2 -2
  75. package/src/tools/mandates.ts +25 -14
  76. package/src/tools/openclaw.ts +6 -6
  77. package/src/tools/receipts.ts +5 -6
  78. package/src/tools/reputation.ts +26 -4
  79. package/src/tools/schemas.ts +72 -26
  80. package/src/tools/verification-keys.ts +2 -2
  81. package/src/tools/verification.ts +3 -3
  82. package/tests/conformance.test.ts +219 -0
  83. package/tests/conformance.ts +75 -0
  84. package/tests/{code-mode-manifest.test.ts → drift/code-mode-manifest.test.ts} +2 -2
  85. package/tests/harness.ts +55 -0
  86. package/tests/integration/output-schema-validation.test.ts +167 -0
  87. package/tests/mock-client.ts +71 -0
  88. package/tests/profiles.test.ts +135 -0
  89. package/tests/resources/contract-types.test.ts +82 -0
  90. package/tests/tools/a2a.test.ts +241 -0
  91. package/tests/tools/agent-mandates.test.ts +206 -0
  92. package/tests/tools/agents-refs.test.ts +199 -0
  93. package/tests/tools/capabilities.test.ts +86 -0
  94. package/tests/tools/code-mode.test.ts +168 -0
  95. package/tests/tools/compliance.test.ts +131 -0
  96. package/tests/tools/dashboard.test.ts +120 -0
  97. package/tests/tools/disputes.test.ts +131 -0
  98. package/tests/tools/enterprises.test.ts +181 -0
  99. package/tests/tools/events.test.ts +61 -0
  100. package/tests/tools/federation-admin.test.ts +509 -0
  101. package/tests/tools/federation.test.ts +556 -0
  102. package/tests/tools/health.test.ts +67 -0
  103. package/tests/tools/mandates.test.ts +155 -0
  104. package/tests/tools/openclaw.test.ts +160 -0
  105. package/tests/tools/receipts.test.ts +170 -0
  106. package/tests/tools/reputation.test.ts +117 -0
  107. package/tests/tools/schemas.test.ts +397 -0
  108. package/tests/tools/verification-keys.test.ts +62 -0
  109. package/tests/tools/verification.test.ts +74 -0
  110. package/tests/enterprises.test.ts +0 -96
  111. package/tests/schemas.test.ts +0 -531
@@ -0,0 +1,556 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerFederationTools } from '../../src/tools/federation.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ const EXPECTED_TOOLS = [
7
+ 'federation_broadcast_revocations',
8
+ 'federation_catch_up',
9
+ 'federation_confirm_schema_publish',
10
+ 'federation_contribute_reputation',
11
+ 'federation_get_agent_reputation',
12
+ 'federation_get_contract_type',
13
+ 'federation_get_mandate_criteria',
14
+ 'federation_heartbeat',
15
+ 'federation_list_agents',
16
+ 'federation_list_contract_types',
17
+ 'federation_publish_schema',
18
+ 'federation_register',
19
+ 'federation_register_agent',
20
+ 'federation_relay_signal',
21
+ 'federation_revoke',
22
+ 'federation_rotate_key',
23
+ 'federation_stream',
24
+ 'federation_submit_mandate_criteria',
25
+ 'federation_submit_transition',
26
+ 'federation_sync_agent_directory',
27
+ ];
28
+
29
+ describe('federation tools', () => {
30
+ let harness: TestHarness;
31
+
32
+ beforeAll(async () => {
33
+ harness = await createTestHarness({
34
+ registerFns: [registerFederationTools],
35
+ mockOverrides: {
36
+ federation: {
37
+ register: vi.fn().mockResolvedValue({
38
+ gatewayId: 'gw-1',
39
+ organizationId: 'org-1',
40
+ status: 'active',
41
+ bearerToken: 'tok-abc',
42
+ bearerTokenExpiresAt: '2026-05-01T00:00:00Z',
43
+ }),
44
+ heartbeat: vi.fn().mockResolvedValue({
45
+ gatewayId: 'gw-1',
46
+ token: 'tok-refreshed',
47
+ expiresAt: '2026-05-01T00:00:00Z',
48
+ bearerTokenExpiresAt: '2026-05-01T00:00:00Z',
49
+ revocations: [],
50
+ }),
51
+ registerAgent: vi.fn().mockResolvedValue({
52
+ agentId: 'agent-1',
53
+ registered: true,
54
+ contractTypes: ['ACH-PROC-v1'],
55
+ }),
56
+ listAgents: vi.fn().mockResolvedValue({
57
+ data: [{ agentId: 'agent-1', contractTypes: ['ACH-PROC-v1'] }],
58
+ hasMore: false,
59
+ agents: [{ agentId: 'agent-1', gatewayId: 'gw-1', contractTypes: ['ACH-PROC-v1'], displayName: 'Agent 1' }],
60
+ }),
61
+ submitStateTransition: vi.fn().mockResolvedValue({
62
+ mandateId: 'mnd-1',
63
+ state: 'ACTIVE',
64
+ seq: 1,
65
+ hubState: 'ACTIVE',
66
+ subStatus: 'none',
67
+ hubTimestamp: '2026-04-13T00:00:00Z',
68
+ }),
69
+ relaySignal: vi.fn().mockResolvedValue({
70
+ mandateId: 'mnd-1',
71
+ signal: 'SETTLE',
72
+ signalSeq: 1,
73
+ relayed: true,
74
+ targetGatewayId: 'gw-2',
75
+ hubTimestamp: '2026-04-13T00:00:00Z',
76
+ }),
77
+ rotateKey: vi.fn().mockResolvedValue({
78
+ gatewayId: 'gw-1',
79
+ rotated: true,
80
+ rotatedAt: '2026-04-13T00:00:00Z',
81
+ }),
82
+ revoke: vi.fn().mockResolvedValue({
83
+ gatewayId: 'gw-1',
84
+ reason: 'key_compromise',
85
+ revoked: true,
86
+ revokedAt: '2026-04-13T00:00:00Z',
87
+ }),
88
+ catchUp: vi.fn().mockResolvedValue({
89
+ data: [{ mandateId: 'mnd-1', state: 'ACTIVE', seq: 1 }],
90
+ hasMore: false,
91
+ nextPosition: 1,
92
+ }),
93
+ stream: vi.fn().mockResolvedValue({
94
+ events: [{ type: 'transition', timestamp: '2026-04-13T00:00:00Z' }],
95
+ }),
96
+ publishSchema: vi.fn().mockResolvedValue({
97
+ contractType: 'ACH-PROC-v1',
98
+ status: 'pending',
99
+ confirmationToken: 'tok-confirm',
100
+ }),
101
+ confirmSchemaPublish: vi.fn().mockResolvedValue({
102
+ contractType: 'ACH-PROC-v1',
103
+ confirmed: true,
104
+ }),
105
+ listContractTypes: vi.fn().mockResolvedValue([
106
+ { contractType: 'ACH-PROC-v1', version: '1.0', status: 'active' },
107
+ ]),
108
+ getContractType: vi.fn().mockResolvedValue({
109
+ contractType: 'ACH-PROC-v1',
110
+ version: '1.0',
111
+ status: 'active',
112
+ schema: {},
113
+ }),
114
+ getMandateCriteria: vi.fn().mockResolvedValue({
115
+ mandateId: 'mnd-1',
116
+ submittedBy: 'gw-1',
117
+ criteria: { item: 'widget' },
118
+ }),
119
+ submitMandateCriteria: vi.fn().mockResolvedValue({
120
+ mandateId: 'mnd-1',
121
+ submittedBy: 'gw-1',
122
+ submittedAt: '2026-04-13T00:00:00Z',
123
+ status: 'submitted',
124
+ }),
125
+ contributeReputation: vi.fn().mockResolvedValue({
126
+ agentId: 'agent-1',
127
+ recorded: true,
128
+ }),
129
+ getAgentReputation: vi.fn().mockResolvedValue({
130
+ agentId: 'agent-1',
131
+ overallScore: 95,
132
+ score: 95,
133
+ totalMandates: 20,
134
+ contributions: 12,
135
+ }),
136
+ broadcastRevocations: vi.fn().mockResolvedValue({
137
+ gatewayId: 'gw-1',
138
+ broadcast: true,
139
+ peersNotified: 3,
140
+ }),
141
+ syncAgentDirectory: vi.fn().mockResolvedValue({
142
+ synced: 2,
143
+ }),
144
+ },
145
+ },
146
+ });
147
+ });
148
+
149
+ afterAll(async () => { await harness.cleanup(); });
150
+
151
+ it('registers exactly 20 tools', async () => {
152
+ const { tools } = await harness.client.listTools();
153
+ expect(tools.map((t: any) => t.name).sort()).toEqual(EXPECTED_TOOLS);
154
+ });
155
+
156
+ // --- Top 5 tools: happy path + error ---
157
+
158
+ describe('federation_register', () => {
159
+ it('registers a gateway', async () => {
160
+ const result = await harness.client.callTool({
161
+ name: 'federation_register',
162
+ arguments: {
163
+ registrationToken: 'tok-123',
164
+ organizationId: 'org-1',
165
+ signingPublicKey: 'key-sign',
166
+ encryptionPublicKey: 'key-enc',
167
+ endpointUrl: 'https://gw.example.com',
168
+ revocationSecret: 'secret',
169
+ timestamp: '2026-04-13T00:00:00Z',
170
+ nonce: 'nonce-1',
171
+ signature: 'sig-1',
172
+ },
173
+ });
174
+ assertSuccessResult(result as any);
175
+ expect((result as any).content[0].text).toContain('gw-1');
176
+ expect((result as any).content[0].text).toContain('registered');
177
+ });
178
+
179
+ it('returns error on failure', async () => {
180
+ (harness.mockSdk.federation as any).register.mockRejectedValueOnce(new Error('Token expired'));
181
+ const result = await harness.client.callTool({
182
+ name: 'federation_register',
183
+ arguments: {
184
+ registrationToken: 'bad-tok',
185
+ organizationId: 'org-1',
186
+ signingPublicKey: 'key-sign',
187
+ encryptionPublicKey: 'key-enc',
188
+ endpointUrl: 'https://gw.example.com',
189
+ revocationSecret: 'secret',
190
+ timestamp: '2026-04-13T00:00:00Z',
191
+ nonce: 'nonce-1',
192
+ signature: 'sig-1',
193
+ },
194
+ });
195
+ assertErrorResult(result as any);
196
+ });
197
+ });
198
+
199
+ describe('federation_heartbeat', () => {
200
+ it('sends heartbeat successfully', async () => {
201
+ const result = await harness.client.callTool({
202
+ name: 'federation_heartbeat',
203
+ arguments: {
204
+ gatewayId: 'gw-1',
205
+ agentCount: 5,
206
+ mandateCount: 10,
207
+ timestamp: '2026-04-13T00:00:00Z',
208
+ },
209
+ });
210
+ assertSuccessResult(result as any);
211
+ expect((result as any).content[0].text).toContain('Heartbeat accepted');
212
+ expect((result as any).content[0].text).toContain('gw-1');
213
+ });
214
+
215
+ it('returns error on failure', async () => {
216
+ (harness.mockSdk.federation as any).heartbeat.mockRejectedValueOnce(new Error('Gateway not found'));
217
+ const result = await harness.client.callTool({
218
+ name: 'federation_heartbeat',
219
+ arguments: {
220
+ gatewayId: 'bad-gw',
221
+ agentCount: 0,
222
+ mandateCount: 0,
223
+ timestamp: '2026-04-13T00:00:00Z',
224
+ },
225
+ });
226
+ assertErrorResult(result as any);
227
+ });
228
+ });
229
+
230
+ describe('federation_submit_transition', () => {
231
+ it('submits a state transition', async () => {
232
+ const result = await harness.client.callTool({
233
+ name: 'federation_submit_transition',
234
+ arguments: {
235
+ mandateId: 'mnd-1',
236
+ gatewayId: 'gw-1',
237
+ state: 'ACTIVE',
238
+ contractType: 'ACH-PROC-v1',
239
+ criteriaHash: 'hash-abc',
240
+ role: 'principal',
241
+ seq: 1,
242
+ idempotencyKey: 'idem-1',
243
+ timestamp: '2026-04-13T00:00:00Z',
244
+ nonce: 'nonce-1',
245
+ signature: 'sig-1',
246
+ },
247
+ });
248
+ assertSuccessResult(result as any);
249
+ expect((result as any).content[0].text).toContain('Transition accepted');
250
+ expect((result as any).content[0].text).toContain('ACTIVE');
251
+ });
252
+
253
+ it('returns error on failure', async () => {
254
+ (harness.mockSdk.federation as any).submitStateTransition.mockRejectedValueOnce(new Error('Sequence conflict'));
255
+ const result = await harness.client.callTool({
256
+ name: 'federation_submit_transition',
257
+ arguments: {
258
+ mandateId: 'mnd-1',
259
+ gatewayId: 'gw-1',
260
+ state: 'ACTIVE',
261
+ contractType: 'ACH-PROC-v1',
262
+ criteriaHash: 'hash-abc',
263
+ role: 'principal',
264
+ seq: 99,
265
+ idempotencyKey: 'idem-bad',
266
+ timestamp: '2026-04-13T00:00:00Z',
267
+ nonce: 'nonce-1',
268
+ signature: 'sig-1',
269
+ },
270
+ });
271
+ assertErrorResult(result as any);
272
+ });
273
+ });
274
+
275
+ describe('federation_relay_signal', () => {
276
+ it('relays a settlement signal', async () => {
277
+ const result = await harness.client.callTool({
278
+ name: 'federation_relay_signal',
279
+ arguments: {
280
+ mandateId: 'mnd-1',
281
+ signal: 'SETTLE',
282
+ outcomeHash: 'hash-out',
283
+ signalSeq: 1,
284
+ validUntil: '2026-05-01T00:00:00Z',
285
+ performerGatewayId: 'gw-2',
286
+ timestamp: '2026-04-13T00:00:00Z',
287
+ nonce: 'nonce-1',
288
+ performerSignature: 'sig-perf',
289
+ },
290
+ });
291
+ assertSuccessResult(result as any);
292
+ expect((result as any).content[0].text).toContain('Signal relayed');
293
+ expect((result as any).content[0].text).toContain('gw-2');
294
+ });
295
+
296
+ it('returns error on failure', async () => {
297
+ (harness.mockSdk.federation as any).relaySignal.mockRejectedValueOnce(new Error('Invalid signal'));
298
+ const result = await harness.client.callTool({
299
+ name: 'federation_relay_signal',
300
+ arguments: {
301
+ mandateId: 'mnd-1',
302
+ signal: 'SETTLE',
303
+ outcomeHash: 'hash-out',
304
+ signalSeq: 1,
305
+ validUntil: '2026-05-01T00:00:00Z',
306
+ performerGatewayId: 'gw-2',
307
+ timestamp: '2026-04-13T00:00:00Z',
308
+ nonce: 'nonce-1',
309
+ performerSignature: 'sig-perf',
310
+ },
311
+ });
312
+ assertErrorResult(result as any);
313
+ });
314
+ });
315
+
316
+ describe('federation_register_agent', () => {
317
+ it('registers a federated agent', async () => {
318
+ const result = await harness.client.callTool({
319
+ name: 'federation_register_agent',
320
+ arguments: {
321
+ agentId: 'agent-1',
322
+ contractTypes: ['ACH-PROC-v1'],
323
+ displayName: 'Test Agent',
324
+ },
325
+ });
326
+ assertSuccessResult(result as any);
327
+ expect((result as any).content[0].text).toContain('agent-1');
328
+ expect((result as any).content[0].text).toContain('registered');
329
+ });
330
+
331
+ it('returns error on failure', async () => {
332
+ (harness.mockSdk.federation as any).registerAgent.mockRejectedValueOnce(new Error('Agent already registered'));
333
+ const result = await harness.client.callTool({
334
+ name: 'federation_register_agent',
335
+ arguments: {
336
+ agentId: 'agent-dup',
337
+ contractTypes: ['ACH-PROC-v1'],
338
+ },
339
+ });
340
+ assertErrorResult(result as any);
341
+ });
342
+ });
343
+
344
+ // --- Remaining tools: happy path only ---
345
+
346
+ describe('federation_list_agents', () => {
347
+ it('lists federated agents', async () => {
348
+ const result = await harness.client.callTool({
349
+ name: 'federation_list_agents',
350
+ arguments: {},
351
+ });
352
+ assertSuccessResult(result as any);
353
+ expect((result as any).content[0].text).toContain('1 federated agent');
354
+ });
355
+ });
356
+
357
+ describe('federation_rotate_key', () => {
358
+ it('rotates gateway keys', async () => {
359
+ const result = await harness.client.callTool({
360
+ name: 'federation_rotate_key',
361
+ arguments: {
362
+ gatewayId: 'gw-1',
363
+ newSigningPublicKey: 'new-sign-key',
364
+ newEncryptionPublicKey: 'new-enc-key',
365
+ signatureOldKey: 'sig-old',
366
+ signatureNewKey: 'sig-new',
367
+ timestamp: '2026-04-13T00:00:00Z',
368
+ nonce: 'nonce-rot',
369
+ },
370
+ });
371
+ assertSuccessResult(result as any);
372
+ expect((result as any).content[0].text).toContain('Keys rotated');
373
+ expect((harness.mockSdk.federation as any).rotateKey).toHaveBeenCalledWith('gw-1', expect.objectContaining({
374
+ newSigningPublicKey: 'new-sign-key',
375
+ }));
376
+ });
377
+ });
378
+
379
+ describe('federation_revoke', () => {
380
+ it('revokes a gateway', async () => {
381
+ const result = await harness.client.callTool({
382
+ name: 'federation_revoke',
383
+ arguments: {
384
+ gatewayId: 'gw-1',
385
+ revocationSecret: 'secret',
386
+ reason: 'key_compromise',
387
+ },
388
+ });
389
+ assertSuccessResult(result as any);
390
+ expect((result as any).content[0].text).toContain('revoked');
391
+ expect((result as any).content[0].text).toContain('permanent');
392
+ });
393
+ });
394
+
395
+ describe('federation_catch_up', () => {
396
+ it('catches up missed transitions', async () => {
397
+ const result = await harness.client.callTool({
398
+ name: 'federation_catch_up',
399
+ arguments: { sincePosition: 0 },
400
+ });
401
+ assertSuccessResult(result as any);
402
+ expect((result as any).content[0].text).toContain('1 entry');
403
+ expect((result as any).content[0].text).toContain('Fully caught up');
404
+ });
405
+ });
406
+
407
+ describe('federation_stream', () => {
408
+ it('streams federation events', async () => {
409
+ const result = await harness.client.callTool({
410
+ name: 'federation_stream',
411
+ arguments: { since: '2026-04-12T00:00:00Z' },
412
+ });
413
+ assertSuccessResult(result as any);
414
+ expect((result as any).content[0].text).toContain('1 federation event');
415
+ });
416
+ });
417
+
418
+ describe('federation_publish_schema', () => {
419
+ it('publishes a schema', async () => {
420
+ const result = await harness.client.callTool({
421
+ name: 'federation_publish_schema',
422
+ arguments: {
423
+ contractType: 'ACH-PROC-v1',
424
+ schema: { type: 'object' },
425
+ },
426
+ });
427
+ assertSuccessResult(result as any);
428
+ expect((result as any).content[0].text).toContain('ACH-PROC-v1');
429
+ expect((result as any).content[0].text).toContain('pending');
430
+ });
431
+ });
432
+
433
+ describe('federation_confirm_schema_publish', () => {
434
+ it('confirms a schema publication', async () => {
435
+ const result = await harness.client.callTool({
436
+ name: 'federation_confirm_schema_publish',
437
+ arguments: {
438
+ contractType: 'ACH-PROC-v1',
439
+ confirmationToken: 'tok-confirm',
440
+ },
441
+ });
442
+ assertSuccessResult(result as any);
443
+ expect((result as any).content[0].text).toContain('confirmed');
444
+ });
445
+ });
446
+
447
+ describe('federation_list_contract_types', () => {
448
+ it('lists contract types', async () => {
449
+ const result = await harness.client.callTool({
450
+ name: 'federation_list_contract_types',
451
+ arguments: {},
452
+ });
453
+ assertSuccessResult(result as any);
454
+ expect((result as any).content[0].text).toContain('1 federated contract type');
455
+ });
456
+ });
457
+
458
+ describe('federation_get_contract_type', () => {
459
+ it('gets a contract type', async () => {
460
+ const result = await harness.client.callTool({
461
+ name: 'federation_get_contract_type',
462
+ arguments: { contractType: 'ACH-PROC-v1' },
463
+ });
464
+ assertSuccessResult(result as any);
465
+ expect((result as any).content[0].text).toContain('ACH-PROC-v1');
466
+ expect((result as any).content[0].text).toContain('active');
467
+ });
468
+ });
469
+
470
+ describe('federation_get_mandate_criteria', () => {
471
+ it('gets mandate criteria', async () => {
472
+ const result = await harness.client.callTool({
473
+ name: 'federation_get_mandate_criteria',
474
+ arguments: { mandateId: 'mnd-1' },
475
+ });
476
+ assertSuccessResult(result as any);
477
+ expect((result as any).content[0].text).toContain('mnd-1');
478
+ expect((result as any).content[0].text).toContain('gw-1');
479
+ });
480
+ });
481
+
482
+ describe('federation_submit_mandate_criteria', () => {
483
+ it('submits mandate criteria', async () => {
484
+ const result = await harness.client.callTool({
485
+ name: 'federation_submit_mandate_criteria',
486
+ arguments: {
487
+ mandateId: 'mnd-1',
488
+ criteria: { item: 'widget', quantity: 10 },
489
+ },
490
+ });
491
+ assertSuccessResult(result as any);
492
+ expect((result as any).content[0].text).toContain('Criteria submitted');
493
+ expect((result as any).content[0].text).toContain('mnd-1');
494
+ });
495
+ });
496
+
497
+ describe('federation_contribute_reputation', () => {
498
+ it('contributes reputation data', async () => {
499
+ const result = await harness.client.callTool({
500
+ name: 'federation_contribute_reputation',
501
+ arguments: {
502
+ agentId: 'agent-1',
503
+ contractType: 'ACH-PROC-v1',
504
+ outcome: 'PASS',
505
+ },
506
+ });
507
+ assertSuccessResult(result as any);
508
+ expect((result as any).content[0].text).toContain('agent-1');
509
+ expect((result as any).content[0].text).toContain('PASS');
510
+ });
511
+ });
512
+
513
+ describe('federation_get_agent_reputation', () => {
514
+ it('gets agent reputation', async () => {
515
+ const result = await harness.client.callTool({
516
+ name: 'federation_get_agent_reputation',
517
+ arguments: { agentId: 'agent-1' },
518
+ });
519
+ assertSuccessResult(result as any);
520
+ expect((result as any).content[0].text).toContain('agent-1');
521
+ expect((result as any).content[0].text).toContain('95');
522
+ });
523
+ });
524
+
525
+ describe('federation_broadcast_revocations', () => {
526
+ it('broadcasts revocations', async () => {
527
+ const result = await harness.client.callTool({
528
+ name: 'federation_broadcast_revocations',
529
+ arguments: {
530
+ gatewayId: 'gw-1',
531
+ reason: 'compromised',
532
+ revokedAt: '2026-04-13T00:00:00Z',
533
+ },
534
+ });
535
+ assertSuccessResult(result as any);
536
+ expect((result as any).content[0].text).toContain('gw-1');
537
+ expect((result as any).content[0].text).toContain('broadcast');
538
+ });
539
+ });
540
+
541
+ describe('federation_sync_agent_directory', () => {
542
+ it('syncs agent directory', async () => {
543
+ const result = await harness.client.callTool({
544
+ name: 'federation_sync_agent_directory',
545
+ arguments: {
546
+ agents: [
547
+ { agentId: 'agent-1', contractTypes: ['ACH-PROC-v1'] },
548
+ { agentId: 'agent-2', contractTypes: ['ACH-DLVR-v1'] },
549
+ ],
550
+ },
551
+ });
552
+ assertSuccessResult(result as any);
553
+ expect((result as any).content[0].text).toContain('2 agent(s) pushed');
554
+ });
555
+ });
556
+ });
@@ -0,0 +1,67 @@
1
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
2
+ import { registerHealthTools } from '../../src/tools/health.js';
3
+ import { createTestHarness, type TestHarness } from '../harness.js';
4
+ import { assertOutputSchemaValid, assertToolMetadata, assertErrorResult, assertSuccessResult } from '../conformance.js';
5
+
6
+ describe('health tools', () => {
7
+ let harness: TestHarness;
8
+
9
+ beforeAll(async () => {
10
+ harness = await createTestHarness({
11
+ registerFns: [registerHealthTools],
12
+ mockOverrides: {
13
+ health: {
14
+ check: vi.fn().mockResolvedValue({
15
+ status: 'ok',
16
+ version: '0.15.6',
17
+ uptime: 12345,
18
+ database: 'connected',
19
+ timestamp: '2026-04-13T00:00:00Z',
20
+ }),
21
+ },
22
+ },
23
+ });
24
+ });
25
+
26
+ afterAll(async () => {
27
+ await harness.cleanup();
28
+ });
29
+
30
+ describe('tool registration', () => {
31
+ it('registers exactly 1 tool: check_api_health', async () => {
32
+ const { tools } = await harness.client.listTools();
33
+ expect(tools.map(t => t.name)).toEqual(['check_api_health']);
34
+ });
35
+
36
+ it('has valid outputSchema', async () => {
37
+ const { tools } = await harness.client.listTools();
38
+ assertOutputSchemaValid(tools[0]);
39
+ });
40
+
41
+ it('has valid metadata', async () => {
42
+ const { tools } = await harness.client.listTools();
43
+ assertToolMetadata(tools[0]);
44
+ });
45
+ });
46
+
47
+ describe('check_api_health', () => {
48
+ it('returns health status on success', async () => {
49
+ const result = await harness.client.callTool({ name: 'check_api_health', arguments: {} });
50
+ assertSuccessResult(result as any);
51
+ const content = (result as any).content[0].text;
52
+ expect(content).toContain('status=ok');
53
+ expect(content).toContain('version=0.15.6');
54
+ expect(content).toContain('db=connected');
55
+
56
+ expect((harness.mockSdk.health as any).check).toHaveBeenCalledOnce();
57
+ });
58
+
59
+ it('returns error when API is unreachable', async () => {
60
+ (harness.mockSdk.health as any).check.mockRejectedValueOnce(new Error('Connection refused'));
61
+
62
+ const result = await harness.client.callTool({ name: 'check_api_health', arguments: {} });
63
+ assertErrorResult(result as any);
64
+ expect((result as any).content[0].text).toContain('Connection refused');
65
+ });
66
+ });
67
+ });