Skip to content

Commit 71d95d6

Browse files
committed
test(qa): check in voice call plugin fixture
1 parent dfd2600 commit 71d95d6

3 files changed

Lines changed: 101 additions & 94 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import fs from "node:fs";
2+
3+
const append = (filePath, value) => {
4+
fs.appendFileSync(filePath, `${JSON.stringify(value)}\n`);
5+
};
6+
7+
export default {
8+
id: "qa-voice-call-runtime",
9+
register(api) {
10+
api.registerRealtimeVoiceProvider({
11+
id: "qa-voice-call-realtime",
12+
label: "QA Voice Call Realtime",
13+
isConfigured: () => true,
14+
createBrowserSession() {
15+
throw new Error("Voice Call fixture is bridge-only");
16+
},
17+
createBridge(request) {
18+
append(process.env.OPENCLAW_QA_VOICE_BRIDGE_CALLS_PATH, {
19+
instructions: request.instructions,
20+
tools: request.tools?.map((tool) => tool.name) ?? [],
21+
});
22+
let connected = false;
23+
return {
24+
supportsToolResultContinuation: true,
25+
async connect() {
26+
connected = true;
27+
request.onReady?.();
28+
request.onTranscript?.("user", "Caller partial transcript context", false);
29+
setTimeout(() => {
30+
request.onToolCall?.({
31+
itemId: "qa-consult-item",
32+
callId: "qa-consult-call",
33+
name: "openclaw_agent_consult",
34+
args: {
35+
question: "Use the embedded agent context to identify the caller request.",
36+
context: "Realtime provider context marker: VOICE-CONSULT-42",
37+
},
38+
});
39+
}, 10);
40+
},
41+
sendAudio() {},
42+
setMediaTimestamp() {},
43+
submitToolResult(callId, result, options) {
44+
append(process.env.OPENCLAW_QA_VOICE_TOOL_RESULTS_PATH, { callId, result, options });
45+
},
46+
acknowledgeMark() {},
47+
close() {
48+
connected = false;
49+
},
50+
isConnected() {
51+
return connected;
52+
},
53+
triggerGreeting() {},
54+
};
55+
},
56+
});
57+
api.registerGatewayMethod("qa.voiceCall.streamSession", async ({ params, respond }) => {
58+
const runtime = globalThis[Symbol.for("openclaw.voice-call.runtime")];
59+
const callId = typeof params?.callId === "string" ? params.callId : "";
60+
const call = runtime?.manager?.getCall?.(callId);
61+
const issue = runtime?.manager?.streamSessionIssuer;
62+
if (!runtime || !call || typeof issue !== "function" || !call.providerCallId) {
63+
respond(false, undefined, {
64+
code: "UNAVAILABLE",
65+
message: "Voice Call runtime stream issuer unavailable",
66+
});
67+
return;
68+
}
69+
const session = issue({
70+
providerName: "twilio",
71+
callId,
72+
from: call.from,
73+
to: call.to,
74+
direction: call.direction,
75+
});
76+
respond(true, {
77+
...session,
78+
providerCallId: call.providerCallId,
79+
webhookUrl: runtime.webhookUrl,
80+
});
81+
});
82+
},
83+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "qa-voice-call-runtime",
3+
"activation": {
4+
"onStartup": true
5+
},
6+
"configSchema": {
7+
"type": "object",
8+
"additionalProperties": false,
9+
"properties": {}
10+
}
11+
}

‎test/e2e/qa-lab/runtime/voice-call-gateway.ts‎

Lines changed: 7 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -45,99 +45,12 @@ function parseOptions(argv: readonly string[]): ProducerOptions {
4545
};
4646
}
4747

48-
async function createFixturePlugin(root: string) {
49-
const pluginDir = path.join(root, FIXTURE_PLUGIN_ID);
50-
const bridgeCallsPath = path.join(root, "bridge-calls.jsonl");
51-
const toolResultsPath = path.join(root, "tool-results.jsonl");
52-
await fs.mkdir(pluginDir, { recursive: true });
53-
await fs.writeFile(
54-
path.join(pluginDir, "openclaw.plugin.json"),
55-
`${JSON.stringify(
56-
{
57-
id: FIXTURE_PLUGIN_ID,
58-
activation: { onStartup: true },
59-
configSchema: { type: "object", additionalProperties: false, properties: {} },
60-
},
61-
null,
62-
2,
63-
)}\n`,
64-
"utf8",
65-
);
66-
await fs.writeFile(
67-
path.join(pluginDir, "index.js"),
68-
`const fs = require("node:fs");
69-
70-
const append = (file, value) => fs.appendFileSync(file, JSON.stringify(value) + "\\n");
71-
module.exports = {
72-
id: ${JSON.stringify(FIXTURE_PLUGIN_ID)},
73-
register(api) {
74-
api.registerRealtimeVoiceProvider({
75-
id: ${JSON.stringify(FIXTURE_REALTIME_PROVIDER_ID)},
76-
label: "QA Voice Call Realtime",
77-
isConfigured: () => true,
78-
createBrowserSession() {
79-
throw new Error("Voice Call fixture is bridge-only");
80-
},
81-
createBridge(request) {
82-
append(process.env.OPENCLAW_QA_VOICE_BRIDGE_CALLS_PATH, {
83-
instructions: request.instructions,
84-
tools: request.tools?.map((tool) => tool.name) ?? [],
85-
});
86-
let connected = false;
87-
return {
88-
supportsToolResultContinuation: true,
89-
async connect() {
90-
connected = true;
91-
request.onReady?.();
92-
request.onTranscript?.("user", "Caller partial transcript context", false);
93-
setTimeout(() => {
94-
request.onToolCall?.({
95-
itemId: "qa-consult-item",
96-
callId: "qa-consult-call",
97-
name: "openclaw_agent_consult",
98-
args: {
99-
question: "Use the embedded agent context to identify the caller request.",
100-
context: "Realtime provider context marker: VOICE-CONSULT-42",
101-
},
102-
});
103-
}, 10);
104-
},
105-
sendAudio() {},
106-
setMediaTimestamp() {},
107-
submitToolResult(callId, result, options) {
108-
append(process.env.OPENCLAW_QA_VOICE_TOOL_RESULTS_PATH, { callId, result, options });
109-
},
110-
acknowledgeMark() {},
111-
close() { connected = false; },
112-
isConnected() { return connected; },
113-
triggerGreeting() {},
114-
};
115-
},
116-
});
117-
api.registerGatewayMethod("qa.voiceCall.streamSession", async ({ params, respond }) => {
118-
const runtime = globalThis[Symbol.for("openclaw.voice-call.runtime")];
119-
const callId = typeof params?.callId === "string" ? params.callId : "";
120-
const call = runtime?.manager?.getCall?.(callId);
121-
const issue = runtime?.manager?.streamSessionIssuer;
122-
if (!runtime || !call || typeof issue !== "function" || !call.providerCallId) {
123-
respond(false, undefined, { code: "UNAVAILABLE", message: "Voice Call runtime stream issuer unavailable" });
124-
return;
125-
}
126-
const session = issue({
127-
providerName: "twilio",
128-
callId,
129-
from: call.from,
130-
to: call.to,
131-
direction: call.direction,
132-
});
133-
respond(true, { ...session, providerCallId: call.providerCallId, webhookUrl: runtime.webhookUrl });
134-
});
135-
},
136-
};
137-
`,
138-
"utf8",
139-
);
140-
return { bridgeCallsPath, pluginDir, toolResultsPath };
48+
function createFixturePlugin(repoRoot: string, outputRoot: string) {
49+
return {
50+
pluginDir: path.join(repoRoot, "test/e2e/qa-lab/runtime/fixtures/voice-call-runtime-plugin"),
51+
bridgeCallsPath: path.join(outputRoot, "bridge-calls.jsonl"),
52+
toolResultsPath: path.join(outputRoot, "tool-results.jsonl"),
53+
};
14154
}
14255

14356
function withVoiceCallConfig(params: {
@@ -255,7 +168,7 @@ async function openRealtimeMediaStream(params: {
255168

256169
async function runVoiceCallProof(options: ProducerOptions): Promise<string> {
257170
const fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-voice-call-gateway-"));
258-
const fixture = await createFixturePlugin(fixtureRoot);
171+
const fixture = createFixturePlugin(options.repoRoot, fixtureRoot);
259172
const mock = await startQaMockOpenAiServer();
260173
const servePort = await getFreePort();
261174
let gateway: Awaited<ReturnType<typeof startQaGatewayChild>> | undefined;

0 commit comments

Comments
 (0)