From 39a6f3fa47f9096c1ffe88728048830d02167e8a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 07:53:46 +0100 Subject: [PATCH] test: tighten media echo transcript assertions --- .../echo-transcript.test.ts | 91 +++++++++++-------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/src/media-understanding/echo-transcript.test.ts b/src/media-understanding/echo-transcript.test.ts index d495efb169a..c1f31af621e 100644 --- a/src/media-understanding/echo-transcript.test.ts +++ b/src/media-understanding/echo-transcript.test.ts @@ -25,6 +25,8 @@ vi.mock("../utils/message-channel.js", () => ({ import { DEFAULT_ECHO_TRANSCRIPT_FORMAT, sendTranscriptEcho } from "./echo-transcript.js"; +const EMPTY_CONFIG = {} as OpenClawConfig; + function createCtx(overrides?: Partial): MsgContext { return { Provider: "voicechat", @@ -47,44 +49,47 @@ describe("sendTranscriptEcho", () => { it("sends the default formatted transcript to the resolved origin", async () => { await sendTranscriptEcho({ ctx: createCtx(), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "hello world", }); expect(mockDeliverOutboundPayloads).toHaveBeenCalledOnce(); - expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - channel: "voicechat", - to: "+10000000001", - accountId: "acc1", - threadId: undefined, - payloads: [{ text: DEFAULT_ECHO_TRANSCRIPT_FORMAT.replace("{transcript}", "hello world") }], - bestEffort: true, - durability: "best_effort", - }), - ); + expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith({ + cfg: EMPTY_CONFIG, + channel: "voicechat", + to: "+10000000001", + accountId: "acc1", + threadId: undefined, + payloads: [{ text: DEFAULT_ECHO_TRANSCRIPT_FORMAT.replace("{transcript}", "hello world") }], + bestEffort: true, + durability: "best_effort", + }); }); it("uses a custom format when provided", async () => { await sendTranscriptEcho({ ctx: createCtx(), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "custom message", format: "🎙️ Heard: {transcript}", }); - expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith( - expect.objectContaining({ - payloads: [{ text: "🎙️ Heard: custom message" }], - }), - ); + expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith({ + cfg: EMPTY_CONFIG, + channel: "voicechat", + to: "+10000000001", + accountId: "acc1", + threadId: undefined, + payloads: [{ text: "🎙️ Heard: custom message" }], + bestEffort: true, + durability: "best_effort", + }); }); it("skips non-deliverable channels", async () => { await sendTranscriptEcho({ ctx: createCtx({ Provider: "internal-system", From: "some-source" }), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "hello world", }); @@ -94,7 +99,7 @@ describe("sendTranscriptEcho", () => { it("skips when ctx has no resolved destination", async () => { await sendTranscriptEcho({ ctx: createCtx({ From: undefined, OriginatingTo: undefined }), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "hello world", }); @@ -104,15 +109,20 @@ describe("sendTranscriptEcho", () => { it("prefers OriginatingTo when From is absent", async () => { await sendTranscriptEcho({ ctx: createCtx({ From: undefined, OriginatingTo: "+19999999999" }), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "hello world", }); - expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith( - expect.objectContaining({ - to: "+19999999999", - }), - ); + expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith({ + cfg: EMPTY_CONFIG, + channel: "voicechat", + to: "+19999999999", + accountId: "acc1", + threadId: undefined, + payloads: [{ text: DEFAULT_ECHO_TRANSCRIPT_FORMAT.replace("{transcript}", "hello world") }], + bestEffort: true, + durability: "best_effort", + }); }); it("forwards Telegram account and thread metadata to outbound delivery", async () => { @@ -124,21 +134,22 @@ describe("sendTranscriptEcho", () => { AccountId: "primary", MessageThreadId: 77, }), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "threaded voice note", }); - expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "telegram", - to: "telegram:42", - accountId: "primary", - threadId: 77, - payloads: [ - { text: DEFAULT_ECHO_TRANSCRIPT_FORMAT.replace("{transcript}", "threaded voice note") }, - ], - }), - ); + expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith({ + cfg: EMPTY_CONFIG, + channel: "telegram", + to: "telegram:42", + accountId: "primary", + threadId: 77, + payloads: [ + { text: DEFAULT_ECHO_TRANSCRIPT_FORMAT.replace("{transcript}", "threaded voice note") }, + ], + bestEffort: true, + durability: "best_effort", + }); }); it("swallows delivery failures", async () => { @@ -147,7 +158,7 @@ describe("sendTranscriptEcho", () => { await expect( sendTranscriptEcho({ ctx: createCtx(), - cfg: {} as OpenClawConfig, + cfg: EMPTY_CONFIG, transcript: "hello world", }), ).resolves.toBeUndefined();