forked from samanhappy/mcphub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverConfigPersistence.test.ts
More file actions
97 lines (91 loc) · 3.17 KB
/
Copy pathserverConfigPersistence.test.ts
File metadata and controls
97 lines (91 loc) · 3.17 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
import { normalizeServerConfigForPersistence } from '../../src/utils/serverConfigPersistence.js';
describe('normalizeServerConfigForPersistence', () => {
it('clears empty remote collections while preserving explicit field presence for DB/JSON persistence', () => {
const normalized = normalizeServerConfigForPersistence({
type: 'sse',
description: '',
url: ' https://example.com/sse ',
env: {},
headers: {},
passthroughHeaders: [],
oauth: {},
options: {},
enableKeepAlive: false,
keepAliveInterval: 60000,
});
expect(normalized).toMatchObject({
type: 'sse',
url: 'https://example.com/sse',
enableKeepAlive: false,
});
expect(normalized).toHaveProperty('description', undefined);
expect(normalized).toHaveProperty('env', undefined);
expect(normalized).toHaveProperty('headers', undefined);
expect(normalized).toHaveProperty('passthroughHeaders', undefined);
expect(normalized).toHaveProperty('oauth', undefined);
expect(normalized).toHaveProperty('options', undefined);
expect(normalized).toHaveProperty('keepAliveInterval', undefined);
});
it('clears stale remote fields when switching to stdio', () => {
const normalized = normalizeServerConfigForPersistence({
type: 'stdio',
description: ' local ',
url: 'https://example.com/sse',
command: ' npx ',
args: ['-y', 'demo-server'],
env: {},
headers: {
Authorization: 'Bearer token',
},
passthroughHeaders: ['Authorization'],
oauth: {
clientId: 'client-id',
},
openapi: {
version: '3.1.0',
url: 'https://example.com/openapi.json',
},
enableKeepAlive: true,
keepAliveInterval: 15000,
});
expect(normalized).toMatchObject({
type: 'stdio',
description: 'local',
command: 'npx',
args: ['-y', 'demo-server'],
});
expect(normalized).toHaveProperty('url', undefined);
expect(normalized).toHaveProperty('headers', undefined);
expect(normalized).toHaveProperty('passthroughHeaders', undefined);
expect(normalized).toHaveProperty('oauth', undefined);
expect(normalized).toHaveProperty('openapi', undefined);
expect(normalized).toHaveProperty('enableKeepAlive', undefined);
expect(normalized).toHaveProperty('keepAliveInterval', undefined);
});
it('normalizes openapi payloads and trims empty values', () => {
const normalized = normalizeServerConfigForPersistence({
type: 'openapi',
headers: {},
url: 'https://example.com/old-sse',
openapi: {
version: ' 3.1.0 ',
url: ' ',
passthroughHeaders: [],
},
command: 'npx',
args: ['-y'],
env: {
' API_KEY ': 'value',
},
});
expect(normalized.type).toBe('openapi');
expect(normalized).toHaveProperty('url', undefined);
expect(normalized).toHaveProperty('command', undefined);
expect(normalized).toHaveProperty('args', undefined);
expect(normalized).toHaveProperty('env', undefined);
expect(normalized).toHaveProperty('headers', undefined);
expect(normalized.openapi).toEqual({
version: '3.1.0',
});
});
});