fix(heartbeat): route unified sessions to last channel
This commit is contained in:
@@ -1787,6 +1787,42 @@ def test_heartbeat_target_skips_archived_webui_sessions():
|
||||
assert target == ("websocket", "active")
|
||||
|
||||
|
||||
def test_heartbeat_target_uses_last_channel_for_unified_session():
|
||||
from nanobot.cli.commands import _pick_heartbeat_target_from_sessions
|
||||
from nanobot.session.keys import LAST_CHANNEL_METADATA_KEY, UNIFIED_SESSION_KEY
|
||||
|
||||
target = _pick_heartbeat_target_from_sessions(
|
||||
enabled_channels=["telegram", "discord"],
|
||||
archived_keys=[],
|
||||
sessions=[{"key": UNIFIED_SESSION_KEY}],
|
||||
unified_session_metadata={LAST_CHANNEL_METADATA_KEY: "discord:chat-42"},
|
||||
)
|
||||
|
||||
assert target == ("discord", "chat-42")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"metadata",
|
||||
[
|
||||
{"last_channel": "telegram:chat-42"},
|
||||
{"last_channel": "cli:direct"},
|
||||
{"last_channel": "invalid"},
|
||||
],
|
||||
)
|
||||
def test_heartbeat_target_rejects_unroutable_unified_metadata(metadata):
|
||||
from nanobot.cli.commands import _pick_heartbeat_target_from_sessions
|
||||
from nanobot.session.keys import UNIFIED_SESSION_KEY
|
||||
|
||||
target = _pick_heartbeat_target_from_sessions(
|
||||
enabled_channels=["discord"],
|
||||
archived_keys=[],
|
||||
sessions=[{"key": UNIFIED_SESSION_KEY}],
|
||||
unified_session_metadata=metadata,
|
||||
)
|
||||
|
||||
assert target == ("cli", "direct")
|
||||
|
||||
|
||||
def _write_instance_config(tmp_path: Path) -> Path:
|
||||
config_file = tmp_path / "instance" / "config.json"
|
||||
config_file.parent.mkdir(parents=True)
|
||||
|
||||
Reference in New Issue
Block a user