From a732b916f4f63a97c91ae7cb5f362c30058c609b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 23:59:08 +0100 Subject: [PATCH] test: use synthetic media channel fixtures --- .../apply.echo-transcript.test.ts | 11 ++++++---- .../echo-transcript.test.ts | 10 +++++++--- .../channel-inbound-roots.fast-path.test.ts | 18 ++++++++--------- src/media/read-capability.test.ts | 14 ++++++------- src/plugins/wired-hooks-inbound-claim.test.ts | 20 +++++++++---------- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/media-understanding/apply.echo-transcript.test.ts b/src/media-understanding/apply.echo-transcript.test.ts index 852999adc4a..19b0b123e56 100644 --- a/src/media-understanding/apply.echo-transcript.test.ts +++ b/src/media-understanding/apply.echo-transcript.test.ts @@ -67,7 +67,7 @@ function createAudioCtxWithProvider(mediaPath: string, extra?: Partial", MediaPath: mediaPath, MediaType: "audio/ogg", - Provider: "whatsapp", + Provider: "voicechat", From: "+10000000001", AccountId: "acc1", ...extra, @@ -174,6 +174,9 @@ describe("applyMediaUnderstanding – echo transcript", () => { vi.doMock("../infra/outbound/deliver-runtime.js", () => ({ deliverOutboundPayloads: (...args: unknown[]) => mockDeliverOutboundPayloads(...args), })); + vi.doMock("../utils/message-channel.js", () => ({ + isDeliverableMessageChannel: (channel: string) => channel === "voicechat", + })); vi.doMock("./provider-registry.js", async () => { const actual = await vi.importActual("./provider-registry.js"); @@ -220,7 +223,7 @@ describe("applyMediaUnderstanding – echo transcript", () => { runExecMock.mockReset(); runCommandWithTimeoutMock.mockReset(); mockDeliverOutboundPayloads.mockClear(); - mockDeliverOutboundPayloads.mockResolvedValue([{ channel: "whatsapp", messageId: "echo-1" }]); + mockDeliverOutboundPayloads.mockResolvedValue([{ channel: "voicechat", messageId: "echo-1" }]); }); afterAll(async () => { @@ -262,7 +265,7 @@ describe("applyMediaUnderstanding – echo transcript", () => { await applyMediaUnderstanding({ ctx, cfg, providers }); const callArgs = expectSingleEchoDeliveryCall(); - expect(callArgs.channel).toBe("whatsapp"); + expect(callArgs.channel).toBe("voicechat"); expect(callArgs.to).toBe("+10000000001"); expect(callArgs.accountId).toBe("acc1"); expect(callArgs.payloads).toHaveLength(1); @@ -279,7 +282,7 @@ describe("applyMediaUnderstanding – echo transcript", () => { Body: "", MediaPath: imgPath, MediaType: "image/jpeg", - Provider: "whatsapp", + Provider: "voicechat", From: "+10000000001", }; diff --git a/src/media-understanding/echo-transcript.test.ts b/src/media-understanding/echo-transcript.test.ts index 02784c8e577..163b85d44bf 100644 --- a/src/media-understanding/echo-transcript.test.ts +++ b/src/media-understanding/echo-transcript.test.ts @@ -8,11 +8,15 @@ vi.mock("../infra/outbound/deliver-runtime.js", () => ({ deliverOutboundPayloads: (...args: unknown[]) => mockDeliverOutboundPayloads(...args), })); +vi.mock("../utils/message-channel.js", () => ({ + isDeliverableMessageChannel: (channel: string) => channel === "voicechat", +})); + import { DEFAULT_ECHO_TRANSCRIPT_FORMAT, sendTranscriptEcho } from "./echo-transcript.js"; function createCtx(overrides?: Partial): MsgContext { return { - Provider: "whatsapp", + Provider: "voicechat", From: "+10000000001", AccountId: "acc1", ...overrides, @@ -22,7 +26,7 @@ function createCtx(overrides?: Partial): MsgContext { describe("sendTranscriptEcho", () => { beforeEach(() => { mockDeliverOutboundPayloads.mockReset(); - mockDeliverOutboundPayloads.mockResolvedValue([{ channel: "whatsapp", messageId: "echo-1" }]); + mockDeliverOutboundPayloads.mockResolvedValue([{ channel: "voicechat", messageId: "echo-1" }]); }); it("sends the default formatted transcript to the resolved origin", async () => { @@ -35,7 +39,7 @@ describe("sendTranscriptEcho", () => { expect(mockDeliverOutboundPayloads).toHaveBeenCalledOnce(); expect(mockDeliverOutboundPayloads).toHaveBeenCalledWith({ cfg: {}, - channel: "whatsapp", + channel: "voicechat", to: "+10000000001", accountId: "acc1", threadId: undefined, diff --git a/src/media/channel-inbound-roots.fast-path.test.ts b/src/media/channel-inbound-roots.fast-path.test.ts index bbaf6194fe6..2174dcb4245 100644 --- a/src/media/channel-inbound-roots.fast-path.test.ts +++ b/src/media/channel-inbound-roots.fast-path.test.ts @@ -26,7 +26,7 @@ function unableToResolve(dirName: string, artifactBasename: string): Error { function createContext(provider: string, accountId = "work"): MsgContext { return { Body: "hi", - From: "imessage:work:demo", + From: "localchat:work:demo", To: "+2000", ChatType: "direct", Provider: provider, @@ -42,7 +42,7 @@ describe("channel inbound roots fast path", () => { it("prefers media contract artifacts over full channel bootstrap", () => { publicSurfaceLoaderMocks.loadBundledPluginPublicArtifactModuleSync.mockImplementation( ({ artifactBasename, dirName }: { artifactBasename: string; dirName: string }) => { - if (dirName === "imessage" && artifactBasename === "media-contract-api.js") { + if (dirName === "localchat" && artifactBasename === "media-contract-api.js") { return { resolveInboundAttachmentRoots: ({ accountId }: { accountId?: string }) => [ `/local/${accountId}`, @@ -59,18 +59,18 @@ describe("channel inbound roots fast path", () => { expect( resolveChannelInboundAttachmentRoots({ cfg, - ctx: createContext("imessage"), + ctx: createContext("localchat"), }), ).toEqual(["/local/work"]); expect( resolveChannelRemoteInboundAttachmentRoots({ cfg, - ctx: createContext("imessage"), + ctx: createContext("localchat"), }), ).toEqual(["/remote/work"]); expect(publicSurfaceLoaderMocks.loadBundledPluginPublicArtifactModuleSync).toHaveBeenCalledWith( { - dirName: "imessage", + dirName: "localchat", artifactBasename: "media-contract-api.js", }, ); @@ -86,25 +86,25 @@ describe("channel inbound roots fast path", () => { expect( resolveChannelRemoteInboundAttachmentRoots({ cfg, - ctx: createContext("whatsapp"), + ctx: createContext("mobilechat"), }), ).toBeUndefined(); expect(publicSurfaceLoaderMocks.loadBundledPluginPublicArtifactModuleSync).toHaveBeenCalledWith( { - dirName: "whatsapp", + dirName: "mobilechat", artifactBasename: "media-contract-api.js", }, ); expect( publicSurfaceLoaderMocks.loadBundledPluginPublicArtifactModuleSync, ).not.toHaveBeenCalledWith({ - dirName: "whatsapp", + dirName: "mobilechat", artifactBasename: "contract-api.js", }); expect( publicSurfaceLoaderMocks.loadBundledPluginPublicArtifactModuleSync, ).not.toHaveBeenCalledWith({ - dirName: "whatsapp", + dirName: "mobilechat", artifactBasename: "index.js", }); }); diff --git a/src/media/read-capability.test.ts b/src/media/read-capability.test.ts index f2000ac4e90..0e2277ec2ca 100644 --- a/src/media/read-capability.test.ts +++ b/src/media/read-capability.test.ts @@ -36,7 +36,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { allow: ["read"], }, channels: { - whatsapp: { + requestchat: { groups: { ops: { toolsBySender: { @@ -52,7 +52,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { const result = resolveAgentScopedOutboundMediaAccess({ cfg, - sessionKey: "agent:main:whatsapp:group:ops", + sessionKey: "agent:main:requestchat:group:ops", mediaSources: ["/Users/peter/Pictures/photo.png"], // Production call sites set messageProvider: undefined when sessionKey is present; // resolveGroupToolPolicy derives channel from the session key instead. @@ -69,7 +69,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { allow: ["read"], }, channels: { - whatsapp: { + requestchat: { groups: { ops: { toolsBySender: { @@ -85,7 +85,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { const result = resolveAgentScopedOutboundMediaAccess({ cfg, - sessionKey: "agent:main:whatsapp:group:ops", + sessionKey: "agent:main:requestchat:group:ops", mediaSources: ["/Users/peter/Pictures/photo.png"], requesterSenderId: "trusted-user", }); @@ -101,7 +101,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { allow: ["read"], }, } as OpenClawConfig, - messageProvider: "whatsapp", + messageProvider: "requestchat", requesterSenderId: "trusted-user", }); @@ -115,7 +115,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { allow: ["read"], }, channels: { - whatsapp: { + requestchat: { groups: { ops: { toolsBySender: { @@ -128,7 +128,7 @@ describe("resolveAgentScopedOutboundMediaAccess", () => { }, }, } as OpenClawConfig, - messageProvider: "whatsapp", + messageProvider: "requestchat", requesterSenderId: "dm-sender", }); diff --git a/src/plugins/wired-hooks-inbound-claim.test.ts b/src/plugins/wired-hooks-inbound-claim.test.ts index df2ba0027ec..fc8a478fc47 100644 --- a/src/plugins/wired-hooks-inbound-claim.test.ts +++ b/src/plugins/wired-hooks-inbound-claim.test.ts @@ -3,31 +3,31 @@ import { createHookRunnerWithRegistry } from "./hooks.test-helpers.js"; const inboundClaimEvent = { content: "who are you", - channel: "discord", + channel: "guildchat", accountId: "default", conversationId: "channel:1", isGroup: true, }; const inboundClaimCtx = { - channelId: "discord", + channelId: "guildchat", accountId: "default", conversationId: "channel:1", }; -function createInboundClaimTelegramEvent() { +function createInboundClaimForumEvent() { return { content: "who are you", - channel: "telegram", + channel: "forum", accountId: "default", conversationId: "123:topic:77", isGroup: true, }; } -function createInboundClaimTelegramCtx() { +function createInboundClaimForumCtx() { return { - channelId: "telegram", + channelId: "forum", accountId: "default", conversationId: "123:topic:77", }; @@ -43,8 +43,8 @@ describe("inbound_claim hook runner", () => { ]); const result = await runner.runInboundClaim( - createInboundClaimTelegramEvent(), - createInboundClaimTelegramCtx(), + createInboundClaimForumEvent(), + createInboundClaimForumCtx(), ); expect(result).toEqual({ handled: true }); @@ -69,13 +69,13 @@ describe("inbound_claim hook runner", () => { const result = await runner.runInboundClaim( { - ...createInboundClaimTelegramEvent(), + ...createInboundClaimForumEvent(), content: "hi", conversationId: "123", isGroup: false, }, { - ...createInboundClaimTelegramCtx(), + ...createInboundClaimForumCtx(), conversationId: "123", }, );