auto-sync: 2026-06-01 22:44:40
This commit is contained in:
+11
-17
@@ -236,7 +236,7 @@ class TestAcquireFirst:
|
|||||||
asyncio.run(
|
asyncio.run(
|
||||||
spawner.spawn_full_agent("test-agent", "task2", task_id="t2")
|
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):
|
def test_phase2_session_check_under_lock(self, spawner):
|
||||||
"""E11.4 Phase 2: session check 在锁保护下执行
|
"""E11.4 Phase 2: session check 在锁保护下执行
|
||||||
@@ -327,23 +327,23 @@ class TestCompactHanging:
|
|||||||
compact_hanging outcome 时 counter 应被 release,任务不应被标 failed。
|
compact_hanging outcome 时 counter 应被 release,任务不应被标 failed。
|
||||||
"""
|
"""
|
||||||
from src.daemon.counter import ActiveAgentCounter
|
from src.daemon.counter import ActiveAgentCounter
|
||||||
|
from src.blackboard.models import Task as TaskModel
|
||||||
counter = ActiveAgentCounter(max_global=5, max_per_agent=1)
|
counter = ActiveAgentCounter(max_global=5, max_per_agent=1)
|
||||||
|
|
||||||
db_path = Path("/tmp/test_compact_hanging.db")
|
db_path = Path("/tmp/test_compact_hanging.db")
|
||||||
try:
|
try:
|
||||||
bb = Blackboard(db_path)
|
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"))
|
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
|
# 模拟 compact_hanging outcome 的 on_complete
|
||||||
outcomes = []
|
outcomes = []
|
||||||
async def mock_on_complete(aid, outcome):
|
async def mock_on_complete(aid, outcome):
|
||||||
outcomes.append((aid, outcome))
|
outcomes.append((aid, outcome))
|
||||||
|
|
||||||
# compact_hanging 的 on_complete 应 release counter
|
|
||||||
# 通过 wrapped_on_complete 机制验证
|
|
||||||
sid = asyncio.run(spawner.spawn_full_agent(
|
sid = asyncio.run(spawner.spawn_full_agent(
|
||||||
"test-agent", "task", task_id="t1",
|
"test-agent", "task", task_id="t1",
|
||||||
on_complete=mock_on_complete,
|
on_complete=mock_on_complete,
|
||||||
@@ -409,14 +409,10 @@ class TestAgentBusyErrorClassification:
|
|||||||
def test_session_blocker_reasons(self, spawner):
|
def test_session_blocker_reasons(self, spawner):
|
||||||
"""E14.2: session locked/running/compacting → 具体 reason + detail.blockers"""
|
"""E14.2: session locked/running/compacting → 具体 reason + detail.blockers"""
|
||||||
test_cases = [
|
test_cases = [
|
||||||
(
|
{
|
||||||
{"status": "idle", "lock_pid_alive": True, "lock_expired": False},
|
"state": {"status": "idle", "lock_pid_alive": True, "lock_expired": False},
|
||||||
"session_locked",
|
"expected": "session_locked",
|
||||||
),
|
},
|
||||||
(
|
|
||||||
{"status": "running", "lock_pid_alive": True, "lock_expired": False},
|
|
||||||
"session_running",
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
"state": {"status": "idle", "lock_pid_alive": False, "recent_compact": True},
|
"state": {"status": "idle", "lock_pid_alive": False, "recent_compact": True},
|
||||||
"expected": "session_compacting",
|
"expected": "session_compacting",
|
||||||
@@ -424,10 +420,8 @@ class TestAgentBusyErrorClassification:
|
|||||||
]
|
]
|
||||||
|
|
||||||
for i, tc in enumerate(test_cases):
|
for i, tc in enumerate(test_cases):
|
||||||
if isinstance(tc, dict):
|
state = tc["state"]
|
||||||
state, expected = tc["state"], tc["expected"]
|
expected = tc["expected"]
|
||||||
else:
|
|
||||||
state, expected = tc
|
|
||||||
|
|
||||||
spawner._check_session_state = lambda aid, s=state: s
|
spawner._check_session_state = lambda aid, s=state: s
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user