Skip to content
Source
Sign inSign up

textGenerators.test.ts

40 lines1.6 KB

1import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { nextTextGeneratorId, textGeneratorBrand } from "./textGenerators";
5​
6describe("nextTextGeneratorId", () => {
7 it("skips ids that would make a selection name another target", () => {
8 const settings = {
9 providerInstances: {
10 [ProviderInstanceId.make("openai")]: { driver: ProviderDriverKind.make("codex") },
11 },
12 textGenerators: {
13 [ProviderInstanceId.make("openai-2")]: {
14 kind: "openaiCompatible" as const,
15 baseUrl: "https://api.openai.com/v1",
16 apiKey: "",
17 enabled: true,
18 },
19 },
20 };
21 const providers = [{ instanceId: ProviderInstanceId.make("openai-3") }];
22​
23 expect(nextTextGeneratorId("openai", settings, providers)).toBe("openai-4");
24 // A driver's default instance id is taken even before it has a snapshot or config.
25 expect(nextTextGeneratorId("cursor", settings, [])).toBe("cursor-2");
26 expect(nextTextGeneratorId("openrouter", settings, providers)).toBe("openrouter");
27 });
28});
29​
30describe("textGeneratorBrand", () => {
31 it.each([
32 ["anthropic", "https://proxy.example/v1", "anthropic"],
33 ["openaiCompatible", "https://openrouter.ai/api/v1", "openrouter"],
34 ["openaiCompatible", "https://api.openai.com/v1", "openai"],
35 ["openaiCompatible", "http://localhost:11434/v1", "ollama"],
36 ["openaiCompatible", "http://localhost:1234/v1", "openaiCompatible"],
37 ] as const)("%s at %s shows the %s icon", (kind, baseUrl, brand) => {
38 expect(textGeneratorBrand({ kind, baseUrl })).toBe(brand);
39 });
40});