


























@@ -164,6 +164,10 @@ function lastCallArg(mock: unknown, argIndex: number, label: string) {
164164return callArg(mock, calls.length - 1, argIndex, label);
165165}
166166167+function singleTextMessageBody(callIndex = 0) {
168+return callArg(sendSingleTextMessageMatrixMock, callIndex, 1, "single text message body");
169+}
170+167171function expectMockCallWithFields(mock: unknown, fields: Record<string, unknown>) {
168172const matched = mockCalls(mock, "mock calls").some(([value]) => {
169173if (!value || typeof value !== "object") {
@@ -413,7 +417,7 @@ describe("matrix monitor handler pairing account scope", () => {
413417await handler("!room:example.org", makeEvent("$event1"));
414418await handler("!room:example.org", makeEvent("$event2"));
415419expect(sendMessageMatrixMock).toHaveBeenCalledTimes(1);
416-const pairingReminder = sendMessageMatrixMock.mock.calls[0]?.[1];
420+const pairingReminder = callArg(sendMessageMatrixMock, 0, 1, "pairing reminder");
417421expect(typeof pairingReminder).toBe("string");
418422expect(pairingReminder).toContain("Pairing request is still pending approval.");
419423@@ -2916,7 +2920,7 @@ describe("matrix monitor handler draft streaming", () => {
29162920await vi.waitFor(() => {
29172921expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
29182922});
2919-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toMatch(/\n`🧩 Read File`$/);
2923+expect(singleTextMessageBody()).toMatch(/\n`🧩 Read File`$/);
2920292429212925await deliver({ text: "Done" }, { kind: "final" });
29222926@@ -2949,7 +2953,7 @@ describe("matrix monitor handler draft streaming", () => {
29492953await vi.waitFor(() => {
29502954expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
29512955});
2952-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("- `second`");
2956+expect(singleTextMessageBody()).toBe("- `second`");
29532957await finish();
29542958});
29552959@@ -2967,7 +2971,7 @@ describe("matrix monitor handler draft streaming", () => {
29672971await vi.waitFor(() => {
29682972expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
29692973});
2970-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toMatch(
2974+expect(singleTextMessageBody()).toMatch(
29712975/\n- `@room ping @alice:example\.org \[label\]\(https:\/\/example\.org\)`$/,
29722976);
29732977await finish();
@@ -3128,7 +3132,7 @@ describe("matrix monitor handler draft streaming", () => {
31283132await vi.waitFor(() => {
31293133expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(2);
31303134});
3131-expect(sendSingleTextMessageMatrixMock.mock.calls[1]?.[1]).toBe("Beta");
3135+expect(singleTextMessageBody(1)).toBe("Beta");
31323136expect(deliverMatrixRepliesMock).not.toHaveBeenCalled();
31333137expect(redactEventMock).not.toHaveBeenCalled();
31343138await finish();
@@ -3170,7 +3174,7 @@ describe("matrix monitor handler draft streaming", () => {
31703174},
31713175{ interval: 1 },
31723176);
3173-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
3177+expect(singleTextMessageBody()).toBe("Beta");
31743178expectMatrixEdit("!room:example.org", "$draft1", "Alpha");
31753179expect(deliverMatrixRepliesMock).not.toHaveBeenCalled();
31763180expect(redactEventMock).not.toHaveBeenCalled();
@@ -3247,7 +3251,7 @@ describe("matrix monitor handler draft streaming", () => {
32473251});
3248325232493253// The draft stream should have received "Block two", not empty string.
3250-const sentBody = sendSingleTextMessageMatrixMock.mock.calls[0]?.[1];
3254+const sentBody = singleTextMessageBody();
32513255expect(sentBody).toBe("Block two");
32523256await finish();
32533257});
@@ -3283,7 +3287,7 @@ describe("matrix monitor handler draft streaming", () => {
32833287await vi.waitFor(() => {
32843288expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
32853289});
3286-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
3290+expect(singleTextMessageBody()).toBe("Beta");
3287329132883292await deliver({ text: "Beta" }, { kind: "final" });
32893293@@ -3324,7 +3328,7 @@ describe("matrix monitor handler draft streaming", () => {
33243328await vi.waitFor(() => {
33253329expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
33263330});
3327-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
3331+expect(singleTextMessageBody()).toBe("Beta");
3328333233293333await deliver({ text: "Beta" }, { kind: "final" });
33303334@@ -3341,7 +3345,7 @@ describe("matrix monitor handler draft streaming", () => {
33413345await vi.waitFor(() => {
33423346expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
33433347});
3344-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Alpha");
3348+expect(singleTextMessageBody()).toBe("Alpha");
3345334933463350await opts.onBlockReplyQueued?.({ text: "Alpha" });
33473351opts.onPartialReply?.({ text: "AlphaBeta" });
@@ -3362,7 +3366,7 @@ describe("matrix monitor handler draft streaming", () => {
33623366await vi.waitFor(() => {
33633367expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
33643368});
3365-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
3369+expect(singleTextMessageBody()).toBe("Beta");
33663370expectFinalizedPreviewEdit("$draft1", "Alpha");
3367337133683372sendSingleTextMessageMatrixMock.mockClear();
@@ -3376,7 +3380,7 @@ describe("matrix monitor handler draft streaming", () => {
33763380await vi.waitFor(() => {
33773381expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
33783382});
3379-expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Gamma");
3383+expect(singleTextMessageBody()).toBe("Gamma");
33803384expectFinalizedPreviewEdit("$draft2", "Beta");
3381338533823386await finish();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。