|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { shouldUseSingleFileRead } from "../single-file-read-models.js" |
| 3 | + |
| 4 | +describe("shouldUseSingleFileRead", () => { |
| 5 | + describe("with user setting", () => { |
| 6 | + it("should return true when useSingleFileReadMode is true, regardless of model", () => { |
| 7 | + // Test various models when user setting is enabled |
| 8 | + expect(shouldUseSingleFileRead("claude-3-5-sonnet", true)).toBe(true) |
| 9 | + expect(shouldUseSingleFileRead("gpt-4", true)).toBe(true) |
| 10 | + expect(shouldUseSingleFileRead("qwen-coder", true)).toBe(true) |
| 11 | + expect(shouldUseSingleFileRead("any-random-model", true)).toBe(true) |
| 12 | + }) |
| 13 | + |
| 14 | + it("should return false when useSingleFileReadMode is false and model is not in the list", () => { |
| 15 | + // Test models that are not in the single-file list when user setting is disabled |
| 16 | + expect(shouldUseSingleFileRead("claude-3-5-sonnet", false)).toBe(false) |
| 17 | + expect(shouldUseSingleFileRead("gpt-4", false)).toBe(false) |
| 18 | + expect(shouldUseSingleFileRead("qwen-coder", false)).toBe(false) |
| 19 | + }) |
| 20 | + |
| 21 | + it("should respect false setting even for models that normally use single-file mode", () => { |
| 22 | + // When user explicitly sets to false, it should override model defaults |
| 23 | + expect(shouldUseSingleFileRead("grok-code-fast-1", false)).toBe(false) |
| 24 | + expect(shouldUseSingleFileRead("code-supernova", false)).toBe(false) |
| 25 | + expect(shouldUseSingleFileRead("some-model-with-grok-code-fast-1-in-name", false)).toBe(false) |
| 26 | + }) |
| 27 | + }) |
| 28 | + |
| 29 | + describe("without user setting (undefined)", () => { |
| 30 | + it("should return true for models that include the special strings", () => { |
| 31 | + // Exact matches |
| 32 | + expect(shouldUseSingleFileRead("grok-code-fast-1", undefined)).toBe(true) |
| 33 | + expect(shouldUseSingleFileRead("code-supernova", undefined)).toBe(true) |
| 34 | + |
| 35 | + // Models that contain the special strings |
| 36 | + expect(shouldUseSingleFileRead("x/grok-code-fast-1", undefined)).toBe(true) |
| 37 | + expect(shouldUseSingleFileRead("provider/code-supernova-v2", undefined)).toBe(true) |
| 38 | + expect(shouldUseSingleFileRead("grok-code-fast-1-turbo", undefined)).toBe(true) |
| 39 | + }) |
| 40 | + |
| 41 | + it("should return false for models not in the single-file list", () => { |
| 42 | + expect(shouldUseSingleFileRead("claude-3-5-sonnet", undefined)).toBe(false) |
| 43 | + expect(shouldUseSingleFileRead("gpt-4", undefined)).toBe(false) |
| 44 | + expect(shouldUseSingleFileRead("gemini-pro", undefined)).toBe(false) |
| 45 | + expect(shouldUseSingleFileRead("any-other-model", undefined)).toBe(false) |
| 46 | + expect(shouldUseSingleFileRead("", undefined)).toBe(false) |
| 47 | + }) |
| 48 | + |
| 49 | + it("should return false when no parameters are provided", () => { |
| 50 | + expect(shouldUseSingleFileRead(undefined, undefined)).toBe(false) |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + describe("edge cases", () => { |
| 55 | + it("should handle empty model string", () => { |
| 56 | + expect(shouldUseSingleFileRead("", true)).toBe(true) // User setting takes precedence |
| 57 | + expect(shouldUseSingleFileRead("", false)).toBe(false) |
| 58 | + expect(shouldUseSingleFileRead("", undefined)).toBe(false) |
| 59 | + }) |
| 60 | + |
| 61 | + it("should handle undefined model", () => { |
| 62 | + expect(shouldUseSingleFileRead(undefined, true)).toBe(true) // User setting takes precedence |
| 63 | + expect(shouldUseSingleFileRead(undefined, false)).toBe(false) |
| 64 | + expect(shouldUseSingleFileRead(undefined, undefined)).toBe(false) |
| 65 | + }) |
| 66 | + |
| 67 | + it("should handle partial model name matches correctly", () => { |
| 68 | + // The function uses includes(), so partial matches matter |
| 69 | + expect(shouldUseSingleFileRead("grok-code", undefined)).toBe(false) // Doesn't include full "grok-code-fast-1" |
| 70 | + expect(shouldUseSingleFileRead("code-fast-1", undefined)).toBe(false) // Doesn't include full "grok-code-fast-1" |
| 71 | + expect(shouldUseSingleFileRead("supernova", undefined)).toBe(false) // Doesn't include full "code-supernova" |
| 72 | + expect(shouldUseSingleFileRead("grok", undefined)).toBe(false) // Too short |
| 73 | + expect(shouldUseSingleFileRead("code", undefined)).toBe(false) // Too short |
| 74 | + }) |
| 75 | + |
| 76 | + it("should be case-sensitive", () => { |
| 77 | + // The function uses includes() which is case-sensitive |
| 78 | + expect(shouldUseSingleFileRead("GROK-CODE-FAST-1", undefined)).toBe(false) |
| 79 | + expect(shouldUseSingleFileRead("Code-Supernova", undefined)).toBe(false) |
| 80 | + expect(shouldUseSingleFileRead("Grok-Code-Fast-1", undefined)).toBe(false) |
| 81 | + expect(shouldUseSingleFileRead("CODE-SUPERNOVA", undefined)).toBe(false) |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + describe("user preference priority", () => { |
| 86 | + it("should always prioritize explicit user preference over model defaults", () => { |
| 87 | + // User explicitly wants single-file mode for a model that doesn't require it |
| 88 | + expect(shouldUseSingleFileRead("claude-3-5-sonnet", true)).toBe(true) |
| 89 | + |
| 90 | + // User explicitly doesn't want single-file mode for models that typically require it |
| 91 | + expect(shouldUseSingleFileRead("grok-code-fast-1", false)).toBe(false) |
| 92 | + expect(shouldUseSingleFileRead("code-supernova", false)).toBe(false) |
| 93 | + expect(shouldUseSingleFileRead("provider/grok-code-fast-1-latest", false)).toBe(false) |
| 94 | + }) |
| 95 | + }) |
| 96 | +}) |
0 commit comments