| 1 | import { beforeEach, describe, expect, it } from "vitest"; |
| 2 | |
| 3 | import { parseArgs } from "./args.js"; |
| 4 | |
| 5 | describe("parseArgs --mcp flag", () => { |
| 6 | beforeEach(() => { |
| 7 | // Clear process.argv before each test |
| 8 | process.argv = ["node", "test"]; |
| 9 | }); |
| 10 | |
| 11 | it("should parse single MCP from --mcp flag", () => { |
| 12 | process.argv = ["node", "test", "--mcp", "my-org/my-mcp"]; |
| 13 | const result = parseArgs(); |
| 14 | expect(result.mcps).toEqual(["my-org/my-mcp"]); |
| 15 | }); |
| 16 | |
| 17 | it("should parse multiple MCPs from multiple --mcp flags", () => { |
| 18 | process.argv = ["node", "test", "--mcp", "org1/mcp1", "--mcp", "org2/mcp2"]; |
| 19 | const result = parseArgs(); |
| 20 | expect(result.mcps).toEqual(["org1/mcp1", "org2/mcp2"]); |
| 21 | }); |
| 22 | |
| 23 | it("should handle MCP flag with other flags", () => { |
| 24 | process.argv = [ |
| 25 | "node", |
| 26 | "test", |
| 27 | "--config", |
| 28 | "my-config.yaml", |
| 29 | "--mcp", |
| 30 | "my-org/my-mcp", |
| 31 | "--org", |
| 32 | "test-org", |
| 33 | ]; |
| 34 | const result = parseArgs(); |
| 35 | expect(result.configPath).toBe("my-config.yaml"); |
| 36 | expect(result.mcps).toEqual(["my-org/my-mcp"]); |
| 37 | expect(result.organizationSlug).toBe("test-org"); |
| 38 | }); |
| 39 | |
| 40 | it("should handle MCP flag with prompt", () => { |
| 41 | process.argv = ["node", "test", "--mcp", "my-org/my-mcp", "hello world"]; |
| 42 | const result = parseArgs(); |
| 43 | expect(result.mcps).toEqual(["my-org/my-mcp"]); |
| 44 | expect(result.prompt).toBe("hello world"); |
| 45 | }); |
| 46 | |
| 47 | it("should ignore MCP and rule flag values when extracting prompt", () => { |
| 48 | process.argv = [ |
| 49 | "node", |
| 50 | "test", |
| 51 | "actual prompt", |
| 52 | "--rule", |
| 53 | "my-rule", |
| 54 | "--mcp", |
| 55 | "my-org/my-mcp", |
| 56 | ]; |
| 57 | const result = parseArgs(); |
| 58 | expect(result.prompt).toBe("actual prompt"); |
| 59 | expect(result.rules).toEqual(["my-rule"]); |
| 60 | expect(result.mcps).toEqual(["my-org/my-mcp"]); |
| 61 | }); |
| 62 | |
| 63 | it("should handle MCP flag without value", () => { |
| 64 | process.argv = ["node", "test", "--mcp"]; |
| 65 | const result = parseArgs(); |
| 66 | expect(result.mcps).toEqual([]); |
| 67 | }); |
| 68 | |
| 69 | it("should handle MCP flag at the end without value", () => { |
| 70 | process.argv = ["node", "test", "my prompt", "--mcp"]; |
| 71 | const result = parseArgs(); |
| 72 | expect(result.prompt).toBe("my prompt"); |
| 73 | expect(result.mcps).toEqual([]); |
| 74 | }); |
| 75 | }); |