Skip to content

Commit

Permalink
fix: Fix get task
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Dec 26, 2024
1 parent 3b188f3 commit fc981b6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 74 deletions.
4 changes: 2 additions & 2 deletions agents-api/agents_api/common/protocol/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +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]
tools = spec.pop("tools", []) or []
tools = [{tool["type"]: tool.pop("spec"), **tool} for tool in tools if tool]

return {
"id": task_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
**d["agent"],
},
"agent_tools": [
{tool["type"]: tool.pop("spec"), **tool} for tool in d["tools"]
{tool["type"]: tool.pop("spec"), **tool} for tool in (d.get("tools", []) or [])
],
"arguments": d["execution"]["input"],
"execution": {
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/queries/tasks/get_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
jsonb_agg(tl) as tools
FROM
tasks t
INNER JOIN
LEFT JOIN
workflows w ON t.developer_id = w.developer_id AND t.task_id = w.task_id AND t.version = w.version
INNER JOIN
LEFT JOIN
tools tl ON t.developer_id = tl.developer_id AND t.task_id = tl.task_id
WHERE
t.developer_id = $1 AND t.task_id = $2
Expand Down
139 changes: 70 additions & 69 deletions agents-api/tests/test_task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)

from .fixtures import test_execution, test_transition
from .utils import patch_testing_temporal


@test("route: unauthorized should fail")
Expand Down Expand Up @@ -60,43 +61,43 @@ def _(make_request=make_request, agent=test_agent):
assert response.status_code == 201


# @test("route: create task execution")
# async def _(make_request=make_request, task=test_task):
# data = dict(
# input={},
# metadata={},
# )
@test("route: create task 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,
)

# assert response.status_code == 201
assert response.status_code == 201


# @test("route: get execution not exists")
# def _(make_request=make_request):
# execution_id = str(uuid7())
@test("route: get execution not exists")
def _(make_request=make_request):
execution_id = str(uuid7())

# response = make_request(
# method="GET",
# url=f"/executions/{execution_id}",
# )
response = make_request(
method="GET",
url=f"/executions/{execution_id}",
)

# assert response.status_code == 404
assert response.status_code == 404


# @test("route: get execution exists")
# def _(make_request=make_request, execution=test_execution):
# response = make_request(
# method="GET",
# url=f"/executions/{str(execution.id)}",
# )
@test("route: get execution exists")
def _(make_request=make_request, execution=test_execution):
response = make_request(
method="GET",
url=f"/executions/{str(execution.id)}",
)

# assert response.status_code == 200
assert response.status_code == 200


@test("route: get task not exists")
Expand Down Expand Up @@ -136,19 +137,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")
Expand Down Expand Up @@ -193,42 +194,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"

0 comments on commit fc981b6

Please sign in to comment.