diff --git a/src/gateway/server.test.ts b/src/gateway/server.test.ts index 422fa9e7b..5985af980 100644 --- a/src/gateway/server.test.ts +++ b/src/gateway/server.test.ts @@ -108,6 +108,70 @@ async function startServerWithClient(token?: string) { } describe("gateway server", () => { + test("agent routes main last-channel whatsapp", async () => { + const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-")); + testSessionStorePath = path.join(dir, "sessions.json"); + await fs.writeFile( + testSessionStorePath, + JSON.stringify( + { + main: { + sessionId: "sess-main-whatsapp", + updatedAt: Date.now(), + lastChannel: "whatsapp", + lastTo: "+1555", + }, + }, + null, + 2, + ), + "utf-8", + ); + + const { server, ws } = await startServerWithClient(); + ws.send( + JSON.stringify({ + type: "hello", + minProtocol: 1, + maxProtocol: 1, + client: { name: "test", version: "1", platform: "test", mode: "test" }, + caps: [], + }), + ); + await onceMessage(ws, (o) => o.type === "hello-ok"); + + ws.send( + JSON.stringify({ + type: "req", + id: "agent-last-whatsapp", + method: "agent", + params: { + message: "hi", + sessionKey: "main", + channel: "last", + deliver: true, + idempotencyKey: "idem-agent-last-whatsapp", + }, + }), + ); + await onceMessage( + ws, + (o) => o.type === "res" && o.id === "agent-last-whatsapp", + ); + + const spy = vi.mocked(agentCommand); + expect(spy).toHaveBeenCalled(); + const call = spy.mock.calls.at(-1)?.[0] as Record; + expect(call.provider).toBe("whatsapp"); + expect(call.to).toBe("+1555"); + expect(call.deliver).toBe(true); + expect(call.bestEffortDeliver).toBe(true); + expect(call.sessionId).toBe("sess-main-whatsapp"); + + ws.close(); + await server.close(); + }); + test("agent routes main last-channel telegram", async () => { const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-")); testSessionStorePath = path.join(dir, "sessions.json");