
























@@ -14,6 +14,18 @@ const { matrixMessageActions } = await import("./actions.js");
14141515const profileAction = "set-profile" as ChannelMessageActionContext["action"];
161617+function matrixActionCall() {
18+const call = mocks.handleMatrixAction.mock.calls[0];
19+if (!call) {
20+throw new Error("expected handleMatrixAction call");
21+}
22+return {
23+input: call[0] as Record<string, unknown>,
24+cfg: call[1],
25+options: call[2],
26+};
27+}
28+1729function createContext(
1830overrides: Partial<ChannelMessageActionContext>,
1931): ChannelMessageActionContext {
@@ -56,14 +68,11 @@ describe("matrixMessageActions account propagation", () => {
5668}),
5769);
587059-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
60-expect.objectContaining({
61-action: "sendMessage",
62-accountId: "ops",
63-}),
64-expect.any(Object),
65-{ mediaLocalRoots: undefined },
66-);
71+const call = matrixActionCall();
72+expect(call.input.action).toBe("sendMessage");
73+expect(call.input.accountId).toBe("ops");
74+expect(call.cfg).toBeTypeOf("object");
75+expect(call.options).toEqual({ mediaLocalRoots: undefined });
6776});
68776978it("forwards accountId for permissions actions", async () => {
@@ -77,14 +86,11 @@ describe("matrixMessageActions account propagation", () => {
7786}),
7887);
798880-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
81-expect.objectContaining({
82-action: "verificationList",
83-accountId: "ops",
84-}),
85-expect.any(Object),
86-{ mediaLocalRoots: undefined },
87-);
89+const call = matrixActionCall();
90+expect(call.input.action).toBe("verificationList");
91+expect(call.input.accountId).toBe("ops");
92+expect(call.cfg).toBeTypeOf("object");
93+expect(call.options).toEqual({ mediaLocalRoots: undefined });
8894});
89959096it("forwards accountId for self-profile updates", async () => {
@@ -100,21 +106,18 @@ describe("matrixMessageActions account propagation", () => {
100106}),
101107);
102108103-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
104-expect.objectContaining({
105-action: "setProfile",
106-accountId: "ops",
107-displayName: "Ops Bot",
108-avatarUrl: "mxc://example/avatar",
109-}),
110-expect.any(Object),
111-{ mediaLocalRoots: undefined },
112-);
109+const call = matrixActionCall();
110+expect(call.input.action).toBe("setProfile");
111+expect(call.input.accountId).toBe("ops");
112+expect(call.input.displayName).toBe("Ops Bot");
113+expect(call.input.avatarUrl).toBe("mxc://example/avatar");
114+expect(call.cfg).toBeTypeOf("object");
115+expect(call.options).toEqual({ mediaLocalRoots: undefined });
113116});
114117115118it("rejects self-profile updates for non-owner callers", async () => {
116-await expect(
117-matrixMessageActions.handleAction?.(
119+try {
120+await matrixMessageActions.handleAction?.(
118121createContext({
119122action: profileAction,
120123senderIsOwner: false,
@@ -123,30 +126,32 @@ describe("matrixMessageActions account propagation", () => {
123126displayName: "Ops Bot",
124127},
125128}),
126-),
127-).rejects.toMatchObject({
128-name: "ToolAuthorizationError",
129-message: "Matrix profile updates require owner access.",
130-});
129+);
130+throw new Error("expected non-owner self-profile update to reject");
131+} catch (error) {
132+expect((error as Error).name).toBe("ToolAuthorizationError");
133+expect((error as Error).message).toBe("Matrix profile updates require owner access.");
134+}
131135132136expect(mocks.handleMatrixAction).not.toHaveBeenCalled();
133137});
134138135139it("rejects self-profile updates when owner status is unknown", async () => {
136-await expect(
137-matrixMessageActions.handleAction?.(
140+try {
141+await matrixMessageActions.handleAction?.(
138142createContext({
139143action: profileAction,
140144accountId: "ops",
141145params: {
142146displayName: "Ops Bot",
143147},
144148}),
145-),
146-).rejects.toMatchObject({
147-name: "ToolAuthorizationError",
148-message: "Matrix profile updates require owner access.",
149-});
149+);
150+throw new Error("expected unknown-owner self-profile update to reject");
151+} catch (error) {
152+expect((error as Error).name).toBe("ToolAuthorizationError");
153+expect((error as Error).message).toBe("Matrix profile updates require owner access.");
154+}
150155151156expect(mocks.handleMatrixAction).not.toHaveBeenCalled();
152157});
@@ -163,15 +168,12 @@ describe("matrixMessageActions account propagation", () => {
163168}),
164169);
165170166-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
167-expect.objectContaining({
168-action: "setProfile",
169-accountId: "ops",
170-avatarPath: "/tmp/avatar.jpg",
171-}),
172-expect.any(Object),
173-{ mediaLocalRoots: undefined },
174-);
171+const call = matrixActionCall();
172+expect(call.input.action).toBe("setProfile");
173+expect(call.input.accountId).toBe("ops");
174+expect(call.input.avatarPath).toBe("/tmp/avatar.jpg");
175+expect(call.cfg).toBeTypeOf("object");
176+expect(call.options).toEqual({ mediaLocalRoots: undefined });
175177});
176178177179it("forwards mediaLocalRoots for media sends", async () => {
@@ -188,15 +190,12 @@ describe("matrixMessageActions account propagation", () => {
188190}),
189191);
190192191-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
192-expect.objectContaining({
193-action: "sendMessage",
194-accountId: "ops",
195-mediaUrl: "file:///tmp/photo.png",
196-}),
197-expect.any(Object),
198-{ mediaLocalRoots: ["/tmp/openclaw-matrix-test"] },
199-);
193+const call = matrixActionCall();
194+expect(call.input.action).toBe("sendMessage");
195+expect(call.input.accountId).toBe("ops");
196+expect(call.input.mediaUrl).toBe("file:///tmp/photo.png");
197+expect(call.cfg).toBeTypeOf("object");
198+expect(call.options).toEqual({ mediaLocalRoots: ["/tmp/openclaw-matrix-test"] });
200199});
201200202201it("allows media-only sends without requiring a message body", async () => {
@@ -211,16 +210,13 @@ describe("matrixMessageActions account propagation", () => {
211210}),
212211);
213212214-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
215-expect.objectContaining({
216-action: "sendMessage",
217-accountId: "ops",
218-content: undefined,
219-mediaUrl: "file:///tmp/photo.png",
220-}),
221-expect.any(Object),
222-{ mediaLocalRoots: undefined },
223-);
213+const call = matrixActionCall();
214+expect(call.input.action).toBe("sendMessage");
215+expect(call.input.accountId).toBe("ops");
216+expect(call.input.content).toBeUndefined();
217+expect(call.input.mediaUrl).toBe("file:///tmp/photo.png");
218+expect(call.cfg).toBeTypeOf("object");
219+expect(call.options).toEqual({ mediaLocalRoots: undefined });
224220});
225221226222it("accepts shared media aliases and forwards voice-send intent", async () => {
@@ -236,16 +232,13 @@ describe("matrixMessageActions account propagation", () => {
236232}),
237233);
238234239-expect(mocks.handleMatrixAction).toHaveBeenCalledWith(
240-expect.objectContaining({
241-action: "sendMessage",
242-accountId: "ops",
243-content: undefined,
244-mediaUrl: "/tmp/clip.mp3",
245-audioAsVoice: true,
246-}),
247-expect.any(Object),
248-{ mediaLocalRoots: undefined },
249-);
235+const call = matrixActionCall();
236+expect(call.input.action).toBe("sendMessage");
237+expect(call.input.accountId).toBe("ops");
238+expect(call.input.content).toBeUndefined();
239+expect(call.input.mediaUrl).toBe("/tmp/clip.mp3");
240+expect(call.input.audioAsVoice).toBe(true);
241+expect(call.cfg).toBeTypeOf("object");
242+expect(call.options).toEqual({ mediaLocalRoots: undefined });
250243});
251244});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。