@@ -202,4 +202,91 @@ describe("settings", () => {
202202 verbose: false,
203203 });
204204 });
205+
206+ test("loadSettings parses valid customProviders entries", () => {
207+ const dir = createTempDir();
208+ const path = join(dir, "settings.json");
209+ writeFileSync(
210+ path,
211+ JSON.stringify({
212+ customProviders: [
213+ { name: "ollama", baseUrl: "http://localhost:11434/v1" },
214+ {
215+ name: "lm-studio",
216+ baseUrl: "http://localhost:1234/v1",
217+ apiKey: "lm-studio",
218+ },
219+ ],
220+ }),
221+ "utf-8",
222+ );
223+
224+ const settings = loadSettings(path);
225+ expect(settings.customProviders).toEqual([
226+ { name: "ollama", baseUrl: "http://localhost:11434/v1" },
227+ {
228+ name: "lm-studio",
229+ baseUrl: "http://localhost:1234/v1",
230+ apiKey: "lm-studio",
231+ },
232+ ]);
233+ });
234+
235+ test("loadSettings drops customProviders entries with missing or invalid fields", () => {
236+ const dir = createTempDir();
237+ const path = join(dir, "settings.json");
238+ writeFileSync(
239+ path,
240+ JSON.stringify({
241+ customProviders: [
242+ { name: "good", baseUrl: "http://localhost:11434/v1" },
243+ { name: "", baseUrl: "http://localhost:1234/v1" },
244+ { name: "no-url" },
245+ { baseUrl: "http://localhost:5678/v1" },
246+ "not-an-object",
247+ 42,
248+ null,
249+ ],
250+ }),
251+ "utf-8",
252+ );
253+
254+ const settings = loadSettings(path);
255+ expect(settings.customProviders).toEqual([
256+ { name: "good", baseUrl: "http://localhost:11434/v1" },
257+ ]);
258+ });
259+
260+ test("loadSettings drops duplicate customProviders names keeping the first", () => {
261+ const dir = createTempDir();
262+ const path = join(dir, "settings.json");
263+ writeFileSync(
264+ path,
265+ JSON.stringify({
266+ customProviders: [
267+ { name: "ollama", baseUrl: "http://localhost:11434/v1" },
268+ { name: "ollama", baseUrl: "http://localhost:9999/v1" },
269+ ],
270+ }),
271+ "utf-8",
272+ );
273+
274+ const settings = loadSettings(path);
275+ expect(settings.customProviders).toEqual([
276+ { name: "ollama", baseUrl: "http://localhost:11434/v1" },
277+ ]);
278+ });
279+
280+ test("loadSettings omits customProviders when the field is not an array", () => {
281+ const dir = createTempDir();
282+ const path = join(dir, "settings.json");
283+ writeFileSync(
284+ path,
285+ JSON.stringify({ customProviders: "not-an-array" }),
286+ "utf-8",
287+ );
288+
289+ const settings = loadSettings(path);
290+ expect(settings.customProviders).toBeUndefined();
291+ });
205292 });