test: use synthetic media channel fixtures

This commit is contained in:
Peter Steinberger
2026-04-20 23:59:08 +01:00
parent c8086b731a
commit a732b916f4
5 changed files with 40 additions and 33 deletions

View File

@@ -67,7 +67,7 @@ function createAudioCtxWithProvider(mediaPath: string, extra?: Partial<MsgContex
Body: "<media:audio>",
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<typeof import("./provider-registry.js")>("./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: "<media:image>",
MediaPath: imgPath,
MediaType: "image/jpeg",
Provider: "whatsapp",
Provider: "voicechat",
From: "+10000000001",
};

View File

@@ -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>): MsgContext {
return {
Provider: "whatsapp",
Provider: "voicechat",
From: "+10000000001",
AccountId: "acc1",
...overrides,
@@ -22,7 +26,7 @@ function createCtx(overrides?: Partial<MsgContext>): 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,

View File

@@ -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",
});
});

View File

@@ -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",
});

View File

@@ -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",
},
);