fix: harden outbound mirroring normalization

This commit is contained in:
Peter Steinberger
2026-01-24 12:51:29 +00:00
parent 8b4e40c602
commit 62c9255b6a
6 changed files with 60 additions and 2 deletions

View File

@@ -137,6 +137,34 @@ describe("gateway send mirroring", () => {
);
});
it("lowercases provided session keys for mirroring", async () => {
mocks.deliverOutboundPayloads.mockResolvedValue([{ messageId: "m-lower", channel: "slack" }]);
const respond = vi.fn();
await sendHandlers.send({
params: {
to: "channel:C1",
message: "hi",
channel: "slack",
idempotencyKey: "idem-lower",
sessionKey: "agent:main:slack:channel:C123",
},
respond,
context: makeContext(),
req: { type: "req", id: "1", method: "send" },
client: null,
isWebchatConnect: () => false,
});
expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
expect.objectContaining({
mirror: expect.objectContaining({
sessionKey: "agent:main:slack:channel:c123",
}),
}),
);
});
it("derives a target session key when none is provided", async () => {
mocks.deliverOutboundPayloads.mockResolvedValue([{ messageId: "m3", channel: "slack" }]);

View File

@@ -145,7 +145,7 @@ export const sendHandlers: GatewayRequestHandlers = {
);
const providedSessionKey =
typeof request.sessionKey === "string" && request.sessionKey.trim()
? request.sessionKey.trim()
? request.sessionKey.trim().toLowerCase()
: undefined;
const derivedAgentId = resolveSessionAgentId({ config: cfg });
// If callers omit sessionKey, derive a target session key from the outbound route.