
























@@ -9,6 +9,20 @@ import type {
991010const cfg = {} as OpenClawConfig;
111112+function requireFirstCallArg(mock: {
13+mock: { calls: readonly unknown[][] };
14+}): Record<string, unknown> {
15+const [call] = mock.mock.calls;
16+if (!call) {
17+throw new Error("expected first mock call");
18+}
19+const [arg] = call;
20+if (typeof arg !== "object" || arg === null || Array.isArray(arg)) {
21+throw new Error("expected first mock call argument to be an object");
22+}
23+return arg as Record<string, unknown>;
24+}
25+1226describe("createChannelMessageAdapterFromOutbound", () => {
1327it("wraps outbound text sends with a message receipt", async () => {
1428const sendText = vi.fn(async (_request: ChannelMessageSendTextContext) => ({
@@ -34,11 +48,13 @@ describe("createChannelMessageAdapterFromOutbound", () => {
3448expect(adapter.id).toBe("demo");
3549expect(adapter.durableFinal).toEqual({ capabilities: { text: true, replyTo: true } });
3650expect(sendText).toHaveBeenCalledTimes(1);
37-const sendTextRequest = sendText.mock.calls[0]?.[0];
38-expect(sendTextRequest?.to).toBe("room-1");
39-expect(sendTextRequest?.text).toBe("hello");
40-expect(sendTextRequest?.replyToId).toBe("parent-1");
41-expect(sendTextRequest?.threadId).toBe("thread-1");
51+const sendTextRequest = requireFirstCallArg(
52+sendText,
53+) as unknown as ChannelMessageSendTextContext;
54+expect(sendTextRequest.to).toBe("room-1");
55+expect(sendTextRequest.text).toBe("hello");
56+expect(sendTextRequest.replyToId).toBe("parent-1");
57+expect(sendTextRequest.threadId).toBe("thread-1");
4258expect(result?.messageId).toBe("msg-1");
4359expect(result?.receipt.primaryPlatformMessageId).toBe("msg-1");
4460expect(result?.receipt.platformMessageIds).toEqual(["msg-1"]);
@@ -109,7 +125,10 @@ describe("createChannelMessageAdapterFromOutbound", () => {
109125110126expect(adapter.durableFinal?.capabilities).toEqual({ payload: true, batch: true });
111127expect(sendPayload).toHaveBeenCalledTimes(1);
112-expect(sendPayload.mock.calls[0]?.[0].payload).toEqual({
128+const sendPayloadRequest = requireFirstCallArg(
129+sendPayload,
130+) as unknown as ChannelMessageSendPayloadContext;
131+expect(sendPayloadRequest.payload).toEqual({
113132presentation: { blocks: [{ type: "text", text: "ready" }] },
114133});
115134expect(result?.receipt.parts[0]?.platformMessageId).toBe("card-1");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。