Changesets · Branches · Tags · Compare
| Changeset | fc89067dc2f197c70068671a5236feb29fba9860fbfdc67eafe60e2672b005dc |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-24 15:39 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-24 15:39 -07:00 |
| Parents | 675e3d10e9f3 |
5 files changed
modified extensions/cli/src/configEnhancer.test.ts +52 −0
| @@ -127,4 +127,56 @@ | ||
| 127 | 127 | expect(config.rules?.[0]).toBe("./rules/my-rule.md"); |
| 128 | 128 | expect(config.rules?.[1]).toBe("/absolute/path/rule.txt"); |
| 129 | 129 | }); |
| 130 | + | |
| 131 | + it("should prepend models from --model flag to make them default", async () => { | |
| 132 | + // Mock loadPackagesFromHub to return test models | |
| 133 | + const { loadPackagesFromHub } = await import("./hubLoader.js"); | |
| 134 | + (loadPackagesFromHub as any).mockResolvedValueOnce([ | |
| 135 | + { name: "GPT-5", provider: "openai", model: "gpt-5" }, | |
| 136 | + { name: "Claude-3", provider: "anthropic", model: "claude-3" }, | |
| 137 | + ]); | |
| 138 | + | |
| 139 | + // Set up existing models in config | |
| 140 | + mockConfig.models = [ | |
| 141 | + { name: "GPT-4", provider: "openai", model: "gpt-4" }, | |
| 142 | + { name: "Claude-2", provider: "anthropic", model: "claude-2" }, | |
| 143 | + ]; | |
| 144 | + | |
| 145 | + const options: BaseCommandOptions = { | |
| 146 | + model: ["openai/gpt-5", "anthropic/claude-3"], | |
| 147 | + }; | |
| 148 | + | |
| 149 | + const config = await enhancer.enhanceConfig(mockConfig, options); | |
| 150 | + | |
| 151 | + // Models from --model flag should be prepended (at the start) | |
| 152 | + expect(config.models).toHaveLength(4); | |
| 153 | + expect(config.models?.[0]).toEqual({ name: "GPT-5", provider: "openai", model: "gpt-5" }); | |
| 154 | + expect(config.models?.[1]).toEqual({ name: "Claude-3", provider: "anthropic", model: "claude-3" }); | |
| 155 | + expect(config.models?.[2]).toEqual({ name: "GPT-4", provider: "openai", model: "gpt-4" }); | |
| 156 | + expect(config.models?.[3]).toEqual({ name: "Claude-2", provider: "anthropic", model: "claude-2" }); | |
| 157 | + }); | |
| 158 | + | |
| 159 | + it("should prepend MCPs from --mcp flag", async () => { | |
| 160 | + // Mock loadPackagesFromHub to return test MCPs | |
| 161 | + const { loadPackagesFromHub } = await import("./hubLoader.js"); | |
| 162 | + (loadPackagesFromHub as any).mockResolvedValueOnce([ | |
| 163 | + { name: "New-MCP", command: "new-mcp" }, | |
| 164 | + ]); | |
| 165 | + | |
| 166 | + // Set up existing MCPs in config | |
| 167 | + mockConfig.mcpServers = [ | |
| 168 | + { name: "Existing-MCP", command: "existing-mcp" }, | |
| 169 | + ]; | |
| 170 | + | |
| 171 | + const options: BaseCommandOptions = { | |
| 172 | + mcp: ["test/new-mcp"], | |
| 173 | + }; | |
| 174 | + | |
| 175 | + const config = await enhancer.enhanceConfig(mockConfig, options); | |
| 176 | + | |
| 177 | + // MCPs from --mcp flag should be prepended (at the start) | |
| 178 | + expect(config.mcpServers).toHaveLength(2); | |
| 179 | + expect(config.mcpServers?.[0]).toEqual({ name: "New-MCP", command: "new-mcp" }); | |
| 180 | + expect(config.mcpServers?.[1]).toEqual({ name: "Existing-MCP", command: "existing-mcp" }); | |
| 181 | + }); | |
| 130 | 182 | }); |
| No newline at the end of the file |
modified extensions/cli/src/configEnhancer.ts +4 −4
| @@ -103,11 +103,11 @@ | ||
| 103 | 103 | // Clone the config to avoid mutating the original |
| 104 | 104 | const modifiedConfig = { ...config }; |
| 105 | 105 | |
| 106 | - // Add processed MCPs to existing mcpServers array | |
| 106 | + // Prepend processed MCPs to existing mcpServers array for consistency | |
| 107 | 107 | const existingMcpServers = (modifiedConfig as any).mcpServers || []; |
| 108 | 108 | (modifiedConfig as any).mcpServers = [ |
| 109 | - ...existingMcpServers, | |
| 110 | 109 | ...processedMcps, |
| 110 | + ...existingMcpServers, | |
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | 113 | return modifiedConfig; |
| @@ -125,9 +125,9 @@ | ||
| 125 | 125 | // Clone the config to avoid mutating the original |
| 126 | 126 | const modifiedConfig = { ...config }; |
| 127 | 127 | |
| 128 | - // Add processed models to existing models array | |
| 128 | + // Prepend processed models to existing models array so they become the default | |
| 129 | 129 | const existingModels = (modifiedConfig as any).models || []; |
| 130 | - (modifiedConfig as any).models = [...existingModels, ...processedModels]; | |
| 130 | + (modifiedConfig as any).models = [...processedModels, ...existingModels]; | |
| 131 | 131 | |
| 132 | 132 | return modifiedConfig; |
| 133 | 133 | } |
modified extensions/cli/src/hubLoader.test.ts +19 −12
| @@ -93,7 +93,11 @@ | ||
| 93 | 93 | }); |
| 94 | 94 | |
| 95 | 95 | const result = await loadPackageFromHub("owner/mcp", mcpProcessor); |
| 96 | - expect(result).toEqual(mcpConfig); | |
| 96 | + // Should parse the YAML content, not return the wrapper | |
| 97 | + expect(result).toEqual({ | |
| 98 | + name: "test-mcp", | |
| 99 | + version: "1.0.0" | |
| 100 | + }); | |
| 97 | 101 | }); |
| 98 | 102 | |
| 99 | 103 | it("should handle missing files", async () => { |
| @@ -186,11 +190,12 @@ | ||
| 186 | 190 | |
| 187 | 191 | expect(result).toBeDefined(); |
| 188 | 192 | expect(typeof result).toBe("object"); |
| 189 | - // The registry returns an object with a content field containing the YAML/JSON | |
| 190 | - expect(result).toHaveProperty("content"); | |
| 191 | - expect(typeof result.content).toBe("string"); | |
| 192 | - // The content should contain MCP configuration | |
| 193 | - expect(result.content).toContain("mcp"); | |
| 193 | + // Should now return the parsed MCP configuration | |
| 194 | + expect(result).toHaveProperty("name"); | |
| 195 | + expect(typeof result.name).toBe("string"); | |
| 196 | + // The MCP should have type and url properties | |
| 197 | + expect(result).toHaveProperty("type"); | |
| 198 | + expect(result).toHaveProperty("url"); | |
| 194 | 199 | }, 30000); |
| 195 | 200 | |
| 196 | 201 | it("should load model from real hub: openai/gpt-5", async () => { |
| @@ -203,12 +208,14 @@ | ||
| 203 | 208 | |
| 204 | 209 | expect(result).toBeDefined(); |
| 205 | 210 | expect(typeof result).toBe("object"); |
| 206 | - // The registry returns an object with a content field containing the model configuration | |
| 207 | - expect(result).toHaveProperty("content"); | |
| 208 | - expect(typeof result.content).toBe("string"); | |
| 209 | - // The content should contain model configuration | |
| 210 | - expect(result.content).toContain("model"); | |
| 211 | - expect(result.content).toContain("gpt-5"); | |
| 211 | + // Should now return the extracted model from the models array | |
| 212 | + expect(result).toHaveProperty("name"); | |
| 213 | + expect(result).toHaveProperty("provider"); | |
| 214 | + expect(result).toHaveProperty("model"); | |
| 215 | + // Check that the model properties are correct | |
| 216 | + expect(result.provider).toBe("openai"); | |
| 217 | + expect(result.model).toBe("gpt-5"); | |
| 218 | + expect(result.name).toBe("GPT-5"); | |
| 212 | 219 | }, 30000); |
| 213 | 220 | |
| 214 | 221 | it("should load prompt from real hub: launchdarkly/using-flags", async () => { |
modified extensions/cli/src/hubLoader.ts +37 −7
| @@ -34,12 +34,21 @@ | ||
| 34 | 34 | type: "mcp", |
| 35 | 35 | expectedFileExtensions: [".json", ".yaml", ".yml"], |
| 36 | 36 | parseContent: async (content: string, filename: string) => { |
| 37 | + let parsed; | |
| 37 | 38 | if (filename.endsWith(".json")) { |
| 38 | - return JSON.parse(content); | |
| 39 | + parsed = JSON.parse(content); | |
| 39 | 40 | } else { |
| 40 | 41 | const yaml = await import("yaml"); |
| 41 | - return yaml.parse(content); | |
| 42 | + parsed = yaml.parse(content); | |
| 42 | 43 | } |
| 44 | + | |
| 45 | + // If the parsed content has an 'mcpServers' array, extract the first MCP server | |
| 46 | + // This handles hub packages that return a full config block | |
| 47 | + if (parsed.mcpServers && Array.isArray(parsed.mcpServers) && parsed.mcpServers.length > 0) { | |
| 48 | + return parsed.mcpServers[0]; | |
| 49 | + } | |
| 50 | + | |
| 51 | + return parsed; | |
| 43 | 52 | }, |
| 44 | 53 | }; |
| 45 | 54 | |
| @@ -50,12 +59,21 @@ | ||
| 50 | 59 | type: "model", |
| 51 | 60 | expectedFileExtensions: [".json", ".yaml", ".yml"], |
| 52 | 61 | parseContent: async (content: string, filename: string) => { |
| 62 | + let parsed; | |
| 53 | 63 | if (filename.endsWith(".json")) { |
| 54 | - return JSON.parse(content); | |
| 64 | + parsed = JSON.parse(content); | |
| 55 | 65 | } else { |
| 56 | 66 | const yaml = await import("yaml"); |
| 57 | - return yaml.parse(content); | |
| 67 | + parsed = yaml.parse(content); | |
| 68 | + } | |
| 69 | + | |
| 70 | + // If the parsed content has a 'models' array, extract the first model | |
| 71 | + // This handles hub packages that return a full config block | |
| 72 | + if (parsed.models && Array.isArray(parsed.models) && parsed.models.length > 0) { | |
| 73 | + return parsed.models[0]; | |
| 58 | 74 | } |
| 75 | + | |
| 76 | + return parsed; | |
| 59 | 77 | }, |
| 60 | 78 | }; |
| 61 | 79 | |
| @@ -109,9 +127,21 @@ | ||
| 109 | 127 | |
| 110 | 128 | // Check if this is a registry endpoint (returns JSON directly) or a zip file |
| 111 | 129 | if (processor.type === "mcp" || processor.type === "model") { |
| 112 | - // Registry endpoints return JSON directly | |
| 113 | - const jsonContent = await response.json(); | |
| 114 | - return jsonContent; | |
| 130 | + // Registry endpoints return JSON with a 'content' field containing YAML/JSON | |
| 131 | + const jsonResponse = await response.json(); | |
| 132 | + | |
| 133 | + // Extract and parse the content field | |
| 134 | + if (jsonResponse.content) { | |
| 135 | + // Parse the YAML/JSON content | |
| 136 | + const parsedContent = await processor.parseContent( | |
| 137 | + jsonResponse.content, | |
| 138 | + `${slug}.yaml`, | |
| 139 | + ); | |
| 140 | + return parsedContent; | |
| 141 | + } else { | |
| 142 | + // If there's no content field, return the response as-is (backward compatibility) | |
| 143 | + return jsonResponse; | |
| 144 | + } | |
| 115 | 145 | } else { |
| 116 | 146 | // v0 endpoints return zip files |
| 117 | 147 | const arrayBuffer = await response.arrayBuffer(); |
modified extensions/cli/src/loadMcpFromHub.test.ts +6 −1
| @@ -62,7 +62,12 @@ | ||
| 62 | 62 | }); |
| 63 | 63 | |
| 64 | 64 | const result = await loadMcpFromHub("continuedev/test-mcp"); |
| 65 | - expect(result).toEqual(mockConfig); | |
| 65 | + // Should now parse the YAML content and return the parsed object | |
| 66 | + expect(result).toEqual({ | |
| 67 | + name: "test-mcp", | |
| 68 | + command: "npx test-mcp", | |
| 69 | + args: ["--port", 3000] | |
| 70 | + }); | |
| 66 | 71 | }); |
| 67 | 72 | |
| 68 | 73 | it("should handle missing configuration files", async () => { |