test(contracts): fix tts provider fixtures

This commit is contained in:
Vincent Koc
2026-04-04 02:23:33 +09:00
parent 5fbef0f914
commit bee60a479b

View File

@@ -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<string, unknown>,
providerId: string,
...aliases: string[]
): Record<string, unknown> {
const providers =
typeof rawConfig.providers === "object" &&
rawConfig.providers !== null &&
!Array.isArray(rawConfig.providers)
? (rawConfig.providers as Record<string, unknown>)
: {};
for (const key of [providerId, ...aliases]) {
const direct = rawConfig[key];
if (typeof direct === "object" && direct !== null && !Array.isArray(direct)) {
return direct as Record<string, unknown>;
}
const nested = providers[key];
if (typeof nested === "object" && nested !== null && !Array.isArray(nested)) {
return nested as Record<string, unknown>;
}
}
return {};
}
function buildTestOpenAISpeechProvider(): SpeechProviderPlugin {
return {
id: "openai",
label: "OpenAI",
autoSelectOrder: 10,
resolveConfig: ({ rawConfig }) => {
const config = (rawConfig.openai ?? {}) as Record<string, unknown>;
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<string, unknown>;
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: {