@agledger/mcp-server 1.4.3 → 1.5.0
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/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +0 -3
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +20 -220
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +10 -74
- 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 +9 -61
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +2 -14
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/code-mode.d.ts.map +1 -1
- package/dist/tools/code-mode.js +4 -35
- package/dist/tools/code-mode.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +3 -37
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +3 -37
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +4 -41
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +6 -62
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +1 -19
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +24 -256
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +20 -197
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +1 -13
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +10 -93
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +5 -32
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +4 -94
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +3 -33
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +16 -186
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts.map +1 -1
- package/dist/tools/verification-keys.js +1 -22
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +2 -27
- package/dist/tools/verification.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -3
- package/src/server.ts +3 -5
- package/src/tool-scopes.ts +0 -4
- package/src/tools/a2a.ts +20 -233
- package/src/tools/agent-mandates.ts +10 -76
- package/src/tools/agents-refs.ts +9 -65
- package/src/tools/capabilities.ts +2 -15
- package/src/tools/compliance.ts +3 -37
- package/src/tools/dashboard.ts +3 -37
- package/src/tools/disputes.ts +4 -42
- package/src/tools/enterprises.ts +6 -62
- package/src/tools/events.ts +1 -20
- package/src/tools/federation-admin.ts +24 -281
- package/src/tools/federation.ts +20 -217
- package/src/tools/health.ts +1 -14
- package/src/tools/mandates.ts +10 -95
- package/src/tools/openclaw.ts +5 -51
- package/src/tools/receipts.ts +4 -95
- package/src/tools/reputation.ts +3 -34
- package/src/tools/schemas.ts +16 -194
- package/src/tools/verification-keys.ts +1 -24
- package/src/tools/verification.ts +2 -29
- package/tests/conformance.test.ts +4 -26
- package/tests/conformance.ts +3 -13
- package/tests/profiles.test.ts +2 -17
- package/tests/tools/a2a.test.ts +0 -28
- package/tests/tools/agent-mandates.test.ts +0 -10
- package/tests/tools/agents-refs.test.ts +0 -9
- package/tests/tools/capabilities.test.ts +0 -6
- package/tests/tools/compliance.test.ts +0 -8
- package/tests/tools/dashboard.test.ts +0 -9
- package/tests/tools/disputes.test.ts +0 -8
- package/tests/tools/enterprises.test.ts +0 -10
- package/tests/tools/events.test.ts +0 -5
- package/tests/tools/federation-admin.test.ts +0 -41
- package/tests/tools/federation.test.ts +0 -34
- package/tests/tools/health.test.ts +1 -12
- package/tests/tools/mandates.test.ts +0 -12
- package/tests/tools/openclaw.test.ts +0 -12
- package/tests/tools/receipts.test.ts +1 -14
- package/tests/tools/reputation.test.ts +0 -9
- package/tests/tools/schemas.test.ts +0 -23
- package/tests/tools/verification-keys.test.ts +0 -6
- package/tests/tools/verification.test.ts +1 -11
- package/src/tools/code-mode.ts +0 -461
- package/tests/drift/code-mode-manifest.test.ts +0 -144
- package/tests/integration/output-schema-validation.test.ts +0 -167
- package/tests/tools/code-mode.test.ts +0 -168
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RESOURCE_MANIFEST drift test
|
|
3
|
-
*
|
|
4
|
-
* Verifies that the RESOURCE_MANIFEST in code-mode.ts stays in sync with the
|
|
5
|
-
* actual AgledgerClient resource properties. If a resource is added to or
|
|
6
|
-
* removed from the SDK client, this test will fail until the manifest is updated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, it, expect } from 'vitest';
|
|
10
|
-
import { readFileSync } from 'node:fs';
|
|
11
|
-
import { resolve, dirname } from 'node:path';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
|
|
14
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Extract resource names from the SDK client source
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
function getClientResourceNames(): string[] {
|
|
21
|
-
const clientPath = resolve(__dirname, '../../../../agledger-sdk/src/client.ts');
|
|
22
|
-
const source = readFileSync(clientPath, 'utf8');
|
|
23
|
-
|
|
24
|
-
// Match "readonly <name>: <Type>Resource" property declarations
|
|
25
|
-
const pattern = /^\s+readonly\s+(\w+)\s*:\s+\w+Resource/gm;
|
|
26
|
-
const names: string[] = [];
|
|
27
|
-
let match: RegExpExecArray | null;
|
|
28
|
-
while ((match = pattern.exec(source)) !== null) {
|
|
29
|
-
names.push(match[1]);
|
|
30
|
-
}
|
|
31
|
-
return names.sort();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
// Extract resource names from the RESOURCE_MANIFEST in code-mode.ts
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
function getManifestResourceNames(): string[] {
|
|
39
|
-
const codePath = resolve(__dirname, '../../src/tools/code-mode.ts');
|
|
40
|
-
const source = readFileSync(codePath, 'utf8');
|
|
41
|
-
|
|
42
|
-
// The manifest is defined as: const RESOURCE_MANIFEST: Record<string, string> = { key: `...`, ... };
|
|
43
|
-
// Extract the keys by finding the block between the opening { and closing };
|
|
44
|
-
const startMarker = 'const RESOURCE_MANIFEST: Record<string, string> = {';
|
|
45
|
-
const startIdx = source.indexOf(startMarker);
|
|
46
|
-
if (startIdx === -1) {
|
|
47
|
-
throw new Error('Could not find RESOURCE_MANIFEST in code-mode.ts');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Find matching closing brace by counting depth
|
|
51
|
-
let depth = 0;
|
|
52
|
-
let inString = false;
|
|
53
|
-
let stringChar = '';
|
|
54
|
-
let endIdx = -1;
|
|
55
|
-
|
|
56
|
-
for (let i = startIdx + startMarker.length - 1; i < source.length; i++) {
|
|
57
|
-
const ch = source[i];
|
|
58
|
-
const prev = i > 0 ? source[i - 1] : '';
|
|
59
|
-
|
|
60
|
-
if (inString) {
|
|
61
|
-
if (ch === stringChar && prev !== '\\') {
|
|
62
|
-
inString = false;
|
|
63
|
-
}
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (ch === '`' || ch === '"' || ch === "'") {
|
|
68
|
-
inString = true;
|
|
69
|
-
stringChar = ch;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (ch === '{') depth++;
|
|
74
|
-
if (ch === '}') {
|
|
75
|
-
depth--;
|
|
76
|
-
if (depth === 0) {
|
|
77
|
-
endIdx = i;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (endIdx === -1) {
|
|
84
|
-
throw new Error('Could not parse RESOURCE_MANIFEST block');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const block = source.slice(startIdx + startMarker.length, endIdx);
|
|
88
|
-
|
|
89
|
-
// Extract top-level keys: lines matching " <key>: `" at the start
|
|
90
|
-
const keyPattern = /^\s+(\w+)\s*:\s*`/gm;
|
|
91
|
-
const names: string[] = [];
|
|
92
|
-
let m: RegExpExecArray | null;
|
|
93
|
-
while ((m = keyPattern.exec(block)) !== null) {
|
|
94
|
-
names.push(m[1]);
|
|
95
|
-
}
|
|
96
|
-
return names.sort();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
// Tests
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
|
|
103
|
-
describe('RESOURCE_MANIFEST ↔ SDK Client drift', () => {
|
|
104
|
-
const clientResources = getClientResourceNames();
|
|
105
|
-
const manifestResources = getManifestResourceNames();
|
|
106
|
-
|
|
107
|
-
it('SDK client has at least one resource', () => {
|
|
108
|
-
expect(clientResources.length).toBeGreaterThan(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('RESOURCE_MANIFEST has at least one resource', () => {
|
|
112
|
-
expect(manifestResources.length).toBeGreaterThan(0);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('every SDK resource is present in RESOURCE_MANIFEST', () => {
|
|
116
|
-
const missing = clientResources.filter((r) => !manifestResources.includes(r));
|
|
117
|
-
if (missing.length > 0) {
|
|
118
|
-
expect.fail(
|
|
119
|
-
`${missing.length} SDK resource(s) missing from RESOURCE_MANIFEST in code-mode.ts:\n` +
|
|
120
|
-
missing.map((r) => ` - ${r}`).join('\n') +
|
|
121
|
-
'\n\nFix: add entries to RESOURCE_MANIFEST for these resources.',
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('every RESOURCE_MANIFEST entry corresponds to an SDK resource', () => {
|
|
127
|
-
const extra = manifestResources.filter((r) => !clientResources.includes(r));
|
|
128
|
-
if (extra.length > 0) {
|
|
129
|
-
expect.fail(
|
|
130
|
-
`${extra.length} RESOURCE_MANIFEST entry/entries have no corresponding SDK resource:\n` +
|
|
131
|
-
extra.map((r) => ` - ${r}`).join('\n') +
|
|
132
|
-
'\n\nFix: remove stale entries from RESOURCE_MANIFEST, or add missing resources to the SDK client.',
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('resource counts match exactly', () => {
|
|
138
|
-
expect(manifestResources.length).toBe(clientResources.length);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('resource names match exactly (sorted)', () => {
|
|
142
|
-
expect(manifestResources).toEqual(clientResources);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test: validate MCP tool outputSchemas against real API responses.
|
|
3
|
-
*
|
|
4
|
-
* Connects the MCP server to a live AGLedger API, calls tools that hit real endpoints,
|
|
5
|
-
* and verifies structuredContent passes the MCP SDK's outputSchema validation.
|
|
6
|
-
*
|
|
7
|
-
* Auto-skips when the API is unreachable (no AGLEDGER_TEST_API_URL or connection refused).
|
|
8
|
-
*
|
|
9
|
-
* Environment:
|
|
10
|
-
* AGLEDGER_TEST_API_URL - API base URL (default: http://localhost:3001)
|
|
11
|
-
* AGLEDGER_TEST_API_KEY - Enterprise API key with standard scopes
|
|
12
|
-
*/
|
|
13
|
-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
14
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
15
|
-
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
16
|
-
import { AgledgerMcpServer } from '../../src/server.js';
|
|
17
|
-
|
|
18
|
-
const API_URL = process.env['AGLEDGER_TEST_API_URL'] || 'http://localhost:3001';
|
|
19
|
-
const API_KEY = process.env['AGLEDGER_TEST_API_KEY'] || '';
|
|
20
|
-
|
|
21
|
-
async function isApiReachable(): Promise<boolean> {
|
|
22
|
-
try {
|
|
23
|
-
const res = await fetch(`${API_URL}/health`, { signal: AbortSignal.timeout(3000) });
|
|
24
|
-
return res.ok;
|
|
25
|
-
} catch {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('outputSchema vs real API responses', async () => {
|
|
31
|
-
const reachable = await isApiReachable();
|
|
32
|
-
if (!reachable || !API_KEY) {
|
|
33
|
-
it.skip('API not reachable or AGLEDGER_TEST_API_KEY not set', () => {});
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let client: Client;
|
|
38
|
-
let cleanup: () => Promise<void>;
|
|
39
|
-
let enterpriseId: string;
|
|
40
|
-
|
|
41
|
-
// Track created resources for cleanup
|
|
42
|
-
let createdMandateId: string | undefined;
|
|
43
|
-
|
|
44
|
-
beforeAll(async () => {
|
|
45
|
-
// Discover enterprise ID from auth/me
|
|
46
|
-
const meRes = await fetch(`${API_URL}/v1/auth/me`, { headers: { Authorization: `Bearer ${API_KEY}` } });
|
|
47
|
-
const me = await meRes.json() as Record<string, unknown>;
|
|
48
|
-
enterpriseId = (me.ownerId ?? me.enterpriseId ?? '') as string;
|
|
49
|
-
const server = new AgledgerMcpServer({
|
|
50
|
-
apiKey: API_KEY,
|
|
51
|
-
apiUrl: API_URL,
|
|
52
|
-
profile: 'full',
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
56
|
-
client = new Client({ name: 'integration-test', version: '0.0.0' });
|
|
57
|
-
await Promise.all([server.mcp.connect(st), client.connect(ct)]);
|
|
58
|
-
|
|
59
|
-
cleanup = async () => {
|
|
60
|
-
// Cancel any created mandates
|
|
61
|
-
if (createdMandateId) {
|
|
62
|
-
try {
|
|
63
|
-
await client.callTool({ name: 'cancel_mandate', arguments: { mandateId: createdMandateId, reason: 'integration test cleanup' } });
|
|
64
|
-
} catch { /* best effort */ }
|
|
65
|
-
}
|
|
66
|
-
await client.close();
|
|
67
|
-
await server.mcp.close();
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
afterAll(async () => { await cleanup(); });
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Helper: call a tool and assert it succeeds (no isError, no MCP validation error).
|
|
75
|
-
* The MCP SDK validates structuredContent against outputSchema automatically —
|
|
76
|
-
* if the real API response doesn't match our schema, this throws.
|
|
77
|
-
*/
|
|
78
|
-
async function callAndExpectSuccess(name: string, args: Record<string, unknown>): Promise<any> {
|
|
79
|
-
const result = await client.callTool({ name, arguments: args });
|
|
80
|
-
const r = result as any;
|
|
81
|
-
if (r.isError) {
|
|
82
|
-
const text = r.content?.[0]?.text ?? '';
|
|
83
|
-
// Permission errors are expected for some tools — don't fail
|
|
84
|
-
if (text.includes('Insufficient scopes') || text.includes('not approved')) {
|
|
85
|
-
return { skipped: true, reason: text };
|
|
86
|
-
}
|
|
87
|
-
throw new Error(`Tool ${name} returned error: ${text.slice(0, 300)}`);
|
|
88
|
-
}
|
|
89
|
-
return r;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// --- Read-only tools that work without prior state ---
|
|
93
|
-
|
|
94
|
-
it('check_api_health: response matches outputSchema', async () => {
|
|
95
|
-
const result = await callAndExpectSuccess('check_api_health', {});
|
|
96
|
-
expect(result.content[0].text).toContain('status=');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('list_contract_schemas: response matches outputSchema', async () => {
|
|
100
|
-
const result = await callAndExpectSuccess('list_contract_schemas', {});
|
|
101
|
-
expect(result.content[0].text).toMatch(/\d+ contract type/);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('get_contract_schema: response matches outputSchema', async () => {
|
|
105
|
-
const result = await callAndExpectSuccess('get_contract_schema', { contractType: 'ACH-PROC-v1' });
|
|
106
|
-
expect(result.content[0].text).toContain('ACH-PROC-v1');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('get_meta_schema: response matches outputSchema', async () => {
|
|
110
|
-
const result = await callAndExpectSuccess('get_meta_schema', {});
|
|
111
|
-
expect(result.content[0].text).toBeTruthy();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('search_mandates: response matches outputSchema', async () => {
|
|
115
|
-
const result = await callAndExpectSuccess('search_mandates', { enterpriseId });
|
|
116
|
-
expect(result.content[0].text).toContain('mandates');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('get_mandate_summary: response matches outputSchema', async () => {
|
|
120
|
-
const result = await callAndExpectSuccess('get_mandate_summary', {});
|
|
121
|
-
expect(result.content[0].text).toBeTruthy();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('list_verification_keys: response matches outputSchema', async () => {
|
|
125
|
-
const result = await callAndExpectSuccess('list_verification_keys', {});
|
|
126
|
-
expect(result.content[0].text).toBeTruthy();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// --- Schema tools ---
|
|
130
|
-
|
|
131
|
-
it('get_schema_template: response matches outputSchema', async () => {
|
|
132
|
-
const result = await callAndExpectSuccess('get_schema_template', { contractType: 'ACH-PROC-v1' });
|
|
133
|
-
expect(result.content[0].text).toContain('template');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('get_blank_schema_template: response matches outputSchema', async () => {
|
|
137
|
-
const result = await callAndExpectSuccess('get_blank_schema_template', {});
|
|
138
|
-
expect(result.content[0].text).toContain('template');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('get_schema_versions: response matches outputSchema', async () => {
|
|
142
|
-
const result = await callAndExpectSuccess('get_schema_versions', { contractType: 'ACH-PROC-v1' });
|
|
143
|
-
expect(result.content[0].text).toBeTruthy();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('get_schema_rules: response matches outputSchema', async () => {
|
|
147
|
-
const result = await callAndExpectSuccess('get_schema_rules', { contractType: 'ACH-PROC-v1' });
|
|
148
|
-
expect(result.content[0].text).toBeTruthy();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// --- Dashboard ---
|
|
152
|
-
|
|
153
|
-
it('get_dashboard_summary: response matches outputSchema', async () => {
|
|
154
|
-
const result = await callAndExpectSuccess('get_dashboard_summary', {});
|
|
155
|
-
expect(result.content[0].text).toBeTruthy();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('get_dashboard_metrics: response matches outputSchema', async () => {
|
|
159
|
-
const result = await callAndExpectSuccess('get_dashboard_metrics', {});
|
|
160
|
-
expect(result.content[0].text).toBeTruthy();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('get_dashboard_alerts: response matches outputSchema', async () => {
|
|
164
|
-
const result = await callAndExpectSuccess('get_dashboard_alerts', {});
|
|
165
|
-
expect(result.content[0].text).toBeTruthy();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
|
|
2
|
-
import { registerCodeModeTools } from '../../src/tools/code-mode.js';
|
|
3
|
-
import { createTestHarness, type TestHarness } from '../harness.js';
|
|
4
|
-
import { assertErrorResult, assertSuccessResult } from '../conformance.js';
|
|
5
|
-
|
|
6
|
-
describe('code-mode tools', () => {
|
|
7
|
-
let harness: TestHarness;
|
|
8
|
-
|
|
9
|
-
beforeAll(async () => {
|
|
10
|
-
harness = await createTestHarness({
|
|
11
|
-
registerFns: [registerCodeModeTools],
|
|
12
|
-
mockOverrides: {
|
|
13
|
-
health: {
|
|
14
|
-
check: vi.fn().mockResolvedValue({ status: 'healthy', version: '1.0.0' }),
|
|
15
|
-
},
|
|
16
|
-
mandates: {
|
|
17
|
-
get: vi.fn().mockResolvedValue({
|
|
18
|
-
id: 'm-1',
|
|
19
|
-
status: 'ACTIVE',
|
|
20
|
-
contractType: 'ACH-PROC-v1',
|
|
21
|
-
}),
|
|
22
|
-
list: vi.fn().mockResolvedValue({
|
|
23
|
-
data: [{ id: 'm-1' }, { id: 'm-2' }],
|
|
24
|
-
total: 2,
|
|
25
|
-
hasMore: false,
|
|
26
|
-
}),
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
afterAll(async () => { await harness.cleanup(); });
|
|
33
|
-
|
|
34
|
-
it('registers exactly 2 tools', async () => {
|
|
35
|
-
const { tools } = await harness.client.listTools();
|
|
36
|
-
expect(tools.map((t: any) => t.name).sort()).toEqual(['sdk_describe', 'sdk_execute']);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('sdk_describe', () => {
|
|
40
|
-
it('returns full manifest when no resource specified', async () => {
|
|
41
|
-
const result = await harness.client.callTool({
|
|
42
|
-
name: 'sdk_describe',
|
|
43
|
-
arguments: {},
|
|
44
|
-
});
|
|
45
|
-
assertSuccessResult(result as any);
|
|
46
|
-
const text = (result as any).content[0].text;
|
|
47
|
-
expect(text).toContain('AGLedger SDK');
|
|
48
|
-
expect(text).toContain('client.mandates');
|
|
49
|
-
expect(text).toContain('client.federation');
|
|
50
|
-
expect(text).toContain('client.health');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns single resource manifest when resource specified', async () => {
|
|
54
|
-
const result = await harness.client.callTool({
|
|
55
|
-
name: 'sdk_describe',
|
|
56
|
-
arguments: { resource: 'mandates' },
|
|
57
|
-
});
|
|
58
|
-
assertSuccessResult(result as any);
|
|
59
|
-
const text = (result as any).content[0].text;
|
|
60
|
-
expect(text).toContain('client.mandates');
|
|
61
|
-
expect(text).toContain('create(');
|
|
62
|
-
expect(text).toContain('get(');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('returns error for unknown resource', async () => {
|
|
66
|
-
const result = await harness.client.callTool({
|
|
67
|
-
name: 'sdk_describe',
|
|
68
|
-
arguments: { resource: 'nonexistent' },
|
|
69
|
-
});
|
|
70
|
-
expect((result as any).isError).toBe(true);
|
|
71
|
-
expect((result as any).content[0].text).toContain('Unknown resource');
|
|
72
|
-
expect((result as any).content[0].text).toContain('nonexistent');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('handles normalized resource names', async () => {
|
|
76
|
-
const result = await harness.client.callTool({
|
|
77
|
-
name: 'sdk_describe',
|
|
78
|
-
arguments: { resource: 'federation-admin' },
|
|
79
|
-
});
|
|
80
|
-
assertSuccessResult(result as any);
|
|
81
|
-
expect((result as any).content[0].text).toContain('client.federationAdmin');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('sdk_execute', () => {
|
|
86
|
-
it('executes simple code and returns result', async () => {
|
|
87
|
-
const result = await harness.client.callTool({
|
|
88
|
-
name: 'sdk_execute',
|
|
89
|
-
arguments: { code: 'return { result: "hello" }' },
|
|
90
|
-
});
|
|
91
|
-
assertSuccessResult(result as any);
|
|
92
|
-
const text = (result as any).content[0].text;
|
|
93
|
-
expect(text).toContain('Execution completed');
|
|
94
|
-
expect(text).toContain('hello');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('can access the client object', async () => {
|
|
98
|
-
const result = await harness.client.callTool({
|
|
99
|
-
name: 'sdk_execute',
|
|
100
|
-
arguments: { code: 'const h = await client.health.check(); return h;' },
|
|
101
|
-
});
|
|
102
|
-
assertSuccessResult(result as any);
|
|
103
|
-
const text = (result as any).content[0].text;
|
|
104
|
-
expect(text).toContain('healthy');
|
|
105
|
-
expect((harness.mockSdk.health as any).check).toHaveBeenCalled();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('can call client.mandates.get()', async () => {
|
|
109
|
-
const result = await harness.client.callTool({
|
|
110
|
-
name: 'sdk_execute',
|
|
111
|
-
arguments: { code: 'const m = await client.mandates.get("m-1"); return m;' },
|
|
112
|
-
});
|
|
113
|
-
assertSuccessResult(result as any);
|
|
114
|
-
const text = (result as any).content[0].text;
|
|
115
|
-
expect(text).toContain('m-1');
|
|
116
|
-
expect(text).toContain('ACTIVE');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('can call client.mandates.list()', async () => {
|
|
120
|
-
const result = await harness.client.callTool({
|
|
121
|
-
name: 'sdk_execute',
|
|
122
|
-
arguments: { code: 'const page = await client.mandates.list({}); return page.data;' },
|
|
123
|
-
});
|
|
124
|
-
assertSuccessResult(result as any);
|
|
125
|
-
const text = (result as any).content[0].text;
|
|
126
|
-
expect(text).toContain('m-1');
|
|
127
|
-
expect(text).toContain('m-2');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('returns error when code throws', async () => {
|
|
131
|
-
const result = await harness.client.callTool({
|
|
132
|
-
name: 'sdk_execute',
|
|
133
|
-
arguments: { code: 'throw new Error("intentional failure")' },
|
|
134
|
-
});
|
|
135
|
-
expect((result as any).isError).toBe(true);
|
|
136
|
-
expect((result as any).content[0].text).toContain('intentional failure');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('returns error when SDK method rejects', async () => {
|
|
140
|
-
(harness.mockSdk.health as any).check.mockRejectedValueOnce(new Error('Connection refused'));
|
|
141
|
-
const result = await harness.client.callTool({
|
|
142
|
-
name: 'sdk_execute',
|
|
143
|
-
arguments: { code: 'return await client.health.check()' },
|
|
144
|
-
});
|
|
145
|
-
expect((result as any).isError).toBe(true);
|
|
146
|
-
expect((result as any).content[0].text).toContain('Connection refused');
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('handles null return value', async () => {
|
|
150
|
-
const result = await harness.client.callTool({
|
|
151
|
-
name: 'sdk_execute',
|
|
152
|
-
arguments: { code: 'return null' },
|
|
153
|
-
});
|
|
154
|
-
assertSuccessResult(result as any);
|
|
155
|
-
expect((result as any).content[0].text).toContain('Execution completed');
|
|
156
|
-
expect((result as any).content[0].text).toContain('null');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('reports execution time', async () => {
|
|
160
|
-
const result = await harness.client.callTool({
|
|
161
|
-
name: 'sdk_execute',
|
|
162
|
-
arguments: { code: 'return 42' },
|
|
163
|
-
});
|
|
164
|
-
assertSuccessResult(result as any);
|
|
165
|
-
expect((result as any).content[0].text).toMatch(/Execution completed in \d+ms/);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|