mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 22:50:22 +00:00
test: move extension-owned coverage into plugins
This commit is contained in:
46
extensions/mistral/media-understanding-provider.test.ts
Normal file
46
extensions/mistral/media-understanding-provider.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createRequestCaptureJsonFetch,
|
||||
installPinnedHostnameTestHooks,
|
||||
} from "../../src/media-understanding/audio.test-helpers.js";
|
||||
import { mistralMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
|
||||
installPinnedHostnameTestHooks();
|
||||
|
||||
describe("mistralMediaUnderstandingProvider", () => {
|
||||
it("has expected provider metadata", () => {
|
||||
expect(mistralMediaUnderstandingProvider.id).toBe("mistral");
|
||||
expect(mistralMediaUnderstandingProvider.capabilities).toEqual(["audio"]);
|
||||
expect(mistralMediaUnderstandingProvider.transcribeAudio).toBeDefined();
|
||||
});
|
||||
|
||||
it("uses Mistral base URL by default", async () => {
|
||||
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "bonjour" });
|
||||
|
||||
const result = await mistralMediaUnderstandingProvider.transcribeAudio!({
|
||||
buffer: Buffer.from("audio-bytes"),
|
||||
fileName: "voice.ogg",
|
||||
apiKey: "test-mistral-key",
|
||||
timeoutMs: 5000,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
expect(getRequest().url).toBe("https://api.mistral.ai/v1/audio/transcriptions");
|
||||
expect(result.text).toBe("bonjour");
|
||||
});
|
||||
|
||||
it("allows overriding baseUrl", async () => {
|
||||
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "ok" });
|
||||
|
||||
await mistralMediaUnderstandingProvider.transcribeAudio!({
|
||||
buffer: Buffer.from("audio"),
|
||||
fileName: "note.mp3",
|
||||
apiKey: "key",
|
||||
timeoutMs: 1000,
|
||||
baseUrl: "https://custom.mistral.example/v1",
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
expect(getRequest().url).toBe("https://custom.mistral.example/v1/audio/transcriptions");
|
||||
});
|
||||
});
|
||||
77
extensions/mistral/onboard.test.ts
Normal file
77
extensions/mistral/onboard.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
resolveAgentModelFallbackValues,
|
||||
resolveAgentModelPrimaryValue,
|
||||
} from "../../src/config/model-input.js";
|
||||
import { buildMistralModelDefinition as buildCoreMistralModelDefinition } from "../../src/plugins/provider-model-definitions.js";
|
||||
import {
|
||||
createConfigWithFallbacks,
|
||||
createLegacyProviderConfig,
|
||||
EXPECTED_FALLBACKS,
|
||||
} from "../../test/helpers/extensions/onboard-config.js";
|
||||
import { buildMistralModelDefinition as buildBundledMistralModelDefinition } from "./model-definitions.js";
|
||||
import {
|
||||
applyMistralConfig,
|
||||
applyMistralProviderConfig,
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
} from "./onboard.js";
|
||||
|
||||
describe("mistral onboard", () => {
|
||||
it("adds Mistral provider with correct settings", () => {
|
||||
const cfg = applyMistralConfig({});
|
||||
expect(cfg.models?.providers?.mistral).toMatchObject({
|
||||
baseUrl: "https://api.mistral.ai/v1",
|
||||
api: "openai-completions",
|
||||
});
|
||||
expect(resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model)).toBe(
|
||||
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",
|
||||
);
|
||||
expect(mistralDefault?.contextWindow).toBe(262144);
|
||||
expect(mistralDefault?.maxTokens).toBe(16384);
|
||||
});
|
||||
|
||||
it("keeps the core and bundled mistral defaults aligned", () => {
|
||||
const bundled = buildBundledMistralModelDefinition();
|
||||
const core = buildCoreMistralModelDefinition();
|
||||
|
||||
expect(core).toMatchObject({
|
||||
id: bundled.id,
|
||||
contextWindow: bundled.contextWindow,
|
||||
maxTokens: bundled.maxTokens,
|
||||
});
|
||||
});
|
||||
|
||||
it("adds the expected alias for the default model", () => {
|
||||
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,
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user