Spaces:
Sleeping
Sleeping
Download backend/src/lib/inference/resolveCredentials.test.ts from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/inference/resolveCredentials.test.ts
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/src/lib/inference/resolveCredentials.test.ts
-
curl -L -o resolveCredentials.test.ts https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/inference/resolveCredentials.test.ts
1.67 kB
| import assert from "node:assert/strict"; | |
| import test from "node:test"; | |
| import { | |
| assertCredentialsAtCallTime, | |
| missingApiKeyErrorPayload, | |
| resolveCredentials, | |
| } from "./resolveCredentials"; | |
| import { MissingApiKeyError } from "./errors"; | |
| import { resetInferenceManifestCache } from "./config"; | |
| test.beforeEach(() => { | |
| resetInferenceManifestCache(); | |
| delete process.env.INFERENCE_MANIFEST_PATH; | |
| delete process.env.OPENAI_API_KEY; | |
| delete process.env.GEMINI_API_KEY; | |
| }); | |
| test("user openai_api_key is used when env unset", () => { | |
| const key = resolveCredentials("proxy-openai", { | |
| openai: "user-openai-key", | |
| }); | |
| assert.equal(key, "user-openai-key"); | |
| }); | |
| test("env key is used when user key is null", () => { | |
| process.env.GEMINI_API_KEY = "env-gemini-key"; | |
| const key = resolveCredentials("google-genai", { | |
| gemini: null, | |
| }); | |
| assert.equal(key, "env-gemini-key"); | |
| }); | |
| test("missing both user and env credentials returns null at call time", () => { | |
| const key = resolveCredentials("proxy-openai", { openai: null }); | |
| assert.equal(key, null); | |
| }); | |
| test("assertCredentialsAtCallTime throws missing_api_key error", () => { | |
| assert.throws( | |
| () => assertCredentialsAtCallTime("google-genai", { gemini: null }), | |
| MissingApiKeyError, | |
| ); | |
| try { | |
| assertCredentialsAtCallTime("google-genai", { gemini: null }); | |
| } catch (error) { | |
| assert.equal((error as MissingApiKeyError).code, "missing_api_key"); | |
| assert.deepEqual( | |
| missingApiKeyErrorPayload("google-genai"), | |
| { error: "missing_api_key", provider: "google-genai" }, | |
| ); | |
| } | |
| }); | |