| 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | |
| 3 | import { parseArgs, loadMcpFromHub } from "./args.js"; |
| 4 | |
| 5 | // Integration test to demonstrate the --mcp flag functionality |
| 6 | describe("--mcp flag integration", () => { |
| 7 | beforeEach(() => { |
| 8 | // Clear process.argv before each test |
| 9 | process.argv = ["node", "test"]; |
| 10 | vi.clearAllMocks(); |
| 11 | }); |
| 12 | |
| 13 | it("should demonstrate the complete --mcp flag functionality", () => { |
| 14 | // Test command line parsing |
| 15 | process.argv = [ |
| 16 | "node", |
| 17 | "test", |
| 18 | "--config", |
| 19 | "my-config.yaml", |
| 20 | "--mcp", |
| 21 | "continuedev/filesystem", |
| 22 | "--mcp", |
| 23 | "continuedev/github", |
| 24 | "hello world", |
| 25 | ]; |
| 26 | |
| 27 | const args = parseArgs(); |
| 28 | |
| 29 | // Verify the parsed command line arguments |
| 30 | expect(args).toEqual({ |
| 31 | configPath: "my-config.yaml", |
| 32 | mcps: ["continuedev/filesystem", "continuedev/github"], |
| 33 | prompt: "hello world", |
| 34 | }); |
| 35 | |
| 36 | // Verify MCP slugs are properly captured |
| 37 | expect(args.mcps).toHaveLength(2); |
| 38 | expect(args.mcps).toContain("continuedev/filesystem"); |
| 39 | expect(args.mcps).toContain("continuedev/github"); |
| 40 | }); |
| 41 | |
| 42 | it("should validate MCP slug format", async () => { |
| 43 | // Test that invalid slug formats are rejected |
| 44 | await expect(loadMcpFromHub("invalid-slug")).rejects.toThrow( |
| 45 | 'Invalid hub slug format. Expected "owner/package", got: invalid-slug', |
| 46 | ); |
| 47 | |
| 48 | // Valid format should not throw during validation step |
| 49 | const mockFetch = vi.fn().mockResolvedValue({ |
| 50 | ok: false, |
| 51 | status: 404, |
| 52 | statusText: "Not Found", |
| 53 | }); |
| 54 | global.fetch = mockFetch; |
| 55 | |
| 56 | // This will fail at the HTTP level, not validation level |
| 57 | await expect(loadMcpFromHub("valid/slug")).rejects.toThrow( |
| 58 | 'Failed to load mcp from hub "valid/slug": HTTP 404: Not Found', |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | it("should demonstrate MCP flag with other command line options", () => { |
| 63 | process.argv = [ |
| 64 | "node", |
| 65 | "test", |
| 66 | "--config", |
| 67 | "test-config.yaml", |
| 68 | "--org", |
| 69 | "my-org", |
| 70 | "--rule", |
| 71 | "my-rule", |
| 72 | "--mcp", |
| 73 | "continuedev/filesystem", |
| 74 | "--allow", |
| 75 | "readFile", |
| 76 | "--readonly", |
| 77 | "analyze this code", |
| 78 | ]; |
| 79 | |
| 80 | const args = parseArgs(); |
| 81 | |
| 82 | // Verify all flags are parsed correctly together |
| 83 | expect(args).toEqual({ |
| 84 | configPath: "test-config.yaml", |
| 85 | organizationSlug: "my-org", |
| 86 | rules: ["my-rule"], |
| 87 | mcps: ["continuedev/filesystem"], |
| 88 | readonly: true, |
| 89 | prompt: "analyze this code", |
| 90 | }); |
| 91 | }); |
| 92 | }); |