Elffuss BraidHub

kikocis/continue public

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