diff --git a/extensions/whatsapp/src/send.test.ts b/extensions/whatsapp/src/send.test.ts index bf17b4131b7a..e4a51122d740 100644 --- a/extensions/whatsapp/src/send.test.ts +++ b/extensions/whatsapp/src/send.test.ts @@ -4,6 +4,7 @@ import os from "node:os"; import path from "node:path"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; import { redactIdentifier } from "openclaw/plugin-sdk/logging-core"; +import { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS } from "openclaw/plugin-sdk/media-runtime"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { WhatsAppSendKind, WhatsAppSendResult } from "./inbound/send-result.js"; import type { ActiveWebListener } from "./inbound/types.js"; @@ -296,9 +297,28 @@ describe("web outbound", () => { mediaUrl: `/tmp/${media.fileName}`, }); - expect(hoisted.runFfmpeg).toHaveBeenCalledWith( - expect.arrayContaining(["-c:a", "libopus", "-ar", "48000", "-b:a", "64k"]), - ); + expect(hoisted.runFfmpeg).toHaveBeenCalledTimes(1); + const ffmpegArgs = hoisted.runFfmpeg.mock.calls[0]?.[0] as string[] | undefined; + expect(ffmpegArgs?.slice(0, 5)).toEqual(["-hide_banner", "-loglevel", "error", "-y", "-i"]); + expect(ffmpegArgs?.[5]).toContain(`/input.${media.name}`); + expect(ffmpegArgs?.slice(6, -1)).toEqual([ + "-vn", + "-sn", + "-dn", + "-t", + String(MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS), + "-ar", + "48000", + "-ac", + "1", + "-c:a", + "libopus", + "-b:a", + "64k", + ]); + const outputPath = ffmpegArgs?.at(-1); + expect(outputPath).toContain("/fs-safe-output-"); + expect(outputPath).toContain("-voice.ogg.part"); expect(sendMessage).toHaveBeenNthCalledWith( 1, "+1555", @@ -381,12 +401,12 @@ describe("web outbound", () => { mediaUrls: [" /tmp/secondary.jpg "], }); - expect(loadWebMediaMock).toHaveBeenCalledWith( - "/tmp/primary.jpg", - expect.objectContaining({ - hostReadCapability: false, - }), - ); + expect(loadWebMediaMock).toHaveBeenCalledWith("/tmp/primary.jpg", { + maxBytes: 50 * 1024 * 1024, + localRoots: undefined, + readFile: undefined, + hostReadCapability: false, + }); expect(sendMessage).toHaveBeenLastCalledWith("+1555", "pic", buf, "image/jpeg"); }); @@ -402,12 +422,12 @@ describe("web outbound", () => { cfg: WHATSAPP_TEST_CFG, mediaUrls: [" ", " /tmp/pic.jpg "], }); - expect(loadWebMediaMock).toHaveBeenCalledWith( - "/tmp/pic.jpg", - expect.objectContaining({ - hostReadCapability: false, - }), - ); + expect(loadWebMediaMock).toHaveBeenCalledWith("/tmp/pic.jpg", { + maxBytes: 50 * 1024 * 1024, + localRoots: undefined, + readFile: undefined, + hostReadCapability: false, + }); expect(sendMessage).toHaveBeenLastCalledWith("+1555", "pic", buf, "image/jpeg"); }); @@ -463,13 +483,12 @@ describe("web outbound", () => { mediaLocalRoots: ["/tmp/workspace"], }); - expect(loadWebMediaMock).toHaveBeenCalledWith( - "/tmp/pic.jpg", - expect.objectContaining({ - maxBytes: 100 * 1024 * 1024, - localRoots: ["/tmp/workspace"], - }), - ); + expect(loadWebMediaMock).toHaveBeenCalledWith("/tmp/pic.jpg", { + maxBytes: 100 * 1024 * 1024, + localRoots: ["/tmp/workspace"], + readFile: undefined, + hostReadCapability: false, + }); }); it("sends polls via active listener", async () => {