Просмотр исходного кода

test(core): lookupModel + listEnabledModels coverage for A group

fanghanjun 6 месяцев назад
Родитель
Сommit
40b0492c8f
1 измененных файлов с 62 добавлено и 0 удалено
  1. 62 0
      packages/core/src/__tests__/providers-lookup.test.ts

+ 62 - 0
packages/core/src/__tests__/providers-lookup.test.ts

@@ -0,0 +1,62 @@
+import { describe, it, expect } from "vitest";
+import { lookupModel, listEnabledModels } from "../llm/providers/lookup.js";
+
+describe("lookupModel", () => {
+  describe("Layer 1(已知 provider 精确查)", () => {
+    it("anthropic 下 claude-sonnet-4-6 命中 provider.models", () => {
+      const hit = lookupModel("anthropic", "claude-sonnet-4-6");
+      expect(hit).toBeDefined();
+      expect(hit?.maxOutput).toBe(64_000);
+      expect(hit?.contextWindowTokens).toBe(1_000_000);
+    });
+
+    it("openai 下 gpt-4o 命中", () => {
+      const hit = lookupModel("openai", "gpt-4o");
+      expect(hit).toBeDefined();
+      expect(hit?.maxOutput).toBe(4096);
+      expect(hit?.contextWindowTokens).toBe(128_000);
+    });
+
+    it("大小写不敏感", () => {
+      const hit = lookupModel("anthropic", "CLAUDE-SONNET-4-6");
+      expect(hit?.maxOutput).toBe(64_000);
+    });
+  });
+
+  describe("Layer 2(全局扫按优先级)", () => {
+    it("custom 下 gpt-4o 命中 openai provider", () => {
+      const hit = lookupModel("custom", "gpt-4o");
+      expect(hit?.maxOutput).toBe(4096);
+    });
+
+    it("custom 下 claude-sonnet-4-6 命中 anthropic provider", () => {
+      const hit = lookupModel("custom", "claude-sonnet-4-6");
+      expect(hit?.maxOutput).toBe(64_000);
+    });
+
+    it("未知 id 返回 undefined", () => {
+      const hit = lookupModel("custom", "my-private-llm-does-not-exist");
+      expect(hit).toBeUndefined();
+    });
+  });
+
+  describe("Layer 2 优先级排序(B 组之后会覆盖更多场景)", () => {
+    it("当同 id 在多个 provider 都存在时按 PROVIDER_PRIORITY 排序", () => {
+      const hit = lookupModel("custom", "deepseek-chat");
+      expect(hit?.maxOutput).toBeGreaterThan(0);
+    });
+  });
+});
+
+describe("listEnabledModels", () => {
+  it("返回 provider 里 enabled !== false 的 models", () => {
+    const models = listEnabledModels("anthropic");
+    expect(models.length).toBeGreaterThan(0);
+    expect(models.every((m) => m.enabled !== false)).toBe(true);
+  });
+
+  it("未知 service 返回空数组", () => {
+    const models = listEnabledModels("nope");
+    expect(models).toEqual([]);
+  });
+});