test: share session target and outbound mirror helpers

This commit is contained in:
Peter Steinberger
2026-03-13 22:03:57 +00:00
parent 017c0dce32
commit c5dc61e795
2 changed files with 71 additions and 53 deletions

View File

@@ -47,6 +47,47 @@ describe("executeSendAction", () => {
};
}
function expectMirrorWrite(
expected: Partial<{
agentId: string;
sessionKey: string;
text: string;
idempotencyKey: string;
mediaUrls: string[];
}>,
) {
expect(mocks.appendAssistantMessageToSessionTranscript).toHaveBeenCalledWith(
expect.objectContaining(expected),
);
}
async function executePluginMirroredSend(params: {
mirror?: Partial<{
sessionKey: string;
agentId?: string;
idempotencyKey?: string;
}>;
mediaUrls?: string[];
}) {
mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin"));
await executeSendAction({
ctx: {
cfg: {},
channel: "discord",
params: { to: "channel:123", message: "hello" },
dryRun: false,
mirror: {
sessionKey: "agent:main:discord:channel:123",
...params.mirror,
},
},
to: "channel:123",
message: "hello",
mediaUrls: params.mediaUrls,
});
}
beforeEach(() => {
mocks.dispatchChannelMessageAction.mockClear();
mocks.sendMessage.mockClear();
@@ -131,59 +172,33 @@ describe("executeSendAction", () => {
});
it("passes mirror idempotency keys through plugin-handled sends", async () => {
mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin"));
await executeSendAction({
ctx: {
cfg: {},
channel: "discord",
params: { to: "channel:123", message: "hello" },
dryRun: false,
mirror: {
sessionKey: "agent:main:discord:channel:123",
idempotencyKey: "idem-plugin-send-1",
},
await executePluginMirroredSend({
mirror: {
idempotencyKey: "idem-plugin-send-1",
},
to: "channel:123",
message: "hello",
});
expect(mocks.appendAssistantMessageToSessionTranscript).toHaveBeenCalledWith(
expect.objectContaining({
sessionKey: "agent:main:discord:channel:123",
text: "hello",
idempotencyKey: "idem-plugin-send-1",
}),
);
expectMirrorWrite({
sessionKey: "agent:main:discord:channel:123",
text: "hello",
idempotencyKey: "idem-plugin-send-1",
});
});
it("falls back to message and media params for plugin-handled mirror writes", async () => {
mocks.dispatchChannelMessageAction.mockResolvedValue(pluginActionResult("msg-plugin"));
await executeSendAction({
ctx: {
cfg: {},
channel: "discord",
params: { to: "channel:123", message: "hello" },
dryRun: false,
mirror: {
sessionKey: "agent:main:discord:channel:123",
agentId: "agent-9",
},
await executePluginMirroredSend({
mirror: {
agentId: "agent-9",
},
to: "channel:123",
message: "hello",
mediaUrls: ["https://example.com/a.png", "https://example.com/b.png"],
});
expect(mocks.appendAssistantMessageToSessionTranscript).toHaveBeenCalledWith(
expect.objectContaining({
agentId: "agent-9",
sessionKey: "agent:main:discord:channel:123",
text: "hello",
mediaUrls: ["https://example.com/a.png", "https://example.com/b.png"],
}),
);
expectMirrorWrite({
agentId: "agent-9",
sessionKey: "agent:main:discord:channel:123",
text: "hello",
mediaUrls: ["https://example.com/a.png", "https://example.com/b.png"],
});
});
it("skips plugin dispatch during dry-run sends and forwards gateway + silent to sendMessage", async () => {