|
1 | | -import { expect, test } from "vitest"; |
2 | | -import { autodetectTemplateType } from "./autodetect"; |
| 1 | +import { describe, expect, it, test } from "vitest"; |
| 2 | +import { autodetectTemplateType, modelSupportsNextEdit } from "./autodetect"; |
3 | 3 |
|
4 | 4 | test("autodetectTemplateType returns 'codellama-70b' for CodeLlama 70B models", () => { |
5 | 5 | expect(autodetectTemplateType("codellama-70b")).toBe("codellama-70b"); |
@@ -201,3 +201,137 @@ test("autodetectTemplateType handles models with mixed keywords", () => { |
201 | 201 | expect(autodetectTemplateType("gpt-llama")).toBe(undefined); // gpt comes first, returns undefined |
202 | 202 | expect(autodetectTemplateType("claude-llama")).toBe("llama2"); // llama comes first, returns llama2 |
203 | 203 | }); |
| 204 | + |
| 205 | +describe("modelSupportsNextEdit", () => { |
| 206 | + describe("when capabilities.nextEdit is defined", () => { |
| 207 | + it("should return true when capabilities.nextEdit is true", () => { |
| 208 | + expect( |
| 209 | + modelSupportsNextEdit( |
| 210 | + { |
| 211 | + nextEdit: true, |
| 212 | + }, |
| 213 | + "any-model", |
| 214 | + "Any Title", |
| 215 | + ), |
| 216 | + ).toBe(true); |
| 217 | + }); |
| 218 | + |
| 219 | + it("should return false when capabilities.nextEdit is false", () => { |
| 220 | + expect( |
| 221 | + modelSupportsNextEdit( |
| 222 | + { nextEdit: false }, |
| 223 | + "mercury-coder-nextedit", |
| 224 | + "Mercury Coder", |
| 225 | + ), |
| 226 | + ).toBe(false); |
| 227 | + }); |
| 228 | + |
| 229 | + it("should prioritize capabilities over model name matching", () => { |
| 230 | + // Even though model name matches, capabilities should take precedence. |
| 231 | + expect( |
| 232 | + modelSupportsNextEdit( |
| 233 | + { nextEdit: false }, |
| 234 | + "mercury-coder-nextedit", |
| 235 | + "Mercury Coder", |
| 236 | + ), |
| 237 | + ).toBe(false); |
| 238 | + }); |
| 239 | + }); |
| 240 | + |
| 241 | + describe("when capabilities.nextEdit is undefined", () => { |
| 242 | + it("should return true for mercury-coder-nextedit model (case insensitive)", () => { |
| 243 | + expect( |
| 244 | + modelSupportsNextEdit(undefined, "Mercury-Coder-Nextedit", undefined), |
| 245 | + ).toBe(true); |
| 246 | + }); |
| 247 | + |
| 248 | + it("should return true for model-1", () => { |
| 249 | + expect(modelSupportsNextEdit(undefined, "model-1", undefined)).toBe(true); |
| 250 | + }); |
| 251 | + |
| 252 | + it("should return true when model contains supported model name as substring", () => { |
| 253 | + expect( |
| 254 | + modelSupportsNextEdit( |
| 255 | + undefined, |
| 256 | + "provider/mercury-coder-nextedit-v2", |
| 257 | + undefined, |
| 258 | + ), |
| 259 | + ).toBe(true); |
| 260 | + }); |
| 261 | + |
| 262 | + it("should return true when title contains supported model name", () => { |
| 263 | + expect( |
| 264 | + modelSupportsNextEdit( |
| 265 | + undefined, |
| 266 | + "some-model", |
| 267 | + "This is mercury-coder-nextedit model", |
| 268 | + ), |
| 269 | + ).toBe(true); |
| 270 | + }); |
| 271 | + |
| 272 | + it("should return true when title contains model-1", () => { |
| 273 | + expect( |
| 274 | + modelSupportsNextEdit(undefined, "some-model", "model-1 deployment"), |
| 275 | + ).toBe(true); |
| 276 | + }); |
| 277 | + |
| 278 | + it("should return true for unsupported models that have capabilities explicitly set to true", () => { |
| 279 | + expect( |
| 280 | + modelSupportsNextEdit( |
| 281 | + { |
| 282 | + nextEdit: true, |
| 283 | + }, |
| 284 | + "gpt-4", |
| 285 | + "GPT-4 Model", |
| 286 | + ), |
| 287 | + ).toBe(true); |
| 288 | + }); |
| 289 | + |
| 290 | + it("should return false for unsupported models", () => { |
| 291 | + expect(modelSupportsNextEdit(undefined, "gpt-4", "GPT-4 Model")).toBe( |
| 292 | + false, |
| 293 | + ); |
| 294 | + }); |
| 295 | + |
| 296 | + it("should return false when model and title are both undefined/null", () => { |
| 297 | + expect(modelSupportsNextEdit(undefined, "", undefined)).toBe(false); |
| 298 | + }); |
| 299 | + |
| 300 | + it("should return false when model and title do not contain supported names", () => { |
| 301 | + expect( |
| 302 | + modelSupportsNextEdit(undefined, "claude-3", "Claude 3 Sonnet"), |
| 303 | + ).toBe(false); |
| 304 | + }); |
| 305 | + }); |
| 306 | + |
| 307 | + describe("edge cases", () => { |
| 308 | + it("should handle empty strings", () => { |
| 309 | + expect(modelSupportsNextEdit(undefined, "", "")).toBe(false); |
| 310 | + }); |
| 311 | + |
| 312 | + it("should handle undefined title gracefully", () => { |
| 313 | + expect( |
| 314 | + modelSupportsNextEdit(undefined, "mercury-coder-nextedit", undefined), |
| 315 | + ).toBe(true); |
| 316 | + }); |
| 317 | + |
| 318 | + it("should handle case sensitivity correctly", () => { |
| 319 | + expect( |
| 320 | + modelSupportsNextEdit(undefined, "MERCURY-CODER-NEXTEDIT", "MODEL-1"), |
| 321 | + ).toBe(true); |
| 322 | + }); |
| 323 | + |
| 324 | + it("should handle capabilities with other properties", () => { |
| 325 | + expect( |
| 326 | + modelSupportsNextEdit( |
| 327 | + { |
| 328 | + nextEdit: true, |
| 329 | + uploadImage: false, |
| 330 | + }, |
| 331 | + "unsupported-model", |
| 332 | + undefined, |
| 333 | + ), |
| 334 | + ).toBe(true); |
| 335 | + }); |
| 336 | + }); |
| 337 | +}); |
0 commit comments