Просмотр исходного кода

fix ut

(cherry picked from commit b4f808d7dcb4f23c0de86bce47be392b2d9e4281)
aheizi 9 месяцев назад
Родитель
Сommit
362359cc3c

+ 14 - 0
src/__mocks__/@modelcontextprotocol/sdk/client/sse.js

@@ -0,0 +1,14 @@
+class SSEClientTransport {
+	constructor(url, options = {}) {
+		this.url = url
+		this.options = options
+		this.onerror = null
+		this.connect = jest.fn().mockResolvedValue()
+		this.close = jest.fn().mockResolvedValue()
+		this.start = jest.fn().mockResolvedValue()
+	}
+}
+
+module.exports = {
+	SSEClientTransport,
+}

+ 16 - 5
src/services/mcp/__tests__/McpHub.test.ts

@@ -71,6 +71,7 @@ describe("McpHub", () => {
 			JSON.stringify({
 				mcpServers: {
 					"test-server": {
+						type: "stdio",
 						command: "node",
 						args: ["test.js"],
 						alwaysAllow: ["allowed-tool"],
@@ -87,6 +88,7 @@ describe("McpHub", () => {
 			const mockConfig = {
 				mcpServers: {
 					"test-server": {
+						type: "stdio",
 						command: "node",
 						args: ["test.js"],
 						alwaysAllow: [],
@@ -109,6 +111,7 @@ describe("McpHub", () => {
 			const mockConfig = {
 				mcpServers: {
 					"test-server": {
+						type: "stdio",
 						command: "node",
 						args: ["test.js"],
 						alwaysAllow: ["existing-tool"],
@@ -131,6 +134,7 @@ describe("McpHub", () => {
 			const mockConfig = {
 				mcpServers: {
 					"test-server": {
+						type: "stdio",
 						command: "node",
 						args: ["test.js"],
 					},
@@ -155,6 +159,7 @@ describe("McpHub", () => {
 			const mockConfig = {
 				mcpServers: {
 					"test-server": {
+						type: "stdio",
 						command: "node",
 						args: ["test.js"],
 						disabled: false,
@@ -294,6 +299,7 @@ describe("McpHub", () => {
 			it("should validate timeout values", () => {
 				// Test valid timeout values
 				const validConfig = {
+					type: "stdio",
 					command: "test",
 					timeout: 60,
 				}
@@ -301,9 +307,9 @@ describe("McpHub", () => {
 
 				// Test invalid timeout values
 				const invalidConfigs = [
-					{ command: "test", timeout: 0 }, // Too low
-					{ command: "test", timeout: 3601 }, // Too high
-					{ command: "test", timeout: -1 }, // Negative
+					{ type: "stdio", command: "test", timeout: 0 }, // Too low
+					{ type: "stdio", command: "test", timeout: 3601 }, // Too high
+					{ type: "stdio", command: "test", timeout: -1 }, // Negative
 				]
 
 				invalidConfigs.forEach((config) => {
@@ -315,7 +321,7 @@ describe("McpHub", () => {
 				const mockConnection: McpConnection = {
 					server: {
 						name: "test-server",
-						config: JSON.stringify({ command: "test" }), // No timeout specified
+						config: JSON.stringify({ type: "stdio", command: "test" }), // No timeout specified
 						status: "connected",
 					},
 					client: {
@@ -338,7 +344,7 @@ describe("McpHub", () => {
 				const mockConnection: McpConnection = {
 					server: {
 						name: "test-server",
-						config: JSON.stringify({ command: "test", timeout: 120 }), // 2 minutes
+						config: JSON.stringify({ type: "stdio", command: "test", timeout: 120 }), // 2 minutes
 						status: "connected",
 					},
 					client: {
@@ -363,6 +369,7 @@ describe("McpHub", () => {
 				const mockConfig = {
 					mcpServers: {
 						"test-server": {
+							type: "stdio",
 							command: "node",
 							args: ["test.js"],
 							timeout: 60,
@@ -385,6 +392,7 @@ describe("McpHub", () => {
 				const mockConfig = {
 					mcpServers: {
 						"test-server": {
+							type: "stdio",
 							command: "node",
 							args: ["test.js"],
 							timeout: 60,
@@ -406,6 +414,7 @@ describe("McpHub", () => {
 					server: {
 						name: "test-server",
 						config: JSON.stringify({
+							type: "stdio",
 							command: "node",
 							args: ["test.js"],
 							timeout: 3601, // Invalid timeout
@@ -435,6 +444,7 @@ describe("McpHub", () => {
 				const mockConfig = {
 					mcpServers: {
 						"test-server": {
+							type: "stdio",
 							command: "node",
 							args: ["test.js"],
 							timeout: 60,
@@ -458,6 +468,7 @@ describe("McpHub", () => {
 				const mockConfig = {
 					mcpServers: {
 						"test-server": {
+							type: "stdio",
 							command: "node",
 							args: ["test.js"],
 							timeout: 60,