


















@@ -32,6 +32,10 @@ function expectRecordFields(value: unknown, expected: Record<string, unknown>) {
3232return actual;
3333}
343435+function mockCall<T extends readonly unknown[]>(mock: { mock: { calls: T[] } }, index = 0) {
36+return mock.mock.calls.at(index);
37+}
38+3539function buildMatrixReceipt(messageIds: readonly string[], roomId = "!room:example.org") {
3640return {
3741primaryPlatformMessageId: messageIds[0],
@@ -204,7 +208,7 @@ describe("matrixApprovalNativeRuntime", () => {
204208 pendingPayload,
205209});
206210207-const [target, text, options] = sendSingleTextMessage.mock.calls[0] ?? [];
211+const [target, text, options] = mockCall(sendSingleTextMessage) ?? [];
208212expect(target).toBe("room:!room:example.org");
209213expect(String(text)).toContain("echo hi");
210214const extraContent = (options as { extraContent?: Record<string, unknown> } | undefined)
@@ -254,7 +258,7 @@ describe("matrixApprovalNativeRuntime", () => {
254258 pendingPayload,
255259});
256260257-const [target, text, options] = sendSingleTextMessage.mock.calls[0] ?? [];
261+const [target, text, options] = mockCall(sendSingleTextMessage) ?? [];
258262expect(target).toBe("room:!room:example.org");
259263expect(String(text)).toContain("deploy");
260264const extraContent = (options as { extraContent?: Record<string, unknown> } | undefined)
@@ -284,10 +288,10 @@ describe("matrixApprovalNativeRuntime", () => {
284288agentId: "agent-1",
285289severity: "critical",
286290});
287-expect(reactMessage.mock.calls[0]?.[0]).toBe("!room:example.org");
288-expect(reactMessage.mock.calls[0]?.[1]).toBe("$plugin-approval");
289-expect(reactMessage.mock.calls[0]?.[2]).toBe("✅");
290-expectRecordFields(reactMessage.mock.calls[0]?.[3], { accountId: "default" });
291+expect(mockCall(reactMessage)?.[0]).toBe("!room:example.org");
292+expect(mockCall(reactMessage)?.[1]).toBe("$plugin-approval");
293+expect(mockCall(reactMessage)?.[2]).toBe("✅");
294+expectRecordFields(mockCall(reactMessage)?.[3], { accountId: "default" });
291295});
292296293297it("binds Matrix approval reactions before publishing option reactions", async () => {
@@ -468,16 +472,16 @@ describe("matrixApprovalNativeRuntime", () => {
468472 pendingPayload,
469473});
470474471-expect(sendMessage.mock.calls[0]?.[0]).toBe("room:!room:example.org");
472-expect(sendMessage.mock.calls[0]?.[1]).toBe(pendingPayload.text);
473-expectRecordFields(sendMessage.mock.calls[0]?.[2], {
475+expect(mockCall(sendMessage)?.[0]).toBe("room:!room:example.org");
476+expect(mockCall(sendMessage)?.[1]).toBe(pendingPayload.text);
477+expectRecordFields(mockCall(sendMessage)?.[2], {
474478accountId: "default",
475479extraContent: pendingPayload.extraContent,
476480});
477-expect(reactMessage.mock.calls[0]?.[0]).toBe("!room:example.org");
478-expect(reactMessage.mock.calls[0]?.[1]).toBe("$primary");
479-expect(typeof reactMessage.mock.calls[0]?.[2]).toBe("string");
480-expectRecordFields(reactMessage.mock.calls[0]?.[3], { accountId: "default" });
481+expect(mockCall(reactMessage)?.[0]).toBe("!room:example.org");
482+expect(mockCall(reactMessage)?.[1]).toBe("$primary");
483+expect(typeof mockCall(reactMessage)?.[2]).toBe("string");
484+expectRecordFields(mockCall(reactMessage)?.[3], { accountId: "default" });
481485expectRecordFields(entry, {
482486roomId: "!room:example.org",
483487platformMessageIds: ["$primary", "$last"],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。