Fix: allow agent status change on unassigned tasks
This commit is contained in:
@@ -2075,15 +2075,7 @@ async def _apply_non_lead_agent_task_rules(
|
|||||||
code="task_board_mismatch",
|
code="task_board_mismatch",
|
||||||
message="Agent can only update tasks for their assigned board.",
|
message="Agent can only update tasks for their assigned board.",
|
||||||
)
|
)
|
||||||
if (
|
# Allow agents to claim unassigned tasks by updating status (when permitted by board rules).
|
||||||
update.actor.agent
|
|
||||||
and "status" in update.updates
|
|
||||||
and (update.task.assigned_agent_id is None)
|
|
||||||
):
|
|
||||||
raise _task_update_forbidden_error(
|
|
||||||
code="task_assignee_required",
|
|
||||||
message="Agents can only change status on tasks assigned to them.",
|
|
||||||
)
|
|
||||||
if (
|
if (
|
||||||
update.actor.agent
|
update.actor.agent
|
||||||
and update.task.assigned_agent_id is not None
|
and update.task.assigned_agent_id is not None
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ async def test_non_lead_agent_can_update_status_for_assigned_task() -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_non_lead_agent_forbidden_without_assigned_task() -> None:
|
async def test_non_lead_agent_can_update_status_for_unassigned_task() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
try:
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
@@ -127,6 +127,7 @@ async def test_non_lead_agent_forbidden_without_assigned_task() -> None:
|
|||||||
name="board",
|
name="board",
|
||||||
slug="board",
|
slug="board",
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
|
only_lead_can_change_status=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
session.add(
|
session.add(
|
||||||
@@ -155,21 +156,15 @@ async def test_non_lead_agent_forbidden_without_assigned_task() -> None:
|
|||||||
actor = (await session.exec(select(Agent).where(col(Agent.id) == actor_id))).first()
|
actor = (await session.exec(select(Agent).where(col(Agent.id) == actor_id))).first()
|
||||||
assert actor is not None
|
assert actor is not None
|
||||||
|
|
||||||
with pytest.raises(HTTPException) as exc:
|
updated = await tasks_api.update_task(
|
||||||
await tasks_api.update_task(
|
payload=TaskUpdate(status="in_progress"),
|
||||||
payload=TaskUpdate(status="in_progress"),
|
task=task,
|
||||||
task=task,
|
session=session,
|
||||||
session=session,
|
actor=ActorContext(actor_type="agent", agent=actor),
|
||||||
actor=ActorContext(actor_type="agent", agent=actor),
|
|
||||||
)
|
|
||||||
|
|
||||||
assert exc.value.status_code == 403
|
|
||||||
assert isinstance(exc.value.detail, dict)
|
|
||||||
assert exc.value.detail["code"] == "task_assignee_required"
|
|
||||||
assert (
|
|
||||||
exc.value.detail["message"]
|
|
||||||
== "Agents can only change status on tasks assigned to them."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert updated.status == "in_progress"
|
||||||
|
assert updated.assigned_agent_id == actor_id
|
||||||
finally:
|
finally:
|
||||||
await engine.dispose()
|
await engine.dispose()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user