test: use synthetic outbound routing fixtures

This commit is contained in:
Peter Steinberger
2026-04-20 23:32:08 +01:00
parent 68954f9c6c
commit 1151d69bb8
4 changed files with 37 additions and 29 deletions

View File

@@ -69,6 +69,14 @@ vi.mock("./targets.js", () => ({
resolveSessionDeliveryTarget: mocks.resolveSessionDeliveryTarget,
}));
vi.mock("../../utils/message-channel.js", () => ({
INTERNAL_MESSAGE_CHANNEL: "webchat",
isDeliverableMessageChannel: (channel: string) => ["directchat", "workspace"].includes(channel),
isGatewayMessageChannel: (channel: string) =>
["directchat", "workspace", "webchat"].includes(channel),
normalizeMessageChannel: (value: string) => value.trim().toLowerCase(),
}));
import type { OpenClawConfig } from "../../config/config.js";
let resolveAgentDeliveryPlan: typeof import("./agent-delivery.js").resolveAgentDeliveryPlan;
let resolveAgentOutboundTarget: typeof import("./agent-delivery.js").resolveAgentOutboundTarget;
@@ -93,7 +101,7 @@ describe("agent delivery helpers", () => {
sessionEntry: {
sessionId: "s1",
updatedAt: 1,
deliveryContext: { channel: "whatsapp", to: "+1555", accountId: "work" },
deliveryContext: { channel: "directchat", to: "+1555", accountId: "work" },
},
requestedChannel: "last",
explicitTo: undefined,
@@ -101,7 +109,7 @@ describe("agent delivery helpers", () => {
wantsDelivery: true,
},
expected: {
resolvedChannel: "whatsapp",
resolvedChannel: "directchat",
resolvedTo: "+1555",
resolvedAccountId: "work",
deliveryTargetMode: "implicit",
@@ -125,17 +133,17 @@ describe("agent delivery helpers", () => {
sessionEntry: {
sessionId: "s4",
updatedAt: 4,
deliveryContext: { channel: "slack", to: "U_WRONG", accountId: "wrong" },
deliveryContext: { channel: "workspace", to: "U_WRONG", accountId: "wrong" },
},
requestedChannel: "last",
turnSourceChannel: "whatsapp",
turnSourceChannel: "directchat",
turnSourceTo: "+17775550123",
turnSourceAccountId: "work",
accountId: undefined,
wantsDelivery: true,
},
expected: {
resolvedChannel: "whatsapp",
resolvedChannel: "directchat",
resolvedTo: "+17775550123",
resolvedAccountId: "work",
},
@@ -145,15 +153,15 @@ describe("agent delivery helpers", () => {
sessionEntry: {
sessionId: "s5",
updatedAt: 5,
deliveryContext: { channel: "slack", to: "U_WRONG" },
deliveryContext: { channel: "workspace", to: "U_WRONG" },
},
requestedChannel: "last",
turnSourceChannel: "whatsapp",
turnSourceChannel: "directchat",
accountId: undefined,
wantsDelivery: true,
},
expected: {
resolvedChannel: "whatsapp",
resolvedChannel: "directchat",
resolvedTo: undefined,
},
},
@@ -167,7 +175,7 @@ describe("agent delivery helpers", () => {
sessionEntry: {
sessionId: "s2",
updatedAt: 2,
deliveryContext: { channel: "whatsapp" },
deliveryContext: { channel: "directchat" },
},
requestedChannel: "last",
explicitTo: undefined,
@@ -191,7 +199,7 @@ describe("agent delivery helpers", () => {
sessionEntry: {
sessionId: "s3",
updatedAt: 3,
deliveryContext: { channel: "whatsapp", to: "+1555" },
deliveryContext: { channel: "directchat", to: "+1555" },
},
requestedChannel: "last",
explicitTo: "+1555",

View File

@@ -154,7 +154,7 @@ describe("executeSendAction", () => {
cfg: {},
channel: "demo-outbound",
params: { media: "/tmp/host.png" },
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
dryRun: false,
...overrides,
} as ExecuteSendContext;
@@ -230,7 +230,7 @@ describe("executeSendAction", () => {
cfg: {},
channel: "demo-outbound",
params: {},
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
requesterSenderId: "attacker",
dryRun: false,
},
@@ -259,7 +259,7 @@ describe("executeSendAction", () => {
cfg: {},
channel: "demo-outbound",
params: {},
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
requesterSenderName: "Alice",
requesterSenderUsername: "alice_u",
requesterSenderE164: "+15551234567",
@@ -292,7 +292,7 @@ describe("executeSendAction", () => {
cfg: {},
channel: "demo-outbound",
params: {},
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
requesterAccountId: "source-account",
requesterSenderId: "attacker",
accountId: "destination-account",
@@ -304,7 +304,7 @@ describe("executeSendAction", () => {
expect(mocks.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
requesterSessionKey: "agent:main:whatsapp:group:ops",
requesterSessionKey: "agent:main:directchat:group:ops",
requesterAccountId: "source-account",
requesterSenderId: "attacker",
accountId: "destination-account",
@@ -347,7 +347,7 @@ describe("executeSendAction", () => {
expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith(
expect.objectContaining({
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
messageProvider: undefined,
}),
);
@@ -362,7 +362,7 @@ describe("executeSendAction", () => {
expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith(
expect.objectContaining({
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
accountId: "source-account",
}),
);
@@ -376,7 +376,7 @@ describe("executeSendAction", () => {
expect(mocks.resolveAgentScopedOutboundMediaAccess).toHaveBeenCalledWith(
expect.objectContaining({
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
accountId: "destination-account",
}),
);
@@ -396,7 +396,7 @@ describe("executeSendAction", () => {
cfg: {},
channel: "demo-outbound",
params: {},
sessionKey: "agent:main:whatsapp:group:ops",
sessionKey: "agent:main:directchat:group:ops",
requesterSenderId: "attacker",
accountId: "destination-account",
dryRun: false,
@@ -407,7 +407,7 @@ describe("executeSendAction", () => {
expect(mocks.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
requesterSessionKey: "agent:main:whatsapp:group:ops",
requesterSessionKey: "agent:main:directchat:group:ops",
requesterAccountId: "destination-account",
}),
);

View File

@@ -102,13 +102,13 @@ describe("buildOutboundSessionContext", () => {
expect(
buildOutboundSessionContext({
cfg: {} as never,
requesterSenderId: "id:telegram:123",
requesterSenderId: "id:forum:123",
requesterSenderName: " Alice ",
requesterSenderUsername: " alice_u ",
requesterSenderE164: " +15551234567 ",
}),
).toEqual({
requesterSenderId: "id:telegram:123",
requesterSenderId: "id:forum:123",
requesterSenderName: "Alice",
requesterSenderUsername: "alice_u",
requesterSenderE164: "+15551234567",

View File

@@ -88,7 +88,7 @@ describe("resolveMessagingTarget (directory fallback)", () => {
const first = await expectOkResolution({
cfg,
channel: "discord",
channel: "richchat",
input: "support",
});
expect(first.target.source).toBe("directory");
@@ -98,7 +98,7 @@ describe("resolveMessagingTarget (directory fallback)", () => {
const second = await expectOkResolution({
cfg,
channel: "discord",
channel: "richchat",
input: "support",
});
expect(second.target.to).toBe("123456789");
@@ -109,7 +109,7 @@ describe("resolveMessagingTarget (directory fallback)", () => {
it("skips directory lookup for direct ids", async () => {
const result = await expectOkResolution({
cfg,
channel: "discord",
channel: "richchat",
input: "123456789",
});
expect(result.target.source).toBe("normalized");
@@ -177,7 +177,7 @@ describe("resolveMessagingTarget (directory fallback)", () => {
const result = await expectOkResolution({
cfg,
channel: "imessage",
channel: "localchat",
input: "+15551234567",
});
expect(result.target).toEqual({
@@ -213,7 +213,7 @@ describe("resolveMessagingTarget (directory fallback)", () => {
const result = await expectOkResolution({
cfg,
channel: "slack",
channel: "workspace",
input: "#C123ABC",
});
expect(result.target.to).toBe("channel:C123ABC");
@@ -223,10 +223,10 @@ describe("resolveMessagingTarget (directory fallback)", () => {
it("defers target display formatting to the plugin when available", () => {
mocks.getChannelPlugin.mockReturnValue({
messaging: {
formatTargetDisplay: ({ target }: { target: string }) => target.replace(/^telegram:/i, ""),
formatTargetDisplay: ({ target }: { target: string }) => target.replace(/^forum:/i, ""),
},
});
expect(formatTargetDisplay({ channel: "telegram", target: "telegram:12345" })).toBe("12345");
expect(formatTargetDisplay({ channel: "forum", target: "forum:12345" })).toBe("12345");
});
});