|
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest" |
| 2 | +import * as yaml from "yaml" |
| 3 | +import * as fs from "fs/promises" |
| 4 | +import * as path from "path" |
| 5 | +import { mcpMarketplaceItemSchema, type MarketplaceItem } from "@roo-code/types" |
| 6 | + |
| 7 | +describe("CodeRabbit MCP Integration", () => { |
| 8 | + describe("Marketplace Configuration", () => { |
| 9 | + it("should have a valid CodeRabbit MCP marketplace configuration", async () => { |
| 10 | + // Read the CodeRabbit marketplace configuration |
| 11 | + const configPath = path.join(process.cwd(), "..", "marketplace", "mcps", "coderabbit.yaml") |
| 12 | + const configContent = await fs.readFile(configPath, "utf-8") |
| 13 | + const yamlData = yaml.parse(configContent) |
| 14 | + |
| 15 | + // Validate the configuration structure |
| 16 | + expect(yamlData).toHaveProperty("items") |
| 17 | + expect(Array.isArray(yamlData.items)).toBe(true) |
| 18 | + expect(yamlData.items).toHaveLength(1) |
| 19 | + |
| 20 | + const coderabbitConfig = yamlData.items[0] |
| 21 | + |
| 22 | + // Validate against the schema |
| 23 | + const result = mcpMarketplaceItemSchema.safeParse(coderabbitConfig) |
| 24 | + expect(result.success).toBe(true) |
| 25 | + |
| 26 | + if (result.success) { |
| 27 | + const item = result.data |
| 28 | + |
| 29 | + // Verify CodeRabbit specific properties |
| 30 | + expect(item.id).toBe("coderabbit") |
| 31 | + expect(item.name).toBe("CodeRabbit") |
| 32 | + expect(item.description).toContain("code review") |
| 33 | + expect(item.url).toBe("https://github.com/coderabbitai/mcp-server") |
| 34 | + expect(item.author).toBe("CodeRabbit") |
| 35 | + expect(item.authorUrl).toBe("https://coderabbit.ai") |
| 36 | + |
| 37 | + // Verify tags |
| 38 | + expect(item.tags).toContain("code-review") |
| 39 | + expect(item.tags).toContain("github") |
| 40 | + expect(item.tags).toContain("ai") |
| 41 | + |
| 42 | + // Verify installation methods |
| 43 | + expect(Array.isArray(item.content)).toBe(true) |
| 44 | + if (Array.isArray(item.content)) { |
| 45 | + expect(item.content).toHaveLength(3) |
| 46 | + |
| 47 | + // Check NPX installation method |
| 48 | + const npxMethod = item.content[0] |
| 49 | + expect(npxMethod.name).toBe("NPX Installation (Recommended)") |
| 50 | + expect(npxMethod.parameters).toBeDefined() |
| 51 | + expect(npxMethod.parameters?.some((p) => p.key === "CODERABBIT_API_KEY")).toBe(true) |
| 52 | + |
| 53 | + // Check Docker installation method |
| 54 | + const dockerMethod = item.content[1] |
| 55 | + expect(dockerMethod.name).toBe("Docker Installation") |
| 56 | + expect(dockerMethod.parameters).toBeDefined() |
| 57 | + expect(dockerMethod.parameters?.some((p) => p.key === "CODERABBIT_API_KEY")).toBe(true) |
| 58 | + expect(dockerMethod.parameters?.some((p) => p.key === "GITHUB_TOKEN")).toBe(true) |
| 59 | + |
| 60 | + // Check Local installation method |
| 61 | + const localMethod = item.content[2] |
| 62 | + expect(localMethod.name).toBe("Local Installation") |
| 63 | + expect(localMethod.parameters).toBeDefined() |
| 64 | + expect(localMethod.parameters?.some((p) => p.key === "CODERABBIT_API_KEY")).toBe(true) |
| 65 | + } |
| 66 | + |
| 67 | + // Verify global parameters |
| 68 | + expect(item.parameters).toBeDefined() |
| 69 | + expect(item.parameters?.some((p) => p.key === "CODERABBIT_REPO_PATH")).toBe(true) |
| 70 | + expect(item.parameters?.some((p) => p.key === "CODERABBIT_AUTO_REVIEW")).toBe(true) |
| 71 | + expect(item.parameters?.some((p) => p.key === "CODERABBIT_LANGUAGE")).toBe(true) |
| 72 | + } |
| 73 | + }) |
| 74 | + |
| 75 | + it("should have valid JSON content in each installation method", async () => { |
| 76 | + const configPath = path.join(process.cwd(), "..", "marketplace", "mcps", "coderabbit.yaml") |
| 77 | + const configContent = await fs.readFile(configPath, "utf-8") |
| 78 | + const yamlData = yaml.parse(configContent) |
| 79 | + const coderabbitConfig = yamlData.items[0] |
| 80 | + |
| 81 | + if (Array.isArray(coderabbitConfig.content)) { |
| 82 | + for (const method of coderabbitConfig.content) { |
| 83 | + // Parse the JSON content |
| 84 | + const config = JSON.parse(method.content) |
| 85 | + |
| 86 | + // Verify it has required fields |
| 87 | + expect(config).toHaveProperty("command") |
| 88 | + expect(typeof config.command).toBe("string") |
| 89 | + |
| 90 | + if (config.args) { |
| 91 | + expect(Array.isArray(config.args)).toBe(true) |
| 92 | + } |
| 93 | + |
| 94 | + // Verify environment variables are properly templated |
| 95 | + if (config.env) { |
| 96 | + expect(typeof config.env).toBe("object") |
| 97 | + for (const [key, value] of Object.entries(config.env)) { |
| 98 | + expect(typeof value).toBe("string") |
| 99 | + // Check that API key is templated |
| 100 | + if (key === "CODERABBIT_API_KEY") { |
| 101 | + expect(value).toContain("${CODERABBIT_API_KEY}") |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + }) |
| 108 | + }) |
| 109 | + |
| 110 | + describe("Local MCP Configuration", () => { |
| 111 | + it("should have a valid local MCP configuration for testing", async () => { |
| 112 | + const mcpConfigPath = path.join(process.cwd(), "..", ".roo", "mcp.json") |
| 113 | + const configContent = await fs.readFile(mcpConfigPath, "utf-8") |
| 114 | + const config = JSON.parse(configContent) |
| 115 | + |
| 116 | + // Verify structure |
| 117 | + expect(config).toHaveProperty("mcpServers") |
| 118 | + expect(config.mcpServers).toHaveProperty("coderabbit") |
| 119 | + |
| 120 | + const coderabbitServer = config.mcpServers.coderabbit |
| 121 | + |
| 122 | + // Verify server configuration |
| 123 | + expect(coderabbitServer.command).toBe("npx") |
| 124 | + expect(coderabbitServer.args).toEqual(["-y", "@coderabbitai/mcp-server"]) |
| 125 | + expect(coderabbitServer.env).toHaveProperty("CODERABBIT_API_KEY") |
| 126 | + expect(coderabbitServer.env.CODERABBIT_API_KEY).toBe("${CODERABBIT_API_KEY}") |
| 127 | + |
| 128 | + // Verify it's disabled by default (for safety) |
| 129 | + expect(coderabbitServer.disabled).toBe(true) |
| 130 | + |
| 131 | + // Verify timeout is set |
| 132 | + expect(coderabbitServer.timeout).toBe(60) |
| 133 | + }) |
| 134 | + }) |
| 135 | + |
| 136 | + describe("MCP Server Tools", () => { |
| 137 | + it("should define expected CodeRabbit MCP tools", () => { |
| 138 | + // This is a placeholder test for when the MCP server is actually running |
| 139 | + // It would verify that the server exposes the expected tools |
| 140 | + const expectedTools = [ |
| 141 | + "analyze_pr", |
| 142 | + "review_code", |
| 143 | + "suggest_improvements", |
| 144 | + "check_patterns", |
| 145 | + "generate_summary", |
| 146 | + ] |
| 147 | + |
| 148 | + // When the server is running, we would fetch the actual tools |
| 149 | + // and verify they match our expectations |
| 150 | + expect(expectedTools).toBeDefined() |
| 151 | + }) |
| 152 | + }) |
| 153 | + |
| 154 | + describe("Integration with Marketplace Manager", () => { |
| 155 | + it("should be installable through the marketplace system", async () => { |
| 156 | + // This test would verify that the CodeRabbit MCP can be installed |
| 157 | + // through the existing marketplace installation system |
| 158 | + |
| 159 | + const mockMarketplaceItem: MarketplaceItem = { |
| 160 | + type: "mcp", |
| 161 | + id: "coderabbit", |
| 162 | + name: "CodeRabbit", |
| 163 | + description: "AI-powered code review assistant", |
| 164 | + url: "https://github.com/coderabbitai/mcp-server", |
| 165 | + content: [ |
| 166 | + { |
| 167 | + name: "NPX Installation", |
| 168 | + content: JSON.stringify({ |
| 169 | + command: "npx", |
| 170 | + args: ["-y", "@coderabbitai/mcp-server"], |
| 171 | + env: { CODERABBIT_API_KEY: "${CODERABBIT_API_KEY}" }, |
| 172 | + }), |
| 173 | + parameters: [ |
| 174 | + { |
| 175 | + name: "CodeRabbit API Key", |
| 176 | + key: "CODERABBIT_API_KEY", |
| 177 | + placeholder: "Your API key", |
| 178 | + optional: false, |
| 179 | + }, |
| 180 | + ], |
| 181 | + }, |
| 182 | + ], |
| 183 | + } |
| 184 | + |
| 185 | + // Verify the item structure matches what the installer expects |
| 186 | + expect(mockMarketplaceItem.type).toBe("mcp") |
| 187 | + expect(mockMarketplaceItem.content).toBeDefined() |
| 188 | + expect(Array.isArray(mockMarketplaceItem.content)).toBe(true) |
| 189 | + }) |
| 190 | + }) |
| 191 | +}) |
0 commit comments