fix(chat): preserve routing for side-channel command replies (#6736)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-20 16:47:07 +08:00
1 parent 3e9024ea04
commit cd75dbfaac
13 files changed
+155 -34

No files matched your search

+19 -2
View File
@@ -155,12 +155,15 @@ async def _run_dream_command(ctx: CommandContext) -> OutboundMessage:
@pytest.mark.asyncio
async def test_dream_no_history_explains_how_to_create_input(tmp_path) -> None:
ctx, bus = _make_dream_ctx(tmp_path)
ctx.msg.metadata = {"slack": {"thread_ts": "123.456"}}
immediate = await _run_dream_command(ctx)
assert immediate.content == "Dreaming..."
assert len(bus.outbound) == 1
content = bus.outbound[0].content
assert immediate.metadata == ctx.msg.metadata
[completion] = bus.outbound
assert completion.metadata == {**ctx.msg.metadata, "render_as": "text"}
content = completion.content
assert "Dream has no conversation history to process yet." in content
assert "`memory/history.jsonl`" in content
assert "idle auto-compact" in content
@@ -214,6 +217,20 @@ async def test_dream_internal_run_silences_progress(tmp_path) -> None:
assert progress_sentinel not in completion.content
@pytest.mark.parametrize("command,handler", [("/dream-log", cmd_dream_log), ("/dream-restore", cmd_dream_restore)])
@pytest.mark.parametrize("initialized", [False, True])
async def test_dream_inspection_replies_preserve_topic_routing(command, handler, initialized) -> None:
ctx = _make_ctx(command, _FakeGit(initialized=initialized))
ctx.msg.metadata = {"message_thread_id": 12, "message_id": 34}
reply = await handler(ctx)
assert reply.metadata == {
**ctx.msg.metadata,
**({"render_as": "text"} if initialized or command == "/dream-log" else {}),
}
@pytest.mark.parametrize("completed", [True, False])
async def test_dream_command_reports_outcome_and_versions_only_real_edits(tmp_path, completed) -> None:
ctx, bus = _make_dream_ctx(tmp_path)
+3 -1
View File
@@ -6,7 +6,7 @@ from nanobot.bus.events import InboundMessage
from nanobot.bus.queue import MessageBus
from nanobot.command.builtin import cmd_pairing
from nanobot.command.router import CommandContext
from nanobot.pairing import store
from nanobot.pairing import PAIRING_COMMAND_META_KEY, store
from nanobot.pairing.events import PairingChanged
@@ -19,10 +19,12 @@ async def test_pairing_command_notifies_after_persistence_without_a_file_watcher
bus.subscribe(lambda _event: approved.append(store.is_approved("telegram", "alice")), PairingChanged)
loop = MagicMock(bus=bus)
msg = InboundMessage(channel="cli", sender_id="owner", chat_id="direct", content=f"/pairing approve {code}")
msg.metadata = {"webui_turn_id": "pairing-turn", "_history_generation": "admitted"}
ctx = CommandContext(msg=msg, session=None, key=msg.session_key, raw=msg.content, args=f"approve {code}", loop=loop)
result = await cmd_pairing(ctx)
await bus.drain()
assert "Approved" in result.content and approved == [True]
assert result.metadata == {**msg.metadata, PAIRING_COMMAND_META_KEY: True}
ctx.args = "approve invalid"
await cmd_pairing(ctx)
ctx.args = "list"