





















@@ -173,12 +173,29 @@ function expectNoticeSent(mock: unknown) {
173173expect(String(message.body)).toContain("channels.matrix.dm.sessionScope");
174174}
175175176+function expectRuntimeErrorContaining(mock: unknown, text: string) {
177+const matched = mockCalls(mock, "runtime error").some(([message]) =>
178+String(message).includes(text),
179+);
180+expect(matched).toBe(true);
181+}
182+176183function findMockCall(mock: unknown, label: string, predicate: (call: Array<unknown>) => boolean) {
177184const call = mockCalls(mock, label).find(predicate);
178185expect(call, label).toBeDefined();
179186return call as Array<unknown>;
180187}
181188189+function expectMatrixEdit(roomId: string, eventId: string, body: string) {
190+const call = findMockCall(
191+editMessageMatrixMock,
192+`edit call for ${eventId}`,
193+([room, editedEventId, editedBody]) =>
194+room === roomId && editedEventId === eventId && editedBody === body,
195+);
196+expect(call[3], "edit options").toBeDefined();
197+}
198+182199function expectFinalizedPreviewEdit(eventId: string, text: string) {
183200const call = findMockCall(
184201editMessageMatrixMock,
@@ -709,7 +726,8 @@ describe("matrix monitor handler pairing account scope", () => {
709726}),
710727);
711728712-expect(hasControlCommand).toHaveBeenCalledWith("/new", expect.anything());
729+expect(callArg(hasControlCommand, 0, 0, "control command")).toBe("/new");
730+expect(callArg(hasControlCommand, 0, 1, "control command")).toBeDefined();
713731expect(recordInboundSession).not.toHaveBeenCalled();
714732expect(finalizeInboundContext).not.toHaveBeenCalled();
715733});
@@ -734,7 +752,8 @@ describe("matrix monitor handler pairing account scope", () => {
734752}),
735753);
736754737-expect(hasControlCommand).toHaveBeenCalledWith("/new", expect.anything());
755+expect(callArg(hasControlCommand, 0, 0, "control command")).toBe("/new");
756+expect(callArg(hasControlCommand, 0, 1, "control command")).toBeDefined();
738757const context = requireRecord(
739758callArg(finalizeInboundContext, 0, 0, "finalized context"),
740759"finalized context",
@@ -1060,7 +1079,8 @@ describe("matrix monitor handler pairing account scope", () => {
10601079}),
10611080);
106210811063-expect(sendNotice).toHaveBeenCalledWith("!dm:example.org", expect.anything());
1082+expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org");
1083+expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined();
10641084expectNoticeSent(sendNotice);
1065108510661086await handler(
@@ -1114,7 +1134,8 @@ describe("matrix monitor handler pairing account scope", () => {
11141134}),
11151135);
111611361117-expect(sendNotice).toHaveBeenCalledWith("!dm:example.org", expect.anything());
1137+expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org");
1138+expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined();
11181139expectNoticeSent(sendNotice);
11191140} finally {
11201141fs.rmSync(tempDir, { recursive: true, force: true });
@@ -1166,7 +1187,8 @@ describe("matrix monitor handler pairing account scope", () => {
11661187}),
11671188);
116811891169-expect(sendNotice).toHaveBeenCalledWith("!dm:example.org", expect.anything());
1190+expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org");
1191+expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined();
11701192expectNoticeSent(sendNotice);
11711193} finally {
11721194fs.rmSync(tempDir, { recursive: true, force: true });
@@ -1208,7 +1230,8 @@ describe("matrix monitor handler pairing account scope", () => {
12081230}),
12091231);
121012321211-expect(sendNotice).toHaveBeenCalledWith("!dm:example.org", expect.anything());
1233+expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org");
1234+expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined();
12121235expectNoticeSent(sendNotice);
12131236} finally {
12141237fs.rmSync(tempDir, { recursive: true, force: true });
@@ -2373,7 +2396,7 @@ describe("matrix monitor handler durable inbound dedupe", () => {
23732396roomId: "!room:example.org",
23742397eventId: "$release-on-error",
23752398});
2376-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("matrix handler failed"));
2399+expectRuntimeErrorContaining(runtime.error, "matrix handler failed");
23772400});
2378240123792402it("keeps replay committed when queued final delivery fails after a generic error", async () => {
@@ -2418,9 +2441,7 @@ describe("matrix monitor handler durable inbound dedupe", () => {
24182441eventId: "$release-on-final-delivery-error",
24192442});
24202443expect(inboundDeduper.releaseEvent).not.toHaveBeenCalled();
2421-expect(runtime.error).toHaveBeenCalledWith(
2422-expect.stringContaining("matrix final reply failed"),
2423-);
2444+expectRuntimeErrorContaining(runtime.error, "matrix final reply failed");
24242445});
2425244624262447it.each(["tool", "block"] as const)(
@@ -2471,9 +2492,7 @@ describe("matrix monitor handler durable inbound dedupe", () => {
24712492eventId: `$release-on-${kind}-delivery-error`,
24722493});
24732494expect(inboundDeduper.releaseEvent).not.toHaveBeenCalled();
2474-expect(runtime.error).toHaveBeenCalledWith(
2475-expect.stringContaining(`matrix ${kind} reply failed`),
2476-);
2495+expectRuntimeErrorContaining(runtime.error, `matrix ${kind} reply failed`);
24772496},
24782497);
24792498@@ -3016,12 +3035,7 @@ describe("matrix monitor handler draft streaming", () => {
30163035opts.onPartialReply?.({ text: "AlphaBeta" });
30173036await vi.waitFor(
30183037() => {
3019-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3020-"!room:example.org",
3021-"$draft1",
3022-"AlphaBeta",
3023-expect.anything(),
3024-);
3038+expectMatrixEdit("!room:example.org", "$draft1", "AlphaBeta");
30253039},
30263040{ interval: 1 },
30273041);
@@ -3043,12 +3057,7 @@ describe("matrix monitor handler draft streaming", () => {
30433057{ interval: 1 },
30443058);
30453059expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
3046-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3047-"!room:example.org",
3048-"$draft1",
3049-"Alpha",
3050-expect.anything(),
3051-);
3060+expectMatrixEdit("!room:example.org", "$draft1", "Alpha");
30523061expect(deliverMatrixRepliesMock).not.toHaveBeenCalled();
30533062expect(redactEventMock).not.toHaveBeenCalled();
30543063await finish();
@@ -3143,12 +3152,7 @@ describe("matrix monitor handler draft streaming", () => {
31433152opts.onPartialReply?.({ text: "Beta" });
3144315331453154await vi.waitFor(() => {
3146-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3147-"!room:example.org",
3148-"$draft1",
3149-"Beta",
3150-expect.anything(),
3151-);
3155+expectMatrixEdit("!room:example.org", "$draft1", "Beta");
31523156});
3153315731543158sendSingleTextMessageMatrixMock.mockClear();
@@ -3159,12 +3163,7 @@ describe("matrix monitor handler draft streaming", () => {
31593163});
31603164await deliver({ text: "Alpha" }, { kind: "block" });
316131653162-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3163-"!room:example.org",
3164-"$draft1",
3165-"Alpha",
3166-expect.anything(),
3167-);
3166+expectMatrixEdit("!room:example.org", "$draft1", "Alpha");
31683167expect(deliverMatrixRepliesMock).not.toHaveBeenCalled();
31693168expect(redactEventMock).not.toHaveBeenCalled();
31703169await vi.waitFor(() => {
@@ -3194,12 +3193,7 @@ describe("matrix monitor handler draft streaming", () => {
31943193opts.onPartialReply?.({ text: "Beta" });
3195319431963195await vi.waitFor(() => {
3197-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3198-"!room:example.org",
3199-"$draft1",
3200-"Beta",
3201-expect.anything(),
3202-);
3196+expectMatrixEdit("!room:example.org", "$draft1", "Beta");
32033197});
3204319832053199sendSingleTextMessageMatrixMock.mockClear();
@@ -3210,12 +3204,7 @@ describe("matrix monitor handler draft streaming", () => {
32103204});
32113205await deliver({ text: "Alpha" }, { kind: "block" });
321232063213-expect(editMessageMatrixMock).toHaveBeenCalledWith(
3214-"!room:example.org",
3215-"$draft1",
3216-"Alpha",
3217-expect.anything(),
3218-);
3207+expectMatrixEdit("!room:example.org", "$draft1", "Alpha");
32193208expect(deliverMatrixRepliesMock).not.toHaveBeenCalled();
32203209expect(redactEventMock).not.toHaveBeenCalled();
32213210await vi.waitFor(() => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。