test: stabilize provider discovery matrix cases

This commit is contained in:
Peter Steinberger
2026-04-05 12:50:48 +01:00
parent d0afdb56ce
commit 59a243e46b
4 changed files with 55 additions and 39 deletions

View File

@@ -108,6 +108,7 @@ export const MODELS_CONFIG_IMPLICIT_ENV_VARS = [
"HF_TOKEN",
"HUGGINGFACE_HUB_TOKEN",
"MINIMAX_API_KEY",
"MINIMAX_API_HOST",
"MINIMAX_OAUTH_TOKEN",
"MOONSHOT_API_KEY",
"NVIDIA_API_KEY",
@@ -212,6 +213,8 @@ export function snapshotImplicitProviderEnv(env?: NodeJS.ProcessEnv): NodeJS.Pro
// Provider discovery tests can temporarily scrub VITEST/NODE_ENV to exercise
// live HTTP paths. Keep the bundled plugin root pinned to the source checkout
// so those tests do not fall back to potentially stale dist-runtime wrappers.
snapshot.VITEST ??= process.env.VITEST;
snapshot.NODE_ENV ??= process.env.NODE_ENV;
snapshot.OPENCLAW_BUNDLED_PLUGINS_DIR ??=
resolveBundledPluginsDir({ VITEST: "true" } as NodeJS.ProcessEnv) ?? undefined;
@@ -264,6 +267,15 @@ async function inferImplicitProviderTestPluginIds(params: {
providerIds.add(providerId.trim());
}
}
const legacyGrokApiKey =
params.config?.tools?.web?.search &&
typeof params.config.tools.web.search === "object" &&
"grok" in params.config.tools.web.search
? (params.config.tools.web.search.grok as { apiKey?: unknown } | undefined)?.apiKey
: undefined;
if (legacyGrokApiKey !== undefined) {
providerIds.add("xai");
}
for (const [envVar, mappedProviderIds] of Object.entries(TEST_PROVIDER_ENV_TO_PROVIDER_IDS)) {
if (!params.env[envVar]?.trim()) {
continue;

View File

@@ -171,5 +171,6 @@ describe("implicit provider resolution matrix", () => {
assertProviders(providers);
},
240_000,
);
});

View File

@@ -10,11 +10,12 @@ import { resolveImplicitProvidersForTest } from "./models-config.e2e-harness.js"
describe("NVIDIA provider", () => {
it("should include nvidia when NVIDIA_API_KEY is configured", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync({ NVIDIA_API_KEY: "test-key" }, async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.nvidia).toBeDefined();
expect(providers?.nvidia?.models?.length).toBeGreaterThan(0);
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { NVIDIA_API_KEY: "test-key" },
});
expect(providers?.nvidia).toBeDefined();
expect(providers?.nvidia?.models?.length).toBeGreaterThan(0);
});
it("resolves the nvidia api key value from env", async () => {
@@ -33,28 +34,30 @@ describe("NVIDIA provider", () => {
});
describe("MiniMax implicit provider (#15275)", () => {
it("should use anthropic-messages API for API-key provider", async () => {
it("should use anthropic-messages API for API-key provider", { timeout: 240_000 }, async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync({ MINIMAX_API_KEY: "test-key", MINIMAX_API_HOST: undefined }, async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.minimax).toBeDefined();
expect(providers?.minimax?.api).toBe("anthropic-messages");
expect(providers?.minimax?.authHeader).toBe(true);
expect(providers?.minimax?.baseUrl).toBe("https://api.minimax.io/anthropic");
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { MINIMAX_API_KEY: "test-key" },
});
expect(providers?.minimax).toBeDefined();
expect(providers?.minimax?.api).toBe("anthropic-messages");
expect(providers?.minimax?.authHeader).toBe(true);
expect(providers?.minimax?.baseUrl).toBe("https://api.minimax.io/anthropic");
});
it("should respect MINIMAX_API_HOST env var for CN endpoint (#34487)", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync(
{ MINIMAX_API_KEY: "test-key", MINIMAX_API_HOST: "https://api.minimaxi.com" },
async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.minimax).toBeDefined();
expect(providers?.minimax?.baseUrl).toBe("https://api.minimaxi.com/anthropic");
expect(providers?.["minimax-portal"]?.baseUrl).toBe("https://api.minimaxi.com/anthropic");
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: {
MINIMAX_API_KEY: "test-key",
MINIMAX_API_HOST: "https://api.minimaxi.com",
},
);
});
expect(providers?.minimax).toBeDefined();
expect(providers?.minimax?.baseUrl).toBe("https://api.minimaxi.com/anthropic");
expect(providers?.["minimax-portal"]?.baseUrl).toBe("https://api.minimaxi.com/anthropic");
});
it("should set authHeader for minimax portal provider", async () => {
@@ -86,35 +89,35 @@ describe("MiniMax implicit provider (#15275)", () => {
it("should include minimax portal provider when MINIMAX_OAUTH_TOKEN is configured", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync({ MINIMAX_OAUTH_TOKEN: "portal-token" }, async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.["minimax-portal"]).toBeDefined();
expect(providers?.["minimax-portal"]?.authHeader).toBe(true);
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { MINIMAX_OAUTH_TOKEN: "portal-token" },
});
expect(providers?.["minimax-portal"]).toBeDefined();
expect(providers?.["minimax-portal"]?.authHeader).toBe(true);
});
});
describe("vLLM provider", () => {
it("should not include vllm when no API key is configured", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync({ VLLM_API_KEY: undefined }, async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.vllm).toBeUndefined();
});
const providers = await resolveImplicitProvidersForTest({ agentDir, env: {} });
expect(providers?.vllm).toBeUndefined();
});
it("should include vllm when VLLM_API_KEY is set", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await withEnvAsync({ VLLM_API_KEY: "test-key" }, async () => {
const providers = await resolveImplicitProvidersForTest({ agentDir });
expect(providers?.vllm).toBeDefined();
expect(providers?.vllm?.apiKey).toBe("VLLM_API_KEY");
expect(providers?.vllm?.baseUrl).toBe("http://127.0.0.1:8000/v1");
expect(providers?.vllm?.api).toBe("openai-completions");
// Note: discovery is disabled in test environments (VITEST check)
expect(providers?.vllm?.models).toEqual([]);
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { VLLM_API_KEY: "test-key" },
});
expect(providers?.vllm).toBeDefined();
expect(providers?.vllm?.apiKey).toBe("VLLM_API_KEY");
expect(providers?.vllm?.baseUrl).toBe("http://127.0.0.1:8000/v1");
expect(providers?.vllm?.api).toBe("openai-completions");
// Note: discovery is disabled in test environments (VITEST check)
expect(providers?.vllm?.models).toEqual([]);
});
});

View File

@@ -13,7 +13,7 @@ describe("StepFun provider catalog", () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { ...process.env, STEPFUN_API_KEY: "test-stepfun-key" },
env: { STEPFUN_API_KEY: "test-stepfun-key" },
});
expect(providers?.stepfun).toMatchObject({
@@ -68,7 +68,7 @@ describe("StepFun provider catalog", () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
const providers = await resolveImplicitProvidersForTest({
agentDir,
env: { ...process.env, STEPFUN_API_KEY: "test-stepfun-key" },
env: { STEPFUN_API_KEY: "test-stepfun-key" },
config: {
models: {
providers: {