From 1c4fbeed0b5224817f2045866348f6d2ea3ed8d8 Mon Sep 17 00:00:00 2001 From: Dmitry Paramonov Date: Thu, 26 Dec 2024 16:11:56 +0300 Subject: [PATCH] fix: Fix get task --- .../agents_api/common/protocol/tasks.py | 6 +- agents-api/tests/test_task_routes.py | 84 ++++++++++--------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/agents-api/agents_api/common/protocol/tasks.py b/agents-api/agents_api/common/protocol/tasks.py index 07736e7d6..cea2a3b28 100644 --- a/agents-api/agents_api/common/protocol/tasks.py +++ b/agents-api/agents_api/common/protocol/tasks.py @@ -306,10 +306,8 @@ def spec_to_task_data(spec: dict) -> dict: workflows = spec.pop("workflows") workflows_dict = {workflow["name"]: workflow["steps"] for workflow in workflows} - tools = spec.pop("tools", []) - tools = [ - {tool["type"]: tool.pop("spec"), **tool} for tool in tools if tool is not None - ] + tools = spec.pop("tools", []) or [] + tools = [{tool["type"]: tool.pop("spec"), **tool} for tool in tools if tool] return { "id": task_id, diff --git a/agents-api/tests/test_task_routes.py b/agents-api/tests/test_task_routes.py index e67b6a3b0..c94d6112a 100644 --- a/agents-api/tests/test_task_routes.py +++ b/agents-api/tests/test_task_routes.py @@ -11,6 +11,8 @@ test_task, test_transition, ) + +from .fixtures import test_execution, test_transition from .utils import patch_testing_temporal @@ -136,19 +138,19 @@ def _(make_request=make_request, execution=test_execution, transition=test_trans assert len(transitions) > 0 -# @test("route: list task executions") -# def _(make_request=make_request, execution=test_execution): -# response = make_request( -# method="GET", -# url=f"/tasks/{str(execution.task_id)}/executions", -# ) +@test("route: list task executions") +def _(make_request=make_request, execution=test_execution): + response = make_request( + method="GET", + url=f"/tasks/{str(execution.task_id)}/executions", + ) -# assert response.status_code == 200 -# response = response.json() -# executions = response["items"] + assert response.status_code == 200 + response = response.json() + executions = response["items"] -# assert isinstance(executions, list) -# assert len(executions) > 0 + assert isinstance(executions, list) + assert len(executions) > 0 @test("route: list tasks") @@ -193,42 +195,42 @@ def _(make_request=make_request, agent=test_agent): # FIXME: This test is failing -# @test("route: patch execution") -# async def _(make_request=make_request, task=test_task): -# data = dict( -# input={}, -# metadata={}, -# ) +@test("route: patch execution") +async def _(make_request=make_request, task=test_task): + data = dict( + input={}, + metadata={}, + ) -# async with patch_testing_temporal(): -# response = make_request( -# method="POST", -# url=f"/tasks/{str(task.id)}/executions", -# json=data, -# ) + async with patch_testing_temporal(): + response = make_request( + method="POST", + url=f"/tasks/{str(task.id)}/executions", + json=data, + ) -# execution = response.json() + execution = response.json() -# data = dict( -# status="running", -# ) + data = dict( + status="running", + ) -# response = make_request( -# method="PATCH", -# url=f"/tasks/{str(task.id)}/executions/{str(execution['id'])}", -# json=data, -# ) + response = make_request( + method="PATCH", + url=f"/tasks/{str(task.id)}/executions/{str(execution['id'])}", + json=data, + ) -# assert response.status_code == 200 + assert response.status_code == 200 -# execution_id = response.json()["id"] + execution_id = response.json()["id"] -# response = make_request( -# method="GET", -# url=f"/executions/{execution_id}", -# ) + response = make_request( + method="GET", + url=f"/executions/{execution_id}", + ) -# assert response.status_code == 200 -# execution = response.json() + assert response.status_code == 200 + execution = response.json() -# assert execution["status"] == "running" + assert execution["status"] == "running"