Skip to content

Commit 9f5776e

Browse files
authored
fix(voice-call): status exits after offline lookup (#125354)
* fix(voice-call): keep status fallback read-only * test(voice-call): assert offline status stays read-only * chore: keep changelog release-owned * test(voice-call): share status fallback harness
1 parent d402e5d commit 9f5776e

3 files changed

Lines changed: 66 additions & 30 deletions

File tree

‎extensions/voice-call/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ describe("voice-call plugin", () => {
12271227
}
12281228
});
12291229

1230-
it("CLI status lists active calls without a call id", async () => {
1230+
it("CLI status stays read-only when the gateway is unavailable", async () => {
12311231
const program = new Command();
12321232
const stdout = captureStdout();
12331233
await registerVoiceCallCli(program);
@@ -1237,8 +1237,8 @@ describe("voice-call plugin", () => {
12371237
const parsed = JSON.parse(stdout.output()) as {
12381238
calls?: Array<{ callId?: string }>;
12391239
};
1240-
expect(parsed.calls).toHaveLength(1);
1241-
expect(parsed.calls?.[0]?.callId).toBe("call-1");
1240+
expect(parsed.calls).toEqual([]);
1241+
expect(createVoiceCallRuntime).not.toHaveBeenCalled();
12421242
} finally {
12431243
stdout.restore();
12441244
}

‎extensions/voice-call/src/cli.test.ts‎

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Command } from "commander";
66
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
77
import { afterEach, describe, expect, it, vi } from "vitest";
88
const callGatewayFromCliMock = vi.hoisted(() => vi.fn());
9+
const findCallMatchesInStoreMock = vi.hoisted(() => vi.fn());
10+
const loadActiveCallsFromStoreMock = vi.hoisted(() => vi.fn());
911
const sleepMock = vi.hoisted(() =>
1012
vi.fn(
1113
async (ms: number) =>
@@ -23,6 +25,11 @@ vi.mock("../api.js", async (importOriginal) => ({
2325
...(await importOriginal<typeof import("../api.js")>()),
2426
sleep: sleepMock,
2527
}));
28+
vi.mock("./manager/store.js", async (importOriginal) => ({
29+
...(await importOriginal<typeof import("./manager/store.js")>()),
30+
findCallMatchesInStore: findCallMatchesInStoreMock,
31+
loadActiveCallsFromStore: loadActiveCallsFromStoreMock,
32+
}));
2633

2734
import { registerVoiceCallCli } from "./cli.js";
2835

@@ -41,6 +48,8 @@ function captureStdout() {
4148
describe("voice-call CLI status fallback", () => {
4249
afterEach(() => {
4350
callGatewayFromCliMock.mockReset();
51+
findCallMatchesInStoreMock.mockReset();
52+
loadActiveCallsFromStoreMock.mockReset();
4453
sleepMock.mockReset();
4554
sleepMock.mockImplementation(
4655
async (ms: number) =>
@@ -66,53 +75,72 @@ describe("voice-call CLI status fallback", () => {
6675
return program;
6776
}
6877

69-
async function runStatusWithUnavailableGateway(
70-
manager: Record<string, unknown>,
71-
error = new Error("connect ECONNREFUSED 127.0.0.1:18789"),
72-
): Promise<unknown> {
73-
callGatewayFromCliMock.mockRejectedValue(error);
74-
const program = buildProgram(manager);
78+
async function runStatusWithUnavailableGateway(params: {
79+
persisted?: unknown;
80+
error?: Error;
81+
args?: string[];
82+
}): Promise<unknown> {
83+
callGatewayFromCliMock.mockRejectedValue(
84+
params.error ?? new Error("connect ECONNREFUSED 127.0.0.1:18789"),
85+
);
86+
findCallMatchesInStoreMock.mockResolvedValue({ byCallId: params.persisted });
87+
const ensureRuntime = vi.fn(async () => {
88+
throw new Error("status fallback must not initialize the telephony runtime");
89+
});
90+
const program = new Command();
91+
registerVoiceCallCli({
92+
program,
93+
config: {} as never,
94+
ensureRuntime,
95+
stateRuntime: {} as never,
96+
logger: { info() {}, warn() {}, error() {}, debug() {} } as never,
97+
});
7598
const capturer = captureStdout();
7699
try {
77-
await program.parseAsync(["voicecall", "status", "--call-id", "call-1", "--json"], {
78-
from: "user",
79-
});
100+
await program.parseAsync(
101+
["voicecall", "status", ...(params.args ?? ["--call-id", "call-1"]), "--json"],
102+
{ from: "user" },
103+
);
80104
} finally {
81105
capturer.restore();
82106
}
107+
expect(ensureRuntime).not.toHaveBeenCalled();
83108
return JSON.parse(capturer.output().trim());
84109
}
85110

86111
it("uses the manager's persisted fallback when the gateway is unavailable", async () => {
87112
const result = await runStatusWithUnavailableGateway({
88-
getActiveCalls: () => [],
89-
getCallFromMemoryOrStore: async () => ({
113+
persisted: {
90114
callId: "call-1",
91115
providerCallId: "CA123",
92116
state: "completed",
93117
endReason: "completed",
94118
endedAt: 1,
95-
}),
119+
},
96120
});
97121
expect(result).toMatchObject({ callId: "call-1", state: "completed" });
98122
});
99123

100124
it("reports found:false when the call is neither active nor persisted", async () => {
101-
const result = await runStatusWithUnavailableGateway({
102-
getActiveCalls: () => [],
103-
getCallFromMemoryOrStore: async () => undefined,
104-
});
125+
const result = await runStatusWithUnavailableGateway({});
105126
expect(result).toEqual({ found: false });
106127
});
107128

129+
it("lists persisted active calls without initializing the telephony runtime", async () => {
130+
loadActiveCallsFromStoreMock.mockReturnValue({
131+
activeCalls: new Map([["call-1", { callId: "call-1", state: "ringing" }]]),
132+
});
133+
expect(await runStatusWithUnavailableGateway({ args: [] })).toEqual({
134+
found: true,
135+
calls: [{ callId: "call-1", state: "ringing" }],
136+
});
137+
});
138+
108139
it("falls back after an abnormal local gateway close", async () => {
109-
const result = await runStatusWithUnavailableGateway(
110-
{
111-
getActiveCalls: () => [],
112-
getCallFromMemoryOrStore: async () => ({ callId: "call-1", state: "completed" }),
113-
},
114-
new Error("gateway closed (1006 abnormal closure (no close frame)): no close reason"),
115-
);
140+
const result = await runStatusWithUnavailableGateway({
141+
persisted: { callId: "call-1", state: "completed" },
142+
error: new Error("gateway closed (1006 abnormal closure (no close frame)): no close reason"),
143+
});
116144
expect(result).toMatchObject({ callId: "call-1", state: "completed" });
117145
});
118146

‎extensions/voice-call/src/cli.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import {
1919
} from "openclaw/plugin-sdk/string-coerce-runtime";
2020
import { sleep } from "../api.js";
2121
import { validateProviderConfig, type VoiceCallConfig } from "./config.js";
22-
import { getCallHistoryFromStore } from "./manager/store.js";
22+
import {
23+
findCallMatchesInStore,
24+
getCallHistoryFromStore,
25+
loadActiveCallsFromStore,
26+
} from "./manager/store.js";
2327
import { setVoiceCallStateRuntime, type VoiceCallStateRuntime } from "./runtime-state.js";
2428
import type { VoiceCallRuntime } from "./runtime.js";
2529
import { resolveDefaultVoiceCallStoreDir } from "./store-path.js";
@@ -716,15 +720,19 @@ export function registerVoiceCallCli(params: {
716720
writeStdoutJson(gateway.payload);
717721
return;
718722
}
719-
const rt = await ensureRuntime();
723+
// Status is a read-only command. Starting the telephony runtime here would
724+
// bind the webhook port and keep this one-shot CLI process alive.
725+
ensureHistoryStateRuntime();
726+
const storePath = path.dirname(resolveDefaultStorePath(config));
720727
if (options.callId) {
721-
const call = await rt.manager.getCallFromMemoryOrStore(options.callId);
728+
const persisted = await findCallMatchesInStore(storePath, options.callId);
729+
const call = persisted.byCallId ?? persisted.byProviderCallId;
722730
writeStdoutJson(call ?? { found: false });
723731
return;
724732
}
725733
writeStdoutJson({
726734
found: true,
727-
calls: rt.manager.getActiveCalls(),
735+
calls: Array.from(loadActiveCallsFromStore(storePath).activeCalls.values()),
728736
});
729737
});
730738

0 commit comments

Comments
 (0)