mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-27 21:35:51 +00:00
test(discord): cover streamed reply overflow
Lock the Discord streaming path with a regression test for final chunk splitting so oversized replies stay safe to merge and ship. Made-with: Cursor
This commit is contained in:
parent
e49b6c0c96
commit
61dd5ac13a
@ -9,7 +9,7 @@ discord = pytest.importorskip("discord")
|
|||||||
|
|
||||||
from nanobot.bus.events import OutboundMessage
|
from nanobot.bus.events import OutboundMessage
|
||||||
from nanobot.bus.queue import MessageBus
|
from nanobot.bus.queue import MessageBus
|
||||||
from nanobot.channels.discord import DiscordBotClient, DiscordChannel, DiscordConfig
|
from nanobot.channels.discord import MAX_MESSAGE_LEN, DiscordBotClient, DiscordChannel, DiscordConfig
|
||||||
from nanobot.command.builtin import build_help_text
|
from nanobot.command.builtin import build_help_text
|
||||||
|
|
||||||
|
|
||||||
@ -471,6 +471,33 @@ async def test_send_delta_streams_by_editing_message(monkeypatch) -> None:
|
|||||||
assert owner._stream_bufs == {}
|
assert owner._stream_bufs == {}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_delta_stream_end_splits_oversized_reply(monkeypatch) -> None:
|
||||||
|
owner = DiscordChannel(DiscordConfig(enabled=True, allow_from=["*"]), MessageBus())
|
||||||
|
client = _FakeDiscordClient(owner, intents=None)
|
||||||
|
owner._client = client
|
||||||
|
owner._running = True
|
||||||
|
target = _FakeChannel(channel_id=123)
|
||||||
|
client.channels[123] = target
|
||||||
|
|
||||||
|
prefix = "a" * (MAX_MESSAGE_LEN - 100)
|
||||||
|
suffix = "b" * 150
|
||||||
|
full_text = prefix + suffix
|
||||||
|
chunks = DiscordBotClient._build_chunks(full_text, [], False)
|
||||||
|
assert len(chunks) == 2
|
||||||
|
|
||||||
|
times = iter([1.0, 3.0])
|
||||||
|
monkeypatch.setattr("nanobot.channels.discord.time.monotonic", lambda: next(times, 3.0))
|
||||||
|
|
||||||
|
await owner.send_delta("123", prefix, {"_stream_delta": True, "_stream_id": "s1"})
|
||||||
|
await owner.send_delta("123", suffix, {"_stream_delta": True, "_stream_id": "s1"})
|
||||||
|
await owner.send_delta("123", "", {"_stream_end": True, "_stream_id": "s1"})
|
||||||
|
|
||||||
|
assert target.sent_payloads == [{"content": prefix}, {"content": chunks[1]}]
|
||||||
|
assert target.sent_messages[0].edits == [{"content": chunks[0]}, {"content": chunks[0]}]
|
||||||
|
assert owner._stream_bufs == {}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_slash_new_forwards_when_user_is_allowlisted() -> None:
|
async def test_slash_new_forwards_when_user_is_allowlisted() -> None:
|
||||||
channel = DiscordChannel(DiscordConfig(enabled=True, allow_from=["123"]), MessageBus())
|
channel = DiscordChannel(DiscordConfig(enabled=True, allow_from=["123"]), MessageBus())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user