test(subagent): verify cascade exec termination on /stop

- terminate_by_owner kills matching sessions, skips others, handles
  empty owner case
- cancel_by_session calls terminate_by_owner on the session key
This commit is contained in:
yorkhellen
2026-07-22 15:28:34 +08:00
committed by chengyongru
parent 7b1d81a868
commit ebf1ef5cab
2 changed files with 103 additions and 0 deletions
+21
View File
@@ -274,6 +274,27 @@ class TestSubagentCancellation:
)
assert await mgr.cancel_by_session("nonexistent") == 0
@pytest.mark.asyncio
async def test_cancel_by_session_terminates_exec_sessions(self):
from nanobot.agent.subagent import SubagentManager
from nanobot.agent.tools.exec_session import ExecSessionManager
from nanobot.bus.queue import MessageBus
bus = MessageBus()
mgr = SubagentManager(
workspace=MagicMock(),
bus=bus,
max_tool_result_chars=_MAX_TOOL_RESULT_CHARS,
)
# Replace the real exec session manager with a mock
mock_exec_mgr = AsyncMock(spec=ExecSessionManager)
mock_exec_mgr.terminate_by_owner = AsyncMock(return_value=0)
mgr._exec_session_manager = mock_exec_mgr
await mgr.cancel_by_session("test:c1")
mock_exec_mgr.terminate_by_owner.assert_awaited_once_with("test:c1")
@pytest.mark.asyncio
async def test_subagent_preserves_reasoning_fields_in_tool_turn(self, monkeypatch, tmp_path):
from nanobot.agent.subagent import SubagentManager