mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-04-30 14:02:56 +08:00
fix(voice-call): avoid blocking gateway startup
This commit is contained in:
@@ -178,6 +178,32 @@ describe("voice-call plugin", () => {
|
||||
expect(respond).toHaveBeenCalledWith(true, { callId: "call-1", initiated: true });
|
||||
});
|
||||
|
||||
it("does not block service startup while runtime exposure initializes", async () => {
|
||||
let resolveRuntime: ((runtime: VoiceCallRuntime) => void) | undefined;
|
||||
vi.mocked(createVoiceCallRuntime).mockReturnValueOnce(
|
||||
new Promise<VoiceCallRuntime>((resolve) => {
|
||||
resolveRuntime = resolve;
|
||||
}),
|
||||
);
|
||||
const { service, methods } = setup({ provider: "mock" });
|
||||
|
||||
expect(service).toBeDefined();
|
||||
expect(service!.start(createServiceContext())).toBeUndefined();
|
||||
expect(createVoiceCallRuntime).toHaveBeenCalledTimes(1);
|
||||
|
||||
resolveRuntime?.(runtimeStub);
|
||||
const handler = methods.get("voicecall.initiate") as
|
||||
| ((ctx: {
|
||||
params: Record<string, unknown>;
|
||||
respond: ReturnType<typeof vi.fn>;
|
||||
}) => Promise<void>)
|
||||
| undefined;
|
||||
const respond = vi.fn();
|
||||
await handler?.({ params: { message: "Hi" }, respond });
|
||||
|
||||
expect(respond).toHaveBeenCalledWith(true, { callId: "call-1", initiated: true });
|
||||
});
|
||||
|
||||
it("creates a fresh shared runtime after service stop", async () => {
|
||||
const first = setup({ provider: "mock" });
|
||||
await first.service?.start(createServiceContext());
|
||||
|
||||
@@ -607,7 +607,7 @@ export default definePluginEntry({
|
||||
|
||||
api.registerService({
|
||||
id: "voicecall",
|
||||
start: async () => {
|
||||
start: () => {
|
||||
if (!config.enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -617,11 +617,9 @@ export default definePluginEntry({
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await ensureRuntime();
|
||||
} catch (err) {
|
||||
void ensureRuntime().catch((err) => {
|
||||
api.logger.error(`[voice-call] Failed to start runtime: ${formatErrorMessage(err)}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
stop: async () => {
|
||||
if (runtimeState[VOICE_CALL_RUNTIME_STOP_PROMISE_KEY]) {
|
||||
|
||||
Reference in New Issue
Block a user