UNPKG

codn_ts

Version:

智能代码分析工具 - 支持语义搜索、调用链分析和代码结构可视化,对大模型/AI agent 友好

69 lines 2.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const mcp_1 = require("./mcp"); const node_fetch_1 = __importDefault(require("node-fetch")); let server; const PORT = 7789; const BASE_URL = `http://localhost:${PORT}`; (0, vitest_1.beforeAll)(() => { server = (0, mcp_1.startMcpServer)(PORT); }); (0, vitest_1.afterAll)(() => { server.close(); }); (0, vitest_1.describe)('MCP API', () => { (0, vitest_1.it)('should return describe with codn_ref tool', async () => { const res = await (0, node_fetch_1.default)(`${BASE_URL}/mcp/describe`); (0, vitest_1.expect)(res.status).toBe(200); const json = await res.json(); (0, vitest_1.expect)(Array.isArray(json.tools)).toBe(true); const refTool = json.tools.find((t) => t.id === 'codn_ref'); (0, vitest_1.expect)(refTool).toBeTruthy(); (0, vitest_1.expect)(refTool.parameters).toHaveProperty('symbol'); }); (0, vitest_1.it)('should call codn_ref and return symbol reference', async () => { const body = { jsonrpc: '2.0', id: 'test1', method: 'codn_ref', params: { project: '.', symbol: 'analyzeProjectReferences', includeExternal: false, maxDepth: 2, caseSensitive: false } }; const res = await (0, node_fetch_1.default)(`${BASE_URL}/mcp/rpc`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); (0, vitest_1.expect)(res.status).toBe(200); const json = await res.json(); (0, vitest_1.expect)(json.result).toBeDefined(); (0, vitest_1.expect)(Array.isArray(json.result)).toBe(true); (0, vitest_1.expect)(json.result[0]?.symbol).toBe('analyzeProjectReferences'); }, 30000); (0, vitest_1.it)('should return error for unknown method', async () => { const body = { jsonrpc: '2.0', id: 'err1', method: 'not_exist', params: {} }; const res = await (0, node_fetch_1.default)(`${BASE_URL}/mcp/rpc`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); (0, vitest_1.expect)(res.status).toBe(200); const json = await res.json(); (0, vitest_1.expect)(json.error).toBeDefined(); }); }); //# sourceMappingURL=mcp.test.js.map