fix(gateway): bypass active-session guard for gateway-handled slash commands
This commit is contained in:
@@ -200,6 +200,38 @@ class TestCommandBypassActiveSession:
|
||||
"/background response was not sent back to the user"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_help_bypasses_guard(self):
|
||||
"""/help must bypass so it is not silently dropped as pending slash text."""
|
||||
adapter = _make_adapter()
|
||||
sk = _session_key()
|
||||
adapter._active_sessions[sk] = asyncio.Event()
|
||||
|
||||
await adapter.handle_message(_make_event("/help"))
|
||||
|
||||
assert sk not in adapter._pending_messages, (
|
||||
"/help was queued as a pending message instead of being dispatched"
|
||||
)
|
||||
assert any("handled:help" in r for r in adapter.sent_responses), (
|
||||
"/help response was not sent back to the user"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_bypasses_guard(self):
|
||||
"""/update must bypass so it is not discarded by the pending-command safety net."""
|
||||
adapter = _make_adapter()
|
||||
sk = _session_key()
|
||||
adapter._active_sessions[sk] = asyncio.Event()
|
||||
|
||||
await adapter.handle_message(_make_event("/update"))
|
||||
|
||||
assert sk not in adapter._pending_messages, (
|
||||
"/update was queued as a pending message instead of being dispatched"
|
||||
)
|
||||
assert any("handled:update" in r for r in adapter.sent_responses), (
|
||||
"/update response was not sent back to the user"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_bypasses_guard(self):
|
||||
"""/queue must bypass so it can queue without interrupting."""
|
||||
|
||||
@@ -288,6 +288,38 @@ async def test_command_messages_do_not_leave_sentinel():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("command_text", "handler_attr", "handler_result"),
|
||||
[
|
||||
("/help", "_handle_help_command", "Help text"),
|
||||
("/commands", "_handle_commands_command", "Commands text"),
|
||||
("/update", "_handle_update_command", "Update text"),
|
||||
("/profile", "_handle_profile_command", "Profile text"),
|
||||
],
|
||||
)
|
||||
async def test_active_session_bypass_commands_dispatch_without_interrupt(
|
||||
command_text,
|
||||
handler_attr,
|
||||
handler_result,
|
||||
):
|
||||
"""Gateway-handled bypass commands must return directly while an agent runs."""
|
||||
runner = _make_runner()
|
||||
event = _make_event(text=command_text)
|
||||
session_key = build_session_key(event.source)
|
||||
|
||||
fake_agent = MagicMock()
|
||||
fake_agent.get_activity_summary.return_value = {"seconds_since_activity": 0}
|
||||
runner._running_agents[session_key] = fake_agent
|
||||
setattr(runner, handler_attr, AsyncMock(return_value=handler_result))
|
||||
|
||||
result = await runner._handle_message(event)
|
||||
|
||||
assert result == handler_result
|
||||
fake_agent.interrupt.assert_not_called()
|
||||
assert session_key not in runner.adapters[Platform.TELEGRAM]._pending_messages
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 6: /stop during sentinel force-cleans and unlocks session
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user