Files
hermes-agent/tests/gateway/test_matrix_latex_maths.py
Teknium e22e04692a test(matrix): trim LaTeX salvage to two invariant tests, tidy _markdown_to_html
Keep the two tests that fail without the fix: inline + display math reach
formatted_body as data-mx-maths markup with the TeX HTML-escaped while the
plain body keeps the raw TeX; unpaired dollars and text colliding with the
sentinel format pass through unchanged (no IndexError). The 17 unit tests
from #106452 are dropped per the salvage bar (≤ 2 invariant tests).

Also drop the dead `_tex_store = []` pre-assignment and the `_fb`/`html`
temporaries in `_markdown_to_html` — pure tidy, no behaviour change.
2026-09-09 10:43:58 -07:00

26 lines
1.1 KiB
Python

"""Outbound ``$...$`` / ``$$...$$`` become Element ``data-mx-maths`` markup (#106458)."""
from gateway.config import PlatformConfig
from plugins.platforms.matrix.adapter import MatrixAdapter
def _adapter() -> MatrixAdapter:
return MatrixAdapter(PlatformConfig(
enabled=True, token="syt_test_token",
extra={"homeserver": "https://matrix.example.org", "user_id": "@bot:example.org"}))
def test_inline_and_display_math_survive_sanitizer_with_escaped_tex():
content = _adapter()._build_text_message_content("Wave: $a<b$ and $$\\hat{H}\\Psi = E\\Psi$$")
html = content["formatted_body"]
assert '<span data-mx-maths="a&lt;b">a&lt;b</span>' in html
assert '<div data-mx-maths="\\hat{H}\\Psi = E\\Psi">\\hat{H}\\Psi = E\\Psi</div>' in html
assert "$" not in html
# Plain-text fallback keeps the raw TeX for clients without the Labs feature.
assert content["body"] == "Wave: $a<b$ and $$\\hat{H}\\Psi = E\\Psi$$"
def test_unpaired_dollars_and_sentinel_collisions_pass_through_unchanged():
text = "Costs $5 or $10 today; HERMESTEXINLINE7HERMESTEXEND is not ours"
assert _adapter()._markdown_to_html(text) == text