fix(matrix): keep draft previews mention-inert

This commit is contained in:
Vincent Koc
2026-05-27 16:36:55 +02:00
parent 5eeaa5603f
commit 96eec2aab6
4 changed files with 34 additions and 1 deletions
@@ -202,6 +202,7 @@ describe("createMatrixDraftStream", () => {
.mockImplementation((text: string) => (text ? [text] : []));
convertMarkdownTablesMock.mockReset().mockImplementation((text: string) => text);
sendModuleMocks.editMessageMatrix.mockClear();
sendModuleMocks.sendSingleTextMessageMatrix.mockClear();
});
afterEach(() => {
@@ -220,6 +221,11 @@ describe("createMatrixDraftStream", () => {
expect(sendMessageMock).toHaveBeenCalledTimes(1);
expect(sentContentAt(0).msgtype).toBe("m.text");
expect(sendModuleMocks.sendSingleTextMessageMatrix.mock.calls[0]?.[2]).toMatchObject({
includeMentions: false,
live: true,
msgtype: "m.text",
});
expect(stream.eventId()).toBe("$evt1");
});
@@ -17,8 +17,11 @@ function resolveDraftPreviewOptions(mode: MatrixDraftPreviewMode): {
includeMentions: false,
};
}
// Drafts can contain partial model text and raw tool-progress paths; keep
// Matrix mentions inert until callers send a normal final message.
return {
msgtype: MsgType.Text,
includeMentions: false,
};
}
@@ -3097,7 +3097,7 @@ describe("matrix monitor handler draft streaming", () => {
"draft options",
);
expect(draftOptions.msgtype).not.toBe("m.notice");
expect(draftOptions.includeMentions).not.toBe(false);
expect(draftOptions.includeMentions).toBe(false);
await deliver({ text: "Single block" }, { kind: "final" });
+24
View File
@@ -716,6 +716,30 @@ describe("sendSingleTextMessageMatrix", () => {
);
});
it("supports partial draft preview sends without activating mention-looking text", async () => {
const { client, sendMessage } = makeClient();
await sendSingleTextMessageMatrix(
"room:!room:example",
"Working...\n- `read matrix-progress-@room-@alice:example.org-!room:example.org.txt failed`",
{
client,
cfg: {} as never,
includeMentions: false,
live: true,
},
);
const content = sentContent(sendMessage);
expect(content.msgtype).toBe("m.text");
expect(content).not.toHaveProperty("m.mentions");
expect(content["org.matrix.msc4357.live"]).toEqual({});
expect((content as { formatted_body?: string }).formatted_body).toContain(
"<code>read matrix-progress-@room-@alice:example.org-!room:example.org.txt failed</code>",
);
expect((content as { formatted_body?: string }).formatted_body).not.toContain("matrix.to");
});
it("does not activate mentions inside Matrix tool-progress code spans", async () => {
const { client, sendMessage } = makeClient();