"""Unit tests for Matrix channel adapter.
Tests formatter, normalizer, thread_utils, session, crypto, probe, adapter,
and new modules: reaction_utils, encryption, concurrency, config_patch,
group_mentions, profile_sync, session (S7 target ID), probe (S14 device/backup).
"""
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from yuxi.channels.adapters.matrix.adapter import MatrixAdapter
from yuxi.channels.adapters.matrix.formatter import markdown_to_matrix_html
from yuxi.channels.adapters.matrix.session import MatrixSessionHelper
from yuxi.channels.adapters.matrix.thread_utils import is_thread_event
from yuxi.channels.models import (
ChannelIdentity,
ChannelMessage,
ChannelResponse,
ChannelStatus,
ChannelType,
ChatType,
DeliveryResult,
EventType,
MessageType,
)
CHANNEL_ID = "matrix"
CHANNEL_TYPE = ChannelType.MATRIX
class TestFormatter:
def test_bold_text(self):
result = markdown_to_matrix_html("**hello**")
assert "hello" in result
def test_italic_text(self):
result = markdown_to_matrix_html("*hello*")
assert "hello" in result
def test_strikethrough_text(self):
result = markdown_to_matrix_html("~~hello~~")
assert "hello" in result
def test_inline_code(self):
result = markdown_to_matrix_html("`code`")
assert "code" in result
def test_code_block_escapes_html(self):
result = markdown_to_matrix_html("```\n\n```")
assert "
" in result
assert "<script>" in result
assert "alert(1)" in result
assert "</script>" in result
def test_link_renders_anchor(self):
result = markdown_to_matrix_html("[click](https://example.com)")
assert '' in result
def test_heading_renders_h_tags(self):
result = markdown_to_matrix_html("## Hello")
assert "Hello
" in result
def test_horizontal_rule_renders_hr(self):
result = markdown_to_matrix_html("---")
assert "
" in result
def test_unordered_list_renders_li(self):
result = markdown_to_matrix_html("- item")
assert "item " in result
def test_ordered_list_renders_li(self):
result = markdown_to_matrix_html("1. item")
assert "item " in result
def test_blockquote_renders_blockquote(self):
result = markdown_to_matrix_html("> quoted")
assert "quoted
" in result
def test_strips_script_tag(self):
result = markdown_to_matrix_html("")
assert "