mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 23:14:31 +00:00
test(memory): dedupe model-auth mock setup
This commit is contained in:
@@ -3,15 +3,10 @@ import * as authModule from "../agents/model-auth.js";
|
|||||||
import { type FetchMock, withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
import { type FetchMock, withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
||||||
import { createVoyageEmbeddingProvider, normalizeVoyageModel } from "./embeddings-voyage.js";
|
import { createVoyageEmbeddingProvider, normalizeVoyageModel } from "./embeddings-voyage.js";
|
||||||
|
|
||||||
vi.mock("../agents/model-auth.js", () => ({
|
vi.mock("../agents/model-auth.js", async () => {
|
||||||
resolveApiKeyForProvider: vi.fn(),
|
const { createModelAuthMockModule } = await import("../test-utils/model-auth-mock.js");
|
||||||
requireApiKey: (auth: { apiKey?: string; mode?: string }, provider: string) => {
|
return createModelAuthMockModule();
|
||||||
if (auth?.apiKey) {
|
});
|
||||||
return auth.apiKey;
|
|
||||||
}
|
|
||||||
throw new Error(`No API key resolved for provider "${provider}" (auth mode: ${auth?.mode}).`);
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const createFetchMock = () => {
|
const createFetchMock = () => {
|
||||||
const fetchMock = vi.fn<FetchMock>(
|
const fetchMock = vi.fn<FetchMock>(
|
||||||
|
|||||||
@@ -3,15 +3,10 @@ import * as authModule from "../agents/model-auth.js";
|
|||||||
import { DEFAULT_GEMINI_EMBEDDING_MODEL } from "./embeddings-gemini.js";
|
import { DEFAULT_GEMINI_EMBEDDING_MODEL } from "./embeddings-gemini.js";
|
||||||
import { createEmbeddingProvider, DEFAULT_LOCAL_MODEL } from "./embeddings.js";
|
import { createEmbeddingProvider, DEFAULT_LOCAL_MODEL } from "./embeddings.js";
|
||||||
|
|
||||||
vi.mock("../agents/model-auth.js", () => ({
|
vi.mock("../agents/model-auth.js", async () => {
|
||||||
resolveApiKeyForProvider: vi.fn(),
|
const { createModelAuthMockModule } = await import("../test-utils/model-auth-mock.js");
|
||||||
requireApiKey: (auth: { apiKey?: string; mode?: string }, provider: string) => {
|
return createModelAuthMockModule();
|
||||||
if (auth?.apiKey) {
|
});
|
||||||
return auth.apiKey;
|
|
||||||
}
|
|
||||||
throw new Error(`No API key resolved for provider "${provider}" (auth mode: ${auth?.mode}).`);
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const importNodeLlamaCppMock = vi.fn();
|
const importNodeLlamaCppMock = vi.fn();
|
||||||
vi.mock("./node-llama.js", () => ({
|
vi.mock("./node-llama.js", () => ({
|
||||||
|
|||||||
13
src/test-utils/model-auth-mock.ts
Normal file
13
src/test-utils/model-auth-mock.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
export function createModelAuthMockModule() {
|
||||||
|
return {
|
||||||
|
resolveApiKeyForProvider: vi.fn(),
|
||||||
|
requireApiKey: (auth: { apiKey?: string; mode?: string }, provider: string) => {
|
||||||
|
if (auth?.apiKey) {
|
||||||
|
return auth.apiKey;
|
||||||
|
}
|
||||||
|
throw new Error(`No API key resolved for provider "${provider}" (auth mode: ${auth?.mode}).`);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user