fix(channels): preserve explicit compaction feedback and silent delivery
This commit is contained in:
1 parent
0b402d0414
commit
7644d845b4
13 files changed
+96
-37
No files matched your search
@@ -2,8 +2,8 @@
|
||||
|
||||
QQ's C2C/group message API has no edit or recall endpoint, so the
|
||||
compaction lifecycle would land as two separate permanent messages. The
|
||||
channel drops ``ContextCompactionEvent`` by default; ``showCompactionNotices:
|
||||
true`` restores the notices for anyone who wants them (#5784).
|
||||
channel drops automatic notices by default; ``showCompactionNotices: true``
|
||||
restores them (#5784). Manual requests keep their feedback independently.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -20,16 +20,18 @@ from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.qq.runtime import QQChannel, QQConfig
|
||||
|
||||
|
||||
def _make_channel(**config_kwargs) -> QQChannel:
|
||||
config = QQConfig(app_id="test_app", secret="test_secret", **config_kwargs)
|
||||
def _make_channel(tmp_path, **config_kwargs) -> QQChannel:
|
||||
config = QQConfig(
|
||||
app_id="test_app", secret="test_secret", media_dir=str(tmp_path), **config_kwargs,
|
||||
)
|
||||
channel = QQChannel(config, MessageBus())
|
||||
channel._client = object() # truthy: pass the initialized check
|
||||
return channel
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_compaction_notices_dropped_by_default(monkeypatch) -> None:
|
||||
channel = _make_channel()
|
||||
async def test_compaction_notices_dropped_by_default(monkeypatch, tmp_path) -> None:
|
||||
channel = _make_channel(tmp_path)
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
@@ -43,23 +45,40 @@ async def test_compaction_notices_dropped_by_default(monkeypatch) -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_compaction_notices_sent_when_enabled(monkeypatch) -> None:
|
||||
channel = _make_channel(show_compaction_notices=True)
|
||||
@pytest.mark.parametrize("notify", [False, True])
|
||||
@pytest.mark.parametrize("phase", ["started", "succeeded", "failed", "cancelled"])
|
||||
async def test_compaction_notices_sent_when_enabled(monkeypatch, tmp_path, notify, phase) -> None:
|
||||
channel = _make_channel(tmp_path, show_compaction_notices=True)
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
await channel.send(outbound_message_for_event(
|
||||
channel="qq", chat_id="chat",
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase="started", notify=True),
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase=phase, notify=notify),
|
||||
))
|
||||
|
||||
send_text.assert_awaited_once()
|
||||
assert send_text.await_args.kwargs["content"] == "Compressing context…"
|
||||
assert send_text.await_args.kwargs["content"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ordinary_messages_unaffected(monkeypatch) -> None:
|
||||
channel = _make_channel()
|
||||
@pytest.mark.parametrize("phase", ["started", "succeeded", "failed", "cancelled"])
|
||||
async def test_manual_compaction_has_feedback_with_default_config(monkeypatch, tmp_path, phase) -> None:
|
||||
channel = _make_channel(tmp_path)
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
await channel.send(outbound_message_for_event(
|
||||
channel="qq", chat_id="chat",
|
||||
event=ContextCompactionEvent(compaction_id="manual", phase=phase, notify=True),
|
||||
))
|
||||
|
||||
send_text.assert_awaited_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ordinary_messages_unaffected(monkeypatch, tmp_path) -> None:
|
||||
channel = _make_channel(tmp_path)
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
|
||||
Reference in new issue
Block a user