mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:48:28 +00:00
refactor(test): dedupe provider env setup in model config tests
This commit is contained in:
@@ -2,31 +2,23 @@ import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import { withEnvAsync } from "../test-utils/env.js";
|
||||
import { resolveApiKeyForProvider } from "./model-auth.js";
|
||||
import { buildNvidiaProvider, resolveImplicitProviders } from "./models-config.providers.js";
|
||||
|
||||
describe("NVIDIA provider", () => {
|
||||
it("should include nvidia when NVIDIA_API_KEY is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["NVIDIA_API_KEY"]);
|
||||
process.env.NVIDIA_API_KEY = "test-key";
|
||||
|
||||
try {
|
||||
await withEnvAsync({ NVIDIA_API_KEY: "test-key" }, async () => {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
expect(providers?.nvidia).toBeDefined();
|
||||
expect(providers?.nvidia?.models?.length).toBeGreaterThan(0);
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves the nvidia api key value from env", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["NVIDIA_API_KEY"]);
|
||||
process.env.NVIDIA_API_KEY = "nvidia-test-api-key";
|
||||
|
||||
try {
|
||||
await withEnvAsync({ NVIDIA_API_KEY: "nvidia-test-api-key" }, async () => {
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: "nvidia",
|
||||
agentDir,
|
||||
@@ -35,9 +27,7 @@ describe("NVIDIA provider", () => {
|
||||
expect(auth.apiKey).toBe("nvidia-test-api-key");
|
||||
expect(auth.mode).toBe("api-key");
|
||||
expect(auth.source).toContain("NVIDIA_API_KEY");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should build nvidia provider with correct configuration", () => {
|
||||
@@ -60,40 +50,27 @@ describe("NVIDIA provider", () => {
|
||||
describe("MiniMax implicit provider (#15275)", () => {
|
||||
it("should use anthropic-messages API for API-key provider", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["MINIMAX_API_KEY"]);
|
||||
process.env.MINIMAX_API_KEY = "test-key";
|
||||
|
||||
try {
|
||||
await withEnvAsync({ MINIMAX_API_KEY: "test-key" }, async () => {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
expect(providers?.minimax).toBeDefined();
|
||||
expect(providers?.minimax?.api).toBe("anthropic-messages");
|
||||
expect(providers?.minimax?.baseUrl).toBe("https://api.minimax.io/anthropic");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("vLLM provider", () => {
|
||||
it("should not include vllm when no API key is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["VLLM_API_KEY"]);
|
||||
delete process.env.VLLM_API_KEY;
|
||||
|
||||
try {
|
||||
await withEnvAsync({ VLLM_API_KEY: undefined }, async () => {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
expect(providers?.vllm).toBeUndefined();
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should include vllm when VLLM_API_KEY is set", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["VLLM_API_KEY"]);
|
||||
process.env.VLLM_API_KEY = "test-key";
|
||||
|
||||
try {
|
||||
await withEnvAsync({ VLLM_API_KEY: "test-key" }, async () => {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
|
||||
expect(providers?.vllm).toBeDefined();
|
||||
@@ -103,8 +80,6 @@ describe("vLLM provider", () => {
|
||||
|
||||
// Note: discovery is disabled in test environments (VITEST check)
|
||||
expect(providers?.vllm?.models).toEqual([]);
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user