diff --git a/tests/test_spawner.py b/tests/test_spawner.py index 98fd083..f4f774e 100644 --- a/tests/test_spawner.py +++ b/tests/test_spawner.py @@ -447,6 +447,31 @@ class TestAgentBusyErrorClassification: assert exc_info.value.detail is not None, \ f"Case {i}: expected detail to be set" + def test_session_running_in_blockers(self, spawner): + """session_running 出现在 blockers 列表中(session_locked 优先) + + status=running + lock alive → session_locked 和 session_running 同时存在, + session_locked 排第一(primary_reason),但 blockers 列表包含 session_running。 + """ + spawner._check_session_state = lambda aid: { + "status": "running", "lock_pid_alive": True, "lock_expired": False, + } + + with pytest.raises(AgentBusyError) as exc_info: + asyncio.run( + spawner.spawn_full_agent( + "test-agent", "task", + task_id="t1", use_main_session=True, + ) + ) + # primary_reason 是 session_locked + assert "session_locked" in exc_info.value.reason + # blockers 列表包含 session_running + blockers = exc_info.value.detail.get("blockers", []) + blocker_reasons = [b[0] for b in blockers] + assert "session_running" in blocker_reasons + assert "session_locked" in blocker_reasons + def test_error_attributes(self): """E14 补充: AgentBusyError 属性验证""" err = AgentBusyError(