Skip to content

Commit 158733b

Browse files
committed
fix(agents-api): Fix failing tests
Signed-off-by: Diwank Singh Tomer <[email protected]>
1 parent ca50098 commit 158733b

File tree

6 files changed

+534
-434
lines changed

6 files changed

+534
-434
lines changed

agents-api/.pytest-runtimes

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

agents-api/tests/conftest.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,11 @@ async def test_doc_with_embedding(pg_dsn, test_developer, test_doc):
242242
"""Create a test document with embeddings."""
243243
pool = await create_db_pool(dsn=pg_dsn)
244244
embedding_with_confidence_0 = make_vector_with_similarity(d=0.0)
245-
make_vector_with_similarity(d=0.5)
246-
make_vector_with_similarity(d=-0.5)
245+
embedding_with_confidence_0_5 = make_vector_with_similarity(d=0.5)
246+
embedding_with_confidence_neg_0_5 = make_vector_with_similarity(d=-0.5)
247247
embedding_with_confidence_1_neg = make_vector_with_similarity(d=-1.0)
248248

249+
# Insert embedding with all 1.0s (similarity = 1.0)
249250
await pool.execute(
250251
"""
251252
INSERT INTO docs_embeddings_store (developer_id, doc_id, index, chunk_seq, chunk, embedding)
@@ -269,7 +270,7 @@ async def test_doc_with_embedding(pg_dsn, test_developer, test_doc):
269270
f"[{', '.join([str(x) for x in embedding_with_confidence_0])}]",
270271
)
271272

272-
# Insert embedding with confidence -1
273+
# Insert embedding with confidence 0.5
273274
await pool.execute(
274275
"""
275276
INSERT INTO docs_embeddings_store (developer_id, doc_id, index, chunk_seq, chunk, embedding)
@@ -278,6 +279,30 @@ async def test_doc_with_embedding(pg_dsn, test_developer, test_doc):
278279
test_developer.id,
279280
test_doc.id,
280281
"Test content 2",
282+
f"[{', '.join([str(x) for x in embedding_with_confidence_0_5])}]",
283+
)
284+
285+
# Insert embedding with confidence -0.5
286+
await pool.execute(
287+
"""
288+
INSERT INTO docs_embeddings_store (developer_id, doc_id, index, chunk_seq, chunk, embedding)
289+
VALUES ($1, $2, 3, 3, $3, $4)
290+
""",
291+
test_developer.id,
292+
test_doc.id,
293+
"Test content 3",
294+
f"[{', '.join([str(x) for x in embedding_with_confidence_neg_0_5])}]",
295+
)
296+
297+
# Insert embedding with confidence -1
298+
await pool.execute(
299+
"""
300+
INSERT INTO docs_embeddings_store (developer_id, doc_id, index, chunk_seq, chunk, embedding)
301+
VALUES ($1, $2, 4, 4, $3, $4)
302+
""",
303+
test_developer.id,
304+
test_doc.id,
305+
"Test content 4",
281306
f"[{', '.join([str(x) for x in embedding_with_confidence_1_neg])}]",
282307
)
283308

@@ -552,16 +577,26 @@ async def s3_client():
552577
with get_localstack() as localstack:
553578
s3_endpoint = localstack.get_url()
554579

580+
from botocore.config import Config
581+
555582
session = get_session()
556583
s3 = await session.create_client(
557584
"s3",
558585
endpoint_url=s3_endpoint,
559586
aws_access_key_id=localstack.env["AWS_ACCESS_KEY_ID"],
560587
aws_secret_access_key=localstack.env["AWS_SECRET_ACCESS_KEY"],
588+
config=Config(s3={'addressing_style': 'path'})
561589
).__aenter__()
562590

563591
app.state.s3_client = s3
564592

593+
# Create the bucket if it doesn't exist
594+
from agents_api.env import blob_store_bucket
595+
try:
596+
await s3.head_bucket(Bucket=blob_store_bucket)
597+
except Exception:
598+
await s3.create_bucket(Bucket=blob_store_bucket)
599+
565600
try:
566601
yield s3
567602
finally:

agents-api/tests/test_docs_queries.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,10 @@ async def test_query_search_docs_by_embedding_with_different_confidence_levels(
660660
confidence_tests = [
661661
(0.99, 0), # Very high similarity threshold - should find no results
662662
(0.7, 1), # High similarity - should find 1 result (the embedding with all 1.0s)
663-
(0.3, 2), # Medium similarity - should find 2 results (including 0.3-0.7 embedding)
664-
(-0.8, 3), # Low similarity - should find 3 results (including -0.8 to 0.8 embedding)
665-
(-1.0, 4), # Lowest similarity - should find all 4 results (including alternating -1/1)
663+
(0.3, 2), # Medium similarity - should find 2 results (including 0.5 similarity embedding)
664+
(-0.3, 3), # Low similarity - should find 3 results (including 0 similarity embedding)
665+
(-0.8, 4), # Lower similarity - should find 4 results (including -0.5 similarity)
666+
(-1.0, 5), # Lowest similarity - should find all 5 results (including -1 similarity)
666667
]
667668

668669
for confidence, expected_min_results in confidence_tests:
@@ -686,7 +687,11 @@ async def test_query_search_docs_by_embedding_with_different_confidence_levels(
686687

687688
if results:
688689
# Verify that all returned results meet the confidence threshold
690+
# Distance uses cosine distance (0=identical, 2=opposite)
691+
# The SQL converts confidence to search_threshold = 1.0 - confidence
692+
# and filters results where distance <= search_threshold
693+
search_threshold = 1.0 - confidence
689694
for result in results:
690-
assert result.distance >= confidence, (
691-
f"Result distance {result.distance} is below confidence threshold {confidence}"
695+
assert result.distance <= search_threshold, (
696+
f"Result distance {result.distance} exceeds search threshold {search_threshold} (confidence={confidence})"
692697
)

agents-api/tests/test_middleware.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ async def test_middleware_cant_create_session_when_cost_limit_is_reached(make_re
235235
pool = await create_db_pool(dsn=pg_dsn)
236236
developer_id = uuid7()
237237
email = f'test-{developer_id}@example.com'
238-
await create_developer(email=email, active=True, tags=[], settings={}, developer_id=developer_id, connection_pool=pool)
238+
try:
239+
await create_developer(email=email, active=True, tags=[], settings={}, developer_id=developer_id, connection_pool=pool)
240+
finally:
241+
await pool.close()
242+
239243
mock_user_cost_data = {'active': True, 'cost': float(free_tier_cost_limit) + 1.0, 'developer_id': developer_id, 'tags': []}
240244
with patch('agents_api.web.get_usage_cost', new=AsyncMock(return_value=mock_user_cost_data)):
241245
response = make_request(method='POST', url='/sessions', json={'agent_id': str(test_agent.id)}, headers={'X-Developer-Id': str(developer_id)})
@@ -248,12 +252,16 @@ async def test_middleware_cant_delete_session_when_cost_limit_is_reached(make_re
248252
pool = await create_db_pool(dsn=pg_dsn)
249253
developer_id = uuid7()
250254
email = f'test-{developer_id}@example.com'
251-
await create_developer(email=email, active=True, tags=[], settings={}, developer_id=developer_id, connection_pool=pool)
255+
try:
256+
await create_developer(email=email, active=True, tags=[], settings={}, developer_id=developer_id, connection_pool=pool)
257+
finally:
258+
await pool.close()
259+
252260
mock_responses = [{'active': True, 'cost': float(free_tier_cost_limit) - 0.5, 'developer_id': developer_id, 'tags': []}, {'active': True, 'cost': float(free_tier_cost_limit) + 1.0, 'developer_id': developer_id, 'tags': []}]
253261
mock_get_usage_cost = AsyncMock()
254262
mock_get_usage_cost.side_effect = mock_responses
255263
with patch('agents_api.web.get_usage_cost', new=mock_get_usage_cost):
256-
session_response = make_request(method='POST', url='/sessions', json={'agent': str(test_agent.id)}, headers={'X-Developer-Id': str(developer_id)})
264+
session_response = make_request(method='POST', url='/sessions', json={'agent_id': str(test_agent.id)}, headers={'X-Developer-Id': str(developer_id)})
257265
assert session_response.status_code == status.HTTP_201_CREATED
258266
session_id = session_response.json()['id']
259267
delete_response = make_request(method='DELETE', url=f'/sessions/{session_id}', headers={'X-Developer-Id': str(developer_id)})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Python 3.13 Migration Plan for agents-api
2+
3+
## Assessment Summary
4+
Switching to Python 3.13 is **mostly feasible** with some caveats. Most critical dependencies support Python 3.13, but there are a few blockers.
5+
6+
## Key Findings
7+
8+
### ✅ Dependencies that support Python 3.13:
9+
- **temporalio**: Full support (dropped Python 3.8, added 3.13)
10+
- **uvloop 0.21.0**: Full support with cp313 wheels
11+
- **numpy 2.0+**: Full support (requires 2.0 or higher)
12+
- **FastAPI, Pydantic, and most other dependencies**: Compatible
13+
14+
### ❌ Blockers:
15+
- **pytype**: Only supports Python 3.8-3.12, no 3.13 support yet
16+
- This is used for type checking in the development workflow
17+
18+
## Migration Plan
19+
20+
### 1. Update Python version constraints:
21+
- `agents-api/pyproject.toml`: Change `requires-python = ">=3.12,<3.13"` to `requires-python = ">=3.12,<3.14"`
22+
- `agents-api/.python-version`: Change from `3.12` to `3.13`
23+
- `agents-api/Dockerfile`: Change `FROM python:3.12-slim` to `FROM python:3.13-slim`
24+
- `agents-api/Dockerfile.worker`: Update similarly
25+
26+
### 2. Handle pytype incompatibility:
27+
- **Option A**: Replace pytype with pyright (already in dev dependencies) for type checking
28+
- **Option B**: Keep pytype but run it with Python 3.12 while running the service with 3.13
29+
- **Option C**: Wait for pytype to add Python 3.13 support
30+
31+
### 3. Update other services for consistency:
32+
- `integrations-service` uses same Python constraints (`>=3.12,<3.13`)
33+
- `cli` service uses `>=3.11,<3.13`
34+
- Both would need similar updates
35+
36+
### 4. Update CI/CD:
37+
- GitHub Actions workflows use `uv python install` which respects `.python-version`
38+
- Docker builds will automatically use new Python version
39+
- No manual changes needed for workflows
40+
41+
### 5. Testing Plan:
42+
- Run full test suite with Python 3.13
43+
- Check for any deprecation warnings or compatibility issues
44+
- Test Docker builds and deployments
45+
- Verify all integration tests pass
46+
47+
## Recommendation
48+
The migration is mostly trivial except for the pytype issue. I recommend proceeding with **Option A** (replacing pytype with pyright) since pyright is already in your dev dependencies and supports Python 3.13.
49+
50+
## Implementation Steps
51+
1. Replace pytype with pyright in poe tasks
52+
2. Update all Python version references
53+
3. Run `uv sync` to update dependencies
54+
4. Run full test suite
55+
5. Update Docker images
56+
6. Test in staging environment
57+
58+
## Estimated Effort
59+
- Low complexity: Most changes are version string updates
60+
- Main effort: Replacing pytype with pyright configuration
61+
- Timeline: 1-2 hours of work + testing time

agents-api/uv.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)