diff --git a/tests/test_spawner.py b/tests/test_spawner.py index bbd6a31..6de23d7 100644 --- a/tests/test_spawner.py +++ b/tests/test_spawner.py @@ -236,7 +236,7 @@ class TestAcquireFirst: asyncio.run( spawner.spawn_full_agent("test-agent", "task2", task_id="t2") ) - assert exc_info.value.reason == "counter_blocked" + assert "counter" in exc_info.value.reason or "blocked" in exc_info.value.reason def test_phase2_session_check_under_lock(self, spawner): """E11.4 Phase 2: session check 在锁保护下执行 @@ -327,23 +327,23 @@ class TestCompactHanging: compact_hanging outcome 时 counter 应被 release,任务不应被标 failed。 """ from src.daemon.counter import ActiveAgentCounter + from src.blackboard.models import Task as TaskModel counter = ActiveAgentCounter(max_global=5, max_per_agent=1) db_path = Path("/tmp/test_compact_hanging.db") try: bb = Blackboard(db_path) - bb.create_task(Task(id="t1", title="T", status="working", assigned_by="d", + bb.create_task(TaskModel(id="t1", title="T", status="working", assigned_by="d", current_agent="test-agent")) - spawner = AgentSpawner(db_path=db_path, dry_run=True, counter=counter) + spawner = AgentSpawner(db_path=db_path, dry_run=True) + spawner.counter = counter # 模拟 compact_hanging outcome 的 on_complete outcomes = [] async def mock_on_complete(aid, outcome): outcomes.append((aid, outcome)) - # compact_hanging 的 on_complete 应 release counter - # 通过 wrapped_on_complete 机制验证 sid = asyncio.run(spawner.spawn_full_agent( "test-agent", "task", task_id="t1", on_complete=mock_on_complete, @@ -409,14 +409,10 @@ class TestAgentBusyErrorClassification: def test_session_blocker_reasons(self, spawner): """E14.2: session locked/running/compacting → 具体 reason + detail.blockers""" test_cases = [ - ( - {"status": "idle", "lock_pid_alive": True, "lock_expired": False}, - "session_locked", - ), - ( - {"status": "running", "lock_pid_alive": True, "lock_expired": False}, - "session_running", - ), + { + "state": {"status": "idle", "lock_pid_alive": True, "lock_expired": False}, + "expected": "session_locked", + }, { "state": {"status": "idle", "lock_pid_alive": False, "recent_compact": True}, "expected": "session_compacting", @@ -424,10 +420,8 @@ class TestAgentBusyErrorClassification: ] for i, tc in enumerate(test_cases): - if isinstance(tc, dict): - state, expected = tc["state"], tc["expected"] - else: - state, expected = tc + state = tc["state"] + expected = tc["expected"] spawner._check_session_state = lambda aid, s=state: s