


























@@ -10,6 +10,9 @@ import type { MatrixRawEvent } from "./types.js";
1010describe("createMatrixRoomMessageHandler inbound body formatting", () => {
1111type MatrixHandlerHarness = ReturnType<typeof createMatrixHandlerTestHarness>;
1212type FinalizedReplyContext = {
13+MessageThreadId?: string;
14+RawBody?: string;
15+ReplyToId?: string;
1316ReplyToBody?: string;
1417ReplyToSender?: string;
1518ThreadStarterBody?: string;
@@ -64,6 +67,13 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
6467return vi.mocked(finalizeInboundContext).mock.calls.at(-1)?.[0] as FinalizedReplyContext;
6568}
666970+function latestSessionKey(recordInboundSession: MatrixHandlerHarness["recordInboundSession"]) {
71+const context = vi.mocked(recordInboundSession).mock.calls.at(-1)?.[0] as
72+| { sessionKey?: string }
73+| undefined;
74+return context?.sessionKey;
75+}
76+6777beforeEach(() => {
6878installMatrixMonitorTestRuntime({
6979matchesMentionPatterns: () => false,
@@ -101,18 +111,13 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
101111}),
102112);
103113104-expect(finalizeInboundContext).toHaveBeenCalledWith(
105-expect.objectContaining({
106-MessageThreadId: "$thread-root",
107-ThreadStarterBody: "Matrix thread root $thread-root from Alice:\nRoot topic",
108-}),
114+const finalized = latestFinalizedReplyContext(finalizeInboundContext);
115+expect(finalized.MessageThreadId).toBe("$thread-root");
116+expect(finalized.ThreadStarterBody).toBe(
117+"Matrix thread root $thread-root from Alice:\nRoot topic",
109118);
110119// Thread messages get thread-scoped session keys (thread isolation feature).
111-expect(recordInboundSession).toHaveBeenCalledWith(
112-expect.objectContaining({
113-sessionKey: "agent:ops:main:thread:$thread-root",
114-}),
115-);
120+expect(latestSessionKey(recordInboundSession)).toBe("agent:ops:main:thread:$thread-root");
116121});
117122118123it("starts the thread-scoped session from the triggering message when threadReplies is always", async () => {
@@ -131,17 +136,10 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
131136}),
132137);
133138134-expect(finalizeInboundContext).toHaveBeenCalledWith(
135-expect.objectContaining({
136-MessageThreadId: "$thread-root",
137-ReplyToId: undefined,
138-}),
139-);
140-expect(recordInboundSession).toHaveBeenCalledWith(
141-expect.objectContaining({
142-sessionKey: "agent:ops:main:thread:$thread-root",
143-}),
144-);
139+const finalized = latestFinalizedReplyContext(finalizeInboundContext);
140+expect(finalized.MessageThreadId).toBe("$thread-root");
141+expect(finalized.ReplyToId).toBeUndefined();
142+expect(latestSessionKey(recordInboundSession)).toBe("agent:ops:main:thread:$thread-root");
145143});
146144147145it("records formatted poll results for inbound poll response events", async () => {
@@ -198,16 +196,10 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
198196},
199197} as MatrixRawEvent);
200198201-expect(finalizeInboundContext).toHaveBeenCalledWith(
202-expect.objectContaining({
203-RawBody: expect.stringMatching(/1\. Pizza \(1 vote\)[\s\S]*Total voters: 1/),
204-}),
205-);
206-expect(recordInboundSession).toHaveBeenCalledWith(
207-expect.objectContaining({
208-sessionKey: "agent:ops:main",
209-}),
210-);
199+const finalized = latestFinalizedReplyContext(finalizeInboundContext);
200+expect(finalized.RawBody).toContain("1. Pizza (1 vote)");
201+expect(finalized.RawBody).toContain("Total voters: 1");
202+expect(latestSessionKey(recordInboundSession)).toBe("agent:ops:main");
211203});
212204213205it("records reply context for quoted poll start events inside always-threaded replies", async () => {
@@ -268,14 +260,13 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
268260}),
269261);
270262271-expect(finalizeInboundContext).toHaveBeenCalledWith(
272-expect.objectContaining({
273-MessageThreadId: "$thread-root",
274-ReplyToId: undefined,
275-ReplyToSender: "Alice",
276-ReplyToBody: "[Poll]\nLunch?\n\n1. Pizza\n2. Sushi",
277-ThreadStarterBody: "Matrix thread root $thread-root from Bob:\nRoot topic",
278-}),
263+const finalized = latestFinalizedReplyContext(finalizeInboundContext);
264+expect(finalized.MessageThreadId).toBe("$thread-root");
265+expect(finalized.ReplyToId).toBeUndefined();
266+expect(finalized.ReplyToSender).toBe("Alice");
267+expect(finalized.ReplyToBody).toBe("[Poll]\nLunch?\n\n1. Pizza\n2. Sushi");
268+expect(finalized.ThreadStarterBody).toBe(
269+"Matrix thread root $thread-root from Bob:\nRoot topic",
279270);
280271});
281272@@ -311,14 +302,13 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
311302}),
312303);
313304314-expect(finalizeInboundContext).toHaveBeenCalledWith(
315-expect.objectContaining({
316-MessageThreadId: "$thread-root",
317-ReplyToId: undefined,
318-ReplyToSender: "Alice",
319-ReplyToBody: "Root topic",
320-ThreadStarterBody: "Matrix thread root $thread-root from Alice:\nRoot topic",
321-}),
305+const finalized = latestFinalizedReplyContext(finalizeInboundContext);
306+expect(finalized.MessageThreadId).toBe("$thread-root");
307+expect(finalized.ReplyToId).toBeUndefined();
308+expect(finalized.ReplyToSender).toBe("Alice");
309+expect(finalized.ReplyToBody).toBe("Root topic");
310+expect(finalized.ThreadStarterBody).toBe(
311+"Matrix thread root $thread-root from Alice:\nRoot topic",
322312);
323313expect(getEvent).toHaveBeenCalledTimes(1);
324314expect(getMemberDisplayName).toHaveBeenCalledTimes(2);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。