Files
nousresearch--hermes-agent/tests/gateway/test_discord_format.py
T
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

59 lines
1.9 KiB
Python

"""Discord format_message: tables converted to bullet groups."""
import types
import sys
def _make_discord_adapter():
"""Construct a DiscordAdapter with discord.py stubbed out."""
fake_discord = types.ModuleType("discord")
fake_discord.Intents = type("Intents", (), {"default": classmethod(lambda cls: cls())})
fake_discord.Message = object
fake_ext = types.ModuleType("discord.ext")
fake_commands = types.ModuleType("discord.ext.commands")
fake_ext.commands = fake_commands
fake_discord.ext = fake_ext
sys.modules.setdefault("discord", fake_discord)
sys.modules.setdefault("discord.ext", fake_ext)
sys.modules.setdefault("discord.ext.commands", fake_commands)
from plugins.platforms.discord.adapter import DiscordAdapter
adapter = object.__new__(DiscordAdapter)
return adapter
class TestDiscordFormatMessage:
def test_table_converted_to_bullets(self):
adapter = _make_discord_adapter()
text = (
"Results:\n\n"
"| Name | Score |\n"
"|------|-------|\n"
"| Alice | 95 |\n"
"| Bob | 80 |\n"
"\nDone."
)
out = adapter.format_message(text)
assert "**Alice**" in out
assert "• Score: 95" in out
assert "**Bob**" in out
assert "• Score: 80" in out
assert out.startswith("Results:")
assert out.rstrip().endswith("Done.")
assert "|---" not in out
def test_plain_text_unchanged(self):
adapter = _make_discord_adapter()
text = "Hello world, no tables here."
assert adapter.format_message(text) == text
def test_code_block_table_unchanged(self):
adapter = _make_discord_adapter()
text = "```\n| a | b |\n|---|---|\n| 1 | 2 |\n```"
assert adapter.format_message(text) == text
def test_empty_string(self):
adapter = _make_discord_adapter()
assert adapter.format_message("") == ""