
























@@ -0,0 +1,81 @@
1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import { maybeControlDiscordVoiceAgentRun } from "./agent-control.js";
3+4+const mocks = vi.hoisted(() => ({
5+controlRealtimeVoiceAgentRun: vi.fn(),
6+shouldAutoControlRealtimeVoiceAgentText: vi.fn(),
7+}));
8+9+vi.mock("openclaw/plugin-sdk/realtime-voice", () => ({
10+controlRealtimeVoiceAgentRun: mocks.controlRealtimeVoiceAgentRun,
11+shouldAutoControlRealtimeVoiceAgentText: mocks.shouldAutoControlRealtimeVoiceAgentText,
12+}));
13+14+function createEntry() {
15+return { route: { sessionKey: "discord:g1:c1" } } as Parameters<
16+typeof maybeControlDiscordVoiceAgentRun
17+>[0]["entry"];
18+}
19+20+describe("maybeControlDiscordVoiceAgentRun", () => {
21+beforeEach(() => {
22+vi.clearAllMocks();
23+mocks.shouldAutoControlRealtimeVoiceAgentText.mockReturnValue(true);
24+});
25+26+it("falls back for inactive cancel-like phrases", async () => {
27+const result = {
28+ok: true,
29+active: false,
30+mode: "cancel",
31+sessionKey: "discord:g1:c1",
32+message: "There is no active OpenClaw run to cancel.",
33+speak: true,
34+suppress: false,
35+};
36+mocks.controlRealtimeVoiceAgentRun.mockResolvedValue(result);
37+38+await expect(
39+maybeControlDiscordVoiceAgentRun({
40+entry: createEntry(),
41+text: "cancel my meeting tomorrow",
42+}),
43+).resolves.toEqual({ handled: false, result });
44+});
45+46+it("handles active cancel requests", async () => {
47+const result = {
48+ok: true,
49+active: true,
50+mode: "cancel",
51+sessionKey: "discord:g1:c1",
52+message: "Cancelled the active OpenClaw run.",
53+speak: true,
54+suppress: false,
55+};
56+mocks.controlRealtimeVoiceAgentRun.mockResolvedValue(result);
57+58+await expect(
59+maybeControlDiscordVoiceAgentRun({
60+entry: createEntry(),
61+text: "cancel that",
62+}),
63+).resolves.toEqual({
64+handled: true,
65+ result,
66+speakText: "Cancelled the active OpenClaw run.",
67+});
68+});
69+70+it("ignores non-control phrases", async () => {
71+mocks.shouldAutoControlRealtimeVoiceAgentText.mockReturnValue(false);
72+73+await expect(
74+maybeControlDiscordVoiceAgentRun({
75+entry: createEntry(),
76+text: "what is next",
77+}),
78+).resolves.toEqual({ handled: false });
79+expect(mocks.controlRealtimeVoiceAgentRun).not.toHaveBeenCalled();
80+});
81+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。