Skip to content

Commit 7b99da3

Browse files
committed
test: fold webchat auto tts proof into qa
1 parent a202dd0 commit 7b99da3

4 files changed

Lines changed: 169 additions & 160 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
title: WebChat auto TTS delivery
2+
3+
scenario:
4+
id: webchat-auto-tts
5+
surface: media-understanding-and-media-generation
6+
category: media-understanding-and-media-generation.text-to-speech-delivery
7+
coverage:
8+
primary:
9+
- media.tts
10+
- media.outbound-voice-audio-delivery
11+
objective: Verify WebChat auto-TTS synthesizes only the final reply tail and exposes trusted local audio blocks for browser delivery.
12+
successCriteria:
13+
- WebChat block delivery does not synthesize intermediate TTS audio.
14+
- WebChat final delivery synthesizes one local TTS audio file with spoken text metadata.
15+
- Trusted local TTS media becomes a WebChat audio attachment while untrusted local paths are rejected.
16+
docsRefs:
17+
- docs/tools/tts.md
18+
- docs/tools/media-overview.md
19+
- docs/concepts/qa-e2e-automation.md
20+
codeRefs:
21+
- packages/speech-core/src/tts.ts
22+
- src/gateway/server-methods/chat-webchat-media.ts
23+
- test/e2e/qa-lab/media/webchat-auto-tts.e2e.test.ts
24+
execution:
25+
kind: vitest
26+
path: test/e2e/qa-lab/media/webchat-auto-tts.e2e.test.ts
27+
summary: Vitest QA Lab coverage for WebChat auto-TTS synthesis and trusted local audio delivery.

‎scripts/repro/webchat-auto-tts-live-proof.mjs‎

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import fs from "node:fs";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
5+
import { afterEach, describe, expect, it } from "vitest";
6+
import { maybeApplyTtsToPayload } from "../../../../packages/speech-core/src/tts.ts";
7+
import { buildWebchatAudioContentBlocksFromReplyPayloads } from "../../../../src/gateway/server-methods/chat-webchat-media.ts";
8+
import { createPluginRecord } from "../../../../src/plugins/loader-records.ts";
9+
import { createPluginRegistry } from "../../../../src/plugins/registry.ts";
10+
import {
11+
resetPluginRuntimeStateForTest,
12+
setActivePluginRegistry,
13+
} from "../../../../src/plugins/runtime.ts";
14+
15+
const noopLogger = {
16+
info() {},
17+
warn() {},
18+
error() {},
19+
debug() {},
20+
};
21+
22+
function installMockTtsProvider() {
23+
const registry = createPluginRegistry({
24+
logger: noopLogger,
25+
runtime: {},
26+
activateGlobalSideEffects: false,
27+
});
28+
const record = createPluginRecord({
29+
id: "qa-webchat-auto-tts",
30+
name: "QA WebChat Auto TTS",
31+
source: "test/e2e/qa-lab/media/webchat-auto-tts.e2e.test.ts",
32+
origin: "global",
33+
enabled: true,
34+
configSchema: false,
35+
});
36+
const synthesizeCalls: string[] = [];
37+
38+
registry.registerSpeechProvider(record, {
39+
id: "mock",
40+
label: "Mock",
41+
autoSelectOrder: 1,
42+
isConfigured: () => true,
43+
synthesize: async (request) => {
44+
synthesizeCalls.push(request.text);
45+
return {
46+
audioBuffer: Buffer.from("voice"),
47+
fileExtension: ".ogg",
48+
outputFormat: "ogg",
49+
voiceCompatible: request.target === "voice-note",
50+
};
51+
},
52+
});
53+
setActivePluginRegistry(registry.registry);
54+
return synthesizeCalls;
55+
}
56+
57+
describe("QA WebChat auto TTS", () => {
58+
afterEach(() => {
59+
resetPluginRuntimeStateForTest();
60+
});
61+
62+
it("synthesizes only the final WebChat tail and exposes trusted local audio", async () => {
63+
resetPluginRuntimeStateForTest();
64+
const synthesizeCalls = installMockTtsProvider();
65+
const prefsPath = path.join(os.tmpdir(), `openclaw-webchat-tts-${process.pid}.json`);
66+
let mediaPath: string | undefined;
67+
68+
try {
69+
const text = "WebChat streams block text; dispatch synthesizes one TTS tail with kind final.";
70+
const cfg = {
71+
messages: {
72+
tts: {
73+
enabled: true,
74+
provider: "mock",
75+
prefsPath,
76+
},
77+
},
78+
} satisfies OpenClawConfig;
79+
80+
const blockResult = await maybeApplyTtsToPayload({
81+
payload: { text },
82+
cfg,
83+
channel: "webchat",
84+
kind: "block",
85+
});
86+
expect(blockResult.mediaUrl).toBeUndefined();
87+
expect(blockResult.text).toBe(text);
88+
expect(synthesizeCalls).toEqual([]);
89+
90+
const tailResult = await maybeApplyTtsToPayload({
91+
payload: { text },
92+
cfg,
93+
channel: "webchat",
94+
kind: "final",
95+
});
96+
mediaPath = tailResult.mediaUrl;
97+
98+
expect(synthesizeCalls).toEqual([text]);
99+
expect(mediaPath).toMatch(/voice-\d+\.ogg$/);
100+
if (!mediaPath || !fs.existsSync(mediaPath)) {
101+
throw new Error("expected final WebChat TTS to write local audio");
102+
}
103+
expect(tailResult).toMatchObject({
104+
spokenText: text,
105+
trustedLocalMedia: true,
106+
});
107+
108+
const trustedBlocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
109+
[
110+
{
111+
mediaUrl: mediaPath,
112+
audioAsVoice: tailResult.audioAsVoice,
113+
spokenText: text,
114+
trustedLocalMedia: true,
115+
},
116+
],
117+
{ localRoots: [path.dirname(mediaPath)] },
118+
);
119+
const untrustedBlocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
120+
[{ mediaUrl: mediaPath }],
121+
{ localRoots: [path.dirname(mediaPath)] },
122+
);
123+
124+
expect(trustedBlocks).toHaveLength(1);
125+
expect(trustedBlocks[0]).toMatchObject({
126+
type: "attachment",
127+
attachment: {
128+
kind: "audio",
129+
label: path.basename(mediaPath),
130+
mimeType: "audio/ogg",
131+
url: fs.realpathSync(mediaPath),
132+
},
133+
});
134+
expect(untrustedBlocks).toHaveLength(0);
135+
} finally {
136+
if (mediaPath) {
137+
fs.rmSync(path.dirname(mediaPath), { recursive: true, force: true });
138+
}
139+
fs.rmSync(prefsPath, { force: true });
140+
}
141+
});
142+
});

‎test/scripts/webchat-auto-tts-live-proof.test.ts‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)