|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import type { ProviderCatalogEntry } from "./index.js"; |
| 4 | +import { buildProviderEntry } from "./providers.js"; |
| 5 | + |
| 6 | +const baseCatalog: ProviderCatalogEntry[] = [ |
| 7 | + { |
| 8 | + name: "bf", |
| 9 | + baseURL: "http://localhost:8080/v1", |
| 10 | + apiKey: "sk-bf-existing", |
| 11 | + models: ["m1"], |
| 12 | + bifrostVirtualKey: true, |
| 13 | + }, |
| 14 | + { |
| 15 | + name: "openai", |
| 16 | + baseURL: "https://api.openai.com/v1", |
| 17 | + apiKey: "sk-openai", |
| 18 | + models: ["gpt-4o"], |
| 19 | + }, |
| 20 | +]; |
| 21 | + |
| 22 | +describe("buildProviderEntry bifrostVirtualKey preserve-on-edit", () => { |
| 23 | + test("keeps existing bifrostVirtualKey when submission omits the flag", () => { |
| 24 | + const result = buildProviderEntry( |
| 25 | + { |
| 26 | + name: "bf", |
| 27 | + originalName: "bf", |
| 28 | + baseURL: "http://localhost:8080/v1", |
| 29 | + models: ["m1", "m2"], |
| 30 | + }, |
| 31 | + baseCatalog, |
| 32 | + ); |
| 33 | + |
| 34 | + expect(result.ok).toBe(true); |
| 35 | + if (!result.ok) return; |
| 36 | + expect(result.entry.bifrostVirtualKey).toBe(true); |
| 37 | + }); |
| 38 | + |
| 39 | + test("omits bifrostVirtualKey when existing entry has no flag", () => { |
| 40 | + const result = buildProviderEntry( |
| 41 | + { |
| 42 | + name: "openai", |
| 43 | + originalName: "openai", |
| 44 | + baseURL: "https://api.openai.com/v1", |
| 45 | + models: ["gpt-4o-mini"], |
| 46 | + }, |
| 47 | + baseCatalog, |
| 48 | + ); |
| 49 | + |
| 50 | + expect(result.ok).toBe(true); |
| 51 | + if (!result.ok) return; |
| 52 | + expect(result.entry.bifrostVirtualKey).toBeUndefined(); |
| 53 | + }); |
| 54 | +}); |
0 commit comments