Rebase onto upstream (a4d95fd)
#12
@@ -204,13 +204,16 @@ class ChannelManager:
|
|||||||
self.bus.consume_outbound(),
|
self.bus.consume_outbound(),
|
||||||
timeout=1.0
|
timeout=1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
if msg.metadata.get("_progress"):
|
if msg.metadata.get("_progress"):
|
||||||
if msg.metadata.get("_tool_hint") and not self.config.channels.send_tool_hints:
|
if msg.metadata.get("_tool_hint") and not self.config.channels.send_tool_hints:
|
||||||
continue
|
continue
|
||||||
if not msg.metadata.get("_tool_hint") and not self.config.channels.send_progress:
|
if not msg.metadata.get("_tool_hint") and not self.config.channels.send_progress:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Resolve any pending correlation (hook request-response)
|
||||||
|
self.bus.resolve_correlation(msg)
|
||||||
|
|
||||||
channel = self.channels.get(msg.channel)
|
channel = self.channels.get(msg.channel)
|
||||||
if channel:
|
if channel:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""Tests for correlation resolution in outbound dispatch."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
from nanobot.bus.queue import MessageBus
|
||||||
|
from nanobot.bus.events import OutboundMessage
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_dispatch_resolves_correlation_before_channel_send():
|
||||||
|
"""Correlation Future should be resolved when outbound message is dispatched."""
|
||||||
|
bus = MessageBus()
|
||||||
|
future = bus.register_correlation("corr-1")
|
||||||
|
|
||||||
|
msg = OutboundMessage(channel="telegram", chat_id="123", content="response", metadata={"correlation_id": "corr-1"})
|
||||||
|
await bus.publish_outbound(msg)
|
||||||
|
|
||||||
|
# Simulate what _dispatch_outbound does: consume + resolve
|
||||||
|
consumed = await asyncio.wait_for(bus.consume_outbound(), timeout=1.0)
|
||||||
|
bus.resolve_correlation(consumed)
|
||||||
|
|
||||||
|
assert future.done()
|
||||||
|
assert future.result() == "response"
|
||||||
Reference in New Issue
Block a user