Skip to content

Commit 60a6da9

Browse files
committed
fix(agents-api): Fix all pytest tests
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
1 parent 55cb1f7 commit 60a6da9

File tree

13 files changed

+344
-282
lines changed

13 files changed

+344
-282
lines changed

agents-api/.pytest-runtimes

Lines changed: 256 additions & 256 deletions
Large diffs are not rendered by default.

agents-api/AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ Key Uses
8585
- All Ward imports removed, migration complete
8686
- Run tests: `poe test` or `poe test -k "pattern"` for specific tests
8787
- Stop on first failure: `poe test -x`
88+
89+
## Type Checking
90+
- AIDEV-NOTE: autogen/openapi_model.py is handwritten, not auto-generated
91+
- Type checking errors from openapi_model.py are intentional (dynamic type property patches)
92+
- Use `ty check` for extremely fast type checking (pytype replacement)

agents-api/agents_api/autogen/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This folder contains auto-generated code in `agents-api` from TypeSpec and OpenA
44

55
Key Points
66
- Do NOT edit files here manually; they are overwritten on regeneration.
7+
- EXCEPTION: `openapi_model.py` is handwritten and should be edited manually (not auto-generated).
78
- Regenerate via `bash scripts/generate_openapi_code.sh` from the project root.
89
- Source-of-truth TypeSpec definitions reside in the `typespec/` directory.
910
- Ensure version compatibility between TypeSpec plugin and codegen scripts.

agents-api/agents_api/autogen/openapi_model.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ruff: noqa: F401, F403, F405
2+
# AIDEV-NOTE: This file is handwritten, not auto-generated like other files in autogen/
23
import ast
34
from typing import Annotated, Any, Generic, Literal, Self, TypeVar, get_args
45
from uuid import UUID
@@ -103,20 +104,20 @@ def type_property(self: BaseModel) -> str:
103104
else "api_call"
104105
if self.api_call
105106
else None
106-
)
107+
) # type: ignore[invalid-return-type]
107108

108109

109110
# Patch original Tool class to add 'type' property
110-
TaskTool.type = computed_field(property(type_property))
111+
TaskTool.type = computed_field(property(type_property)) # type: ignore[invalid-attribute-access]
111112

112113
# Patch original Tool class to add 'type' property
113-
Tool.type = computed_field(property(type_property))
114+
Tool.type = computed_field(property(type_property)) # type: ignore[invalid-attribute-access]
114115

115116
# Patch original UpdateToolRequest class to add 'type' property
116-
UpdateToolRequest.type = computed_field(property(type_property))
117+
UpdateToolRequest.type = computed_field(property(type_property)) # type: ignore[invalid-attribute-access]
117118

118119
# Patch original PatchToolRequest class to add 'type' property
119-
PatchToolRequest.type = computed_field(property(type_property))
120+
PatchToolRequest.type = computed_field(property(type_property)) # type: ignore[invalid-attribute-access]
120121

121122

122123
# Patch Task Workflow Steps

agents-api/agents_api/workflows/task_execution/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def validate_execution_input(execution_input: ExecutionInput) -> TaskSpecDef:
4646
Raises:
4747
ApplicationError: If task is None
4848
"""
49-
if execution_input.task is None:
49+
task = execution_input.task
50+
if task is None:
5051
msg = "Execution input task cannot be None"
5152
raise ApplicationError(msg)
52-
return execution_input.task
53+
return task
5354

5455

5556
async def base_evaluate_activity(

agents-api/tests/conftest.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Migrated from Ward fixtures.py
44
"""
55

6+
import contextlib
67
import os
78
import random
89
import string
@@ -615,11 +616,37 @@ def disable_s3_cache():
615616

616617

617618
@pytest.fixture
618-
def s3_client():
619+
async def s3_client(localstack_container):
619620
"""S3 client fixture that works with TestClient's event loop."""
620-
# The TestClient's lifespan will create the S3 client
621-
# The disable_s3_cache fixture ensures we don't have event loop issues
622-
yield
621+
from contextlib import AsyncExitStack
622+
623+
from aiobotocore.session import get_session
624+
625+
# AIDEV-NOTE: Fixed S3 client fixture with proper LocalStack integration
626+
# to resolve NoSuchKey errors in file route tests
627+
628+
# Create async S3 client using LocalStack
629+
session = get_session()
630+
631+
async with AsyncExitStack() as stack:
632+
client = await stack.enter_async_context(
633+
session.create_client(
634+
"s3",
635+
aws_access_key_id=localstack_container.env["AWS_ACCESS_KEY_ID"],
636+
aws_secret_access_key=localstack_container.env["AWS_SECRET_ACCESS_KEY"],
637+
endpoint_url=localstack_container.get_url(),
638+
region_name="us-east-1",
639+
)
640+
)
641+
642+
# Ensure default bucket exists
643+
try:
644+
await client.head_bucket(Bucket="default")
645+
except Exception:
646+
with contextlib.suppress(Exception):
647+
await client.create_bucket(Bucket="default") # Bucket might already exist
648+
649+
yield client
623650

624651

625652
@pytest.fixture

agents-api/tests/sample_tasks/test_find_selector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_workflow_sample_find_selector_start_with_bad_input_should_fail(
4848
):
4949
task_def = sample_file.read()
5050

51-
async with patch_testing_temporal() as (_, temporal_client):
51+
async with patch_testing_temporal():
5252
response = make_request(
5353
method="POST",
5454
url=f"/agents/{agent_id}/tasks/{task_id}",
@@ -85,7 +85,7 @@ async def test_workflow_sample_find_selector_start_with_correct_input(
8585
):
8686
task_def = sample_file.read()
8787

88-
async with patch_testing_temporal() as (_, mock_temporal_client):
88+
async with patch_testing_temporal():
8989
response = make_request(
9090
method="POST",
9191
url=f"/agents/{agent_id}/tasks/{task_id}",

agents-api/tests/test_chat_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ async def mock_render(*args, **kwargs):
333333
create_entries_mock.assert_called_once()
334334
call_args = create_entries_mock.call_args[1]
335335
assert call_args["developer_id"] == test_developer_id
336-
assert call_args["session_id"] == test_session.id
336+
assert call_args["session_id"] == session.id
337337
# Verify we're saving the user message
338338
assert len(call_args["data"]) == 1
339339
assert call_args["data"][0].role == "user"

agents-api/tests/test_docs_routes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from .utils import patch_testing_temporal
32

43

agents-api/tests/test_middleware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import asyncpg
99
import pytest
1010
from agents_api.app import app
11+
from agents_api.clients.pg import create_db_pool
1112
from agents_api.env import free_tier_cost_limit
13+
from agents_api.queries.developers.create_developer import create_developer
1214
from fastapi import HTTPException, status
1315
from fastapi.testclient import TestClient
1416
from pydantic import BaseModel

0 commit comments

Comments
 (0)