|
1 | 1 | import { describe, expect, test } from "vitest"; |
2 | | -import { parseFileMetadataFromUrl, _urljoin } from "./util"; |
| 2 | +import { type APISecret } from "@schema"; |
| 3 | +import { |
| 4 | + isNativeInferenceSecret, |
| 5 | + parseFileMetadataFromUrl, |
| 6 | + _urljoin, |
| 7 | +} from "./util"; |
3 | 8 |
|
4 | 9 | describe("parseFileMetadataFromUrl", () => { |
5 | 10 | test("handles basic URLs", () => { |
@@ -222,3 +227,58 @@ test("_urljoin", () => { |
222 | 227 | expect(_urljoin()).toBe(""); |
223 | 228 | expect(_urljoin("a")).toBe("a"); |
224 | 229 | }); |
| 230 | + |
| 231 | +describe("isNativeInferenceSecret", () => { |
| 232 | + test("treats braintrust secrets without custom models as native inference", () => { |
| 233 | + const secret: APISecret = { |
| 234 | + type: "braintrust", |
| 235 | + secret: "test-secret", |
| 236 | + metadata: { |
| 237 | + api_base: "http://localhost:8001/native-inference-test", |
| 238 | + }, |
| 239 | + }; |
| 240 | + |
| 241 | + expect(isNativeInferenceSecret(secret, "brain-test-native-1")).toBe(true); |
| 242 | + }); |
| 243 | + |
| 244 | + test("treats custom model secrets as native inference only for matching models", () => { |
| 245 | + const secret: APISecret = { |
| 246 | + type: "openai", |
| 247 | + secret: "test-secret", |
| 248 | + metadata: { |
| 249 | + customModels: { |
| 250 | + "brain-test-native-1": { |
| 251 | + format: "openai", |
| 252 | + flavor: "chat", |
| 253 | + }, |
| 254 | + }, |
| 255 | + }, |
| 256 | + }; |
| 257 | + |
| 258 | + expect(isNativeInferenceSecret(secret, "brain-test-native-1")).toBe(true); |
| 259 | + expect(isNativeInferenceSecret(secret, "brain-test-native-2")).toBe(false); |
| 260 | + }); |
| 261 | + |
| 262 | + test("treats non-braintrust secrets without matching custom models as non-native", () => { |
| 263 | + const secret: APISecret = { |
| 264 | + type: "openai", |
| 265 | + secret: "test-secret", |
| 266 | + metadata: { |
| 267 | + api_base: "https://api.openai.com/v1", |
| 268 | + }, |
| 269 | + }; |
| 270 | + |
| 271 | + expect(isNativeInferenceSecret(secret, "brain-test-native-1")).toBe(false); |
| 272 | + }); |
| 273 | + |
| 274 | + test("returns false when the model is missing", () => { |
| 275 | + const secret: APISecret = { |
| 276 | + type: "braintrust", |
| 277 | + secret: "test-secret", |
| 278 | + metadata: null, |
| 279 | + }; |
| 280 | + |
| 281 | + expect(isNativeInferenceSecret(secret, null)).toBe(false); |
| 282 | + expect(isNativeInferenceSecret(secret, undefined)).toBe(false); |
| 283 | + }); |
| 284 | +}); |
0 commit comments