From bee60a479b0d1ade26e4606ff6a52bf519c77b90 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 4 Apr 2026 02:23:33 +0900 Subject: [PATCH] test(contracts): fix tts provider fixtures --- src/plugins/contracts/tts.contract.test.ts | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/plugins/contracts/tts.contract.test.ts b/src/plugins/contracts/tts.contract.test.ts index 72febf8f399..b94afe4c7be 100644 --- a/src/plugins/contracts/tts.contract.test.ts +++ b/src/plugins/contracts/tts.contract.test.ts @@ -170,13 +170,37 @@ function resolveBaseUrl(rawValue: unknown, fallback: string): string { return typeof rawValue === "string" && rawValue.trim() ? rawValue.replace(/\/+$/u, "") : fallback; } +function resolveTestProviderConfig( + rawConfig: Record, + providerId: string, + ...aliases: string[] +): Record { + const providers = + typeof rawConfig.providers === "object" && + rawConfig.providers !== null && + !Array.isArray(rawConfig.providers) + ? (rawConfig.providers as Record) + : {}; + for (const key of [providerId, ...aliases]) { + const direct = rawConfig[key]; + if (typeof direct === "object" && direct !== null && !Array.isArray(direct)) { + return direct as Record; + } + const nested = providers[key]; + if (typeof nested === "object" && nested !== null && !Array.isArray(nested)) { + return nested as Record; + } + } + return {}; +} + function buildTestOpenAISpeechProvider(): SpeechProviderPlugin { return { id: "openai", label: "OpenAI", autoSelectOrder: 10, resolveConfig: ({ rawConfig }) => { - const config = (rawConfig.openai ?? {}) as Record; + const config = resolveTestProviderConfig(rawConfig, "openai"); return { ...config, baseUrl: resolveBaseUrl( @@ -275,7 +299,7 @@ function buildTestMicrosoftSpeechProvider(): SpeechProviderPlugin { aliases: ["edge"], autoSelectOrder: 30, resolveConfig: ({ rawConfig }) => { - const edgeConfig = (rawConfig.edge ?? rawConfig.microsoft ?? {}) as Record; + const edgeConfig = resolveTestProviderConfig(rawConfig, "microsoft", "edge"); return { ...edgeConfig, outputFormat: edgeConfig.outputFormat ?? "audio-24khz-48kbitrate-mono-mp3", @@ -297,6 +321,7 @@ function buildTestElevenLabsSpeechProvider(): SpeechProviderPlugin { id: "elevenlabs", label: "ElevenLabs", autoSelectOrder: 20, + resolveConfig: ({ rawConfig }) => resolveTestProviderConfig(rawConfig, "elevenlabs"), parseDirectiveToken: ({ key, value, currentOverrides }) => { if (key === "voiceid") { return { handled: true, overrides: { voiceId: value } }; @@ -651,7 +676,7 @@ describe("tts", () => { describe("resolveTtsConfig provider normalization", () => { it("normalizes legacy edge provider ids to microsoft", () => { const config = resolveTtsConfig( - asLegacyTtsConfig({ + asLegacyOpenClawConfig({ agents: { defaults: { model: { primary: "openai/gpt-4o-mini" } } }, messages: { tts: {