fix: normalize delivery routing context

Co-authored-by: adam91holt <adam91holt@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-17 06:38:15 +00:00
parent eb8a0510e0
commit 65a8a93854
14 changed files with 220 additions and 110 deletions

View File

@@ -20,9 +20,15 @@ vi.mock("../infra/outbound/deliver.js", () => ({
deliverOutboundPayloads: mocks.deliverOutboundPayloads,
}));
vi.mock("../infra/outbound/targets.js", () => ({
resolveOutboundTarget: mocks.resolveOutboundTarget,
}));
vi.mock("../infra/outbound/targets.js", async () => {
const actual = await vi.importActual<typeof import("../infra/outbound/targets.js")>(
"../infra/outbound/targets.js",
);
return {
...actual,
resolveOutboundTarget: mocks.resolveOutboundTarget,
};
});
describe("deliverAgentCommandResult", () => {
beforeEach(() => {
@@ -178,4 +184,39 @@ describe("deliverAgentCommandResult", () => {
expect.objectContaining({ accountId: undefined, channel: "whatsapp" }),
);
});
it("uses session last channel when none is provided", async () => {
const cfg = {} as ClawdbotConfig;
const deps = {} as CliDeps;
const runtime = {
log: vi.fn(),
error: vi.fn(),
} as unknown as RuntimeEnv;
const sessionEntry = {
lastChannel: "telegram",
lastTo: "123",
} as SessionEntry;
const result = {
payloads: [{ text: "hi" }],
meta: {},
};
const { deliverAgentCommandResult } = await import("./agent/delivery.js");
await deliverAgentCommandResult({
cfg,
deps,
runtime,
opts: {
message: "hello",
deliver: true,
},
sessionEntry,
result,
payloads: result.payloads,
});
expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
expect.objectContaining({ channel: "telegram", to: "123" }),
);
});
});