test: add vitest for autodetect next edit

This commit is contained in:
Jacob Kim 2025-08-06 15:59:27 -07:00
parent 6a31f985b0
commit 3c51d54cc2

View file

@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { autodetectTemplateType } from "./autodetect";
import { describe, expect, it, test } from "vitest";
import { autodetectTemplateType, modelSupportsNextEdit } from "./autodetect";
test("autodetectTemplateType returns 'codellama-70b' for CodeLlama 70B models", () => {
expect(autodetectTemplateType("codellama-70b")).toBe("codellama-70b");
@ -201,3 +201,125 @@ test("autodetectTemplateType handles models with mixed keywords", () => {
expect(autodetectTemplateType("gpt-llama")).toBe(undefined); // gpt comes first, returns undefined
expect(autodetectTemplateType("claude-llama")).toBe("llama2"); // llama comes first, returns llama2
});
describe("modelSupportsNextEdit", () => {
describe("when capabilities.nextEdit is defined", () => {
it("should return true when capabilities.nextEdit is true", () => {
const result = modelSupportsNextEdit("any-model", "Any Title", {
nextEdit: true,
});
expect(result).toBe(true);
});
it("should return false when capabilities.nextEdit is false", () => {
const result = modelSupportsNextEdit(
"mercury-coder-nextedit",
"Mercury Coder",
{ nextEdit: false },
);
expect(result).toBe(false);
});
it("should prioritize capabilities over model name matching", () => {
// Even though model name matches, capabilities should take precedence.
const result = modelSupportsNextEdit(
"mercury-coder-nextedit",
"Mercury Coder",
{ nextEdit: false },
);
expect(result).toBe(false);
});
});
describe("when capabilities.nextEdit is undefined", () => {
it("should return true for mercury-coder-nextedit model (case insensitive)", () => {
expect(
modelSupportsNextEdit("Mercury-Coder-Nextedit", undefined, undefined),
).toBe(true);
});
it("should return true for model-1", () => {
expect(modelSupportsNextEdit("model-1", undefined, undefined)).toBe(true);
});
it("should return true when model contains supported model name as substring", () => {
expect(
modelSupportsNextEdit(
"provider/mercury-coder-nextedit-v2",
undefined,
undefined,
),
).toBe(true);
});
it("should return true when title contains supported model name", () => {
expect(
modelSupportsNextEdit(
"some-model",
"This is mercury-coder-nextedit model",
undefined,
),
).toBe(true);
});
it("should return true when title contains model-1", () => {
expect(
modelSupportsNextEdit("some-model", "model-1 deployment", undefined),
).toBe(true);
});
it("should return true for unsupported models that have capabilities explicitly set to true", () => {
expect(
modelSupportsNextEdit("gpt-4", "GPT-4 Model", {
nextEdit: true,
}),
).toBe(true);
});
it("should return false for unsupported models", () => {
expect(modelSupportsNextEdit("gpt-4", "GPT-4 Model", undefined)).toBe(
false,
);
});
it("should return false when model and title are both undefined/null", () => {
expect(modelSupportsNextEdit("", undefined, undefined)).toBe(false);
});
it("should return false when model and title do not contain supported names", () => {
expect(
modelSupportsNextEdit("claude-3", "Claude 3 Sonnet", undefined),
).toBe(false);
});
});
describe("edge cases", () => {
it("should handle empty strings", () => {
expect(modelSupportsNextEdit("", "", undefined)).toBe(false);
});
it("should handle undefined title gracefully", () => {
expect(
modelSupportsNextEdit("mercury-coder-nextedit", undefined, undefined),
).toBe(true);
});
it("should handle case sensitivity correctly", () => {
expect(
modelSupportsNextEdit("MERCURY-CODER-NEXTEDIT", "MODEL-1", undefined),
).toBe(true);
});
it("should handle capabilities with other properties", () => {
expect(
modelSupportsNextEdit("unsupported-model", undefined, {
nextEdit: true,
uploadImage: false,
}),
).toBe(true);
});
});
});