























@@ -22,6 +22,12 @@ vi.mock("../send.js", () => ({
2222import { setMatrixRuntime } from "../../runtime.js";
2323import { deliverMatrixReplies } from "./replies.js";
242425+function sendOptions(index: number): Record<string, unknown> {
26+const options = sendMessageMatrixMock.mock.calls[index]?.[2];
27+expect(options).toBeDefined();
28+return options as Record<string, unknown>;
29+}
30+2531describe("deliverMatrixReplies", () => {
2632const cfg = { channels: { matrix: {} } };
2733const loadConfigMock = vi.fn(() => ({}));
@@ -90,15 +96,12 @@ describe("deliverMatrixReplies", () => {
9096});
91979298expect(sendMessageMatrixMock).toHaveBeenCalledTimes(3);
93-expect(sendMessageMatrixMock.mock.calls[0]?.[2]).toEqual(
94-expect.objectContaining({ replyToId: "reply-1", threadId: undefined }),
95-);
96-expect(sendMessageMatrixMock.mock.calls[1]?.[2]).toEqual(
97-expect.objectContaining({ replyToId: "reply-1", threadId: undefined }),
98-);
99-expect(sendMessageMatrixMock.mock.calls[2]?.[2]).toEqual(
100-expect.objectContaining({ replyToId: undefined, threadId: undefined }),
101-);
99+expect(sendOptions(0).replyToId).toBe("reply-1");
100+expect(sendOptions(0).threadId).toBeUndefined();
101+expect(sendOptions(1).replyToId).toBe("reply-1");
102+expect(sendOptions(1).threadId).toBeUndefined();
103+expect(sendOptions(2).replyToId).toBeUndefined();
104+expect(sendOptions(2).threadId).toBeUndefined();
102105});
103106104107it("keeps replyToId on every reply when replyToMode=all", async () => {
@@ -122,27 +125,17 @@ describe("deliverMatrixReplies", () => {
122125});
123126124127expect(sendMessageMatrixMock).toHaveBeenCalledTimes(3);
125-expect(sendMessageMatrixMock.mock.calls[0]).toEqual([
126-"room:2",
127-"caption",
128-expect.objectContaining({
129-mediaUrl: "https://example.com/a.jpg",
130-mediaLocalRoots: ["/tmp/openclaw-matrix-test"],
131-replyToId: "reply-media",
132-}),
133-]);
134-expect(sendMessageMatrixMock.mock.calls[1]).toEqual([
135-"room:2",
136-"",
137-expect.objectContaining({
138-mediaUrl: "https://example.com/b.jpg",
139-mediaLocalRoots: ["/tmp/openclaw-matrix-test"],
140-replyToId: "reply-media",
141-}),
142-]);
143-expect(sendMessageMatrixMock.mock.calls[2]?.[2]).toEqual(
144-expect.objectContaining({ replyToId: "reply-text" }),
145-);
128+expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:2");
129+expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("caption");
130+expect(sendOptions(0).mediaUrl).toBe("https://example.com/a.jpg");
131+expect(sendOptions(0).mediaLocalRoots).toEqual(["/tmp/openclaw-matrix-test"]);
132+expect(sendOptions(0).replyToId).toBe("reply-media");
133+expect(sendMessageMatrixMock.mock.calls[1]?.[0]).toBe("room:2");
134+expect(sendMessageMatrixMock.mock.calls[1]?.[1]).toBe("");
135+expect(sendOptions(1).mediaUrl).toBe("https://example.com/b.jpg");
136+expect(sendOptions(1).mediaLocalRoots).toEqual(["/tmp/openclaw-matrix-test"]);
137+expect(sendOptions(1).replyToId).toBe("reply-media");
138+expect(sendOptions(2).replyToId).toBe("reply-text");
146139});
147140148141it("suppresses replyToId when threadId is set", async () => {
@@ -166,12 +159,10 @@ describe("deliverMatrixReplies", () => {
166159});
167160168161expect(sendMessageMatrixMock).toHaveBeenCalledTimes(2);
169-expect(sendMessageMatrixMock.mock.calls[0]?.[2]).toEqual(
170-expect.objectContaining({ replyToId: undefined, threadId: "thread-77" }),
171-);
172-expect(sendMessageMatrixMock.mock.calls[1]?.[2]).toEqual(
173-expect.objectContaining({ replyToId: undefined, threadId: "thread-77" }),
174-);
162+expect(sendOptions(0).replyToId).toBeUndefined();
163+expect(sendOptions(0).threadId).toBe("thread-77");
164+expect(sendOptions(1).replyToId).toBeUndefined();
165+expect(sendOptions(1).threadId).toBe("thread-77");
175166});
176167177168it("suppresses reasoning-only text before Matrix sends", async () => {
@@ -190,11 +181,9 @@ describe("deliverMatrixReplies", () => {
190181});
191182192183expect(sendMessageMatrixMock).toHaveBeenCalledTimes(1);
193-expect(sendMessageMatrixMock).toHaveBeenCalledWith(
194-"room:5",
195-"Visible answer",
196-expect.objectContaining({ cfg }),
197-);
184+expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:5");
185+expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("Visible answer");
186+expect(sendOptions(0).cfg).toBe(cfg);
198187});
199188200189it("uses supplied cfg for chunking and send delivery without reloading runtime config", async () => {
@@ -230,15 +219,11 @@ describe("deliverMatrixReplies", () => {
230219accountId: "ops",
231220tableMode: "code",
232221});
233-expect(sendMessageMatrixMock).toHaveBeenCalledWith(
234-"room:4",
235-"hello",
236-expect.objectContaining({
237-cfg: explicitCfg,
238-accountId: "ops",
239-replyToId: "reply-1",
240-}),
241-);
222+expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:4");
223+expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("hello");
224+expect(sendOptions(0).cfg).toBe(explicitCfg);
225+expect(sendOptions(0).accountId).toBe("ops");
226+expect(sendOptions(0).replyToId).toBe("reply-1");
242227});
243228244229it("passes raw media captions through to sendMessageMatrix without pre-converting them", async () => {
@@ -254,12 +239,8 @@ describe("deliverMatrixReplies", () => {
254239replyToMode: "off",
255240});
256241257-expect(sendMessageMatrixMock).toHaveBeenCalledWith(
258-"room:6",
259-"caption",
260-expect.objectContaining({
261-mediaUrl: "https://example.com/a.jpg",
262-}),
263-);
242+expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:6");
243+expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("caption");
244+expect(sendOptions(0).mediaUrl).toBe("https://example.com/a.jpg");
264245});
265246});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。