























@@ -54,6 +54,32 @@ function createConfig(): OpenClawConfig {
54545555const createRuntimeEnv = () => createZalouserRuntimeEnv();
565657+type DispatchReplyCallArg = {
58+ctx?: {
59+Body?: string;
60+BodyForCommands?: string;
61+CommandAuthorized?: boolean;
62+CommandBody?: string;
63+InboundHistory?: unknown;
64+OriginatingTo?: string;
65+SessionKey?: string;
66+To?: string;
67+WasMentioned?: boolean;
68+};
69+};
70+71+function mockCallArg(mock: unknown, label: string, index = 0) {
72+const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.at(index);
73+if (!call) {
74+throw new Error(`Expected ${label} call ${index + 1}`);
75+}
76+return call[0];
77+}
78+79+function dispatchReplyCall(mock: unknown, index = 0): DispatchReplyCallArg {
80+return mockCallArg(mock, "dispatch reply", index) as DispatchReplyCallArg;
81+}
82+5783function installRuntime(params: {
5884commandAuthorized?: boolean;
5985replyPayload?: { text?: string; mediaUrl?: string; mediaUrls?: string[] };
@@ -414,7 +440,7 @@ describe("zalouser monitor group mention gating", () => {
414440});
415441expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1);
416442expect(resolveCommandAuthorizedFromAuthorizers).not.toHaveBeenCalled();
417-const callArg = dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
443+const callArg = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
418444expect(callArg?.ctx?.CommandAuthorized).toBe(params.expectedCommandAuthorized);
419445}
420446@@ -492,7 +518,7 @@ describe("zalouser monitor group mention gating", () => {
492518message: createGroupMessage(params.message),
493519});
494520expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1);
495-return dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
521+return dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
496522}
497523498524it("skips unmentioned group messages when requireMention=true", async () => {
@@ -748,7 +774,7 @@ describe("zalouser monitor group mention gating", () => {
748774dangerouslyAllowNameMatching: true,
749775expectedDispatches: 1,
750776});
751-const callArg = dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
777+const callArg = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
752778expect(callArg?.ctx?.To).toBe("zalouser:group:g-attacker-001");
753779});
754780@@ -806,12 +832,17 @@ describe("zalouser monitor group mention gating", () => {
806832const { dispatchReplyWithBufferedBlockDispatcher, resolveAgentRoute, buildAgentSessionKey } =
807833await processOpenDmMessage();
808834809-const routeInput = resolveAgentRoute.mock.calls[0]?.[0];
835+const routeInput = mockCallArg(resolveAgentRoute, "resolve agent route") as {
836+peer?: unknown;
837+};
810838expect(routeInput?.peer).toEqual({ kind: "direct", id: "321" });
811-const sessionKeyInput = buildAgentSessionKey.mock.calls[0]?.[0];
839+const sessionKeyInput = mockCallArg(buildAgentSessionKey, "build agent session key") as {
840+dmScope?: string;
841+peer?: unknown;
842+};
812843expect(sessionKeyInput?.peer).toEqual({ kind: "direct", id: "321" });
813844expect(sessionKeyInput?.dmScope).toBe("per-channel-peer");
814-const callArg = dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
845+const callArg = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
815846expect(callArg?.ctx?.SessionKey).toBe("agent:main:zalouser:direct:321");
816847});
817848@@ -821,7 +852,7 @@ describe("zalouser monitor group mention gating", () => {
821852input?.sessionKey === "agent:main:zalouser:group:321" ? 123 : undefined,
822853});
823854824-const callArg = dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
855+const callArg = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
825856expect(callArg?.ctx?.SessionKey).toBe("agent:main:zalouser:group:321");
826857});
827858@@ -907,15 +938,15 @@ describe("zalouser monitor group mention gating", () => {
907938 historyState,
908939});
909940expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1);
910-const firstDispatch = dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0];
941+const firstDispatch = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher);
911942expect(firstDispatch?.ctx?.InboundHistory).toEqual([
912943{
913944sender: "Alice",
914945body: "first unmentioned line",
915946timestamp: 1700000000000,
916947},
917948]);
918-expect(String(firstDispatch?.ctx?.Body ?? "")).toContain("first unmentioned line");
949+expect(firstDispatch?.ctx?.Body ?? "").toContain("first unmentioned line");
919950920951await __testing.processMessage({
921952message: createGroupMessage({
@@ -929,7 +960,7 @@ describe("zalouser monitor group mention gating", () => {
929960 historyState,
930961});
931962expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(2);
932-const secondDispatch = dispatchReplyWithBufferedBlockDispatcher.mock.calls[1]?.[0];
963+const secondDispatch = dispatchReplyCall(dispatchReplyWithBufferedBlockDispatcher, 1);
933964expect(secondDispatch?.ctx?.InboundHistory).toStrictEqual([]);
934965});
935966});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。