Skip to content

Commit 7a5077f

Browse files
committed
sync_test_agent
1 parent 52b81be commit 7a5077f

File tree

14 files changed

+73
-73
lines changed

14 files changed

+73
-73
lines changed

TESTING_RESULTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ All bugs found and fixed:
5454

5555
1.**`extract_agent_response()`** - Handle `result` as list of TaskMessages
5656
2.**`send_message_streaming()`** - Use `send_message_stream()` API, not `send_message(stream=True)`
57-
3.**Missing `@contextmanager`** - Added to `test_sync_agent()`
57+
3.**Missing `@contextmanager`** - Added to `sync_test_agent()`
5858
4.**Pytest collection** - Created `conftest.py` to prevent collecting framework functions
5959
5.**State filtering** - Filter states by `task_id` (states.list returns all tasks)
6060
6.**Test assertions** - Made more flexible for agents needing configuration

examples/tutorials/00_sync/000_hello_acp/tests/test_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
from agentex.lib.testing import (
21-
test_sync_agent,
21+
sync_test_agent,
2222
collect_streaming_deltas,
2323
assert_valid_agent_response,
2424
)
@@ -35,7 +35,7 @@ def agent_name():
3535
@pytest.fixture
3636
def test_agent(agent_name: str):
3737
"""Fixture to create a test sync agent."""
38-
with test_sync_agent(agent_name=agent_name) as test:
38+
with sync_test_agent(agent_name=agent_name) as test:
3939
yield test
4040

4141

examples/tutorials/00_sync/010_multiturn/tests/test_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import pytest
2020

2121
from agentex.lib.testing import (
22-
test_sync_agent,
22+
sync_test_agent,
2323
collect_streaming_deltas,
2424
assert_valid_agent_response,
2525
)
@@ -36,7 +36,7 @@ def agent_name():
3636
@pytest.fixture
3737
def test_agent(agent_name: str):
3838
"""Fixture to create a test sync agent."""
39-
with test_sync_agent(agent_name=agent_name) as test:
39+
with sync_test_agent(agent_name=agent_name) as test:
4040
yield test
4141

4242

examples/tutorials/00_sync/020_streaming/tests/test_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pytest
1818

1919
from agentex.lib.testing import (
20-
test_sync_agent,
20+
sync_test_agent,
2121
collect_streaming_deltas,
2222
assert_valid_agent_response,
2323
)
@@ -34,7 +34,7 @@ def agent_name():
3434
@pytest.fixture
3535
def test_agent(agent_name: str):
3636
"""Fixture to create a test sync agent."""
37-
with test_sync_agent(agent_name=agent_name) as test:
37+
with sync_test_agent(agent_name=agent_name) as test:
3838
yield test
3939

4040

examples/tutorials/20_behavior_testing/000_basic_sync_testing/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ Automated tests for sync agents that verify:
1919

2020
Run the tests:
2121
```bash
22-
pytest test_sync_agent.py -v
22+
pytest sync_test_agent.py -v
2323
```
2424

2525
## Understanding Sync Agent Testing
2626

2727
Sync agents respond **immediately** via the `send_message()` API. Testing them is straightforward:
2828

2929
```python
30-
from agentex.lib.testing import test_sync_agent
30+
from agentex.lib.testing import sync_test_agent
3131

3232
def test_basic_response():
33-
with test_sync_agent() as test:
33+
with sync_test_agent() as test:
3434
response = test.send_message("Hello!")
3535
assert response is not None
3636
```
3737

38-
## The Test Helper: `test_sync_agent()`
38+
## The Test Helper: `sync_test_agent()`
3939

40-
The `test_sync_agent()` context manager:
40+
The `sync_test_agent()` context manager:
4141
1. Connects to AgentEx
4242
2. Finds a sync agent
4343
3. Creates a test task
@@ -78,7 +78,7 @@ assert_conversation_maintains_context(history, ["Alice"])
7878

7979
A typical sync agent test follows this pattern:
8080

81-
1. **Setup** - `with test_sync_agent() as test:`
81+
1. **Setup** - `with sync_test_agent() as test:`
8282
2. **Action** - `response = test.send_message("...")`
8383
3. **Assert** - Validate response
8484
4. **Cleanup** - Automatic when context manager exits

examples/tutorials/20_behavior_testing/000_basic_sync_testing/test_sync_agent.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
3. Update AGENT_NAME below
1414
1515
Run:
16-
pytest test_sync_agent.py -v
16+
pytest sync_test_agent.py -v
1717
"""
1818

1919
from agentex.lib.testing import (
20-
test_sync_agent,
20+
sync_test_agent,
2121
assert_valid_agent_response,
2222
assert_agent_response_contains,
2323
assert_conversation_maintains_context,
@@ -27,9 +27,9 @@
2727
AGENT_NAME = "s000-hello-acp"
2828

2929

30-
def test_sync_agent_responds():
30+
def sync_test_agent_responds():
3131
"""Test that sync agent responds to a simple message."""
32-
with test_sync_agent(agent_name=AGENT_NAME) as test:
32+
with sync_test_agent(agent_name=AGENT_NAME) as test:
3333
# Send a message
3434
response = test.send_message("Hello! How are you?")
3535

@@ -38,9 +38,9 @@ def test_sync_agent_responds():
3838
print(f"✓ Agent responded: {response.content[:50]}...")
3939

4040

41-
def test_sync_agent_multi_turn():
41+
def sync_test_agent_multi_turn():
4242
"""Test that sync agent handles multi-turn conversation."""
43-
with test_sync_agent(agent_name=AGENT_NAME) as test:
43+
with sync_test_agent(agent_name=AGENT_NAME) as test:
4444
# First exchange
4545
response1 = test.send_message("Hello!")
4646
assert_valid_agent_response(response1)
@@ -59,9 +59,9 @@ def test_sync_agent_multi_turn():
5959
print(f"✓ Completed {len(history)} message conversation")
6060

6161

62-
def test_sync_agent_context():
62+
def sync_test_agent_context():
6363
"""Test that sync agent maintains conversation context."""
64-
with test_sync_agent(agent_name=AGENT_NAME) as test:
64+
with sync_test_agent(agent_name=AGENT_NAME) as test:
6565
# Establish context
6666
response1 = test.send_message("My name is Sarah and I'm a teacher")
6767
assert_valid_agent_response(response1)
@@ -76,9 +76,9 @@ def test_sync_agent_context():
7676
print("✓ Agent maintained conversation context")
7777

7878

79-
def test_sync_agent_specific_content():
79+
def sync_test_agent_specific_content():
8080
"""Test that agent responds with expected content."""
81-
with test_sync_agent(agent_name=AGENT_NAME) as test:
81+
with sync_test_agent(agent_name=AGENT_NAME) as test:
8282
# Ask a factual question
8383
response = test.send_message("What is 2 plus 2?")
8484

@@ -91,9 +91,9 @@ def test_sync_agent_specific_content():
9191
print(f"✓ Agent provided correct answer: {response.content[:50]}...")
9292

9393

94-
def test_sync_agent_conversation_length():
94+
def sync_test_agent_conversation_length():
9595
"""Test conversation history tracking."""
96-
with test_sync_agent(agent_name=AGENT_NAME) as test:
96+
with sync_test_agent(agent_name=AGENT_NAME) as test:
9797
# Send 3 messages
9898
test.send_message("First message")
9999
test.send_message("Second message")
@@ -108,4 +108,4 @@ def test_sync_agent_conversation_length():
108108

109109

110110
if __name__ == "__main__":
111-
print("Run with: pytest test_sync_agent.py -v")
111+
print("Run with: pytest sync_test_agent.py -v")

examples/tutorials/20_behavior_testing/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Learn how to write automated tests for your AgentEx agents using the `agentex.li
2121
Learn the fundamentals of testing sync agents that respond immediately.
2222

2323
**Key Concepts:**
24-
- Using `test_sync_agent()` context manager
24+
- Using `sync_test_agent()` context manager
2525
- Sending messages with `send_message()`
2626
- Basic response assertions
2727
- Testing conversation history
2828

2929
**Run:**
3030
```bash
3131
cd 000_basic_sync_testing
32-
pytest test_sync_agent.py -v
32+
pytest sync_test_agent.py -v
3333
```
3434

3535
### `010_agentic_testing/`
@@ -52,10 +52,10 @@ pytest async_test_agent.py -v
5252
The simplest way to test an agent:
5353

5454
```python
55-
from agentex.lib.testing import test_sync_agent, assert_valid_agent_response
55+
from agentex.lib.testing import sync_test_agent, assert_valid_agent_response
5656

5757
def test_my_sync_agent():
58-
with test_sync_agent() as test:
58+
with sync_test_agent() as test:
5959
response = test.send_message("Hello!")
6060
assert_valid_agent_response(response)
6161
```

examples/tutorials/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
Pytest configuration for AgentEx tutorials.
33
44
Prevents pytest from trying to collect our testing framework helper functions
5-
(test_sync_agent, async_test_agent) as if they were test functions.
5+
(sync_test_agent, async_test_agent) as if they were test functions.
66
"""
77

88

99
def pytest_configure(config): # noqa: ARG001
1010
"""
1111
Configure pytest to not collect our framework functions.
1212
13-
Mark test_sync_agent and async_test_agent as non-tests.
13+
Mark sync_test_agent and async_test_agent as non-tests.
1414
1515
Args:
1616
config: Pytest config (required by hook signature)
@@ -21,7 +21,7 @@ def pytest_configure(config): # noqa: ARG001
2121
import agentex.lib.testing.sessions.agentic
2222

2323
# Mark our context manager functions as non-tests
24-
agentex.lib.testing.sessions.sync.test_sync_agent.__test__ = False
24+
agentex.lib.testing.sessions.sync.sync_test_agent.__test__ = False
2525
agentex.lib.testing.sessions.agentic.async_test_agent.__test__ = False
2626
except (ImportError, AttributeError):
2727
# If module not available, that's fine

src/agentex/lib/cli/templates/sync/test_agent.py.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Run tests:
1717
"""
1818

1919
from agentex.lib.testing import (
20-
test_sync_agent,
20+
sync_test_agent,
2121
assert_valid_agent_response,
2222
assert_agent_response_contains,
2323
collect_streaming_deltas,
@@ -28,7 +28,7 @@ AGENT_NAME = "{{ agent_name }}"
2828

2929
def test_agent_basic_response():
3030
"""Test that sync agent responds to basic messages."""
31-
with test_sync_agent(agent_name=AGENT_NAME) as test:
31+
with sync_test_agent(agent_name=AGENT_NAME) as test:
3232
response = test.send_message("Hello! Please respond briefly.")
3333

3434
assert_valid_agent_response(response)
@@ -38,7 +38,7 @@ def test_agent_basic_response():
3838

3939
def test_agent_multi_turn():
4040
"""Test multi-turn conversation."""
41-
with test_sync_agent(agent_name=AGENT_NAME) as test:
41+
with sync_test_agent(agent_name=AGENT_NAME) as test:
4242
# Turn 1
4343
response1 = test.send_message("Hello!")
4444
assert_valid_agent_response(response1)
@@ -59,7 +59,7 @@ def test_agent_multi_turn():
5959

6060
def test_agent_streaming():
6161
"""Test streaming responses from sync agent."""
62-
with test_sync_agent(agent_name=AGENT_NAME) as test:
62+
with sync_test_agent(agent_name=AGENT_NAME) as test:
6363
# Get streaming response
6464
response_gen = test.send_message_streaming("Stream this response please")
6565

@@ -77,7 +77,7 @@ def test_agent_custom_scenario():
7777

7878
Customize this test for your agent's specific behavior and requirements.
7979
"""
80-
with test_sync_agent(agent_name=AGENT_NAME) as test:
80+
with sync_test_agent(agent_name=AGENT_NAME) as test:
8181
# Example: Test specific functionality
8282
response = test.send_message("Your custom test message here")
8383

0 commit comments

Comments
 (0)