|
| 1 | +import { |
| 2 | + applyNanoGptRoutingPreference, |
| 3 | + dynamicProviders, |
| 4 | + getModelId, |
| 5 | + getProviderDefaultModelId, |
| 6 | + isSecretStateKey, |
| 7 | + nanoGptDefaultModelId, |
| 8 | + nanoGptDefaultRoutingPreference, |
| 9 | + providerIdentifiers, |
| 10 | + providerSettingsSchema, |
| 11 | +} from "../index.js" |
| 12 | + |
| 13 | +describe("NanoGPT shared contract", () => { |
| 14 | + it("registers the stable dynamic-provider identity and default model", () => { |
| 15 | + expect(providerIdentifiers.nanogpt).toBe("nanogpt") |
| 16 | + expect(dynamicProviders).toContain("nanogpt") |
| 17 | + expect(getProviderDefaultModelId("nanogpt")).toBe(nanoGptDefaultModelId) |
| 18 | + }) |
| 19 | + |
| 20 | + it("classifies the API key as secret and resolves missing routing to auto", () => { |
| 21 | + expect(isSecretStateKey("nanoGptApiKey")).toBe(true) |
| 22 | + const settings = providerSettingsSchema.parse({ apiProvider: "nanogpt", nanoGptModelId: "model" }) |
| 23 | + expect(settings.nanoGptRoutingPreference ?? nanoGptDefaultRoutingPreference).toBe("auto") |
| 24 | + expect(getModelId(settings)).toBe("model") |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +describe("applyNanoGptRoutingPreference", () => { |
| 29 | + it.each([ |
| 30 | + ["auto", "model"], |
| 31 | + ["fast", "model:fast"], |
| 32 | + ["cheap", "model:cheap"], |
| 33 | + ["latency", "model:latency"], |
| 34 | + ["throughput", "model:throughput"], |
| 35 | + ["tools", "model:tools"], |
| 36 | + ["caching", "model"], |
| 37 | + ] as const)("maps %s routing", (preference, expected) => { |
| 38 | + expect(applyNanoGptRoutingPreference("model", preference)).toBe(expected) |
| 39 | + }) |
| 40 | + |
| 41 | + it.each([ |
| 42 | + "speed", |
| 43 | + "fast", |
| 44 | + "throughput", |
| 45 | + "latency", |
| 46 | + "price", |
| 47 | + "cheap", |
| 48 | + "floor", |
| 49 | + "tools", |
| 50 | + "caching", |
| 51 | + "cache", |
| 52 | + "cached", |
| 53 | + ])("replaces the recognized %s routing alias", (alias) => { |
| 54 | + expect(applyNanoGptRoutingPreference(`model:thinking:${alias}`, "cheap")).toBe("model:thinking:cheap") |
| 55 | + expect(applyNanoGptRoutingPreference(`model:thinking:${alias}`, "auto")).toBe("model:thinking") |
| 56 | + }) |
| 57 | + |
| 58 | + it("preserves legitimate identity suffixes", () => { |
| 59 | + expect(applyNanoGptRoutingPreference("model:thinking", "fast")).toBe("model:thinking:fast") |
| 60 | + expect(applyNanoGptRoutingPreference("model:thinking", "auto")).toBe("model:thinking") |
| 61 | + }) |
| 62 | + |
| 63 | + it("normalizes multiple trailing routing suffixes to exactly one active preference", () => { |
| 64 | + expect(applyNanoGptRoutingPreference("model:thinking:fast:cheap", "latency")).toBe("model:thinking:latency") |
| 65 | + expect(applyNanoGptRoutingPreference("model:thinking:FAST:CACHED", "auto")).toBe("model:thinking") |
| 66 | + }) |
| 67 | +}) |
0 commit comments