| 1 | import { afterEach, describe, expect, it, vi } from 'vitest';
|
| 2 | import { callOpenClaspTool, sendMcpA2ARequest } from '../connectors/botpress/src/mcp.js';
|
| 3 |
|
| 4 | afterEach(() => vi.unstubAllGlobals());
|
| 5 |
|
| 6 | describe('Botpress OpenClasp MCP bridge', () => {
|
| 7 | it('calls a tool with the paired bearer token and parses an SSE result', async () => {
|
| 8 | const fetchMock = vi.fn().mockResolvedValue(
|
| 9 | new Response(
|
| 10 | `event: message\ndata: ${JSON.stringify({
|
| 11 | jsonrpc: '2.0',
|
| 12 | id: 'request',
|
| 13 | result: { content: [{ type: 'text', text: JSON.stringify({ ready: true }) }] },
|
| 14 | })}\n\n`,
|
| 15 | { status: 200, headers: { 'content-type': 'text/event-stream' } },
|
| 16 | ),
|
| 17 | );
|
| 18 | vi.stubGlobal('fetch', fetchMock);
|
| 19 |
|
| 20 | await expect(
|
| 21 | callOpenClaspTool('https://openclasp.dev/', 'oc_at_secret', 'openclasp_search_agents', {
|
| 22 | query: 'buyer',
|
| 23 | }),
|
| 24 | ).resolves.toEqual({ ready: true });
|
| 25 | expect(fetchMock).toHaveBeenCalledWith(
|
| 26 | 'https://openclasp.dev/mcp',
|
| 27 | expect.objectContaining({
|
| 28 | method: 'POST',
|
| 29 | headers: expect.objectContaining({ authorization: 'Bearer oc_at_secret' }),
|
| 30 | }),
|
| 31 | );
|
| 32 | });
|
| 33 |
|
| 34 | it('sends a returned MCP A2A request directly to the peer', async () => {
|
| 35 | const fetchMock = vi.fn().mockResolvedValue(new Response('{}', { status: 200 }));
|
| 36 | vi.stubGlobal('fetch', fetchMock);
|
| 37 |
|
| 38 | await expect(
|
| 39 | sendMcpA2ARequest({
|
| 40 | a2a: {
|
| 41 | endpoint: 'https://peer.example/a2a',
|
| 42 | bearerToken: 'session-token',
|
| 43 | request: {
|
| 44 | params: { message: { role: 'user', parts: [{ kind: 'data', data: {} }] } },
|
| 45 | },
|
| 46 | },
|
| 47 | }),
|
| 48 | ).resolves.toBe(true);
|
| 49 | expect(fetchMock).toHaveBeenCalledWith(
|
| 50 | 'https://peer.example/a2a',
|
| 51 | expect.objectContaining({ method: 'POST' }),
|
| 52 | );
|
| 53 | });
|
| 54 | });
|