test(providers): share onboard primary assertions

This commit is contained in:
Vincent Koc
2026-04-12 04:19:54 +01:00
parent 54c45ae9ca
commit 17bdc76d90
4 changed files with 48 additions and 76 deletions

View File

@@ -1,13 +1,9 @@
import {
resolveAgentModelFallbackValues,
resolveAgentModelPrimaryValue,
} from "openclaw/plugin-sdk/provider-onboard";
import { resolveAgentModelPrimaryValue } from "openclaw/plugin-sdk/provider-onboard";
import { describe, expect, it } from "vitest";
import {
createConfigWithFallbacks,
createLegacyProviderConfig,
EXPECTED_FALLBACKS,
} from "../../test/helpers/plugins/onboard-config.js";
expectProviderOnboardMergedLegacyConfig,
expectProviderOnboardPreservesPrimary,
} from "../../test/helpers/plugins/provider-onboard.js";
import { applyMinimaxApiConfig, applyMinimaxApiProviderConfig } from "./onboard.js";
describe("minimax onboard", () => {
@@ -48,20 +44,15 @@ describe("minimax onboard", () => {
});
it("merges existing minimax provider models", () => {
const cfg = applyMinimaxApiConfig(
createLegacyProviderConfig({
providerId: "minimax",
api: "openai-completions",
}),
);
expect(cfg.models?.providers?.minimax?.baseUrl).toBe("https://api.minimax.io/anthropic");
expect(cfg.models?.providers?.minimax?.api).toBe("anthropic-messages");
expect(cfg.models?.providers?.minimax?.authHeader).toBe(true);
expect(cfg.models?.providers?.minimax?.apiKey).toBe("old-key");
expect(cfg.models?.providers?.minimax?.models.map((m) => m.id)).toEqual([
"old-model",
"MiniMax-M2.7",
]);
const provider = expectProviderOnboardMergedLegacyConfig({
applyProviderConfig: applyMinimaxApiConfig,
providerId: "minimax",
providerApi: "anthropic-messages",
baseUrl: "https://api.minimax.io/anthropic",
legacyApi: "openai-completions",
});
expect(provider?.authHeader).toBe(true);
expect(provider?.models.map((m) => m.id)).toEqual(["old-model", "MiniMax-M2.7"]);
});
it("preserves other providers when adding minimax", () => {
@@ -99,12 +90,10 @@ describe("minimax onboard", () => {
});
it("does not overwrite existing primary model in provider-only mode", () => {
const cfg = applyMinimaxApiProviderConfig({
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },
expectProviderOnboardPreservesPrimary({
applyProviderConfig: applyMinimaxApiProviderConfig,
primaryModelRef: "anthropic/claude-opus-4-5",
});
expect(resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model)).toBe(
"anthropic/claude-opus-4-5",
);
});
it("sets the chosen model as primary in config mode", () => {
@@ -113,11 +102,4 @@ describe("minimax onboard", () => {
"minimax/MiniMax-M2.7-highspeed",
);
});
it("preserves existing model fallbacks", () => {
const cfg = applyMinimaxApiConfig(createConfigWithFallbacks());
expect(resolveAgentModelFallbackValues(cfg.agents?.defaults?.model)).toEqual([
...EXPECTED_FALLBACKS,
]);
});
});

View File

@@ -1,13 +1,8 @@
import {
resolveAgentModelFallbackValues,
resolveAgentModelPrimaryValue,
} from "openclaw/plugin-sdk/provider-onboard";
import { describe, expect, it } from "vitest";
import {
createConfigWithFallbacks,
createLegacyProviderConfig,
EXPECTED_FALLBACKS,
} from "../../test/helpers/plugins/onboard-config.js";
expectProviderOnboardMergedLegacyConfig,
expectProviderOnboardPrimaryAndFallbacks,
} from "../../test/helpers/plugins/provider-onboard.js";
import { buildMistralModelDefinition as buildBundledMistralModelDefinition } from "./model-definitions.js";
import {
applyMistralConfig,
@@ -22,31 +17,24 @@ describe("mistral onboard", () => {
baseUrl: "https://api.mistral.ai/v1",
api: "openai-completions",
});
expect(resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model)).toBe(
MISTRAL_DEFAULT_MODEL_REF,
);
expectProviderOnboardPrimaryAndFallbacks({
applyConfig: applyMistralConfig,
modelRef: MISTRAL_DEFAULT_MODEL_REF,
});
});
it("merges Mistral models and keeps existing provider overrides", () => {
const cfg = applyMistralProviderConfig(
createLegacyProviderConfig({
providerId: "mistral",
api: "anthropic-messages",
modelId: "custom-model",
modelName: "Custom",
}),
);
expect(cfg.models?.providers?.mistral?.baseUrl).toBe("https://api.mistral.ai/v1");
expect(cfg.models?.providers?.mistral?.api).toBe("openai-completions");
expect(cfg.models?.providers?.mistral?.apiKey).toBe("old-key");
expect(cfg.models?.providers?.mistral?.models.map((m) => m.id)).toEqual([
"custom-model",
"mistral-large-latest",
]);
const mistralDefault = cfg.models?.providers?.mistral?.models.find(
(model) => model.id === "mistral-large-latest",
);
const provider = expectProviderOnboardMergedLegacyConfig({
applyProviderConfig: applyMistralProviderConfig,
providerId: "mistral",
providerApi: "openai-completions",
baseUrl: "https://api.mistral.ai/v1",
legacyApi: "anthropic-messages",
legacyModelId: "custom-model",
legacyModelName: "Custom",
});
expect(provider?.models.map((m) => m.id)).toEqual(["custom-model", "mistral-large-latest"]);
const mistralDefault = provider?.models.find((model) => model.id === "mistral-large-latest");
expect(mistralDefault?.contextWindow).toBe(262144);
expect(mistralDefault?.maxTokens).toBe(16384);
});
@@ -69,11 +57,4 @@ describe("mistral onboard", () => {
const cfg = applyMistralProviderConfig({});
expect(cfg.agents?.defaults?.models?.[MISTRAL_DEFAULT_MODEL_REF]?.alias).toBe("Mistral");
});
it("preserves existing model fallbacks", () => {
const cfg = applyMistralConfig(createConfigWithFallbacks());
expect(resolveAgentModelFallbackValues(cfg.agents?.defaults?.model)).toEqual([
...EXPECTED_FALLBACKS,
]);
});
});

View File

@@ -1,5 +1,6 @@
import { resolveAgentModelPrimaryValue } from "openclaw/plugin-sdk/provider-onboard";
import { describe, expect, it } from "vitest";
import { expectProviderOnboardPreservesPrimary } from "../../test/helpers/plugins/provider-onboard.js";
import { ZAI_CODING_CN_BASE_URL, ZAI_GLOBAL_BASE_URL } from "./model-definitions.js";
import { applyZaiConfig, applyZaiProviderConfig } from "./onboard.js";
@@ -27,11 +28,9 @@ describe("zai onboard", () => {
});
it("does not overwrite existing primary model in provider-only mode", () => {
const cfg = applyZaiProviderConfig({
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },
expectProviderOnboardPreservesPrimary({
applyProviderConfig: applyZaiProviderConfig,
primaryModelRef: "anthropic/claude-opus-4-5",
});
expect(resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model)).toBe(
"anthropic/claude-opus-4-5",
);
});
});

View File

@@ -43,6 +43,16 @@ export function expectProviderOnboardPrimaryAndFallbacks(params: {
]);
}
export function expectProviderOnboardPreservesPrimary(params: {
applyProviderConfig: (config: OpenClawConfig) => OpenClawConfig;
primaryModelRef: string;
}) {
const cfg = params.applyProviderConfig({
agents: { defaults: { model: { primary: params.primaryModelRef } } },
});
expect(resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model)).toBe(params.primaryModelRef);
}
export function expectProviderOnboardMergedLegacyConfig(params: {
applyProviderConfig: (config: OpenClawConfig) => OpenClawConfig;
providerId: string;