Skip to content

Commit 9e81d48

Browse files
fix: Checked all tests, typechecks,lint
1 parent 6720cb5 commit 9e81d48

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

tests/test_agent_instructions_signature.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def test_one_parameter_raises_error(self, mock_run_context):
3939
def invalid_instructions(context):
4040
return "Should fail"
4141

42-
agent = Agent(name="test_agent", instructions=invalid_instructions)
42+
agent = Agent(name="test_agent", instructions=invalid_instructions) # type: ignore[arg-type]
4343

4444
with pytest.raises(TypeError) as exc_info:
4545
await agent.get_system_prompt(mock_run_context)
@@ -53,7 +53,7 @@ async def test_three_parameters_raises_error(self, mock_run_context):
5353
def invalid_instructions(context, agent, extra):
5454
return "Should fail"
5555

56-
agent = Agent(name="test_agent", instructions=invalid_instructions)
56+
agent = Agent(name="test_agent", instructions=invalid_instructions) # type: ignore[arg-type]
5757

5858
with pytest.raises(TypeError) as exc_info:
5959
await agent.get_system_prompt(mock_run_context)
@@ -67,7 +67,7 @@ async def test_zero_parameters_raises_error(self, mock_run_context):
6767
def invalid_instructions():
6868
return "Should fail"
6969

70-
agent = Agent(name="test_agent", instructions=invalid_instructions)
70+
agent = Agent(name="test_agent", instructions=invalid_instructions) # type: ignore[arg-type]
7171

7272
with pytest.raises(TypeError) as exc_info:
7373
await agent.get_system_prompt(mock_run_context)
@@ -76,16 +76,18 @@ def invalid_instructions():
7676
assert "but got 0" in str(exc_info.value)
7777

7878
@pytest.mark.asyncio
79-
async def test_function_with_args_kwargs_passes(self, mock_run_context):
80-
"""Test that function with *args/**kwargs still works (edge case)"""
79+
async def test_function_with_args_kwargs_fails(self, mock_run_context):
80+
"""Test that function with *args/**kwargs fails validation"""
8181
def flexible_instructions(context, agent, *args, **kwargs):
8282
return "Flexible instructions"
8383

8484
agent = Agent(name="test_agent", instructions=flexible_instructions)
85-
# This should potentially pass as it can accept the 2 required args
86-
# Adjust this test based on your desired behavior
87-
result = await agent.get_system_prompt(mock_run_context)
88-
assert result == "Flexible instructions"
85+
86+
with pytest.raises(TypeError) as exc_info:
87+
await agent.get_system_prompt(mock_run_context)
88+
89+
assert "must accept exactly 2 arguments" in str(exc_info.value)
90+
assert "but got" in str(exc_info.value)
8991

9092
@pytest.mark.asyncio
9193
async def test_string_instructions_still_work(self, mock_run_context):
@@ -102,10 +104,10 @@ async def test_none_instructions_return_none(self, mock_run_context):
102104
assert result is None
103105

104106
@pytest.mark.asyncio
105-
async def test_non_callable_instructions_log_error(self, mock_run_context, caplog):
106-
"""Test that non-callable instructions log an error"""
107-
agent = Agent(name="test_agent", instructions=123) # Invalid type
108-
result = await agent.get_system_prompt(mock_run_context)
109-
assert result is None
110-
# Check that error was logged (adjust based on actual logging setup)
111-
# assert "Instructions must be a string or a function" in caplog.text
107+
async def test_non_callable_instructions_raises_error(self, mock_run_context):
108+
"""Test that non-callable instructions raise a TypeError during initialization"""
109+
with pytest.raises(TypeError) as exc_info:
110+
Agent(name="test_agent", instructions=123) # type: ignore[arg-type]
111+
112+
assert "Agent instructions must be a string, callable, or None" in str(exc_info.value)
113+
assert "got int" in str(exc_info.value)

0 commit comments

Comments
 (0)