test: tighten media echo transcript assertions

This commit is contained in:
Peter Steinberger
2026-05-09 07:53:46 +01:00
parent 5c57e55f2f
commit 39a6f3fa47

View File

@@ -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>): 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();