|
| 1 | +// Verifies catalog-backed endpoint classification for externalized official providers. |
| 2 | +import { describe, expect, it, vi } from "vitest"; |
| 3 | + |
| 4 | +// Simulates a built dist tree: externalized provider plugins (qwen, moonshot, |
| 5 | +// zai, ...) are excluded from dist packaging, so no plugin manifest supplies |
| 6 | +// their endpoint metadata. Classification must come from the bundled catalog. |
| 7 | +// The single conflicting manifest entry proves installed manifests stay |
| 8 | +// authoritative over catalog metadata (first match wins). |
| 9 | +vi.mock("../plugins/manifest-metadata-scan.js", () => ({ |
| 10 | + listOpenClawPluginManifestMetadata: () => [ |
| 11 | + { |
| 12 | + pluginDir: "installed-conflict-fixture", |
| 13 | + manifest: { |
| 14 | + providerEndpoints: [ |
| 15 | + { endpointClass: "openai-public", hosts: ["coding.dashscope.aliyuncs.com"] }, |
| 16 | + ], |
| 17 | + }, |
| 18 | + origin: "installed", |
| 19 | + }, |
| 20 | + ], |
| 21 | +})); |
| 22 | + |
| 23 | +import { |
| 24 | + resolveProviderEndpoint, |
| 25 | + resolveProviderRequestCapabilities, |
| 26 | +} from "./provider-attribution.js"; |
| 27 | + |
| 28 | +describe("catalog-backed provider endpoint classification", () => { |
| 29 | + it.each([ |
| 30 | + ["https://dashscope.aliyuncs.com/compatible-mode/v1", "modelstudio-native"], |
| 31 | + ["https://dashscope-intl.aliyuncs.com/compatible-mode/v1", "modelstudio-native"], |
| 32 | + ["https://coding-intl.dashscope.aliyuncs.com/v1", "modelstudio-native"], |
| 33 | + ["https://api.moonshot.ai/v1", "moonshot-native"], |
| 34 | + ["https://api.moonshot.cn/v1", "moonshot-native"], |
| 35 | + ["https://api.z.ai/api/coding/paas/v4", "zai-native"], |
| 36 | + ["https://api.deepseek.com", "deepseek-native"], |
| 37 | + ["https://api.groq.com/openai/v1", "groq-native"], |
| 38 | + ["https://api.cerebras.ai/v1", "cerebras-native"], |
| 39 | + ["https://llm.chutes.ai/v1", "chutes-native"], |
| 40 | + ])("classifies %s as %s without an installed plugin manifest", (baseUrl, endpointClass) => { |
| 41 | + expect(resolveProviderEndpoint(baseUrl).endpointClass).toBe(endpointClass); |
| 42 | + }); |
| 43 | + |
| 44 | + it("resolves DashScope request capabilities from catalog metadata", () => { |
| 45 | + // Image describe placement and streaming-usage compat both key off this |
| 46 | + // classification; see shouldPlaceImagePromptInUserContent and |
| 47 | + // normalizeModelCompat regressions when qwen was externalized. |
| 48 | + const capabilities = resolveProviderRequestCapabilities({ |
| 49 | + provider: "qwen", |
| 50 | + api: "openai-completions", |
| 51 | + baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1", |
| 52 | + capability: "image", |
| 53 | + transport: "media-understanding", |
| 54 | + }); |
| 55 | + expect(capabilities.endpointClass).toBe("modelstudio-native"); |
| 56 | + expect(capabilities.supportsNativeStreamingUsageCompat).toBe(true); |
| 57 | + expect(capabilities.isKnownNativeEndpoint).toBe(true); |
| 58 | + }); |
| 59 | + |
| 60 | + it("prefers installed plugin manifest endpoints over catalog metadata", () => { |
| 61 | + expect(resolveProviderEndpoint("https://coding.dashscope.aliyuncs.com/v1").endpointClass).toBe( |
| 62 | + "openai-public", |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + it("keeps unknown hosts classified as custom", () => { |
| 67 | + expect(resolveProviderEndpoint("https://proxy.example.com/v1").endpointClass).toBe("custom"); |
| 68 | + }); |
| 69 | + |
| 70 | + it("drops catalog endpoint classes core does not recognize", () => { |
| 71 | + // qwen-portal-native, deepinfra-native, and gmi-native are mirrored |
| 72 | + // faithfully from their manifests but are not core ProviderEndpointClass |
| 73 | + // members, so they must stay inert (same filtering as installed manifests). |
| 74 | + expect(resolveProviderEndpoint("https://portal.qwen.ai/v1").endpointClass).toBe("custom"); |
| 75 | + expect(resolveProviderEndpoint("https://api.deepinfra.com/v1/openai").endpointClass).toBe( |
| 76 | + "custom", |
| 77 | + ); |
| 78 | + expect(resolveProviderEndpoint("https://api.gmi-serving.com/v1").endpointClass).toBe("custom"); |
| 79 | + }); |
| 80 | +}); |
0 commit comments