Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { rankModelPickerSearch, scoreModelPickerSearch } from "./modelSearch.ts";
4
5describe("scoreModelPickerSearch", () => {
6 it("ranks exact token matches ahead of fuzzier matches", () => {
7 const exactScore = scoreModelPickerSearch(
8 {
9 driverKind: "opencode",
10 providerDisplayName: "opencode",
11 name: "Claude Opus 4.7",
12 subProvider: "GitHub Copilot",
13 },
14 "copilot opus",
15 );
16 const fuzzyScore = scoreModelPickerSearch(
17 {
18 driverKind: "opencode",
19 providerDisplayName: "opencode",
20 name: "Claude Opus 4.7",
21 subProvider: "GitHub Copilot",
22 },
23 "coplt op",
24 );
25
26 expect(exactScore).not.toBeNull();
27 expect(fuzzyScore).not.toBeNull();
28 expect(exactScore!).toBeLessThan(fuzzyScore!);
29 });
30
31 it("does not let the favorite boost outrank clearly better textual matches", () => {
32 const favoriteScore = scoreModelPickerSearch(
33 {
34 driverKind: "claudeAgent",
35 providerDisplayName: "Claude",
36 name: "Claude Opus 4.7",
37 isFavorite: true,
38 },
39 "opus 4.7",
40 );
41 const nonFavoriteExactScore = scoreModelPickerSearch(
42 {
43 driverKind: "cursor",
44 providerDisplayName: "Cursor",
45 name: "Opus 4.7",
46 },
47 "opus 4.7",
48 );
49
50 expect(favoriteScore).not.toBeNull();
51 expect(nonFavoriteExactScore).not.toBeNull();
52 expect(nonFavoriteExactScore!).toBeLessThan(favoriteScore!);
53 });
54});
55
56type CatalogModel = {
57 driverKind: string;
58 providerDisplayName: string;
59 name: string;
60 slug?: string;
61 subProvider?: string;
62 isFavorite?: boolean;
63};
64
65function instanceModels(
66 driverKind: string,
67 providerDisplayName: string,
68 names: ReadonlyArray<string>,
69): CatalogModel[] {
70 return names.map((name) => ({ driverKind, providerDisplayName, name }));
71}
72
73const catalog: CatalogModel[] = [
74 ...instanceModels("claudeAgent", "Claude", [
75 "Claude Opus 5.5",
76 "Claude Sonnet 5.5",
77 "Claude Fable 5.1",
78 "Claude Fable 5",
79 "Claude Opus 5",
80 "Claude Opus 4.8",
81 "Claude Opus 4.7",
82 "Claude Opus 4.6",
83 "Claude Opus 4.5",
84 "Claude Sonnet 5",
85 "Claude Sonnet 4.6",
86 "Claude Haiku 5.5",
87 "Claude Haiku 4.5",
88 ]),
89 ...instanceModels("codex", "Codex", [
90 "GPT-6.1 Sol",
91 "GPT-6 Astra",
92 "GPT-6 Luna",
93 "GPT-6 Sol",
94 "GPT-5.6 Sol",
95 "GPT-5.6 Terra",
96 "GPT-5.6 Luna",
97 "GPT-5.5",
98 ]),
99 ...instanceModels("grok", "Grok", ["Grok 4.7", "Grok 4.6", "Grok 4.5"]),
100 ...instanceModels("antigravity", "Antigravity", [
101 "Gemini 3.8 Flash (High)",
102 "Gemini 3.8 Flash (Medium)",
103 "Gemini 3.8 Flash (Low)",
104 "Gemini 3.7 Flash (High)",
105 "Gemini 3.7 Flash (Medium)",
106 "Gemini 3.7 Flash (Low)",
107 "Gemini 3.6 Flash (High)",
108 "Gemini 3.6 Flash (Medium)",
109 "Gemini 3.6 Flash (Low)",
110 "Gemini 3.1 Pro (High)",
111 "Gemini 3.1 Pro (Low)",
112 ]),
113 {
114 driverKind: "opencode",
115 providerDisplayName: "OpenCode",
116 name: "Kimi K3",
117 subProvider: "Moonshot",
118 },
119 {
120 driverKind: "opencode",
121 providerDisplayName: "OpenCode",
122 name: "Kimi K2.5",
123 subProvider: "Moonshot",
124 },
125 {
126 driverKind: "opencode",
127 providerDisplayName: "OpenCode",
128 name: "Kimi K2",
129 subProvider: "Moonshot",
130 },
131 {
132 driverKind: "opencode",
133 providerDisplayName: "OpenCode",
134 name: "DeepSeek V4.1 Flash 1017",
135 slug: "opencode-go/deepseek-v4.1-flash",
136 subProvider: "OpenCode Go",
137 },
138];
139
140function search(query: string, models: ReadonlyArray<CatalogModel> = catalog): string[] {
141 return rankModelPickerSearch(models, query, (model) => model).map((model) => model.name);
142}
143
144describe("rankModelPickerSearch", () => {
145 it("keeps newest first when a version token narrows the family", () => {
146 expect(search("opus 4")).toEqual([
147 "Claude Opus 4.8",
148 "Claude Opus 4.7",
149 "Claude Opus 4.6",
150 "Claude Opus 4.5",
151 ]);
152 expect(search("opus 5")).toEqual(["Claude Opus 5.5", "Claude Opus 5", "Claude Opus 4.5"]);
153 expect(search("opus 5.")).toEqual(["Claude Opus 5.5"]);
154 });
155
156 it("still ranks an exact name above newer models that extend it", () => {
157 expect(search("gpt-6 sol").slice(0, 2)).toEqual(["GPT-6 Sol", "GPT-6.1 Sol"]);
158 expect(search("claude opus 5").slice(0, 2)).toEqual(["Claude Opus 5", "Claude Opus 5.5"]);
159 expect(search("Grok 4.6")[0]).toBe("Grok 4.6");
160 });
161
162 it("matches the provider when the name does not", () => {
163 expect(search("moonshot")).toEqual(["Kimi K3", "Kimi K2.5", "Kimi K2"]);
164 });
165
166 it("finds a model by its full or bare ID when the name is written differently", () => {
167 expect(search("opencode-go/deepseek-v4.1-flash")).toEqual(["DeepSeek V4.1 Flash 1017"]);
168 expect(search("deepseek-v4.1-flash")).toEqual(["DeepSeek V4.1 Flash 1017"]);
169 });
170
171 it("ranks a favorite above newer models in the same family", () => {
172 const models = catalog.map((model) =>
173 model.name === "Claude Opus 4.5" ? { ...model, isFavorite: true } : model,
174 );
175 expect(search("opus", models).slice(0, 3)).toEqual([
176 "Claude Opus 4.5",
177 "Claude Opus 5.5",
178 "Claude Opus 5",
179 ]);
180 });
181});