forked from patternfly/patternfly-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdioTransport.test.ts
More file actions
114 lines (94 loc) · 3.34 KB
/
stdioTransport.test.ts
File metadata and controls
114 lines (94 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Requires: npm run build prior to running Jest.
*/
import { startServer, type StdioTransportClient } from './utils/stdioTransportClient';
import { loadFixture } from './utils/fixtures';
import { setupFetchMock } from './utils/fetchMock';
describe('PatternFly MCP, STDIO', () => {
let client: StdioTransportClient;
beforeEach(async () => {
client = await startServer();
});
afterEach(async () => client.stop());
it('should concatenate headers and separator with two local files', async () => {
const req = {
method: 'tools/call',
params: {
name: 'usePatternFlyDocs',
arguments: {
urlList: [
'documentation/guidelines/README.md',
'documentation/components/README.md'
]
}
}
};
const response = await client.send(req);
const text = response?.result?.content?.[0]?.text || '';
expect(text.startsWith('# Documentation from')).toBe(true);
expect(text).toMatchSnapshot();
});
it('should expose expected tools and stable shape', async () => {
const response = await client.send({ method: 'tools/list' });
const tools = response?.result?.tools || [];
const toolNames = tools.map((tool: any) => tool.name).sort();
expect(toolNames).toEqual(expect.arrayContaining(['usePatternFlyDocs', 'fetchDocs']));
expect({ toolNames }).toMatchSnapshot();
});
});
describe('Hosted mode, --docs-host', () => {
let client: StdioTransportClient;
beforeEach(async () => {
client = await startServer({ args: ['--docs-host'] });
});
afterEach(async () => client.stop());
it('should read llms-files and includes expected tokens', async () => {
const req = {
method: 'tools/call',
params: {
name: 'usePatternFlyDocs',
arguments: { urlList: ['react-core/6.0.0/llms.txt'] }
}
};
const resp = await client.send(req);
const text = resp?.result?.content?.[0]?.text || '';
expect(text.startsWith('# Documentation from')).toBe(true);
expect(text.includes('react-core')).toBe(true);
expect(text.split(/\n/g).filter(Boolean).splice(1)).toMatchSnapshot();
});
});
describe('External URLs', () => {
let fetchMock: Awaited<ReturnType<typeof setupFetchMock>> | undefined;
let url: string;
let client: StdioTransportClient;
beforeEach(async () => {
client = await startServer();
});
afterEach(async () => client.stop());
beforeAll(async () => {
// Note: The helper creates index-based paths based on routing (/0, /1, etc.), so we use /0 for the first route
fetchMock = await setupFetchMock({
routes: [
{
url: /\/readme$/,
status: 200,
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
body: loadFixture('README.md')
}
]
});
url = `${fetchMock.fixture.baseUrl}/0`;
});
afterAll(async () => fetchMock?.cleanup());
it('should fetch a document', async () => {
const req = {
method: 'tools/call',
params: { name: 'fetchDocs', arguments: { urlList: [url] } }
};
const resp = await client.send(req, { timeoutMs: 10000 });
const text = resp?.result?.content?.[0]?.text || '';
expect(text.startsWith('# Documentation from')).toBe(true);
expect(/patternfly/i.test(text)).toBe(true);
expect(text.split(/\n/g).filter(Boolean).splice(1)).toMatchSnapshot();
});
});