9993c96907
Move provider auth and OAuth flows onto pi-ai Models, compose models.json and extension overlays through ModelRuntime, and retain ModelRegistry as an extension compatibility facade.
43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { AuthStorage } from "../src/core/auth-storage.ts";
|
|
import { RuntimeCredentials } from "../src/core/runtime-credentials.ts";
|
|
|
|
describe("RuntimeCredentials", () => {
|
|
test("runtime overrides mask stored credentials without persisting", async () => {
|
|
const storage = AuthStorage.inMemory({ anthropic: { type: "api_key", key: "stored-key" } });
|
|
const credentials = new RuntimeCredentials(storage);
|
|
|
|
credentials.setRuntimeApiKey("anthropic", "runtime-key");
|
|
expect(await credentials.read("anthropic")).toEqual({ type: "api_key", key: "runtime-key" });
|
|
expect(await storage.read("anthropic")).toEqual({ type: "api_key", key: "stored-key" });
|
|
|
|
credentials.removeRuntimeApiKey("anthropic");
|
|
expect(await credentials.read("anthropic")).toEqual({ type: "api_key", key: "stored-key" });
|
|
});
|
|
|
|
test("enumeration merges overrides without exposing keys", async () => {
|
|
const storage = AuthStorage.inMemory({
|
|
anthropic: { type: "oauth", access: "access", refresh: "refresh", expires: Date.now() + 60_000 },
|
|
});
|
|
const credentials = new RuntimeCredentials(storage);
|
|
credentials.setRuntimeApiKey("anthropic", "runtime-key");
|
|
credentials.setRuntimeApiKey("openai", "other-runtime-key");
|
|
|
|
expect(await credentials.list()).toEqual([
|
|
{ providerId: "anthropic", type: "api_key" },
|
|
{ providerId: "openai", type: "api_key" },
|
|
]);
|
|
});
|
|
|
|
test("delete clears both the override and persisted credential", async () => {
|
|
const storage = AuthStorage.inMemory({ anthropic: { type: "api_key", key: "stored-key" } });
|
|
const credentials = new RuntimeCredentials(storage);
|
|
credentials.setRuntimeApiKey("anthropic", "runtime-key");
|
|
|
|
await credentials.delete("anthropic");
|
|
|
|
expect(await credentials.read("anthropic")).toBeUndefined();
|
|
expect(await credentials.list()).toEqual([]);
|
|
});
|
|
});
|