test: stub gateway speech providers

This commit is contained in:
Peter Steinberger
2026-04-03 19:16:41 +01:00
parent 956e746da1
commit 4c5c361db7
2 changed files with 36 additions and 28 deletions

View File

@@ -17,31 +17,6 @@ import { setActivePluginRegistry } from "../plugins/runtime.js";
import type { SpeechProviderPlugin } from "../plugins/types.js";
import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
import { loadBundledPluginTestApiSync } from "../test-utils/bundled-plugin-public-surface.js";
type BuildSpeechProvider = () => SpeechProviderPlugin;
let buildElevenLabsSpeechProviderCache: BuildSpeechProvider | undefined;
let buildOpenAISpeechProviderCache: BuildSpeechProvider | undefined;
function getBuildElevenLabsSpeechProvider(): BuildSpeechProvider {
if (!buildElevenLabsSpeechProviderCache) {
({ buildElevenLabsSpeechProvider: buildElevenLabsSpeechProviderCache } =
loadBundledPluginTestApiSync<{
buildElevenLabsSpeechProvider: BuildSpeechProvider;
}>("elevenlabs"));
}
return buildElevenLabsSpeechProviderCache;
}
function getBuildOpenAISpeechProvider(): BuildSpeechProvider {
if (!buildOpenAISpeechProviderCache) {
({ buildOpenAISpeechProvider: buildOpenAISpeechProviderCache } = loadBundledPluginTestApiSync<{
buildOpenAISpeechProvider: BuildSpeechProvider;
}>("openai"));
}
return buildOpenAISpeechProviderCache;
}
function buildBundledPluginModuleId(pluginId: string, artifactBasename: string): string {
return ["..", "..", "extensions", pluginId, artifactBasename].join("/");
@@ -105,6 +80,32 @@ const createStubChannelPlugin = (params: StubChannelOptions): ChannelPlugin => (
},
});
type StubSpeechProviderOptions = {
id: SpeechProviderPlugin["id"];
label: string;
aliases?: string[];
voices?: string[];
};
const createStubSpeechProvider = (params: StubSpeechProviderOptions): SpeechProviderPlugin => ({
id: params.id,
label: params.label,
aliases: params.aliases,
voices: params.voices,
isConfigured: () => true,
synthesize: async () => ({
audioBuffer: Buffer.from(`${params.id}-audio`, "utf8"),
outputFormat: "mp3",
fileExtension: ".mp3",
voiceCompatible: true,
}),
listVoices: async () =>
(params.voices ?? []).map((voiceId) => ({
id: voiceId,
name: voiceId,
})),
});
const createStubPluginRegistry = (): PluginRegistry => ({
plugins: [],
tools: [],
@@ -181,12 +182,20 @@ const createStubPluginRegistry = (): PluginRegistry => ({
{
pluginId: "openai",
source: "test",
provider: getBuildOpenAISpeechProvider()(),
provider: createStubSpeechProvider({
id: "openai",
label: "OpenAI",
voices: ["alloy", "nova"],
}),
},
{
pluginId: "elevenlabs",
source: "test",
provider: getBuildElevenLabsSpeechProvider()(),
provider: createStubSpeechProvider({
id: "elevenlabs",
label: "ElevenLabs",
voices: ["EXAVITQu4vr4xnSDxMaL", "voice-default"],
}),
},
],
mediaUnderstandingProviders: [],

View File

@@ -158,7 +158,6 @@ describe("non-extension test boundaries", () => {
"src/auto-reply/reply.triggers.trigger-handling.test-harness.ts",
"src/channels/plugins/contracts/slack-outbound-harness.ts",
"src/commands/channel-test-registry.ts",
"src/gateway/test-helpers.mocks.ts",
"src/plugin-sdk/testing.ts",
]);
const files = walkCode(path.join(repoRoot, "src"));