Skip to content

Commit 362359c

Browse files
author
aheizi
committed
fix ut
(cherry picked from commit b4f808d)
1 parent 3975c8d commit 362359c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class SSEClientTransport {
2+
constructor(url, options = {}) {
3+
this.url = url
4+
this.options = options
5+
this.onerror = null
6+
this.connect = jest.fn().mockResolvedValue()
7+
this.close = jest.fn().mockResolvedValue()
8+
this.start = jest.fn().mockResolvedValue()
9+
}
10+
}
11+
12+
module.exports = {
13+
SSEClientTransport,
14+
}

src/services/mcp/__tests__/McpHub.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe("McpHub", () => {
7171
JSON.stringify({
7272
mcpServers: {
7373
"test-server": {
74+
type: "stdio",
7475
command: "node",
7576
args: ["test.js"],
7677
alwaysAllow: ["allowed-tool"],
@@ -87,6 +88,7 @@ describe("McpHub", () => {
8788
const mockConfig = {
8889
mcpServers: {
8990
"test-server": {
91+
type: "stdio",
9092
command: "node",
9193
args: ["test.js"],
9294
alwaysAllow: [],
@@ -109,6 +111,7 @@ describe("McpHub", () => {
109111
const mockConfig = {
110112
mcpServers: {
111113
"test-server": {
114+
type: "stdio",
112115
command: "node",
113116
args: ["test.js"],
114117
alwaysAllow: ["existing-tool"],
@@ -131,6 +134,7 @@ describe("McpHub", () => {
131134
const mockConfig = {
132135
mcpServers: {
133136
"test-server": {
137+
type: "stdio",
134138
command: "node",
135139
args: ["test.js"],
136140
},
@@ -155,6 +159,7 @@ describe("McpHub", () => {
155159
const mockConfig = {
156160
mcpServers: {
157161
"test-server": {
162+
type: "stdio",
158163
command: "node",
159164
args: ["test.js"],
160165
disabled: false,
@@ -294,16 +299,17 @@ describe("McpHub", () => {
294299
it("should validate timeout values", () => {
295300
// Test valid timeout values
296301
const validConfig = {
302+
type: "stdio",
297303
command: "test",
298304
timeout: 60,
299305
}
300306
expect(() => ServerConfigSchema.parse(validConfig)).not.toThrow()
301307

302308
// Test invalid timeout values
303309
const invalidConfigs = [
304-
{ command: "test", timeout: 0 }, // Too low
305-
{ command: "test", timeout: 3601 }, // Too high
306-
{ command: "test", timeout: -1 }, // Negative
310+
{ type: "stdio", command: "test", timeout: 0 }, // Too low
311+
{ type: "stdio", command: "test", timeout: 3601 }, // Too high
312+
{ type: "stdio", command: "test", timeout: -1 }, // Negative
307313
]
308314

309315
invalidConfigs.forEach((config) => {
@@ -315,7 +321,7 @@ describe("McpHub", () => {
315321
const mockConnection: McpConnection = {
316322
server: {
317323
name: "test-server",
318-
config: JSON.stringify({ command: "test" }), // No timeout specified
324+
config: JSON.stringify({ type: "stdio", command: "test" }), // No timeout specified
319325
status: "connected",
320326
},
321327
client: {
@@ -338,7 +344,7 @@ describe("McpHub", () => {
338344
const mockConnection: McpConnection = {
339345
server: {
340346
name: "test-server",
341-
config: JSON.stringify({ command: "test", timeout: 120 }), // 2 minutes
347+
config: JSON.stringify({ type: "stdio", command: "test", timeout: 120 }), // 2 minutes
342348
status: "connected",
343349
},
344350
client: {
@@ -363,6 +369,7 @@ describe("McpHub", () => {
363369
const mockConfig = {
364370
mcpServers: {
365371
"test-server": {
372+
type: "stdio",
366373
command: "node",
367374
args: ["test.js"],
368375
timeout: 60,
@@ -385,6 +392,7 @@ describe("McpHub", () => {
385392
const mockConfig = {
386393
mcpServers: {
387394
"test-server": {
395+
type: "stdio",
388396
command: "node",
389397
args: ["test.js"],
390398
timeout: 60,
@@ -406,6 +414,7 @@ describe("McpHub", () => {
406414
server: {
407415
name: "test-server",
408416
config: JSON.stringify({
417+
type: "stdio",
409418
command: "node",
410419
args: ["test.js"],
411420
timeout: 3601, // Invalid timeout
@@ -435,6 +444,7 @@ describe("McpHub", () => {
435444
const mockConfig = {
436445
mcpServers: {
437446
"test-server": {
447+
type: "stdio",
438448
command: "node",
439449
args: ["test.js"],
440450
timeout: 60,
@@ -458,6 +468,7 @@ describe("McpHub", () => {
458468
const mockConfig = {
459469
mcpServers: {
460470
"test-server": {
471+
type: "stdio",
461472
command: "node",
462473
args: ["test.js"],
463474
timeout: 60,

0 commit comments

Comments
 (0)