Plugins: reuse compatible registries for runtime providers

This commit is contained in:
Gustavo Madeira Santana
2026-03-28 00:07:15 -04:00
parent fd0aac297c
commit a00127bf5b
7 changed files with 125 additions and 82 deletions

View File

@@ -5,10 +5,14 @@ import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../plug
import type { SpeechProviderPlugin } from "../plugins/types.js";
const loadOpenClawPluginsMock = vi.fn();
const getCompatibleActivePluginRegistryMock = vi.fn();
vi.mock("../plugins/loader.js", () => ({
loadOpenClawPlugins: (...args: Parameters<typeof loadOpenClawPluginsMock>) =>
loadOpenClawPluginsMock(...args),
getCompatibleActivePluginRegistry: (
...args: Parameters<typeof getCompatibleActivePluginRegistryMock>
) => getCompatibleActivePluginRegistryMock(...args),
}));
let getSpeechProvider: typeof import("./provider-registry.js").getSpeechProvider;
@@ -37,6 +41,8 @@ describe("speech provider registry", () => {
resetPluginRuntimeStateForTest();
loadOpenClawPluginsMock.mockReset();
loadOpenClawPluginsMock.mockReturnValue(createEmptyPluginRegistry());
getCompatibleActivePluginRegistryMock.mockReset();
getCompatibleActivePluginRegistryMock.mockReturnValue(undefined);
({
getSpeechProvider,
listSpeechProviders,
@@ -60,7 +66,16 @@ describe("speech provider registry", () => {
},
],
});
getCompatibleActivePluginRegistryMock.mockReturnValue({
...createEmptyPluginRegistry(),
speechProviders: [
{
pluginId: "test-demo-speech",
source: "test",
provider: createSpeechProvider("demo-speech"),
},
],
});
const providers = listSpeechProviders();
expect(providers.map((provider) => provider.id)).toEqual(["demo-speech"]);
@@ -112,6 +127,16 @@ describe("speech provider registry", () => {
},
],
});
getCompatibleActivePluginRegistryMock.mockReturnValue({
...createEmptyPluginRegistry(),
speechProviders: [
{
pluginId: "test-microsoft",
source: "test",
provider: createSpeechProvider("microsoft", ["edge"]),
},
],
});
expect(normalizeSpeechProviderId("edge")).toBe("edge");
expect(canonicalizeSpeechProviderId("edge")).toBe("microsoft");