Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
288 lines
8.9 KiB
TypeScript
288 lines
8.9 KiB
TypeScript
// Microsoft tests cover speech provider plugin behavior.
|
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import {
|
|
finalizeDebugProxyCapture,
|
|
getDebugProxyCaptureStore,
|
|
initializeDebugProxyCapture,
|
|
} from "openclaw/plugin-sdk/proxy-capture";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { installDebugProxyTestResetHooks } from "../test-support/debug-proxy-env-test-helpers.js";
|
|
|
|
vi.mock("node-edge-tts", () => ({
|
|
EdgeTTS: class {
|
|
async ttsPromise(): Promise<void> {}
|
|
},
|
|
}));
|
|
|
|
import {
|
|
buildMicrosoftSpeechProvider,
|
|
isCjkDominant,
|
|
listMicrosoftVoices,
|
|
} from "./speech-provider.js";
|
|
import * as ttsModule from "./tts.js";
|
|
|
|
const TEST_CFG = {} as OpenClawConfig;
|
|
|
|
function requireFirstEdgeTtsCall(edgeSpy: ReturnType<typeof vi.spyOn>): {
|
|
config?: unknown;
|
|
outputPath: string;
|
|
text?: string;
|
|
timeoutMs?: number;
|
|
} {
|
|
const [call] = edgeSpy.mock.calls;
|
|
if (!call) {
|
|
throw new Error("expected Microsoft Edge TTS call");
|
|
}
|
|
const [edgeCall] = call;
|
|
if (!edgeCall || typeof edgeCall !== "object" || Array.isArray(edgeCall)) {
|
|
throw new Error("expected Microsoft Edge TTS call");
|
|
}
|
|
return edgeCall as {
|
|
config?: unknown;
|
|
outputPath: string;
|
|
text?: string;
|
|
timeoutMs?: number;
|
|
};
|
|
}
|
|
|
|
describe("listMicrosoftVoices", () => {
|
|
const proxyReset = installDebugProxyTestResetHooks();
|
|
|
|
it("maps Microsoft voice metadata into speech voice options", async () => {
|
|
globalThis.fetch = vi.fn().mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify([
|
|
{
|
|
ShortName: "en-US-AvaNeural",
|
|
FriendlyName: "Microsoft Ava Online (Natural) - English (United States)",
|
|
Locale: "en-US",
|
|
Gender: "Female",
|
|
VoiceTag: {
|
|
ContentCategories: ["General"],
|
|
VoicePersonalities: ["Friendly", "Positive"],
|
|
},
|
|
},
|
|
]),
|
|
{ status: 200 },
|
|
),
|
|
) as unknown as typeof globalThis.fetch;
|
|
|
|
const voices = await listMicrosoftVoices();
|
|
|
|
expect(voices).toEqual([
|
|
{
|
|
id: "en-US-AvaNeural",
|
|
name: "Microsoft Ava Online (Natural) - English (United States)",
|
|
category: "General",
|
|
description: "Friendly, Positive",
|
|
locale: "en-US",
|
|
gender: "Female",
|
|
personalities: ["Friendly", "Positive"],
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("throws on Microsoft voice list failures", async () => {
|
|
globalThis.fetch = vi
|
|
.fn()
|
|
.mockResolvedValue(
|
|
new Response("nope", { status: 503 }),
|
|
) as unknown as typeof globalThis.fetch;
|
|
|
|
await expect(listMicrosoftVoices()).rejects.toThrow("Microsoft voices API error (503)");
|
|
});
|
|
|
|
it("records voice discovery exchanges in debug proxy capture mode", async () => {
|
|
const tempDir = mkdtempSync(path.join(os.tmpdir(), "microsoft-voices-capture-"));
|
|
proxyReset.captureProxyEnv();
|
|
process.env.OPENCLAW_DEBUG_PROXY_ENABLED = "1";
|
|
process.env.OPENCLAW_STATE_DIR = tempDir;
|
|
process.env.OPENCLAW_DEBUG_PROXY_SESSION_ID = "ms-voices-session";
|
|
|
|
globalThis.fetch = vi
|
|
.fn()
|
|
.mockResolvedValue(
|
|
new Response(JSON.stringify([{ ShortName: "en-US-AvaNeural" }]), { status: 200 }),
|
|
) as unknown as typeof globalThis.fetch;
|
|
|
|
const store = getDebugProxyCaptureStore();
|
|
store.upsertSession({
|
|
id: "ms-voices-session",
|
|
startedAt: Date.now(),
|
|
mode: "test",
|
|
sourceScope: "openclaw",
|
|
sourceProcess: "openclaw",
|
|
});
|
|
|
|
await listMicrosoftVoices();
|
|
|
|
await vi.waitFor(() => {
|
|
const events = store.getSessionEvents("ms-voices-session", 10);
|
|
expect(
|
|
events.some(
|
|
(event) => event.kind === "request" && event.host === "speech.platform.bing.com",
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
events.some(
|
|
(event) => event.kind === "response" && event.host === "speech.platform.bing.com",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
it("does not double-capture voice discovery when the global fetch patch is installed", async () => {
|
|
const tempDir = mkdtempSync(path.join(os.tmpdir(), "microsoft-voices-global-"));
|
|
proxyReset.captureProxyEnv();
|
|
process.env.OPENCLAW_DEBUG_PROXY_ENABLED = "1";
|
|
process.env.OPENCLAW_STATE_DIR = tempDir;
|
|
process.env.OPENCLAW_DEBUG_PROXY_SESSION_ID = "ms-voices-global-session";
|
|
|
|
globalThis.fetch = vi.fn(
|
|
async () => new Response(JSON.stringify([{ ShortName: "en-US-AvaNeural" }]), { status: 200 }),
|
|
) as unknown as typeof globalThis.fetch;
|
|
|
|
const store = getDebugProxyCaptureStore();
|
|
store.upsertSession({
|
|
id: "ms-voices-global-session",
|
|
startedAt: Date.now(),
|
|
mode: "test",
|
|
sourceScope: "openclaw",
|
|
sourceProcess: "openclaw",
|
|
});
|
|
initializeDebugProxyCapture("test");
|
|
|
|
try {
|
|
await listMicrosoftVoices();
|
|
|
|
let events: Array<Record<string, unknown>> = [];
|
|
await vi.waitFor(() => {
|
|
events = store
|
|
.getSessionEvents("ms-voices-global-session", 10)
|
|
.filter((event) => event.host === "speech.platform.bing.com");
|
|
expect(events).toHaveLength(2);
|
|
});
|
|
const kinds = events.map((event) => String(event.kind)).toSorted();
|
|
expect(kinds).toEqual(["request", "response"]);
|
|
} finally {
|
|
globalThis.fetch = proxyReset.originalFetch;
|
|
finalizeDebugProxyCapture();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("isCjkDominant", () => {
|
|
it("returns true for Chinese text", () => {
|
|
expect(isCjkDominant("你好世界")).toBe(true);
|
|
});
|
|
|
|
it("returns true for mixed text with majority CJK", () => {
|
|
expect(isCjkDominant("你好,这是一个测试 hello")).toBe(true);
|
|
});
|
|
|
|
it("returns false for English text", () => {
|
|
expect(isCjkDominant("Hello, this is a test")).toBe(false);
|
|
});
|
|
|
|
it("returns false for empty string", () => {
|
|
expect(isCjkDominant("")).toBe(false);
|
|
});
|
|
|
|
it("returns false for mostly English with a few CJK chars", () => {
|
|
expect(isCjkDominant("This is a long English sentence with one 字")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("buildMicrosoftSpeechProvider", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("switches to a Chinese voice for CJK text when no explicit voice override is set", async () => {
|
|
const provider = buildMicrosoftSpeechProvider();
|
|
const edgeSpy = vi.spyOn(ttsModule, "edgeTTS").mockImplementation(async ({ outputPath }) => {
|
|
writeFileSync(outputPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
|
|
});
|
|
|
|
await provider.synthesize({
|
|
text: "你好,这是一个测试 hello",
|
|
cfg: TEST_CFG,
|
|
providerConfig: {
|
|
enabled: true,
|
|
voice: "en-US-MichelleNeural",
|
|
lang: "en-US",
|
|
outputFormat: "audio-24khz-48kbitrate-mono-mp3",
|
|
outputFormatConfigured: true,
|
|
saveSubtitles: false,
|
|
},
|
|
providerOverrides: {},
|
|
timeoutMs: 1000,
|
|
target: "audio-file",
|
|
});
|
|
|
|
expect(edgeSpy).toHaveBeenCalledOnce();
|
|
const edgeCall = requireFirstEdgeTtsCall(edgeSpy);
|
|
expect(edgeCall.text).toBe("你好,这是一个测试 hello");
|
|
expect(path.basename(edgeCall.outputPath)).toBe("speech.mp3");
|
|
expect(edgeCall.timeoutMs).toBe(1000);
|
|
expect(edgeCall.config).toEqual({
|
|
enabled: true,
|
|
voice: "zh-CN-XiaoxiaoNeural",
|
|
lang: "zh-CN",
|
|
outputFormat: "audio-24khz-48kbitrate-mono-mp3",
|
|
outputFormatConfigured: true,
|
|
pitch: undefined,
|
|
rate: undefined,
|
|
volume: undefined,
|
|
saveSubtitles: false,
|
|
proxy: undefined,
|
|
timeoutMs: undefined,
|
|
});
|
|
});
|
|
|
|
it("preserves an explicitly configured English voice for CJK text", async () => {
|
|
const provider = buildMicrosoftSpeechProvider();
|
|
const edgeSpy = vi.spyOn(ttsModule, "edgeTTS").mockImplementation(async ({ outputPath }) => {
|
|
writeFileSync(outputPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
|
|
});
|
|
|
|
await provider.synthesize({
|
|
text: "你好,这是一个测试 hello",
|
|
cfg: TEST_CFG,
|
|
providerConfig: {
|
|
enabled: true,
|
|
voice: "en-US-AvaNeural",
|
|
lang: "en-US",
|
|
outputFormat: "audio-24khz-48kbitrate-mono-mp3",
|
|
outputFormatConfigured: true,
|
|
saveSubtitles: false,
|
|
},
|
|
providerOverrides: {},
|
|
timeoutMs: 1000,
|
|
target: "audio-file",
|
|
});
|
|
|
|
expect(edgeSpy).toHaveBeenCalledOnce();
|
|
const edgeCall = requireFirstEdgeTtsCall(edgeSpy);
|
|
expect(edgeCall.text).toBe("你好,这是一个测试 hello");
|
|
expect(path.basename(edgeCall.outputPath)).toBe("speech.mp3");
|
|
expect(edgeCall.timeoutMs).toBe(1000);
|
|
expect(edgeCall.config).toEqual({
|
|
enabled: true,
|
|
voice: "en-US-AvaNeural",
|
|
lang: "en-US",
|
|
outputFormat: "audio-24khz-48kbitrate-mono-mp3",
|
|
outputFormatConfigured: true,
|
|
pitch: undefined,
|
|
rate: undefined,
|
|
volume: undefined,
|
|
saveSubtitles: false,
|
|
proxy: undefined,
|
|
timeoutMs: undefined,
|
|
});
|
|
});
|
|
});
|