6fada0c3ba
The endpoint-scoped Ollama cache key collapsed every base URL on the same origin. Catalog discovery preserves reverse-proxy path prefixes, so different tenants could still reuse one fresh cache row. Include the normalized native path in the cache fingerprint while removing only a terminal /v1 suffix and trailing slashes. Cover tenant isolation and equivalent native/OpenAI-compatible URL spellings. Fixes #7087
34 lines
1.8 KiB
TypeScript
34 lines
1.8 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { PROVIDER_DESCRIPTORS, resolveModelCacheProviderId } from "@oh-my-pi/pi-catalog/provider-models";
|
|
|
|
test("lightweight cache resolver matches every descriptor default", () => {
|
|
for (const descriptor of PROVIDER_DESCRIPTORS) {
|
|
const options = descriptor.createModelManagerOptions({});
|
|
expect(resolveModelCacheProviderId(descriptor.providerId)).toBe(options.cacheProviderId ?? descriptor.providerId);
|
|
}
|
|
});
|
|
|
|
test("lightweight cache resolver matches scoped descriptor inputs", () => {
|
|
const cases = [
|
|
{ providerId: "litellm", baseUrl: "http://litellm.example:4100/v1" },
|
|
{ providerId: "ollama", baseUrl: "http://ollama.example:11434/v1/" },
|
|
{ providerId: "opencode-go", baseUrl: "https://opencode.example/go" },
|
|
{ providerId: "opencode-zen", baseUrl: "https://opencode.example/zen/v1/" },
|
|
{ providerId: "vllm", baseUrl: "http://vllm.example:8000/v1" },
|
|
] as const;
|
|
for (const { providerId, baseUrl } of cases) {
|
|
const descriptor = PROVIDER_DESCRIPTORS.find(candidate => candidate.providerId === providerId);
|
|
if (!descriptor) throw new Error(`Missing descriptor for ${providerId}`);
|
|
const config = { apiKey: "cache-test-key", baseUrl };
|
|
const options = descriptor.createModelManagerOptions(config);
|
|
expect(resolveModelCacheProviderId(providerId, config)).toBe(options.cacheProviderId ?? providerId);
|
|
}
|
|
});
|
|
|
|
test("ollama cache scope preserves reverse-proxy path prefixes", () => {
|
|
const teamA = resolveModelCacheProviderId("ollama", { baseUrl: "https://proxy.example/team-a/v1/" });
|
|
expect(teamA).toBe(resolveModelCacheProviderId("ollama", { baseUrl: "https://proxy.example/team-a" }));
|
|
expect(teamA).toBe(resolveModelCacheProviderId("ollama", { baseUrl: "https://proxy.example/team-a/" }));
|
|
expect(teamA).not.toBe(resolveModelCacheProviderId("ollama", { baseUrl: "https://proxy.example/team-b/v1" }));
|
|
});
|