mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:20:43 +00:00
test(plugins): trim tts summarization contract boot
This commit is contained in:
@@ -7,6 +7,8 @@ import { createEmptyPluginRegistry } from "../../../src/plugins/registry-empty.j
|
||||
import { setActivePluginRegistry } from "../../../src/plugins/runtime.js";
|
||||
import type { SpeechProviderPlugin } from "../../../src/plugins/types.js";
|
||||
import { withEnv } from "../../../src/test-utils/env.js";
|
||||
import { summarizeText as summarizeTextCore } from "../../../src/tts/tts-core.js";
|
||||
import type { ResolvedTtsConfig } from "../../../src/tts/tts-types.js";
|
||||
|
||||
type TtsRuntimeModule = typeof import("../../../src/tts/tts.js");
|
||||
|
||||
@@ -25,7 +27,6 @@ let maybeApplyTtsToPayload: TtsRuntimeModule["maybeApplyTtsToPayload"];
|
||||
let getTtsProvider: TtsRuntimeModule["getTtsProvider"];
|
||||
let parseTtsDirectives: TtsRuntimeModule["_test"]["parseTtsDirectives"];
|
||||
let resolveModelOverridePolicy: TtsRuntimeModule["_test"]["resolveModelOverridePolicy"];
|
||||
let summarizeText: TtsRuntimeModule["_test"]["summarizeText"];
|
||||
let getResolvedSpeechProviderConfig: TtsRuntimeModule["_test"]["getResolvedSpeechProviderConfig"];
|
||||
let formatTtsProviderError: TtsRuntimeModule["_test"]["formatTtsProviderError"];
|
||||
let sanitizeTtsErrorForLog: TtsRuntimeModule["_test"]["sanitizeTtsErrorForLog"];
|
||||
@@ -415,7 +416,6 @@ async function setupTtsRuntime() {
|
||||
({
|
||||
parseTtsDirectives,
|
||||
resolveModelOverridePolicy,
|
||||
summarizeText,
|
||||
getResolvedSpeechProviderConfig,
|
||||
formatTtsProviderError,
|
||||
sanitizeTtsErrorForLog,
|
||||
@@ -435,6 +435,35 @@ function setupTestSpeechProviderRegistry() {
|
||||
setActivePluginRegistry(registry, getTtsPluginRegistryCacheKey());
|
||||
}
|
||||
|
||||
function createResolvedSummarizationConfig(cfg: OpenClawConfig): ResolvedTtsConfig {
|
||||
const rawConfig =
|
||||
typeof cfg.messages?.tts === "object" && cfg.messages?.tts !== null ? cfg.messages.tts : {};
|
||||
return {
|
||||
auto: "off",
|
||||
mode: rawConfig.mode ?? "final",
|
||||
provider: "",
|
||||
providerSource:
|
||||
typeof rawConfig.provider === "string" && rawConfig.provider ? "config" : "default",
|
||||
summaryModel: typeof rawConfig.summaryModel === "string" ? rawConfig.summaryModel : undefined,
|
||||
modelOverrides: {
|
||||
enabled: true,
|
||||
allowText: true,
|
||||
allowProvider: false,
|
||||
allowVoice: true,
|
||||
allowModelId: true,
|
||||
allowVoiceSettings: true,
|
||||
allowNormalization: true,
|
||||
allowSeed: true,
|
||||
},
|
||||
providerConfigs: {},
|
||||
prefsPath: typeof rawConfig.prefsPath === "string" ? rawConfig.prefsPath : undefined,
|
||||
maxTextLength: typeof rawConfig.maxTextLength === "number" ? rawConfig.maxTextLength : 4096,
|
||||
timeoutMs: typeof rawConfig.timeoutMs === "number" ? rawConfig.timeoutMs : 30_000,
|
||||
rawConfig,
|
||||
sourceConfig: cfg,
|
||||
};
|
||||
}
|
||||
|
||||
async function setupSummarizationMocks() {
|
||||
({ completeSimple } = await import("@mariozechner/pi-ai"));
|
||||
({ getApiKeyForModel: getApiKeyForModelMock, requireApiKey: requireApiKeyMock } =
|
||||
@@ -459,6 +488,7 @@ async function setupSummarizationMocks() {
|
||||
>,
|
||||
);
|
||||
vi.mocked(ensureCustomApiRegisteredMock).mockReset();
|
||||
prepareModelForSimpleCompletionMock = vi.fn(({ model }) => model);
|
||||
}
|
||||
|
||||
async function setupTtsContractTest() {
|
||||
@@ -468,7 +498,7 @@ async function setupTtsContractTest() {
|
||||
}
|
||||
|
||||
async function setupTtsSummarizationTest() {
|
||||
await setupTtsContractTest();
|
||||
vi.clearAllMocks();
|
||||
await setupSummarizationMocks();
|
||||
}
|
||||
|
||||
@@ -804,8 +834,8 @@ export function describeTtsSummarizationContract() {
|
||||
cfg?: OpenClawConfig;
|
||||
}) {
|
||||
const cfg = params?.cfg ?? baseCfg;
|
||||
const config = resolveTtsConfig(cfg);
|
||||
return await summarizeText(
|
||||
const config = createResolvedSummarizationConfig(cfg);
|
||||
return await summarizeTextCore(
|
||||
{
|
||||
text: params?.text ?? "Long text to summarize",
|
||||
targetLength: params?.targetLength ?? 500,
|
||||
|
||||
Reference in New Issue
Block a user